2 SANYO PHC-25 Emulator 'ePHC-25'
3 SEIKO MAP-1010 Emulator 'eMAP-1010'
5 Author : Takeda.Toshiya
12 #include "../../emu.h"
13 #include "../device.h"
16 #include "../datarec.h"
18 #include "../mc6847.h"
21 //#include "../ym2203.h"
22 #include "../ay_3_891x.h"
26 #include "../debugger.h"
34 using PHC25::JOYSTICK;
35 using PHC25::KEYBOARD;
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
46 first_device = last_device = NULL;
47 dummy = new DEVICE(this, emu); // must be 1st device
48 event = new EVENT(this, emu); // must be 2nd device
49 dummy->set_device_name(_T("1st Dummy"));
51 drec = new DATAREC(this, emu);
52 drec->set_context_noise_play(new NOISE(this, emu));
53 drec->set_context_noise_stop(new NOISE(this, emu));
54 drec->set_context_noise_fast(new NOISE(this, emu));
55 io = new IO(this, emu);
57 vdp = new MC6847(this, emu);
58 not_vsync = new NOT(this, emu);
59 psg = new AY_3_891X(this, emu);
61 psg->set_context_debugger(new DEBUGGER(this, emu));
63 cpu = new Z80(this, emu);
64 not_vsync->set_device_name(_T("NOT GATE(VSYNC)"));
66 joystick = new JOYSTICK(this, emu);
67 keyboard = new KEYBOARD(this, emu);
68 memory = new MEMORY(this, emu);
69 system = new SYSTEM(this, emu);
71 event->set_context_cpu(cpu);
72 event->set_context_sound(psg);
73 event->set_context_sound(drec);
74 event->set_context_sound(drec->get_context_noise_play());
75 event->set_context_sound(drec->get_context_noise_stop());
76 event->set_context_sound(drec->get_context_noise_fast());
78 vdp->load_font_image(create_local_path(_T("FONT.ROM")));
79 vdp->set_vram_ptr(memory->get_vram(), 0x1800);
80 // vdp->set_context_cpu(cpu);
81 vdp->set_context_vsync(not_vsync, SIG_NOT_INPUT, 1);
82 not_vsync->set_context_out(cpu, SIG_CPU_IRQ, 1);
84 vdp->set_context_vsync(system, SIG_SYSTEM_PORT, 0x10);
85 drec->set_context_ear(system, SIG_SYSTEM_PORT, 0x20);
87 vdp->set_context_hsync(system, SIG_SYSTEM_PORT, 0x80);
89 joystick->set_context_psg(psg);
91 memory->set_context_keyboard(keyboard);
93 system->set_context_drec(drec);
94 system->set_context_vdp(vdp);
97 cpu->set_context_mem(memory);
98 cpu->set_context_io(io);
99 cpu->set_context_intr(dummy);
101 cpu->set_context_debugger(new DEBUGGER(this, emu));
105 io->set_iomap_single_rw(0x40, system);
107 io->set_iomap_range_r(0x80, 0x88, keyboard);
109 io->set_iomap_alias_w(0xc0, psg, 1); // PSG data
110 io->set_iomap_alias_w(0xc1, psg, 0); // PSG ch
111 // io->set_iomap_alias_r(0xc0, psg, 1);
112 io->set_iomap_alias_r(0xc1, psg, 1); // PSG data
114 // initialize all devices
115 #if defined(__GIT_REPO_VERSION)
116 set_git_repo_version(__GIT_REPO_VERSION);
118 initialize_devices();
123 // delete all devices
124 for(DEVICE* device = first_device; device;) {
125 DEVICE *next_device = device->next_device;
128 device = next_device;
132 DEVICE* VM::get_device(int id)
134 for(DEVICE* device = first_device; device; device = device->next_device) {
135 if(device->this_device_id == id) {
142 // ----------------------------------------------------------------------------
143 // drive virtual machine
144 // ----------------------------------------------------------------------------
149 for(DEVICE* device = first_device; device; device = device->next_device) {
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
164 DEVICE *VM::get_cpu(int index)
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 void VM::draw_screen()
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
186 void VM::initialize_sound(int rate, int samples)
188 // init sound manager
189 event->initialize_sound(rate, samples);
192 psg->initialize_sound(rate, 1996750, samples, 0, 0);
195 uint16_t* VM::create_sound(int* extra_frames)
197 return event->create_sound(extra_frames);
200 int VM::get_sound_buffer_ptr()
202 return event->get_sound_buffer_ptr();
205 #ifdef USE_SOUND_VOLUME
206 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
209 psg->set_volume(1, decibel_l, decibel_r);
211 drec->set_volume(0, decibel_l, decibel_r);
213 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
214 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
215 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
220 // ----------------------------------------------------------------------------
222 // ----------------------------------------------------------------------------
224 void VM::play_tape(int drv, const _TCHAR* file_path)
226 bool remote = drec->get_remote();
228 if(drec->play_tape(file_path) && remote) {
229 // if machine already sets remote on, start playing now
234 void VM::rec_tape(int drv, const _TCHAR* file_path)
236 bool remote = drec->get_remote();
238 if(drec->rec_tape(file_path) && remote) {
239 // if machine already sets remote on, start recording now
244 void VM::close_tape(int drv)
249 drec->set_remote(false);
252 bool VM::is_tape_inserted(int drv)
254 return drec->is_tape_inserted();
257 bool VM::is_tape_playing(int drv)
259 return drec->is_tape_playing();
262 bool VM::is_tape_recording(int drv)
264 return drec->is_tape_recording();
267 int VM::get_tape_position(int drv)
269 return drec->get_tape_position();
272 const _TCHAR* VM::get_tape_message(int drv)
274 return drec->get_message();
277 void VM::push_play(int drv)
279 drec->set_remote(false);
281 drec->set_remote(true);
284 void VM::push_stop(int drv)
286 drec->set_remote(false);
289 void VM::push_fast_forward(int drv)
291 drec->set_remote(false);
293 drec->set_remote(true);
296 void VM::push_fast_rewind(int drv)
298 drec->set_remote(false);
299 drec->set_ff_rew(-1);
300 drec->set_remote(true);
303 bool VM::is_frame_skippable()
305 return event->is_frame_skippable();
308 void VM::update_config()
310 for(DEVICE* device = first_device; device; device = device->next_device) {
311 device->update_config();
315 double VM::get_current_usec()
317 if(event == NULL) return 0.0;
318 return event->get_current_usec();
321 uint64_t VM::get_current_clock_uint64()
323 if(event == NULL) return (uint64_t)0;
324 return event->get_current_clock_uint64();
327 #define STATE_VERSION 5
329 bool VM::process_state(FILEIO* state_fio, bool loading)
331 if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) {
334 // Machine specified.