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 #include "../../fileio.h"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 VM::VM(EMU* parent_emu) : emu(parent_emu)
72 static const int cpu_clock[] = {
75 #elif defined(HAS_I386)
77 #elif defined(HAS_I486)
82 #if defined(_FMR60) && (defined(HAS_I386) || defined(HAS_I486) || defined(HAS_PENTIUM))
83 uint8 machine_id = 0xf0; // FMR-70/80
85 uint8 machine_id = 0xf8; // FMR-50/60
88 FILEIO* fio = new FILEIO();
89 if(fio->Fopen(emu->bios_path(_T("MACHINE.ID")), FILEIO_READ_BINARY)) {
90 machine_id = fio->Fgetc();
97 machine_id |= 0; // 286
98 #elif defined(HAS_I386)
99 // machine_id |= 1; // 386DX
100 machine_id |= 3; // 386SX
101 #elif defined(HAS_I486)
102 machine_id |= 2; // 486SX/DX
106 first_device = last_device = NULL;
107 dummy = new DEVICE(this, emu); // must be 1st device
108 event = new EVENT(this, emu); // must be 2nd device
110 #if defined(HAS_I286)
111 cpu = new I286(this, emu);
113 cpu = new I386(this, emu);
115 crtc = new HD46505(this, emu);
117 acrtc = new HD63484(this, emu);
119 sio = new I8251(this, emu);
120 pit0 = new I8253(this, emu);
121 pit1 = new I8253(this, emu);
122 pic = new I8259(this, emu);
123 io = new IO(this, emu);
124 fdc = new MB8877(this, emu);
125 rtc = new MSM58321(this, emu);
126 pcm = new PCM1BIT(this, emu);
127 dma = new UPD71071(this, emu);
129 bios = new BIOS(this, emu);
130 cmos = new CMOS(this, emu);
131 floppy = new FLOPPY(this, emu);
132 keyboard = new KEYBOARD(this, emu);
133 memory = new MEMORY(this, emu);
134 scsi = new SCSI(this, emu);
135 // serial = new SERIAL(this, emu);
136 timer = new TIMER(this, emu);
139 event->set_context_cpu(cpu, cpu_clock[config.cpu_type & 1]);
140 event->set_context_sound(pcm);
148 6 floppy drive or dma ???
164 crtc->set_context_disp(memory, SIG_MEMORY_DISP, 1);
165 crtc->set_context_vsync(memory, SIG_MEMORY_VSYNC, 1);
167 acrtc->set_vram_ptr((uint16*)memory->get_vram(), 0x80000);
169 pit0->set_context_ch0(timer, SIG_TIMER_CH0, 1);
170 pit0->set_context_ch1(timer, SIG_TIMER_CH1, 1);
171 pit0->set_context_ch2(pcm, SIG_PCM1BIT_SIGNAL, 1);
172 pit0->set_constant_clock(0, 307200);
173 pit0->set_constant_clock(1, 307200);
174 pit0->set_constant_clock(2, 307200);
175 pit1->set_constant_clock(1, 1228800);
176 pic->set_context_cpu(cpu);
177 fdc->set_context_drq(dma, SIG_UPD71071_CH0, 1);
178 fdc->set_context_irq(floppy, SIG_FLOPPY_IRQ, 1);
179 rtc->set_context_data(timer, SIG_TIMER_RTC, 0x0f, 0);
180 rtc->set_context_busy(timer, SIG_TIMER_RTC, 0x80);
181 dma->set_context_memory(memory);
182 dma->set_context_ch0(fdc);
183 // dma->set_context_ch1(scsi);
185 bios->set_context_mem(memory);
186 bios->set_context_io(io);
187 bios->set_cmos_ptr(cmos->get_cmos());
188 bios->set_vram_ptr(memory->get_vram());
189 bios->set_cvram_ptr(memory->get_cvram());
191 bios->set_avram_ptr(memory->get_avram());
193 bios->set_kvram_ptr(memory->get_kvram());
195 floppy->set_context_fdc(fdc);
196 floppy->set_context_pic(pic);
197 keyboard->set_context_pic(pic);
198 memory->set_context_cpu(cpu);
199 memory->set_machine_id(machine_id);
200 memory->set_context_crtc(crtc);
201 memory->set_chregs_ptr(crtc->get_regs());
202 // scsi->set_context_dma(dma);
203 // scsi->set_context_pic(pic);
204 timer->set_context_pcm(pcm);
205 timer->set_context_pic(pic);
206 timer->set_context_rtc(rtc);
209 cpu->set_context_mem(memory);
210 cpu->set_context_io(io);
211 cpu->set_context_intr(pic);
212 cpu->set_context_bios(bios);
213 #ifdef SINGLE_MODE_DMA
214 cpu->set_context_dma(dma);
217 cpu->set_context_debugger(new DEBUGGER(this, emu));
221 io->set_iomap_alias_rw(0x00, pic, I8259_ADDR_CHIP0 | 0);
222 io->set_iomap_alias_rw(0x02, pic, I8259_ADDR_CHIP0 | 1);
223 io->set_iomap_alias_rw(0x10, pic, I8259_ADDR_CHIP1 | 0);
224 io->set_iomap_alias_rw(0x12, pic, I8259_ADDR_CHIP1 | 1);
225 io->set_iomap_single_rw(0x20, memory); // reset
226 io->set_iomap_single_r(0x21, memory); // cpu misc
227 io->set_iomap_single_w(0x22, memory); // dma
228 io->set_iomap_single_rw(0x24, memory); // dma
229 io->set_iomap_single_r(0x26, timer);
230 io->set_iomap_single_r(0x27, timer);
231 io->set_iomap_single_r(0x30, memory); // cpu id
232 io->set_iomap_alias_rw(0x40, pit0, 0);
233 io->set_iomap_alias_rw(0x42, pit0, 1);
234 io->set_iomap_alias_rw(0x44, pit0, 2);
235 io->set_iomap_alias_rw(0x46, pit0, 3);
236 io->set_iomap_alias_rw(0x50, pit1, 0);
237 io->set_iomap_alias_rw(0x52, pit1, 1);
238 io->set_iomap_alias_rw(0x54, pit1, 2);
239 io->set_iomap_alias_rw(0x56, pit1, 3);
240 io->set_iomap_single_rw(0x60, timer);
241 io->set_iomap_single_rw(0x70, timer);
242 io->set_iomap_single_w(0x80, timer);
244 io->set_iomap_single_w(0x90, cmos);
246 io->set_iomap_range_rw(0xa0, 0xaf, dma);
247 io->set_iomap_alias_rw(0x200, fdc, 0);
248 io->set_iomap_alias_rw(0x202, fdc, 1);
249 io->set_iomap_alias_rw(0x204, fdc, 2);
250 io->set_iomap_alias_rw(0x206, fdc, 3);
251 io->set_iomap_single_rw(0x208, floppy);
252 io->set_iomap_single_rw(0x20c, floppy);
253 io->set_iomap_single_rw(0x400, memory); // crtc
254 io->set_iomap_single_rw(0x402, memory); // crtc
255 io->set_iomap_single_rw(0x404, memory); // crtc
256 io->set_iomap_single_w(0x408, memory); // crtc
257 io->set_iomap_single_rw(0x40a, memory); // crtc
258 io->set_iomap_single_rw(0x40c, memory); // crtc
259 io->set_iomap_single_rw(0x40e, memory); // crtc
260 io->set_iomap_alias_rw(0x500, crtc, 0);
261 io->set_iomap_alias_rw(0x502, crtc, 1);
263 io->set_iomap_range_rw(0x520, 0x523, acrtc);
265 io->set_iomap_single_rw(0x600, keyboard);
266 io->set_iomap_single_rw(0x602, keyboard);
267 io->set_iomap_single_rw(0x604, keyboard);
268 io->set_iomap_alias_rw(0xa00, sio, 0);
269 io->set_iomap_alias_rw(0xa02, sio, 1);
270 // io->set_iomap_single_r(0xa04, serial);
271 // io->set_iomap_single_r(0xa06, serial);
272 // io->set_iomap_single_w(0xa08, serial);
273 io->set_iomap_single_rw(0xc30, scsi);
274 io->set_iomap_single_rw(0xc32, scsi);
275 io->set_iomap_range_rw(0x3000, 0x3fff, cmos);
276 io->set_iomap_range_rw(0xfd98, 0xfd9f, memory); // crtc
277 io->set_iomap_single_rw(0xfda0, memory); // crtc
279 // initialize all devices
280 for(DEVICE* device = first_device; device; device = device->next_device) {
281 device->initialize();
283 for(int i = 0; i < MAX_DRIVE; i++) {
284 bios->set_disk_handler(i, fdc->get_disk_handler(i));
290 // delete all devices
291 for(DEVICE* device = first_device; device;) {
292 DEVICE *next_device = device->next_device;
295 device = next_device;
299 DEVICE* VM::get_device(int id)
301 for(DEVICE* device = first_device; device; device = device->next_device) {
302 if(device->this_device_id == id) {
309 // ----------------------------------------------------------------------------
310 // drive virtual machine
311 // ----------------------------------------------------------------------------
316 for(DEVICE* device = first_device; device; device = device->next_device) {
320 for(DEVICE* device = first_device; device; device = device->next_device) {
330 // ----------------------------------------------------------------------------
332 // ----------------------------------------------------------------------------
335 DEVICE *VM::get_cpu(int index)
344 // ----------------------------------------------------------------------------
346 // ----------------------------------------------------------------------------
348 void VM::draw_screen()
350 memory->draw_screen();
353 int VM::access_lamp()
355 uint32 status = fdc->read_signal(0) | bios->read_signal(0);
356 return (status & 0x10) ? 4 : (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
359 // ----------------------------------------------------------------------------
361 // ----------------------------------------------------------------------------
363 void VM::initialize_sound(int rate, int samples)
365 // init sound manager
366 event->initialize_sound(rate, samples);
369 pcm->init(rate, 8000);
372 uint16* VM::create_sound(int* extra_frames)
374 return event->create_sound(extra_frames);
377 int VM::sound_buffer_ptr()
379 return event->sound_buffer_ptr();
382 // ----------------------------------------------------------------------------
384 // ----------------------------------------------------------------------------
386 void VM::key_down(int code, bool repeat)
388 keyboard->key_down(code);
391 void VM::key_up(int code)
393 keyboard->key_up(code);
396 // ----------------------------------------------------------------------------
398 // ----------------------------------------------------------------------------
400 void VM::open_disk(int drv, _TCHAR* file_path, int offset)
402 fdc->open_disk(drv, file_path, offset);
403 floppy->change_disk(drv);
406 void VM::close_disk(int drv)
408 fdc->close_disk(drv);
411 bool VM::disk_inserted(int drv)
413 return fdc->disk_inserted(drv);
418 return event->now_skip();
421 void VM::update_config()
423 for(DEVICE* device = first_device; device; device = device->next_device) {
424 device->update_config();