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 PC8201_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();
109 rtc->write_signal(SIG_UPD1990A_STB, 0, 0);
114 // delete all devices
115 for(DEVICE* device = first_device; device;) {
116 DEVICE *next_device = device->next_device;
119 device = next_device;
123 DEVICE* VM::get_device(int id)
125 for(DEVICE* device = first_device; device; device = device->next_device) {
126 if(device->this_device_id == id) {
133 // ----------------------------------------------------------------------------
134 // drive virtual machine
135 // ----------------------------------------------------------------------------
140 for(DEVICE* device = first_device; device; device = device->next_device) {
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
155 DEVICE *VM::get_cpu(int index)
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 void VM::draw_screen()
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 void VM::initialize_sound(int rate, int samples)
179 // init sound manager
180 event->initialize_sound(rate, samples);
183 pcm->initialize_sound(rate, 8000);
186 uint16_t* VM::create_sound(int* extra_frames)
188 return event->create_sound(extra_frames);
191 int VM::get_sound_buffer_ptr()
193 return event->get_sound_buffer_ptr();
196 #ifdef USE_SOUND_VOLUME
197 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
200 pcm->set_volume(0, decibel_l, decibel_r);
202 drec->set_volume(0, decibel_l, decibel_r);
204 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
205 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
206 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 void VM::key_down(int code, bool repeat)
217 keyboard->key_down(code);
220 void VM::key_up(int code)
224 bool VM::get_caps_locked()
226 return keyboard->get_caps_locked();
229 bool VM::get_kana_locked()
231 return keyboard->get_kana_locked();
234 // ----------------------------------------------------------------------------
236 // ----------------------------------------------------------------------------
238 void VM::play_tape(int drv, const _TCHAR* file_path)
241 drec->play_tape(file_path);
242 // drec->set_remote(true);
245 void VM::rec_tape(int drv, const _TCHAR* file_path)
250 // drec->set_remote(false);
251 cmt->rec_tape(file_path);
254 void VM::close_tape(int drv)
259 // drec->set_remote(false);
263 bool VM::is_tape_inserted(int drv)
265 return drec->is_tape_inserted() || cmt->is_tape_inserted();
268 bool VM::is_tape_playing(int drv)
270 if(drec->is_tape_inserted()) {
271 return drec->is_tape_playing();
273 return cmt->is_tape_playing();
277 bool VM::is_tape_recording(int drv)
279 if(drec->is_tape_inserted()) {
280 return drec->is_tape_recording();
282 return cmt->is_tape_recording();
286 int VM::get_tape_position(int drv)
288 if(drec->is_tape_inserted()) {
289 return drec->get_tape_position();
291 return cmt->get_tape_position();
295 const _TCHAR* VM::get_tape_message(int drv)
297 if(drec->is_tape_inserted()) {
298 return drec->get_message();
304 void VM::push_play(int drv)
306 if(drec->is_tape_inserted()) {
308 drec->set_remote(true);
312 void VM::push_stop(int drv)
314 if(drec->is_tape_inserted()) {
315 drec->set_remote(false);
319 void VM::push_fast_forward(int drv)
321 if(drec->is_tape_inserted()) {
323 drec->set_remote(true);
327 void VM::push_fast_rewind(int drv)
329 if(drec->is_tape_inserted()) {
330 drec->set_ff_rew(-1);
331 drec->set_remote(true);
335 bool VM::is_frame_skippable()
337 return event->is_frame_skippable();
340 void VM::update_config()
342 for(DEVICE* device = first_device; device; device = device->next_device) {
343 device->update_config();
347 #define STATE_VERSION 3
349 bool VM::process_state(FILEIO* state_fio, bool loading)
351 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
354 for(DEVICE* device = first_device; device; device = device->next_device) {
355 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
356 // const char *name = typeid(*device).name();
357 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
358 const char *name = device->get_device_name();
359 int len = strlen(name);
361 if(!state_fio->StateCheckInt32(len)) {
363 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
367 if(!state_fio->StateCheckBuffer(name, len, 1)) {
369 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
373 if(!device->process_state(state_fio, loading)) {
375 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
380 // Machine specified.