2 IBM Japan Ltd PC/JX Emulator 'eJX'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
16 #include "../hd46505.h"
23 #include "../memory.h"
25 #include "../pcm1bit.h"
26 #include "../sn76489an.h"
27 #include "../upd765a.h"
30 #include "../debugger.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 VM::VM(EMU* parent_emu) : emu(parent_emu)
45 first_device = last_device = NULL;
46 dummy = new DEVICE(this, emu); // must be 1st device
47 event = new EVENT(this, emu); // must be 2nd device
48 dummy->set_device_name(_T("1st Dummy"));
50 crtc = new HD46505(this, emu);
51 sio = new I8251(this, emu);
52 pit = new I8253(this, emu);
53 pio = new I8255(this, emu);
54 pic = new I8259(this, emu);
55 cpu = new I86(this, emu); // 8088
56 io = new IO(this, emu);
57 mem = new MEMORY(this, emu);
58 pcm = new PCM1BIT(this, emu);
59 psg = new SN76489AN(this, emu); // SN76496N
60 fdc = new UPD765A(this, emu);
61 fdc->set_context_noise_seek(new NOISE(this, emu));
62 fdc->set_context_noise_head_down(new NOISE(this, emu));
63 fdc->set_context_noise_head_up(new NOISE(this, emu));
65 display = new DISPLAY(this, emu);
66 floppy = new FLOPPY(this, emu);
67 keyboard = new KEYBOARD(this, emu);
68 speaker = new SPEAKER(this, emu);
69 /* IRQ 0 Timer Clock Interrupt
70 1 I/O Channel (Reserved)
72 3 Asynchronous Port Interrupt (RS-232C)
74 5 Vertical Retrace Interrupt (Display)
75 6 Diskette Interrupt (WDT)
76 7 I/O Channel (Parallel Printer)
80 event->set_context_cpu(cpu);
81 event->set_context_sound(pcm);
82 event->set_context_sound(fdc->get_context_noise_seek());
83 event->set_context_sound(fdc->get_context_noise_head_down());
84 event->set_context_sound(fdc->get_context_noise_head_up());
87 cpu->set_context_mem(mem);
88 cpu->set_context_io(io);
89 cpu->set_context_intr(pic);
91 cpu->set_context_debugger(new DEBUGGER(this, emu));
94 crtc->set_context_disp(display, SIG_DISPLAY_ENABLE, 1);
95 crtc->set_context_vblank(display, SIG_DISPLAY_VBLANK, 1);
96 crtc->set_context_vblank(pic, SIG_I8259_IR5, 1);
101 pit->set_constant_clock(0, CPU_CLOCKS / 4);
103 pit->set_constant_clock(1, CPU_CLOCKS / 4);
105 pit->set_constant_clock(2, CPU_CLOCKS / 4);
106 pit->set_context_ch0(pic, SIG_I8259_IR0, 1); // to IRQ0
108 pit->set_context_ch0(keyboard, SIG_KEYBOARD_TIMER, 1); // to clock of timer1
110 pit->set_context_ch2(pio, SIG_I8255_PORT_C, 0x20); // to PC5
111 pit->set_context_ch2(pcm, SIG_PCM1BIT_SIGNAL, 0x20); // to speaker
112 pio->set_context_port_b(pit, SIG_I8253_GATE_2, 0x01, 0); // PB0
113 pio->set_context_port_b(speaker, SIG_SPEAKER_PIO, 0x62, 0); // PB1+5+6
114 pio->set_context_port_b(display, SIG_DISPLAY_PIO, 0x04, 0); // PB2
115 pic->set_context_cpu(cpu);
117 display->set_context_mem(mem);
118 display->set_regs_ptr(crtc->get_regs());
119 floppy->set_context_fdc(fdc);
120 floppy->set_context_pic(pic);
121 keyboard->set_context_cpu(cpu);
122 keyboard->set_context_pio(pio);
123 keyboard->set_context_pit(pit);
124 speaker->set_context_pcm(pcm);
125 speaker->set_context_psg(psg);
129 // 80000-B7FFF KANJI ROM ???
130 // A0000-A7FFF EXT-VRAM
132 // D0000-FFFFF CART+IPL
134 memset(font, 0xff, sizeof(font));
135 memset(kanji, 0xff, sizeof(kanji));
136 memset(ram, 0, sizeof(ram));
137 memset(ipl, 0xff, sizeof(ipl));
139 mem->read_bios(_T("FONT.ROM"), font, sizeof(font));
140 mem->read_bios(_T("KANJI.ROM"), kanji, sizeof(kanji));
141 int length = mem->read_bios(_T("IPL.ROM"), ipl, sizeof(ipl));
142 int offset = 0x30000 - length;
143 memmove(ipl + offset, ipl, length);
144 memset(ipl, 0xff, offset);
146 mem->set_memory_rw(0x00000, 0x7ffff, ram);
147 // mem->set_memory_r(0x80000, 0xb7fff, kanji);
148 mem->set_memory_r(0xd0000, 0xfffff, ipl);
150 display->set_font_ptr(font);
151 display->set_kanji_ptr(kanji);
154 for(int i = 0x20; i <= 0x27; i++) {
155 io->set_iomap_alias_rw(i, pic, i & 1);
157 io->set_iomap_range_rw(0x40, 0x43, pit);
158 io->set_iomap_range_rw(0x60, 0x67, pio);
159 io->set_iomap_range_rw(0xa0, 0xa7, keyboard);
160 io->set_iomap_range_w(0xc0, 0xc7, psg);
162 io->set_iomap_single_w(0xf2, floppy);
163 io->set_iomap_range_rw(0xf4, 0xf5, fdc);
165 io->set_iomap_single_rw(0x1ff, display);
167 /// io->set_iovalue_range_r(0x200, 0x207, 0);
169 io->set_iomap_range_rw(0x3d0, 0x3d1, crtc);
170 io->set_iomap_range_rw(0x3d4, 0x3d5, crtc);
171 io->set_iomap_range_rw(0x3d8, 0x3df, display);
173 // initialize all devices
174 for(DEVICE* device = first_device; device; device = device->next_device) {
175 device->initialize();
177 for(int i = 0; i < 4; i++) {
178 fdc->set_drive_type(i, DRIVE_TYPE_2DD);
184 // delete all devices
185 for(DEVICE* device = first_device; device;) {
186 DEVICE *next_device = device->next_device;
189 device = next_device;
193 DEVICE* VM::get_device(int id)
195 for(DEVICE* device = first_device; device; device = device->next_device) {
196 if(device->this_device_id == id) {
203 // ----------------------------------------------------------------------------
204 // drive virtual machine
205 // ----------------------------------------------------------------------------
210 for(DEVICE* device = first_device; device; device = device->next_device) {
214 // initial device settings
215 pio->write_signal(SIG_I8255_PORT_C, 0x02, 0x02); // PC1=1: Modem card is not installed
216 pio->write_signal(SIG_I8255_PORT_C, 0x00, 0x04); // PC2=0: Diskette card is installed
217 // pio->write_signal(SIG_I8255_PORT_C, 0x04, 0x04); // PC2=0: Diskette card is no installed
218 pio->write_signal(SIG_I8255_PORT_C, 0x00, 0x08); // PC3=0: 64KB Memory and Display Expansion is installed
219 pio->write_signal(SIG_I8255_PORT_C, 0x00, 0x80); // PC7=0: Keyboard cable is connected
227 // ----------------------------------------------------------------------------
229 // ----------------------------------------------------------------------------
232 DEVICE *VM::get_cpu(int index)
241 // ----------------------------------------------------------------------------
243 // ----------------------------------------------------------------------------
245 void VM::draw_screen()
247 display->draw_screen();
250 // ----------------------------------------------------------------------------
252 // ----------------------------------------------------------------------------
254 void VM::initialize_sound(int rate, int samples)
256 // init sound manager
257 event->initialize_sound(rate, samples);
260 pcm->initialize_sound(rate, 8000);
261 psg->initialize_sound(rate, 3579545, 8000);
264 uint16_t* VM::create_sound(int* extra_frames)
266 return event->create_sound(extra_frames);
269 int VM::get_sound_buffer_ptr()
271 return event->get_sound_buffer_ptr();
274 #ifdef USE_SOUND_VOLUME
275 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
278 pcm->set_volume(0, decibel_l, decibel_r);
280 fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
281 fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
282 fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
287 // ----------------------------------------------------------------------------
289 // ----------------------------------------------------------------------------
291 void VM::key_down(int code, bool repeat)
293 keyboard->key_down(code);
296 void VM::key_up(int code)
298 keyboard->key_up(code);
301 // ----------------------------------------------------------------------------
303 // ----------------------------------------------------------------------------
305 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
307 fdc->open_disk(drv, file_path, bank);
310 void VM::close_floppy_disk(int drv)
312 fdc->close_disk(drv);
315 bool VM::is_floppy_disk_inserted(int drv)
317 return fdc->is_disk_inserted(drv);
320 void VM::is_floppy_disk_protected(int drv, bool value)
322 fdc->is_disk_protected(drv, value);
325 bool VM::is_floppy_disk_protected(int drv)
327 return fdc->is_disk_protected(drv);
330 uint32_t VM::is_floppy_disk_accessed()
332 return fdc->read_signal(0);
335 bool VM::is_frame_skippable()
337 return event->is_frame_skippable();
340 void VM::update_config()
342 for(DEVICE* device = first_device; device; device = device->next_device) {
343 device->update_config();