2 TOSHIBA EX-80 Emulator 'eEX-80'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
19 #include "../pcm1bit.h"
22 #include "../debugger.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
37 first_device = last_device = NULL;
38 dummy = new DEVICE(this, emu); // must be 1st device
39 event = new EVENT(this, emu); // must be 2nd device
41 sio = new I8251(this, emu);
42 pio = new I8255(this, emu);
43 io = new IO(this, emu);
44 pcm = new PCM1BIT(this, emu);
45 cpu = new I8080(this, emu);
47 cmt = new CMT(this, emu);
48 display = new DISPLAY(this, emu);
49 keyboard = new KEYBOARD(this, emu);
50 memory = new MEMORY(this, emu);
53 dummy->set_device_name(_T("1st Dummy"));
55 pio->set_device_name(_T("i8255(SOUND/KEY/DISPLAY)"));
56 sio->set_device_name(_T("i8251(CMT)"));
57 pcm->set_device_name(_T("SOUND OUT"));
61 event->set_context_cpu(cpu);
62 event->set_context_sound(pcm);
64 sio->set_context_out(cmt, SIG_CMT_OUT);
65 pio->set_context_port_c(pcm, SIG_PCM1BIT_SIGNAL, 0x08, 0);
66 pio->set_context_port_c(keyboard, SIG_KEYBOARD_COLUMN, 0x70, 0);
67 pio->set_context_port_c(display, SIG_DISPLAY_DMA, 0x80, 0);
68 // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
69 //pcm->set_realtime_render(true);
71 cmt->set_context_sio(sio);
72 display->set_context_cpu(cpu);
73 display->set_ram_ptr(memory->get_ram());
74 keyboard->set_context_pio(pio);
75 memory->set_context_cpu(cpu);
78 cpu->set_context_mem(memory);
79 cpu->set_context_io(io);
80 cpu->set_context_intr(dummy);
82 cpu->set_context_debugger(new DEBUGGER(this, emu));
86 io->set_iomap_range_rw(0xdc, 0xdd, sio);
87 io->set_iomap_range_rw(0xf8, 0xfb, pio);
89 // initialize all devices
90 #if defined(__GIT_REPO_VERSION)
91 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
93 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 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
142 DEVICE *VM::get_cpu(int index)
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 void VM::draw_screen()
157 display->draw_screen();
160 int VM::max_draw_ranges()
162 return (config.monitor_type == 0) ? 9 : 8;
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 void VM::initialize_sound(int rate, int samples)
171 // init sound manager
172 event->initialize_sound(rate, samples);
175 pcm->initialize_sound(rate, 8000);
178 uint16_t* VM::create_sound(int* extra_frames)
180 return event->create_sound(extra_frames);
183 int VM::get_sound_buffer_ptr()
185 return event->get_sound_buffer_ptr();
188 #ifdef USE_SOUND_VOLUME
189 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
192 pcm->set_volume(0, decibel_l, decibel_r);
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 void VM::load_binary(int drv, const _TCHAR* file_path)
204 memory->load_binary(file_path);
208 void VM::save_binary(int drv, const _TCHAR* file_path)
211 memory->save_binary(file_path);
215 void VM::play_tape(int drv, const _TCHAR* file_path)
217 cmt->play_tape(file_path);
220 void VM::rec_tape(int drv, const _TCHAR* file_path)
222 cmt->rec_tape(file_path);
225 void VM::close_tape(int drv)
230 bool VM::is_tape_inserted(int drv)
232 return cmt->is_tape_inserted();
235 bool VM::is_frame_skippable()
237 return event->is_frame_skippable();
240 void VM::update_config()
242 for(DEVICE* device = first_device; device; device = device->next_device) {
243 device->update_config();
247 #define STATE_VERSION 2
249 #include "../../statesub.h"
250 #include "../../qt/gui/csp_logger.h"
251 extern CSP_Logger DLL_PREFIX_I *csp_logger;
253 void VM::decl_state(void)
255 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::EX80_HEAD")), csp_logger);
256 for(DEVICE* device = first_device; device; device = device->next_device) {
257 device->decl_state();
261 void VM::save_state(FILEIO* state_fio)
263 //state_fio->FputUint32(STATE_VERSION);
265 if(state_entry != NULL) {
266 state_entry->save_state(state_fio);
268 for(DEVICE* device = first_device; device; device = device->next_device) {
269 device->save_state(state_fio);
273 bool VM::load_state(FILEIO* state_fio)
275 //if(state_fio->FgetUint32() != STATE_VERSION) {
279 if(state_entry != NULL) {
280 mb = state_entry->load_state(state_fio);
283 emu->out_debug_log("INFO: HEADER DATA ERROR");
286 for(DEVICE* device = first_device; device; device = device->next_device) {
287 if(!device->load_state(state_fio)) {