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 // ----------------------------------------------------------------------------
31 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
34 first_device = last_device = NULL;
35 dummy = new DEVICE(this, emu); // must be 1st device
36 event = new EVENT(this, emu); // must be 2nd device
38 drec = new DATAREC(this, emu);
39 drec->set_context_noise_play(new NOISE(this, emu));
40 drec->set_context_noise_stop(new NOISE(this, emu));
41 drec->set_context_noise_fast(new NOISE(this, emu));
42 cpu = new MC6800(this, emu);
43 pia = new MC6820(this, emu);
45 memory = new MEMORY(this, emu);
49 dummy->set_device_name(_T("1st Dummy"));
52 event->set_context_cpu(cpu);
53 event->set_context_sound(drec);
54 event->set_context_sound(memory);
55 event->set_context_sound(drec->get_context_noise_play());
56 event->set_context_sound(drec->get_context_noise_stop());
57 event->set_context_sound(drec->get_context_noise_fast());
59 drec->set_context_ear(memory, SIG_MEMORY_DATAREC_EAR, 1);
61 memory->set_context_drec(drec);
62 memory->set_context_cpu(cpu);
63 memory->set_context_pia(pia);
66 cpu->set_context_mem(memory);
68 cpu->set_context_debugger(new DEBUGGER(this, emu));
71 // initialize all devices
72 #if defined(__GIT_REPO_VERSION)
73 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
75 for(DEVICE* device = first_device; device; device = device->next_device) {
83 for(DEVICE* device = first_device; device;) {
84 DEVICE *next_device = device->next_device;
91 DEVICE* VM::get_device(int id)
93 for(DEVICE* device = first_device; device; device = device->next_device) {
94 if(device->this_device_id == id) {
101 // ----------------------------------------------------------------------------
102 // drive virtual machine
103 // ----------------------------------------------------------------------------
108 for(DEVICE* device = first_device; device; device = device->next_device) {
113 void VM::special_reset()
116 for(DEVICE* device = first_device; device; device = device->next_device) {
126 double VM::get_frame_rate()
128 return event->get_frame_rate();
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
136 DEVICE *VM::get_cpu(int index)
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 void VM::draw_screen()
151 memory->draw_screen();
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 void VM::initialize_sound(int rate, int samples)
160 // init sound manager
161 event->initialize_sound(rate, samples);
164 uint16_t* VM::create_sound(int* extra_frames)
166 return event->create_sound(extra_frames);
169 int VM::get_sound_buffer_ptr()
171 return event->get_sound_buffer_ptr();
174 #ifdef USE_SOUND_VOLUME
175 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
178 memory->set_volume(0, decibel_l, decibel_r);
180 drec->set_volume(0, decibel_l, decibel_r);
182 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
183 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
184 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
189 // ----------------------------------------------------------------------------
191 // ----------------------------------------------------------------------------
193 void VM::key_down(int code, bool repeat)
196 memory->key_down(code);
200 void VM::key_up(int code)
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 void VM::play_tape(int drv, const _TCHAR* file_path)
210 drec->play_tape(file_path);
211 // drec->set_remote(true);
214 void VM::rec_tape(int drv, const _TCHAR* file_path)
216 drec->rec_tape(file_path);
217 // drec->set_remote(true);
220 void VM::close_tape(int drv)
225 // drec->set_remote(false);
228 bool VM::is_tape_inserted(int drv)
230 return drec->is_tape_inserted();
233 bool VM::is_tape_playing(int drv)
235 return drec->is_tape_playing();
238 bool VM::is_tape_recording(int drv)
240 return drec->is_tape_recording();
243 int VM::get_tape_position(int drv)
245 return drec->get_tape_position();
248 const _TCHAR* VM::get_tape_message(int drv)
250 return drec->get_message();
253 void VM::push_play(int drv)
256 drec->set_remote(true);
259 void VM::push_stop(int drv)
261 drec->set_remote(false);
264 void VM::push_fast_forward(int drv)
267 drec->set_remote(true);
270 void VM::push_fast_rewind(int drv)
272 drec->set_ff_rew(-1);
273 drec->set_remote(true);
276 bool VM::is_frame_skippable()
278 return event->is_frame_skippable();
281 void VM::update_config()
283 for(DEVICE* device = first_device; device; device = device->next_device) {
284 device->update_config();
288 #define STATE_VERSION 3
291 bool VM::process_state(FILEIO* state_fio, bool loading)
293 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
296 for(DEVICE* device = first_device; device; device = device->next_device) {
297 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
298 // const char *name = typeid(*device).name();
299 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
300 const char *name = device->get_device_name();
301 int len = strlen(name);
303 if(!state_fio->StateCheckInt32(len)) {
305 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
309 if(!state_fio->StateCheckBuffer(name, len, 1)) {
311 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
315 if(!device->process_state(state_fio, loading)) {
317 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
322 // Machine specified.