2 EPSON HC-40 Emulator 'eHC-40'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
16 #include "../datarec.h"
21 #include "../debugger.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 VM::VM(EMU* parent_emu) : emu(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 beep = new BEEP(this, emu);
39 drec = new DATAREC(this, emu);
40 tf20 = new PTF20(this, emu);
41 cpu = new Z80(this, emu);
43 io = new IO(this, emu);
44 memory = new MEMORY(this, emu);
47 event->set_context_cpu(cpu);
48 event->set_context_sound(beep);
49 event->set_context_sound(drec);
51 drec->set_context_ear(io, SIG_IO_DREC, 1);
52 tf20->set_context_sio(io, SIG_IO_ART);
54 io->set_context_cpu(cpu);
55 io->set_context_mem(memory, memory->get_ram());
56 io->set_context_tf20(tf20);
57 io->set_context_beep(beep);
58 io->set_context_drec(drec);
61 cpu->set_context_mem(memory);
62 cpu->set_context_io(io);
63 cpu->set_context_intr(io);
65 cpu->set_context_debugger(new DEBUGGER(this, emu));
68 // initialize all devices
69 for(DEVICE* device = first_device; device; device = device->next_device) {
77 for(DEVICE* device = first_device; device;) {
78 DEVICE *next_device = device->next_device;
85 DEVICE* VM::get_device(int id)
87 for(DEVICE* device = first_device; device; device = device->next_device) {
88 if(device->this_device_id == id) {
95 // ----------------------------------------------------------------------------
96 // drive virtual machine
97 // ----------------------------------------------------------------------------
102 for(DEVICE* device = first_device; device; device = device->next_device) {
107 void VM::special_reset()
110 for(DEVICE* device = first_device; device; device = device->next_device) {
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
126 DEVICE *VM::get_cpu(int index)
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 void VM::draw_screen()
144 int VM::access_lamp()
146 uint32 status = tf20->read_signal(0);
147 return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 void VM::initialize_sound(int rate, int samples)
156 // init sound manager
157 event->initialize_sound(rate, samples);
160 beep->init(rate, 1000, 8000);
163 uint16* VM::create_sound(int* extra_frames)
165 return event->create_sound(extra_frames);
168 int VM::sound_buffer_ptr()
170 return event->sound_buffer_ptr();
173 #ifdef USE_SOUND_VOLUME
174 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
177 beep->set_volume(0, decibel_l, decibel_r);
179 drec->set_volume(0, decibel_l, decibel_r);
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 void VM::key_down(int code, bool repeat)
193 void VM::key_up(int code)
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 void VM::open_disk(int drv, const _TCHAR* file_path, int bank)
204 tf20->open_disk(drv, file_path, bank);
207 void VM::close_disk(int drv)
209 tf20->close_disk(drv);
212 bool VM::disk_inserted(int drv)
214 return tf20->disk_inserted(drv);
217 void VM::set_disk_protected(int drv, bool value)
219 tf20->set_disk_protected(drv, value);
222 bool VM::get_disk_protected(int drv)
224 return tf20->get_disk_protected(drv);
227 void VM::play_tape(const _TCHAR* file_path)
229 drec->play_tape(file_path);
232 void VM::rec_tape(const _TCHAR* file_path)
234 drec->rec_tape(file_path);
237 void VM::close_tape()
242 bool VM::tape_inserted()
244 return drec->tape_inserted();
247 bool VM::tape_playing()
249 return drec->tape_playing();
252 bool VM::tape_recording()
254 return drec->tape_recording();
257 int VM::tape_position()
259 return drec->tape_position();
264 return event->now_skip();
267 void VM::update_config()
269 for(DEVICE* device = first_device; device; device = device->next_device) {
270 device->update_config();
274 #define STATE_VERSION 1
276 void VM::save_state(FILEIO* state_fio)
278 state_fio->FputUint32(STATE_VERSION);
280 for(DEVICE* device = first_device; device; device = device->next_device) {
281 device->save_state(state_fio);
285 bool VM::load_state(FILEIO* state_fio)
287 if(state_fio->FgetUint32() != STATE_VERSION) {
290 for(DEVICE* device = first_device; device; device = device->next_device) {
291 if(!device->load_state(state_fio)) {