2 NEC PC-98LT Emulator 'ePC-98LT'
3 NEC PC-98HA Emulator 'eHANDY98'
5 Author : Takeda.Toshiya
12 #include "../../emu.h"
13 #include "../device.h"
24 #include "../upd4991a.h"
26 #include "../upd1990a.h"
28 #include "../upd71071.h"
29 #include "../upd765a.h"
32 #include "../debugger.h"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 VM::VM(EMU* parent_emu) : emu(parent_emu)
50 first_device = last_device = NULL;
51 dummy = new DEVICE(this, emu); // must be 1st device
52 event = new EVENT(this, emu); // must be 2nd device
54 beep = new BEEP(this, emu);
55 sio_rs = new I8251(this, emu); // for rs232c
56 sio_kbd = new I8251(this, emu); // for keyboard
57 pit = new I8253(this, emu); // V50 internal
58 pio_sys = new I8255(this, emu); // for system port
59 pio_prn = new I8255(this, emu); // for printer
60 pic = new I8259(this, emu); // V50 internal
61 cpu = new I86(this, emu); // V50
62 io = new IO(this, emu);
64 rtc = new UPD4991A(this, emu);
66 rtc = new UPD1990A(this, emu);
68 dma = new UPD71071(this, emu); // V50 internal
69 fdc = new UPD765A(this, emu);
71 bios = new BIOS(this, emu);
72 calendar = new CALENDAR(this, emu);
73 floppy = new FLOPPY(this, emu);
74 keyboard = new KEYBOARD(this, emu);
75 memory = new MEMORY(this, emu);
76 note = new NOTE(this, emu);
77 printer = new PRINTER(this, emu);
80 event->set_context_cpu(cpu);
81 event->set_context_sound(beep);
83 //??? sio_rs->set_context_rxrdy(pic, SIG_I8259_IR4, 1);
84 sio_kbd->set_context_rxrdy(pic, SIG_I8259_IR1, 1);
85 // sio_kbd->set_context_out(keyboard, SIG_KEYBOARD_RECV);
86 pit->set_context_ch0(pic, SIG_I8259_IR0, 1);
87 pit->set_context_ch1(pic, SIG_I8259_IR2, 1);
89 pit->set_constant_clock(0, 2457600);
90 pit->set_constant_clock(1, 2457600);
91 pit->set_constant_clock(2, 2457600);
93 pit->set_constant_clock(0, 1996800);
94 pit->set_constant_clock(1, 300); // ???
95 pit->set_constant_clock(2, 1996800);
97 pio_sys->set_context_port_c(beep, SIG_BEEP_MUTE, 8, 0);
98 pio_prn->set_context_port_a(printer, SIG_PRINTER_OUT, 0xff, 0);
99 pio_prn->set_context_port_c(printer, SIG_PRINTER_STB, 0x80, 0);
100 pic->set_context_cpu(cpu);
102 rtc->set_context_dout(pio_sys, SIG_I8255_PORT_B, 1);
104 dma->set_context_memory(memory);
105 dma->set_context_ch2(fdc); // 1MB
106 dma->set_context_ch3(fdc); // 640KB
107 fdc->set_context_irq(pic, SIG_I8259_IR6, 1);
108 fdc->set_context_drq(dma, SIG_UPD71071_CH3, 1);
109 fdc->raise_irq_when_media_changed = true;
111 bios->set_context_fdc(fdc);
112 calendar->set_context_rtc(rtc);
113 floppy->set_context_fdc(fdc);
114 keyboard->set_context_sio(sio_kbd);
115 note->set_context_pic(pic);
116 printer = new PRINTER(this, emu);
119 cpu->set_context_bios(bios);
120 cpu->set_context_mem(memory);
121 cpu->set_context_io(io);
122 cpu->set_context_intr(pic);
123 #ifdef SINGLE_MODE_DMA
124 cpu->set_context_dma(dma);
127 cpu->set_context_debugger(new DEBUGGER(this, emu));
131 io->set_iomap_alias_rw(0x00, pic, 0);
132 io->set_iomap_alias_rw(0x02, pic, 1);
134 io->set_iomap_range_rw(0x22, 0x23, calendar);
136 io->set_iomap_single_w(0x20, calendar);
138 io->set_iomap_alias_rw(0x30, sio_rs, 0);
139 io->set_iomap_alias_rw(0x32, sio_rs, 1);
140 io->set_iomap_alias_rw(0x31, pio_sys, 0);
141 io->set_iomap_alias_rw(0x33, pio_sys, 1);
142 io->set_iomap_alias_rw(0x35, pio_sys, 2);
143 io->set_iomap_alias_rw(0x37, pio_sys, 3);
144 io->set_iomap_alias_rw(0x40, pio_prn, 0);
145 io->set_iomap_alias_rw(0x42, pio_prn, 1);
146 io->set_iomap_alias_rw(0x44, pio_prn, 2);
147 io->set_iomap_alias_rw(0x46, pio_prn, 3);
148 io->set_iomap_alias_rw(0x41, sio_kbd, 0);
149 io->set_iomap_alias_rw(0x43, sio_kbd, 1);
150 io->set_iomap_alias_rw(0x71, pit, 0);
151 io->set_iomap_alias_rw(0x73, pit, 1);
152 io->set_iomap_alias_rw(0x75, pit, 2);
153 io->set_iomap_alias_rw(0x77, pit, 3);
154 #if defined(_PC98LT) || defined(DOCKING_STATION)
155 io->set_iomap_single_r(0xc8, floppy);
156 io->set_iomap_single_rw(0xca, floppy);
157 io->set_iomap_single_rw(0xcc, floppy);
158 io->set_iomap_single_rw(0xbe, floppy);
160 io->set_iomap_range_rw(0xe0, 0xef, dma);
161 io->set_iomap_single_w(0x8e1, memory);
162 io->set_iomap_single_w(0x8e3, memory);
163 io->set_iomap_single_w(0x8e5, memory);
164 io->set_iomap_single_w(0x8e7, memory);
165 io->set_iomap_single_rw(0x0c10, memory);
166 io->set_iomap_single_w(0x0e8e, memory);
167 io->set_iomap_single_w(0x1e8e, memory);
168 io->set_iomap_single_rw(0x4c10, memory);
169 io->set_iomap_single_rw(0x8c10, memory);
170 io->set_iomap_single_rw(0xcc10, memory);
171 io->set_iomap_single_rw(0x0810, note);
172 io->set_iomap_single_rw(0x0812, note);
173 io->set_iomap_single_r(0x0f8e, note);
174 io->set_iomap_single_r(0x5e8e, note);
175 io->set_iomap_single_rw(0x8810, note);
176 io->set_iomap_single_w(0xc810, note);
178 // initialize all devices
179 for(DEVICE* device = first_device; device; device = device->next_device) {
180 device->initialize();
186 // delete all devices
187 for(DEVICE* device = first_device; device;) {
188 DEVICE *next_device = device->next_device;
191 device = next_device;
195 DEVICE* VM::get_device(int id)
197 for(DEVICE* device = first_device; device; device = device->next_device) {
198 if(device->this_device_id == id) {
205 // ----------------------------------------------------------------------------
206 // drive virtual machine
207 // ----------------------------------------------------------------------------
212 for(DEVICE* device = first_device; device; device = device->next_device) {
216 // initial device settings
217 pio_sys->write_signal(SIG_I8255_PORT_A, 0xe3, 0xff);
218 pio_sys->write_signal(SIG_I8255_PORT_B, 0xe0, 0xff);
220 pio_prn->write_signal(SIG_I8255_PORT_B, 0xde, 0xff);
222 pio_prn->write_signal(SIG_I8255_PORT_B, 0xfc, 0xff);
224 beep->write_signal(SIG_BEEP_ON, 1, 1);
225 beep->write_signal(SIG_BEEP_MUTE, 1, 1);
233 // ----------------------------------------------------------------------------
235 // ----------------------------------------------------------------------------
238 DEVICE *VM::get_cpu(int index)
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
251 void VM::draw_screen()
253 memory->draw_screen();
256 int VM::access_lamp()
258 uint32 status = fdc->read_signal(0);
259 return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
262 // ----------------------------------------------------------------------------
264 // ----------------------------------------------------------------------------
266 void VM::initialize_sound(int rate, int samples)
268 // init sound manager
269 event->initialize_sound(rate, samples);
272 beep->init(rate, 2400, 8000);
275 uint16* VM::create_sound(int* extra_frames)
277 return event->create_sound(extra_frames);
280 int VM::sound_buffer_ptr()
282 return event->sound_buffer_ptr();
285 // ----------------------------------------------------------------------------
287 // ----------------------------------------------------------------------------
289 void VM::key_down(int code, bool repeat)
291 keyboard->key_down(code);
294 void VM::key_up(int code)
296 keyboard->key_up(code);
299 // ----------------------------------------------------------------------------
301 // ----------------------------------------------------------------------------
303 void VM::open_disk(int drv, _TCHAR* file_path, int bank)
305 fdc->open_disk(drv, file_path, bank);
308 void VM::close_disk(int drv)
310 fdc->close_disk(drv);
313 bool VM::disk_inserted(int drv)
315 return fdc->disk_inserted(drv);
319 void VM::set_disk_protected(int drv, bool value)
321 fdc->set_disk_protected(drv, value);
324 bool VM::get_disk_protected(int drv)
326 return fdc->get_disk_protected(drv);
331 return event->now_skip();
334 void VM::update_config()
336 for(DEVICE* device = first_device; device; device = device->next_device) {
337 device->update_config();
341 #define STATE_VERSION 1
343 void VM::save_state(FILEIO* state_fio)
345 state_fio->FputUint32(STATE_VERSION);
347 for(DEVICE* device = first_device; device; device = device->next_device) {
348 device->save_state(state_fio);
352 bool VM::load_state(FILEIO* state_fio)
354 if(state_fio->FgetUint32() != STATE_VERSION) {
357 for(DEVICE* device = first_device; device; device = device->next_device) {
358 if(!device->load_state(state_fio)) {