2 ASCII MSX1 Emulator 'yaMSX1'
3 ASCII MSX2 Emulator 'yaMSX2'
4 Pioneer PX-7 Emulator 'ePX-7'
9 modified by Takeda.Toshiya
16 #include "../../emu.h"
17 #include "../device.h"
20 #include "../datarec.h"
27 #include "../ym2203.h"
28 #include "../pcm1bit.h"
30 #include "../rp5c01.h"
33 #include "../tms9918a.h"
38 #include "../debugger.h"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 VM::VM(EMU* parent_emu) : emu(parent_emu)
55 first_device = last_device = NULL;
56 dummy = new DEVICE(this, emu); // must be 1st device
57 event = new EVENT(this, emu); // must be 2nd device
59 drec = new DATAREC(this, emu);
60 pio = new I8255(this, emu);
61 io = new IO(this, emu);
63 ldp = new LD700(this, emu);
65 d_not = new NOT(this, emu);
66 psg = new YM2203(this, emu);
67 pcm = new PCM1BIT(this, emu);
69 rtc = new RP5C01(this, emu);
70 vdp = new V99X8(this, emu);
72 vdp = new TMS9918A(this, emu);
74 cpu = new Z80(this, emu);
76 joystick = new JOYSTICK(this, emu);
77 keyboard = new KEYBOARD(this, emu);
78 memory = new MEMORY(this, emu);
80 rtcif = new RTCIF(this, emu);
82 slot0 = new SLOT0(this, emu); // #0: main memory
83 slot1 = new SLOT1(this, emu); // #1: rom-cartridge or msx-dos
84 slot2 = new SLOT2(this, emu); // #2: fdd-cartridge or p-basic
85 slot3 = new SLOT3(this, emu); // #3: rom-cartridge or ram-cartridge
88 event->set_context_cpu(cpu);
89 event->set_context_sound(psg);
90 event->set_context_sound(pcm);
91 event->set_context_sound(drec);
93 event->set_context_sound(ldp);
96 drec->set_context_out(psg, SIG_YM2203_PORT_A, 0x80);
97 pio->set_context_port_a(memory, SIG_MEMORY_SEL, 0xff, 0);
98 pio->set_context_port_c(keyboard, SIG_KEYBOARD_COLUMN, 0x0f, 0);
99 pio->set_context_port_c(d_not, SIG_NOT_INPUT, 0x10, 0);
100 d_not->set_context_out(drec, SIG_DATAREC_REMOTE, 1);
101 pio->set_context_port_c(drec, SIG_DATAREC_OUT, 0x20, 0);
102 pio->set_context_port_c(pcm, SIG_PCM1BIT_SIGNAL, 0x80, 0);
103 psg->set_context_port_b(joystick, SIG_JOYSTICK_SEL, 0x40, 0);
104 vdp->set_context_irq(cpu, SIG_CPU_IRQ, 1);
106 pio->set_context_port_c(slot2, SIG_SLOT2_MUTE, 0x10, 0);
107 ldp->set_context_exv(slot2, SIG_SLOT2_EXV, 1);
108 ldp->set_context_ack(slot2, SIG_SLOT2_ACK, 1);
109 ldp->set_context_sound(psg, SIG_YM2203_PORT_A, 0x80);
112 joystick->set_context_psg(psg);
113 // keyboard->set_context_cpu(cpu);
114 keyboard->set_context_pio(pio);
115 memory->set_context_slot(0, slot0);
116 memory->set_context_slot(1, slot1);
117 memory->set_context_slot(2, slot2);
118 memory->set_context_slot(3, slot3);
120 rtcif->set_context_rtc(rtc);
123 slot2->set_context_cpu(cpu);
124 slot2->set_context_ldp(ldp);
125 slot2->set_context_vdp(vdp);
129 cpu->set_context_mem(memory);
130 cpu->set_context_io(io);
131 cpu->set_context_intr(dummy);
133 cpu->set_context_bios(memory);
136 cpu->set_context_debugger(new DEBUGGER(this, emu));
141 io->set_iomap_range_rw(0xb4, 0xb5, rtcif);
142 io->set_iomap_range_rw(0x98, 0x9b, vdp);
144 io->set_iomap_range_rw(0x98, 0x99, vdp);
146 io->set_iomap_range_rw(0xa8, 0xab, pio);
147 io->set_iomap_alias_w(0xa0, psg, 0); // PSG ch
148 io->set_iomap_alias_w(0xa1, psg, 1); // PSG data
149 io->set_iomap_alias_r(0xa2, psg, 1); // PSG data
150 io->set_iomap_range_rw(0xfc, 0xff, memory);
152 // initialize all devices
153 for(DEVICE* device = first_device; device; device = device->next_device) {
154 device->initialize();
160 // delete all devices
161 for(DEVICE* device = first_device; device;) {
162 DEVICE *next_device = device->next_device;
165 device = next_device;
169 DEVICE* VM::get_device(int id)
171 for(DEVICE* device = first_device; device; device = device->next_device) {
172 if(device->this_device_id == id) {
179 // ----------------------------------------------------------------------------
180 // drive virtual machine
181 // ----------------------------------------------------------------------------
186 for(DEVICE* device = first_device; device; device = device->next_device) {
196 // ----------------------------------------------------------------------------
198 // ----------------------------------------------------------------------------
201 DEVICE *VM::get_cpu(int index)
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 void VM::draw_screen()
219 // ----------------------------------------------------------------------------
221 // ----------------------------------------------------------------------------
223 void VM::initialize_sound(int rate, int samples)
225 // init sound manager
226 event->initialize_sound(rate, samples);
229 psg->init(rate, 3579545, samples, 0, 0);
230 pcm->init(rate, 8000);
232 ldp->initialize_sound(rate, samples);
236 uint16* VM::create_sound(int* extra_frames)
238 return event->create_sound(extra_frames);
241 int VM::sound_buffer_ptr()
243 return event->sound_buffer_ptr();
247 void VM::movie_sound_callback(uint8 *buffer, long size)
249 ldp->movie_sound_callback(buffer, size);
253 // ----------------------------------------------------------------------------
255 // ----------------------------------------------------------------------------
257 void VM::open_cart(int drv, _TCHAR* file_path)
260 slot1->open_cart(file_path);
262 slot3->open_cart(file_path);
267 void VM::close_cart(int drv)
277 bool VM::cart_inserted(int drv)
280 return slot1->cart_inserted();
282 return slot3->cart_inserted();
286 void VM::play_tape(_TCHAR* file_path)
288 drec->play_tape(file_path);
291 void VM::rec_tape(_TCHAR* file_path)
293 drec->rec_tape(file_path);
296 void VM::close_tape()
301 bool VM::tape_inserted()
303 return drec->tape_inserted();
306 int VM::get_tape_ptr(void)
308 return drec->get_tape_ptr();
312 void VM::open_laser_disc(_TCHAR* file_path)
314 ldp->open_disc(file_path);
317 void VM::close_laser_disc()
322 bool VM::laser_disc_inserted()
324 return ldp->disc_inserted();
327 void VM::open_disk(int drv, _TCHAR* file_path, int bank)
329 memory->open_disk(drv, file_path, bank);
332 void VM::close_disk(int drv)
334 memory->close_disk(drv);
337 bool VM::disk_inserted(int drv)
339 return memory->disk_inserted(drv);
341 void VM::write_protect_fd(int drv, bool flag)
343 //fdc->write_protect_fd(drv, flag);
345 bool VM::is_write_protect_fd(int drv)
347 //return fdc->is_write_protect_fd(drv);
351 //int VM::access_lamp()
353 // //uint32 status = fdc->read_signal(0);
354 // //return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
361 return event->now_skip();
364 void VM::update_config()
366 for(DEVICE* device = first_device; device; device = device->next_device) {
367 device->update_config();
371 #define STATE_VERSION 1
373 void VM::save_state(FILEIO* state_fio)
375 state_fio->FputUint32(STATE_VERSION);
377 for(DEVICE* device = first_device; device; device = device->next_device) {
378 device->save_state(state_fio);
382 bool VM::load_state(FILEIO* state_fio)
384 if(state_fio->FgetUint32() != STATE_VERSION) {
387 for(DEVICE* device = first_device; device; device = device->next_device) {
388 if(!device->load_state(state_fio)) {