2 SANYO PHC-20 Emulator 'ePHC-20'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
16 #include "../mc6847.h"
21 #include "../debugger.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
33 first_device = last_device = NULL;
34 dummy = new DEVICE(this, emu); // must be 1st device
35 event = new EVENT(this, emu); // must be 2nd device
36 dummy->set_device_name(_T("1st Dummy"));
38 drec = new DATAREC(this, emu);
39 drec->set_context_noise_play(new NOISE(this, emu));
40 drec->set_context_noise_stop(new NOISE(this, emu));
41 drec->set_context_noise_fast(new NOISE(this, emu));
42 vdp = new MC6847(this, emu);
43 cpu = new Z80(this, emu);
44 memory = new MEMORY(this, emu);
46 event->set_context_cpu(cpu);
47 event->set_context_sound(drec);
48 event->set_context_sound(drec->get_context_noise_play());
49 event->set_context_sound(drec->get_context_noise_stop());
50 event->set_context_sound(drec->get_context_noise_fast());
52 drec->set_context_ear(memory, SIG_MEMORY_SYSPORT, 1);
53 vdp->set_context_vsync(memory, SIG_MEMORY_SYSPORT, 2); // vsync / hsync?
55 vdp->load_font_image(create_local_path(_T("FONT.ROM")));
56 vdp->set_vram_ptr(memory->get_vram(), 0x400);
57 vdp->set_context_cpu(cpu);
58 vdp->write_signal(SIG_MC6847_AG, 0, 0); // force character mode
59 vdp->write_signal(SIG_MC6847_AS, 0, 0);
60 vdp->write_signal(SIG_MC6847_INTEXT, 0, 0); // force internal character ???
61 vdp->write_signal(SIG_MC6847_CSS, 0, 0);
63 memory->set_context_drec(drec);
66 cpu->set_context_mem(memory);
67 cpu->set_context_io(dummy);
68 cpu->set_context_intr(dummy);
70 cpu->set_context_debugger(new DEBUGGER(this, emu));
73 // initialize all devices
74 for(DEVICE* device = first_device; device; device = device->next_device) {
83 for(DEVICE* device = first_device; device;) {
84 DEVICE *next_device = device->next_device;
91 DEVICE* VM::get_device(int id)
93 for(DEVICE* device = first_device; device; device = device->next_device) {
94 if(device->this_device_id == id) {
101 // ----------------------------------------------------------------------------
102 // drive virtual machine
103 // ----------------------------------------------------------------------------
108 for(DEVICE* device = first_device; device; device = device->next_device) {
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
123 DEVICE *VM::get_cpu(int index)
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 void VM::draw_screen()
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 void VM::initialize_sound(int rate, int samples)
147 // init sound manager
148 event->initialize_sound(rate, samples);
151 uint16_t* VM::create_sound(int* extra_frames)
153 return event->create_sound(extra_frames);
156 int VM::get_sound_buffer_ptr()
158 return event->get_sound_buffer_ptr();
161 #ifdef USE_SOUND_VOLUME
162 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
165 drec->set_volume(0, decibel_l, decibel_r);
167 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
168 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
169 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 void VM::play_tape(int drv, const _TCHAR* file_path)
180 drec->play_tape(file_path);
181 // drec->set_remote(true);
184 void VM::rec_tape(int drv, const _TCHAR* file_path)
186 drec->rec_tape(file_path);
187 // drec->set_remote(true);
190 void VM::close_tape(int drv)
195 // drec->set_remote(false);
198 bool VM::is_tape_inserted(int drv)
200 return drec->is_tape_inserted();
203 bool VM::is_tape_playing(int drv)
205 return drec->is_tape_playing();
208 bool VM::is_tape_recording(int drv)
210 return drec->is_tape_recording();
213 int VM::get_tape_position(int drv)
215 return drec->get_tape_position();
218 const _TCHAR* VM::get_tape_message(int drv)
220 return drec->get_message();
223 void VM::push_play(int drv)
226 drec->set_remote(true);
229 void VM::push_stop(int drv)
231 drec->set_remote(false);
234 void VM::push_fast_forward(int drv)
237 drec->set_remote(true);
240 void VM::push_fast_rewind(int drv)
242 drec->set_ff_rew(-1);
243 drec->set_remote(true);
246 bool VM::is_frame_skippable()
248 return event->is_frame_skippable();
251 void VM::update_config()
253 for(DEVICE* device = first_device; device; device = device->next_device) {
254 device->update_config();
258 #define STATE_VERSION 3
260 #include "../../statesub.h"
261 #include "../../qt/gui/csp_logger.h"
262 extern CSP_Logger DLL_PREFIX_I *csp_logger;
264 void VM::decl_state(void)
266 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PHC_20_HEAD")), csp_logger);
268 for(DEVICE* device = first_device; device; device = device->next_device) {
269 device->decl_state();
273 void VM::save_state(FILEIO* state_fio)
275 //state_fio->FputUint32(STATE_VERSION);
277 if(state_entry != NULL) {
278 state_entry->save_state(state_fio);
280 for(DEVICE* device = first_device; device; device = device->next_device) {
281 device->save_state(state_fio);
285 bool VM::load_state(FILEIO* state_fio)
287 //if(state_fio->FgetUint32() != STATE_VERSION) {
292 if(state_entry != NULL) {
293 mb = state_entry->load_state(state_fio);
296 emu->out_debug_log("INFO: HEADER DATA ERROR");
299 for(DEVICE* device = first_device; device; device = device->next_device) {
300 if(!device->load_state(state_fio)) {