#include "../z80ctc.h"
#include "../z80pio.h"
+#ifdef USE_DEBUGGER
+#include "../debugger.h"
+#endif
+
#include "display.h"
#include "keyboard.h"
// initialize
// ----------------------------------------------------------------------------
-VM::VM(EMU* parent_emu) : emu(parent_emu)
+VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
{
// create devices
first_device = last_device = NULL;
cpu = new Z80(this, emu);
ctc = new Z80CTC(this, emu);
pio1 = new Z80PIO(this, emu);
+ pio1->set_device_name(_T("Z80 PIO (LEDs)"));
pio2 = new Z80PIO(this, emu);
+ pio2->set_device_name(_T("Z80 PIO (7-Seg/Keyboard)"));
display = new DISPLAY(this, emu);
keyboard = new KEYBOARD(this, emu);
-
+
+ // Set names
+#if defined(_USE_QT)
+ dummy->set_device_name(_T("1st Dummy"));
+ pio1->set_device_name(_T("Z80 PIO(LEDs)"));
+ pio2->set_device_name(_T("Z80 PIO(7SEG/KEYBOARD)"));
+#endif
// set contexts
event->set_context_cpu(cpu);
cpu->set_context_mem(memory);
cpu->set_context_io(io);
cpu->set_context_intr(ctc);
+#ifdef USE_DEBUGGER
+ cpu->set_context_debugger(new DEBUGGER(this, emu));
+#endif
// z80 family daisy chain
ctc->set_context_intr(cpu, 0);
io->set_iomap_range_rw(0x20, 0x23, pio2);
// initialize all devices
+#if defined(__GIT_REPO_VERSION)
+ strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
+#endif
for(DEVICE* device = first_device; device; device = device->next_device) {
device->initialize();
}
}
// ----------------------------------------------------------------------------
+// debugger
+// ----------------------------------------------------------------------------
+
+#ifdef USE_DEBUGGER
+DEVICE *VM::get_cpu(int index)
+{
+ if(index == 0) {
+ return cpu;
+ }
+ return NULL;
+}
+#endif
+
+// ----------------------------------------------------------------------------
// draw screen
// ----------------------------------------------------------------------------
}
}
+#define STATE_VERSION 2
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ for(DEVICE* device = first_device; device; device = device->next_device) {
+ // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+ // const char *name = typeid(*device).name();
+ // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+ const char *name = device->get_device_name();
+ int len = strlen(name);
+
+ if(!state_fio->StateCheckInt32(len)) {
+ if(loading) {
+ printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
+ return false;
+ }
+ if(!state_fio->StateCheckBuffer(name, len, 1)) {
+ if(loading) {
+ printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
+ return false;
+ }
+ if(!device->process_state(state_fio, loading)) {
+ if(loading) {
+ printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+ }
+ return false;
+ }
+ }
+ // Machine specified.
+ state_fio->StateBuffer(ram, sizeof(ram), 1);
+ if(loading) {
+ update_config();
+ }
+ return true;
+}