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 "../noise.h"
21 #include "../ym2413.h"
22 #include "../sn76489an.h"
23 #include "../315-5124.h"
24 ///#include "../upd765a.h"
28 #include "../debugger.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
42 first_device = last_device = NULL;
43 dummy = new DEVICE(this, emu); // must be 1st device
44 event = new EVENT(this, emu); // must be 2nd device
45 dummy->set_device_name(_T("1st Dummy"));
46 /// drec = new DATAREC(this, emu);
47 /// drec->set_context_noise_play(new NOISE(this, emu));
48 /// drec->set_context_noise_stop(new NOISE(this, emu));
49 /// drec->set_context_noise_fast(new NOISE(this, emu));
50 /// sio = new I8251(this, emu);
51 pio_k = new I8255(this, emu);
52 pio_k->set_device_name(_T("8255 PIO (Keyboard)"));
53 pio_f = new I8255(this, emu);
54 pio_f->set_device_name(_T("8255 PIO (Floppy I/F)"));
55 io = new IO(this, emu);
56 psg = new SN76489AN(this, emu);
57 fm = new YM2413(this, emu);
58 vdp = new _315_5124(this, emu);
59 /// fdc = new UPD765A(this, emu);
60 /// fdc->set_context_noise_seek(new NOISE(this, emu));
61 /// fdc->set_context_noise_head_down(new NOISE(this, emu));
62 // fdc->set_context_noise_head_up(new NOISE(this, emu));
63 cpu = new Z80(this, emu);
65 key = new KEYBOARD(this, emu);
66 memory = new MEMORY(this, emu);
67 system = new SYSTEM(this, emu);
70 event->set_context_cpu(cpu);
71 event->set_context_sound(psg);
72 event->set_context_sound(fm);
73 /// event->set_context_sound(fdc->get_context_noise_seek());
74 /// event->set_context_sound(fdc->get_context_noise_head_down());
75 /// event->set_context_sound(fdc->get_context_noise_head_up());
76 /// event->set_context_sound(drec->get_context_noise_play());
77 /// event->set_context_sound(drec->get_context_noise_stop());
78 /// event->set_context_sound(drec->get_context_noise_fast());
81 /// drec->set_context_ear(pio_k, SIG_I8255_PORT_B, 0x80);
82 pio_k->set_context_port_c(key, SIG_KEYBOARD_COLUMN, 0x07, 0);
83 /// pio_k->set_context_port_c(drec, SIG_DATAREC_REMOTE, 0x08, 0);
84 /// pio_k->set_context_port_c(drec, SIG_DATAREC_MIC, 0x10, 0);
85 /// pio_f->set_context_port_c(fdc, SIG_UPD765A_MOTOR_NEG, 2, 0);
86 /// pio_f->set_context_port_c(fdc, SIG_UPD765A_TC, 4, 0);
87 /// pio_f->set_context_port_c(fdc, SIG_UPD765A_RESET, 8, 0);
88 pio_f->set_context_port_c(memory, SIG_MEMORY_SEL, 0x40, 0);
89 vdp->set_context_irq(cpu, SIG_CPU_IRQ, 1);
90 /// fdc->set_context_irq(pio_f, SIG_I8255_PORT_A, 1);
91 /// fdc->set_context_index(pio_f, SIG_I8255_PORT_A, 4);
93 key->set_context_cpu(cpu);
94 key->set_context_pio(pio_k);
95 system->set_context_key(key);
96 vdp->set_context_key(key);
97 vdp->set_context_psg(psg);
98 /// vdp->set_context_cpu(cpu);
101 cpu->set_context_mem(memory);
102 cpu->set_context_io(io);
103 cpu->set_context_intr(system);
105 cpu->set_context_debugger(new DEBUGGER(this, emu));
109 io->set_iomap_single_r(0x00, system); // GG START
110 io->set_iomap_single_w(0x80, system); // COL TENKEY
111 io->set_iomap_single_w(0xc0, system); // COL JOYPAD
112 io->set_iomap_range_rw(0xfc, 0xfe, system); // COL JOYPAD
113 io->set_iomap_range_rw(0xff, 0xff, psg); // COL PSG
114 io->set_iomap_range_rw(0x7e, 0x7f, vdp); // SG VDP
115 io->set_iomap_range_rw(0xbe, 0xbf, vdp); // SG VDP
116 io->set_iomap_range_rw(0xdc, 0xdf, pio_k); // SG KEY
117 /// io->set_iomap_range_rw(0xe0, 0xe3, fdc); // SG FDD
118 /// io->set_iomap_range_rw(0xe4, 0xe7, pio_f); // SG FDD
119 /// io->set_iomap_range_rw(0xe8, 0xe9, sio); // SG SERIAL
120 io->set_iomap_range_rw(0xf0, 0xf2, fm); // MS FM
122 // initialize all devices
123 for(DEVICE* device = first_device; device; device = device->next_device) {
124 device->initialize();
129 memory->open_cart(create_local_path(_T("SMS.ROM")));
130 /// for(int i = 0; i < 4; i++) {
131 /// fdc->set_drive_type(i, DRIVE_TYPE_2D);
137 // delete all devices
138 for(DEVICE* device = first_device; device;) {
139 DEVICE *next_device = device->next_device;
142 device = next_device;
146 DEVICE* VM::get_device(int id)
148 for(DEVICE* device = first_device; device; device = device->next_device) {
149 if(device->this_device_id == id) {
156 // ----------------------------------------------------------------------------
157 // drive virtual machine
158 // ----------------------------------------------------------------------------
163 for(DEVICE* device = first_device; device; device = device->next_device) {
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
178 DEVICE *VM::get_cpu(int index)
187 // ----------------------------------------------------------------------------
189 // ----------------------------------------------------------------------------
191 void VM::draw_screen()
196 // ----------------------------------------------------------------------------
198 // ----------------------------------------------------------------------------
200 void VM::initialize_sound(int rate, int samples)
202 // init sound manager
203 event->initialize_sound(rate, samples);
206 psg->initialize_sound(rate, 3579545, 4000);
207 fm->initialize_sound(rate, 3579545, samples);
210 uint16_t* VM::create_sound(int* extra_frames)
212 return event->create_sound(extra_frames);
215 int VM::get_sound_buffer_ptr()
217 return event->get_sound_buffer_ptr();
220 #ifdef USE_SOUND_VOLUME
221 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
224 psg->set_volume(0, decibel_l, decibel_r);
226 fm->set_volume(0, decibel_l, decibel_r);
227 /// } else if(ch == 2) {
228 /// fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
229 /// fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
230 /// fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
231 /// } else if(ch == 3) {
232 /// drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
233 /// drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
234 /// drec->get_context_noise_fast()->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 ///uint32_t VM::is_floppy_disk_accessed()
307 /// return fdc->read_signal(0);
310 ///void VM::play_tape(int drv, const _TCHAR* file_path)
312 /// drec->play_tape(file_path);
313 /// drec->set_remote(true);
316 ///void VM::rec_tape(int drv, const _TCHAR* file_path)
318 /// drec->rec_tape(file_path);
319 /// drec->set_remote(true);
322 ///void VM::close_tape(int drv)
325 /// drec->close_tape();
326 /// emu->unlock_vm();
327 /// drec->set_remote(false);
330 ///bool VM::is_tape_inserted(int drv)
332 /// return drec->is_tape_inserted();
335 ///bool VM::is_tape_playing(int drv)
337 /// return drec->is_tape_playing();
340 ///bool VM::is_tape_recording(int drv)
342 /// return drec->is_tape_recording();
345 ///int VM::get_tape_position(int drv)
347 /// return drec->get_tape_position();
350 ///const _TCHAR* VM::get_tape_message(int drv)
352 /// return drec->get_message();
355 ///void VM::push_play(int drv)
357 /// drec->set_ff_rew(0);
358 /// drec->set_remote(true);
361 ///void VM::push_stop(int drv)
363 /// drec->set_remote(false);
366 ///void VM::push_fast_forward(int drv)
368 /// drec->set_ff_rew(1);
369 /// drec->set_remote(true);
372 ///void VM::push_fast_rewind(int drv)
374 /// drec->set_ff_rew(-1);
375 /// drec->set_remote(true);
378 bool VM::is_frame_skippable()
380 return event->is_frame_skippable();
383 void VM::update_config()
385 for(DEVICE* device = first_device; device; device = device->next_device) {
386 device->update_config();