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"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
34 first_device = last_device = NULL;
35 dummy = new DEVICE(this, emu); // must be 1st device
36 event = new EVENT(this, emu); // must be 2nd device
38 io = new IO(this, emu);
39 psg = new SN76489AN(this, emu);
40 vdp = new TMS9918A(this, emu);
41 cpu = new Z80(this, emu);
43 key = new KEYBOARD(this, emu);
44 memory = new MEMORY(this, emu);
47 event->set_context_cpu(cpu);
48 event->set_context_sound(psg);
50 vdp->set_context_irq(cpu, SIG_CPU_NMI, 1);
51 key->set_context_cpu(cpu);
54 cpu->set_context_mem(memory);
55 cpu->set_context_io(io);
56 cpu->set_context_intr(dummy);
58 cpu->set_context_debugger(new DEBUGGER(this, emu));
62 io->set_iomap_range_w(0x80, 0x9f, key);
63 io->set_iomap_range_rw(0xbe, 0xbf, vdp);
64 io->set_iomap_range_w(0xc0, 0xdf, key);
65 io->set_iomap_range_r(0xfc, 0xff, key);
66 io->set_iomap_range_w(0xff, 0xff, psg);
68 // initialize all devices
69 #if defined(__GIT_REPO_VERSION)
70 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
72 for(DEVICE* device = first_device; device; device = device->next_device) {
80 for(DEVICE* device = first_device; device;) {
81 DEVICE *next_device = device->next_device;
88 DEVICE* VM::get_device(int id)
90 for(DEVICE* device = first_device; device; device = device->next_device) {
91 if(device->this_device_id == id) {
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
103 DEVICE *VM::get_cpu(int index)
112 // ----------------------------------------------------------------------------
113 // drive virtual machine
114 // ----------------------------------------------------------------------------
119 for(DEVICE* device = first_device; device; device = device->next_device) {
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 void VM::draw_screen()
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 void VM::initialize_sound(int rate, int samples)
144 // init sound manager
145 event->initialize_sound(rate, samples);
148 psg->initialize_sound(rate, 3579545, 8000);
151 uint16_t* VM::create_sound(int* extra_frames)
153 return event->create_sound(extra_frames);
156 int VM::get_sound_buffer_ptr()
158 return event->get_sound_buffer_ptr();
161 #ifdef USE_SOUND_VOLUME
162 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
165 psg->set_volume(0, decibel_l, decibel_r);
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 void VM::open_cart(int drv, const _TCHAR* file_path)
177 memory->open_cart(file_path);
182 void VM::close_cart(int drv)
185 memory->close_cart();
190 bool VM::is_cart_inserted(int drv)
193 return memory->is_cart_inserted();
199 bool VM::is_frame_skippable()
201 return event->is_frame_skippable();
204 void VM::update_config()
206 for(DEVICE* device = first_device; device; device = device->next_device) {
207 device->update_config();
211 #define STATE_VERSION 2
213 bool VM::process_state(FILEIO* state_fio, bool loading)
215 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
218 for(DEVICE* device = first_device; device; device = device->next_device) {
219 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
220 // const char *name = typeid(*device).name();
221 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
222 const char *name = device->get_device_name();
223 int len = strlen(name);
225 if(!state_fio->StateCheckInt32(len)) {
227 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
231 if(!state_fio->StateCheckBuffer(name, len, 1)) {
233 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
237 if(!device->process_state(state_fio, loading)) {
239 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
244 // Machine specified.