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
46 dummy->set_device_name(_T("1st Dummy"));
47 event->set_device_name(_T("EVENT"));
49 /// drec = new DATAREC(this, emu);
50 /// sio = new I8251(this, emu);
51 pio_k = new I8255(this, emu);
52 pio_f = new I8255(this, emu);
53 io = new IO(this, emu);
54 psg = new SN76489AN(this, emu);
55 fm = new YM2413(this, emu);
56 vdp = new _315_5124(this, emu);
57 /// fdc = new UPD765A(this, emu);
58 cpu = new Z80(this, emu);
60 pio_k->set_device_name(_T("i8255(SG KEYBOARD)"));
61 pio_f->set_device_name(_T("i8255(SG FDD)"));
62 io->set_device_name(_T("I/O BUS"));
63 psg->set_device_name(_T("SN76489AN PSG"));
64 fm->set_device_name(_T("YM2413 OPL"));
65 vdp->set_device_name(_T("SEGA 315-5124 VDP"));
66 cpu->set_device_name(_T("CPU(Z80)"));
69 key = new KEYBOARD(this, emu);
70 memory = new MEMORY(this, emu);
71 system = new SYSTEM(this, emu);
73 key->set_device_name(_T("KEYBOARD"));
74 memory->set_device_name(_T("MEMORY"));
75 system->set_device_name(_T("SYSTEM"));
79 event->set_context_cpu(cpu);
80 event->set_context_sound(psg);
81 event->set_context_sound(fm);
83 /// drec->set_context_ear(pio_k, SIG_I8255_PORT_B, 0x80);
84 pio_k->set_context_port_c(key, SIG_KEYBOARD_COLUMN, 0x07, 0);
85 /// pio_k->set_context_port_c(drec, SIG_DATAREC_REMOTE, 0x08, 0);
86 /// pio_k->set_context_port_c(drec, SIG_DATAREC_MIC, 0x10, 0);
87 /// pio_f->set_context_port_c(fdc, SIG_UPD765A_MOTOR_NEG, 2, 0);
88 /// pio_f->set_context_port_c(fdc, SIG_UPD765A_TC, 4, 0);
89 /// pio_f->set_context_port_c(fdc, SIG_UPD765A_RESET, 8, 0);
90 pio_f->set_context_port_c(memory, SIG_MEMORY_SEL, 0x40, 0);
91 vdp->set_context_irq(cpu, SIG_CPU_IRQ, 1);
92 /// fdc->set_context_irq(pio_f, SIG_I8255_PORT_A, 1);
93 /// fdc->set_context_index(pio_f, SIG_I8255_PORT_A, 4);
95 key->set_context_cpu(cpu);
96 key->set_context_pio(pio_k);
97 system->set_context_key(key);
98 vdp->set_context_key(key);
99 vdp->set_context_psg(psg);
100 /// vdp->set_context_cpu(cpu);
103 cpu->set_context_mem(memory);
104 cpu->set_context_io(io);
105 cpu->set_context_intr(system);
107 cpu->set_context_debugger(new DEBUGGER(this, emu));
111 io->set_iomap_single_r(0x00, system); // GG START
112 io->set_iomap_single_w(0x80, system); // COL TENKEY
113 io->set_iomap_single_w(0xc0, system); // COL JOYPAD
114 io->set_iomap_range_rw(0xfc, 0xfe, system); // COL JOYPAD
115 io->set_iomap_range_rw(0xff, 0xff, psg); // COL PSG
116 io->set_iomap_range_rw(0x7e, 0x7f, vdp); // SG VDP
117 io->set_iomap_range_rw(0xbe, 0xbf, vdp); // SG VDP
118 io->set_iomap_range_rw(0xdc, 0xdf, pio_k); // SG KEY
119 /// io->set_iomap_range_rw(0xe0, 0xe3, fdc); // SG FDD
120 /// io->set_iomap_range_rw(0xe4, 0xe7, pio_f); // SG FDD
121 /// io->set_iomap_range_rw(0xe8, 0xe9, sio); // SG SERIAL
122 io->set_iomap_range_rw(0xf0, 0xf2, fm); // MS FM
124 // initialize all devices
125 for(DEVICE* device = first_device; device; device = device->next_device) {
126 device->initialize();
131 memory->open_cart(create_local_path(_T("SMS.ROM")));
132 /// for(int i = 0; i < 4; i++) {
133 /// fdc->set_drive_type(i, DRIVE_TYPE_2D);
139 // delete all devices
140 for(DEVICE* device = first_device; device;) {
141 DEVICE *next_device = device->next_device;
144 device = next_device;
148 DEVICE* VM::get_device(int id)
150 for(DEVICE* device = first_device; device; device = device->next_device) {
151 if(device->this_device_id == id) {
158 // ----------------------------------------------------------------------------
159 // drive virtual machine
160 // ----------------------------------------------------------------------------
165 for(DEVICE* device = first_device; device; device = device->next_device) {
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
180 DEVICE *VM::get_cpu(int index)
189 // ----------------------------------------------------------------------------
191 // ----------------------------------------------------------------------------
193 void VM::draw_screen()
198 ///uint32_t VM::get_access_lamp_status()
200 /// uint32_t status = fdc->read_signal(0);
201 /// return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 void VM::initialize_sound(int rate, int samples)
210 // init sound manager
211 event->initialize_sound(rate, samples);
214 psg->initialize_sound(rate, 3579545, 4000);
215 fm->initialize_sound(rate, 3579545, samples);
218 uint16_t* VM::create_sound(int* extra_frames)
220 return event->create_sound(extra_frames);
223 int VM::get_sound_buffer_ptr()
225 return event->get_sound_buffer_ptr();
228 #ifdef USE_SOUND_VOLUME
229 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
232 psg->set_volume(0, decibel_l, decibel_r);
234 fm->set_volume(0, decibel_l, decibel_r);
239 // ----------------------------------------------------------------------------
241 // ----------------------------------------------------------------------------
243 void VM::open_cart(int drv, const _TCHAR* file_path)
246 memory->open_cart(file_path);
247 if (check_file_extension(file_path, _T(".col"))) {
248 vdp->set_context_irq(cpu, SIG_CPU_NMI, 1);
249 vdp->set_console(0x00);
252 vdp->set_context_irq(cpu, SIG_CPU_IRQ, 1);
253 if (check_file_extension(file_path, _T(".gg"))) {
254 vdp->set_console(0x40);
256 vdp->set_console(0x20);
263 void VM::close_cart(int drv)
266 memory->close_cart();
271 bool VM::is_cart_inserted(int drv)
274 return memory->is_cart_inserted();
280 ///void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
282 /// fdc->open_disk(drv, file_path, bank);
285 ///void VM::close_floppy_disk(int drv)
287 /// fdc->close_disk(drv);
290 ///bool VM::is_floppy_disk_inserted(int drv)
292 /// return fdc->is_disk_inserted(drv);
295 ///void VM::is_floppy_disk_protected(int drv, bool value)
297 /// fdc->is_disk_protected(drv, value);
300 ///bool VM::is_floppy_disk_protected(int drv)
302 /// return fdc->is_disk_protected(drv);
305 ///void VM::play_tape(const _TCHAR* file_path)
307 /// drec->play_tape(file_path);
310 ///void VM::rec_tape(const _TCHAR* file_path)
312 /// drec->rec_tape(file_path);
315 ///void VM::close_tape()
318 /// drec->close_tape();
319 /// emu->unlock_vm();
322 ///bool VM::is_tape_inserted()
324 /// return drec->is_tape_inserted();
327 ///bool VM::is_tape_playing()
329 /// return drec->is_tape_playing();
332 ///bool VM::is_tape_recording()
334 /// return drec->is_tape_recording();
337 ///int VM::get_tape_position()
339 /// return drec->get_tape_position();
342 bool VM::is_frame_skippable()
344 return event->is_frame_skippable();
347 void VM::update_config()
349 for(DEVICE* device = first_device; device; device = device->next_device) {
350 device->update_config();