2 NEC-HE PC Engine Emulator 'ePCEngine'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../huc6280.h"
16 #include "../msm5205.h"
17 #include "../scsi_cdrom.h"
18 #include "../scsi_host.h"
21 #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
36 pceevent = new EVENT(this, emu);
37 // pceevent->set_frames_per_sec(FRAMES_PER_SEC);
38 // pceevent->set_lines_per_frame(LINES_PER_FRAME);
39 dummy->set_device_name(_T("1st Dummy"));
40 pceevent->set_device_name(_T("PC-ENGINE EVENT"));
42 pcecpu = new HUC6280(this, emu);
43 pcecpu->set_device_name(_T("PC-ENGINE CPU(HuC6280)"));
44 // pcecpu->set_context_event_manager(pceevent);
45 adpcm = new MSM5205(this, emu);
46 // adpcm->set_context_event_manager(pceevent);
47 scsi_host = new SCSI_HOST(this, emu);
48 // scsi_host->set_context_event_manager(pceevent);
49 scsi_cdrom = new SCSI_CDROM(this, emu);
50 // scsi_cdrom->set_context_event_manager(pceevent);
52 pce = new PCE(this, emu);
53 // pce->set_context_event_manager(pceevent);
55 pce->set_device_name(_T("PC-ENGINE MAIN"));
58 pceevent->set_context_cpu(pcecpu, CPU_CLOCKS);
59 pceevent->set_context_sound(pce);
60 // NOTE: adpcm::mix() and scsi_cdrom::mix() will be called in pce::mix()
61 // pceevent->set_context_sound(adpcm);
62 // pceevent->set_context_sound(scsi_cdrom);
64 pcecpu->set_context_mem(pce);
65 pcecpu->set_context_io(pce);
67 pcecpu->set_context_debugger(new DEBUGGER(this, emu));
69 scsi_cdrom->scsi_id = 0;
70 scsi_cdrom->set_context_interface(scsi_host);
71 scsi_host->set_context_target(scsi_cdrom);
73 scsi_host->set_context_irq(pce, SIG_PCE_SCSI_IRQ, 1);
74 scsi_host->set_context_drq(pce, SIG_PCE_SCSI_DRQ, 1);
75 scsi_host->set_context_bsy(pce, SIG_PCE_SCSI_BSY, 1);
76 scsi_cdrom->set_context_done(pce, SIG_PCE_CDDA_DONE, 1);
77 adpcm->set_context_vclk(pce, SIG_PCE_ADPCM_VCLK, 1);
79 pce->set_context_cpu(pcecpu);
80 pce->set_context_adpcm(adpcm);
81 pce->set_context_scsi_host(scsi_host);
82 pce->set_context_scsi_cdrom(scsi_cdrom);
84 // initialize all devices
85 for(DEVICE* device = first_device; device; device = device->next_device) {
94 for(DEVICE* device = first_device; device;) {
95 DEVICE *next_device = device->next_device;
102 DEVICE* VM::get_device(int id)
104 for(DEVICE* device = first_device; device; device = device->next_device) {
105 if(device->this_device_id == id) {
112 // ----------------------------------------------------------------------------
113 // drive virtual machine
114 // ----------------------------------------------------------------------------
119 for(DEVICE* device = first_device; device; device = device->next_device) {
129 double VM::get_frame_rate()
131 return pceevent->get_frame_rate();
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
139 DEVICE *VM::get_cpu(int index)
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 void VM::draw_screen()
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
161 void VM::initialize_sound(int rate, int samples)
163 // init sound manager
164 pceevent->initialize_sound(rate, samples);
167 pce->initialize_sound(rate);
168 adpcm->initialize_sound(ADPCM_CLOCK / 6, MSM5205_S48_4B);
171 uint16_t* VM::create_sound(int* extra_frames)
173 return pceevent->create_sound(extra_frames);
176 int VM::get_sound_buffer_ptr()
178 return pceevent->get_sound_buffer_ptr();
181 #ifdef USE_SOUND_VOLUME
182 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
185 pce->set_volume(0, decibel_l, decibel_r);
187 scsi_cdrom->set_volume(0, decibel_l, decibel_r);
189 adpcm->set_volume(0, decibel_l, decibel_r);
194 // ----------------------------------------------------------------------------
196 // ----------------------------------------------------------------------------
198 void VM::open_cart(int drv, const _TCHAR* file_path)
200 pce->open_cart(file_path);
205 void VM::close_cart(int drv)
212 bool VM::is_cart_inserted(int drv)
214 return pce->is_cart_inserted();
217 void VM::open_compact_disc(int drv, const _TCHAR* file_path)
219 scsi_cdrom->open(file_path);
222 void VM::close_compact_disc(int drv)
227 bool VM::is_compact_disc_inserted(int drv)
229 return scsi_cdrom->mounted();
232 uint32_t VM::is_compact_disc_accessed()
234 return scsi_cdrom->accessed();
237 void VM::update_config()
239 for(DEVICE* device = first_device; device; device = device->next_device) {
240 device->update_config();
244 #define STATE_VERSION 2
246 #include "../../statesub.h"
247 #include "../../qt/gui/csp_logger.h"
248 extern CSP_Logger DLL_PREFIX_I *csp_logger;
250 void VM::decl_state(void)
252 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_ENGINE_HEAD")), csp_logger);
253 for(DEVICE* device = first_device; device; device = device->next_device) {
254 device->decl_state();
258 void VM::save_state(FILEIO* state_fio)
260 //state_fio->FputUint32(STATE_VERSION);
262 if(state_entry != NULL) {
263 state_entry->save_state(state_fio);
265 for(DEVICE* device = first_device; device; device = device->next_device) {
266 device->save_state(state_fio);
270 bool VM::load_state(FILEIO* state_fio)
272 //if(state_fio->FgetUint32() != STATE_VERSION) {
276 if(state_entry != NULL) {
277 mb = state_entry->load_state(state_fio);
280 emu->out_debug_log("INFO: HEADER DATA ERROR");
283 for(DEVICE* device = first_device; device; device = device->next_device) {
284 if(!device->load_state(state_fio)) {