2 SHARP MZ-2800 Emulator 'EmuZ-2800'
\r
4 Author : Takeda.Toshiya
\r
11 #include "../../emu.h"
\r
12 #include "../device.h"
\r
13 #include "../event.h"
\r
15 #include "../i8253.h"
\r
16 #include "../i8255.h"
\r
17 #include "../i8259.h"
\r
18 #include "../i286.h"
\r
20 #include "../mb8877.h"
\r
21 #include "../pcm1bit.h"
\r
22 #include "../rp5c01.h"
\r
23 //#include "../sasi.h"
\r
24 #include "../upd71071.h"
\r
25 #include "../ym2203.h"
\r
26 #include "../z80pio.h"
\r
27 #include "../z80sio.h"
\r
30 #include "../debugger.h"
\r
35 #include "joystick.h"
\r
36 #include "keyboard.h"
\r
41 #include "sysport.h"
\r
43 // ----------------------------------------------------------------------------
\r
45 // ----------------------------------------------------------------------------
\r
47 VM::VM(EMU* parent_emu) : emu(parent_emu)
\r
50 first_device = last_device = NULL;
\r
51 dummy = new DEVICE(this, emu); // must be 1st device
\r
52 event = new EVENT(this, emu); // must be 2nd device
\r
54 cpu = new I286(this, emu);
\r
55 pit = new I8253(this, emu);
\r
56 pio0 = new I8255(this, emu);
\r
57 pic = new I8259(this, emu);
\r
58 io = new IO(this, emu);
\r
59 fdc = new MB8877(this, emu);
\r
60 pcm = new PCM1BIT(this, emu);
\r
61 rtc = new RP5C01(this, emu); // RP-5C15
\r
62 // sasi = new SASI(this, emu);
\r
63 dma = new UPD71071(this, emu);
\r
64 opn = new YM2203(this, emu);
\r
65 pio1 = new Z80PIO(this, emu);
\r
66 sio = new Z80SIO(this, emu);
\r
68 crtc = new CRTC(this, emu);
\r
69 floppy = new FLOPPY(this, emu);
\r
70 joystick = new JOYSTICK(this, emu);
\r
71 keyboard = new KEYBOARD(this, emu);
\r
72 memory = new MEMORY(this, emu);
\r
73 mouse = new MOUSE(this, emu);
\r
74 rst = new RESET(this, emu);
\r
75 serial = new SERIAL(this, emu);
\r
76 sysport = new SYSPORT(this, emu);
\r
79 event->set_context_cpu(cpu);
\r
80 event->set_context_sound(opn);
\r
81 event->set_context_sound(pcm);
\r
83 pit->set_constant_clock(0, 31250);
\r
84 pit->set_constant_clock(2, 31250);
\r
85 pit->set_context_ch0(pit, SIG_I8253_CLOCK_1, 1);
\r
86 pit->set_context_ch0(pic, SIG_I8259_CHIP0 | SIG_I8259_IR0, 1);
\r
87 pit->set_context_ch1(pic, SIG_I8259_CHIP0 | SIG_I8259_IR6, 1);
\r
88 pit->set_context_ch2(pic, SIG_I8259_CHIP1 | SIG_I8259_IR0, 1);
\r
89 pio0->set_context_port_c(rst, SIG_RESET_CONTROL, 0xff, 0);
\r
90 pio0->set_context_port_c(crtc, SIG_CRTC_MASK, 0x01, 0);
\r
91 pio0->set_context_port_c(pcm, SIG_PCM1BIT_SIGNAL, 0x04, 0);
\r
92 pic->set_context_cpu(cpu);
\r
93 fdc->set_context_drq(dma, SIG_UPD71071_CH1, 1);
\r
94 fdc->set_context_irq(pic, SIG_I8259_CHIP0 | SIG_I8259_IR5, 1);
\r
95 rtc->set_context_alarm(pic, SIG_I8259_CHIP1 | SIG_I8259_IR2, 1);
\r
96 rtc->set_context_pulse(opn, SIG_YM2203_PORT_B, 8);
\r
97 // sasi->set_context_drq(dma, SIG_UPD71071_CH0, 1);
\r
98 // sasi->set_context_irq(pic, SIG_I8259_CHIP0 | SIG_I8259_IR4, 1);
\r
99 dma->set_context_memory(memory);
\r
100 // dma->set_context_ch0(sasi);
\r
101 dma->set_context_ch1(fdc);
\r
102 dma->set_context_tc(pic, SIG_I8259_CHIP0 | SIG_I8259_IR3, 1);
\r
103 opn->set_context_irq(pic, SIG_I8259_CHIP1 | SIG_I8259_IR7, 1);
\r
104 opn->set_context_port_a(crtc, SIG_CRTC_PALLETE, 0x04, 0);
\r
105 opn->set_context_port_a(mouse, SIG_MOUSE_SEL, 0x08, 0);
\r
106 pio1->set_context_port_a(crtc, SIG_CRTC_COLUMN_SIZE, 0x20, 0);
\r
107 pio1->set_context_port_a(keyboard, SIG_KEYBOARD_COLUMN, 0xff, 0);
\r
108 sio->set_context_intr(pic, SIG_I8259_CHIP0 | SIG_I8259_IR2);
\r
109 sio->set_context_dtr1(mouse, SIG_MOUSE_DTR, 1);
\r
111 crtc->set_context_pic(pic);
\r
112 crtc->set_context_pio(pio0);
\r
113 crtc->set_vram_ptr(memory->get_vram());
\r
114 crtc->set_tvram_ptr(memory->get_tvram());
\r
115 crtc->set_kanji_ptr(memory->get_kanji());
\r
116 crtc->set_pcg_ptr(memory->get_pcg());
\r
117 floppy->set_context_fdc(fdc);
\r
118 keyboard->set_context_pio0(pio0);
\r
119 keyboard->set_context_pio1(pio1);
\r
120 memory->set_context_crtc(crtc);
\r
121 mouse->set_context_sio(sio);
\r
122 serial->set_context_sio(sio);
\r
123 sysport->set_context_pit(pit);
\r
124 sysport->set_context_sio(sio);
\r
127 cpu->set_context_mem(memory);
\r
128 cpu->set_context_io(io);
\r
129 cpu->set_context_intr(pic);
\r
130 #ifdef SINGLE_MODE_DMA
\r
131 cpu->set_context_dma(dma);
\r
133 #ifdef USE_DEBUGGER
\r
134 cpu->set_context_debugger(new DEBUGGER(this, emu));
\r
138 io->set_iomap_range_rw(0x70, 0x7f, dma);
\r
139 io->set_iomap_alias_rw(0x80, pic, I8259_ADDR_CHIP0 | 0);
\r
140 io->set_iomap_alias_rw(0x81, pic, I8259_ADDR_CHIP0 | 1);
\r
141 io->set_iomap_alias_rw(0x82, pic, I8259_ADDR_CHIP1 | 0);
\r
142 io->set_iomap_alias_rw(0x83, pic, I8259_ADDR_CHIP1 | 1);
\r
143 io->set_iomap_range_rw(0x8c, 0x8d, memory);
\r
144 io->set_iovalue_single_r(0x8e, 0xff); // dipswitch
\r
145 io->set_flipflop_single_rw(0x8f, 0x00); // shut
\r
146 io->set_iomap_range_rw(0xa0, 0xa3, serial);
\r
147 for(uint32 p = 0xae; p <= 0x1fae; p += 0x100) {
\r
148 io->set_iomap_single_w(p, crtc);
\r
150 // io->set_iomap_single_rw(0xaf, sasi);
\r
151 io->set_iomap_range_rw(0xb0, 0xb3, serial);
\r
152 io->set_iomap_single_r(0xbe, sysport);
\r
153 io->set_iomap_range_rw(0xc8, 0xc9, opn);
\r
154 io->set_iovalue_single_r(0xca, 0x7f); // voice communication ???
\r
155 for(uint32 p = 0xcc; p <= 0xfcc; p += 0x100) {
\r
156 io->set_iomap_alias_rw(p, rtc, p >> 8);
\r
158 io->set_iomap_single_w(0xcd, serial);
\r
159 io->set_iomap_single_rw(0xce, memory);
\r
160 io->set_iomap_range_rw(0xd8, 0xdb, fdc);
\r
161 io->set_iomap_range_w(0xdc, 0xdf, floppy);
\r
162 io->set_iomap_range_rw(0xe0, 0xe3, pio0);
\r
163 io->set_iomap_range_rw(0xe4, 0xe7, pit);
\r
164 io->set_iomap_range_rw(0xe8, 0xeb, pio1);
\r
165 io->set_iomap_single_rw(0xef, joystick);
\r
166 // io->set_iomap_range_w(0xf0, 0xf3, sysport);
\r
167 io->set_iomap_single_w(0x170, crtc);
\r
168 io->set_iomap_single_w(0x172, crtc);
\r
169 io->set_iomap_single_w(0x174, crtc);
\r
170 io->set_iomap_single_w(0x176, crtc);
\r
171 io->set_iomap_range_w(0x178, 0x17b, crtc);
\r
172 io->set_iomap_single_w(0x270, crtc);
\r
173 io->set_iomap_single_w(0x272, crtc);
\r
174 io->set_iomap_single_rw(0x274, memory);
\r
176 // initialize all devices
\r
177 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
178 device->initialize();
\r
184 // delete all devices
\r
185 for(DEVICE* device = first_device; device;) {
\r
186 DEVICE *next_device = device->next_device;
\r
189 device = next_device;
\r
193 DEVICE* VM::get_device(int id)
\r
195 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
196 if(device->this_device_id == id) {
\r
203 // ----------------------------------------------------------------------------
\r
204 // drive virtual machine
\r
205 // ----------------------------------------------------------------------------
\r
209 // reset all devices
\r
210 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
213 // temporary fix...
\r
214 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
218 // set initial port status
\r
219 pio0->write_signal(SIG_I8255_PORT_B, 0x7c, 0xff);
\r
220 opn->write_signal(SIG_YM2203_PORT_B, 0x37, 0xff);
\r
223 void VM::cpu_reset()
\r
233 // ----------------------------------------------------------------------------
\r
235 // ----------------------------------------------------------------------------
\r
237 #ifdef USE_DEBUGGER
\r
238 DEVICE *VM::get_cpu(int index)
\r
247 // ----------------------------------------------------------------------------
\r
249 // ----------------------------------------------------------------------------
\r
251 void VM::draw_screen()
\r
253 crtc->draw_screen();
\r
256 int VM::access_lamp()
\r
258 uint32 status = fdc->read_signal(0);
\r
259 return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
\r
262 // ----------------------------------------------------------------------------
\r
264 // ----------------------------------------------------------------------------
\r
266 void VM::initialize_sound(int rate, int samples)
\r
268 // init sound manager
\r
269 event->initialize_sound(rate, samples);
\r
272 opn->init(rate, 2000000, samples, 0, -8);
\r
273 pcm->init(rate, 4096);
\r
276 uint16* VM::create_sound(int* extra_frames)
\r
278 return event->create_sound(extra_frames);
\r
281 int VM::sound_buffer_ptr()
\r
283 return event->sound_buffer_ptr();
\r
286 // ----------------------------------------------------------------------------
\r
288 // ----------------------------------------------------------------------------
\r
290 void VM::open_disk(int drv, _TCHAR* file_path, int offset)
\r
292 fdc->open_disk(drv, file_path, offset);
\r
295 void VM::close_disk(int drv)
\r
297 fdc->close_disk(drv);
\r
300 bool VM::disk_inserted(int drv)
\r
302 return fdc->disk_inserted(drv);
\r
305 bool VM::now_skip()
\r
307 return event->now_skip();
\r
310 void VM::update_config()
\r
312 for(DEVICE* device = first_device; device; device = device->next_device) {
\r
313 device->update_config();
\r