2 HITACH BASIC Master Jr Emulator 'eBASICMasterJr'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
16 #include "../mc6800.h"
17 #include "../mc6820.h"
21 #include "../debugger.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 VM::VM(EMU* parent_emu) : emu(parent_emu)
33 first_device = last_device = NULL;
34 dummy = new DEVICE(this, emu); // must be 1st device
35 event = new EVENT(this, emu); // must be 2nd device
37 drec = new DATAREC(this, emu);
38 drec->set_context_noise_play(new NOISE(this, emu));
39 drec->set_context_noise_stop(new NOISE(this, emu));
40 drec->set_context_noise_fast(new NOISE(this, emu));
41 cpu = new MC6800(this, emu);
42 pia = new MC6820(this, emu);
44 memory = new MEMORY(this, emu);
48 dummy->set_device_name(_T("1st Dummy"));
49 event->set_device_name(_T("EVENT"));
50 cpu->set_device_name(_T("CPU(MC6800)"));
51 pia->set_device_name(_T("MC6820 PIA"));
52 memory->set_device_name(_T("MEMORY"));
55 event->set_context_cpu(cpu);
56 event->set_context_sound(drec);
57 event->set_context_sound(memory);
58 event->set_context_sound(drec->get_context_noise_play());
59 event->set_context_sound(drec->get_context_noise_stop());
60 event->set_context_sound(drec->get_context_noise_fast());
62 drec->set_context_ear(memory, SIG_MEMORY_DATAREC_EAR, 1);
64 memory->set_context_drec(drec);
65 memory->set_context_cpu(cpu);
66 memory->set_context_pia(pia);
69 cpu->set_context_mem(memory);
71 cpu->set_context_debugger(new DEBUGGER(this, emu));
74 // initialize all devices
75 for(DEVICE* device = first_device; device; device = device->next_device) {
83 for(DEVICE* device = first_device; device;) {
84 DEVICE *next_device = device->next_device;
91 DEVICE* VM::get_device(int id)
93 for(DEVICE* device = first_device; device; device = device->next_device) {
94 if(device->this_device_id == id) {
101 // ----------------------------------------------------------------------------
102 // drive virtual machine
103 // ----------------------------------------------------------------------------
108 for(DEVICE* device = first_device; device; device = device->next_device) {
113 void VM::special_reset()
116 for(DEVICE* device = first_device; device; device = device->next_device) {
126 double VM::get_frame_rate()
128 return event->get_frame_rate();
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
136 DEVICE *VM::get_cpu(int index)
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 void VM::draw_screen()
151 memory->draw_screen();
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 void VM::initialize_sound(int rate, int samples)
160 // init sound manager
161 event->initialize_sound(rate, samples);
164 uint16_t* VM::create_sound(int* extra_frames)
166 return event->create_sound(extra_frames);
169 int VM::get_sound_buffer_ptr()
171 return event->get_sound_buffer_ptr();
174 #ifdef USE_SOUND_VOLUME
175 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
178 memory->set_volume(0, decibel_l, decibel_r);
180 drec->set_volume(0, decibel_l, decibel_r);
182 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
183 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
184 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 void VM::key_down(int code, bool repeat)
197 memory->key_down(code);
201 void VM::key_up(int code)
205 // ----------------------------------------------------------------------------
207 // ----------------------------------------------------------------------------
209 void VM::play_tape(int drv, const _TCHAR* file_path)
211 drec->play_tape(file_path);
215 void VM::rec_tape(int drv, const _TCHAR* file_path)
217 drec->rec_tape(file_path);
221 void VM::close_tape(int drv)
229 bool VM::is_tape_inserted(int drv)
231 return drec->is_tape_inserted();
234 bool VM::is_tape_playing(int drv)
236 return drec->is_tape_playing();
239 bool VM::is_tape_recording(int drv)
241 return drec->is_tape_recording();
244 int VM::get_tape_position(int drv)
246 return drec->get_tape_position();
249 const _TCHAR* VM::get_tape_message(int drv)
251 return drec->get_message();
254 void VM::push_play(int drv)
257 drec->set_remote(true);
260 void VM::push_stop(int drv)
262 drec->set_remote(false);
265 void VM::push_fast_forward(int drv)
268 drec->set_remote(true);
271 void VM::push_fast_rewind(int drv)
273 drec->set_ff_rew(-1);
274 drec->set_remote(true);
277 bool VM::is_frame_skippable()
279 return event->is_frame_skippable();
282 void VM::update_config()
284 for(DEVICE* device = first_device; device; device = device->next_device) {
285 device->update_config();
289 #define STATE_VERSION 2
291 void VM::save_state(FILEIO* state_fio)
293 state_fio->FputUint32(STATE_VERSION);
295 for(DEVICE* device = first_device; device; device = device->next_device) {
296 device->save_state(state_fio);
300 bool VM::load_state(FILEIO* state_fio)
302 if(state_fio->FgetUint32() != STATE_VERSION) {
305 for(DEVICE* device = first_device; device; device = device->next_device) {
306 if(!device->load_state(state_fio)) {