2 SANYO PHC-25 Emulator 'ePHC-25'
3 SEIKO MAP-1010 Emulator 'eMAP-1010'
5 Author : Takeda.Toshiya
12 #include "../../emu.h"
13 #include "../device.h"
16 #include "../datarec.h"
18 #include "../mc6847.h"
20 #include "../ym2203.h"
24 #include "../debugger.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 VM::VM(EMU* parent_emu) : emu(parent_emu)
39 first_device = last_device = NULL;
40 dummy = new DEVICE(this, emu); // must be 1st device
41 event = new EVENT(this, emu); // must be 2nd device
43 drec = new DATAREC(this, emu);
44 io = new IO(this, emu);
45 vdp = new MC6847(this, emu);
46 not_vsync = new NOT(this, emu);
47 psg = new YM2203(this, emu);
48 cpu = new Z80(this, emu);
50 joystick = new JOYSTICK(this, emu);
51 keyboard = new KEYBOARD(this, emu);
52 memory = new MEMORY(this, emu);
53 system = new SYSTEM(this, emu);
56 event->set_context_cpu(cpu);
57 event->set_context_sound(psg);
58 event->set_context_sound(drec);
60 vdp->load_font_image(create_local_path(_T("FONT.ROM")));
61 vdp->set_vram_ptr(memory->get_vram(), 0x1800);
62 // vdp->set_context_cpu(cpu);
63 vdp->set_context_vsync(not_vsync, SIG_NOT_INPUT, 1);
64 not_vsync->set_context_out(cpu, SIG_CPU_IRQ, 1);
66 vdp->set_context_vsync(system, SIG_SYSTEM_PORT, 0x10);
67 drec->set_context_ear(system, SIG_SYSTEM_PORT, 0x20);
69 vdp->set_context_hsync(system, SIG_SYSTEM_PORT, 0x80);
71 joystick->set_context_psg(psg);
73 memory->set_context_keyboard(keyboard);
75 system->set_context_drec(drec);
76 system->set_context_vdp(vdp);
79 cpu->set_context_mem(memory);
80 cpu->set_context_io(io);
81 cpu->set_context_intr(dummy);
83 cpu->set_context_debugger(new DEBUGGER(this, emu));
87 io->set_iomap_single_rw(0x40, system);
89 io->set_iomap_range_r(0x80, 0x88, keyboard);
91 io->set_iomap_alias_w(0xc0, psg, 1); // PSG data
92 io->set_iomap_alias_w(0xc1, psg, 0); // PSG ch
93 // io->set_iomap_alias_r(0xc0, psg, 1);
94 io->set_iomap_alias_r(0xc1, psg, 1); // PSG data
96 // initialize all devices
97 for(DEVICE* device = first_device; device; device = device->next_device) {
104 // delete all devices
105 for(DEVICE* device = first_device; device;) {
106 DEVICE *next_device = device->next_device;
109 device = next_device;
113 DEVICE* VM::get_device(int id)
115 for(DEVICE* device = first_device; device; device = device->next_device) {
116 if(device->this_device_id == id) {
123 // ----------------------------------------------------------------------------
124 // drive virtual machine
125 // ----------------------------------------------------------------------------
130 for(DEVICE* device = first_device; device; device = device->next_device) {
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
145 DEVICE *VM::get_cpu(int index)
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 void VM::draw_screen()
163 // ----------------------------------------------------------------------------
165 // ----------------------------------------------------------------------------
167 void VM::initialize_sound(int rate, int samples)
169 // init sound manager
170 event->initialize_sound(rate, samples);
173 psg->initialize_sound(rate, 1996750, samples, 0, 0);
176 uint16_t* VM::create_sound(int* extra_frames)
178 return event->create_sound(extra_frames);
181 int VM::get_sound_buffer_ptr()
183 return event->get_sound_buffer_ptr();
186 #ifdef USE_SOUND_VOLUME
187 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
190 psg->set_volume(1, decibel_l, decibel_r);
192 drec->set_volume(0, decibel_l, decibel_r);
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 void VM::play_tape(const _TCHAR* file_path)
203 drec->play_tape(file_path);
206 void VM::rec_tape(const _TCHAR* file_path)
208 drec->rec_tape(file_path);
211 void VM::close_tape()
216 bool VM::is_tape_inserted()
218 return drec->is_tape_inserted();
221 bool VM::is_tape_playing()
223 return drec->is_tape_playing();
226 bool VM::is_tape_recording()
228 return drec->is_tape_recording();
231 int VM::get_tape_position()
233 return drec->get_tape_position();
236 bool VM::is_frame_skippable()
238 return event->is_frame_skippable();
241 void VM::update_config()
243 for(DEVICE* device = first_device; device; device = device->next_device) {
244 device->update_config();
248 #define STATE_VERSION 1
250 void VM::save_state(FILEIO* state_fio)
252 state_fio->FputUint32(STATE_VERSION);
254 for(DEVICE* device = first_device; device; device = device->next_device) {
255 device->save_state(state_fio);
259 bool VM::load_state(FILEIO* state_fio)
261 if(state_fio->FgetUint32() != STATE_VERSION) {
264 for(DEVICE* device = first_device; device; device = device->next_device) {
265 if(!device->load_state(state_fio)) {