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"
33 using PC8201::KEYBOARD;
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
44 first_device = last_device = NULL;
45 dummy = new DEVICE(this, emu); // must be 1st device
46 event = new EVENT(this, emu); // must be 2nd device
48 drec = new DATAREC(this, emu);
49 drec->set_context_noise_play(new NOISE(this, emu));
50 drec->set_context_noise_stop(new NOISE(this, emu));
51 drec->set_context_noise_fast(new NOISE(this, emu));
52 cpu = new I8080(this, emu);
53 pio = new I8155(this, emu);
54 io = new IO(this, emu);
55 pcm = new PCM1BIT(this, emu);
56 rtc = new UPD1990A(this, emu);
58 cmt = new CMT(this, emu);
59 keyboard = new KEYBOARD(this, emu);
60 lcd = new LCD(this, emu);
61 memory = new MEMORY(this, emu);
64 event->set_context_cpu(cpu);
65 event->set_context_sound(pcm);
66 event->set_context_sound(drec);
67 event->set_context_sound(drec->get_context_noise_play());
68 event->set_context_sound(drec->get_context_noise_stop());
69 event->set_context_sound(drec->get_context_noise_fast());
71 drec->set_context_ear(cpu, SIG_I8085_SID, 1);
72 cpu->set_context_sod(cmt, SIG_CMT_SOD, 1);
73 pio->set_context_port_a(rtc, SIG_UPD1990A_C0, 1, 0);
74 pio->set_context_port_a(rtc, SIG_UPD1990A_C1, 2, 0);
75 pio->set_context_port_a(rtc, SIG_UPD1990A_C2, 4, 0);
76 pio->set_context_port_a(rtc, SIG_UPD1990A_CLK, 8, 0);
77 pio->set_context_port_a(rtc, SIG_UPD1990A_DIN, 0x10, 0);
78 pio->set_context_port_a(keyboard, SIG_KEYBOARD_COLUMN_L, 0xff, 0);
79 pio->set_context_port_a(lcd, SIG_LCD_CHIPSEL_L, 0xff, 0);
80 pio->set_context_port_b(keyboard, SIG_KEYBOARD_COLUMN_H, 1, 0);
81 pio->set_context_port_b(lcd, SIG_LCD_CHIPSEL_H, 3, 0);
82 pio->set_context_port_b(pcm, SIG_PCM1BIT_MUTE, 0x20, 0);
83 pio->set_context_timer(pcm, SIG_PCM1BIT_SIGNAL, 1);
84 pio->set_constant_clock(CPU_CLOCKS);
85 rtc->set_context_dout(pio, SIG_I8155_PORT_C, 1);
86 rtc->set_context_tp(cpu, SIG_I8085_RST7, 1);
88 memory->set_context_cmt(cmt);
89 memory->set_context_drec(drec);
90 memory->set_context_rtc(rtc);
93 cpu->set_context_mem(memory);
94 cpu->set_context_io(io);
95 cpu->set_context_intr(io);
97 cpu->set_context_debugger(new DEBUGGER(this, emu));
101 io->set_iomap_range_w(0x90, 0x9f, memory);
102 io->set_iomap_range_rw(0xa0, 0xaf, memory);
103 io->set_iomap_range_rw(0xb0, 0xbf, pio);
104 io->set_iomap_range_r(0xe0, 0xef, keyboard);
105 io->set_iomap_range_rw(0xf0, 0xff, lcd);
107 // initialize all devices
108 #if defined(__GIT_REPO_VERSION)
109 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
111 for(DEVICE* device = first_device; device; device = device->next_device) {
112 device->initialize();
114 rtc->write_signal(SIG_UPD1990A_STB, 0, 0);
119 // delete all devices
120 for(DEVICE* device = first_device; device;) {
121 DEVICE *next_device = device->next_device;
124 device = next_device;
128 DEVICE* VM::get_device(int id)
130 for(DEVICE* device = first_device; device; device = device->next_device) {
131 if(device->this_device_id == id) {
138 // ----------------------------------------------------------------------------
139 // drive virtual machine
140 // ----------------------------------------------------------------------------
145 for(DEVICE* device = first_device; device; device = device->next_device) {
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
160 DEVICE *VM::get_cpu(int index)
169 // ----------------------------------------------------------------------------
171 // ----------------------------------------------------------------------------
173 void VM::draw_screen()
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 void VM::initialize_sound(int rate, int samples)
184 // init sound manager
185 event->initialize_sound(rate, samples);
188 pcm->initialize_sound(rate, 8000);
191 uint16_t* VM::create_sound(int* extra_frames)
193 return event->create_sound(extra_frames);
196 int VM::get_sound_buffer_ptr()
198 return event->get_sound_buffer_ptr();
201 #ifdef USE_SOUND_VOLUME
202 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
205 pcm->set_volume(0, decibel_l, decibel_r);
207 drec->set_volume(0, decibel_l, decibel_r);
209 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
210 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
211 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
216 // ----------------------------------------------------------------------------
218 // ----------------------------------------------------------------------------
220 void VM::key_down(int code, bool repeat)
222 keyboard->key_down(code);
225 void VM::key_up(int code)
229 bool VM::get_caps_locked()
231 return keyboard->get_caps_locked();
234 bool VM::get_kana_locked()
236 return keyboard->get_kana_locked();
239 // ----------------------------------------------------------------------------
241 // ----------------------------------------------------------------------------
243 void VM::play_tape(int drv, const _TCHAR* file_path)
246 drec->play_tape(file_path);
247 // drec->set_remote(true);
250 void VM::rec_tape(int drv, const _TCHAR* file_path)
255 // drec->set_remote(false);
256 cmt->rec_tape(file_path);
259 void VM::close_tape(int drv)
264 // drec->set_remote(false);
268 bool VM::is_tape_inserted(int drv)
270 return drec->is_tape_inserted() || cmt->is_tape_inserted();
273 bool VM::is_tape_playing(int drv)
275 if(drec->is_tape_inserted()) {
276 return drec->is_tape_playing();
278 return cmt->is_tape_playing();
282 bool VM::is_tape_recording(int drv)
284 if(drec->is_tape_inserted()) {
285 return drec->is_tape_recording();
287 return cmt->is_tape_recording();
291 int VM::get_tape_position(int drv)
293 if(drec->is_tape_inserted()) {
294 return drec->get_tape_position();
296 return cmt->get_tape_position();
300 const _TCHAR* VM::get_tape_message(int drv)
302 if(drec->is_tape_inserted()) {
303 return drec->get_message();
309 void VM::push_play(int drv)
311 if(drec->is_tape_inserted()) {
313 drec->set_remote(true);
317 void VM::push_stop(int drv)
319 if(drec->is_tape_inserted()) {
320 drec->set_remote(false);
324 void VM::push_fast_forward(int drv)
326 if(drec->is_tape_inserted()) {
328 drec->set_remote(true);
332 void VM::push_fast_rewind(int drv)
334 if(drec->is_tape_inserted()) {
335 drec->set_ff_rew(-1);
336 drec->set_remote(true);
340 bool VM::is_frame_skippable()
342 return event->is_frame_skippable();
345 void VM::update_config()
347 for(DEVICE* device = first_device; device; device = device->next_device) {
348 device->update_config();
352 #define STATE_VERSION 3
354 bool VM::process_state(FILEIO* state_fio, bool loading)
356 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
359 for(DEVICE* device = first_device; device; device = device->next_device) {
360 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
361 // const char *name = typeid(*device).name();
362 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
363 const char *name = device->get_device_name();
364 int len = strlen(name);
366 if(!state_fio->StateCheckInt32(len)) {
368 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
372 if(!state_fio->StateCheckBuffer(name, len, 1)) {
374 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
378 if(!device->process_state(state_fio, loading)) {
380 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
385 // Machine specified.