2 FUJITSU FM-Towns Emulator 'eFMR-60'
4 Author : Kyuma Ohta <whatisthis.sowhat _at_ gmail.com>
9 2016-12-28 Copy from eFMR-50.
13 #include "../../emu.h"
14 #include "../device.h"
17 //#include "../hd46505.h"
25 #include "../mb8877.h"
26 #include "../msm58321.h"
27 #include "../pcm1bit.h"
28 #include "../scsi_hdd.h"
29 #include "../scsi_host.h"
30 #include "../upd71071.h"
32 #include "towns_crtc.h"
34 //#include "mb87078.h"
36 //#include "../ym2612.h"
44 #include "../debugger.h"
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
80 first_device = last_device = NULL;
81 dummy = new DEVICE(this, emu); // must be 1st device
82 event = new EVENT(this, emu); // must be 2nd device
84 dummy->set_device_name(_T("1st Dummy"));
85 event->set_device_name(_T("EVENT"));
88 cpu = new I386(this, emu);
91 cpu->set_device_name(_T("CPU(i386)"));
92 #elif defined(HAS_I486)
93 cpu->set_device_name(_T("CPU(i486)"));
94 #elif defined(HAS_PENTIUM)
95 cpu->set_device_name(_T("CPU(Pentium)"));
99 io = new IO(this, emu);
101 crtc = new TOWNS_CRTC(this, emu);
102 cdc = new CDC(this, emu);
103 cdc_scsi = new SCSI_HOST(this, emu);
104 cdrom = new TOWNS_CDROM(this, emu);
106 memory = new TOWNS_MEMORY(this, emu);
107 vram = new TOWNS_VRAM(this, emu);
108 sprite = new TOWNS_SPRITE(this, emu);
109 sysrom = new SYSROM(this, emu);
110 msdosrom = new MSDOSROM(this, emu);
111 fontrom = new FONT_ROM(this, emu);
112 dictionary = new DICTIONARY(this, emu);
113 #if defined(HAS_20PIX_FONTS)
114 fontrom_20pix = new FONT_ROM_20PIX(this, emu);
116 serialrom = new SERIAL_ROM(this, emu);
118 adc = new AD7820KR(this, emu);
119 adpcm = new RF5C68(this, emu);
120 e_volume[0] = new MB87878(this, emu);
121 e_volume[1] = new MB87878(this, emu);
123 sio = new I8251(this, emu);
124 pit0 = new I8253(this, emu);
125 pit1 = new I8253(this, emu);
126 pic = new I8259(this, emu);
127 fdc = new MB8877(this, emu);
128 rtc = new MSM58321(this, emu);
129 beep = new PCM1BIT(this, emu);
130 opn2 = new YM2612(this, emu);
132 scsi_host = new SCSI_HOST(this, emu);
133 scsi_host->set_device_name(_T("SCSI HOST"));
134 for(int i = 0; i < 7; i++) {
135 if(FILEIO::IsFileExisting(create_local_path(_T("SCSI%d.DAT"), i))) {
136 SCSI_HDD* scsi_hdd = new SCSI_HDD(this, emu);
138 char d_name[64] = {0};
139 snprintf(d_name, 64, "SCSI DISK #%d", i + 1);
140 scsi_hdd->set_device_name(d_name);
142 scsi_hdd->scsi_id = i;
143 scsi_hdd->set_context_interface(scsi_host);
144 scsi_host->set_context_target(scsi_hdd);
147 dma = new UPD71071(this, emu);
148 extra_dma = new UPD71071(this, emu);
150 floppy = new FLOPPY(this, emu);
151 keyboard = new KEYBOARD(this, emu);
152 memory = new TOWNS_MEMORY(this, emu);
153 scsi = new SCSI(this, emu);
154 timer = new TIMER(this, emu);
156 uint16_t machine_id = 0x0100; // FM-Towns1
157 uint16_t cpu_id = 0x0001; // i386DX
158 uint32_t cpu_clock = 16000 * 1000; // 16MHz
159 #if defined(_FMTOWNS1_2ND_GEN)
160 machine_id = 0x0200; // 1F/2F/1H/2H
161 #elif defined(_FMTOWNS_UX_VARIANTS)
162 machine_id = 0x0300; // UX10/20/40
163 cpu_id = 0x0003; // i386SX
164 #elif defined(_FMTOWNS1_3RD_GEN)
165 machine_id = 0x0400; // 10F/20F.40H/80H
166 #elif defined(_FMTOWNS2_CX_VARIANTS)
167 machine_id = 0x0500; // CX10/20/30/40
168 #elif defined(_FMTOWNS_UG_VARIANTS)
169 machine_id = 0x0600; // UG10/20/40/80
170 cpu_id = 0x0003; // i386SX
171 cpu_clock = 20000 * 1000; // 20MHz
172 #elif defined(_FMTOWNS_HR_VARIANTS)
174 cpu_id = 0x0002; // i486SX
175 cpu_clock = 20000 * 1000; // 20MHz
176 #elif defined(_FMTOWNS_HG_VARIANTS)
178 cpu_clock = 20000 * 1000; // 20MHz
179 #elif defined(_FMTOWNS_SG_VARIANTS)
180 machine_id = 0x0800; // OK?
181 #elif defined(_FMTOWNS_SR_VARIANTS)
182 machine_id = 0x0700; // OK?
183 cpu_id = 0x0002; // i486SX
184 cpu_clock = 20000 * 1000; // 20MHz
185 #elif defined(_FMTOWNS_MA_VARIANTS)
186 machine_id = 0x0b00; // OK?
187 cpu_id = 0x0002; // i486SX
188 cpu_clock = 33000 * 1000; // 33MHz
189 #elif defined(_FMTOWNS_ME_VARIANTS)
190 machine_id = 0x0d00; // OK?
191 cpu_id = 0x0002; // i486SX
192 cpu_clock = 25000 * 1000; // 25MHz
193 #elif defined(_FMTOWNS_MF_VARIANTS)
194 machine_id = 0x0f00; // OK?
195 cpu_id = 0x0002; // i486SX
196 cpu_clock = 33000 * 1000; // 33MHz
197 #elif defined(_FMTOWNS_MX_VARIANTS)
198 machine_id = 0x0c00; // OK?
199 cpu_id = 0x0002; // i486DX (With FPU?)
200 cpu_clock = 66000 * 1000; // 66MHz
201 #elif defined(_FMTOWNS_MX_VARIANTS)
202 machine_id = 0x0c00; // OK?
203 cpu_id = 0x0002; // i486DX (With FPU?)
204 cpu_clock = 66000 * 1000; // 66MHz
206 // ToDo: Pentium Model (After HB).
210 set_machine_type(machine_id, cpu_id);
213 event->set_context_cpu(cpu, cpu_clock);
214 event->set_context_sound(beep);
215 event->set_context_sound(opn2);
216 event->set_context_sound(adpcm);
217 event->set_context_sound(cdc);
218 //event->set_context_sound_in(cdc);
219 //event->set_context_sound_in(line_in);
220 //event->set_context_sound_in(mic);
221 //event->set_context_sound_in(modem);
223 if(fdc->load_sound_data(MB8877_SND_TYPE_SEEK, _T("FDDSEEK.WAV"))) {
224 event->set_context_sound(fdc);
233 6 floppy drive or dma ???
240 13 sound (OPN2 + ADPCM)
259 pit0->set_context_ch0(timer, SIG_TIMER_CH0, 1);
260 pit0->set_context_ch1(timer, SIG_TIMER_CH1, 1);
261 pit0->set_context_ch2(beep, SIG_PCM1BIT_SIGNAL, 1);
262 pit0->set_constant_clock(0, 307200);
263 pit0->set_constant_clock(1, 307200);
264 pit0->set_constant_clock(2, 307200);
265 pit1->set_constant_clock(1, 1228800);
266 pic->set_context_cpu(cpu);
267 fdc->set_context_drq(dma, SIG_UPD71071_CH0, 1);
268 fdc->set_context_irq(floppy, SIG_FLOPPY_IRQ, 1);
269 rtc->set_context_data(timer, SIG_TIMER_RTC, 0x0f, 0);
270 rtc->set_context_busy(timer, SIG_TIMER_RTC, 0x80);
271 scsi_host->set_context_irq(scsi, SIG_SCSI_IRQ, 1);
272 scsi_host->set_context_drq(scsi, SIG_SCSI_DRQ, 1);
273 dma->set_context_memory(memory);
274 dma->set_context_ch0(fdc);
275 dma->set_context_ch1(scsi_host);
276 //dma->set_context_ch2(printer);
277 dma->set_context_ch3(cdc);
278 dma->set_context_child_dma(extra_dma);
280 floppy->set_context_fdc(fdc);
281 floppy->set_context_pic(pic);
282 keyboard->set_context_pic(pic);
284 sprite->set_context_vram(vram);
286 //e_volume[0]->set_context_ch0(line_in, MB87878_VOLUME_LEFT);
287 //e_volume[0]->set_context_ch1(line_in, MB87878_VOLUME_RIGHT);
288 //e_volume[0]->set_context_ch2(NULL, MB87878_VOLUME_LEFT);
289 //e_volume[0]->set_context_ch3(NULL, MB87878_VOLUME_RIGHT);
290 e_volume[1]->set_context_ch0(cdc, MB87878_VOLUME_LEFT);
291 e_volume[1]->set_context_ch1(cdc, MB87878_VOLUME_RIGHT);
292 //e_volume[1]->set_context_ch2(mic, MB87878_VOLUME_LEFT | MB87878_VOLUME_RIGHT);
293 //e_volume[1]->set_context_ch3(modem, MB87878_VOLUME_LEFT | MB87878_VOLUME_RIGHT);
295 memory->set_context_vram(vram);
296 memory->set_context_rom(sys_rom);
297 memory->set_context_msdos(msdos_rom);
298 memory->set_context_dictionary(dict_rom);
299 memory->set_context_beep(beep);
300 memory->set_context_serial_rom(serial_rom);
301 memory->set_context_sprite(sprite);
302 memory->set_context_machine_id(machine_id);
303 memory->set_context_cpu_id(cpu_id);
304 memory->set_context_cpu(cpu);
306 cdc->set_context_cdrom(cdrom);
307 cdc->set_context_scsi_host(cdc_scsi);
308 cdc->set_context_drq(dma, SIG_UPD71071_CH3, 0xff);
309 cdc->set_context_pic(pic, SIG_I8259_CHIP1 | SIG_I8259_IR1);
311 crtc->set_context_vsync(pic, SIG_I8259_CHIP1 | SIG_I8259_IR3); // VSYNC
312 sound->set_context_pic(pic, SIG_I8259_CHIP1 | SIG_I8259_IR5); // ADPCM AND OPN2
313 sound->set_context_opn2(opn2);
314 sound->set_context_adpcm(adpcm);
315 sound->set_context_adc(adc);
320 scsi->set_context_dma(dma);
321 scsi->set_context_pic(pic);
322 scsi->set_context_host(scsi_host);
323 timer->set_context_pcm(beep);
324 timer->set_context_pic(pic);
325 timer->set_context_rtc(rtc);
328 cpu->set_context_mem(memory);
329 cpu->set_context_io(io);
330 cpu->set_context_intr(pic);
331 cpu->set_context_dma(dma);
335 cpu->set_context_debugger(new DEBUGGER(this, emu));
340 io->set_iomap_alias_rw(0x00, pic, I8259_ADDR_CHIP0 | 0);
341 io->set_iomap_alias_rw(0x02, pic, I8259_ADDR_CHIP0 | 1);
342 io->set_iomap_alias_rw(0x10, pic, I8259_ADDR_CHIP1 | 0);
343 io->set_iomap_alias_rw(0x12, pic, I8259_ADDR_CHIP1 | 1);
344 io->set_iomap_single_rw(0x20, memory); // reset
345 io->set_iomap_single_r(0x21, memory); // cpu misc
346 io->set_iomap_single_w(0x22, memory); // power
347 //io->set_iomap_single_rw(0x24, memory); // dma
348 io->set_iomap_single_r(0x25, memory); // cpu_misc4 (after Towns2)
349 //io->set_iomap_single_r(0x26, timer);
350 //io->set_iomap_single_r(0x27, timer);
351 io->set_iomap_single_r(0x28, memory); // NMI MASK (after Towns2)
352 io->set_iomap_single_r(0x30, memory); // cpu id
353 io->set_iomap_single_r(0x31, memory); // cpu id
355 io->set_iomap_single_rw(0x32, serial_rom); // serial rom
357 io->set_iomap_alias_rw(0x40, pit0, 0);
358 io->set_iomap_alias_rw(0x42, pit0, 1);
359 io->set_iomap_alias_rw(0x44, pit0, 2);
360 io->set_iomap_alias_rw(0x46, pit0, 3);
361 io->set_iomap_alias_rw(0x50, pit1, 0);
362 io->set_iomap_alias_rw(0x52, pit1, 1);
363 io->set_iomap_alias_rw(0x54, pit1, 2);
364 io->set_iomap_alias_rw(0x56, pit1, 3);
366 io->set_iomap_single_rw(0x60, timer);
367 io->set_iomap_single_rw(0x68, timer); // Interval timer register2 (after Towns 10F).
368 io->set_iomap_single_rw(0x6a, timer); // Interval timer register2 (after Towns 10F).
369 io->set_iomap_single_rw(0x6b, timer); // Interval timer register2 (after Towns 10F).
370 io->set_iomap_single_rw(0x6c, memory); // 1uS wait register (after Towns 10F).
372 io->set_iomap_single_rw(0x70, timer);
373 io->set_iomap_single_w(0x80, timer);
375 io->set_iomap_range_rw(0xa0, 0xaf, dma);
376 io->set_iomap_range_rw(0xb0, 0xbf, extra_dma);
378 io->set_iomap_alias_rw(0x200, fdc, 0);
379 io->set_iomap_alias_rw(0x202, fdc, 1);
380 io->set_iomap_alias_rw(0x204, fdc, 2);
381 io->set_iomap_alias_rw(0x206, fdc, 3);
382 io->set_iomap_single_rw(0x208, floppy);
383 io->set_iomap_single_rw(0x20c, floppy);
384 io->set_iomap_single_rw(0x20e, floppy); // Towns drive SW
386 io->set_iomap_single_rw(0x400, memory); // System Status
387 //io->set_iomap_single_rw(0x402, memory);
388 io->set_iomap_single_rw(0x404, memory); // System status
390 io->set_iomap_range_rw(0x440, 0x443, crtc); // CRTC
391 io->set_iomap_range_rw(0x448, 0x44c, vram); //
392 io->set_iomap_single_rw(0x450, sprite); //
393 io->set_iomap_single_rw(0x452, sprite); //
395 io->set_iomap_range_rw(0x458, 0x45f, vram); // CRTC
397 io->set_iomap_single_rw(0x480, memory); //
398 io->set_iomap_single_rw(0x484, memory); // Dictionary
399 //io->set_iomap_alias_r(0x48a, memory_card, 0); //
400 //io->set_iomap_alias_rw(0x490, memory_card); // After Towns2
401 //io->set_iomap_alias_rw(0x491, memory_card); // After Towns2
403 io->set_iomap_range_rw(0x4c0, 0x4cf, cdc); // CDROM
405 io->set_iomap_alias_r(0x4d0, pad, 0); // Pad1
406 io->set_iomap_alias_r(0x4d2, pad, 1); // Pad 2
407 io->set_iomap_alias_rw(0x4d5, sound, 0); // mute
408 io->set_iomap_alias_w(0x4d6, pad, 3); // Pad out
411 io->set_iomap_alias_rw(0x4d8, opn2, 0); // STATUS(R)/Addrreg 0(W)
412 io->set_iomap_alias_w(0x4da, opn2, 1); // Datareg 0(W)
413 io->set_iomap_alias_w(0x4dc, opn2, 2); // Addrreg 1(W)
414 io->set_iomap_alias_w(0x4de, opn2, 3); // Datareg 1(W)
416 io->set_iomap_alias_rw(0x4e0, e_volume[0], 0);
417 io->set_iomap_alias_rw(0x4e1, e_volume[0], 1);
418 io->set_iomap_alias_rw(0x4e2, e_volume[1], 0);
419 io->set_iomap_alias_rw(0x4e3, e_volume[1], 1);
422 io->set_iomap_single_w(0x4e7, 0x4ff, adpcm); //
424 io->set_iomap_single_rw(0x5c0, memory); // NMI MASK
425 io->set_iomap_single_r(0x5c2, memory); // NMI STATUS
426 io->set_iomap_single_r(0x5c8, vram); // TVRAM EMULATION
427 io->set_iomap_single_w(0x5ca, vram); // VSYNC INTERRUPT
429 io->set_iomap_single_r(0x5e8, memory); // RAM capacity register.(later Towns1H/2H/1F/2F).
430 io->set_iomap_single_r(0x5ec, memory); // RAM Wait register , ofcially after Towns2, but exists after Towns1H.
432 io->set_iomap_single_rw(0x600, keyboard);
433 io->set_iomap_single_rw(0x602, keyboard);
434 io->set_iomap_single_rw(0x604, keyboard);
435 //io->set_iomap_single_r(0x606, keyboard); // BufFul (After Towns2)
437 //io->set_iomap_single_rw(0x800, printer);
438 //io->set_iomap_single_rw(0x802, printer);
439 //io->set_iomap_single_rw(0x804, printer);
441 io->set_iomap_alias_rw(0xa00, sio, 0);
442 io->set_iomap_alias_rw(0xa02, sio, 1);
443 // io->set_iomap_single_r(0xa04, serial);
444 // io->set_iomap_single_r(0xa06, serial);
445 // io->set_iomap_single_w(0xa08, serial);
446 // io->set_iomap_single_rw(0xa0a, modem);
448 io->set_iomap_single_rw(0xc30, scsi);
449 io->set_iomap_single_rw(0xc32, scsi);
452 io->set_iomap_range_rw(0x3000, 0x3fff, memory); // CMOS
453 io->set_iomap_range_rw(0xfd90, 0xfda0, vram); // Palette and CRTC
455 // Vram allocation may be before initialize().
456 bool alloc_failed = false;
457 for(int bank = 0; bank < 2; bank++) {
458 if(alloc_failed) break;
459 for(int layer = 0; layer < 2; layer++) {
460 d_renderbuffer[bank][layer] = NULL;
461 renderbuffer_size[bank][layer] = 0;
463 uint32_t initial_width = 640;
464 uint32_t initial_height = 480;
465 uint32_t initial_stride = 640;
466 uint32_t __size = initial_stride * initial_height * sizeof(scrntype_t);
467 scrntype_t *p = (scrntype_t*)malloc(__size);
472 memset(p, 0x00, __size);
473 renderbuffer_size[bank][layer] = __size;
474 d_renderbuffer[bank][layer] = p;
475 d_vram->set_context_renderbuffer(p, layer, bank, width, height, stride);
480 for(int bank = 0; bank < 2; bank++) {
481 for(int layer = 0; layer < 2; layer++) {
482 renderbuffer_size[bank][layer] = 0;
483 if(d_renderbuffer[bank][layer] != NULL) {
484 free((void *)(d_renderbuffer[bank][layer]));
486 d_renderbuffer[bank][layer] = NULL;
487 d_vram->set_context_renderbuffer(NULL, layer, bank, 0, 0, 0);
491 // initialize all devices
492 #if defined(__GIT_REPO_VERSION)
493 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
495 for(DEVICE* device = first_device; device; device = device->next_device) {
496 device->initialize();
502 // delete all devices
503 for(DEVICE* device = first_device; device;) {
504 DEVICE *next_device = device->next_device;
507 device = next_device;
511 DEVICE* VM::get_device(int id)
513 for(DEVICE* device = first_device; device; device = device->next_device) {
514 if(device->this_device_id == id) {
521 void VM::set_machine_type(uint16_t machine_id, uint16_t cpu_id)
524 memory->set_cpu_id(cpu_id);
525 memory->set_machine_id(machine_id);
528 vram->set_cpu_id(cpu_id);
529 vram->set_machine_id(machine_id);
532 sprite->set_cpu_id(cpu_id);
533 sprite->set_machine_id(machine_id);
535 if(sys_rom != NULL) {
536 sysrom->set_cpu_id(cpu_id);
537 sysrom->set_machine_id(machine_id);
539 if(msdos_rom != NULL) {
540 msdosrom->set_cpu_id(cpu_id);
541 msdosrom->set_machine_id(machine_id);
543 if(dictinoary != NULL) {
544 dictionary->set_cpu_id(cpu_id);
545 dictionary->set_machine_id(machine_id);
547 if(fontrom != NULL) {
548 fontrom->set_cpu_id(cpu_id);
549 fontrom->set_machine_id(machine_id);
551 if(serialrom != NULL) {
552 serialrom->set_cpu_id(cpu_id);
553 serialrom->set_machine_id(machine_id);
556 crtc->set_cpu_id(cpu_id);
557 crtc->set_machine_id(machine_id);
560 cdc->set_cpu_id(cpu_id);
561 cdc->set_machine_id(machine_id);
563 #if defined(HAS_20PIX_FONTS)
564 if(fontrom_20pix != NULL) {
565 fontrom_20pix->set_cpu_id(cpu_id);
566 fontrom_20pix->set_machine_id(machine_id);
573 // ----------------------------------------------------------------------------
574 // drive virtual machine
575 // ----------------------------------------------------------------------------
580 for(DEVICE* device = first_device; device; device = device->next_device) {
584 for(DEVICE* device = first_device; device; device = device->next_device) {
594 // ----------------------------------------------------------------------------
596 // ----------------------------------------------------------------------------
599 DEVICE *VM::get_cpu(int index)
608 // ----------------------------------------------------------------------------
610 // ----------------------------------------------------------------------------
612 void VM::draw_screen()
614 memory->draw_screen();
617 uint32_t VM::is_floppy_disk_accessed()
619 return fdc->read_signal(0);
622 // ----------------------------------------------------------------------------
624 // ----------------------------------------------------------------------------
626 void VM::initialize_sound(int rate, int samples)
628 // init sound manager
629 event->initialize_sound(rate, samples);
632 beep->initialize_sound(rate, 8000);
635 uint16_t* VM::create_sound(int* extra_frames)
637 return event->create_sound(extra_frames);
640 int VM::get_sound_buffer_ptr()
642 return event->get_sound_buffer_ptr();
645 // ToDo: Sound IN as double buffer.
646 bool VM::clear_sound_in()
649 sound_in_buf_bank = !sound_in_buf_bank;
652 sound_in_buf = sound_in_buf_pool[(sound_in_buf_bank) ? 1 : 0];
653 if(sound_in_buf != NULL) {
654 memset(sound_in_buf, 0x00, sound_in_bufsize * 2 * sizeof(int32_t));
659 for(int ch = 0; ch < 4; ch++) {
660 sound_in_bufptr[ch] = 0;
667 void VM::initialize_sample_in_buf(int samples)
669 sound_in_bufsize = 0;
671 if(samples <= 0) return;
673 sound_in_bufsize = samples;
674 sound_in_buf_pool = (int32_t*)malloc(samples * sizeof(int32_t) * 2);
678 int VM::get_samples_in_buf(int ch, int32* dst, int samples)
681 if(samples <= 0) return 0;
682 if(samples >= sound_in_bufsize) return 0;
683 if((sound_in_outptr + samples) >= sound_in_bufsize) {
684 samples = sound_in_bufsize - sound_in_outptr;
688 memcpy(dst, &(sound_in_buf[sound_in_outptr << 1]), samples * sizeof(int32_t) * 2);
694 int VM::get_samples_length_sound_in()
696 return sound_in_bufsize;
699 int VM::sound_in(int ch, int32* src, int samples)
702 if(ch >= 4) return 0;
704 int np = sound_in_bufptr[ch];
706 for(;left > 0; left--) {
707 if(np >= (sound_in_bufsize << 1)) break;
709 sound_in_buf[np + 0] = sound_in_buf[np + 0] + src[sp + 0];
710 sound_in_buf[np + 1] = sound_in_buf[np + 1] + src[sp + 1];
711 if(sound_in_buf[np + 0] > 32767) sound_in_buf[np + 0] = 32767;
712 if(sound_in_buf[np + 0] < -32768) sound_in_buf[np + 0] = -32768;
713 if(sound_in_buf[np + 1] > 32767) sound_in_buf[np + 1] = 32767;
714 if(sound_in_buf[np + 1] < -32768) sound_in_buf[np + 1] = -32768;
722 #ifdef USE_SOUND_VOLUME
723 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
725 #ifndef HAS_LINEIN_SOUND
728 #ifndef HAS_MIC_SOUND
731 #ifndef HAS_MODEM_SOUND
734 #ifndef HAS_2ND_ADPCM
737 if(ch == 0) { // BEEP
738 beep->set_volume(0, decibel_l, decibel_r);
740 else if(ch == 1) { // CD-ROM
741 e_volume[1]->set_volume(0, decibel_l);
742 e_volume[1]->set_volume(1, decibel_r);
744 else if(ch == 2) { // OPN2
745 opn2->set_volume(0, decibel_l, decibel_r);
747 else if(ch == 3) { // ADPCM
748 adpcm->set_volume(0, decibel_l, decibel_r);
750 else if(ch == 4) { // LINE IN
751 e_volume[0]->set_volume(0, decibel_l);
752 e_volume[0]->set_volume(1, decibel_r);
754 else if(ch == 5) { // MIC
755 e_volume[1]->set_volume(2, (decibel_l + decibel_r) / 2);
757 else if(ch == 6) { // MODEM
758 e_volume[1]->set_volume(2, (decibel_l + decibel_r) / 2);
760 else if(ch == 7) { // ADPCM
761 adpcm2->set_volume(0, decibel_l, decibel_r);
763 else if(ch == 8) { // FDD
764 fdc->set_volume(0, decibel_l, decibel_r);
766 else if(ch == 9) { // HDD(ToDo)
767 fdc->set_volume(0, decibel_l, decibel_r);
773 // ----------------------------------------------------------------------------
775 // ----------------------------------------------------------------------------
777 void VM::key_down(int code, bool repeat)
779 keyboard->key_down(code);
782 void VM::key_up(int code)
784 keyboard->key_up(code);
787 // ----------------------------------------------------------------------------
789 // ----------------------------------------------------------------------------
791 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
793 fdc->open_disk(drv, file_path, bank);
794 floppy->change_disk(drv);
797 void VM::close_floppy_disk(int drv)
799 fdc->close_disk(drv);
802 bool VM::is_floppy_disk_inserted(int drv)
804 return fdc->is_disk_inserted(drv);
807 void VM::is_floppy_disk_protected(int drv, bool value)
809 fdc->is_disk_protected(drv, value);
812 bool VM::is_floppy_disk_protected(int drv)
814 return fdc->is_disk_protected(drv);
817 bool VM::is_frame_skippable()
819 return event->is_frame_skippable();
822 void VM::update_config()
824 for(DEVICE* device = first_device; device; device = device->next_device) {
825 device->update_config();
829 #define STATE_VERSION 3
831 void VM::save_state(FILEIO* state_fio)
833 state_fio->FputUint32(STATE_VERSION);
835 for(DEVICE* device = first_device; device; device = device->next_device) {
836 device->save_state(state_fio);
840 bool VM::load_state(FILEIO* state_fio)
842 if(state_fio->FgetUint32() != STATE_VERSION) {
845 for(DEVICE* device = first_device; device; device = device->next_device) {
846 if(!device->load_state(state_fio)) {