2 CASIO FP-200 Emulator 'eFP-200'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
17 #include "../memory.h"
19 #include "../rp5c01.h"
22 #include "../debugger.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
32 VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
35 first_device = last_device = NULL;
36 dummy = new DEVICE(this, emu); // must be 1st device
37 event = new EVENT(this, emu); // must be 2nd device
38 dummy->set_device_name(_T("1st Dummy"));
40 drec = new DATAREC(this, emu);
41 drec->set_context_noise_play(new NOISE(this, emu));
42 drec->set_context_noise_stop(new NOISE(this, emu));
43 drec->set_context_noise_fast(new NOISE(this, emu));
44 cpu = new I8080(this, emu); // i8085
45 memory = new MEMORY(this, emu);
47 rtc = new RP5C01(this, emu);
49 io = new IO(this, emu);
51 event->set_context_cpu(cpu);
52 event->set_context_sound(drec);
53 event->set_context_sound(drec->get_context_noise_play());
54 event->set_context_sound(drec->get_context_noise_stop());
55 event->set_context_sound(drec->get_context_noise_fast());
57 drec->set_context_ear(io, SIG_IO_CMT, 1);
58 cpu->set_context_sod(io, SIG_IO_SOD, 1);
60 io->set_context_cpu(cpu);
61 io->set_context_drec(drec);
62 io->set_context_rtc(rtc);
65 cpu->set_context_mem(memory);
66 cpu->set_context_io(io);
67 cpu->set_context_intr(io);
69 cpu->set_context_debugger(new DEBUGGER(this, emu));
73 memset(rom, 0xff, sizeof(rom));
74 memset(ram, 0, sizeof(ram));
76 memory->read_bios(_T("BIOS.ROM"), rom, sizeof(rom));
78 FILEIO* fio = new FILEIO();
79 if(fio->Fopen(create_local_path(_T("RAM.BIN")), FILEIO_READ_BINARY)) {
80 fio->Fread(ram, sizeof(ram), 1);
85 memory->set_memory_r(0x0000, 0x7fff, rom);
86 memory->set_memory_rw(0x8000, 0xffff, ram);
87 memory->set_wait_rw(0x0000, 0xffff, 1);
89 // initialize all devices
90 #if defined(__GIT_REPO_VERSION)
91 set_git_repo_version(__GIT_REPO_VERSION);
99 FILEIO* fio = new FILEIO();
100 if(fio->Fopen(create_local_path(_T("RAM.BIN")), FILEIO_WRITE_BINARY)) {
101 fio->Fwrite(ram, sizeof(ram), 1);
106 // delete all devices
107 for(DEVICE* device = first_device; device;) {
108 DEVICE *next_device = device->next_device;
111 device = next_device;
115 // ----------------------------------------------------------------------------
116 // drive virtual machine
117 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 // ----------------------------------------------------------------------------
128 DEVICE *VM::get_cpu(int index)
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
141 void VM::draw_screen()
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
150 void VM::initialize_sound(int rate, int samples)
152 // init sound manager
153 event->initialize_sound(rate, samples);
156 uint16_t* VM::create_sound(int* extra_frames)
158 return event->create_sound(extra_frames);
161 int VM::get_sound_buffer_ptr()
163 return event->get_sound_buffer_ptr();
166 #ifdef USE_SOUND_VOLUME
167 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
170 drec->set_volume(0, decibel_l, decibel_r);
172 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
173 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
174 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
179 // ----------------------------------------------------------------------------
181 // ----------------------------------------------------------------------------
183 void VM::key_down(int code, bool repeat)
190 void VM::key_up(int code)
195 // ----------------------------------------------------------------------------
197 // ----------------------------------------------------------------------------
199 void VM::play_tape(int drv, const _TCHAR* file_path)
203 bool remote = drec->get_remote();
205 if(drec->play_tape(file_path) && remote) {
206 // if machine already sets remote on, start playing now
211 void VM::rec_tape(int drv, const _TCHAR* file_path)
216 drec->set_remote(false);
217 io->rec_tape(file_path);
220 void VM::close_tape(int drv)
225 drec->set_remote(false);
230 bool VM::is_tape_inserted(int drv)
232 return drec->is_tape_inserted() || io->is_tape_inserted();
235 bool VM::is_tape_playing(int drv)
237 if(drec->is_tape_inserted()) {
238 return drec->is_tape_playing();
240 return io->is_tape_playing();
244 bool VM::is_tape_recording(int drv)
246 if(drec->is_tape_inserted()) {
247 return drec->is_tape_recording();
249 return io->is_tape_recording();
253 int VM::get_tape_position(int drv)
255 if(drec->is_tape_inserted()) {
256 return drec->get_tape_position();
258 return io->get_tape_position();
262 const _TCHAR* VM::get_tape_message(int drv)
264 if(drec->is_tape_inserted()) {
265 return drec->get_message();
271 void VM::push_play(int drv)
273 if(drec->is_tape_inserted()) {
274 drec->set_remote(false);
276 drec->set_remote(true);
280 void VM::push_stop(int drv)
282 if(drec->is_tape_inserted()) {
283 drec->set_remote(false);
287 void VM::push_fast_forward(int drv)
289 if(drec->is_tape_inserted()) {
290 drec->set_remote(false);
292 drec->set_remote(true);
296 void VM::push_fast_rewind(int drv)
298 if(drec->is_tape_inserted()) {
299 drec->set_remote(false);
300 drec->set_ff_rew(-1);
301 drec->set_remote(true);
305 bool VM::is_frame_skippable()
307 return event->is_frame_skippable();
311 double VM::get_current_usec()
313 __UNLIKELY_IF(event == NULL) return 0.0;
314 return event->get_current_usec();
317 uint64_t VM::get_current_clock_uint64()
319 __UNLIKELY_IF(event == NULL) return (uint64_t)0;
320 return event->get_current_clock_uint64();
323 #define STATE_VERSION 3
325 bool VM::process_state(FILEIO* state_fio, bool loading)
327 if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) {
330 state_fio->StateArray(ram, sizeof(ram), 1);