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 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 VM::VM(EMU* parent_emu) : emu(parent_emu)
44 boot_mode = config.boot_mode;
47 first_device = last_device = NULL;
48 dummy = new DEVICE(this, emu); // must be 1st device
50 pc88event = new EVENT(this, emu);
51 // pc88event->set_frames_per_sec(60);
52 // pc88event->set_lines_per_frame(260);
54 pc88 = new PC88(this, emu);
55 // pc88->set_context_event_manager(pc88event);
56 pc88sio = new I8251(this, emu);
57 // pc88sio->set_context_event_manager(pc88event);
58 pc88pio = new I8255(this, emu);
59 // pc88pio->set_context_event_manager(pc88event);
60 pc88pcm = new PCM1BIT(this, emu);
61 // pc88pcm->set_context_event_manager(pc88event);
62 pc88rtc = new UPD1990A(this, emu);
63 // pc88rtc->set_context_event_manager(pc88event);
64 // config.sound_device_type
65 // 0: 44h:OPNA A4h:None PC-8801FH/MH or later
66 // 1: 44h:OPN A4h:None PC-8801mkIISR/TR/MR/FR
67 // 2: 44h:OPN A4h:OPNA PC-8801mkIISR/TR/MR/FR + PC-8801-23
68 pc88opn = new YM2203(this, emu);
69 #ifdef SUPPORT_PC88_OPNA
70 pc88opn->is_ym2608 = (config.sound_device_type == 0);
72 // pc88opn->set_context_event_manager(pc88event);
73 #ifdef SUPPORT_PC88_SB2
74 if(config.sound_device_type == 2) {
75 pc88sb2 = new YM2203(this, emu);
76 #ifdef SUPPORT_PC88_OPNA
77 pc88sb2->is_ym2608 = true;
79 // pc88sb2->set_context_event_manager(pc88event);
84 pc88cpu = new Z80(this, emu);
85 // pc88cpu->set_context_event_manager(pc88event);
86 dummycpu = new DEVICE(this, emu);
88 pc88sub = new PC80S31K(this, emu);
89 // pc88sub->set_context_event_manager(pc88event);
90 pc88pio_sub = new I8255(this, emu);
91 // pc88pio_sub->set_context_event_manager(pc88event);
92 pc88fdc_sub = new UPD765A(this, emu);
93 // pc88fdc_sub->set_context_event_manager(pc88event);
94 pc88cpu_sub = new Z80(this, emu);
95 // pc88cpu_sub->set_context_event_manager(pc88event);
97 #ifdef SUPPORT_PC88_PCG8100
98 pc88pit = new I8253(this, emu);
99 // pc88pit->set_context_event_manager(pc88event);
100 pc88pcm0 = new PCM1BIT(this, emu);
101 // pc88pcm->set_context_event_manager(pc88event);
102 pc88pcm1 = new PCM1BIT(this, emu);
103 // pc88pcm->set_context_event_manager(pc88event);
104 pc88pcm2 = new PCM1BIT(this, emu);
105 // pc88pcm->set_context_event_manager(pc88event);
108 #ifdef SUPPORT_PC88_HIGH_CLOCK
109 pc88event->set_context_cpu(dummycpu, 7987248);
110 pc88event->set_context_cpu(pc88cpu, (config.cpu_type != 0) ? 3993624 : 7987248);
112 pc88event->set_context_cpu(dummycpu, 3993624);
113 pc88event->set_context_cpu(pc88cpu, 3993624);
115 pc88event->set_context_cpu(pc88cpu_sub, 3993624);
116 pc88event->set_context_sound(pc88opn);
117 #ifdef SUPPORT_PC88_SB2
118 if(pc88sb2 != NULL) {
119 pc88event->set_context_sound(pc88sb2);
122 pc88event->set_context_sound(pc88pcm);
123 #ifdef SUPPORT_PC88_PCG8100
124 pc88event->set_context_sound(pc88pcm0);
125 pc88event->set_context_sound(pc88pcm1);
126 pc88event->set_context_sound(pc88pcm2);
129 pc88event->set_context_sound(pc88);
131 pc88->set_context_cpu(pc88cpu);
132 pc88->set_context_opn(pc88opn);
133 #ifdef SUPPORT_PC88_SB2
134 pc88->set_context_sb2(pc88sb2);
136 pc88->set_context_pcm(pc88pcm);
137 pc88->set_context_pio(pc88pio);
138 pc88->set_context_rtc(pc88rtc);
139 pc88->set_context_sio(pc88sio);
140 #ifdef SUPPORT_PC88_PCG8100
141 pc88->set_context_pcg_pit(pc88pit);
142 pc88->set_context_pcg_pcm0(pc88pcm0);
143 pc88->set_context_pcg_pcm1(pc88pcm1);
144 pc88->set_context_pcg_pcm2(pc88pcm2);
146 pc88cpu->set_context_mem(pc88);
147 pc88cpu->set_context_io(pc88);
148 pc88cpu->set_context_intr(pc88);
150 pc88cpu->set_context_debugger(new DEBUGGER(this, emu));
152 pc88opn->set_context_irq(pc88, SIG_PC88_SOUND_IRQ, 1);
153 #ifdef SUPPORT_PC88_SB2
154 if(pc88sb2 != NULL) {
155 pc88sb2->set_context_irq(pc88, SIG_PC88_SB2_IRQ, 1);
158 pc88sio->set_context_rxrdy(pc88, SIG_PC88_USART_IRQ, 1);
159 pc88sio->set_context_out(pc88, SIG_PC88_USART_OUT);
161 pc88sub->set_context_cpu(pc88cpu_sub);
162 pc88sub->set_context_fdc(pc88fdc_sub);
163 pc88sub->set_context_pio(pc88pio_sub);
164 pc88pio->set_context_port_a(pc88pio_sub, SIG_I8255_PORT_B, 0xff, 0);
165 pc88pio->set_context_port_b(pc88pio_sub, SIG_I8255_PORT_A, 0xff, 0);
166 pc88pio->set_context_port_c(pc88pio_sub, SIG_I8255_PORT_C, 0x0f, 4);
167 pc88pio->set_context_port_c(pc88pio_sub, SIG_I8255_PORT_C, 0xf0, -4);
168 pc88pio->clear_ports_by_cmdreg = true;
169 pc88pio_sub->set_context_port_a(pc88pio, SIG_I8255_PORT_B, 0xff, 0);
170 pc88pio_sub->set_context_port_b(pc88pio, SIG_I8255_PORT_A, 0xff, 0);
171 pc88pio_sub->set_context_port_c(pc88pio, SIG_I8255_PORT_C, 0x0f, 4);
172 pc88pio_sub->set_context_port_c(pc88pio, SIG_I8255_PORT_C, 0xf0, -4);
173 pc88pio_sub->clear_ports_by_cmdreg = true;
174 pc88fdc_sub->set_context_irq(pc88cpu_sub, SIG_CPU_IRQ, 1);
175 pc88cpu_sub->set_context_mem(pc88sub);
176 pc88cpu_sub->set_context_io(pc88sub);
177 pc88cpu_sub->set_context_intr(pc88sub);
179 pc88cpu_sub->set_context_debugger(new DEBUGGER(this, emu));
182 #ifdef SUPPORT_PC88_PCG8100
183 pc88pit->set_context_ch0(pc88pcm0, SIG_PCM1BIT_SIGNAL, 1);
184 pc88pit->set_context_ch1(pc88pcm1, SIG_PCM1BIT_SIGNAL, 1);
185 pc88pit->set_context_ch2(pc88pcm2, SIG_PCM1BIT_SIGNAL, 1);
186 pc88pit->set_constant_clock(0, 3993624);
187 pc88pit->set_constant_clock(1, 3993624);
188 pc88pit->set_constant_clock(2, 3993624);
191 // initialize all devices
192 for(DEVICE* device = first_device; device; device = device->next_device) {
193 device->initialize();
199 // delete all devices
200 for(DEVICE* device = first_device; device;) {
201 DEVICE *next_device = device->next_device;
204 device = next_device;
208 DEVICE* VM::get_device(int id)
210 for(DEVICE* device = first_device; device; device = device->next_device) {
211 if(device->this_device_id == id) {
218 // ----------------------------------------------------------------------------
219 // drive virtual machine
220 // ----------------------------------------------------------------------------
225 for(DEVICE* device = first_device; device; device = device->next_device) {
228 for(DEVICE* device = first_device; device; device = device->next_device) {
232 // initial device settings
233 pc88opn->SetReg(0x29, 3); // for Misty Blue
234 pc88pio->write_signal(SIG_I8255_PORT_C, 0, 0xff);
235 pc88pio_sub->write_signal(SIG_I8255_PORT_C, 0, 0xff);
243 double VM::frame_rate()
245 return pc88event->frame_rate();
248 // ----------------------------------------------------------------------------
250 // ----------------------------------------------------------------------------
253 DEVICE *VM::get_cpu(int index)
257 } else if(index == 1) {
264 // ----------------------------------------------------------------------------
266 // ----------------------------------------------------------------------------
268 void VM::draw_screen()
273 int VM::access_lamp()
275 return pc88fdc_sub->read_signal(0);
278 // ----------------------------------------------------------------------------
280 // ----------------------------------------------------------------------------
282 void VM::initialize_sound(int rate, int samples)
284 // init sound manager
285 pc88event->initialize_sound(rate, samples);
288 #ifdef SUPPORT_PC88_OPNA
289 if(pc88opn->is_ym2608) {
290 pc88opn->init(rate, 7987248, samples, 0, 0);
293 pc88opn->init(rate, 3993624, samples, 0, 0);
294 #ifdef SUPPORT_PC88_SB2
295 if(pc88sb2 != NULL) {
296 #ifdef SUPPORT_PC88_OPNA
297 if(pc88sb2->is_ym2608) {
298 pc88sb2->init(rate, 7987248, samples, 0, 0);
301 pc88sb2->init(rate, 3993624, samples, 0, 0);
304 pc88pcm->init(rate, 8000);
305 #ifdef SUPPORT_PC88_PCG8100
306 pc88pcm0->init(rate, 8000);
307 pc88pcm1->init(rate, 8000);
308 pc88pcm2->init(rate, 8000);
312 uint16* VM::create_sound(int* extra_frames)
314 return pc88event->create_sound(extra_frames);
317 int VM::sound_buffer_ptr()
319 return pc88event->sound_buffer_ptr();
322 // ----------------------------------------------------------------------------
324 // ----------------------------------------------------------------------------
326 void VM::key_down(int code, bool repeat)
328 pc88->key_down(code, repeat);
331 void VM::key_up(int code)
335 // ----------------------------------------------------------------------------
337 // ----------------------------------------------------------------------------
339 void VM::open_disk(int drv, const _TCHAR* file_path, int bank)
341 pc88fdc_sub->open_disk(drv, file_path, bank);
344 void VM::close_disk(int drv)
346 pc88fdc_sub->close_disk(drv);
349 bool VM::disk_inserted(int drv)
351 return pc88fdc_sub->disk_inserted(drv);
354 void VM::set_disk_protected(int drv, bool value)
356 pc88fdc_sub->set_disk_protected(drv, value);
359 bool VM::get_disk_protected(int drv)
361 return pc88fdc_sub->get_disk_protected(drv);
364 void VM::play_tape(const _TCHAR* file_path)
366 pc88->play_tape(file_path);
369 void VM::rec_tape(const _TCHAR* file_path)
371 pc88->rec_tape(file_path);
374 void VM::close_tape()
379 bool VM::tape_inserted()
381 return pc88->tape_inserted();
386 // return event->now_skip();
387 return pc88->now_skip();
390 void VM::update_config()
394 #ifdef USE_MULTIPLE_SOUNDCARDS
395 vol1 = vol2 = (config.sound_device_level[1] + 32768) >> 8; // Card1
396 pc88opn->write_signal(SIG_YM2203_LVOLUME, vol1, 0xffffffff); // OPN: LEFT
397 pc88opn->write_signal(SIG_YM2203_RVOLUME, vol2, 0xffffffff); // OPN: RIGHT
398 # ifdef SUPPORT_PC88_SB2
399 if(pc88sb2 != NULL) {
400 vol1 = vol2 = (config.sound_device_level[2] + 32768) >> 8; // Card2
401 pc88sb2->write_signal(SIG_YM2203_LVOLUME, vol1, 0xffffffff); // OPN: LEFT
402 pc88sb2->write_signal(SIG_YM2203_RVOLUME, vol2, 0xffffffff); // OPN: RIGHT
406 if(boot_mode != config.boot_mode) {
407 // boot mode is changed !!!
408 boot_mode = config.boot_mode;
411 for(DEVICE* device = first_device; device; device = device->next_device) {
412 device->update_config();
415 #ifdef SUPPORT_PC88_HIGH_CLOCK
416 pc88event->set_cpu_clock(pc88cpu, (config.cpu_type != 0) ? 3993624 : 7987248);
421 #define STATE_VERSION 4
423 void VM::save_state(FILEIO* state_fio)
425 state_fio->FputUint32(STATE_VERSION);
427 for(DEVICE* device = first_device; device; device = device->next_device) {
428 device->save_state(state_fio);
430 state_fio->FputInt32(boot_mode);
433 bool VM::load_state(FILEIO* state_fio)
435 if(state_fio->FgetUint32() != STATE_VERSION) {
438 for(DEVICE* device = first_device; device; device = device->next_device) {
439 if(!device->load_state(state_fio)) {
443 boot_mode = state_fio->FgetInt32();