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"
20 #include "../z80pio.h"
23 #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
39 drec = new DATAREC(this, emu);
40 drec->set_context_noise_play(new NOISE(this, emu));
41 drec->set_context_noise_stop(new NOISE(this, emu));
42 drec->set_context_noise_fast(new NOISE(this, emu));
43 io = new IO(this, emu);
44 not_ear = new NOT(this, emu);
45 cpu = new Z80(this, emu);
46 pio1 = new Z80PIO(this, emu);
47 pio1->set_device_name(_T("8255 PIO (LEDs/Keyboard/CMT)"));
48 pio2 = new Z80PIO(this, emu);
49 pio2->set_device_name(_T("8255 PIO (User)"));
51 memory = new MEMORY(this, emu);
54 event->set_context_cpu(cpu);
55 event->set_context_sound(drec);
56 event->set_context_sound(drec->get_context_noise_play());
57 event->set_context_sound(drec->get_context_noise_stop());
58 event->set_context_sound(drec->get_context_noise_fast());
60 // PIO1 PA0-7 -> 7seg-LED data
61 pio1->set_context_port_a(memory, SIG_MEMORY_PIO1_PA, 0xff, 0);
62 // PIO1 PB0-2 <- Keyboard data
63 // PIO1 PB3-5 -> 7seg-LED/Keyboard column
64 pio1->set_context_port_b(memory, SIG_MEMORY_PIO1_PB, 0x38, 0);
66 pio1->set_context_port_b(drec, SIG_DATAREC_MIC, 0x40, 0);
67 // PIO1 PB7 <- NOT <- EAR
68 drec->set_context_ear(not_ear, SIG_NOT_INPUT, 1);
69 not_ear->set_context_out(pio1, SIG_Z80PIO_PORT_B, 0x80);
71 memory->set_context_cpu(cpu);
72 memory->set_context_drec(drec);
73 memory->set_context_pio1(pio1);
76 cpu->set_context_mem(memory);
77 cpu->set_context_io(io);
78 cpu->set_context_intr(pio1);
80 // z80 family daisy chain
81 pio1->set_context_intr(cpu, 0);
82 pio1->set_context_child(pio2);
83 pio2->set_context_intr(cpu, 1);
85 cpu->set_context_debugger(new DEBUGGER(this, emu));
89 io->set_iomap_range_rw(0xd0, 0xd3, pio1);
90 io->set_iomap_range_rw(0xd4, 0xd7, pio2);
91 io->set_iomap_range_rw(0xd8, 0xdb, memory);
93 // initialize all devices
94 for(DEVICE* device = first_device; device; device = device->next_device) {
101 // delete all devices
102 for(DEVICE* device = first_device; device;) {
103 DEVICE *next_device = device->next_device;
106 device = next_device;
110 DEVICE* VM::get_device(int id)
112 for(DEVICE* device = first_device; device; device = device->next_device) {
113 if(device->this_device_id == id) {
120 // ----------------------------------------------------------------------------
121 // drive virtual machine
122 // ----------------------------------------------------------------------------
127 for(DEVICE* device = first_device; device; device = device->next_device) {
137 double VM::get_frame_rate()
139 return event->get_frame_rate();
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
147 DEVICE *VM::get_cpu(int index)
156 // ----------------------------------------------------------------------------
158 // ----------------------------------------------------------------------------
160 void VM::draw_screen()
162 memory->draw_screen();
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 void VM::initialize_sound(int rate, int samples)
171 // init sound manager
172 event->initialize_sound(rate, samples);
175 uint16_t* VM::create_sound(int* extra_frames)
177 return event->create_sound(extra_frames);
180 int VM::get_sound_buffer_ptr()
182 return event->get_sound_buffer_ptr();
185 #ifdef USE_SOUND_VOLUME
186 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
189 drec->set_volume(0, decibel_l, decibel_r);
191 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
192 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
193 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 void VM::key_down(int code, bool repeat)
204 if(code == 0x97 && !repeat) {
209 void VM::key_up(int code)
213 // ----------------------------------------------------------------------------
215 // ----------------------------------------------------------------------------
217 void VM::play_tape(const _TCHAR* file_path)
219 drec->play_tape(file_path);
220 drec->set_remote(true);
223 void VM::rec_tape(const _TCHAR* file_path)
225 drec->rec_tape(file_path);
226 drec->set_remote(true);
229 void VM::close_tape()
234 drec->set_remote(false);
237 bool VM::is_tape_inserted()
239 return drec->is_tape_inserted();
242 bool VM::is_tape_playing()
244 return drec->is_tape_playing();
247 bool VM::is_tape_recording()
249 return drec->is_tape_recording();
252 int VM::get_tape_position()
254 return drec->get_tape_position();
257 const _TCHAR* VM::get_tape_message()
259 return drec->get_message();
262 void VM::load_binary(int drv, const _TCHAR* file_path)
265 memory->load_ram(file_path);
269 void VM::save_binary(int drv, const _TCHAR* file_path)
272 memory->save_ram(file_path);
276 bool VM::is_frame_skippable()
278 return event->is_frame_skippable();
281 void VM::update_config()
283 for(DEVICE* device = first_device; device; device = device->next_device) {
284 device->update_config();
288 #define STATE_VERSION 2
290 void VM::save_state(FILEIO* state_fio)
292 state_fio->FputUint32(STATE_VERSION);
294 for(DEVICE* device = first_device; device; device = device->next_device) {
295 device->save_state(state_fio);
299 bool VM::load_state(FILEIO* state_fio)
301 if(state_fio->FgetUint32() != STATE_VERSION) {
304 for(DEVICE* device = first_device; device; device = device->next_device) {
305 if(!device->load_state(state_fio)) {