2 NEC PC-8201 Emulator 'ePC-8201'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
20 #include "../pcm1bit.h"
21 #include "../upd1990a.h"
24 #include "../debugger.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
39 first_device = last_device = NULL;
40 dummy = new DEVICE(this, emu); // must be 1st device
41 event = new EVENT(this, emu); // must be 2nd device
43 drec = new DATAREC(this, emu);
44 drec->set_context_noise_play(new NOISE(this, emu));
45 drec->set_context_noise_stop(new NOISE(this, emu));
46 drec->set_context_noise_fast(new NOISE(this, emu));
47 cpu = new I8080(this, emu);
48 pio = new I8155(this, emu);
49 io = new IO(this, emu);
50 pcm = new PCM1BIT(this, emu);
51 rtc = new UPD1990A(this, emu);
53 cmt = new CMT(this, emu);
54 keyboard = new KEYBOARD(this, emu);
55 lcd = new LCD(this, emu);
56 memory = new MEMORY(this, emu);
59 event->set_context_cpu(cpu);
60 event->set_context_sound(pcm);
61 event->set_context_sound(drec);
62 event->set_context_sound(drec->get_context_noise_play());
63 event->set_context_sound(drec->get_context_noise_stop());
64 event->set_context_sound(drec->get_context_noise_fast());
66 drec->set_context_ear(cpu, SIG_I8085_SID, 1);
67 cpu->set_context_sod(cmt, SIG_CMT_SOD, 1);
68 pio->set_context_port_a(rtc, SIG_UPD1990A_C0, 1, 0);
69 pio->set_context_port_a(rtc, SIG_UPD1990A_C1, 2, 0);
70 pio->set_context_port_a(rtc, SIG_UPD1990A_C2, 4, 0);
71 pio->set_context_port_a(rtc, SIG_UPD1990A_CLK, 8, 0);
72 pio->set_context_port_a(rtc, SIG_UPD1990A_DIN, 0x10, 0);
73 pio->set_context_port_a(keyboard, SIG_KEYBOARD_COLUMN_L, 0xff, 0);
74 pio->set_context_port_a(lcd, SIG_LCD_CHIPSEL_L, 0xff, 0);
75 pio->set_context_port_b(keyboard, SIG_KEYBOARD_COLUMN_H, 1, 0);
76 pio->set_context_port_b(lcd, SIG_LCD_CHIPSEL_H, 3, 0);
77 pio->set_context_port_b(pcm, SIG_PCM1BIT_MUTE, 0x20, 0);
78 pio->set_context_timer(pcm, SIG_PCM1BIT_SIGNAL, 1);
79 pio->set_constant_clock(CPU_CLOCKS);
80 rtc->set_context_dout(pio, SIG_I8155_PORT_C, 1);
81 rtc->set_context_tp(cpu, SIG_I8085_RST7, 1);
83 memory->set_context_cmt(cmt);
84 memory->set_context_drec(drec);
85 memory->set_context_rtc(rtc);
88 cpu->set_context_mem(memory);
89 cpu->set_context_io(io);
90 cpu->set_context_intr(io);
92 cpu->set_context_debugger(new DEBUGGER(this, emu));
96 io->set_iomap_range_w(0x90, 0x9f, memory);
97 io->set_iomap_range_rw(0xa0, 0xaf, memory);
98 io->set_iomap_range_rw(0xb0, 0xbf, pio);
99 io->set_iomap_range_r(0xe0, 0xef, keyboard);
100 io->set_iomap_range_rw(0xf0, 0xff, lcd);
102 // initialize all devices
103 #if defined(__GIT_REPO_VERSION)
104 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
106 for(DEVICE* device = first_device; device; device = device->next_device) {
107 device->initialize();
110 rtc->write_signal(SIG_UPD1990A_STB, 0, 0);
115 // delete all devices
116 for(DEVICE* device = first_device; device;) {
117 DEVICE *next_device = device->next_device;
120 device = next_device;
124 DEVICE* VM::get_device(int id)
126 for(DEVICE* device = first_device; device; device = device->next_device) {
127 if(device->this_device_id == id) {
134 // ----------------------------------------------------------------------------
135 // drive virtual machine
136 // ----------------------------------------------------------------------------
141 for(DEVICE* device = first_device; device; device = device->next_device) {
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
156 DEVICE *VM::get_cpu(int index)
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 void VM::draw_screen()
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 void VM::initialize_sound(int rate, int samples)
180 // init sound manager
181 event->initialize_sound(rate, samples);
184 pcm->initialize_sound(rate, 8000);
187 uint16_t* VM::create_sound(int* extra_frames)
189 return event->create_sound(extra_frames);
192 int VM::get_sound_buffer_ptr()
194 return event->get_sound_buffer_ptr();
197 #ifdef USE_SOUND_VOLUME
198 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
201 pcm->set_volume(0, decibel_l, decibel_r);
203 drec->set_volume(0, decibel_l, decibel_r);
205 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
206 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
207 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
212 // ----------------------------------------------------------------------------
214 // ----------------------------------------------------------------------------
216 void VM::key_down(int code, bool repeat)
218 keyboard->key_down(code);
221 void VM::key_up(int code)
225 bool VM::get_caps_locked()
227 return keyboard->get_caps_locked();
230 bool VM::get_kana_locked()
232 return keyboard->get_kana_locked();
235 // ----------------------------------------------------------------------------
237 // ----------------------------------------------------------------------------
239 void VM::play_tape(int drv, const _TCHAR* file_path)
242 drec->play_tape(file_path);
243 // drec->set_remote(true);
246 void VM::rec_tape(int drv, const _TCHAR* file_path)
251 // drec->set_remote(false);
252 cmt->rec_tape(file_path);
255 void VM::close_tape(int drv)
260 // drec->set_remote(false);
264 bool VM::is_tape_inserted(int drv)
266 return drec->is_tape_inserted() || cmt->is_tape_inserted();
269 bool VM::is_tape_playing(int drv)
271 if(drec->is_tape_inserted()) {
272 return drec->is_tape_playing();
274 return cmt->is_tape_playing();
278 bool VM::is_tape_recording(int drv)
280 if(drec->is_tape_inserted()) {
281 return drec->is_tape_recording();
283 return cmt->is_tape_recording();
287 int VM::get_tape_position(int drv)
289 if(drec->is_tape_inserted()) {
290 return drec->get_tape_position();
292 return cmt->get_tape_position();
296 const _TCHAR* VM::get_tape_message(int drv)
298 if(drec->is_tape_inserted()) {
299 return drec->get_message();
305 void VM::push_play(int drv)
307 if(drec->is_tape_inserted()) {
309 drec->set_remote(true);
313 void VM::push_stop(int drv)
315 if(drec->is_tape_inserted()) {
316 drec->set_remote(false);
320 void VM::push_fast_forward(int drv)
322 if(drec->is_tape_inserted()) {
324 drec->set_remote(true);
328 void VM::push_fast_rewind(int drv)
330 if(drec->is_tape_inserted()) {
331 drec->set_ff_rew(-1);
332 drec->set_remote(true);
336 bool VM::is_frame_skippable()
338 return event->is_frame_skippable();
341 void VM::update_config()
343 for(DEVICE* device = first_device; device; device = device->next_device) {
344 device->update_config();
348 #define STATE_VERSION 3
350 #include "../../statesub.h"
351 #include "../../qt/gui/csp_logger.h"
352 extern CSP_Logger DLL_PREFIX_I *csp_logger;
354 void VM::decl_state(void)
357 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_8201_HEAD")), csp_logger);
358 #elif defined(_PC8201A)
359 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_8201A_HEAD")), csp_logger);
361 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_8201_SERIES_HEAD")), csp_logger);
364 for(DEVICE* device = first_device; device; device = device->next_device) {
365 device->decl_state();
369 void VM::save_state(FILEIO* state_fio)
371 //state_fio->FputUint32(STATE_VERSION);
373 if(state_entry != NULL) {
374 state_entry->save_state(state_fio);
376 for(DEVICE* device = first_device; device; device = device->next_device) {
377 device->save_state(state_fio);
381 bool VM::load_state(FILEIO* state_fio)
383 //if(state_fio->FgetUint32() != STATE_VERSION) {
387 if(state_entry != NULL) {
388 mb = state_entry->load_state(state_fio);
391 emu->out_debug_log("INFO: HEADER DATA ERROR");
394 for(DEVICE* device = first_device; device; device = device->next_device) {
395 if(!device->load_state(state_fio)) {