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"
20 #include "../debugger.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 VM::VM(EMU* parent_emu) : emu(parent_emu)
32 first_device = last_device = NULL;
33 dummy = new DEVICE(this, emu); // must be 1st device
34 event = new EVENT(this, emu); // must be 2nd device
36 drec = new DATAREC(this, emu);
37 cpu = new MC6800(this, emu);
38 pia = new MC6820(this, emu);
40 memory = new MEMORY(this, emu);
43 event->set_context_cpu(cpu);
44 event->set_context_sound(drec);
45 event->set_context_sound(memory);
47 drec->set_context_ear(memory, SIG_MEMORY_DATAREC_EAR, 1);
49 memory->set_context_drec(drec);
50 memory->set_context_cpu(cpu);
51 memory->set_context_pia(pia);
54 cpu->set_context_mem(memory);
56 cpu->set_context_debugger(new DEBUGGER(this, emu));
59 // initialize all devices
60 for(DEVICE* device = first_device; device; device = device->next_device) {
68 for(DEVICE* device = first_device; device;) {
69 DEVICE *next_device = device->next_device;
76 DEVICE* VM::get_device(int id)
78 for(DEVICE* device = first_device; device; device = device->next_device) {
79 if(device->this_device_id == id) {
86 // ----------------------------------------------------------------------------
87 // drive virtual machine
88 // ----------------------------------------------------------------------------
93 for(DEVICE* device = first_device; device; device = device->next_device) {
98 void VM::special_reset()
101 for(DEVICE* device = first_device; device; device = device->next_device) {
111 double VM::get_frame_rate()
113 return event->get_frame_rate();
116 // ----------------------------------------------------------------------------
118 // ----------------------------------------------------------------------------
121 DEVICE *VM::get_cpu(int index)
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
134 void VM::draw_screen()
136 memory->draw_screen();
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
143 void VM::initialize_sound(int rate, int samples)
145 // init sound manager
146 event->initialize_sound(rate, samples);
149 uint16* VM::create_sound(int* extra_frames)
151 return event->create_sound(extra_frames);
154 int VM::get_sound_buffer_ptr()
156 return event->get_sound_buffer_ptr();
159 #ifdef USE_SOUND_VOLUME
160 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
163 memory->set_volume(0, decibel_l, decibel_r);
165 drec->set_volume(0, decibel_l, decibel_r);
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 void VM::key_down(int code, bool repeat)
177 memory->key_down(code);
181 void VM::key_up(int code)
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 void VM::play_tape(const _TCHAR* file_path)
191 drec->play_tape(file_path);
195 void VM::rec_tape(const _TCHAR* file_path)
197 drec->rec_tape(file_path);
201 void VM::close_tape()
207 bool VM::is_tape_inserted()
209 return drec->is_tape_inserted();
212 bool VM::is_tape_playing()
214 return drec->is_tape_playing();
217 bool VM::is_tape_recording()
219 return drec->is_tape_recording();
222 int VM::get_tape_position()
224 return drec->get_tape_position();
230 drec->set_remote(true);
235 drec->set_remote(false);
238 void VM::push_fast_forward()
241 drec->set_remote(true);
244 void VM::push_fast_rewind()
246 drec->set_ff_rew(-1);
247 drec->set_remote(true);
250 bool VM::is_frame_skippable()
252 return event->is_frame_skippable();
255 void VM::update_config()
257 for(DEVICE* device = first_device; device; device = device->next_device) {
258 device->update_config();
262 #define STATE_VERSION 1
264 void VM::save_state(FILEIO* state_fio)
266 state_fio->FputUint32(STATE_VERSION);
268 for(DEVICE* device = first_device; device; device = device->next_device) {
269 device->save_state(state_fio);
273 bool VM::load_state(FILEIO* state_fio)
275 if(state_fio->FgetUint32() != STATE_VERSION) {
278 for(DEVICE* device = first_device; device; device = device->next_device) {
279 if(!device->load_state(state_fio)) {