2 NEC PC-100 Emulator 'ePC-100'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
23 #include "../memory.h"
24 #include "../msm58321.h"
25 #include "../pcm1bit.h"
26 #include "../upd765a.h"
29 #include "../debugger.h"
36 #include "../../fileio.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 VM::VM(EMU* parent_emu) : emu(parent_emu)
45 first_device = last_device = NULL;
46 dummy = new DEVICE(this, emu); // must be 1st device
47 event = new EVENT(this, emu); // must be 2nd device
49 and = new AND(this, emu);
50 beep = new BEEP(this, emu);
51 sio = new I8251(this, emu);
52 pio0 = new I8255(this, emu);
53 pio1 = new I8255(this, emu);
54 pic = new I8259(this, emu);
55 cpu = new I286(this, emu);
56 io = new IO(this, emu);
57 memory = new MEMORY(this, emu);
58 rtc = new MSM58321(this, emu);
59 pcm = new PCM1BIT(this, emu);
60 fdc = new UPD765A(this, emu);
62 crtc = new CRTC(this, emu);
63 ioctrl = new IOCTRL(this, emu);
64 kanji = new KANJI(this, emu);
67 event->set_context_cpu(cpu);
68 event->set_context_sound(beep);
69 event->set_context_sound(pcm);
71 and->set_context_out(cpu, SIG_CPU_NMI, 1);
72 and->set_mask(SIG_AND_BIT_0 | SIG_AND_BIT_1);
73 sio->set_context_rxrdy(pic, SIG_I8259_IR1, 1);
74 pio0->set_context_port_a(rtc, SIG_MSM58321_READ, 1, 0);
75 pio0->set_context_port_a(rtc, SIG_MSM58321_WRITE, 2, 0);
76 pio0->set_context_port_a(rtc, SIG_MSM58321_ADDR_WRITE, 4, 0);
77 pio0->set_context_port_c(rtc, SIG_MSM58321_DATA, 0x0f, 0);
78 pio1->set_context_port_a(crtc, SIG_CRTC_BITMASK_LOW, 0xff, 0);
79 pio1->set_context_port_b(crtc, SIG_CRTC_BITMASK_HIGH, 0xff, 0);
80 pio1->set_context_port_c(crtc, SIG_CRTC_VRAM_PLANE, 0x3f, 0);
81 pio1->set_context_port_c(and, SIG_AND_BIT_0, 0x80, 0);
82 pio1->set_context_port_c(ioctrl, SIG_IOCTRL_RESET, 0x40, 0);
83 pic->set_context_cpu(cpu);
84 rtc->set_context_data(pio0, SIG_I8255_PORT_C, 0x0f, 0);
85 rtc->set_context_busy(pio0, SIG_I8255_PORT_C, 0x10);
86 fdc->set_context_irq(cpu, SIG_CPU_NMI, 1);
87 fdc->set_context_drq(and, SIG_AND_BIT_1, 1);
89 crtc->set_context_pic(pic);
90 ioctrl->set_context_pic(pic);
91 ioctrl->set_context_fdc(fdc);
92 ioctrl->set_context_beep(beep);
93 ioctrl->set_context_pcm(pcm);
96 cpu->set_context_mem(memory);
97 cpu->set_context_io(io);
98 cpu->set_context_intr(pic);
100 cpu->set_context_debugger(new DEBUGGER(this, emu));
104 memset(ram, 0, sizeof(ram));
105 memset(ipl, 0xff, sizeof(ipl));
107 memory->read_bios(_T("IPL.ROM"), ipl, sizeof(ipl));
109 memory->set_memory_rw(0x00000, 0xbffff, ram);
110 memory->set_memory_mapped_io_rw(0xc0000, 0xdffff, crtc);
111 memory->set_memory_r(0xf8000, 0xfffff, ipl);
114 io->set_iomap_alias_rw(0x00, pic, 0);
115 io->set_iomap_alias_rw(0x02, pic, 1);
116 // io->set_iomap_alias_rw(0x04, dma, 0);
117 // io->set_iomap_alias_rw(0x06, dma, 1);
118 io->set_iomap_alias_r(0x08, fdc, 0);
119 io->set_iomap_alias_rw(0x0a, fdc, 1);
120 io->set_iomap_alias_rw(0x10, pio0, 0);
121 io->set_iomap_alias_rw(0x12, pio0, 1);
122 io->set_iomap_alias_rw(0x14, pio0, 2);
123 io->set_iomap_alias_rw(0x16, pio0, 3);
124 io->set_iomap_alias_rw(0x18, pio1, 0);
125 io->set_iomap_alias_rw(0x1a, pio1, 1);
126 io->set_iomap_alias_rw(0x1c, pio1, 2);
127 io->set_iomap_alias_rw(0x1e, pio1, 3);
128 io->set_iomap_single_r(0x20, ioctrl);
129 io->set_iomap_single_rw(0x22, ioctrl);
130 io->set_iomap_single_w(0x24, ioctrl);
131 io->set_iomap_alias_rw(0x28, sio, 0);
132 io->set_iomap_alias_rw(0x2a, sio, 1);
133 io->set_iomap_single_rw(0x30, crtc);
134 io->set_iomap_single_rw(0x38, crtc);
135 io->set_iomap_single_rw(0x3a, crtc);
136 io->set_iomap_single_rw(0x3c, crtc);
137 io->set_iomap_single_rw(0x3e, crtc);
138 for(int i = 0x40; i < 0x62; i++) {
139 io->set_iomap_single_rw(i, crtc);
141 io->set_iomap_single_rw(0x80, kanji);
142 io->set_iomap_single_rw(0x81, kanji);
143 io->set_iomap_single_w(0x84, kanji);
144 io->set_iomap_single_w(0x86, kanji);
146 // initialize all devices
147 for(DEVICE* device = first_device; device; device = device->next_device) {
148 device->initialize();
150 for(int i = 0; i < 4; i++) {
151 fdc->set_drive_type(i, DRIVE_TYPE_2D);
157 // delete all devices
158 for(DEVICE* device = first_device; device;) {
159 DEVICE *next_device = device->next_device;
162 device = next_device;
166 DEVICE* VM::get_device(int id)
168 for(DEVICE* device = first_device; device; device = device->next_device) {
169 if(device->this_device_id == id) {
176 // ----------------------------------------------------------------------------
177 // drive virtual machine
178 // ----------------------------------------------------------------------------
183 for(DEVICE* device = first_device; device; device = device->next_device) {
193 // ----------------------------------------------------------------------------
195 // ----------------------------------------------------------------------------
198 DEVICE *VM::get_cpu(int index)
207 // ----------------------------------------------------------------------------
209 // ----------------------------------------------------------------------------
211 void VM::draw_screen()
216 int VM::access_lamp()
218 uint32 status = fdc->read_signal(0);
219 return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
222 // ----------------------------------------------------------------------------
224 // ----------------------------------------------------------------------------
226 void VM::initialize_sound(int rate, int samples)
228 // init sound manager
229 event->initialize_sound(rate, samples);
232 beep->init(rate, 2400, 8000);
233 pcm->init(rate, 8000);
236 uint16* VM::create_sound(int* extra_frames)
238 return event->create_sound(extra_frames);
241 int VM::sound_buffer_ptr()
243 return event->sound_buffer_ptr();
246 // ----------------------------------------------------------------------------
248 // ----------------------------------------------------------------------------
250 void VM::key_down(int code, bool repeat)
252 ioctrl->key_down(code);
255 void VM::key_up(int code)
257 ioctrl->key_up(code);
260 // ----------------------------------------------------------------------------
262 // ----------------------------------------------------------------------------
264 void VM::open_disk(int drv, _TCHAR* file_path, int offset)
266 fdc->open_disk(drv, file_path, offset);
269 void VM::close_disk(int drv)
271 fdc->close_disk(drv);
274 bool VM::disk_inserted(int drv)
276 return fdc->disk_inserted(drv);
281 return event->now_skip();
284 void VM::update_config()
286 for(DEVICE* device = first_device; device; device = device->next_device) {
287 device->update_config();
291 #define STATE_VERSION 1
293 void VM::save_state(FILEIO* state_fio)
295 state_fio->FputUint32(STATE_VERSION);
297 for(DEVICE* device = first_device; device; device = device->next_device) {
298 device->save_state(state_fio);
300 state_fio->Fwrite(ram, sizeof(ram), 1);
303 bool VM::load_state(FILEIO* state_fio)
305 if(state_fio->FgetUint32() != STATE_VERSION) {
308 for(DEVICE* device = first_device; device; device = device->next_device) {
309 if(!device->load_state(state_fio)) {
313 state_fio->Fread(ram, sizeof(ram), 1);