2 Computer Research CRC-80 Emulator 'eCRC-80'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
17 #include "../memory.h"
21 #include "../z80pio.h"
24 #include "../debugger.h"
27 #include "./display.h"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
40 first_device = last_device = NULL;
41 dummy = new DEVICE(this, emu); // must be 1st device
42 event = new EVENT(this, emu); // must be 2nd device
44 drec = new DATAREC(this, emu);
45 drec->set_context_noise_play(new NOISE(this, emu));
46 drec->set_context_noise_stop(new NOISE(this, emu));
47 drec->set_context_noise_fast(new NOISE(this, emu));
48 io = new IO(this, emu);
49 m_not = new NOT(this, emu);
50 cpu = new Z80(this, emu);
51 pio = new Z80PIO(this, emu);
53 display = new DISPLAY(this, emu);
54 memory = new MEMBUS(this, emu);
57 event->set_context_cpu(cpu);
58 event->set_context_sound(drec);
59 event->set_context_sound(drec->get_context_noise_play());
60 event->set_context_sound(drec->get_context_noise_stop());
61 event->set_context_sound(drec->get_context_noise_fast());
63 drec->set_context_ear(m_not, SIG_NOT_INPUT, 1);
64 m_not->set_context_out(pio, SIG_Z80PIO_PORT_B, 0x80);
65 pio->set_context_port_b(drec, SIG_DATAREC_MIC, 0x40, 0);
66 pio->set_context_port_a(display, SIG_DISPLAY_PA, 0xff, 0);
67 pio->set_context_port_b(display, SIG_DISPLAY_PB, 0x0f, 0);
69 display->set_context_pio(pio);
70 memory->set_context_cpu(cpu);
73 cpu->set_context_mem(memory);
74 cpu->set_context_io(io);
75 cpu->set_context_intr(pio);
77 cpu->set_context_debugger(new DEBUGGER(this, emu));
81 memset(mon, 0xff, sizeof(mon));
82 memset(tty, 0xff, sizeof(tty));
83 memset(ext, 0xff, sizeof(ext));
84 memset(ram, 0x00, sizeof(ram));
86 memory->read_bios(_T("MON.ROM"), mon, sizeof(mon));
87 memory->read_bios(_T("TTY.ROM"), tty, sizeof(tty));
88 memory->read_bios(_T("EXT.ROM"), ext, sizeof(ext));
90 for(int i = 0; i < 0x8000; i += 0x1000) {
91 memory->set_memory_r (i + 0x0000, i + 0x03ff, mon);
92 memory->set_memory_r (i + 0x0400, i + 0x07ff, tty);
93 memory->set_memory_r (i + 0x0800, i + 0x0bff, ext);
94 memory->set_memory_rw(i + 0x8000, i + 0x8fff, ram);
98 for(int i = 0; i < 0x100; i += 4) {
99 io->set_iomap_alias_rw(i + 0, pio, 0);
100 io->set_iomap_alias_rw(i + 1, pio, 2);
101 io->set_iomap_alias_rw(i + 2, pio, 1);
102 io->set_iomap_alias_rw(i + 3, pio, 3);
105 // initialize all devices
106 for(DEVICE* device = first_device; device; device = device->next_device) {
107 device->initialize();
109 pio->write_signal(SIG_Z80PIO_PORT_B, (config.dipswitch & 2) ? 0 : 0xff, 0x10);
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) {
143 pio->write_signal(SIG_Z80PIO_PORT_A, 0xff, 0xff);
144 pio->write_signal(SIG_Z80PIO_PORT_B, (config.dipswitch & 2) ? 0 : 0xff, 0x10);
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
157 DEVICE *VM::get_cpu(int index)
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 void VM::draw_screen()
172 display->draw_screen();
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
179 void VM::initialize_sound(int rate, int samples)
181 // init sound manager
182 event->initialize_sound(rate, samples);
185 uint16_t* VM::create_sound(int* extra_frames)
187 return event->create_sound(extra_frames);
190 int VM::get_sound_buffer_ptr()
192 return event->get_sound_buffer_ptr();
195 #ifdef USE_SOUND_VOLUME
196 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
199 drec->set_volume(0, decibel_l, decibel_r);
201 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
202 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
203 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 void VM::key_down(int code, bool repeat)
216 void VM::key_up(int code)
220 bool VM::get_caps_locked()
225 bool VM::get_kana_locked()
230 // ----------------------------------------------------------------------------
232 // ----------------------------------------------------------------------------
234 void VM::load_binary(int drv, const _TCHAR* file_path)
236 memory->read_image(file_path, ram, sizeof(ram));
239 void VM::save_binary(int drv, const _TCHAR* file_path)
241 memory->write_image(file_path, ram, sizeof(ram));
244 void VM::play_tape(int drv, const _TCHAR* file_path)
246 if(drec->play_tape(file_path)) {
251 void VM::rec_tape(int drv, const _TCHAR* file_path)
253 if(drec->rec_tape(file_path)) {
258 void VM::close_tape(int drv)
266 bool VM::is_tape_inserted(int drv)
268 return drec->is_tape_inserted();
271 bool VM::is_tape_playing(int drv)
273 return drec->is_tape_playing();
276 bool VM::is_tape_recording(int drv)
278 return drec->is_tape_recording();
281 int VM::get_tape_position(int drv)
283 return drec->get_tape_position();
286 const _TCHAR* VM::get_tape_message(int drv)
288 return drec->get_message();
291 void VM::push_play(int drv)
293 drec->set_remote(false);
295 drec->set_remote(true);
298 void VM::push_stop(int drv)
300 drec->set_remote(false);
303 void VM::push_fast_forward(int drv)
305 drec->set_remote(false);
307 drec->set_remote(true);
310 void VM::push_fast_rewind(int drv)
312 drec->set_remote(false);
313 drec->set_ff_rew(-1);
314 drec->set_remote(true);
317 bool VM::is_frame_skippable()
319 return event->is_frame_skippable();
322 void VM::update_config()
324 for(DEVICE* device = first_device; device; device = device->next_device) {
325 device->update_config();
329 #define STATE_VERSION 1
331 bool VM::process_state(FILEIO* state_fio, bool loading)
333 if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) {
336 // Machine specified.
337 state_fio->StateArray(ram, sizeof(ram), 1);