2 COLECO ColecoVision Emulator 'yaCOLECOVISION'
10 #include "colecovision.h"
11 #include "../../emu.h"
12 #include "../device.h"
16 #include "../sn76489an.h"
17 #include "../tms9918a.h"
21 #include "../debugger.h"
24 #include "./keyboard.h"
27 using COLECOVISION::KEYBOARD;
28 using COLECOVISION::MEMORY;
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
36 first_device = last_device = NULL;
37 dummy = new DEVICE(this, emu); // must be 1st device
38 event = new EVENT(this, emu); // must be 2nd device
40 io = new IO(this, emu);
41 psg = new SN76489AN(this, emu);
42 vdp = new TMS9918A(this, emu);
43 cpu = new Z80(this, emu);
45 key = new KEYBOARD(this, emu);
46 memory = new MEMORY(this, emu);
49 event->set_context_cpu(cpu);
50 event->set_context_sound(psg);
52 vdp->set_context_irq(cpu, SIG_CPU_NMI, 1);
53 key->set_context_cpu(cpu);
56 cpu->set_context_mem(memory);
57 cpu->set_context_io(io);
58 cpu->set_context_intr(dummy);
60 cpu->set_context_debugger(new DEBUGGER(this, emu));
64 io->set_iomap_range_w(0x80, 0x9f, key);
65 io->set_iomap_range_rw(0xbe, 0xbf, vdp);
66 io->set_iomap_range_w(0xc0, 0xdf, key);
67 io->set_iomap_range_r(0xfc, 0xff, key);
68 io->set_iomap_range_w(0xff, 0xff, psg);
70 // initialize all devices
71 #if defined(__GIT_REPO_VERSION)
72 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
74 for(DEVICE* device = first_device; device; device = device->next_device) {
82 for(DEVICE* device = first_device; device;) {
83 DEVICE *next_device = device->next_device;
90 DEVICE* VM::get_device(int id)
92 for(DEVICE* device = first_device; device; device = device->next_device) {
93 if(device->this_device_id == id) {
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
105 DEVICE *VM::get_cpu(int index)
114 // ----------------------------------------------------------------------------
115 // drive virtual machine
116 // ----------------------------------------------------------------------------
121 for(DEVICE* device = first_device; device; device = device->next_device) {
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 void VM::draw_screen()
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
144 void VM::initialize_sound(int rate, int samples)
146 // init sound manager
147 event->initialize_sound(rate, samples);
150 psg->initialize_sound(rate, 3579545, 8000);
153 uint16_t* VM::create_sound(int* extra_frames)
155 return event->create_sound(extra_frames);
158 int VM::get_sound_buffer_ptr()
160 return event->get_sound_buffer_ptr();
163 #ifdef USE_SOUND_VOLUME
164 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
167 psg->set_volume(0, decibel_l, decibel_r);
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
176 void VM::open_cart(int drv, const _TCHAR* file_path)
179 memory->open_cart(file_path);
184 void VM::close_cart(int drv)
187 memory->close_cart();
192 bool VM::is_cart_inserted(int drv)
195 return memory->is_cart_inserted();
201 bool VM::is_frame_skippable()
203 return event->is_frame_skippable();
206 void VM::update_config()
208 for(DEVICE* device = first_device; device; device = device->next_device) {
209 device->update_config();
213 #define STATE_VERSION 2
215 bool VM::process_state(FILEIO* state_fio, bool loading)
217 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
220 for(DEVICE* device = first_device; device; device = device->next_device) {
221 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
222 // const char *name = typeid(*device).name();
223 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
224 const char *name = device->get_device_name();
225 int len = strlen(name);
227 if(!state_fio->StateCheckInt32(len)) {
229 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
233 if(!state_fio->StateCheckBuffer(name, len, 1)) {
235 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
239 if(!device->process_state(state_fio, loading)) {
241 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
246 // Machine specified.