2 Homebrew Z80 TV GAME SYSTEM Emulator 'eZ80TVGAME'
4 Author : Takeda.Toshiya
10 // http://w01.tp1.jp/~a571632211/z80tvgame/index.html
12 #include "z80tvgame.h"
13 #include "../../emu.h"
14 #include "../device.h"
20 #include "../z80pio.h"
22 #include "../pcm1bit.h"
26 #include "../debugger.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 VM::VM(EMU* parent_emu) : emu(parent_emu)
39 first_device = last_device = NULL;
40 dummy = new DEVICE(this, emu); // must be 1st device
41 event = new EVENT(this, emu); // must be 2nd device
42 dummy->set_device_name(_T("1st Dummy"));
45 pio = new I8255(this, emu);
47 pio = new Z80PIO(this, emu);
49 pcm = new PCM1BIT(this, emu);
50 cpu = new Z80(this, emu);
52 joystick = new JOYSTICK(this, emu);
53 memory = new MEMORY(this, emu);
56 event->set_context_cpu(cpu);
57 event->set_context_sound(pcm);
59 // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
60 //pcm->set_realtime_render(true);
63 pio->set_context_port_c(pcm, SIG_PCM1BIT_SIGNAL, 1, 0);
65 pio->set_context_port_b(pcm, SIG_PCM1BIT_SIGNAL, 1, 0);
67 joystick->set_context_pio(pio);
70 cpu->set_context_mem(memory);
71 cpu->set_context_io(pio);
72 cpu->set_context_intr(dummy);
74 cpu->set_context_debugger(new DEBUGGER(this, emu));
77 // initialize all devices
78 for(DEVICE* device = first_device; device; device = device->next_device) {
86 for(DEVICE* device = first_device; device;) {
87 DEVICE *next_device = device->next_device;
94 DEVICE* VM::get_device(int id)
96 for(DEVICE* device = first_device; device; device = device->next_device) {
97 if(device->this_device_id == id) {
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
109 DEVICE *VM::get_cpu(int index)
118 // ----------------------------------------------------------------------------
119 // drive virtual machine
120 // ----------------------------------------------------------------------------
125 for(DEVICE* device = first_device; device; device = device->next_device) {
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 void VM::draw_screen()
141 memory->draw_screen();
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 void VM::initialize_sound(int rate, int samples)
150 // init sound manager
151 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 1
219 void VM::save_state(FILEIO* state_fio)
221 state_fio->FputUint32(STATE_VERSION);
223 for(DEVICE* device = first_device; device; device = device->next_device) {
224 device->save_state(state_fio);
228 bool VM::load_state(FILEIO* state_fio)
230 if(state_fio->FgetUint32() != STATE_VERSION) {
233 for(DEVICE* device = first_device; device; device = device->next_device) {
234 if(!device->load_state(state_fio)) {