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"
23 #include "../prnfile.h"
25 #include "../upd4991a.h"
27 #include "../upd1990a.h"
29 #include "../upd71071.h"
30 #include "../upd765a.h"
33 #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 I286(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 if(config.printer_device_type == 0) {
72 printer = new PRNFILE(this, emu);
77 bios = new BIOS(this, emu);
78 calendar = new CALENDAR(this, emu);
79 floppy = new FLOPPY(this, emu);
80 keyboard = new KEYBOARD(this, emu);
81 memory = new MEMORY(this, emu);
82 note = new NOTE(this, emu);
85 event->set_context_cpu(cpu);
86 event->set_context_sound(beep);
88 //??? sio_rs->set_context_rxrdy(pic, SIG_I8259_IR4, 1);
89 sio_kbd->set_context_rxrdy(pic, SIG_I8259_IR1, 1);
90 // sio_kbd->set_context_out(keyboard, SIG_KEYBOARD_RECV);
91 pit->set_context_ch0(pic, SIG_I8259_IR0, 1);
92 pit->set_context_ch1(pic, SIG_I8259_IR2, 1);
94 pit->set_constant_clock(0, 2457600);
95 pit->set_constant_clock(1, 2457600);
96 pit->set_constant_clock(2, 2457600);
98 pit->set_constant_clock(0, 1996800);
99 pit->set_constant_clock(1, 300); // ???
100 pit->set_constant_clock(2, 1996800);
102 pio_sys->set_context_port_c(beep, SIG_BEEP_MUTE, 8, 0);
103 pio_prn->set_context_port_a(printer, SIG_PRINTER_DATA, 0xff, 0);
104 pio_prn->set_context_port_c(printer, SIG_PRINTER_STROBE, 0x80, 0);
105 pic->set_context_cpu(cpu);
107 rtc->set_context_dout(pio_sys, SIG_I8255_PORT_B, 1);
109 dma->set_context_memory(memory);
110 dma->set_context_ch2(fdc); // 1MB
111 dma->set_context_ch3(fdc); // 640KB
112 fdc->set_context_irq(pic, SIG_I8259_IR6, 1);
113 fdc->set_context_drq(dma, SIG_UPD71071_CH3, 1);
114 fdc->raise_irq_when_media_changed = true;
116 bios->set_context_fdc(fdc);
117 calendar->set_context_rtc(rtc);
118 floppy->set_context_fdc(fdc);
119 keyboard->set_context_sio(sio_kbd);
120 note->set_context_pic(pic);
123 cpu->set_context_bios(bios);
124 cpu->set_context_mem(memory);
125 cpu->set_context_io(io);
126 cpu->set_context_intr(pic);
127 #ifdef SINGLE_MODE_DMA
128 cpu->set_context_dma(dma);
131 cpu->set_context_debugger(new DEBUGGER(this, emu));
135 io->set_iomap_alias_rw(0x00, pic, 0);
136 io->set_iomap_alias_rw(0x02, pic, 1);
138 io->set_iomap_range_rw(0x22, 0x23, calendar);
140 io->set_iomap_single_w(0x20, calendar);
142 io->set_iomap_alias_rw(0x30, sio_rs, 0);
143 io->set_iomap_alias_rw(0x32, sio_rs, 1);
144 io->set_iomap_alias_rw(0x31, pio_sys, 0);
145 io->set_iomap_alias_rw(0x33, pio_sys, 1);
146 io->set_iomap_alias_rw(0x35, pio_sys, 2);
147 io->set_iomap_alias_rw(0x37, pio_sys, 3);
148 io->set_iomap_alias_rw(0x40, pio_prn, 0);
149 io->set_iomap_alias_rw(0x42, pio_prn, 1);
150 io->set_iomap_alias_rw(0x44, pio_prn, 2);
151 io->set_iomap_alias_rw(0x46, pio_prn, 3);
152 io->set_iomap_alias_rw(0x41, sio_kbd, 0);
153 io->set_iomap_alias_rw(0x43, sio_kbd, 1);
154 io->set_iomap_alias_rw(0x71, pit, 0);
155 io->set_iomap_alias_rw(0x73, pit, 1);
156 io->set_iomap_alias_rw(0x75, pit, 2);
157 io->set_iomap_alias_rw(0x77, pit, 3);
158 #if defined(_PC98LT) || defined(DOCKING_STATION)
159 io->set_iomap_single_r(0xc8, floppy);
160 io->set_iomap_single_rw(0xca, floppy);
161 io->set_iomap_single_rw(0xcc, floppy);
162 io->set_iomap_single_rw(0xbe, floppy);
164 io->set_iomap_range_rw(0xe0, 0xef, dma);
165 io->set_iomap_single_w(0x8e1, memory);
166 io->set_iomap_single_w(0x8e3, memory);
167 io->set_iomap_single_w(0x8e5, memory);
168 io->set_iomap_single_w(0x8e7, memory);
169 io->set_iomap_single_rw(0x0c10, memory);
170 io->set_iomap_single_w(0x0e8e, memory);
171 io->set_iomap_single_w(0x1e8e, memory);
172 io->set_iomap_single_rw(0x4c10, memory);
173 io->set_iomap_single_rw(0x8c10, memory);
174 io->set_iomap_single_rw(0xcc10, memory);
175 io->set_iomap_single_rw(0x0810, note);
176 io->set_iomap_single_rw(0x0812, note);
177 io->set_iomap_single_r(0x0f8e, note);
178 io->set_iomap_single_r(0x5e8e, note);
179 io->set_iomap_single_rw(0x8810, note);
180 io->set_iomap_single_w(0xc810, note);
182 // initialize all devices
183 for(DEVICE* device = first_device; device; device = device->next_device) {
184 device->initialize();
190 // delete all devices
191 for(DEVICE* device = first_device; device;) {
192 DEVICE *next_device = device->next_device;
195 device = next_device;
199 DEVICE* VM::get_device(int id)
201 for(DEVICE* device = first_device; device; device = device->next_device) {
202 if(device->this_device_id == id) {
209 // ----------------------------------------------------------------------------
210 // drive virtual machine
211 // ----------------------------------------------------------------------------
216 for(DEVICE* device = first_device; device; device = device->next_device) {
220 // initial device settings
221 pio_sys->write_signal(SIG_I8255_PORT_A, 0xe3, 0xff);
222 pio_sys->write_signal(SIG_I8255_PORT_B, 0xe0, 0xff);
224 pio_prn->write_signal(SIG_I8255_PORT_B, 0xde, 0xff);
226 pio_prn->write_signal(SIG_I8255_PORT_B, 0xfc, 0xff);
228 beep->write_signal(SIG_BEEP_ON, 1, 1);
229 beep->write_signal(SIG_BEEP_MUTE, 1, 1);
237 // ----------------------------------------------------------------------------
239 // ----------------------------------------------------------------------------
242 DEVICE *VM::get_cpu(int index)
251 // ----------------------------------------------------------------------------
253 // ----------------------------------------------------------------------------
255 void VM::draw_screen()
257 memory->draw_screen();
260 int VM::access_lamp()
262 uint32 status = fdc->read_signal(0);
263 return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
266 // ----------------------------------------------------------------------------
268 // ----------------------------------------------------------------------------
270 void VM::initialize_sound(int rate, int samples)
272 // init sound manager
273 event->initialize_sound(rate, samples);
276 beep->init(rate, 2400, 8000);
279 uint16* VM::create_sound(int* extra_frames)
281 return event->create_sound(extra_frames);
284 int VM::sound_buffer_ptr()
286 return event->sound_buffer_ptr();
289 // ----------------------------------------------------------------------------
291 // ----------------------------------------------------------------------------
293 void VM::key_down(int code, bool repeat)
295 keyboard->key_down(code);
298 void VM::key_up(int code)
300 keyboard->key_up(code);
303 // ----------------------------------------------------------------------------
305 // ----------------------------------------------------------------------------
307 void VM::open_disk(int drv, const _TCHAR* file_path, int bank)
309 fdc->open_disk(drv, file_path, bank);
312 void VM::close_disk(int drv)
314 fdc->close_disk(drv);
317 bool VM::disk_inserted(int drv)
319 return fdc->disk_inserted(drv);
322 void VM::set_disk_protected(int drv, bool value)
324 fdc->set_disk_protected(drv, value);
327 bool VM::get_disk_protected(int drv)
329 return fdc->get_disk_protected(drv);
334 return event->now_skip();
337 void VM::update_config()
339 for(DEVICE* device = first_device; device; device = device->next_device) {
340 device->update_config();
344 #define STATE_VERSION 3
346 void VM::save_state(FILEIO* state_fio)
348 state_fio->FputUint32(STATE_VERSION);
350 for(DEVICE* device = first_device; device; device = device->next_device) {
351 device->save_state(state_fio);
355 bool VM::load_state(FILEIO* state_fio)
357 if(state_fio->FgetUint32() != STATE_VERSION) {
360 for(DEVICE* device = first_device; device; device = device->next_device) {
361 if(!device->load_state(state_fio)) {