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 for(DEVICE* device = first_device; device; device = device->next_device) {
73 for(DEVICE* device = first_device; device;) {
74 DEVICE *next_device = device->next_device;
81 DEVICE* VM::get_device(int id)
83 for(DEVICE* device = first_device; device; device = device->next_device) {
84 if(device->this_device_id == id) {
91 // ----------------------------------------------------------------------------
92 // drive virtual machine
93 // ----------------------------------------------------------------------------
98 for(DEVICE* device = first_device; device; device = device->next_device) {
108 // ----------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
113 DEVICE *VM::get_cpu(int index)
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 void VM::draw_screen()
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 void VM::initialize_sound(int rate, int samples)
137 // init sound manager
138 event->initialize_sound(rate, samples);
141 sound->initialize_sound(rate);
144 uint16_t* VM::create_sound(int* extra_frames)
146 return event->create_sound(extra_frames);
149 int VM::get_sound_buffer_ptr()
151 return event->get_sound_buffer_ptr();
154 #ifdef USE_SOUND_VOLUME
155 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
157 sound->set_volume(ch, decibel_l, decibel_r);
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
165 void VM::open_cart(int drv, const _TCHAR* file_path)
168 memory->open_cart(file_path);
173 void VM::close_cart(int drv)
176 memory->close_cart();
181 bool VM::is_cart_inserted(int drv)
184 return memory->is_cart_inserted();
190 bool VM::is_frame_skippable()
192 return event->is_frame_skippable();
195 void VM::update_config()
197 for(DEVICE* device = first_device; device; device = device->next_device) {
198 device->update_config();
202 #define STATE_VERSION 2
204 #include "../../statesub.h"
205 #include "../../qt/gui/csp_logger.h"
206 extern CSP_Logger DLL_PREFIX_I *csp_logger;
208 void VM::decl_state(void)
210 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::SCV_HEAD")), csp_logger);
211 for(DEVICE* device = first_device; device; device = device->next_device) {
212 device->decl_state();
216 void VM::save_state(FILEIO* state_fio)
218 //state_fio->FputUint32(STATE_VERSION);
220 if(state_entry != NULL) {
221 state_entry->save_state(state_fio);
223 for(DEVICE* device = first_device; device; device = device->next_device) {
224 device->save_state(state_fio);
228 bool VM::load_state(FILEIO* state_fio)
230 //if(state_fio->FgetUint32() != STATE_VERSION) {
234 if(state_entry != NULL) {
235 mb = state_entry->load_state(state_fio);
238 emu->out_debug_log("INFO: HEADER DATA ERROR");
241 for(DEVICE* device = first_device; device; device = device->next_device) {
242 if(!device->load_state(state_fio)) {