2 SHARP SM-B-80TE Emulator 'eSM-B-80TE'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
19 #include "../z80pio.h"
22 #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 drec = new DATAREC(this, emu);
39 io = new IO(this, emu);
40 not_ear = new NOT(this, emu);
41 cpu = new Z80(this, emu);
42 pio1 = new Z80PIO(this, emu);
43 pio2 = new Z80PIO(this, emu);
45 memory = new MEMORY(this, emu);
48 event->set_context_cpu(cpu);
50 // PIO1 PA0-7 -> 7seg-LED data
51 pio1->set_context_port_a(memory, SIG_MEMORY_PIO1_PA, 0xff, 0);
52 // PIO1 PB0-2 <- Keyboard data
53 // PIO1 PB3-5 -> 7seg-LED/Keyboard column
54 pio1->set_context_port_b(memory, SIG_MEMORY_PIO1_PB, 0x38, 0);
56 pio1->set_context_port_b(drec, SIG_DATAREC_MIC, 0x40, 0);
57 // PIO1 PB7 <- NOT <- EAR
58 drec->set_context_ear(not_ear, SIG_NOT_INPUT, 1);
59 not_ear->set_context_out(pio1, SIG_Z80PIO_PORT_B, 0x80);
61 memory->set_context_cpu(cpu);
62 memory->set_context_drec(drec);
63 memory->set_context_pio1(pio1);
66 cpu->set_context_mem(memory);
67 cpu->set_context_io(io);
68 cpu->set_context_intr(pio1);
70 // z80 family daisy chain
71 pio1->set_context_intr(cpu, 0);
72 pio1->set_context_child(pio2);
73 pio2->set_context_intr(cpu, 1);
75 cpu->set_context_debugger(new DEBUGGER(this, emu));
79 io->set_iomap_range_rw(0xd0, 0xd3, pio1);
80 io->set_iomap_range_rw(0xd4, 0xd7, pio2);
81 io->set_iomap_range_rw(0xd8, 0xdb, memory);
83 // initialize all devices
84 for(DEVICE* device = first_device; device; device = device->next_device) {
92 for(DEVICE* device = first_device; device;) {
93 DEVICE *next_device = device->next_device;
100 DEVICE* VM::get_device(int id)
102 for(DEVICE* device = first_device; device; device = device->next_device) {
103 if(device->this_device_id == id) {
110 // ----------------------------------------------------------------------------
111 // drive virtual machine
112 // ----------------------------------------------------------------------------
117 for(DEVICE* device = first_device; device; device = device->next_device) {
127 double VM::get_frame_rate()
129 return event->get_frame_rate();
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
137 DEVICE *VM::get_cpu(int index)
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
150 void VM::draw_screen()
152 memory->draw_screen();
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 void VM::initialize_sound(int rate, int samples)
161 // init sound manager
162 event->initialize_sound(rate, samples);
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 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
179 void VM::key_down(int code, bool repeat)
181 if(code == 0x97 && !repeat) {
186 void VM::key_up(int code)
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 void VM::play_tape(const _TCHAR* file_path)
196 drec->play_tape(file_path);
197 drec->set_remote(true);
200 void VM::rec_tape(const _TCHAR* file_path)
202 drec->rec_tape(file_path);
203 drec->set_remote(true);
206 void VM::close_tape()
209 drec->set_remote(false);
212 bool VM::is_tape_inserted()
214 return drec->is_tape_inserted();
217 bool VM::is_tape_playing()
219 return drec->is_tape_playing();
222 bool VM::is_tape_recording()
224 return drec->is_tape_recording();
227 int VM::get_tape_position()
229 return drec->get_tape_position();
232 void VM::load_binary(int drv, const _TCHAR* file_path)
235 memory->load_ram(file_path);
239 void VM::save_binary(int drv, const _TCHAR* file_path)
242 memory->save_ram(file_path);
246 bool VM::is_frame_skippable()
248 return event->is_frame_skippable();
251 void VM::update_config()
253 for(DEVICE* device = first_device; device; device = device->next_device) {
254 device->update_config();
258 #define STATE_VERSION 1
260 void VM::save_state(FILEIO* state_fio)
262 state_fio->FputUint32(STATE_VERSION);
264 for(DEVICE* device = first_device; device; device = device->next_device) {
265 device->save_state(state_fio);
269 bool VM::load_state(FILEIO* state_fio)
271 if(state_fio->FgetUint32() != STATE_VERSION) {
274 for(DEVICE* device = first_device; device; device = device->next_device) {
275 if(!device->load_state(state_fio)) {