2 BANDAI RX-78 Emulator 'eRX-78'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
18 #include "../sn76489an.h"
22 #include "../debugger.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 VM::VM(EMU* parent_emu) : emu(parent_emu)
38 first_device = last_device = NULL;
39 dummy = new DEVICE(this, emu); // must be 1st device
40 event = new EVENT(this, emu); // must be 2nd device
41 dummy->set_device_name(_T("1st Dummy"));
43 drec = new DATAREC(this, emu);
44 drec->set_context_noise_play(new NOISE(this, emu));
45 drec->set_context_noise_stop(new NOISE(this, emu));
46 drec->set_context_noise_fast(new NOISE(this, emu));
47 io = new IO(this, emu);
48 psg = new SN76489AN(this, emu);
49 cpu = new Z80(this, emu);
51 cmt = new CMT(this, emu);
52 key = new KEYBOARD(this, emu);
53 memory = new MEMORY(this, emu);
54 prt = new PRINTER(this, emu);
55 vdp = new VDP(this, emu);
58 event->set_context_cpu(cpu);
59 event->set_context_sound(psg);
60 event->set_context_sound(drec);
61 event->set_context_sound(drec->get_context_noise_play());
62 event->set_context_sound(drec->get_context_noise_stop());
63 event->set_context_sound(drec->get_context_noise_fast());
65 drec->set_context_ear(cmt, SIG_CMT_IN, 1);
66 cmt->set_context_drec(drec);
67 vdp->set_context_cpu(cpu);
68 vdp->set_vram_ptr(memory->get_vram());
71 cpu->set_context_mem(memory);
72 cpu->set_context_io(io);
73 cpu->set_context_intr(dummy);
75 cpu->set_context_debugger(new DEBUGGER(this, emu));
79 io->set_iomap_range_rw(0xe2, 0xe3, prt);
80 io->set_iomap_single_rw(0xf0, cmt);
81 io->set_iomap_range_w(0xf1, 0xf2, memory);
82 io->set_iomap_single_rw(0xf4, key);
83 io->set_iomap_range_w(0xf5, 0xfc, vdp);
84 io->set_iomap_single_w(0xfe, vdp);
85 io->set_iomap_single_w(0xff, psg);
87 // initialize all devices
88 for(DEVICE* device = first_device; device; device = device->next_device) {
96 for(DEVICE* device = first_device; device;) {
97 DEVICE *next_device = device->next_device;
100 device = next_device;
104 DEVICE* VM::get_device(int id)
106 for(DEVICE* device = first_device; device; device = device->next_device) {
107 if(device->this_device_id == id) {
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
119 DEVICE *VM::get_cpu(int index)
128 // ----------------------------------------------------------------------------
129 // drive virtual machine
130 // ----------------------------------------------------------------------------
135 for(DEVICE* device = first_device; device; device = device->next_device) {
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 void VM::draw_screen()
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 void VM::initialize_sound(int rate, int samples)
160 // init sound manager
161 event->initialize_sound(rate, samples);
164 psg->initialize_sound(rate, 3579545, 8000);
167 uint16_t* VM::create_sound(int* extra_frames)
169 return event->create_sound(extra_frames);
172 int VM::get_sound_buffer_ptr()
174 return event->get_sound_buffer_ptr();
177 #ifdef USE_SOUND_VOLUME
178 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
181 psg->set_volume(0, decibel_l, decibel_r);
183 drec->set_volume(0, decibel_l, decibel_r);
185 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
186 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
187 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
196 void VM::open_cart(int drv, const _TCHAR* file_path)
199 memory->open_cart(file_path);
204 void VM::close_cart(int drv)
207 memory->close_cart();
212 bool VM::is_cart_inserted(int drv)
215 return memory->is_cart_inserted();
221 void VM::play_tape(int drv, const _TCHAR* file_path)
223 drec->play_tape(file_path);
224 // drec->set_remote(true);
227 void VM::rec_tape(int drv, const _TCHAR* file_path)
229 drec->rec_tape(file_path);
230 // drec->set_remote(true);
233 void VM::close_tape(int drv)
238 // drec->set_remote(false);
241 bool VM::is_tape_inserted(int drv)
243 return drec->is_tape_inserted();
246 bool VM::is_tape_playing(int drv)
248 return drec->is_tape_playing();
251 bool VM::is_tape_recording(int drv)
253 return drec->is_tape_recording();
256 int VM::get_tape_position(int drv)
258 return drec->get_tape_position();
261 const _TCHAR* VM::get_tape_message(int drv)
263 return drec->get_message();
266 void VM::push_play(int drv)
269 drec->set_remote(true);
272 void VM::push_stop(int drv)
274 drec->set_remote(false);
277 void VM::push_fast_forward(int drv)
280 drec->set_remote(true);
283 void VM::push_fast_rewind(int drv)
285 drec->set_ff_rew(-1);
286 drec->set_remote(true);
289 bool VM::is_frame_skippable()
291 return event->is_frame_skippable();
294 void VM::update_config()
296 for(DEVICE* device = first_device; device; device = device->next_device) {
297 device->update_config();
301 #define STATE_VERSION 3
303 void VM::save_state(FILEIO* state_fio)
305 state_fio->FputUint32(STATE_VERSION);
307 for(DEVICE* device = first_device; device; device = device->next_device) {
308 device->save_state(state_fio);
312 bool VM::load_state(FILEIO* state_fio)
314 if(state_fio->FgetUint32() != STATE_VERSION) {
317 for(DEVICE* device = first_device; device; device = device->next_device) {
318 if(!device->load_state(state_fio)) {