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 for(DEVICE* device = first_device; device; device = device->next_device) {
80 for(DEVICE* device = first_device; device;) {
81 DEVICE *next_device = device->next_device;
88 DEVICE* VM::get_device(int id)
90 for(DEVICE* device = first_device; device; device = device->next_device) {
91 if(device->this_device_id == id) {
98 // ----------------------------------------------------------------------------
99 // drive virtual machine
100 // ----------------------------------------------------------------------------
105 for(DEVICE* device = first_device; device; device = device->next_device) {
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
120 DEVICE *VM::get_cpu(int index)
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 void VM::draw_screen()
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 void VM::initialize_sound(int rate, int samples)
144 // init sound manager
145 event->initialize_sound(rate, samples);
148 psg->initialize_sound(rate, 3579545, 8000);
151 uint16_t* VM::create_sound(int* extra_frames)
153 return event->create_sound(extra_frames);
156 int VM::get_sound_buffer_ptr()
158 return event->get_sound_buffer_ptr();
161 #ifdef USE_SOUND_VOLUME
162 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
165 psg->set_volume(0, decibel_l, decibel_r);
167 drec->set_volume(0, decibel_l, decibel_r);
169 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
170 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
171 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 void VM::open_cart(int drv, const _TCHAR* file_path)
183 memory->open_cart(file_path);
188 void VM::close_cart(int drv)
191 memory->close_cart();
196 bool VM::is_cart_inserted(int drv)
199 return memory->is_cart_inserted();
205 void VM::play_tape(int drv, const _TCHAR* file_path)
207 drec->play_tape(file_path);
208 // drec->set_remote(true);
211 void VM::rec_tape(int drv, const _TCHAR* file_path)
213 drec->rec_tape(file_path);
214 // drec->set_remote(true);
217 void VM::close_tape(int drv)
222 // drec->set_remote(false);
225 bool VM::is_tape_inserted(int drv)
227 return drec->is_tape_inserted();
230 bool VM::is_tape_playing(int drv)
232 return drec->is_tape_playing();
235 bool VM::is_tape_recording(int drv)
237 return drec->is_tape_recording();
240 int VM::get_tape_position(int drv)
242 return drec->get_tape_position();
245 const _TCHAR* VM::get_tape_message(int drv)
247 return drec->get_message();
250 void VM::push_play(int drv)
253 drec->set_remote(true);
256 void VM::push_stop(int drv)
258 drec->set_remote(false);
261 void VM::push_fast_forward(int drv)
264 drec->set_remote(true);
267 void VM::push_fast_rewind(int drv)
269 drec->set_ff_rew(-1);
270 drec->set_remote(true);
273 bool VM::is_frame_skippable()
275 return event->is_frame_skippable();
278 void VM::update_config()
280 for(DEVICE* device = first_device; device; device = device->next_device) {
281 device->update_config();
285 #define STATE_VERSION 4
287 #include "../../statesub.h"
288 #include "../../qt/gui/csp_logger.h"
289 extern CSP_Logger DLL_PREFIX_I *csp_logger;
291 void VM::decl_state(void)
293 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PYUTA_HEAD")), csp_logger);
295 for(DEVICE* device = first_device; device; device = device->next_device) {
296 device->decl_state();
300 void VM::save_state(FILEIO* state_fio)
302 //state_fio->FputUint32(STATE_VERSION);
304 if(state_entry != NULL) {
305 state_entry->save_state(state_fio);
307 for(DEVICE* device = first_device; device; device = device->next_device) {
308 device->save_state(state_fio);
312 bool VM::load_state(FILEIO* state_fio)
314 //if(state_fio->FgetUint32() != STATE_VERSION) {
319 if(state_entry != NULL) {
320 mb = state_entry->load_state(state_fio);
323 emu->out_debug_log("INFO: HEADER DATA ERROR");
326 for(DEVICE* device = first_device; device; device = device->next_device) {
327 if(!device->load_state(state_fio)) {