2 TOMY PyuTa Emulator 'ePyuTa'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
17 #include "../sn76489an.h"
18 #include "../tms9918a.h"
19 #include "../tms9995.h"
22 #include "../debugger.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
34 first_device = last_device = NULL;
35 dummy = new DEVICE(this, emu); // must be 1st device
36 event = new EVENT(this, emu); // must be 2nd device
37 dummy->set_device_name(_T("1st Dummy"));
39 drec = new DATAREC(this, emu);
40 drec->set_context_noise_play(new NOISE(this, emu));
41 drec->set_context_noise_stop(new NOISE(this, emu));
42 drec->set_context_noise_fast(new NOISE(this, emu));
43 psg = new SN76489AN(this, emu);
44 vdp = new TMS9918A(this, emu);
45 cpu = new TMS9995(this, emu);
47 memory = new MEMORY(this, emu);
50 event->set_context_cpu(cpu);
51 event->set_context_sound(psg);
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(memory, 0, 1);
58 memory->set_context_cmt(drec);
59 memory->set_context_cpu(cpu);
60 memory->set_context_psg(psg);
61 memory->set_context_vdp(vdp);
64 cpu->set_context_mem(memory);
65 cpu->set_context_io(memory);
67 cpu->set_context_debugger(new DEBUGGER(this, emu));
70 // initialize all devices
71 #if defined(__GIT_REPO_VERSION)
72 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
74 for(DEVICE* device = first_device; device; device = device->next_device) {
83 for(DEVICE* device = first_device; device;) {
84 DEVICE *next_device = device->next_device;
91 DEVICE* VM::get_device(int id)
93 for(DEVICE* device = first_device; device; device = device->next_device) {
94 if(device->this_device_id == id) {
101 // ----------------------------------------------------------------------------
102 // drive virtual machine
103 // ----------------------------------------------------------------------------
108 for(DEVICE* device = first_device; device; device = device->next_device) {
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
123 DEVICE *VM::get_cpu(int index)
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 void VM::draw_screen()
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 void VM::initialize_sound(int rate, int samples)
147 // init sound manager
148 event->initialize_sound(rate, samples);
151 psg->initialize_sound(rate, 3579545, 8000);
154 uint16_t* VM::create_sound(int* extra_frames)
156 return event->create_sound(extra_frames);
159 int VM::get_sound_buffer_ptr()
161 return event->get_sound_buffer_ptr();
164 #ifdef USE_SOUND_VOLUME
165 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
168 psg->set_volume(0, decibel_l, 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::open_cart(int drv, const _TCHAR* file_path)
186 memory->open_cart(file_path);
191 void VM::close_cart(int drv)
194 memory->close_cart();
199 bool VM::is_cart_inserted(int drv)
202 return memory->is_cart_inserted();
208 void VM::play_tape(int drv, const _TCHAR* file_path)
210 drec->play_tape(file_path);
211 // drec->set_remote(true);
214 void VM::rec_tape(int drv, const _TCHAR* file_path)
216 drec->rec_tape(file_path);
217 // drec->set_remote(true);
220 void VM::close_tape(int drv)
225 // drec->set_remote(false);
228 bool VM::is_tape_inserted(int drv)
230 return drec->is_tape_inserted();
233 bool VM::is_tape_playing(int drv)
235 return drec->is_tape_playing();
238 bool VM::is_tape_recording(int drv)
240 return drec->is_tape_recording();
243 int VM::get_tape_position(int drv)
245 return drec->get_tape_position();
248 const _TCHAR* VM::get_tape_message(int drv)
250 return drec->get_message();
253 void VM::push_play(int drv)
256 drec->set_remote(true);
259 void VM::push_stop(int drv)
261 drec->set_remote(false);
264 void VM::push_fast_forward(int drv)
267 drec->set_remote(true);
270 void VM::push_fast_rewind(int drv)
272 drec->set_ff_rew(-1);
273 drec->set_remote(true);
276 bool VM::is_frame_skippable()
278 return event->is_frame_skippable();
281 void VM::update_config()
283 for(DEVICE* device = first_device; device; device = device->next_device) {
284 device->update_config();
288 #define STATE_VERSION 4
290 #include "../../statesub.h"
291 #include "../../qt/gui/csp_logger.h"
292 extern CSP_Logger DLL_PREFIX_I *csp_logger;
294 void VM::decl_state(void)
296 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PYUTA_HEAD")), csp_logger);
298 for(DEVICE* device = first_device; device; device = device->next_device) {
299 device->decl_state();
303 void VM::save_state(FILEIO* state_fio)
305 //state_fio->FputUint32(STATE_VERSION);
307 if(state_entry != NULL) {
308 state_entry->save_state(state_fio);
310 for(DEVICE* device = first_device; device; device = device->next_device) {
311 device->save_state(state_fio);
315 bool VM::load_state(FILEIO* state_fio)
317 //if(state_fio->FgetUint32() != STATE_VERSION) {
322 if(state_entry != NULL) {
323 mb = state_entry->load_state(state_fio);
326 emu->out_debug_log("INFO: HEADER DATA ERROR");
329 for(DEVICE* device = first_device; device; device = device->next_device) {
330 if(!device->load_state(state_fio)) {