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::frame_rate()
113 return event->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::sound_buffer_ptr()
156 return event->sound_buffer_ptr();
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
163 void VM::key_down(int code, bool repeat)
166 memory->key_down(code);
170 void VM::key_up(int code)
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 void VM::play_tape(const _TCHAR* file_path)
180 drec->play_tape(file_path);
184 void VM::rec_tape(const _TCHAR* file_path)
186 drec->rec_tape(file_path);
190 void VM::close_tape()
196 bool VM::tape_inserted()
198 return drec->tape_inserted();
204 drec->set_remote(true);
209 drec->set_remote(false);
212 void VM::push_fast_forward()
215 drec->set_remote(true);
218 void VM::push_fast_rewind()
220 drec->set_ff_rew(-1);
221 drec->set_remote(true);
224 bool VM::get_tape_play(void)
226 return drec->get_tape_play();
231 return event->now_skip();
234 void VM::update_config()
236 for(DEVICE* device = first_device; device; device = device->next_device) {
237 device->update_config();
241 #define STATE_VERSION 1
243 void VM::save_state(FILEIO* state_fio)
245 state_fio->FputUint32(STATE_VERSION);
247 for(DEVICE* device = first_device; device; device = device->next_device) {
248 device->save_state(state_fio);
252 bool VM::load_state(FILEIO* state_fio)
254 if(state_fio->FgetUint32() != STATE_VERSION) {
257 for(DEVICE* device = first_device; device; device = device->next_device) {
258 if(!device->load_state(state_fio)) {