2 NEC PC-8801MA Emulator 'ePC-8801MA'
\r
3 NEC PC-8001mkIISR Emulator 'ePC-8001mkIISR'
\r
5 Author : Takeda.Toshiya
\r
12 #include "../../emu.h"
\r
13 #include "../device.h"
\r
14 #include "../event.h"
\r
16 #include "../beep.h"
\r
17 #include "../i8251.h"
\r
18 #include "../i8255.h"
\r
19 #include "../pcm1bit.h"
\r
20 #include "../upd1990a.h"
\r
21 #include "../ym2203.h"
\r
24 #include "../disk.h"
\r
25 #include "../pc80s31k.h"
\r
26 #include "../upd765a.h"
\r
29 #include "../debugger.h"
\r
32 #ifdef SUPPORT_PC88_PCG8100
\r
33 #include "../i8253.h"
\r
38 #include "../../fileio.h"
\r
40 // ----------------------------------------------------------------------------
\r
42 // ----------------------------------------------------------------------------
\r
44 VM::VM(EMU* parent_emu) : emu(parent_emu)
\r
47 boot_mode = config.boot_mode;
\r
50 first_device = last_device = NULL;
\r
51 dummy = new DEVICE(this, emu); // must be 1st device
\r
53 pc88event = new EVENT(this, emu);
\r
54 // pc88event->set_frames_per_sec(60);
\r
55 // pc88event->set_lines_per_frame(260);
\r
57 pc88 = new PC88(this, emu);
\r
58 // pc88->set_context_event_manager(pc88event);
\r
59 pc88beep = new BEEP(this, emu);
\r
60 // pc88beep->set_context_event_manager(pc88event);
\r
61 pc88sio = new I8251(this, emu);
\r
62 // pc88sio->set_context_event_manager(pc88event);
\r
63 pc88pio = new I8255(this, emu);
\r
64 // pc88pio->set_context_event_manager(pc88event);
\r
65 pc88pcm = new PCM1BIT(this, emu);
\r
66 // pc88pcm->set_context_event_manager(pc88event);
\r
67 pc88rtc = new UPD1990A(this, emu);
\r
68 // pc88rtc->set_context_event_manager(pc88event);
\r
69 pc88opn = new YM2203(this, emu);
\r
70 // pc88opn->set_context_event_manager(pc88event);
\r
71 pc88cpu = new Z80(this, emu);
\r
72 // pc88cpu->set_context_event_manager(pc88event);
\r
74 pc88sub = new PC80S31K(this, emu);
\r
75 // pc88sub->set_context_event_manager(pc88event);
\r
76 pc88pio_sub = new I8255(this, emu);
\r
77 // pc88pio_sub->set_context_event_manager(pc88event);
\r
78 pc88fdc_sub = new UPD765A(this, emu);
\r
79 // pc88fdc_sub->set_context_event_manager(pc88event);
\r
80 pc88cpu_sub = new Z80(this, emu);
\r
81 // pc88cpu_sub->set_context_event_manager(pc88event);
\r
83 #ifdef SUPPORT_PC88_PCG8100
\r
84 pc88pit = new I8253(this, emu);
\r
85 // pc88pit->set_context_event_manager(pc88event);
\r
86 pc88pcm0 = new PCM1BIT(this, emu);
\r
87 // pc88pcm->set_context_event_manager(pc88event);
\r
88 pc88pcm1 = new PCM1BIT(this, emu);
\r
89 // pc88pcm->set_context_event_manager(pc88event);
\r
90 pc88pcm2 = new PCM1BIT(this, emu);
\r
91 // pc88pcm->set_context_event_manager(pc88event);
\r
94 #ifdef SUPPORT_PC88_HIGH_CLOCK
\r
95 pc88event->set_context_cpu(pc88cpu, (config.cpu_type != 0) ? 3993624 : 7987248);
\r
97 pc88event->set_context_cpu(pc88cpu, 3993624);
\r
99 pc88event->set_context_cpu(pc88cpu_sub, 3993624);
\r
100 pc88event->set_context_sound(pc88beep);
\r
101 pc88event->set_context_sound(pc88opn);
\r
102 pc88event->set_context_sound(pc88pcm);
\r
103 #ifdef SUPPORT_PC88_PCG8100
\r
104 pc88event->set_context_sound(pc88pcm0);
\r
105 pc88event->set_context_sound(pc88pcm1);
\r
106 pc88event->set_context_sound(pc88pcm2);
\r
109 pc88->set_context_beep(pc88beep);
\r
110 pc88->set_context_cpu(pc88cpu);
\r
111 pc88->set_context_opn(pc88opn);
\r
112 pc88->set_context_pcm(pc88pcm);
\r
113 pc88->set_context_pio(pc88pio);
\r
114 pc88->set_context_rtc(pc88rtc);
\r
115 pc88->set_context_sio(pc88sio);
\r
116 #ifdef SUPPORT_PC88_PCG8100
\r
117 pc88->set_context_pcg_pit(pc88pit);
\r
118 pc88->set_context_pcg_pcm0(pc88pcm0);
\r
119 pc88->set_context_pcg_pcm1(pc88pcm1);
\r
120 pc88->set_context_pcg_pcm2(pc88pcm2);
\r
122 pc88cpu->set_context_mem(pc88);
\r
123 pc88cpu->set_context_io(pc88);
\r
124 pc88cpu->set_context_intr(pc88);
\r
125 #ifdef USE_DEBUGGER
\r
126 pc88cpu->set_context_debugger(new DEBUGGER(this, emu));
\r
128 pc88opn->set_context_irq(pc88, SIG_PC88_SOUND_IRQ, 1);
\r
129 pc88sio->set_context_rxrdy(pc88, SIG_PC88_USART_IRQ, 1);
\r
130 pc88sio->set_context_out(pc88, SIG_PC88_USART_OUT);
\r
132 pc88sub->set_context_cpu(pc88cpu_sub);
\r
133 pc88sub->set_context_fdc(pc88fdc_sub);
\r
134 pc88sub->set_context_pio(pc88pio_sub);
\r
135 pc88pio->set_context_port_a(pc88pio_sub, SIG_I8255_PORT_B, 0xff, 0);
\r
136 pc88pio->set_context_port_b(pc88pio_sub, SIG_I8255_PORT_A, 0xff, 0);
\r
137 pc88pio->set_context_port_c(pc88pio_sub, SIG_I8255_PORT_C, 0x0f, 4);
\r
138 pc88pio->set_context_port_c(pc88pio_sub, SIG_I8255_PORT_C, 0xf0, -4);
\r
139 pc88pio->clear_ports_by_cmdreg = true;
\r
140 pc88pio_sub->set_context_port_a(pc88pio, SIG_I8255_PORT_B, 0xff, 0);
\r
141 pc88pio_sub->set_context_port_b(pc88pio, SIG_I8255_PORT_A, 0xff, 0);
\r
142 pc88pio_sub->set_context_port_c(pc88pio, SIG_I8255_PORT_C, 0x0f, 4);
\r
143 pc88pio_sub->set_context_port_c(pc88pio, SIG_I8255_PORT_C, 0xf0, -4);
\r
144 pc88pio_sub->clear_ports_by_cmdreg = true;
\r
145 pc88fdc_sub->set_context_irq(pc88cpu_sub, SIG_CPU_IRQ, 1);
\r
146 pc88cpu_sub->set_context_mem(pc88sub);
\r
147 pc88cpu_sub->set_context_io(pc88sub);
\r
148 pc88cpu_sub->set_context_intr(pc88sub);
\r
149 #ifdef USE_DEBUGGER
\r
150 pc88cpu_sub->set_context_debugger(new DEBUGGER(this, emu));
\r
153 #ifdef SUPPORT_PC88_PCG8100
\r
154 pc88pit->set_context_ch0(pc88pcm0, SIG_PCM1BIT_SIGNAL, 1);
\r
155 pc88pit->set_context_ch1(pc88pcm1, SIG_PCM1BIT_SIGNAL, 1);
\r
156 pc88pit->set_context_ch2(pc88pcm2, SIG_PCM1BIT_SIGNAL, 1);
\r
157 pc88pit->set_constant_clock(0, 3993624);
\r
158 pc88pit->set_constant_clock(1, 3993624);
\r
159 pc88pit->set_constant_clock(2, 3993624);
\r
162 // initialize all devices
\r
163 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
164 device->initialize();
\r
170 // delete all devices
\r
171 for(DEVICE* device = first_device; device;) {
\r
172 DEVICE *next_device = device->next_device;
\r
175 device = next_device;
\r
179 DEVICE* VM::get_device(int id)
\r
181 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
182 if(device->this_device_id == id) {
\r
189 // ----------------------------------------------------------------------------
\r
190 // drive virtual machine
\r
191 // ----------------------------------------------------------------------------
\r
195 // reset all devices
\r
196 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
199 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
203 // initial device settings
\r
204 pc88opn->SetReg(0x29, 3); // for Misty Blue
\r
205 pc88pio->write_signal(SIG_I8255_PORT_C, 0, 0xff);
\r
206 pc88pio_sub->write_signal(SIG_I8255_PORT_C, 0, 0xff);
\r
211 pc88event->drive();
\r
214 double VM::frame_rate()
\r
216 return pc88event->frame_rate();
\r
219 // ----------------------------------------------------------------------------
\r
221 // ----------------------------------------------------------------------------
\r
223 #ifdef USE_DEBUGGER
\r
224 DEVICE *VM::get_cpu(int index)
\r
228 } else if(index == 1) {
\r
229 return pc88cpu_sub;
\r
235 // ----------------------------------------------------------------------------
\r
237 // ----------------------------------------------------------------------------
\r
239 void VM::draw_screen()
\r
241 pc88->draw_screen();
\r
244 int VM::access_lamp()
\r
246 return pc88fdc_sub->read_signal(0);
\r
249 // ----------------------------------------------------------------------------
\r
251 // ----------------------------------------------------------------------------
\r
253 void VM::initialize_sound(int rate, int samples)
\r
255 // init sound manager
\r
256 pc88event->initialize_sound(rate, samples);
\r
259 pc88beep->init(rate, 2400, 8000);
\r
261 pc88opn->init(rate, 7987248, samples, 0, 0);
\r
263 pc88opn->init(rate, 3993624, samples, 0, 0);
\r
265 pc88pcm->init(rate, 8000);
\r
266 #ifdef SUPPORT_PC88_PCG8100
\r
267 pc88pcm0->init(rate, 8000);
\r
268 pc88pcm1->init(rate, 8000);
\r
269 pc88pcm2->init(rate, 8000);
\r
273 uint16* VM::create_sound(int* extra_frames)
\r
275 return pc88event->create_sound(extra_frames);
\r
278 int VM::sound_buffer_ptr()
\r
280 return pc88event->sound_buffer_ptr();
\r
283 // ----------------------------------------------------------------------------
\r
285 // ----------------------------------------------------------------------------
\r
287 void VM::key_down(int code, bool repeat)
\r
289 pc88->key_down(code, repeat);
\r
292 void VM::key_up(int code)
\r
296 // ----------------------------------------------------------------------------
\r
298 // ----------------------------------------------------------------------------
\r
300 void VM::open_disk(int drv, _TCHAR* file_path, int offset)
\r
302 pc88fdc_sub->open_disk(drv, file_path, offset);
\r
305 void VM::close_disk(int drv)
\r
307 pc88fdc_sub->close_disk(drv);
\r
310 bool VM::disk_inserted(int drv)
\r
312 return pc88fdc_sub->disk_inserted(drv);
\r
314 void VM::write_protect_fd(int drv, bool flag)
\r
316 pc88fdc_sub->write_protect_fd(drv, flag);
\r
318 bool VM::is_write_protect_fd(int drv)
\r
320 return pc88fdc_sub->is_write_protect_fd(drv);
\r
323 void VM::play_tape(_TCHAR* file_path)
\r
325 pc88->play_tape(file_path);
\r
328 void VM::rec_tape(_TCHAR* file_path)
\r
330 pc88->rec_tape(file_path);
\r
333 void VM::close_tape()
\r
335 pc88->close_tape();
\r
338 bool VM::tape_inserted()
\r
340 return pc88->tape_inserted();
\r
343 bool VM::now_skip()
\r
345 // return event->now_skip();
\r
346 return pc88->now_skip();
\r
349 void VM::update_config()
\r
351 if(boot_mode != config.boot_mode) {
\r
352 // boot mode is changed !!!
\r
353 boot_mode = config.boot_mode;
\r
356 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
357 device->update_config();
\r
362 #define STATE_VERSION 1
\r
364 void VM::save_state(FILEIO* state_fio)
\r
366 state_fio->FputUint32(STATE_VERSION);
\r
368 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
369 device->save_state(state_fio);
\r
371 state_fio->FputInt32(boot_mode);
\r
374 bool VM::load_state(FILEIO* state_fio)
\r
376 if(state_fio->FgetUint32() != STATE_VERSION) {
\r
379 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
380 if(!device->load_state(state_fio)) {
\r
384 boot_mode = state_fio->FgetInt32();
\r