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);
44 dummy->set_device_name(_T("1st Dummy"));
45 event->set_device_name(_T("EVENT"));
46 cpu->set_device_name(_T("CPU(MC6800)"));
47 pia->set_device_name(_T("MC6820 PIA"));
48 memory->set_device_name(_T("MEMORY"));
51 event->set_context_cpu(cpu);
52 event->set_context_sound(drec);
53 event->set_context_sound(memory);
55 drec->set_context_ear(memory, SIG_MEMORY_DATAREC_EAR, 1);
57 memory->set_context_drec(drec);
58 memory->set_context_cpu(cpu);
59 memory->set_context_pia(pia);
62 cpu->set_context_mem(memory);
64 cpu->set_context_debugger(new DEBUGGER(this, emu));
67 // initialize all devices
68 for(DEVICE* device = first_device; device; device = device->next_device) {
76 for(DEVICE* device = first_device; device;) {
77 DEVICE *next_device = device->next_device;
84 DEVICE* VM::get_device(int id)
86 for(DEVICE* device = first_device; device; device = device->next_device) {
87 if(device->this_device_id == id) {
94 // ----------------------------------------------------------------------------
95 // drive virtual machine
96 // ----------------------------------------------------------------------------
101 for(DEVICE* device = first_device; device; device = device->next_device) {
106 void VM::special_reset()
109 for(DEVICE* device = first_device; device; device = device->next_device) {
119 double VM::get_frame_rate()
121 return event->get_frame_rate();
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
129 DEVICE *VM::get_cpu(int index)
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 void VM::draw_screen()
144 memory->draw_screen();
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 void VM::initialize_sound(int rate, int samples)
153 // init sound manager
154 event->initialize_sound(rate, samples);
157 uint16_t* VM::create_sound(int* extra_frames)
159 return event->create_sound(extra_frames);
162 int VM::get_sound_buffer_ptr()
164 return event->get_sound_buffer_ptr();
167 #ifdef USE_SOUND_VOLUME
168 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
171 memory->set_volume(0, decibel_l, decibel_r);
173 drec->set_volume(0, decibel_l, decibel_r);
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 void VM::key_down(int code, bool repeat)
185 memory->key_down(code);
189 void VM::key_up(int code)
193 // ----------------------------------------------------------------------------
195 // ----------------------------------------------------------------------------
197 void VM::play_tape(const _TCHAR* file_path)
199 drec->play_tape(file_path);
203 void VM::rec_tape(const _TCHAR* file_path)
205 drec->rec_tape(file_path);
209 void VM::close_tape()
215 bool VM::is_tape_inserted()
217 return drec->is_tape_inserted();
220 bool VM::is_tape_playing()
222 return drec->is_tape_playing();
225 bool VM::is_tape_recording()
227 return drec->is_tape_recording();
230 int VM::get_tape_position()
232 return drec->get_tape_position();
238 drec->set_remote(true);
243 drec->set_remote(false);
246 void VM::push_fast_forward()
249 drec->set_remote(true);
252 void VM::push_fast_rewind()
254 drec->set_ff_rew(-1);
255 drec->set_remote(true);
258 bool VM::is_frame_skippable()
260 return event->is_frame_skippable();
263 void VM::update_config()
265 for(DEVICE* device = first_device; device; device = device->next_device) {
266 device->update_config();
270 #define STATE_VERSION 1
272 void VM::save_state(FILEIO* state_fio)
274 state_fio->FputUint32(STATE_VERSION);
276 for(DEVICE* device = first_device; device; device = device->next_device) {
277 device->save_state(state_fio);
281 bool VM::load_state(FILEIO* state_fio)
283 if(state_fio->FgetUint32() != STATE_VERSION) {
286 for(DEVICE* device = first_device; device; device = device->next_device) {
287 if(!device->load_state(state_fio)) {