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) : VM_TEMPLATE(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) {
102 // delete all devices
103 for(DEVICE* device = first_device; device;) {
104 DEVICE *next_device = device->next_device;
107 device = next_device;
111 DEVICE* VM::get_device(int id)
113 for(DEVICE* device = first_device; device; device = device->next_device) {
114 if(device->this_device_id == id) {
121 // ----------------------------------------------------------------------------
122 // drive virtual machine
123 // ----------------------------------------------------------------------------
128 for(DEVICE* device = first_device; device; device = device->next_device) {
138 double VM::get_frame_rate()
140 return event->get_frame_rate();
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
148 DEVICE *VM::get_cpu(int index)
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
161 void VM::draw_screen()
163 memory->draw_screen();
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 void VM::initialize_sound(int rate, int samples)
172 // init sound manager
173 event->initialize_sound(rate, samples);
176 uint16_t* VM::create_sound(int* extra_frames)
178 return event->create_sound(extra_frames);
181 int VM::get_sound_buffer_ptr()
183 return event->get_sound_buffer_ptr();
186 #ifdef USE_SOUND_VOLUME
187 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
190 drec->set_volume(0, decibel_l, decibel_r);
192 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
193 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
194 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
203 void VM::key_down(int code, bool repeat)
205 if(code == 0x97 && !repeat) {
210 void VM::key_up(int code)
214 // ----------------------------------------------------------------------------
216 // ----------------------------------------------------------------------------
218 void VM::play_tape(int drv, const _TCHAR* file_path)
220 drec->play_tape(file_path);
221 // drec->set_remote(true);
224 void VM::rec_tape(int drv, const _TCHAR* file_path)
226 drec->rec_tape(file_path);
227 // drec->set_remote(true);
230 void VM::close_tape(int drv)
235 // drec->set_remote(false);
238 bool VM::is_tape_inserted(int drv)
240 return drec->is_tape_inserted();
243 bool VM::is_tape_playing(int drv)
245 return drec->is_tape_playing();
248 bool VM::is_tape_recording(int drv)
250 return drec->is_tape_recording();
253 int VM::get_tape_position(int drv)
255 return drec->get_tape_position();
258 const _TCHAR* VM::get_tape_message(int drv)
260 return drec->get_message();
263 void VM::push_play(int drv)
266 drec->set_remote(true);
269 void VM::push_stop(int drv)
271 drec->set_remote(false);
274 void VM::push_fast_forward(int drv)
277 drec->set_remote(true);
280 void VM::push_fast_rewind(int drv)
282 drec->set_ff_rew(-1);
283 drec->set_remote(true);
286 void VM::load_binary(int drv, const _TCHAR* file_path)
289 memory->load_ram(file_path);
293 void VM::save_binary(int drv, const _TCHAR* file_path)
296 memory->save_ram(file_path);
300 bool VM::is_frame_skippable()
302 return event->is_frame_skippable();
305 void VM::update_config()
307 for(DEVICE* device = first_device; device; device = device->next_device) {
308 device->update_config();
312 #define STATE_VERSION 3
314 #include "../../statesub.h"
315 #include "../../qt/gui/csp_logger.h"
316 extern CSP_Logger DLL_PREFIX_I *csp_logger;
318 void VM::decl_state(void)
320 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::SM_B_80TE_HEAD")), csp_logger);
321 for(DEVICE* device = first_device; device; device = device->next_device) {
322 device->decl_state();
326 void VM::save_state(FILEIO* state_fio)
328 //state_fio->FputUint32(STATE_VERSION);
330 if(state_entry != NULL) {
331 state_entry->save_state(state_fio);
333 for(DEVICE* device = first_device; device; device = device->next_device) {
334 device->save_state(state_fio);
338 bool VM::load_state(FILEIO* state_fio)
340 //if(state_fio->FgetUint32() != STATE_VERSION) {
344 if(state_entry != NULL) {
345 mb = state_entry->load_state(state_fio);
348 emu->out_debug_log("INFO: HEADER DATA ERROR");
351 for(DEVICE* device = first_device; device; device = device->next_device) {
352 if(!device->load_state(state_fio)) {