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"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
35 first_device = last_device = NULL;
36 dummy = new DEVICE(this, emu); // must be 1st device
37 event = new EVENT(this, emu); // must be 2nd device
38 dummy->set_device_name(_T("1st Dummy"));
40 drec = new DATAREC(this, emu);
41 drec->set_context_noise_play(new NOISE(this, emu));
42 drec->set_context_noise_stop(new NOISE(this, emu));
43 drec->set_context_noise_fast(new NOISE(this, emu));
44 psg = new SN76489AN(this, emu);
45 vdp = new TMS9918A(this, emu);
47 // psg->set_context_debugger(new DEBUGGER(this, emu));
48 vdp->set_context_debugger(new DEBUGGER(this, emu));
50 cpu = new TMS9995(this, emu);
52 memory = new MEMORY(this, emu);
55 event->set_context_cpu(cpu);
56 event->set_context_sound(psg);
57 event->set_context_sound(drec);
58 event->set_context_sound(drec->get_context_noise_play());
59 event->set_context_sound(drec->get_context_noise_stop());
60 event->set_context_sound(drec->get_context_noise_fast());
62 drec->set_context_ear(memory, 0, 1);
63 memory->set_context_cmt(drec);
64 memory->set_context_cpu(cpu);
65 memory->set_context_psg(psg);
66 memory->set_context_vdp(vdp);
69 cpu->set_context_mem(memory);
70 cpu->set_context_io(memory);
72 cpu->set_context_debugger(new DEBUGGER(this, emu));
75 // initialize all devices
76 #if defined(__GIT_REPO_VERSION)
77 set_git_repo_version(__GIT_REPO_VERSION);
85 for(DEVICE* device = first_device; device;) {
86 DEVICE *next_device = device->next_device;
93 DEVICE* VM::get_device(int id)
95 for(DEVICE* device = first_device; device; device = device->next_device) {
96 if(device->this_device_id == id) {
103 // ----------------------------------------------------------------------------
104 // drive virtual machine
105 // ----------------------------------------------------------------------------
110 for(DEVICE* device = first_device; device; device = device->next_device) {
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
125 DEVICE *VM::get_cpu(int index)
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 void VM::draw_screen()
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
147 void VM::initialize_sound(int rate, int samples)
149 // init sound manager
150 event->initialize_sound(rate, samples);
153 psg->initialize_sound(rate, 3579545, 8000);
156 uint16_t* VM::create_sound(int* extra_frames)
158 return event->create_sound(extra_frames);
161 int VM::get_sound_buffer_ptr()
163 return event->get_sound_buffer_ptr();
166 #ifdef USE_SOUND_VOLUME
167 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
170 psg->set_volume(0, decibel_l, decibel_r);
172 drec->set_volume(0, decibel_l, decibel_r);
174 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
175 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
176 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
181 // ----------------------------------------------------------------------------
183 // ----------------------------------------------------------------------------
185 void VM::open_cart(int drv, const _TCHAR* file_path)
188 memory->open_cart(file_path);
193 void VM::close_cart(int drv)
196 memory->close_cart();
201 bool VM::is_cart_inserted(int drv)
204 return memory->is_cart_inserted();
210 void VM::play_tape(int drv, const _TCHAR* file_path)
212 bool remote = drec->get_remote();
214 if(drec->play_tape(file_path) && remote) {
215 // if machine already sets remote on, start playing now
220 void VM::rec_tape(int drv, const _TCHAR* file_path)
222 bool remote = drec->get_remote();
224 if(drec->rec_tape(file_path) && remote) {
225 // if machine already sets remote on, start recording now
230 void VM::close_tape(int drv)
235 drec->set_remote(false);
238 bool VM::is_tape_inserted(int drv)
240 return drec->is_tape_inserted();
243 bool VM::is_tape_playing(int drv)
245 return drec->is_tape_playing();
248 bool VM::is_tape_recording(int drv)
250 return drec->is_tape_recording();
253 int VM::get_tape_position(int drv)
255 return drec->get_tape_position();
258 const _TCHAR* VM::get_tape_message(int drv)
260 return drec->get_message();
263 void VM::push_play(int drv)
265 drec->set_remote(false);
267 drec->set_remote(true);
270 void VM::push_stop(int drv)
272 drec->set_remote(false);
275 void VM::push_fast_forward(int drv)
277 drec->set_remote(false);
279 drec->set_remote(true);
282 void VM::push_fast_rewind(int drv)
284 drec->set_remote(false);
285 drec->set_ff_rew(-1);
286 drec->set_remote(true);
289 bool VM::is_frame_skippable()
291 return event->is_frame_skippable();
294 void VM::update_config()
296 for(DEVICE* device = first_device; device; device = device->next_device) {
297 device->update_config();
301 double VM::get_current_usec()
303 if(event == NULL) return 0.0;
304 return event->get_current_usec();
307 uint64_t VM::get_current_clock_uint64()
309 if(event == NULL) return (uint64_t)0;
310 return event->get_current_clock_uint64();
313 #define STATE_VERSION 5
315 bool VM::process_state(FILEIO* state_fio, bool loading)
317 if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) {
320 // Machine specified.