2 FUJITSU FM16pi Emulator 'eFM16pi'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
22 #include "../mb8877.h"
23 #include "../memory.h"
24 #include "../msm58321.h"
27 #include "../pcm1bit.h"
30 #include "../debugger.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 VM::VM(EMU_TEMPLATE* 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 sio = new I8251(this, emu); // for rs232c
49 pit = new I8253(this, emu);
50 pio = new I8255(this, emu); // for system port
51 pic = new I8259(this, emu);
52 cpu = new I86(this, emu);
53 cpu->device_model = INTEL_8086;
54 io = new IO(this, emu);
57 fdc = new MB8877(this, emu);
58 fdc->set_context_noise_seek(new NOISE(this, emu));
59 fdc->set_context_noise_head_down(new NOISE(this, emu));
60 fdc->set_context_noise_head_up(new NOISE(this, emu));
61 memory = new MEMORY(this, emu);
62 memory->space = 0x100000;
63 memory->bank_size = 0x4000;
64 memory->bus_width = 16;
66 rtc = new MSM58321(this, emu);
67 not_pit = new NOT(this, emu);
68 pcm = new PCM1BIT(this, emu);
70 sub = new SUB(this, emu);
73 dummy->set_device_name(_T("1st Dummy"));
74 event->set_device_name(_T("EVENT"));
75 cpu->set_device_name(_T("CPU(MBL8086L)"));
77 sio->set_device_name(_T("i8251(RS-232C)"));
78 pio->set_device_name(_T("i8259(SYSTEM PORT)"));
82 event->set_context_cpu(cpu);
83 event->set_context_sound(pcm);
84 event->set_context_sound(fdc->get_context_noise_seek());
85 event->set_context_sound(fdc->get_context_noise_head_down());
86 event->set_context_sound(fdc->get_context_noise_head_up());
98 sio->set_context_rxrdy(pic, SIG_I8259_IR1, 1);
99 sio->set_context_syndet(pic, SIG_I8259_IR2, 1);
100 sio->set_context_txrdy(pic, SIG_I8259_IR3, 1);
107 pit->set_context_ch0(pic, SIG_I8259_IR0, 1);
108 pit->set_context_ch0(not_pit, SIG_NOT_INPUT, 1);
109 not_pit->set_context_out(pio, SIG_I8255_PORT_B, 0x20);
110 pit->set_context_ch2(pcm, SIG_PCM1BIT_SIGNAL, 1);
111 pit->set_constant_clock(0, 2457600);
112 pit->set_constant_clock(1, 2457600);
113 pit->set_constant_clock(2, 2457600);
115 pic->set_context_cpu(cpu);
117 rtc->set_context_data(sub, SIG_SUB_RTC, 0x0f, 0);
118 rtc->set_context_busy(sub, SIG_SUB_RTC, 0x10);
120 fdc->set_context_irq(pic, SIG_I8259_IR7, 1);
121 fdc->set_context_irq(pio, SIG_I8255_PORT_B, 0x40);
122 fdc->set_context_drq(pio, SIG_I8255_PORT_B, 0x80);
124 sub->set_context_cpu(cpu);
125 sub->set_context_fdc(fdc);
126 sub->set_context_pcm(pcm);
127 sub->set_context_pic(pic);
128 sub->set_context_pio(pio);
129 sub->set_context_rtc(rtc);
130 sub->set_vram_ptr(ram + 0x78000);
133 cpu->set_context_mem(memory);
134 cpu->set_context_io(io);
135 cpu->set_context_intr(pic);
137 cpu->set_context_debugger(new DEBUGGER(this, emu));
141 memset(ram, 0, sizeof(ram));
142 memset(kanji, 0xff, sizeof(kanji));
143 memset(cart, 0xff, sizeof(cart));
145 memory->read_bios(_T("BACKUP.BIN"), ram, sizeof(ram));
146 memory->read_bios(_T("KANJI.ROM"), kanji, sizeof(kanji));
147 memory->read_bios(_T("CART.ROM"), cart, sizeof(cart));
149 memory->set_memory_rw(0x00000, 0x6ffff, ram);
150 memory->set_memory_rw(0x70000, 0x73fff, ram + 0x78000);
151 memory->set_memory_rw(0x74000, 0x77fff, ram + 0x78000);
152 memory->set_memory_rw(0x78000, 0x7bfff, ram + 0x78000);
153 memory->set_memory_rw(0x7c000, 0x7ffff, ram + 0x78000);
154 memory->set_memory_r(0x80000, 0xbffff, kanji);
155 memory->set_memory_r(0xc0000, 0xfffff, cart);
158 io->set_iomap_alias_rw(0x00, pic, 0);
159 io->set_iomap_alias_rw(0x02, pic, 1);
161 20H bit0-7 w printer data
162 22H bit0 r printer busy (1=busy)
163 bit1 r printer error (0=error)
164 bit2 r printer acknlg (0=active)
165 bit3 r printer pe (1=empty)
166 bit4 r printer slct (1=online)
167 bit5 r timer irq (0=active)
168 bit6 r fdc irq (1=active)
169 bit7 r fdc drq (1=active)
170 24H bit0 r datarec write protect (1=protected)
171 bit1 r datarec counter pulse (4hz)
173 bit3 r key irq (0=active)
174 bit4-6 w datarec control
181 bit7 e datarec output
183 io->set_iomap_alias_rw(0x20, pio, 0);
184 io->set_iomap_alias_rw(0x22, pio, 1);
185 io->set_iomap_alias_rw(0x24, pio, 2);
186 io->set_iomap_alias_w(0x26, pio, 3);
189 40H bit0-3 r rtc data
192 bit7 r nmi mask (0=masked)
193 bit0-3 w rtc data/addr
195 bit5 w rtc addr write
198 60H bit0-6 r kbd data
199 bit7 r kbd make/break (0=make)
201 io->set_iomap_single_rw(0x40, sub);
202 io->set_iomap_single_r(0x60, sub);
204 io->set_iomap_alias_rw(0x80, sio, 0);
205 io->set_iomap_alias_rw(0x82, sio, 1);
208 A0H bit0-1 w rs-232c clock select
209 bit2 w printer strobe (1=on)
210 bit3 w printer irq reset (0=reset)
211 bit4 w timer irq reset (0=reset)
212 bit5 w power off (1=power off)
213 bit6 w speaker on/off (1=on)
214 bit7 w nmi mask (0=masked)
216 io->set_iomap_single_w(0xa0, sub);
219 C0H bit0-7 r fdc status register
220 bit0-7 w fdc command register
221 C2H bit0-7 rw fdc track register
222 C4H bit0-7 rw fdc sector register
223 C6H bit0-7 rw fdc data register
224 C8H bit0 rw floppy side register
225 CAH bit0-1 rw floppy drive number
226 bit6 rw floppy drive disable (1=disable)
227 bit7 rw floppy motor on/off (1=on)
229 io->set_iomap_alias_rw(0xc0, fdc, 0);
230 io->set_iomap_alias_rw(0xc2, fdc, 1);
231 io->set_iomap_alias_rw(0xc4, fdc, 2);
232 io->set_iomap_alias_rw(0xc6, fdc, 3);
233 io->set_iomap_single_rw(0xc8, sub);
234 io->set_iomap_single_rw(0xca, sub);
236 io->set_iomap_alias_rw(0xe0, pit, 0);
237 io->set_iomap_alias_rw(0xe2, pit, 1);
238 io->set_iomap_alias_rw(0xe4, pit, 2);
239 io->set_iomap_alias_w(0xe6, pit, 3);
242 400H bit0 w memory write protect 20000H-47FFFH
243 bit1 w memory write protect 48000H-6FFFFH
246 // initialize all devices
247 #if defined(__GIT_REPO_VERSION)
248 set_git_repo_version(__GIT_REPO_VERSION);
250 initialize_devices();
252 //pcm->set_realtime_render(true);
258 memory->write_bios(_T("BACKUP.BIN"), ram, sizeof(ram));
260 // delete all devices
261 for(DEVICE* device = first_device; device;) {
262 DEVICE *next_device = device->next_device;
265 device = next_device;
267 for(int i = 0; i < MAX_DRIVE; i++) {
268 fdc->set_drive_type(i, DRIVE_TYPE_2D);
272 DEVICE* VM::get_device(int id)
274 for(DEVICE* device = first_device; device; device = device->next_device) {
275 if(device->this_device_id == id) {
282 // ----------------------------------------------------------------------------
283 // drive virtual machine
284 // ----------------------------------------------------------------------------
289 for(DEVICE* device = first_device; device; device = device->next_device) {
293 // initial device settings
294 pio->write_signal(SIG_I8255_PORT_B, 0x3f, 0xff); // printer disconnected
295 pio->write_signal(SIG_I8255_PORT_C, 0x0c, 0x0f);
298 void VM::notify_power_off()
300 // this->out_debug_log(_T("--- POWER OFF ---\n"));
301 sub->notify_power_off();
309 // ----------------------------------------------------------------------------
311 // ----------------------------------------------------------------------------
314 DEVICE *VM::get_cpu(int index)
323 // ----------------------------------------------------------------------------
325 // ----------------------------------------------------------------------------
327 void VM::draw_screen()
332 // ----------------------------------------------------------------------------
334 // ----------------------------------------------------------------------------
336 void VM::initialize_sound(int rate, int samples)
338 // init sound manager
339 event->initialize_sound(rate, samples);
342 pcm->initialize_sound(rate, 8000);
345 uint16_t* VM::create_sound(int* extra_frames)
347 return event->create_sound(extra_frames);
350 int VM::get_sound_buffer_ptr()
352 return event->get_sound_buffer_ptr();
355 #ifdef USE_SOUND_VOLUME
356 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
359 pcm->set_volume(0, decibel_l, decibel_r);
361 fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
362 fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
363 fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
368 // ----------------------------------------------------------------------------
370 // ----------------------------------------------------------------------------
372 void VM::key_down(int code, bool repeat)
377 void VM::key_up(int code)
382 // ----------------------------------------------------------------------------
384 // ----------------------------------------------------------------------------
386 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
388 fdc->open_disk(drv, file_path, bank);
391 void VM::close_floppy_disk(int drv)
393 fdc->close_disk(drv);
396 bool VM::is_floppy_disk_inserted(int drv)
398 return fdc->is_disk_inserted(drv);
401 void VM::is_floppy_disk_protected(int drv, bool value)
403 fdc->is_disk_protected(drv, value);
406 bool VM::is_floppy_disk_protected(int drv)
408 return fdc->is_disk_protected(drv);
411 uint32_t VM::is_floppy_disk_accessed()
413 return fdc->read_signal(0);
416 bool VM::is_frame_skippable()
418 return event->is_frame_skippable();
421 void VM::update_config()
423 for(DEVICE* device = first_device; device; device = device->next_device) {
424 device->update_config();
428 double VM::get_current_usec()
430 if(event == NULL) return 0.0;
431 return event->get_current_usec();
434 uint64_t VM::get_current_clock_uint64()
436 if(event == NULL) return (uint64_t)0;
437 return event->get_current_clock_uint64();
440 #define STATE_VERSION 4
442 bool VM::process_state(FILEIO* state_fio, bool loading)
444 if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) {
447 // Machine specified.
448 state_fio->StateArray(ram, sizeof(ram), 1);