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"
26 #include "./display.h"
27 #include "./keyboard.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
42 first_device = last_device = NULL;
43 dummy = new DEVICE(this, emu); // must be 1st device
44 event = new EVENT(this, emu); // must be 2nd device
46 sio = new I8251(this, emu);
47 pio = new I8255(this, emu);
48 io = new IO(this, emu);
49 pcm = new PCM1BIT(this, emu);
50 cpu = new I8080(this, emu);
52 cmt = new CMT(this, emu);
53 display = new DISPLAY(this, emu);
54 keyboard = new KEYBOARD(this, emu);
55 memory = new MEMORY(this, emu);
58 dummy->set_device_name(_T("1st Dummy"));
60 pio->set_device_name(_T("i8255(SOUND/KEY/DISPLAY)"));
61 sio->set_device_name(_T("i8251(CMT)"));
62 pcm->set_device_name(_T("SOUND OUT"));
66 event->set_context_cpu(cpu);
67 event->set_context_sound(pcm);
69 sio->set_context_out(cmt, SIG_CMT_OUT);
70 pio->set_context_port_c(pcm, SIG_PCM1BIT_SIGNAL, 0x08, 0);
71 pio->set_context_port_c(keyboard, SIG_KEYBOARD_COLUMN, 0x70, 0);
72 pio->set_context_port_c(display, SIG_DISPLAY_DMA, 0x80, 0);
73 // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
74 //pcm->set_realtime_render(true);
76 cmt->set_context_sio(sio);
77 display->set_context_cpu(cpu);
78 display->set_ram_ptr(memory->get_ram());
79 keyboard->set_context_pio(pio);
80 memory->set_context_cpu(cpu);
83 cpu->set_context_mem(memory);
84 cpu->set_context_io(io);
85 cpu->set_context_intr(dummy);
87 cpu->set_context_debugger(new DEBUGGER(this, emu));
91 io->set_iomap_range_rw(0xdc, 0xdd, sio);
92 io->set_iomap_range_rw(0xf8, 0xfb, pio);
94 // initialize all devices
95 #if defined(__GIT_REPO_VERSION)
96 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
98 for(DEVICE* device = first_device; device; device = device->next_device) {
105 // delete all devices
106 for(DEVICE* device = first_device; device;) {
107 DEVICE *next_device = device->next_device;
110 device = next_device;
114 DEVICE* VM::get_device(int id)
116 for(DEVICE* device = first_device; device; device = device->next_device) {
117 if(device->this_device_id == id) {
124 // ----------------------------------------------------------------------------
125 // drive virtual machine
126 // ----------------------------------------------------------------------------
131 for(DEVICE* device = first_device; device; device = device->next_device) {
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
146 DEVICE *VM::get_cpu(int index)
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 void VM::draw_screen()
161 display->draw_screen();
164 int VM::max_draw_ranges()
166 return (config.monitor_type == 0) ? 9 : 8;
169 // ----------------------------------------------------------------------------
171 // ----------------------------------------------------------------------------
173 void VM::initialize_sound(int rate, int samples)
175 // init sound manager
176 event->initialize_sound(rate, samples);
179 pcm->initialize_sound(rate, 8000);
182 uint16_t* VM::create_sound(int* extra_frames)
184 return event->create_sound(extra_frames);
187 int VM::get_sound_buffer_ptr()
189 return event->get_sound_buffer_ptr();
192 #ifdef USE_SOUND_VOLUME
193 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
196 pcm->set_volume(0, decibel_l, decibel_r);
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
205 void VM::load_binary(int drv, const _TCHAR* file_path)
208 memory->load_binary(file_path);
212 void VM::save_binary(int drv, const _TCHAR* file_path)
215 memory->save_binary(file_path);
219 void VM::play_tape(int drv, const _TCHAR* file_path)
221 cmt->play_tape(file_path);
224 void VM::rec_tape(int drv, const _TCHAR* file_path)
226 cmt->rec_tape(file_path);
229 void VM::close_tape(int drv)
234 bool VM::is_tape_inserted(int drv)
236 return cmt->is_tape_inserted();
239 bool VM::is_frame_skippable()
241 return event->is_frame_skippable();
244 void VM::update_config()
246 for(DEVICE* device = first_device; device; device = device->next_device) {
247 device->update_config();
251 #define STATE_VERSION 2
253 bool VM::process_state(FILEIO* state_fio, bool loading)
255 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
258 for(DEVICE* device = first_device; device; device = device->next_device) {
259 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
260 // const char *name = typeid(*device).name();
261 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
262 const char *name = device->get_device_name();
263 int len = strlen(name);
265 if(!state_fio->StateCheckInt32(len)) {
267 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
271 if(!state_fio->StateCheckBuffer(name, len, 1)) {
273 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
277 if(!device->process_state(state_fio, loading)) {
279 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
284 // Machine specified.