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);
50 drec->set_context_out(io, SIG_IO_DREC, 1);
51 tf20->set_context_sio(io, SIG_IO_ART);
53 io->set_context_cpu(cpu);
54 io->set_context_mem(memory, memory->get_ram());
55 io->set_context_tf20(tf20);
56 io->set_context_beep(beep);
57 io->set_context_drec(drec);
60 cpu->set_context_mem(memory);
61 cpu->set_context_io(io);
62 cpu->set_context_intr(io);
64 cpu->set_context_debugger(new DEBUGGER(this, emu));
67 // initialize all devices
68 for(DEVICE* device = first_device; device; device = device->next_device) {
76 for(DEVICE* device = first_device; device;) {
77 DEVICE *next_device = device->next_device;
84 DEVICE* VM::get_device(int id)
86 for(DEVICE* device = first_device; device; device = device->next_device) {
87 if(device->this_device_id == id) {
94 // ----------------------------------------------------------------------------
95 // drive virtual machine
96 // ----------------------------------------------------------------------------
101 for(DEVICE* device = first_device; device; device = device->next_device) {
106 void VM::special_reset()
109 for(DEVICE* device = first_device; device; device = device->next_device) {
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
125 DEVICE *VM::get_cpu(int index)
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 void VM::draw_screen()
143 int VM::access_lamp()
145 uint32 status = tf20->read_signal(0);
146 return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 void VM::initialize_sound(int rate, int samples)
155 // init sound manager
156 event->initialize_sound(rate, samples);
159 beep->init(rate, 1000, 8000);
162 uint16* VM::create_sound(int* extra_frames)
164 return event->create_sound(extra_frames);
167 int VM::sound_buffer_ptr()
169 return event->sound_buffer_ptr();
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
176 void VM::key_down(int code, bool repeat)
181 void VM::key_up(int code)
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 void VM::open_disk(int drv, _TCHAR* file_path, int bank)
192 tf20->open_disk(drv, file_path, bank);
195 void VM::close_disk(int drv)
197 tf20->close_disk(drv);
200 bool VM::disk_inserted(int drv)
202 return tf20->disk_inserted(drv);
205 void VM::play_tape(_TCHAR* file_path)
207 drec->play_tape(file_path);
210 void VM::rec_tape(_TCHAR* file_path)
212 drec->rec_tape(file_path);
215 void VM::close_tape()
220 bool VM::tape_inserted()
222 return drec->tape_inserted();
227 return event->now_skip();
230 void VM::update_config()
232 for(DEVICE* device = first_device; device; device = device->next_device) {
233 device->update_config();