2 EPSON HC-40 Emulator 'eHC-40'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
16 #include "../datarec.h"
22 #include "../debugger.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
38 first_device = last_device = NULL;
39 dummy = new DEVICE(this, emu); // must be 1st device
40 event = new EVENT(this, emu); // must be 2nd device
41 dummy->set_device_name(_T("1st Dummy"));
43 beep = new BEEP(this, emu);
44 drec = new DATAREC(this, emu);
45 drec->set_context_noise_play(new NOISE(this, emu));
46 drec->set_context_noise_stop(new NOISE(this, emu));
47 drec->set_context_noise_fast(new NOISE(this, emu));
48 tf20 = new PTF20(this, emu);
49 cpu = new Z80(this, emu);
51 io = new IO(this, emu);
52 memory = new MEMORY(this, emu);
54 event->set_context_cpu(cpu);
55 event->set_context_sound(beep);
56 event->set_context_sound(drec);
57 event->set_context_sound(drec->get_context_noise_play());
58 event->set_context_sound(drec->get_context_noise_stop());
59 event->set_context_sound(drec->get_context_noise_fast());
61 drec->set_context_ear(io, SIG_IO_DREC, 1);
62 tf20->set_context_sio(io, SIG_IO_ART);
64 io->set_context_cpu(cpu);
65 io->set_context_mem(memory, memory->get_ram());
66 io->set_context_tf20(tf20);
67 io->set_context_beep(beep);
68 io->set_context_drec(drec);
71 cpu->set_context_mem(memory);
72 cpu->set_context_io(io);
73 cpu->set_context_intr(io);
75 cpu->set_context_debugger(new DEBUGGER(this, emu));
78 // initialize all devices
79 #if defined(__GIT_REPO_VERSION)
80 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
82 for(DEVICE* device = first_device; device; device = device->next_device) {
90 for(DEVICE* device = first_device; device;) {
91 DEVICE *next_device = device->next_device;
98 DEVICE* VM::get_device(int id)
100 for(DEVICE* device = first_device; device; device = device->next_device) {
101 if(device->this_device_id == id) {
108 // ----------------------------------------------------------------------------
109 // drive virtual machine
110 // ----------------------------------------------------------------------------
115 for(DEVICE* device = first_device; device; device = device->next_device) {
120 void VM::special_reset()
123 for(DEVICE* device = first_device; device; device = device->next_device) {
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
139 DEVICE *VM::get_cpu(int index)
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 void VM::draw_screen()
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
161 void VM::initialize_sound(int rate, int samples)
163 // init sound manager
164 event->initialize_sound(rate, samples);
167 beep->initialize_sound(rate, 1000, 8000);
170 uint16_t* VM::create_sound(int* extra_frames)
172 return event->create_sound(extra_frames);
175 int VM::get_sound_buffer_ptr()
177 return event->get_sound_buffer_ptr();
180 #ifdef USE_SOUND_VOLUME
181 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
184 beep->set_volume(0, decibel_l, decibel_r);
186 drec->set_volume(0, decibel_l, decibel_r);
188 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
189 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
190 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
195 // ----------------------------------------------------------------------------
197 // ----------------------------------------------------------------------------
199 void VM::key_down(int code, bool repeat)
204 void VM::key_up(int code)
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
215 tf20->open_disk(drv, file_path, bank);
218 void VM::close_floppy_disk(int drv)
220 tf20->close_disk(drv);
223 bool VM::is_floppy_disk_inserted(int drv)
225 return tf20->is_disk_inserted(drv);
228 void VM::is_floppy_disk_protected(int drv, bool value)
230 tf20->is_disk_protected(drv, value);
233 bool VM::is_floppy_disk_protected(int drv)
235 return tf20->is_disk_protected(drv);
238 uint32_t VM::is_floppy_disk_accessed()
240 return tf20->read_signal(0);
243 void VM::play_tape(int drv, const _TCHAR* file_path)
245 drec->play_tape(file_path);
246 // drec->set_remote(true);
249 void VM::rec_tape(int drv, const _TCHAR* file_path)
251 drec->rec_tape(file_path);
252 // drec->set_remote(true);
255 void VM::close_tape(int drv)
260 // drec->set_remote(false);
263 bool VM::is_tape_inserted(int drv)
265 return drec->is_tape_inserted();
268 bool VM::is_tape_playing(int drv)
270 return drec->is_tape_playing();
273 bool VM::is_tape_recording(int drv)
275 return drec->is_tape_recording();
278 int VM::get_tape_position(int drv)
280 return drec->get_tape_position();
283 const _TCHAR* VM::get_tape_message(int drv)
285 return drec->get_message();
288 void VM::push_play(int drv)
291 drec->set_remote(true);
294 void VM::push_stop(int drv)
296 drec->set_remote(false);
299 void VM::push_fast_forward(int drv)
302 drec->set_remote(true);
305 void VM::push_fast_rewind(int drv)
307 drec->set_ff_rew(-1);
308 drec->set_remote(true);
311 bool VM::is_frame_skippable()
313 return event->is_frame_skippable();
316 void VM::update_config()
318 for(DEVICE* device = first_device; device; device = device->next_device) {
319 device->update_config();
323 #define STATE_VERSION 3
325 bool VM::process_state(FILEIO* state_fio, bool loading)
327 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
330 for(DEVICE* device = first_device; device; device = device->next_device) {
331 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
332 // const char *name = typeid(*device).name();
333 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
334 const char *name = device->get_device_name();
335 int len = strlen(name);
337 if(!state_fio->StateCheckInt32(len)) {
339 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
343 if(!state_fio->StateCheckBuffer(name, len, 1)) {
345 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
349 if(!device->process_state(state_fio, loading)) {
351 printf("Data loading Error: DEVID=%d\n", device->this_device_id);