2 EPOCH Super Cassette Vision Emulator 'eSCV'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../upd7801.h"
18 #include "../debugger.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
33 first_device = last_device = NULL;
34 dummy = new DEVICE(this, emu); // must be 1st device
35 event = new EVENT(this, emu); // must be 2nd device
36 dummy->set_device_name(_T("1st Dummy"));
37 cpu = new UPD7801(this, emu);
39 io = new IO(this, emu);
40 memory = new MEMORY(this, emu);
41 sound = new SOUND(this, emu);
42 vdp = new VDP(this, emu);
45 event->set_context_cpu(cpu);
46 event->set_context_sound(sound);
48 io->set_context_mem(memory);
49 io->set_context_sound(sound);
50 memory->set_context_sound(sound);
51 sound->set_context_cpu(cpu);
52 vdp->set_context_cpu(cpu);
53 vdp->set_font_ptr(memory->get_font());
54 vdp->set_vram_ptr(memory->get_vram());
57 cpu->set_context_mem(memory);
58 cpu->set_context_io(io);
60 cpu->set_context_debugger(new DEBUGGER(this, emu));
63 // initialize all devices
64 #if defined(__GIT_REPO_VERSION)
65 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
67 for(DEVICE* device = first_device; device; device = device->next_device) {
76 for(DEVICE* device = first_device; device;) {
77 DEVICE *next_device = device->next_device;
84 DEVICE* VM::get_device(int id)
86 for(DEVICE* device = first_device; device; device = device->next_device) {
87 if(device->this_device_id == id) {
94 // ----------------------------------------------------------------------------
95 // drive virtual machine
96 // ----------------------------------------------------------------------------
101 for(DEVICE* device = first_device; device; device = device->next_device) {
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
116 DEVICE *VM::get_cpu(int index)
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
129 void VM::draw_screen()
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 void VM::initialize_sound(int rate, int samples)
140 // init sound manager
141 event->initialize_sound(rate, samples);
144 sound->initialize_sound(rate);
147 uint16_t* VM::create_sound(int* extra_frames)
149 return event->create_sound(extra_frames);
152 int VM::get_sound_buffer_ptr()
154 return event->get_sound_buffer_ptr();
157 #ifdef USE_SOUND_VOLUME
158 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
160 sound->set_volume(ch, decibel_l, decibel_r);
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 void VM::open_cart(int drv, const _TCHAR* file_path)
171 memory->open_cart(file_path);
176 void VM::close_cart(int drv)
179 memory->close_cart();
184 bool VM::is_cart_inserted(int drv)
187 return memory->is_cart_inserted();
193 bool VM::is_frame_skippable()
195 return event->is_frame_skippable();
198 void VM::update_config()
200 for(DEVICE* device = first_device; device; device = device->next_device) {
201 device->update_config();
205 #define STATE_VERSION 2
207 #include "../../statesub.h"
208 #include "../../qt/gui/csp_logger.h"
209 extern CSP_Logger DLL_PREFIX_I *csp_logger;
211 void VM::decl_state(void)
213 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::SCV_HEAD")), csp_logger);
214 for(DEVICE* device = first_device; device; device = device->next_device) {
215 device->decl_state();
219 void VM::save_state(FILEIO* state_fio)
221 //state_fio->FputUint32(STATE_VERSION);
223 if(state_entry != NULL) {
224 state_entry->save_state(state_fio);
226 for(DEVICE* device = first_device; device; device = device->next_device) {
227 device->save_state(state_fio);
231 bool VM::load_state(FILEIO* state_fio)
233 //if(state_fio->FgetUint32() != STATE_VERSION) {
237 if(state_entry != NULL) {
238 mb = state_entry->load_state(state_fio);
241 emu->out_debug_log("INFO: HEADER DATA ERROR");
244 for(DEVICE* device = first_device; device; device = device->next_device) {
245 if(!device->load_state(state_fio)) {