2 SHINKO SANGYO YS-6464A Emulator 'eYS-6464A'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
17 #include "../memory.h"
18 #include "../pcm1bit.h"
22 #include "../debugger.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
35 first_device = last_device = NULL;
36 dummy = new DEVICE(this, emu); // must be 1st device
37 event = new EVENT(this, emu); // must be 2nd device
38 dummy->set_device_name(_T("1st Dummy"));
39 io = new IO(this, emu);
40 pio = new I8255(this, emu);
41 memory = new MEMORY(this, emu);
42 // pcm = new PCM1BIT(this, emu);
43 cpu = new Z80(this, emu);
45 display = new DISPLAY(this, emu);
46 keyboard = new KEYBOARD(this, emu);
49 event->set_context_cpu(cpu);
50 // event->set_context_sound(pcm);
52 // pio->set_context_port_b(pcm, SIG_PCM1BIT_SIGNAL, 0x01, 0);
53 pio->set_context_port_b(display, SIG_DISPLAY_PORT_B, 0xf0, 0);
54 pio->set_context_port_c(display, SIG_DISPLAY_PORT_C, 0xf0, 0);
55 pio->set_context_port_c(keyboard, SIG_KEYBOARD_PORT_C, 0xf0, 0);
56 keyboard->set_context_pio(pio);
59 cpu->set_context_mem(memory);
60 cpu->set_context_io(io);
61 cpu->set_context_intr(dummy);
63 cpu->set_context_debugger(new DEBUGGER(this, emu));
67 memset(ram, 0, sizeof(ram));
68 memset(rom, 0xff, sizeof(rom));
70 memory->read_bios(_T("MON.ROM"), rom, sizeof(rom));
72 memory->set_memory_r(0x0000, 0x1fff, rom);
73 memory->set_memory_r(0x2000, 0x3fff, rom);
74 memory->set_memory_r(0x4000, 0x5fff, rom);
75 memory->set_memory_r(0x6000, 0x7fff, rom);
76 memory->set_memory_rw(0x8000, 0x9fff, ram);
77 memory->set_memory_rw(0xa000, 0xbfff, ram);
78 memory->set_memory_rw(0xc000, 0xdfff, ram);
79 memory->set_memory_rw(0xe000, 0xffff, ram);
82 io->set_iomap_range_w(0xf8, 0xfb, pio);
83 io->set_iomap_range_r(0xf8, 0xfb, pio);
85 // initialize all devices
86 for(DEVICE* device = first_device; device; device = device->next_device) {
95 for(DEVICE* device = first_device; device;) {
96 DEVICE *next_device = device->next_device;
103 DEVICE* VM::get_device(int id)
105 for(DEVICE* device = first_device; device; device = device->next_device) {
106 if(device->this_device_id == id) {
113 // ----------------------------------------------------------------------------
114 // drive virtual machine
115 // ----------------------------------------------------------------------------
120 for(DEVICE* device = first_device; device; device = device->next_device) {
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
135 DEVICE *VM::get_cpu(int index)
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 void VM::draw_screen()
150 display->draw_screen();
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 void VM::initialize_sound(int rate, int samples)
159 // init sound manager
160 event->initialize_sound(rate, samples);
163 // pcm->initialize_sound(rate, 8000);
166 uint16_t* VM::create_sound(int* extra_frames)
168 return event->create_sound(extra_frames);
171 int VM::get_sound_buffer_ptr()
173 return event->get_sound_buffer_ptr();
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 void VM::load_binary(int drv, const _TCHAR* file_path)
183 memory->read_image(file_path, ram, sizeof(ram));
187 void VM::save_binary(int drv, const _TCHAR* file_path)
190 memory->write_image(file_path, ram, sizeof(ram));
194 bool VM::is_frame_skippable()
196 return event->is_frame_skippable();
199 void VM::update_config()
201 for(DEVICE* device = first_device; device; device = device->next_device) {
202 device->update_config();
206 #define STATE_VERSION 2
208 #include "../../statesub.h"
209 #include "../../qt/gui/csp_logger.h"
210 extern CSP_Logger DLL_PREFIX_I *csp_logger;
212 void VM::decl_state(void)
215 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::YS_6464A_HEAD")), csp_logger);
216 DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
217 for(DEVICE* device = first_device; device; device = device->next_device) {
218 device->decl_state();
222 void VM::save_state(FILEIO* state_fio)
224 //state_fio->FputUint32(STATE_VERSION);
226 if(state_entry != NULL) {
227 state_entry->save_state(state_fio);
229 for(DEVICE* device = first_device; device; device = device->next_device) {
230 device->save_state(state_fio);
232 //state_fio->Fwrite(ram, sizeof(ram), 1);
235 bool VM::load_state(FILEIO* state_fio)
237 //if(state_fio->FgetUint32() != STATE_VERSION) {
241 if(state_entry != NULL) {
242 mb = state_entry->load_state(state_fio);
245 emu->out_debug_log("INFO: HEADER DATA ERROR");
248 for(DEVICE* device = first_device; device; device = device->next_device) {
249 if(!device->load_state(state_fio)) {
253 //state_fio->Fread(ram, sizeof(ram), 1);