2 TOSHIBA J-3100GT Emulator 'eJ-3100GT'
3 TOSHIBA J-3100SL Emulator 'eJ-3100SL'
5 Author : Takeda.Toshiya
12 #include "../../emu.h"
13 #include "../device.h"
16 #include "../hd46505.h"
18 //#include "../i8250.h"
23 #include "../pcm1bit.h"
24 #include "../upd765a.h"
26 #include "../rp5c01.h"
28 #include "../hd146818p.h"
36 #include "slkeyboard.h"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 VM::VM(EMU* parent_emu) : emu(parent_emu)
52 first_device = last_device = NULL;
53 dummy = new DEVICE(this, emu); // must be 1st device
54 event = new EVENT(this, emu); // must be 2nd device
56 crtc = new HD46505(this, emu);
57 dma = new I8237(this, emu);
59 dma2 = new I8237(this, emu);
61 // sio = new I8250(this, emu);
62 pit = new I8253(this, emu); // i8254
63 pic = new I8259(this, emu);
64 cpu = new I86(this, emu);
65 io = new IO(this, emu);
66 pcm = new PCM1BIT(this, emu);
67 fdc = new UPD765A(this, emu);
69 rtc = new RP5C01(this, emu);
71 rtc = new HD146818P(this, emu);
74 display = new DISPLAY(this, emu);
75 dmareg = new DMAREG(this, emu);
76 floppy = new FLOPPY(this, emu);
77 keyboard = new KEYBOARD(this, emu);
78 memory = new MEMORY(this, emu);
79 sasi = new SASI(this, emu);
80 system = new SYSTEM(this, emu);
83 event->set_context_cpu(cpu);
84 event->set_context_sound(pcm);
87 cpu->set_context_mem(memory);
88 cpu->set_context_io(io);
89 cpu->set_context_intr(pic);
92 io->set_iomap_range_rw(0x00, 0x0f, dma);
93 io->set_iomap_range_w(0x80, 0x8f, dmareg);
94 dma->set_context_memory(memory);
95 dma->set_context_ch2(fdc);
96 dmareg->set_context_dma(dma);
98 for(int i = 0xc0; i <= 0xde; i += 2) {
99 io->set_iomap_alias_rw(i, dma2, i >> 1);
101 dma2->set_context_memory(memory);
102 dma2->set_word_mode(true);
103 dmareg->set_context_dma2(dma2);
107 io->set_iomap_alias_rw(0x20, pic, I8259_ADDR_CHIP0 | 0);
108 io->set_iomap_alias_rw(0x21, pic, I8259_ADDR_CHIP0 | 1);
110 io->set_iomap_alias_rw(0xa0, pic, I8259_ADDR_CHIP1 | 0);
111 io->set_iomap_alias_rw(0xa1, pic, I8259_ADDR_CHIP1 | 1);
113 pic->set_context_cpu(cpu);
116 io->set_iomap_range_rw(0x40, 0x43, pit);
117 pit->set_constant_clock(0, 1190000);
118 pit->set_constant_clock(1, 1190000);
119 pit->set_constant_clock(2, 1190000);
120 pit->set_context_ch0(pic, SIG_I8259_IR0 | SIG_I8259_CHIP0, 1); // to PIC#0 IR0
121 pit->set_context_ch2(pcm, SIG_PCM1BIT_SIGNAL, 1);
123 pit->set_context_ch2(system, SIG_SYSTEM_TC2O, 1);
126 // system status/command
128 io->set_iomap_single_rw(0x61, system);
129 system->set_context_pcm(pcm);
130 system->set_context_pit(pit);
135 io->set_iomap_range_rw(0x2c0, 0x2cf, rtc);
137 io->set_iomap_alias_w(0x70, rtc, 1); // bit7 = nmi mask
138 io->set_iomap_alias_rw(0x71, rtc, 0);
139 rtc->set_context_intr(pic, SIG_I8259_IR0 | SIG_I8259_CHIP1, 1); // to PIC#1 IR0 (IR8)
144 io->set_iomap_single_w(0xa0, system);
146 // 0x70 bit7 (not implemented)
150 io->set_iomap_range_rw(0x3d0, 0x3d1, crtc);
151 io->set_iomap_range_rw(0x3d4, 0x3d5, crtc);
152 io->set_iomap_range_w(0x3d8, 0x3d9, display);
153 io->set_iomap_single_r(0x3da, display);
154 crtc->set_context_disp(display, SIG_DISPLAY_ENABLE, 1);
155 crtc->set_context_vblank(display, SIG_DISPLAY_VBLANK, 1);
156 display->set_regs_ptr(crtc->get_regs());
157 display->set_vram_ptr(memory->get_vram());
160 io->set_iomap_single_w(0x3f2, floppy);
161 io->set_iomap_range_rw(0x3f4, 0x3f5, fdc);
162 io->set_iomap_single_rw(0x3f7, floppy);
163 fdc->set_context_irq(pic, SIG_I8259_IR6 | SIG_I8259_CHIP0, 1); // to PIC#0 IR6
164 fdc->set_context_drq(dma, SIG_I8237_CH2, 1); // to DMA Ch.2
165 floppy->set_context_fdc(fdc);
168 io->set_flipflop_single_rw(0x378, 0x00);
169 io->set_iovalue_single_r(0x379, 0x78);
170 io->set_flipflop_single_rw(0x37a, 0x00);
174 io->set_iomap_range_rw(0x60, 0x61, keyboard);
177 keyboard->set_context_pic(pic);
182 #if defined(_J3100GT) || defined(TYPE_SL)
183 io->set_iomap_range_rw(0x1f0, 0x1f3, sasi);
184 sasi->set_context_pic(pic);
188 static const int ems_addr[] = {
189 0x208, 0x4208, 0x8208, 0xc208,
190 0x218, 0x4218, 0x8218, 0xc218,
191 0x258, 0x4258, 0x8258, 0xc258,
192 0x268, 0x4268, 0x8268, 0xc268,
194 0x2a8, 0x42a8, 0x82a8, 0xc2a8,
195 0x2b8, 0x42b8, 0x82b8, 0xc2b8,
196 0x2e8, 0x42e8, 0x82e8, 0xc2e8,
199 for(int i = 0; i < array_length(ems_addr); i++) {
200 io->set_iomap_single_rw(ems_addr[i], memory);
202 io->set_iomap_single_w(ems_addr[i] + 1, memory);
206 io->set_iomap_range_rw(0xee, 0xef, memory);
209 // special registers for J-3100SL/SS/SE
212 // bit1 1=8087
\82 \82è
213 io->set_iovalue_single_r(0x62, 0x26); // unknown
214 // io->set_flipflop_single_rw(0x63, 0x00); // unknown
215 static const int iovalues[0x20] = {
216 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x14, 0xff, 0xff, 0x00, 0xff, 0xe0, 0xff, 0x00, 0xff, 0xff,
217 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
219 for(int i = 0xe0; i <= 0xff; i++) {
220 if(i == 0xee && i == 0xef) {
223 io->set_flipflop_single_rw(i, iovalues[i & 0x1f]);
231 // initialize all devices
232 for(DEVICE* device = first_device; device; device = device->next_device) {
233 device->initialize();
239 // delete all devices
240 for(DEVICE* device = first_device; device;) {
241 DEVICE *next_device = device->next_device;
244 device = next_device;
248 DEVICE* VM::get_device(int id)
250 for(DEVICE* device = first_device; device; device = device->next_device) {
251 if(device->this_device_id == id) {
258 // ----------------------------------------------------------------------------
259 // drive virtual machine
260 // ----------------------------------------------------------------------------
265 for(DEVICE* device = first_device; device; device = device->next_device) {
275 // ----------------------------------------------------------------------------
277 // ----------------------------------------------------------------------------
279 void VM::draw_screen()
281 display->draw_screen();
284 int VM::access_lamp()
286 uint32 status = fdc->read_signal(0);
287 return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
290 // ----------------------------------------------------------------------------
292 // ----------------------------------------------------------------------------
294 void VM::initialize_sound(int rate, int samples)
296 // init sound manager
297 event->initialize_sound(rate, samples);
300 pcm->init(rate, 8000);
303 uint16* VM::create_sound(int* extra_frames)
305 return event->create_sound(extra_frames);
308 int VM::sound_buffer_ptr()
310 return event->sound_buffer_ptr();
313 // ----------------------------------------------------------------------------
315 // ----------------------------------------------------------------------------
317 void VM::key_down(int code, bool repeat)
319 keyboard->key_down(code);
322 void VM::key_up(int code)
324 keyboard->key_up(code);
327 // ----------------------------------------------------------------------------
329 // ----------------------------------------------------------------------------
331 void VM::open_disk(int drv, const _TCHAR* file_path, int bank)
333 fdc->open_disk(drv, file_path, bank);
336 void VM::close_disk(int drv)
338 fdc->close_disk(drv);
341 bool VM::disk_inserted(int drv)
343 return fdc->disk_inserted(drv);
346 void VM::set_disk_protected(int drv, bool value)
348 fdc->set_disk_protected(drv, value);
351 bool VM::get_disk_protected(int drv)
353 return fdc->get_disk_protected(drv);
358 return event->now_skip();
361 void VM::update_config()
363 for(DEVICE* device = first_device; device; device = device->next_device) {
364 device->update_config();