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 #if defined(__GIT_REPO_VERSION)
75 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
77 for(DEVICE* device = first_device; device; device = device->next_device) {
86 for(DEVICE* device = first_device; device;) {
87 DEVICE *next_device = device->next_device;
94 DEVICE* VM::get_device(int id)
96 for(DEVICE* device = first_device; device; device = device->next_device) {
97 if(device->this_device_id == id) {
104 // ----------------------------------------------------------------------------
105 // drive virtual machine
106 // ----------------------------------------------------------------------------
111 for(DEVICE* device = first_device; device; device = device->next_device) {
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
126 DEVICE *VM::get_cpu(int index)
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 void VM::draw_screen()
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 void VM::initialize_sound(int rate, int samples)
150 // init sound manager
151 event->initialize_sound(rate, samples);
154 uint16_t* VM::create_sound(int* extra_frames)
156 return event->create_sound(extra_frames);
159 int VM::get_sound_buffer_ptr()
161 return event->get_sound_buffer_ptr();
164 #ifdef USE_SOUND_VOLUME
165 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
168 drec->set_volume(0, decibel_l, decibel_r);
170 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
171 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
172 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
181 void VM::play_tape(int drv, const _TCHAR* file_path)
183 drec->play_tape(file_path);
184 // drec->set_remote(true);
187 void VM::rec_tape(int drv, const _TCHAR* file_path)
189 drec->rec_tape(file_path);
190 // drec->set_remote(true);
193 void VM::close_tape(int drv)
198 // drec->set_remote(false);
201 bool VM::is_tape_inserted(int drv)
203 return drec->is_tape_inserted();
206 bool VM::is_tape_playing(int drv)
208 return drec->is_tape_playing();
211 bool VM::is_tape_recording(int drv)
213 return drec->is_tape_recording();
216 int VM::get_tape_position(int drv)
218 return drec->get_tape_position();
221 const _TCHAR* VM::get_tape_message(int drv)
223 return drec->get_message();
226 void VM::push_play(int drv)
229 drec->set_remote(true);
232 void VM::push_stop(int drv)
234 drec->set_remote(false);
237 void VM::push_fast_forward(int drv)
240 drec->set_remote(true);
243 void VM::push_fast_rewind(int drv)
245 drec->set_ff_rew(-1);
246 drec->set_remote(true);
249 bool VM::is_frame_skippable()
251 return event->is_frame_skippable();
254 void VM::update_config()
256 for(DEVICE* device = first_device; device; device = device->next_device) {
257 device->update_config();
261 #define STATE_VERSION 3
263 #include "../../statesub.h"
264 #include "../../qt/gui/csp_logger.h"
265 extern CSP_Logger DLL_PREFIX_I *csp_logger;
267 void VM::decl_state(void)
269 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PHC_20_HEAD")), csp_logger);
271 for(DEVICE* device = first_device; device; device = device->next_device) {
272 device->decl_state();
276 void VM::save_state(FILEIO* state_fio)
278 //state_fio->FputUint32(STATE_VERSION);
280 if(state_entry != NULL) {
281 state_entry->save_state(state_fio);
283 for(DEVICE* device = first_device; device; device = device->next_device) {
284 device->save_state(state_fio);
288 bool VM::load_state(FILEIO* state_fio)
290 //if(state_fio->FgetUint32() != STATE_VERSION) {
295 if(state_entry != NULL) {
296 mb = state_entry->load_state(state_fio);
299 emu->out_debug_log("INFO: HEADER DATA ERROR");
302 for(DEVICE* device = first_device; device; device = device->next_device) {
303 if(!device->load_state(state_fio)) {