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 dummy->set_device_name(_T("1st Dummy"));
60 event->set_device_name(_T("EVENT"));
63 drec = new DATAREC(this, emu);
64 pio = new I8255(this, emu);
65 io = new IO(this, emu);
67 pio->set_device_name(_T("i8255 PIO"));
68 io->set_device_name(_T("I/O BUS"));
71 ldp = new LD700(this, emu);
73 not_remote = new NOT(this, emu);
74 psg = new YM2203(this, emu);
75 pcm = new PCM1BIT(this, emu);
77 not_remote->set_device_name(_T("NOT GATE(REMOTE)"));
78 psg->set_device_name(_T("AY-3-8910 PSG"));
79 pcm->set_device_name(_T("PCM BUZZER"));
82 rtc = new RP5C01(this, emu);
83 vdp = new V99X8(this, emu);
85 rtc->set_device_name(_T("RP5C01 RTC"));
86 vdp->set_device_name(_T("V99x8 VDP"));
89 vdp = new TMS9918A(this, emu);
91 vdp->set_device_name(_T("TMS9918 VDP"));
94 cpu = new Z80(this, emu);
96 cpu->set_device_name(_T("CPU(Z80)"));
98 joystick = new JOYSTICK(this, emu);
99 keyboard = new KEYBOARD(this, emu);
100 memory = new MEMORY(this, emu);
102 rtcif = new RTCIF(this, emu);
105 joystick->set_device_name(_T("JOYSTICK I/F"));
106 keyboard->set_device_name(_T("KEYBOARD I/F"));
107 memory->set_device_name(_T("MEMORY"));
109 rtcif->set_device_name(_T("RTC I/F"));
112 slot0 = new SLOT0(this, emu); // #0: main memory
113 slot1 = new SLOT1(this, emu); // #1: rom-cartridge or msx-dos
114 slot2 = new SLOT2(this, emu); // #2: fdd-cartridge or p-basic
115 slot3 = new SLOT3(this, emu); // #3: rom-cartridge or ram-cartridge
117 slot0->set_device_name(_T("SLOT#0 MAIN MEMORY"));
118 slot1->set_device_name(_T("SLOT#1 ROM CARTRIDGE"));
119 slot2->set_device_name(_T("SLOT#2 FDD CARTRIDGE"));
120 slot3->set_device_name(_T("SLOT#3 ROM CARTRIDGE"));
123 event->set_context_cpu(cpu);
124 event->set_context_sound(psg);
125 event->set_context_sound(pcm);
126 event->set_context_sound(drec);
128 event->set_context_sound(ldp);
130 #if defined(USE_SOUND_FILES)
132 //if(memory->load_sound_data(MEMORY_SND_TYPE_DISK_SEEK, _T("FDDSEEK.WAV"))) {
133 // event->set_context_sound(memory);
136 //drec->load_sound_data(DATAREC_SNDFILE_EJECT, _T("CMTEJECT.WAV"));
137 drec->load_sound_data(DATAREC_SNDFILE_RELAY_ON, _T("RELAY_ON.WAV"));
138 drec->load_sound_data(DATAREC_SNDFILE_RELAY_OFF, _T("RELAYOFF.WAV"));
141 drec->set_context_ear(psg, SIG_YM2203_PORT_A, 0x80);
142 pio->set_context_port_a(memory, SIG_MEMORY_SEL, 0xff, 0);
143 pio->set_context_port_c(keyboard, SIG_KEYBOARD_COLUMN, 0x0f, 0);
144 pio->set_context_port_c(not_remote, SIG_NOT_INPUT, 0x10, 0);
145 not_remote->set_context_out(drec, SIG_DATAREC_REMOTE, 1);
146 pio->set_context_port_c(drec, SIG_DATAREC_MIC, 0x20, 0);
147 pio->set_context_port_c(pcm, SIG_PCM1BIT_SIGNAL, 0x80, 0);
148 psg->set_context_port_b(joystick, SIG_JOYSTICK_SEL, 0x40, 0);
149 vdp->set_context_irq(cpu, SIG_CPU_IRQ, 1);
151 // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
152 pcm->set_realtime_render(true);
154 pio->set_context_port_c(slot2, SIG_SLOT2_MUTE, 0x10, 0);
155 ldp->set_context_exv(slot2, SIG_SLOT2_EXV, 1);
156 ldp->set_context_ack(slot2, SIG_SLOT2_ACK, 1);
157 ldp->set_context_sound(psg, SIG_YM2203_PORT_A, 0x80);
160 joystick->set_context_psg(psg);
161 // keyboard->set_context_cpu(cpu);
162 keyboard->set_context_pio(pio);
163 memory->set_context_slot(0, slot0);
164 memory->set_context_slot(1, slot1);
165 memory->set_context_slot(2, slot2);
166 memory->set_context_slot(3, slot3);
168 rtcif->set_context_rtc(rtc);
171 slot2->set_context_cpu(cpu);
172 slot2->set_context_ldp(ldp);
173 slot2->set_context_vdp(vdp);
177 cpu->set_context_mem(memory);
178 cpu->set_context_io(io);
179 cpu->set_context_intr(dummy);
181 cpu->set_context_bios(memory);
184 cpu->set_context_debugger(new DEBUGGER(this, emu));
189 io->set_iomap_range_rw(0xb4, 0xb5, rtcif);
190 io->set_iomap_range_rw(0x98, 0x9b, vdp);
192 io->set_iomap_range_rw(0x98, 0x99, vdp);
194 io->set_iomap_range_rw(0xa8, 0xab, pio);
195 io->set_iomap_alias_w(0xa0, psg, 0); // PSG ch
196 io->set_iomap_alias_w(0xa1, psg, 1); // PSG data
197 io->set_iomap_alias_r(0xa2, psg, 1); // PSG data
198 io->set_iomap_range_rw(0xfc, 0xff, memory);
200 // initialize all devices
201 for(DEVICE* device = first_device; device; device = device->next_device) {
202 device->initialize();
208 // delete all devices
209 for(DEVICE* device = first_device; device;) {
210 DEVICE *next_device = device->next_device;
213 device = next_device;
217 DEVICE* VM::get_device(int id)
219 for(DEVICE* device = first_device; device; device = device->next_device) {
220 if(device->this_device_id == id) {
227 // ----------------------------------------------------------------------------
228 // drive virtual machine
229 // ----------------------------------------------------------------------------
234 for(DEVICE* device = first_device; device; device = device->next_device) {
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
249 DEVICE *VM::get_cpu(int index)
258 // ----------------------------------------------------------------------------
260 // ----------------------------------------------------------------------------
262 void VM::draw_screen()
267 // ----------------------------------------------------------------------------
269 // ----------------------------------------------------------------------------
271 void VM::initialize_sound(int rate, int samples)
273 // init sound manager
274 event->initialize_sound(rate, samples);
277 psg->initialize_sound(rate, 3579545, samples, 0, 0);
278 pcm->initialize_sound(rate, 8000);
280 ldp->initialize_sound(rate, samples);
284 uint16_t* VM::create_sound(int* extra_frames)
286 return event->create_sound(extra_frames);
289 int VM::get_sound_buffer_ptr()
291 return event->get_sound_buffer_ptr();
295 void VM::movie_sound_callback(uint8_t *buffer, long size)
297 ldp->movie_sound_callback(buffer, size);
301 #ifdef USE_SOUND_VOLUME
302 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
305 psg->set_volume(1, decibel_l, decibel_r);
307 pcm->set_volume(0, decibel_l, decibel_r);
309 drec->set_volume(0, decibel_l, decibel_r);
312 ldp->set_volume(0, decibel_l, decibel_r);
314 #if defined(USE_SOUND_FILES)
316 //} else if(ch == 3) {
317 //memory->set_volume(MEMORY_SND_TYPE_FDD_SEEK, decibel_l, decibel_r);
321 drec->set_volume(2 + DATAREC_SNDFILE_RELAY_ON, decibel_l, decibel_r);
322 drec->set_volume(2 + DATAREC_SNDFILE_RELAY_OFF, decibel_l, decibel_r);
323 //drec->set_volume(2 + DATAREC_SNDFILE_EJECT, decibel_l, decibel_r);
326 drec->set_volume(2 + DATAREC_SNDFILE_RELAY_ON, decibel_l, decibel_r);
327 drec->set_volume(2 + DATAREC_SNDFILE_RELAY_OFF, decibel_l, decibel_r);
328 //drec->set_volume(2 + DATAREC_SNDFILE_EJECT, decibel_l, decibel_r);
335 // ----------------------------------------------------------------------------
337 // ----------------------------------------------------------------------------
339 void VM::open_cart(int drv, const _TCHAR* file_path)
342 slot1->open_cart(file_path);
344 slot3->open_cart(file_path);
349 void VM::close_cart(int drv)
359 bool VM::is_cart_inserted(int drv)
362 return slot1->is_cart_inserted();
364 return slot3->is_cart_inserted();
368 void VM::play_tape(const _TCHAR* file_path)
370 drec->play_tape(file_path);
373 void VM::rec_tape(const _TCHAR* file_path)
375 drec->rec_tape(file_path);
378 void VM::close_tape()
380 #if defined(USE_SOUND_FILES)
381 //drec->write_signal(SIG_SOUNDER_ADD + DATAREC_SNDFILE_EJECT, 1, 1);
388 bool VM::is_tape_inserted()
390 return drec->is_tape_inserted();
393 bool VM::is_tape_playing()
395 return drec->is_tape_playing();
398 bool VM::is_tape_recording()
400 return drec->is_tape_recording();
403 int VM::get_tape_position()
405 return drec->get_tape_position();
409 void VM::open_laser_disc(const _TCHAR* file_path)
411 ldp->open_disc(file_path);
414 void VM::close_laser_disc()
419 bool VM::is_laser_disc_inserted()
421 return ldp->is_disc_inserted();
424 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
426 memory->open_disk(drv, file_path, bank);
429 void VM::close_floppy_disk(int drv)
431 memory->close_disk(drv);
434 bool VM::is_floppy_disk_inserted(int drv)
436 return memory->is_disk_inserted(drv);
439 void VM::is_floppy_disk_protected(int drv, bool value)
441 memory->is_disk_protected(drv, value);
444 bool VM::is_floppy_disk_protected(int drv)
446 return memory->is_disk_protected(drv);
450 bool VM::is_frame_skippable()
452 return event->is_frame_skippable();
455 void VM::update_config()
457 for(DEVICE* device = first_device; device; device = device->next_device) {
458 device->update_config();
462 #define STATE_VERSION 1
464 void VM::save_state(FILEIO* state_fio)
466 state_fio->FputUint32(STATE_VERSION);
468 for(DEVICE* device = first_device; device; device = device->next_device) {
469 device->save_state(state_fio);
473 bool VM::load_state(FILEIO* state_fio)
475 if(state_fio->FgetUint32() != STATE_VERSION) {
478 for(DEVICE* device = first_device; device; device = device->next_device) {
479 if(!device->load_state(state_fio)) {