2 NEC PC-8801MA Emulator 'ePC-8801MA'
3 NEC PC-8001mkIISR Emulator 'ePC-8001mkIISR'
5 Author : Takeda.Toshiya
12 #include "../../emu.h"
13 #include "../device.h"
18 #include "../pcm1bit.h"
19 #include "../upd1990a.h"
20 #include "../ym2203.h"
24 #include "../pc80s31k.h"
25 #include "../upd765a.h"
28 #include "../debugger.h"
31 #ifdef SUPPORT_PC88_PCG8100
37 #include "../../fileio.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 VM::VM(EMU* parent_emu) : emu(parent_emu)
46 boot_mode = config.boot_mode;
49 first_device = last_device = NULL;
50 dummy = new DEVICE(this, emu); // must be 1st device
52 pc88event = new EVENT(this, emu);
53 // pc88event->set_frames_per_sec(60);
54 // pc88event->set_lines_per_frame(260);
56 pc88 = new PC88(this, emu);
57 // pc88->set_context_event_manager(pc88event);
58 pc88sio = new I8251(this, emu);
59 // pc88sio->set_context_event_manager(pc88event);
60 pc88pio = new I8255(this, emu);
61 // pc88pio->set_context_event_manager(pc88event);
62 pc88pcm = new PCM1BIT(this, emu);
63 // pc88pcm->set_context_event_manager(pc88event);
64 pc88rtc = new UPD1990A(this, emu);
65 // pc88rtc->set_context_event_manager(pc88event);
66 pc88opn = new YM2203(this, emu);
67 #ifdef SUPPORT_PC88_OPNA
68 pc88opn->is_ym2608 = (config.sound_device_type == 0);
70 // pc88opn->set_context_event_manager(pc88event);
71 pc88cpu = new Z80(this, emu);
72 // pc88cpu->set_context_event_manager(pc88event);
74 pc88sub = new PC80S31K(this, emu);
75 // pc88sub->set_context_event_manager(pc88event);
76 pc88pio_sub = new I8255(this, emu);
77 // pc88pio_sub->set_context_event_manager(pc88event);
78 pc88fdc_sub = new UPD765A(this, emu);
79 // pc88fdc_sub->set_context_event_manager(pc88event);
80 pc88cpu_sub = new Z80(this, emu);
81 // pc88cpu_sub->set_context_event_manager(pc88event);
83 #ifdef SUPPORT_PC88_PCG8100
84 pc88pit = new I8253(this, emu);
85 // pc88pit->set_context_event_manager(pc88event);
86 pc88pcm0 = new PCM1BIT(this, emu);
87 // pc88pcm->set_context_event_manager(pc88event);
88 pc88pcm1 = new PCM1BIT(this, emu);
89 // pc88pcm->set_context_event_manager(pc88event);
90 pc88pcm2 = new PCM1BIT(this, emu);
91 // pc88pcm->set_context_event_manager(pc88event);
94 #ifdef SUPPORT_PC88_HIGH_CLOCK
95 pc88event->set_context_cpu(pc88cpu, (config.cpu_type != 0) ? 3993624 : 7987248);
97 pc88event->set_context_cpu(pc88cpu, 3993624);
99 pc88event->set_context_cpu(pc88cpu_sub, 3993624);
100 pc88event->set_context_sound(pc88opn);
101 pc88event->set_context_sound(pc88pcm);
102 #ifdef SUPPORT_PC88_PCG8100
103 pc88event->set_context_sound(pc88pcm0);
104 pc88event->set_context_sound(pc88pcm1);
105 pc88event->set_context_sound(pc88pcm2);
108 pc88->set_context_cpu(pc88cpu);
109 pc88->set_context_opn(pc88opn);
110 pc88->set_context_pcm(pc88pcm);
111 pc88->set_context_pio(pc88pio);
112 pc88->set_context_rtc(pc88rtc);
113 pc88->set_context_sio(pc88sio);
114 #ifdef SUPPORT_PC88_PCG8100
115 pc88->set_context_pcg_pit(pc88pit);
116 pc88->set_context_pcg_pcm0(pc88pcm0);
117 pc88->set_context_pcg_pcm1(pc88pcm1);
118 pc88->set_context_pcg_pcm2(pc88pcm2);
120 pc88cpu->set_context_mem(pc88);
121 pc88cpu->set_context_io(pc88);
122 pc88cpu->set_context_intr(pc88);
124 pc88cpu->set_context_debugger(new DEBUGGER(this, emu));
126 pc88opn->set_context_irq(pc88, SIG_PC88_SOUND_IRQ, 1);
127 pc88sio->set_context_rxrdy(pc88, SIG_PC88_USART_IRQ, 1);
128 pc88sio->set_context_out(pc88, SIG_PC88_USART_OUT);
130 pc88sub->set_context_cpu(pc88cpu_sub);
131 pc88sub->set_context_fdc(pc88fdc_sub);
132 pc88sub->set_context_pio(pc88pio_sub);
133 pc88pio->set_context_port_a(pc88pio_sub, SIG_I8255_PORT_B, 0xff, 0);
134 pc88pio->set_context_port_b(pc88pio_sub, SIG_I8255_PORT_A, 0xff, 0);
135 pc88pio->set_context_port_c(pc88pio_sub, SIG_I8255_PORT_C, 0x0f, 4);
136 pc88pio->set_context_port_c(pc88pio_sub, SIG_I8255_PORT_C, 0xf0, -4);
137 pc88pio->clear_ports_by_cmdreg = true;
138 pc88pio_sub->set_context_port_a(pc88pio, SIG_I8255_PORT_B, 0xff, 0);
139 pc88pio_sub->set_context_port_b(pc88pio, SIG_I8255_PORT_A, 0xff, 0);
140 pc88pio_sub->set_context_port_c(pc88pio, SIG_I8255_PORT_C, 0x0f, 4);
141 pc88pio_sub->set_context_port_c(pc88pio, SIG_I8255_PORT_C, 0xf0, -4);
142 pc88pio_sub->clear_ports_by_cmdreg = true;
143 pc88fdc_sub->set_context_irq(pc88cpu_sub, SIG_CPU_IRQ, 1);
144 pc88cpu_sub->set_context_mem(pc88sub);
145 pc88cpu_sub->set_context_io(pc88sub);
146 pc88cpu_sub->set_context_intr(pc88sub);
148 pc88cpu_sub->set_context_debugger(new DEBUGGER(this, emu));
151 #ifdef SUPPORT_PC88_PCG8100
152 pc88pit->set_context_ch0(pc88pcm0, SIG_PCM1BIT_SIGNAL, 1);
153 pc88pit->set_context_ch1(pc88pcm1, SIG_PCM1BIT_SIGNAL, 1);
154 pc88pit->set_context_ch2(pc88pcm2, SIG_PCM1BIT_SIGNAL, 1);
155 pc88pit->set_constant_clock(0, 3993624);
156 pc88pit->set_constant_clock(1, 3993624);
157 pc88pit->set_constant_clock(2, 3993624);
160 // initialize all devices
161 for(DEVICE* device = first_device; device; device = device->next_device) {
162 device->initialize();
168 // delete all devices
169 for(DEVICE* device = first_device; device;) {
170 DEVICE *next_device = device->next_device;
173 device = next_device;
177 DEVICE* VM::get_device(int id)
179 for(DEVICE* device = first_device; device; device = device->next_device) {
180 if(device->this_device_id == id) {
187 // ----------------------------------------------------------------------------
188 // drive virtual machine
189 // ----------------------------------------------------------------------------
194 for(DEVICE* device = first_device; device; device = device->next_device) {
197 for(DEVICE* device = first_device; device; device = device->next_device) {
201 // initial device settings
202 pc88opn->SetReg(0x29, 3); // for Misty Blue
203 pc88pio->write_signal(SIG_I8255_PORT_C, 0, 0xff);
204 pc88pio_sub->write_signal(SIG_I8255_PORT_C, 0, 0xff);
212 double VM::frame_rate()
214 return pc88event->frame_rate();
217 // ----------------------------------------------------------------------------
219 // ----------------------------------------------------------------------------
222 DEVICE *VM::get_cpu(int index)
226 } else if(index == 1) {
233 // ----------------------------------------------------------------------------
235 // ----------------------------------------------------------------------------
237 void VM::draw_screen()
242 int VM::access_lamp()
244 return pc88fdc_sub->read_signal(0);
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
251 void VM::initialize_sound(int rate, int samples)
253 // init sound manager
254 pc88event->initialize_sound(rate, samples);
257 #ifdef SUPPORT_PC88_OPNA
258 if(pc88opn->is_ym2608) {
259 pc88opn->init(rate, 7987248, samples, 0, 0);
262 pc88opn->init(rate, 3993624, samples, 0, 0);
263 pc88pcm->init(rate, 8000);
264 #ifdef SUPPORT_PC88_PCG8100
265 pc88pcm0->init(rate, 8000);
266 pc88pcm1->init(rate, 8000);
267 pc88pcm2->init(rate, 8000);
271 uint16* VM::create_sound(int* extra_frames)
273 return pc88event->create_sound(extra_frames);
276 int VM::sound_buffer_ptr()
278 return pc88event->sound_buffer_ptr();
281 // ----------------------------------------------------------------------------
283 // ----------------------------------------------------------------------------
285 void VM::key_down(int code, bool repeat)
287 pc88->key_down(code, repeat);
290 void VM::key_up(int code)
294 // ----------------------------------------------------------------------------
296 // ----------------------------------------------------------------------------
298 void VM::open_disk(int drv, _TCHAR* file_path, int bank)
300 pc88fdc_sub->open_disk(drv, file_path, bank);
303 void VM::close_disk(int drv)
305 pc88fdc_sub->close_disk(drv);
308 bool VM::disk_inserted(int drv)
310 return pc88fdc_sub->disk_inserted(drv);
313 void VM::write_protect_fd(int drv, bool flag)
315 pc88fdc_sub->write_protect_fd(drv, flag);
318 bool VM::is_write_protect_fd(int drv)
320 return pc88fdc_sub->is_write_protect_fd(drv);
323 void VM::play_tape(_TCHAR* file_path)
325 pc88->play_tape(file_path);
328 void VM::rec_tape(_TCHAR* file_path)
330 pc88->rec_tape(file_path);
333 void VM::close_tape()
338 bool VM::tape_inserted()
340 return pc88->tape_inserted();
343 int VM::get_tape_ptr()
345 return pc88->get_tape_ptr();
350 // return event->now_skip();
351 return pc88->now_skip();
354 void VM::update_config()
356 if(boot_mode != config.boot_mode) {
357 // boot mode is changed !!!
358 boot_mode = config.boot_mode;
361 for(DEVICE* device = first_device; device; device = device->next_device) {
362 device->update_config();
367 #define STATE_VERSION 3
369 void VM::save_state(FILEIO* state_fio)
371 state_fio->FputUint32(STATE_VERSION);
373 for(DEVICE* device = first_device; device; device = device->next_device) {
374 device->save_state(state_fio);
376 state_fio->FputInt32(boot_mode);
379 bool VM::load_state(FILEIO* state_fio)
381 if(state_fio->FgetUint32() != STATE_VERSION) {
384 for(DEVICE* device = first_device; device; device = device->next_device) {
385 if(!device->load_state(state_fio)) {
389 boot_mode = state_fio->FgetInt32();