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"
22 #include "../debugger.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
33 config.sound_play_tape = false;
34 config.wave_shaper[0] = false;
37 first_device = last_device = NULL;
38 dummy = new DEVICE(this, emu); // must be 1st device
39 event = new EVENT(this, emu); // must be 2nd device
40 dummy->set_device_name(_T("1st Dummy"));
42 drec = new DATAREC(this, emu);
43 drec->set_context_noise_play(new NOISE(this, emu));
44 drec->set_context_noise_stop(new NOISE(this, emu));
45 drec->set_context_noise_fast(new NOISE(this, emu));
46 cpu = new I8080(this, emu); // 8085
47 pio = new I8155(this, emu); // 8156
48 memory = new MEMORY(this, emu);
50 io = new IO(this, emu);
53 event->set_context_cpu(cpu);
54 event->set_context_sound(drec);
55 event->set_context_sound(drec->get_context_noise_play());
56 event->set_context_sound(drec->get_context_noise_stop());
57 event->set_context_sound(drec->get_context_noise_fast());
59 drec->set_context_ear(io, SIG_IO_DREC_EAR, 1);
60 cpu->set_context_sod(drec, SIG_DATAREC_MIC, 1);
61 pio->set_context_port_b(io, SIG_IO_PORT_B, 0xff, 0);
62 pio->set_context_port_c(io, SIG_IO_PORT_C, 0xff, 0);
63 pio->set_context_timer(cpu, SIG_I8085_RST7, 1);
64 pio->set_constant_clock(CPU_CLOCKS); // from 8085 CLOCK OUT
66 io->set_context_drec(drec);
67 io->set_context_cpu(cpu);
68 io->set_context_pio(pio);
69 io->set_vram_ptr(vram);
72 cpu->set_context_mem(memory);
73 cpu->set_context_io(io);
74 cpu->set_context_intr(io);
76 cpu->set_context_debugger(new DEBUGGER(this, emu));
80 memset(rom, 0xff, sizeof(rom));
82 memory->read_bios(_T("BIOS.ROM"), rom, sizeof(rom));
84 memory->set_memory_r(0x0000, 0x1fff, rom);
85 memory->set_memory_rw(0x4000, 0x43ff, vram);
86 memory->set_memory_rw(0x6000, 0x60ff, ram); // 8156
88 // initialize all devices
89 for(DEVICE* device = first_device; device; device = device->next_device) {
98 for(DEVICE* device = first_device; device;) {
99 DEVICE *next_device = device->next_device;
102 device = next_device;
106 DEVICE* VM::get_device(int id)
108 for(DEVICE* device = first_device; device; device = device->next_device) {
109 if(device->this_device_id == id) {
116 // ----------------------------------------------------------------------------
117 // drive virtual machine
118 // ----------------------------------------------------------------------------
123 for(DEVICE* device = first_device; device; device = device->next_device) {
126 pio->write_signal(SIG_I8155_PORT_A, 0xff, 0x80); // PA7=1
127 memset(ram, 0, sizeof(ram));
128 memset(vram, 0, sizeof(vram));
131 void VM::special_reset()
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
146 DEVICE *VM::get_cpu(int index)
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 void VM::draw_screen()
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 void VM::initialize_sound(int rate, int samples)
170 // init sound manager
171 event->initialize_sound(rate, samples);
174 uint16_t* VM::create_sound(int* extra_frames)
176 return event->create_sound(extra_frames);
179 int VM::get_sound_buffer_ptr()
181 return event->get_sound_buffer_ptr();
184 #ifdef USE_SOUND_VOLUME
185 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
188 drec->set_volume(0, decibel_l, decibel_r);
190 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
191 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
192 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 void VM::play_tape(int drv, const _TCHAR* file_path)
203 if(drec->play_tape(file_path)) {
204 drec->set_remote(true);
209 void VM::rec_tape(int drv, const _TCHAR* file_path)
211 if(drec->rec_tape(file_path)) {
212 drec->set_remote(true);
217 void VM::close_tape(int drv)
222 drec->set_remote(false);
225 bool VM::is_tape_inserted(int drv)
227 return drec->is_tape_inserted();
230 bool VM::is_tape_playing(int drv)
232 return drec->is_tape_playing();
235 bool VM::is_tape_recording(int drv)
237 return drec->is_tape_recording();
240 int VM::get_tape_position(int drv)
242 return drec->get_tape_position();
245 const _TCHAR* VM::get_tape_message(int drv)
247 return drec->get_message();
250 void VM::push_play(int drv)
253 drec->set_remote(true);
256 void VM::push_stop(int drv)
258 drec->set_remote(false);
261 void VM::push_fast_forward(int drv)
264 drec->set_remote(true);
267 void VM::push_fast_rewind(int drv)
269 drec->set_ff_rew(-1);
270 drec->set_remote(true);
273 bool VM::is_frame_skippable()
275 return event->is_frame_skippable();
278 void VM::update_config()
280 for(DEVICE* device = first_device; device; device = device->next_device) {
281 device->update_config();
285 #define STATE_VERSION 4
287 #include "../../statesub.h"
288 #include "../../qt/gui/csp_logger.h"
289 extern CSP_Logger DLL_PREFIX_I *csp_logger;
291 void VM::decl_state(void)
294 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::YALKY_HEAD")), csp_logger);
295 DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
296 DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
297 for(DEVICE* device = first_device; device; device = device->next_device) {
298 device->decl_state();
302 void VM::save_state(FILEIO* state_fio)
304 //state_fio->FputUint32(STATE_VERSION);
306 if(state_entry != NULL) {
307 state_entry->save_state(state_fio);
309 for(DEVICE* device = first_device; device; device = device->next_device) {
310 device->save_state(state_fio);
312 //state_fio->Fwrite(ram, sizeof(ram), 1);
313 //state_fio->Fwrite(vram, sizeof(vram), 1);
316 bool VM::load_state(FILEIO* state_fio)
318 //if(state_fio->FgetUint32() != STATE_VERSION) {
322 if(state_entry != NULL) {
323 mb = state_entry->load_state(state_fio);
326 emu->out_debug_log("INFO: HEADER DATA ERROR");
329 for(DEVICE* device = first_device; device; device = device->next_device) {
330 if(!device->load_state(state_fio)) {
334 //state_fio->Fread(ram, sizeof(ram), 1);
335 //state_fio->Fread(vram, sizeof(vram), 1);