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 g_not = 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(emu->bios_path(_T("FONT.ROM")));
61 vdp->set_vram_ptr(memory->get_vram(), 0x1800);
62 // vdp->set_context_cpu(cpu);
63 vdp->set_context_vsync(g_not, SIG_NOT_INPUT, 1);
64 g_not->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->init(rate, 1996750, samples, 0, 0);
176 uint16* VM::create_sound(int* extra_frames)
178 return event->create_sound(extra_frames);
181 int VM::sound_buffer_ptr()
183 return event->sound_buffer_ptr();
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 void VM::play_tape(const _TCHAR* file_path)
192 drec->play_tape(file_path);
195 void VM::rec_tape(const _TCHAR* file_path)
197 drec->rec_tape(file_path);
200 void VM::close_tape()
205 bool VM::tape_inserted()
207 return drec->tape_inserted();
212 return event->now_skip();
215 void VM::update_config()
217 for(DEVICE* device = first_device; device; device = device->next_device) {
218 device->update_config();
222 #define STATE_VERSION 1
224 void VM::save_state(FILEIO* state_fio)
226 state_fio->FputUint32(STATE_VERSION);
228 for(DEVICE* device = first_device; device; device = device->next_device) {
229 device->save_state(state_fio);
233 bool VM::load_state(FILEIO* state_fio)
235 if(state_fio->FgetUint32() != STATE_VERSION) {
238 for(DEVICE* device = first_device; device; device = device->next_device) {
239 if(!device->load_state(state_fio)) {