2 Yuasa Kyouiku System YALKY Emulator 'eYALKY'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
18 #include "../memory.h"
21 #include "../debugger.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 VM::VM(EMU* parent_emu) : emu(parent_emu)
32 config.tape_sound = false;
33 config.wave_shaper = false;
36 first_device = last_device = NULL;
37 dummy = new DEVICE(this, emu); // must be 1st device
38 event = new EVENT(this, emu); // must be 2nd device
40 drec = new DATAREC(this, emu);
41 cpu = new I8080(this, emu); // 8085
42 pio = new I8155(this, emu); // 8156
43 memory = new MEMORY(this, emu);
45 io = new IO(this, emu);
48 event->set_context_cpu(cpu);
49 event->set_context_sound(drec);
51 drec->set_context_ear(io, SIG_IO_DREC_EAR, 1);
52 cpu->set_context_sod(drec, SIG_DATAREC_MIC, 1);
53 pio->set_context_port_b(io, SIG_IO_PORT_B, 0xff, 0);
54 pio->set_context_port_c(io, SIG_IO_PORT_C, 0xff, 0);
55 pio->set_context_timer(cpu, SIG_I8085_RST7, 1);
56 pio->set_constant_clock(CPU_CLOCKS); // from 8085 CLOCK OUT
58 io->set_context_drec(drec);
59 io->set_context_cpu(cpu);
60 io->set_context_pio(pio);
61 io->set_vram_ptr(vram);
64 cpu->set_context_mem(memory);
65 cpu->set_context_io(io);
66 cpu->set_context_intr(io);
68 cpu->set_context_debugger(new DEBUGGER(this, emu));
72 memset(rom, 0xff, sizeof(rom));
74 memory->read_bios(_T("BIOS.ROM"), rom, sizeof(rom));
76 memory->set_memory_r(0x0000, 0x1fff, rom);
77 memory->set_memory_rw(0x4000, 0x43ff, vram);
78 memory->set_memory_rw(0x6000, 0x60ff, ram); // 8156
80 // initialize all devices
81 for(DEVICE* device = first_device; device; device = device->next_device) {
89 for(DEVICE* device = first_device; device;) {
90 DEVICE *next_device = device->next_device;
97 DEVICE* VM::get_device(int id)
99 for(DEVICE* device = first_device; device; device = device->next_device) {
100 if(device->this_device_id == id) {
107 // ----------------------------------------------------------------------------
108 // drive virtual machine
109 // ----------------------------------------------------------------------------
114 for(DEVICE* device = first_device; device; device = device->next_device) {
117 pio->write_signal(SIG_I8155_PORT_A, 0xff, 0x80); // PA7=1
118 memset(ram, 0, sizeof(ram));
119 memset(vram, 0, sizeof(vram));
122 void VM::special_reset()
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
137 DEVICE *VM::get_cpu(int index)
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
150 void VM::draw_screen()
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 void VM::initialize_sound(int rate, int samples)
161 // init sound manager
162 event->initialize_sound(rate, samples);
165 uint16_t* VM::create_sound(int* extra_frames)
167 return event->create_sound(extra_frames);
170 int VM::get_sound_buffer_ptr()
172 return event->get_sound_buffer_ptr();
175 #ifdef USE_SOUND_VOLUME
176 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
178 drec->set_volume(0, decibel_l, decibel_r);
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
186 void VM::play_tape(const _TCHAR* file_path)
188 if(drec->play_tape(file_path)) {
189 drec->set_remote(true);
194 void VM::rec_tape(const _TCHAR* file_path)
196 if(drec->rec_tape(file_path)) {
197 drec->set_remote(true);
202 void VM::close_tape()
205 drec->set_remote(false);
208 bool VM::is_tape_inserted()
210 return drec->is_tape_inserted();
213 bool VM::is_tape_playing()
215 return drec->is_tape_playing();
218 bool VM::is_tape_recording()
220 return drec->is_tape_recording();
223 int VM::get_tape_position()
225 return drec->get_tape_position();
231 drec->set_remote(true);
236 drec->set_remote(false);
239 void VM::push_fast_forward()
242 drec->set_remote(true);
245 void VM::push_fast_rewind()
247 drec->set_ff_rew(-1);
248 drec->set_remote(true);
251 bool VM::is_frame_skippable()
253 return event->is_frame_skippable();
256 void VM::update_config()
258 for(DEVICE* device = first_device; device; device = device->next_device) {
259 device->update_config();
263 #define STATE_VERSION 2
265 void VM::save_state(FILEIO* state_fio)
267 state_fio->FputUint32(STATE_VERSION);
269 for(DEVICE* device = first_device; device; device = device->next_device) {
270 device->save_state(state_fio);
272 state_fio->Fwrite(ram, sizeof(ram), 1);
273 state_fio->Fwrite(vram, sizeof(vram), 1);
276 bool VM::load_state(FILEIO* state_fio)
278 if(state_fio->FgetUint32() != STATE_VERSION) {
281 for(DEVICE* device = first_device; device; device = device->next_device) {
282 if(!device->load_state(state_fio)) {
286 state_fio->Fread(ram, sizeof(ram), 1);
287 state_fio->Fread(vram, sizeof(vram), 1);