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"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
48 first_device = last_device = NULL;
49 dummy = new DEVICE(this, emu); // must be 1st device
50 event = new EVENT(this, emu); // must be 2nd device
52 and_drq = new AND(this, emu);
53 beep = new BEEP(this, emu);
55 // beep->set_context_debugger(new DEBUGGER(this, emu));
57 sio = new I8251(this, emu);
58 pio0 = new I8255(this, emu);
59 pio0->set_device_name(_T("8255 PIO (RTC)"));
60 pio1 = new I8255(this, emu);
61 pio1->set_device_name(_T("8255 PIO (CRTC)"));
62 pic = new I8259(this, emu);
63 cpu = new I86(this, emu);
64 cpu->device_model = INTEL_8086;
66 io = new IO(this, emu);
67 memory = new MEMORY(this, emu);
69 rtc = new MSM58321(this, emu);
70 pcm = new PCM1BIT(this, emu);
71 fdc = new UPD765A(this, emu);
73 // fdc->set_context_debugger(new DEBUGGER(this, emu));
75 fdc->set_context_noise_seek(new NOISE(this, emu));
76 fdc->set_context_noise_head_down(new NOISE(this, emu));
77 fdc->set_context_noise_head_up(new NOISE(this, emu));
79 crtc = new CRTC(this, emu);
80 ioctrl = new IOCTRL(this, emu);
81 kanji = new KANJI(this, emu);
84 event->set_context_cpu(cpu);
85 event->set_context_sound(beep);
86 event->set_context_sound(pcm);
87 event->set_context_sound(fdc->get_context_noise_seek());
88 event->set_context_sound(fdc->get_context_noise_head_down());
89 event->set_context_sound(fdc->get_context_noise_head_up());
91 and_drq->set_context_out(cpu, SIG_CPU_NMI, 1);
92 and_drq->set_mask(SIG_AND_BIT_0 | SIG_AND_BIT_1);
93 sio->set_context_rxrdy(pic, SIG_I8259_IR1, 1);
94 pio0->set_context_port_a(rtc, SIG_MSM58321_READ, 1, 0);
95 pio0->set_context_port_a(rtc, SIG_MSM58321_WRITE, 2, 0);
96 pio0->set_context_port_a(rtc, SIG_MSM58321_ADDR_WRITE, 4, 0);
97 pio0->set_context_port_c(rtc, SIG_MSM58321_DATA, 0x0f, 0);
98 pio1->set_context_port_a(crtc, SIG_CRTC_BITMASK_LOW, 0xff, 0);
99 pio1->set_context_port_b(crtc, SIG_CRTC_BITMASK_HIGH, 0xff, 0);
100 pio1->set_context_port_c(crtc, SIG_CRTC_VRAM_PLANE, 0x3f, 0);
101 pio1->set_context_port_c(and_drq, SIG_AND_BIT_0, 0x80, 0);
102 pio1->set_context_port_c(ioctrl, SIG_IOCTRL_RESET, 0x40, 0);
103 pic->set_context_cpu(cpu);
104 rtc->set_context_data(pio0, SIG_I8255_PORT_C, 0x0f, 0);
105 rtc->set_context_busy(pio0, SIG_I8255_PORT_C, 0x10);
106 fdc->set_context_irq(cpu, SIG_CPU_NMI, 1);
107 fdc->set_context_drq(and_drq, SIG_AND_BIT_1, 1);
109 crtc->set_context_pic(pic);
110 ioctrl->set_context_pic(pic);
111 ioctrl->set_context_fdc(fdc);
112 ioctrl->set_context_beep(beep);
113 ioctrl->set_context_pcm(pcm);
116 cpu->set_context_mem(memory);
117 cpu->set_context_io(io);
118 cpu->set_context_intr(pic);
120 cpu->set_context_debugger(new DEBUGGER(this, emu));
124 memset(ram, 0, sizeof(ram));
125 memset(ipl, 0xff, sizeof(ipl));
127 memory->read_bios(_T("IPL.ROM"), ipl, sizeof(ipl));
129 memory->set_memory_rw(0x00000, 0xbffff, ram);
130 memory->set_memory_mapped_io_rw(0xc0000, 0xdffff, crtc);
131 memory->set_memory_r(0xf8000, 0xfffff, ipl);
134 io->set_iomap_alias_rw(0x00, pic, 0);
135 io->set_iomap_alias_rw(0x02, pic, 1);
136 // io->set_iomap_alias_rw(0x04, dma, 0);
137 // io->set_iomap_alias_rw(0x06, dma, 1);
138 io->set_iomap_alias_r(0x08, fdc, 0);
139 io->set_iomap_alias_rw(0x0a, fdc, 1);
140 io->set_iomap_alias_rw(0x10, pio0, 0);
141 io->set_iomap_alias_rw(0x12, pio0, 1);
142 io->set_iomap_alias_rw(0x14, pio0, 2);
143 io->set_iomap_alias_rw(0x16, pio0, 3);
144 io->set_iomap_alias_rw(0x18, pio1, 0);
145 io->set_iomap_alias_rw(0x1a, pio1, 1);
146 io->set_iomap_alias_rw(0x1c, pio1, 2);
147 io->set_iomap_alias_rw(0x1e, pio1, 3);
148 io->set_iomap_single_r(0x20, ioctrl);
149 io->set_iomap_single_rw(0x22, ioctrl);
150 io->set_iomap_single_w(0x24, ioctrl);
151 io->set_iomap_alias_rw(0x28, sio, 0);
152 io->set_iomap_alias_rw(0x2a, sio, 1);
153 io->set_iomap_single_rw(0x30, crtc);
154 io->set_iomap_single_rw(0x38, crtc);
155 io->set_iomap_single_rw(0x3a, crtc);
156 io->set_iomap_single_rw(0x3c, crtc);
157 io->set_iomap_single_rw(0x3e, crtc);
158 for(int i = 0x40; i < 0x62; i++) {
159 io->set_iomap_single_rw(i, crtc);
161 io->set_iomap_single_rw(0x80, kanji);
162 io->set_iomap_single_rw(0x81, kanji);
163 io->set_iomap_single_w(0x84, kanji);
164 io->set_iomap_single_w(0x86, kanji);
166 // initialize all devices
167 #if defined(__GIT_REPO_VERSION)
168 set_git_repo_version(__GIT_REPO_VERSION);
170 initialize_devices();
172 for(int i = 0; i < 4; i++) {
173 if(config.drive_type) {
174 fdc->set_drive_type(i, DRIVE_TYPE_2DD);
176 fdc->set_drive_type(i, DRIVE_TYPE_2D);
183 // delete all devices
184 for(DEVICE* device = first_device; device;) {
185 DEVICE *next_device = device->next_device;
188 device = next_device;
192 DEVICE* VM::get_device(int id)
194 for(DEVICE* device = first_device; device; device = device->next_device) {
195 if(device->this_device_id == id) {
202 // ----------------------------------------------------------------------------
203 // drive virtual machine
204 // ----------------------------------------------------------------------------
209 for(DEVICE* device = first_device; device; device = device->next_device) {
212 for(int i = 0; i < 4; i++) {
213 if(config.drive_type) {
214 fdc->set_drive_type(i, DRIVE_TYPE_2DD);
216 fdc->set_drive_type(i, DRIVE_TYPE_2D);
226 // ----------------------------------------------------------------------------
228 // ----------------------------------------------------------------------------
231 DEVICE *VM::get_cpu(int index)
240 // ----------------------------------------------------------------------------
242 // ----------------------------------------------------------------------------
244 void VM::draw_screen()
249 // ----------------------------------------------------------------------------
251 // ----------------------------------------------------------------------------
253 void VM::initialize_sound(int rate, int samples)
255 // init sound manager
256 event->initialize_sound(rate, samples);
259 beep->initialize_sound(rate, 2400, 8000);
260 pcm->initialize_sound(rate, 8000);
263 uint16_t* VM::create_sound(int* extra_frames)
265 return event->create_sound(extra_frames);
268 int VM::get_sound_buffer_ptr()
270 return event->get_sound_buffer_ptr();
273 #ifdef USE_SOUND_VOLUME
274 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
277 beep->set_volume(0, decibel_l, decibel_r);
279 pcm->set_volume(0, decibel_l, decibel_r);
281 fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
282 fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
283 fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
288 // ----------------------------------------------------------------------------
290 // ----------------------------------------------------------------------------
292 void VM::key_down(int code, bool repeat)
294 ioctrl->key_down(code);
297 void VM::key_up(int code)
299 ioctrl->key_up(code);
302 bool VM::get_caps_locked()
304 return ioctrl->get_caps_locked();
307 bool VM::get_kana_locked()
309 return ioctrl->get_kana_locked();
312 // ----------------------------------------------------------------------------
314 // ----------------------------------------------------------------------------
316 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
318 fdc->open_disk(drv, file_path, bank);
321 void VM::close_floppy_disk(int drv)
323 fdc->close_disk(drv);
326 bool VM::is_floppy_disk_inserted(int drv)
328 return fdc->is_disk_inserted(drv);
331 void VM::is_floppy_disk_protected(int drv, bool value)
333 fdc->is_disk_protected(drv, value);
336 bool VM::is_floppy_disk_protected(int drv)
338 return fdc->is_disk_protected(drv);
341 uint32_t VM::is_floppy_disk_accessed()
343 return fdc->read_signal(0);
346 bool VM::is_frame_skippable()
348 return event->is_frame_skippable();
351 void VM::update_config()
353 for(DEVICE* device = first_device; device; device = device->next_device) {
354 device->update_config();
358 double VM::get_current_usec()
360 if(event == NULL) return 0.0;
361 return event->get_current_usec();
364 uint64_t VM::get_current_clock_uint64()
366 if(event == NULL) return (uint64_t)0;
367 return event->get_current_clock_uint64();
370 #define STATE_VERSION 4
372 bool VM::process_state(FILEIO* state_fio, bool loading)
374 if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) {
377 // Machine specified.
378 state_fio->StateArray(ram, sizeof(ram), 1);