2 GAKKEN TV BOY Emulator 'yaTVBOY'
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../mc6847.h"
16 #include "../mc6801.h"
17 #include "../pcm1bit.h"
20 #include "../debugger.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
30 VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
33 first_device = last_device = NULL;
34 dummy = new DEVICE(this, emu); // must be 1st device
35 event = new EVENT(this, emu); // must be 2nd device
37 vdp = new MC6847(this, emu);
38 cpu = new MC6801(this, emu);
40 memory = new MEMORY(this, emu);
41 memory->set_context_cpu(cpu);
42 memory->set_context_vdp(vdp);
44 pcm = new PCM1BIT(this, emu);
46 cpu->set_context_port1(pcm, SIG_PCM1BIT_SIGNAL, 0x20, 0);
47 cpu->set_context_port1(pcm, SIG_PCM1BIT_SIGNAL, 0x40, 0);
48 cpu->set_context_port1(memory, SIG_MEMORY_PORT_1, 0x0F, 0);
51 event->set_context_cpu(cpu);
52 event->set_context_sound(pcm);
54 vdp->set_vram_ptr(memory->get_vram(), 0x800);
55 vdp->set_context_cpu(cpu);
58 cpu->set_context_mem(memory);
60 cpu->set_context_debugger(new DEBUGGER(this, emu));
62 pcm = new PCM1BIT(this, emu);
64 // initialize all devices
65 #if defined(__GIT_REPO_VERSION)
66 set_git_repo_version(__GIT_REPO_VERSION);
74 for(DEVICE* device = first_device; device;) {
75 DEVICE *next_device = device->next_device;
82 DEVICE* VM::get_device(int id)
84 for(DEVICE* device = first_device; device; device = device->next_device) {
85 if(device->this_device_id == id) {
92 // ----------------------------------------------------------------------------
93 // drive virtual machine
94 // ----------------------------------------------------------------------------
99 for(DEVICE* device = first_device; device; device = device->next_device) {
109 // ----------------------------------------------------------------------------
111 // ----------------------------------------------------------------------------
114 DEVICE *VM::get_cpu(int index)
123 // ----------------------------------------------------------------------------
125 // ----------------------------------------------------------------------------
127 void VM::draw_screen()
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 void VM::key_down(int code, bool repeat)
138 memory->key_down(code);
141 void VM::key_up(int code)
143 memory->key_up(code);
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
150 void VM::initialize_sound(int rate, int samples)
152 // init sound manager
153 event->initialize_sound(rate, samples);
154 pcm->initialize_sound(rate, 8000);
157 uint16_t* VM::create_sound(int* extra_frames)
159 return event->create_sound(extra_frames);
162 int VM::get_sound_buffer_ptr()
164 return event->get_sound_buffer_ptr();
167 #ifdef USE_SOUND_VOLUME
168 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
171 pcm->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 bool VM::is_frame_skippable()
207 return event->is_frame_skippable();
210 void VM::update_config()
212 for(DEVICE* device = first_device; device; device = device->next_device) {
213 device->update_config();
217 #define STATE_VERSION 3
219 bool VM::process_state(FILEIO* state_fio, bool loading)
221 if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) {