2 FUJITSU FMR-50 Emulator 'eFMR-50'
3 FUJITSU FMR-60 Emulator 'eFMR-60'
5 Author : Takeda.Toshiya
12 #include "../../emu.h"
13 #include "../device.h"
16 #include "../hd46505.h"
18 #include "../hd63484.h"
29 #include "../mb8877.h"
30 #include "../msm58321.h"
31 #include "../pcm1bit.h"
32 #include "../upd71071.h"
35 #include "../debugger.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 VM::VM(EMU* parent_emu) : emu(parent_emu)
70 static const int cpu_clock[] = {
73 #elif defined(HAS_I386)
75 #elif defined(HAS_I486)
80 #if defined(_FMR60) && (defined(HAS_I386) || defined(HAS_I486) || defined(HAS_PENTIUM))
81 uint8 machine_id = 0xf0; // FMR-70/80
83 uint8 machine_id = 0xf8; // FMR-50/60
86 FILEIO* fio = new FILEIO();
87 if(fio->Fopen(emu->bios_path(_T("MACHINE.ID")), FILEIO_READ_BINARY)) {
88 machine_id = fio->Fgetc();
95 machine_id |= 0; // 286
96 #elif defined(HAS_I386)
97 // machine_id |= 1; // 386DX
98 machine_id |= 3; // 386SX
99 #elif defined(HAS_I486)
100 machine_id |= 2; // 486SX/DX
104 first_device = last_device = NULL;
105 dummy = new DEVICE(this, emu); // must be 1st device
106 event = new EVENT(this, emu); // must be 2nd device
108 #if defined(HAS_I286)
109 cpu = new I286(this, emu);
111 cpu = new I386(this, emu);
113 crtc = new HD46505(this, emu);
115 acrtc = new HD63484(this, emu);
117 sio = new I8251(this, emu);
118 pit0 = new I8253(this, emu);
119 pit1 = new I8253(this, emu);
120 pic = new I8259(this, emu);
121 io = new IO(this, emu);
122 fdc = new MB8877(this, emu);
123 rtc = new MSM58321(this, emu);
124 pcm = new PCM1BIT(this, emu);
125 dma = new UPD71071(this, emu);
127 bios = new BIOS(this, emu);
128 cmos = new CMOS(this, emu);
129 floppy = new FLOPPY(this, emu);
130 keyboard = new KEYBOARD(this, emu);
131 memory = new MEMORY(this, emu);
132 scsi = new SCSI(this, emu);
133 // serial = new SERIAL(this, emu);
134 timer = new TIMER(this, emu);
137 event->set_context_cpu(cpu, cpu_clock[config.cpu_type & 1]);
138 event->set_context_sound(pcm);
146 6 floppy drive or dma ???
162 crtc->set_context_disp(memory, SIG_MEMORY_DISP, 1);
163 crtc->set_context_vsync(memory, SIG_MEMORY_VSYNC, 1);
165 acrtc->set_vram_ptr((uint16*)memory->get_vram(), 0x80000);
167 pit0->set_context_ch0(timer, SIG_TIMER_CH0, 1);
168 pit0->set_context_ch1(timer, SIG_TIMER_CH1, 1);
169 pit0->set_context_ch2(pcm, SIG_PCM1BIT_SIGNAL, 1);
170 pit0->set_constant_clock(0, 307200);
171 pit0->set_constant_clock(1, 307200);
172 pit0->set_constant_clock(2, 307200);
173 pit1->set_constant_clock(1, 1228800);
174 pic->set_context_cpu(cpu);
175 fdc->set_context_drq(dma, SIG_UPD71071_CH0, 1);
176 fdc->set_context_irq(floppy, SIG_FLOPPY_IRQ, 1);
177 rtc->set_context_data(timer, SIG_TIMER_RTC, 0x0f, 0);
178 rtc->set_context_busy(timer, SIG_TIMER_RTC, 0x80);
179 dma->set_context_memory(memory);
180 dma->set_context_ch0(fdc);
181 // dma->set_context_ch1(scsi);
183 bios->set_context_mem(memory);
184 bios->set_context_io(io);
185 bios->set_cmos_ptr(cmos->get_cmos());
186 bios->set_vram_ptr(memory->get_vram());
187 bios->set_cvram_ptr(memory->get_cvram());
189 bios->set_avram_ptr(memory->get_avram());
191 bios->set_kvram_ptr(memory->get_kvram());
193 floppy->set_context_fdc(fdc);
194 floppy->set_context_pic(pic);
195 keyboard->set_context_pic(pic);
196 memory->set_context_cpu(cpu);
197 memory->set_machine_id(machine_id);
198 memory->set_context_crtc(crtc);
199 memory->set_chregs_ptr(crtc->get_regs());
200 // scsi->set_context_dma(dma);
201 // scsi->set_context_pic(pic);
202 timer->set_context_pcm(pcm);
203 timer->set_context_pic(pic);
204 timer->set_context_rtc(rtc);
207 cpu->set_context_mem(memory);
208 cpu->set_context_io(io);
209 cpu->set_context_intr(pic);
210 cpu->set_context_bios(bios);
211 #ifdef SINGLE_MODE_DMA
212 cpu->set_context_dma(dma);
215 cpu->set_context_debugger(new DEBUGGER(this, emu));
219 io->set_iomap_alias_rw(0x00, pic, I8259_ADDR_CHIP0 | 0);
220 io->set_iomap_alias_rw(0x02, pic, I8259_ADDR_CHIP0 | 1);
221 io->set_iomap_alias_rw(0x10, pic, I8259_ADDR_CHIP1 | 0);
222 io->set_iomap_alias_rw(0x12, pic, I8259_ADDR_CHIP1 | 1);
223 io->set_iomap_single_rw(0x20, memory); // reset
224 io->set_iomap_single_r(0x21, memory); // cpu misc
225 io->set_iomap_single_w(0x22, memory); // dma
226 io->set_iomap_single_rw(0x24, memory); // dma
227 io->set_iomap_single_r(0x26, timer);
228 io->set_iomap_single_r(0x27, timer);
229 io->set_iomap_single_r(0x30, memory); // cpu id
230 io->set_iomap_alias_rw(0x40, pit0, 0);
231 io->set_iomap_alias_rw(0x42, pit0, 1);
232 io->set_iomap_alias_rw(0x44, pit0, 2);
233 io->set_iomap_alias_rw(0x46, pit0, 3);
234 io->set_iomap_alias_rw(0x50, pit1, 0);
235 io->set_iomap_alias_rw(0x52, pit1, 1);
236 io->set_iomap_alias_rw(0x54, pit1, 2);
237 io->set_iomap_alias_rw(0x56, pit1, 3);
238 io->set_iomap_single_rw(0x60, timer);
239 io->set_iomap_single_rw(0x70, timer);
240 io->set_iomap_single_w(0x80, timer);
242 io->set_iomap_single_w(0x90, cmos);
244 io->set_iomap_range_rw(0xa0, 0xaf, dma);
245 io->set_iomap_alias_rw(0x200, fdc, 0);
246 io->set_iomap_alias_rw(0x202, fdc, 1);
247 io->set_iomap_alias_rw(0x204, fdc, 2);
248 io->set_iomap_alias_rw(0x206, fdc, 3);
249 io->set_iomap_single_rw(0x208, floppy);
250 io->set_iomap_single_rw(0x20c, floppy);
251 io->set_iomap_single_rw(0x400, memory); // crtc
252 io->set_iomap_single_rw(0x402, memory); // crtc
253 io->set_iomap_single_rw(0x404, memory); // crtc
254 io->set_iomap_single_w(0x408, memory); // crtc
255 io->set_iomap_single_rw(0x40a, memory); // crtc
256 io->set_iomap_single_rw(0x40c, memory); // crtc
257 io->set_iomap_single_rw(0x40e, memory); // crtc
258 io->set_iomap_alias_rw(0x500, crtc, 0);
259 io->set_iomap_alias_rw(0x502, crtc, 1);
261 io->set_iomap_range_rw(0x520, 0x523, acrtc);
263 io->set_iomap_single_rw(0x600, keyboard);
264 io->set_iomap_single_rw(0x602, keyboard);
265 io->set_iomap_single_rw(0x604, keyboard);
266 io->set_iomap_alias_rw(0xa00, sio, 0);
267 io->set_iomap_alias_rw(0xa02, sio, 1);
268 // io->set_iomap_single_r(0xa04, serial);
269 // io->set_iomap_single_r(0xa06, serial);
270 // io->set_iomap_single_w(0xa08, serial);
271 io->set_iomap_single_rw(0xc30, scsi);
272 io->set_iomap_single_rw(0xc32, scsi);
273 io->set_iomap_range_rw(0x3000, 0x3fff, cmos);
274 io->set_iomap_range_rw(0xfd98, 0xfd9f, memory); // crtc
275 io->set_iomap_single_rw(0xfda0, memory); // crtc
277 // initialize all devices
278 for(DEVICE* device = first_device; device; device = device->next_device) {
279 device->initialize();
281 for(int i = 0; i < MAX_DRIVE; i++) {
282 bios->set_disk_handler(i, fdc->get_disk_handler(i));
288 // delete all devices
289 for(DEVICE* device = first_device; device;) {
290 DEVICE *next_device = device->next_device;
293 device = next_device;
297 DEVICE* VM::get_device(int id)
299 for(DEVICE* device = first_device; device; device = device->next_device) {
300 if(device->this_device_id == id) {
307 // ----------------------------------------------------------------------------
308 // drive virtual machine
309 // ----------------------------------------------------------------------------
314 for(DEVICE* device = first_device; device; device = device->next_device) {
318 for(DEVICE* device = first_device; device; device = device->next_device) {
328 // ----------------------------------------------------------------------------
330 // ----------------------------------------------------------------------------
333 DEVICE *VM::get_cpu(int index)
342 // ----------------------------------------------------------------------------
344 // ----------------------------------------------------------------------------
346 void VM::draw_screen()
348 memory->draw_screen();
351 int VM::access_lamp()
353 uint32 status = fdc->read_signal(0) | bios->read_signal(0);
354 return (status & 0x10) ? 4 : (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
357 // ----------------------------------------------------------------------------
359 // ----------------------------------------------------------------------------
361 void VM::initialize_sound(int rate, int samples)
363 // init sound manager
364 event->initialize_sound(rate, samples);
367 pcm->init(rate, 8000);
370 uint16* VM::create_sound(int* extra_frames)
372 return event->create_sound(extra_frames);
375 int VM::sound_buffer_ptr()
377 return event->sound_buffer_ptr();
380 // ----------------------------------------------------------------------------
382 // ----------------------------------------------------------------------------
384 void VM::key_down(int code, bool repeat)
386 keyboard->key_down(code);
389 void VM::key_up(int code)
391 keyboard->key_up(code);
394 // ----------------------------------------------------------------------------
396 // ----------------------------------------------------------------------------
398 void VM::open_disk(int drv, _TCHAR* file_path, int bank)
400 fdc->open_disk(drv, file_path, bank);
401 floppy->change_disk(drv);
404 void VM::close_disk(int drv)
406 fdc->close_disk(drv);
409 bool VM::disk_inserted(int drv)
411 return fdc->disk_inserted(drv);
416 return event->now_skip();
419 void VM::update_config()
421 for(DEVICE* device = first_device; device; device = device->next_device) {
422 device->update_config();
426 #define STATE_VERSION 1
428 void VM::save_state(FILEIO* state_fio)
430 state_fio->FputUint32(STATE_VERSION);
432 for(DEVICE* device = first_device; device; device = device->next_device) {
433 device->save_state(state_fio);
437 bool VM::load_state(FILEIO* state_fio)
439 if(state_fio->FgetUint32() != STATE_VERSION) {
442 for(DEVICE* device = first_device; device; device = device->next_device) {
443 if(!device->load_state(state_fio)) {