2 CASIO PV-1000 Emulator 'ePV-1000'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
16 #include "../memory.h"
20 #include "../debugger.h"
27 using PV1000::JOYSTICK;
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
38 first_device = last_device = NULL;
39 dummy = new DEVICE(this, emu); // must be 1st device
40 event = new EVENT(this, emu); // must be 2nd device
41 dummy->set_device_name(_T("1st Dummy"));
43 io = new IO(this, emu);
44 memory = new MEMORY(this, emu);
46 cpu = new Z80(this, emu);
48 joystick = new JOYSTICK(this, emu);
49 psg = new PSG(this, emu);
50 vdp = new VDP(this, emu);
53 event->set_context_cpu(cpu);
54 event->set_context_sound(psg);
56 vdp->set_context_cpu(cpu);
57 vdp->set_memory_ptr(mem);
60 cpu->set_context_mem(memory);
61 cpu->set_context_io(io);
62 cpu->set_context_intr(dummy);
64 cpu->set_context_debugger(new DEBUGGER(this, emu));
68 memset(mem, 0xff, 0x8000);
69 memset(mem + 0x8000, 0, 0x8000);
71 memory->set_memory_r(0x0000, 0x7fff, mem);
72 memory->set_memory_rw(0xb800, 0xbfff, mem + 0xb800);
75 io->set_iomap_range_w(0xf8, 0xfa, psg);
76 io->set_iomap_range_rw(0xfc, 0xfd, joystick);
77 io->set_iomap_range_w(0xfe, 0xff, vdp);
79 // initialize all devices
80 #if defined(__GIT_REPO_VERSION)
81 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
83 for(DEVICE* device = first_device; device; device = device->next_device) {
92 for(DEVICE* device = first_device; device;) {
93 DEVICE *next_device = device->next_device;
100 DEVICE* VM::get_device(int id)
102 for(DEVICE* device = first_device; device; device = device->next_device) {
103 if(device->this_device_id == id) {
110 // ----------------------------------------------------------------------------
111 // drive virtual machine
112 // ----------------------------------------------------------------------------
117 for(DEVICE* device = first_device; device; device = device->next_device) {
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
132 DEVICE *VM::get_cpu(int index)
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 void VM::draw_screen()
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 void VM::initialize_sound(int rate, int samples)
156 // init sound manager
157 event->initialize_sound(rate, samples);
160 psg->initialize_sound(rate);
163 uint16_t* VM::create_sound(int* extra_frames)
165 return event->create_sound(extra_frames);
168 int VM::get_sound_buffer_ptr()
170 return event->get_sound_buffer_ptr();
173 #ifdef USE_SOUND_VOLUME
174 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
177 psg->set_volume(0, decibel_l, decibel_r);
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
186 void VM::open_cart(int drv, const _TCHAR* file_path)
189 memset(mem, 0xff, 0x8000);
190 inserted = memory->read_image(file_path, mem, 0x8000);
195 void VM::close_cart(int drv)
198 memset(mem, 0xff, 0x8000);
204 bool VM::is_cart_inserted(int drv)
213 bool VM::is_frame_skippable()
215 return event->is_frame_skippable();
218 void VM::update_config()
220 for(DEVICE* device = first_device; device; device = device->next_device) {
221 device->update_config();
225 double VM::get_current_usec()
227 if(event == NULL) return 0.0;
228 return event->get_current_usec();
231 uint64_t VM::get_current_clock_uint64()
233 if(event == NULL) return (uint64_t)0;
234 return event->get_current_clock_uint64();
237 #define STATE_VERSION 2
239 bool VM::process_state(FILEIO* state_fio, bool loading)
241 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
244 for(DEVICE* device = first_device; device; device = device->next_device) {
245 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
246 // const char *name = typeid(*device).name();
247 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
248 const char *name = device->get_device_name();
249 int len = strlen(name);
251 if(!state_fio->StateCheckInt32(len)) {
253 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
257 if(!state_fio->StateCheckBuffer(name, len, 1)) {
259 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
263 if(!device->process_state(state_fio, loading)) {
265 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
270 // Machine specified.
271 state_fio->StateArray(mem, sizeof(mem), 1);
272 state_fio->StateValue(inserted);