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"));
51 event->set_context_cpu(cpu);
52 event->set_context_sound(drec);
53 event->set_context_sound(memory);
54 event->set_context_sound(drec->get_context_noise_play());
55 event->set_context_sound(drec->get_context_noise_stop());
56 event->set_context_sound(drec->get_context_noise_fast());
58 drec->set_context_ear(memory, SIG_MEMORY_DATAREC_EAR, 1);
60 memory->set_context_drec(drec);
61 memory->set_context_cpu(cpu);
62 memory->set_context_pia(pia);
65 cpu->set_context_mem(memory);
67 cpu->set_context_debugger(new DEBUGGER(this, emu));
70 // initialize all devices
71 for(DEVICE* device = first_device; device; device = device->next_device) {
79 for(DEVICE* device = first_device; device;) {
80 DEVICE *next_device = device->next_device;
87 DEVICE* VM::get_device(int id)
89 for(DEVICE* device = first_device; device; device = device->next_device) {
90 if(device->this_device_id == id) {
97 // ----------------------------------------------------------------------------
98 // drive virtual machine
99 // ----------------------------------------------------------------------------
104 for(DEVICE* device = first_device; device; device = device->next_device) {
109 void VM::special_reset()
112 for(DEVICE* device = first_device; device; device = device->next_device) {
122 double VM::get_frame_rate()
124 return event->get_frame_rate();
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
132 DEVICE *VM::get_cpu(int index)
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 void VM::draw_screen()
147 memory->draw_screen();
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 void VM::initialize_sound(int rate, int samples)
156 // init sound manager
157 event->initialize_sound(rate, samples);
160 uint16_t* VM::create_sound(int* extra_frames)
162 return event->create_sound(extra_frames);
165 int VM::get_sound_buffer_ptr()
167 return event->get_sound_buffer_ptr();
170 #ifdef USE_SOUND_VOLUME
171 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
174 memory->set_volume(0, decibel_l, decibel_r);
176 drec->set_volume(0, decibel_l, decibel_r);
178 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
179 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
180 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 void VM::key_down(int code, bool repeat)
192 memory->key_down(code);
196 void VM::key_up(int code)
200 // ----------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------
204 void VM::play_tape(int drv, const _TCHAR* file_path)
206 drec->play_tape(file_path);
210 void VM::rec_tape(int drv, const _TCHAR* file_path)
212 drec->rec_tape(file_path);
216 void VM::close_tape(int drv)
224 bool VM::is_tape_inserted(int drv)
226 return drec->is_tape_inserted();
229 bool VM::is_tape_playing(int drv)
231 return drec->is_tape_playing();
234 bool VM::is_tape_recording(int drv)
236 return drec->is_tape_recording();
239 int VM::get_tape_position(int drv)
241 return drec->get_tape_position();
244 const _TCHAR* VM::get_tape_message(int drv)
246 return drec->get_message();
249 void VM::push_play(int drv)
252 drec->set_remote(true);
255 void VM::push_stop(int drv)
257 drec->set_remote(false);
260 void VM::push_fast_forward(int drv)
263 drec->set_remote(true);
266 void VM::push_fast_rewind(int drv)
268 drec->set_ff_rew(-1);
269 drec->set_remote(true);
272 bool VM::is_frame_skippable()
274 return event->is_frame_skippable();
277 void VM::update_config()
279 for(DEVICE* device = first_device; device; device = device->next_device) {
280 device->update_config();
284 #define STATE_VERSION 3
286 void VM::save_state(FILEIO* state_fio)
288 state_fio->FputUint32(STATE_VERSION);
290 for(DEVICE* device = first_device; device; device = device->next_device) {
291 device->save_state(state_fio);
295 bool VM::load_state(FILEIO* state_fio)
297 if(state_fio->FgetUint32() != STATE_VERSION) {
300 for(DEVICE* device = first_device; device; device = device->next_device) {
301 if(!device->load_state(state_fio)) {