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) {
80 for(DEVICE* device = first_device; device;) {
81 DEVICE *next_device = device->next_device;
88 DEVICE* VM::get_device(int id)
90 for(DEVICE* device = first_device; device; device = device->next_device) {
91 if(device->this_device_id == id) {
98 // ----------------------------------------------------------------------------
99 // drive virtual machine
100 // ----------------------------------------------------------------------------
105 for(DEVICE* device = first_device; device; device = device->next_device) {
110 void VM::special_reset()
113 for(DEVICE* device = first_device; device; device = device->next_device) {
123 double VM::get_frame_rate()
125 return event->get_frame_rate();
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
133 DEVICE *VM::get_cpu(int index)
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 void VM::draw_screen()
148 memory->draw_screen();
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 void VM::initialize_sound(int rate, int samples)
157 // init sound manager
158 event->initialize_sound(rate, samples);
161 uint16_t* VM::create_sound(int* extra_frames)
163 return event->create_sound(extra_frames);
166 int VM::get_sound_buffer_ptr()
168 return event->get_sound_buffer_ptr();
171 #ifdef USE_SOUND_VOLUME
172 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
175 memory->set_volume(0, decibel_l, decibel_r);
177 drec->set_volume(0, decibel_l, decibel_r);
179 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
180 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
181 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 void VM::key_down(int code, bool repeat)
193 memory->key_down(code);
197 void VM::key_up(int code)
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
205 void VM::play_tape(int drv, const _TCHAR* file_path)
207 drec->play_tape(file_path);
208 // drec->set_remote(true);
211 void VM::rec_tape(int drv, const _TCHAR* file_path)
213 drec->rec_tape(file_path);
214 // drec->set_remote(true);
217 void VM::close_tape(int drv)
222 // drec->set_remote(false);
225 bool VM::is_tape_inserted(int drv)
227 return drec->is_tape_inserted();
230 bool VM::is_tape_playing(int drv)
232 return drec->is_tape_playing();
235 bool VM::is_tape_recording(int drv)
237 return drec->is_tape_recording();
240 int VM::get_tape_position(int drv)
242 return drec->get_tape_position();
245 const _TCHAR* VM::get_tape_message(int drv)
247 return drec->get_message();
250 void VM::push_play(int drv)
253 drec->set_remote(true);
256 void VM::push_stop(int drv)
258 drec->set_remote(false);
261 void VM::push_fast_forward(int drv)
264 drec->set_remote(true);
267 void VM::push_fast_rewind(int drv)
269 drec->set_ff_rew(-1);
270 drec->set_remote(true);
273 bool VM::is_frame_skippable()
275 return event->is_frame_skippable();
278 void VM::update_config()
280 for(DEVICE* device = first_device; device; device = device->next_device) {
281 device->update_config();
285 #define STATE_VERSION 3
287 #include "../../statesub.h"
289 void VM::decl_state(void)
291 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::BASIC_MASTER_HEAD")));
292 for(DEVICE* device = first_device; device; device = device->next_device) {
293 device->decl_state();
297 void VM::save_state(FILEIO* state_fio)
299 //state_fio->FputUint32(STATE_VERSION);
301 if(state_entry != NULL) {
302 state_entry->save_state(state_fio);
304 for(DEVICE* device = first_device; device; device = device->next_device) {
305 device->save_state(state_fio);
309 bool VM::load_state(FILEIO* state_fio)
311 //if(state_fio->FgetUint32() != STATE_VERSION) {
315 if(state_entry != NULL) {
316 mb = state_entry->load_state(state_fio);
319 emu->out_debug_log("INFO: HEADER DATA ERROR");
322 for(DEVICE* device = first_device; device; device = device->next_device) {
323 if(!device->load_state(state_fio)) {