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 EX80_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) {
100 // delete all devices
101 for(DEVICE* device = first_device; device;) {
102 DEVICE *next_device = device->next_device;
105 device = next_device;
109 DEVICE* VM::get_device(int id)
111 for(DEVICE* device = first_device; device; device = device->next_device) {
112 if(device->this_device_id == id) {
119 // ----------------------------------------------------------------------------
120 // drive virtual machine
121 // ----------------------------------------------------------------------------
126 for(DEVICE* device = first_device; device; device = device->next_device) {
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
141 DEVICE *VM::get_cpu(int index)
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 void VM::draw_screen()
156 display->draw_screen();
159 int VM::max_draw_ranges()
161 return (config.monitor_type == 0) ? 9 : 8;
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 void VM::initialize_sound(int rate, int samples)
170 // init sound manager
171 event->initialize_sound(rate, samples);
174 pcm->initialize_sound(rate, 8000);
177 uint16_t* VM::create_sound(int* extra_frames)
179 return event->create_sound(extra_frames);
182 int VM::get_sound_buffer_ptr()
184 return event->get_sound_buffer_ptr();
187 #ifdef USE_SOUND_VOLUME
188 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
191 pcm->set_volume(0, decibel_l, decibel_r);
196 // ----------------------------------------------------------------------------
198 // ----------------------------------------------------------------------------
200 void VM::load_binary(int drv, const _TCHAR* file_path)
203 memory->load_binary(file_path);
207 void VM::save_binary(int drv, const _TCHAR* file_path)
210 memory->save_binary(file_path);
214 void VM::play_tape(int drv, const _TCHAR* file_path)
216 cmt->play_tape(file_path);
219 void VM::rec_tape(int drv, const _TCHAR* file_path)
221 cmt->rec_tape(file_path);
224 void VM::close_tape(int drv)
229 bool VM::is_tape_inserted(int drv)
231 return cmt->is_tape_inserted();
234 bool VM::is_frame_skippable()
236 return event->is_frame_skippable();
239 void VM::update_config()
241 for(DEVICE* device = first_device; device; device = device->next_device) {
242 device->update_config();
246 #define STATE_VERSION 2
248 bool VM::process_state(FILEIO* state_fio, bool loading)
250 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
253 for(DEVICE* device = first_device; device; device = device->next_device) {
254 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
255 // const char *name = typeid(*device).name();
256 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
257 const char *name = device->get_device_name();
258 int len = strlen(name);
260 if(!state_fio->StateCheckInt32(len)) {
262 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
266 if(!state_fio->StateCheckBuffer(name, len, 1)) {
268 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
272 if(!device->process_state(state_fio, loading)) {
274 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
279 // Machine specified.