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* 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);
46 rtc = new RP5C01(this, emu);
48 io = new IO(this, emu);
50 event->set_context_cpu(cpu);
51 event->set_context_sound(drec);
52 event->set_context_sound(drec->get_context_noise_play());
53 event->set_context_sound(drec->get_context_noise_stop());
54 event->set_context_sound(drec->get_context_noise_fast());
56 drec->set_context_ear(io, SIG_IO_CMT, 1);
57 cpu->set_context_sod(io, SIG_IO_SOD, 1);
59 io->set_context_cpu(cpu);
60 io->set_context_drec(drec);
61 io->set_context_rtc(rtc);
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));
73 memset(ram, 0, sizeof(ram));
75 memory->read_bios(_T("BIOS.ROM"), rom, sizeof(rom));
77 FILEIO* fio = new FILEIO();
78 if(fio->Fopen(create_local_path(_T("RAM.BIN")), FILEIO_READ_BINARY)) {
79 fio->Fread(ram, sizeof(ram), 1);
84 memory->set_memory_r(0x0000, 0x7fff, rom);
85 memory->set_memory_rw(0x8000, 0xffff, ram);
86 memory->set_wait_rw(0x0000, 0xffff, 1);
88 // initialize all devices
89 #if defined(__GIT_REPO_VERSION)
90 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
92 for(DEVICE* device = first_device; device; device = device->next_device) {
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 DEVICE* VM::get_device(int id)
117 for(DEVICE* device = first_device; device; device = device->next_device) {
118 if(device->this_device_id == id) {
125 // ----------------------------------------------------------------------------
126 // drive virtual machine
127 // ----------------------------------------------------------------------------
132 for(DEVICE* device = first_device; device; device = device->next_device) {
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
147 DEVICE *VM::get_cpu(int index)
156 // ----------------------------------------------------------------------------
158 // ----------------------------------------------------------------------------
160 void VM::draw_screen()
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 void VM::initialize_sound(int rate, int samples)
171 // init sound manager
172 event->initialize_sound(rate, samples);
175 uint16_t* VM::create_sound(int* extra_frames)
177 return event->create_sound(extra_frames);
180 int VM::get_sound_buffer_ptr()
182 return event->get_sound_buffer_ptr();
185 #ifdef USE_SOUND_VOLUME
186 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
189 drec->set_volume(0, decibel_l, decibel_r);
191 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
192 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
193 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 void VM::key_down(int code, bool repeat)
209 void VM::key_up(int code)
214 // ----------------------------------------------------------------------------
216 // ----------------------------------------------------------------------------
218 void VM::play_tape(int drv, const _TCHAR* file_path)
221 drec->play_tape(file_path);
222 // drec->set_remote(true);
225 void VM::rec_tape(int drv, const _TCHAR* file_path)
230 // drec->set_remote(false);
231 io->rec_tape(file_path);
234 void VM::close_tape(int drv)
239 // drec->set_remote(false);
243 bool VM::is_tape_inserted(int drv)
245 return drec->is_tape_inserted() || io->is_tape_inserted();
248 bool VM::is_tape_playing(int drv)
250 if(drec->is_tape_inserted()) {
251 return drec->is_tape_playing();
253 return io->is_tape_playing();
257 bool VM::is_tape_recording(int drv)
259 if(drec->is_tape_inserted()) {
260 return drec->is_tape_recording();
262 return io->is_tape_recording();
266 int VM::get_tape_position(int drv)
268 if(drec->is_tape_inserted()) {
269 return drec->get_tape_position();
271 return io->get_tape_position();
275 const _TCHAR* VM::get_tape_message(int drv)
277 if(drec->is_tape_inserted()) {
278 return drec->get_message();
284 void VM::push_play(int drv)
286 if(drec->is_tape_inserted()) {
288 drec->set_remote(true);
292 void VM::push_stop(int drv)
294 if(drec->is_tape_inserted()) {
295 drec->set_remote(false);
299 void VM::push_fast_forward(int drv)
301 if(drec->is_tape_inserted()) {
303 drec->set_remote(true);
307 void VM::push_fast_rewind(int drv)
309 if(drec->is_tape_inserted()) {
310 drec->set_ff_rew(-1);
311 drec->set_remote(true);
315 bool VM::is_frame_skippable()
317 return event->is_frame_skippable();
320 void VM::update_config()
322 for(DEVICE* device = first_device; device; device = device->next_device) {
323 device->update_config();
327 #define STATE_VERSION 3
329 bool VM::process_state(FILEIO* state_fio, bool loading)
331 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
334 for(DEVICE* device = first_device; device; device = device->next_device) {
335 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
336 // const char *name = typeid(*device).name();
337 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
338 const char *name = device->get_device_name();
339 int len = strlen(name);
341 if(!state_fio->StateCheckInt32(len)) {
343 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
347 if(!state_fio->StateCheckBuffer(name, len, 1)) {
349 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
353 if(!device->process_state(state_fio, loading)) {
355 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
360 state_fio->StateArray(ram, sizeof(ram), 1);