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) : emu(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) {
84 for(DEVICE* device = first_device; device;) {
85 DEVICE *next_device = device->next_device;
92 DEVICE* VM::get_device(int id)
94 for(DEVICE* device = first_device; device; device = device->next_device) {
95 if(device->this_device_id == id) {
102 // ----------------------------------------------------------------------------
103 // drive virtual machine
104 // ----------------------------------------------------------------------------
109 for(DEVICE* device = first_device; device; device = device->next_device) {
114 void VM::special_reset()
117 for(DEVICE* device = first_device; device; device = device->next_device) {
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
133 DEVICE *VM::get_cpu(int index)
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 void VM::draw_screen()
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 void VM::initialize_sound(int rate, int samples)
157 // init sound manager
158 event->initialize_sound(rate, samples);
161 beep->initialize_sound(rate, 1000, 8000);
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 beep->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)
198 void VM::key_up(int code)
203 // ----------------------------------------------------------------------------
205 // ----------------------------------------------------------------------------
207 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
209 tf20->open_disk(drv, file_path, bank);
212 void VM::close_floppy_disk(int drv)
214 tf20->close_disk(drv);
217 bool VM::is_floppy_disk_inserted(int drv)
219 return tf20->is_disk_inserted(drv);
222 void VM::is_floppy_disk_protected(int drv, bool value)
224 tf20->is_disk_protected(drv, value);
227 bool VM::is_floppy_disk_protected(int drv)
229 return tf20->is_disk_protected(drv);
232 uint32_t VM::is_floppy_disk_accessed()
234 return tf20->read_signal(0);
237 void VM::play_tape(int drv, const _TCHAR* file_path)
239 drec->play_tape(file_path);
242 void VM::rec_tape(int drv, const _TCHAR* file_path)
244 drec->rec_tape(file_path);
247 void VM::close_tape(int drv)
254 bool VM::is_tape_inserted(int drv)
256 return drec->is_tape_inserted();
259 bool VM::is_tape_playing(int drv)
261 return drec->is_tape_playing();
264 bool VM::is_tape_recording(int drv)
266 return drec->is_tape_recording();
269 int VM::get_tape_position(int drv)
271 return drec->get_tape_position();
274 const _TCHAR* VM::get_tape_message(int drv)
276 return drec->get_message();
279 bool VM::is_frame_skippable()
281 return event->is_frame_skippable();
284 void VM::update_config()
286 for(DEVICE* device = first_device; device; device = device->next_device) {
287 device->update_config();
291 #define STATE_VERSION 3
293 void VM::save_state(FILEIO* state_fio)
295 state_fio->FputUint32(STATE_VERSION);
297 for(DEVICE* device = first_device; device; device = device->next_device) {
298 const char *name = typeid(*device).name() + 6; // skip "class "
300 state_fio->FputInt32(strlen(name));
301 state_fio->Fwrite(name, strlen(name), 1);
302 device->save_state(state_fio);
306 bool VM::load_state(FILEIO* state_fio)
308 if(state_fio->FgetUint32() != STATE_VERSION) {
311 for(DEVICE* device = first_device; device; device = device->next_device) {
312 const char *name = typeid(*device).name() + 6; // skip "class "
314 if(!(state_fio->FgetInt32() == strlen(name) && state_fio->Fcompare(name, strlen(name)))) {
317 if(!device->load_state(state_fio)) {