2 SEGA MASTER SYSTEM Emulator 'yaMASTER SYSTEM'
10 #include "mastersystem.h"
11 #include "../../emu.h"
12 #include "../device.h"
15 ///#include "../datarec.h"
16 ///#include "../disk.h"
17 ///#include "../i8251.h"
20 #include "../ym2413.h"
21 #include "../sn76489an.h"
22 #include "../315-5124.h"
23 ///#include "../upd765a.h"
27 #include "../debugger.h"
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 VM::VM(EMU* parent_emu) : emu(parent_emu)
41 first_device = last_device = NULL;
42 dummy = new DEVICE(this, emu); // must be 1st device
43 event = new EVENT(this, emu); // must be 2nd device
45 /// drec = new DATAREC(this, emu);
46 /// sio = new I8251(this, emu);
47 pio_k = new I8255(this, emu);
48 pio_f = new I8255(this, emu);
49 io = new IO(this, emu);
50 psg = new SN76489AN(this, emu);
51 fm = new YM2413(this, emu);
52 vdp = new _315_5124(this, emu);
53 /// fdc = new UPD765A(this, emu);
54 cpu = new Z80(this, emu);
56 key = new KEYBOARD(this, emu);
57 memory = new MEMORY(this, emu);
58 system = new SYSTEM(this, emu);
61 event->set_context_cpu(cpu);
62 event->set_context_sound(psg);
63 event->set_context_sound(fm);
65 /// drec->set_context_ear(pio_k, SIG_I8255_PORT_B, 0x80);
66 pio_k->set_context_port_c(key, SIG_KEYBOARD_COLUMN, 0x07, 0);
67 /// pio_k->set_context_port_c(drec, SIG_DATAREC_REMOTE, 0x08, 0);
68 /// pio_k->set_context_port_c(drec, SIG_DATAREC_MIC, 0x10, 0);
69 /// pio_f->set_context_port_c(fdc, SIG_UPD765A_MOTOR_NEG, 2, 0);
70 /// pio_f->set_context_port_c(fdc, SIG_UPD765A_TC, 4, 0);
71 /// pio_f->set_context_port_c(fdc, SIG_UPD765A_RESET, 8, 0);
72 pio_f->set_context_port_c(memory, SIG_MEMORY_SEL, 0x40, 0);
73 vdp->set_context_irq(cpu, SIG_CPU_IRQ, 1);
74 /// fdc->set_context_irq(pio_f, SIG_I8255_PORT_A, 1);
75 /// fdc->set_context_index(pio_f, SIG_I8255_PORT_A, 4);
77 key->set_context_cpu(cpu);
78 key->set_context_pio(pio_k);
79 system->set_context_key(key);
80 vdp->set_context_key(key);
81 vdp->set_context_psg(psg);
82 /// vdp->set_context_cpu(cpu);
85 cpu->set_context_mem(memory);
86 cpu->set_context_io(io);
87 cpu->set_context_intr(system);
89 cpu->set_context_debugger(new DEBUGGER(this, emu));
93 io->set_iomap_single_r(0x00, system); // GG START
94 io->set_iomap_single_w(0x80, system); // COL TENKEY
95 io->set_iomap_single_w(0xc0, system); // COL JOYPAD
96 io->set_iomap_range_rw(0xfc, 0xfe, system); // COL JOYPAD
97 io->set_iomap_range_rw(0xff, 0xff, psg); // COL PSG
98 io->set_iomap_range_rw(0x7e, 0x7f, vdp); // SG VDP
99 io->set_iomap_range_rw(0xbe, 0xbf, vdp); // SG VDP
100 io->set_iomap_range_rw(0xdc, 0xdf, pio_k); // SG KEY
101 /// io->set_iomap_range_rw(0xe0, 0xe3, fdc); // SG FDD
102 /// io->set_iomap_range_rw(0xe4, 0xe7, pio_f); // SG FDD
103 /// io->set_iomap_range_rw(0xe8, 0xe9, sio); // SG SERIAL
104 io->set_iomap_range_rw(0xf0, 0xf2, fm); // MS FM
106 // initialize all devices
107 for(DEVICE* device = first_device; device; device = device->next_device) {
108 device->initialize();
113 memory->open_cart(create_local_path(_T("SMS.ROM")));
114 /// for(int i = 0; i < 4; i++) {
115 /// fdc->set_drive_type(i, DRIVE_TYPE_2D);
121 // delete all devices
122 for(DEVICE* device = first_device; device;) {
123 DEVICE *next_device = device->next_device;
126 device = next_device;
130 DEVICE* VM::get_device(int id)
132 for(DEVICE* device = first_device; device; device = device->next_device) {
133 if(device->this_device_id == id) {
140 // ----------------------------------------------------------------------------
141 // drive virtual machine
142 // ----------------------------------------------------------------------------
147 for(DEVICE* device = first_device; device; device = device->next_device) {
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
162 DEVICE *VM::get_cpu(int index)
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 void VM::draw_screen()
180 ///int VM::access_lamp()
182 /// uint32 status = fdc->read_signal(0);
183 /// return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 void VM::initialize_sound(int rate, int samples)
192 // init sound manager
193 event->initialize_sound(rate, samples);
196 psg->init(rate, 3579545, 4000);
197 fm->init(rate, 3579545, samples);
200 uint16* VM::create_sound(int* extra_frames)
202 return event->create_sound(extra_frames);
205 int VM::sound_buffer_ptr()
207 return event->sound_buffer_ptr();
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 void VM::open_cart(int drv, const _TCHAR* file_path)
217 memory->open_cart(file_path);
218 if (strstr(file_path, ".col") ||
219 strstr(file_path, ".COL")) {
220 vdp->set_context_irq(cpu, SIG_CPU_NMI, 1);
221 vdp->set_console(0x00);
224 vdp->set_context_irq(cpu, SIG_CPU_IRQ, 1);
225 if (strstr(file_path, ".gg") ||
226 strstr(file_path, ".GG")) vdp->set_console(0x40);
228 vdp->set_console(0x20);
234 void VM::close_cart(int drv)
237 memory->close_cart();
242 bool VM::cart_inserted(int drv)
245 return memory->cart_inserted();
251 ///void VM::open_disk(int drv, const _TCHAR* file_path, int bank)
253 /// fdc->open_disk(drv, file_path, bank);
256 ///void VM::close_disk(int drv)
258 /// fdc->close_disk(drv);
261 ///bool VM::disk_inserted(int drv)
263 /// return fdc->disk_inserted(drv);
266 ///void VM::set_disk_protected(int drv, bool value)
268 /// fdc->set_disk_protected(drv, value);
271 ///bool VM::get_disk_protected(int drv)
273 /// return fdc->get_disk_protected(drv);
276 ///void VM::play_tape(const _TCHAR* file_path)
278 /// drec->play_tape(file_path);
281 ///void VM::rec_tape(const _TCHAR* file_path)
283 /// drec->rec_tape(file_path);
286 ///void VM::close_tape()
288 /// drec->close_tape();
291 ///bool VM::tape_inserted()
293 /// return drec->tape_inserted();
296 ///bool VM::tape_playing()
298 /// return drec->tape_playing();
301 ///bool VM::tape_recording()
303 /// return drec->tape_recording();
306 ///int VM::tape_position()
308 /// return drec->tape_position();
313 return event->now_skip();
316 void VM::update_config()
318 for(DEVICE* device = first_device; device; device = device->next_device) {
319 device->update_config();