2 NEC-HE PC Engine Emulator 'ePCEngine'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../huc6280.h"
18 #include "../debugger.h"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 VM::VM(EMU* parent_emu) : emu(parent_emu)
30 first_device = last_device = NULL;
31 dummy = new DEVICE(this, emu); // must be 1st device
33 pceevent = new EVENT(this, emu);
34 // pceevent->set_frames_per_sec(FRAMES_PER_SEC);
35 // pceevent->set_lines_per_frame(LINES_PER_FRAME);
37 pcecpu = new HUC6280(this, emu);
38 // pcecpu->set_context_event_manager(pceevent);
39 pce = new PCE(this, emu);
40 // pce->set_context_event_manager(pceevent);
42 pceevent->set_context_cpu(pcecpu, CPU_CLOCKS);
43 pceevent->set_context_sound(pce);
45 pcecpu->set_context_mem(pce);
46 pcecpu->set_context_io(pce);
48 pcecpu->set_context_debugger(new DEBUGGER(this, emu));
50 pce->set_context_cpu(pcecpu);
52 // initialize all devices
53 for(DEVICE* device = first_device; device; device = device->next_device) {
61 for(DEVICE* device = first_device; device;) {
62 DEVICE *next_device = device->next_device;
69 DEVICE* VM::get_device(int id)
71 for(DEVICE* device = first_device; device; device = device->next_device) {
72 if(device->this_device_id == id) {
79 // ----------------------------------------------------------------------------
80 // drive virtual machine
81 // ----------------------------------------------------------------------------
86 for(DEVICE* device = first_device; device; device = device->next_device) {
96 double VM::frame_rate()
98 return pceevent->frame_rate();
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
106 DEVICE *VM::get_cpu(int index)
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 void VM::draw_screen()
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 void VM::initialize_sound(int rate, int samples)
130 // init sound manager
131 pceevent->initialize_sound(rate, samples);
134 pce->initialize_sound(rate);
137 uint16* VM::create_sound(int* extra_frames)
139 return pceevent->create_sound(extra_frames);
142 int VM::sound_buffer_ptr()
144 return pceevent->sound_buffer_ptr();
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 void VM::open_cart(int drv, const _TCHAR* file_path)
154 pce->open_cart(file_path);
160 void VM::close_cart(int drv)
169 bool VM::cart_inserted(int drv)
172 return pce->cart_inserted();
178 void VM::update_config()
180 for(DEVICE* device = first_device; device; device = device->next_device) {
181 device->update_config();
185 #define STATE_VERSION 1
187 void VM::save_state(FILEIO* state_fio)
189 state_fio->FputUint32(STATE_VERSION);
191 for(DEVICE* device = first_device; device; device = device->next_device) {
192 device->save_state(state_fio);
196 bool VM::load_state(FILEIO* state_fio)
198 if(state_fio->FgetUint32() != STATE_VERSION) {
201 for(DEVICE* device = first_device; device; device = device->next_device) {
202 if(!device->load_state(state_fio)) {