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"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
35 first_device = last_device = NULL;
36 dummy = new DEVICE(this, emu); // must be 1st device
37 event = new EVENT(this, emu); // must be 2nd device
38 dummy->set_device_name(_T("1st Dummy"));
40 beep = new BEEP(this, emu);
41 drec = new DATAREC(this, emu);
42 drec->set_context_noise_play(new NOISE(this, emu));
43 drec->set_context_noise_stop(new NOISE(this, emu));
44 drec->set_context_noise_fast(new NOISE(this, emu));
45 tf20 = new PTF20(this, emu);
46 cpu = new Z80(this, emu);
48 io = new IO(this, emu);
49 memory = new MEMORY(this, emu);
51 event->set_context_cpu(cpu);
52 event->set_context_sound(beep);
53 event->set_context_sound(drec);
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(io, SIG_IO_DREC, 1);
59 tf20->set_context_sio(io, SIG_IO_ART);
61 io->set_context_cpu(cpu);
62 io->set_context_mem(memory, memory->get_ram());
63 io->set_context_tf20(tf20);
64 io->set_context_beep(beep);
65 io->set_context_drec(drec);
68 cpu->set_context_mem(memory);
69 cpu->set_context_io(io);
70 cpu->set_context_intr(io);
72 cpu->set_context_debugger(new DEBUGGER(this, emu));
75 // initialize all devices
76 for(DEVICE* device = first_device; device; device = device->next_device) {
85 for(DEVICE* device = first_device; device;) {
86 DEVICE *next_device = device->next_device;
93 DEVICE* VM::get_device(int id)
95 for(DEVICE* device = first_device; device; device = device->next_device) {
96 if(device->this_device_id == id) {
103 // ----------------------------------------------------------------------------
104 // drive virtual machine
105 // ----------------------------------------------------------------------------
110 for(DEVICE* device = first_device; device; device = device->next_device) {
115 void VM::special_reset()
118 for(DEVICE* device = first_device; device; device = device->next_device) {
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
134 DEVICE *VM::get_cpu(int index)
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
147 void VM::draw_screen()
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 void VM::initialize_sound(int rate, int samples)
158 // init sound manager
159 event->initialize_sound(rate, samples);
162 beep->initialize_sound(rate, 1000, 8000);
165 uint16_t* VM::create_sound(int* extra_frames)
167 return event->create_sound(extra_frames);
170 int VM::get_sound_buffer_ptr()
172 return event->get_sound_buffer_ptr();
175 #ifdef USE_SOUND_VOLUME
176 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
179 beep->set_volume(0, decibel_l, decibel_r);
181 drec->set_volume(0, decibel_l, decibel_r);
183 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
184 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
185 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 void VM::key_down(int code, bool repeat)
199 void VM::key_up(int code)
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
210 tf20->open_disk(drv, file_path, bank);
213 void VM::close_floppy_disk(int drv)
215 tf20->close_disk(drv);
218 bool VM::is_floppy_disk_inserted(int drv)
220 return tf20->is_disk_inserted(drv);
223 void VM::is_floppy_disk_protected(int drv, bool value)
225 tf20->is_disk_protected(drv, value);
228 bool VM::is_floppy_disk_protected(int drv)
230 return tf20->is_disk_protected(drv);
233 uint32_t VM::is_floppy_disk_accessed()
235 return tf20->read_signal(0);
238 void VM::play_tape(int drv, const _TCHAR* file_path)
240 drec->play_tape(file_path);
241 // drec->set_remote(true);
244 void VM::rec_tape(int drv, const _TCHAR* file_path)
246 drec->rec_tape(file_path);
247 // drec->set_remote(true);
250 void VM::close_tape(int drv)
255 // drec->set_remote(false);
258 bool VM::is_tape_inserted(int drv)
260 return drec->is_tape_inserted();
263 bool VM::is_tape_playing(int drv)
265 return drec->is_tape_playing();
268 bool VM::is_tape_recording(int drv)
270 return drec->is_tape_recording();
273 int VM::get_tape_position(int drv)
275 return drec->get_tape_position();
278 const _TCHAR* VM::get_tape_message(int drv)
280 return drec->get_message();
283 void VM::push_play(int drv)
286 drec->set_remote(true);
289 void VM::push_stop(int drv)
291 drec->set_remote(false);
294 void VM::push_fast_forward(int drv)
297 drec->set_remote(true);
300 void VM::push_fast_rewind(int drv)
302 drec->set_ff_rew(-1);
303 drec->set_remote(true);
306 bool VM::is_frame_skippable()
308 return event->is_frame_skippable();
311 void VM::update_config()
313 for(DEVICE* device = first_device; device; device = device->next_device) {
314 device->update_config();
318 #define STATE_VERSION 3
320 #include "../../statesub.h"
321 #include "../../qt/gui/csp_logger.h"
322 extern CSP_Logger DLL_PREFIX_I *csp_logger;
324 void VM::decl_state(void)
326 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::HC_40_HEAD")), csp_logger);
327 for(DEVICE* device = first_device; device; device = device->next_device) {
328 device->decl_state();
332 void VM::save_state(FILEIO* state_fio)
334 //state_fio->FputUint32(STATE_VERSION);
336 if(state_entry != NULL) {
337 state_entry->save_state(state_fio);
339 for(DEVICE* device = first_device; device; device = device->next_device) {
340 device->save_state(state_fio);
344 bool VM::load_state(FILEIO* state_fio)
346 //if(state_fio->FgetUint32() != STATE_VERSION) {
350 if(state_entry != NULL) {
351 mb = state_entry->load_state(state_fio);
354 emu->out_debug_log("INFO: HEADER DATA ERROR");
357 for(DEVICE* device = first_device; device; device = device->next_device) {
358 if(!device->load_state(state_fio)) {