2 BANDAI RX-78 Emulator 'eRX-78'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
17 #include "../sn76489an.h"
21 #include "../debugger.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 VM::VM(EMU* parent_emu) : emu(parent_emu)
37 first_device = last_device = NULL;
38 dummy = new DEVICE(this, emu); // must be 1st device
39 event = new EVENT(this, emu); // must be 2nd device
41 drec = new DATAREC(this, emu);
42 io = new IO(this, emu);
43 psg = new SN76489AN(this, emu);
44 cpu = new Z80(this, emu);
46 cmt = new CMT(this, emu);
47 key = new KEYBOARD(this, emu);
48 memory = new MEMORY(this, emu);
49 prt = new PRINTER(this, emu);
50 vdp = new VDP(this, emu);
53 event->set_context_cpu(cpu);
54 event->set_context_sound(psg);
55 event->set_context_sound(drec);
57 drec->set_context_ear(cmt, SIG_CMT_IN, 1);
58 cmt->set_context_drec(drec);
59 vdp->set_context_cpu(cpu);
60 vdp->set_vram_ptr(memory->get_vram());
63 cpu->set_context_mem(memory);
64 cpu->set_context_io(io);
65 cpu->set_context_intr(dummy);
67 cpu->set_context_debugger(new DEBUGGER(this, emu));
71 io->set_iomap_range_rw(0xe2, 0xe3, prt);
72 io->set_iomap_single_rw(0xf0, cmt);
73 io->set_iomap_range_w(0xf1, 0xf2, memory);
74 io->set_iomap_single_rw(0xf4, key);
75 io->set_iomap_range_w(0xf5, 0xfc, vdp);
76 io->set_iomap_single_w(0xfe, vdp);
77 io->set_iomap_single_w(0xff, psg);
79 // initialize all devices
80 for(DEVICE* device = first_device; device; device = device->next_device) {
88 for(DEVICE* device = first_device; device;) {
89 DEVICE *next_device = device->next_device;
96 DEVICE* VM::get_device(int id)
98 for(DEVICE* device = first_device; device; device = device->next_device) {
99 if(device->this_device_id == id) {
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
111 DEVICE *VM::get_cpu(int index)
120 // ----------------------------------------------------------------------------
121 // drive virtual machine
122 // ----------------------------------------------------------------------------
127 for(DEVICE* device = first_device; device; device = device->next_device) {
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
141 void VM::draw_screen()
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
150 void VM::initialize_sound(int rate, int samples)
152 // init sound manager
153 event->initialize_sound(rate, samples);
156 psg->initialize_sound(rate, 3579545, 8000);
159 uint16_t* VM::create_sound(int* extra_frames)
161 return event->create_sound(extra_frames);
164 int VM::get_sound_buffer_ptr()
166 return event->get_sound_buffer_ptr();
169 #ifdef USE_SOUND_VOLUME
170 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
173 psg->set_volume(0, decibel_l, decibel_r);
175 drec->set_volume(0, decibel_l, decibel_r);
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 void VM::open_cart(int drv, const _TCHAR* file_path)
187 memory->open_cart(file_path);
192 void VM::close_cart(int drv)
195 memory->close_cart();
200 bool VM::is_cart_inserted(int drv)
203 return memory->is_cart_inserted();
209 void VM::play_tape(const _TCHAR* file_path)
211 drec->play_tape(file_path);
214 void VM::rec_tape(const _TCHAR* file_path)
216 drec->rec_tape(file_path);
219 void VM::close_tape()
224 bool VM::is_tape_inserted()
226 return drec->is_tape_inserted();
229 bool VM::is_tape_playing()
231 return drec->is_tape_playing();
234 bool VM::is_tape_recording()
236 return drec->is_tape_recording();
239 int VM::get_tape_position()
241 return drec->get_tape_position();
244 bool VM::is_frame_skippable()
246 return event->is_frame_skippable();
249 void VM::update_config()
251 for(DEVICE* device = first_device; device; device = device->next_device) {
252 device->update_config();
256 #define STATE_VERSION 1
258 void VM::save_state(FILEIO* state_fio)
260 state_fio->FputUint32(STATE_VERSION);
262 for(DEVICE* device = first_device; device; device = device->next_device) {
263 device->save_state(state_fio);
267 bool VM::load_state(FILEIO* state_fio)
269 if(state_fio->FgetUint32() != STATE_VERSION) {
272 for(DEVICE* device = first_device; device; device = device->next_device) {
273 if(!device->load_state(state_fio)) {