2 NEC PC-8201 Emulator 'ePC-8201'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
19 #include "../pcm1bit.h"
20 #include "../upd1990a.h"
23 #include "../debugger.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 VM::VM(EMU* parent_emu) : emu(parent_emu)
38 first_device = last_device = NULL;
39 dummy = new DEVICE(this, emu); // must be 1st device
40 event = new EVENT(this, emu); // must be 2nd device
42 drec = new DATAREC(this, emu);
43 cpu = new I8080(this, emu);
44 pio = new I8155(this, emu);
45 io = new IO(this, emu);
46 pcm = new PCM1BIT(this, emu);
47 rtc = new UPD1990A(this, emu);
49 cmt = new CMT(this, emu);
50 keyboard = new KEYBOARD(this, emu);
51 lcd = new LCD(this, emu);
52 memory = new MEMORY(this, emu);
55 event->set_context_cpu(cpu);
56 event->set_context_sound(pcm);
58 drec->set_context_out(cpu, SIG_I8085_SID, 1);
59 cpu->set_context_sod(cmt, SIG_CMT_SOD, 1);
60 pio->set_context_port_a(rtc, SIG_UPD1990A_C0, 1, 0);
61 pio->set_context_port_a(rtc, SIG_UPD1990A_C1, 2, 0);
62 pio->set_context_port_a(rtc, SIG_UPD1990A_C2, 4, 0);
63 pio->set_context_port_a(rtc, SIG_UPD1990A_CLK, 8, 0);
64 pio->set_context_port_a(rtc, SIG_UPD1990A_DIN, 0x10, 0);
65 pio->set_context_port_a(keyboard, SIG_KEYBOARD_COLUMN_L, 0xff, 0);
66 pio->set_context_port_a(lcd, SIG_LCD_CHIPSEL_L, 0xff, 0);
67 pio->set_context_port_b(keyboard, SIG_KEYBOARD_COLUMN_H, 1, 0);
68 pio->set_context_port_b(lcd, SIG_LCD_CHIPSEL_H, 3, 0);
69 pio->set_context_port_b(pcm, SIG_PCM1BIT_MUTE, 0x20, 0);
70 pio->set_context_timer(pcm, SIG_PCM1BIT_SIGNAL, 1);
71 pio->set_constant_clock(CPU_CLOCKS);
72 rtc->set_context_dout(pio, SIG_I8155_PORT_C, 1);
73 rtc->set_context_tp(cpu, SIG_I8085_RST7, 1);
75 memory->set_context_cmt(cmt);
76 memory->set_context_drec(drec);
77 memory->set_context_rtc(rtc);
80 cpu->set_context_mem(memory);
81 cpu->set_context_io(io);
82 cpu->set_context_intr(io);
84 cpu->set_context_debugger(new DEBUGGER(this, emu));
88 io->set_iomap_range_w(0x90, 0x9f, memory);
89 io->set_iomap_range_rw(0xa0, 0xaf, memory);
90 io->set_iomap_range_rw(0xb0, 0xbf, pio);
91 io->set_iomap_range_r(0xe0, 0xef, keyboard);
92 io->set_iomap_range_rw(0xf0, 0xff, lcd);
94 // initialize all devices
95 for(DEVICE* device = first_device; device; device = device->next_device) {
98 rtc->write_signal(SIG_UPD1990A_STB, 0, 0);
103 // delete all devices
104 for(DEVICE* device = first_device; device;) {
105 DEVICE *next_device = device->next_device;
108 device = next_device;
112 DEVICE* VM::get_device(int id)
114 for(DEVICE* device = first_device; device; device = device->next_device) {
115 if(device->this_device_id == id) {
122 // ----------------------------------------------------------------------------
123 // drive virtual machine
124 // ----------------------------------------------------------------------------
129 for(DEVICE* device = first_device; device; device = device->next_device) {
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
144 DEVICE *VM::get_cpu(int index)
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 void VM::draw_screen()
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
166 void VM::initialize_sound(int rate, int samples)
168 // init sound manager
169 event->initialize_sound(rate, samples);
172 pcm->init(rate, 8000);
175 uint16* VM::create_sound(int* extra_frames)
177 return event->create_sound(extra_frames);
180 int VM::sound_buffer_ptr()
182 return event->sound_buffer_ptr();
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 void VM::key_down(int code, bool repeat)
191 keyboard->key_down(code);
194 void VM::key_up(int code)
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 void VM::play_tape(_TCHAR* file_path)
205 drec->play_tape(file_path);
208 void VM::rec_tape(_TCHAR* file_path)
211 cmt->rec_tape(file_path);
214 void VM::close_tape()
220 bool VM::tape_inserted()
222 return drec->tape_inserted() || cmt->tape_inserted();
227 return event->now_skip();
230 void VM::update_config()
232 for(DEVICE* device = first_device; device; device = device->next_device) {
233 device->update_config();