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"
26 #include "../pcm1bit.h"
27 #include "../upd765a.h"
30 #include "../debugger.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
44 first_device = last_device = NULL;
45 dummy = new DEVICE(this, emu); // must be 1st device
46 event = new EVENT(this, emu); // must be 2nd device
48 and_drq = new AND(this, emu);
49 beep = new BEEP(this, emu);
50 sio = new I8251(this, emu);
51 pio0 = new I8255(this, emu);
52 pio0->set_device_name(_T("8255 PIO (RTC)"));
53 pio1 = new I8255(this, emu);
54 pio1->set_device_name(_T("8255 PIO (CRTC)"));
55 pic = new I8259(this, emu);
56 cpu = new I286(this, emu);
57 io = new IO(this, emu);
58 memory = new MEMORY(this, emu);
59 rtc = new MSM58321(this, emu);
60 pcm = new PCM1BIT(this, emu);
61 fdc = new UPD765A(this, emu);
62 fdc->set_context_noise_seek(new NOISE(this, emu));
63 fdc->set_context_noise_head_down(new NOISE(this, emu));
64 fdc->set_context_noise_head_up(new NOISE(this, emu));
66 crtc = new CRTC(this, emu);
67 ioctrl = new IOCTRL(this, emu);
68 kanji = new KANJI(this, emu);
71 event->set_context_cpu(cpu);
72 event->set_context_sound(beep);
73 event->set_context_sound(pcm);
74 event->set_context_sound(fdc->get_context_noise_seek());
75 event->set_context_sound(fdc->get_context_noise_head_down());
76 event->set_context_sound(fdc->get_context_noise_head_up());
78 and_drq->set_context_out(cpu, SIG_CPU_NMI, 1);
79 and_drq->set_mask(SIG_AND_BIT_0 | SIG_AND_BIT_1);
80 sio->set_context_rxrdy(pic, SIG_I8259_IR1, 1);
81 pio0->set_context_port_a(rtc, SIG_MSM58321_READ, 1, 0);
82 pio0->set_context_port_a(rtc, SIG_MSM58321_WRITE, 2, 0);
83 pio0->set_context_port_a(rtc, SIG_MSM58321_ADDR_WRITE, 4, 0);
84 pio0->set_context_port_c(rtc, SIG_MSM58321_DATA, 0x0f, 0);
85 pio1->set_context_port_a(crtc, SIG_CRTC_BITMASK_LOW, 0xff, 0);
86 pio1->set_context_port_b(crtc, SIG_CRTC_BITMASK_HIGH, 0xff, 0);
87 pio1->set_context_port_c(crtc, SIG_CRTC_VRAM_PLANE, 0x3f, 0);
88 pio1->set_context_port_c(and_drq, SIG_AND_BIT_0, 0x80, 0);
89 pio1->set_context_port_c(ioctrl, SIG_IOCTRL_RESET, 0x40, 0);
90 pic->set_context_cpu(cpu);
91 rtc->set_context_data(pio0, SIG_I8255_PORT_C, 0x0f, 0);
92 rtc->set_context_busy(pio0, SIG_I8255_PORT_C, 0x10);
93 fdc->set_context_irq(cpu, SIG_CPU_NMI, 1);
94 fdc->set_context_drq(and_drq, SIG_AND_BIT_1, 1);
96 crtc->set_context_pic(pic);
97 ioctrl->set_context_pic(pic);
98 ioctrl->set_context_fdc(fdc);
99 ioctrl->set_context_beep(beep);
100 ioctrl->set_context_pcm(pcm);
103 cpu->set_context_mem(memory);
104 cpu->set_context_io(io);
105 cpu->set_context_intr(pic);
107 cpu->set_context_debugger(new DEBUGGER(this, emu));
111 memset(ram, 0, sizeof(ram));
112 memset(ipl, 0xff, sizeof(ipl));
114 memory->read_bios(_T("IPL.ROM"), ipl, sizeof(ipl));
116 memory->set_memory_rw(0x00000, 0xbffff, ram);
117 memory->set_memory_mapped_io_rw(0xc0000, 0xdffff, crtc);
118 memory->set_memory_r(0xf8000, 0xfffff, ipl);
121 io->set_iomap_alias_rw(0x00, pic, 0);
122 io->set_iomap_alias_rw(0x02, pic, 1);
123 // io->set_iomap_alias_rw(0x04, dma, 0);
124 // io->set_iomap_alias_rw(0x06, dma, 1);
125 io->set_iomap_alias_r(0x08, fdc, 0);
126 io->set_iomap_alias_rw(0x0a, fdc, 1);
127 io->set_iomap_alias_rw(0x10, pio0, 0);
128 io->set_iomap_alias_rw(0x12, pio0, 1);
129 io->set_iomap_alias_rw(0x14, pio0, 2);
130 io->set_iomap_alias_rw(0x16, pio0, 3);
131 io->set_iomap_alias_rw(0x18, pio1, 0);
132 io->set_iomap_alias_rw(0x1a, pio1, 1);
133 io->set_iomap_alias_rw(0x1c, pio1, 2);
134 io->set_iomap_alias_rw(0x1e, pio1, 3);
135 io->set_iomap_single_r(0x20, ioctrl);
136 io->set_iomap_single_rw(0x22, ioctrl);
137 io->set_iomap_single_w(0x24, ioctrl);
138 io->set_iomap_alias_rw(0x28, sio, 0);
139 io->set_iomap_alias_rw(0x2a, sio, 1);
140 io->set_iomap_single_rw(0x30, crtc);
141 io->set_iomap_single_rw(0x38, crtc);
142 io->set_iomap_single_rw(0x3a, crtc);
143 io->set_iomap_single_rw(0x3c, crtc);
144 io->set_iomap_single_rw(0x3e, crtc);
145 for(int i = 0x40; i < 0x62; i++) {
146 io->set_iomap_single_rw(i, crtc);
148 io->set_iomap_single_rw(0x80, kanji);
149 io->set_iomap_single_rw(0x81, kanji);
150 io->set_iomap_single_w(0x84, kanji);
151 io->set_iomap_single_w(0x86, kanji);
153 // initialize all devices
154 #if defined(__GIT_REPO_VERSION)
155 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
157 for(DEVICE* device = first_device; device; device = device->next_device) {
158 device->initialize();
164 // delete all devices
165 for(DEVICE* device = first_device; device;) {
166 DEVICE *next_device = device->next_device;
169 device = next_device;
173 DEVICE* VM::get_device(int id)
175 for(DEVICE* device = first_device; device; device = device->next_device) {
176 if(device->this_device_id == id) {
183 // ----------------------------------------------------------------------------
184 // drive virtual machine
185 // ----------------------------------------------------------------------------
190 for(DEVICE* device = first_device; device; device = device->next_device) {
193 for(int i = 0; i < 4; i++) {
194 if(config.drive_type) {
195 fdc->set_drive_type(i, DRIVE_TYPE_2DD);
197 fdc->set_drive_type(i, DRIVE_TYPE_2D);
207 // ----------------------------------------------------------------------------
209 // ----------------------------------------------------------------------------
212 DEVICE *VM::get_cpu(int index)
221 // ----------------------------------------------------------------------------
223 // ----------------------------------------------------------------------------
225 void VM::draw_screen()
230 // ----------------------------------------------------------------------------
232 // ----------------------------------------------------------------------------
234 void VM::initialize_sound(int rate, int samples)
236 // init sound manager
237 event->initialize_sound(rate, samples);
240 beep->initialize_sound(rate, 2400, 8000);
241 pcm->initialize_sound(rate, 8000);
244 uint16_t* VM::create_sound(int* extra_frames)
246 return event->create_sound(extra_frames);
249 int VM::get_sound_buffer_ptr()
251 return event->get_sound_buffer_ptr();
254 #ifdef USE_SOUND_VOLUME
255 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
258 beep->set_volume(0, decibel_l, decibel_r);
260 pcm->set_volume(0, decibel_l, decibel_r);
262 fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
263 fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
264 fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
269 // ----------------------------------------------------------------------------
271 // ----------------------------------------------------------------------------
273 void VM::key_down(int code, bool repeat)
275 ioctrl->key_down(code);
278 void VM::key_up(int code)
280 ioctrl->key_up(code);
283 bool VM::get_caps_locked()
285 return ioctrl->get_caps_locked();
288 bool VM::get_kana_locked()
290 return ioctrl->get_kana_locked();
293 // ----------------------------------------------------------------------------
295 // ----------------------------------------------------------------------------
297 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
299 fdc->open_disk(drv, file_path, bank);
302 void VM::close_floppy_disk(int drv)
304 fdc->close_disk(drv);
307 bool VM::is_floppy_disk_inserted(int drv)
309 return fdc->is_disk_inserted(drv);
312 void VM::is_floppy_disk_protected(int drv, bool value)
314 fdc->is_disk_protected(drv, value);
317 bool VM::is_floppy_disk_protected(int drv)
319 return fdc->is_disk_protected(drv);
322 uint32_t VM::is_floppy_disk_accessed()
324 return fdc->read_signal(0);
327 bool VM::is_frame_skippable()
329 return event->is_frame_skippable();
332 void VM::update_config()
334 for(DEVICE* device = first_device; device; device = device->next_device) {
335 device->update_config();
339 #define STATE_VERSION 3
341 bool VM::process_state(FILEIO* state_fio, bool loading)
343 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
346 for(DEVICE* device = first_device; device; device = device->next_device) {
347 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
348 // const char *name = typeid(*device).name();
349 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
350 const char *name = device->get_device_name();
351 int len = strlen(name);
353 if(!state_fio->StateCheckInt32(len)) {
355 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
359 if(!state_fio->StateCheckBuffer(name, len, 1)) {
361 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
365 if(!device->process_state(state_fio, loading)) {
367 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
372 // Machine specified.
373 state_fio->StateBuffer(ram, sizeof(ram), 1);