From 8639d5f3a215d3d68dceb1a6c0e4291d1bfa17cf Mon Sep 17 00:00:00 2001 From: "K.Ohta" Date: Sun, 21 Oct 2018 21:31:14 +0900 Subject: [PATCH] [VM][STATE] Apply New framework to some VMs. --- source/src/vm/phc20/memory.cpp | 66 ++++------------------------- source/src/vm/phc20/memory.h | 14 +++---- source/src/vm/phc20/phc20.cpp | 79 ++++++++++------------------------- source/src/vm/phc20/phc20.h | 8 ++-- source/src/vm/phc25/keyboard.cpp | 51 ----------------------- source/src/vm/phc25/keyboard.h | 4 +- source/src/vm/phc25/memory.cpp | 56 +++---------------------- source/src/vm/phc25/memory.h | 14 +++---- source/src/vm/phc25/phc25.cpp | 88 +++++++++++---------------------------- source/src/vm/phc25/phc25.h | 12 +++--- source/src/vm/phc25/system.cpp | 20 ++++----- source/src/vm/phc25/system.h | 14 +++---- source/src/vm/pv1000/joystick.cpp | 46 +------------------- source/src/vm/pv1000/joystick.h | 4 +- source/src/vm/pv1000/psg.cpp | 47 +-------------------- source/src/vm/pv1000/psg.h | 4 +- source/src/vm/pv1000/pv1000.cpp | 79 +++++++++-------------------------- source/src/vm/pv1000/pv1000.h | 4 +- source/src/vm/pv1000/vdp.cpp | 57 ------------------------- source/src/vm/pv1000/vdp.h | 4 +- source/src/vm/pv2000/cmt.cpp | 56 ------------------------- source/src/vm/pv2000/cmt.h | 4 +- source/src/vm/pv2000/keyboard.cpp | 49 ---------------------- source/src/vm/pv2000/keyboard.h | 4 +- source/src/vm/pv2000/printer.cpp | 50 ---------------------- source/src/vm/pv2000/printer.h | 4 +- source/src/vm/pv2000/pv2000.cpp | 83 +++++++++--------------------------- source/src/vm/pv2000/pv2000.h | 4 +- 28 files changed, 147 insertions(+), 778 deletions(-) diff --git a/source/src/vm/phc20/memory.cpp b/source/src/vm/phc20/memory.cpp index fec8e53d2..558480a7b 100644 --- a/source/src/vm/phc20/memory.cpp +++ b/source/src/vm/phc20/memory.cpp @@ -7,7 +7,7 @@ [ memory ] */ -#include "memory.h" +#include "./memory.h" #include "../datarec.h" static const uint8_t key_map[9][8] = { @@ -38,7 +38,7 @@ static const uint8_t key_map[9][8] = { } \ } -void MEMORY::initialize() +void PHC20_MEMORY::initialize() { memset(rom, 0xff, sizeof(rom)); memset(rdmy, 0xff, sizeof(rdmy)); @@ -64,7 +64,7 @@ void MEMORY::initialize() register_frame_event(this); } -void MEMORY::reset() +void PHC20_MEMORY::reset() { memset(ram, 0, sizeof(ram)); memset(vram, 0, sizeof(vram)); @@ -73,7 +73,7 @@ void MEMORY::reset() sysport = 0; } -void MEMORY::write_data8(uint32_t addr, uint32_t data) +void PHC20_MEMORY::write_data8(uint32_t addr, uint32_t data) { addr &= 0xffff; if((0x3000 <= addr && addr < 0x4000) || 0x4400 <= addr) { @@ -104,7 +104,7 @@ void MEMORY::write_data8(uint32_t addr, uint32_t data) wbank[addr >> 10][addr & 0x3ff] = data; } -uint32_t MEMORY::read_data8(uint32_t addr) +uint32_t PHC20_MEMORY::read_data8(uint32_t addr) { addr &= 0xffff; if((0x3000 <= addr && addr < 0x4000) || 0x4400 <= addr) { @@ -134,7 +134,7 @@ uint32_t MEMORY::read_data8(uint32_t addr) return rbank[addr >> 10][addr & 0x3ff]; } -void MEMORY::event_frame() +void PHC20_MEMORY::event_frame() { memset(status, 0, sizeof(status)); @@ -147,7 +147,7 @@ void MEMORY::event_frame() } } -void MEMORY::write_signal(int id, uint32_t data, uint32_t mask) +void PHC20_MEMORY::write_signal(int id, uint32_t data, uint32_t mask) { if(data & mask) { sysport |= mask; @@ -158,57 +158,7 @@ void MEMORY::write_signal(int id, uint32_t data, uint32_t mask) #define STATE_VERSION 1 -#include "../../statesub.h" - -void MEMORY::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); - DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram)); - DECL_STATE_ENTRY_1D_ARRAY(status, sizeof(status)); - DECL_STATE_ENTRY_UINT8(sysport); - - leave_decl_state(); -} - -void MEMORY::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); -// state_fio->FputInt32(this_device_id); - -// state_fio->Fwrite(ram, sizeof(ram), 1); -// state_fio->Fwrite(vram, sizeof(vram), 1); -// state_fio->Fwrite(status, sizeof(status), 1); -// state_fio->FputUint8(sysport); -} - -bool MEMORY::load_state(FILEIO* state_fio) -{ - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - return false; - } -// if(state_fio->FgetUint32() != STATE_VERSION) { -// return false; -// } -// if(state_fio->FgetInt32() != this_device_id) { -// return false; -// } -// state_fio->Fread(ram, sizeof(ram), 1); -// state_fio->Fread(vram, sizeof(vram), 1); -// state_fio->Fread(status, sizeof(status), 1); -// sysport = state_fio->FgetUint8(); - return true; -} - -bool MEMORY::process_state(FILEIO* state_fio, bool loading) +bool PHC20_MEMORY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { return false; diff --git a/source/src/vm/phc20/memory.h b/source/src/vm/phc20/memory.h index d93b411b4..e4d3b3f19 100644 --- a/source/src/vm/phc20/memory.h +++ b/source/src/vm/phc20/memory.h @@ -7,8 +7,8 @@ [ memory ] */ -#ifndef _MEMORY_H_ -#define _MEMORY_H_ +#ifndef _PHC20_MEMORY_H_ +#define _PHC20_MEMORY_H_ #include "../vm.h" #include "../../emu.h" @@ -16,7 +16,7 @@ #define SIG_MEMORY_SYSPORT 0 -class MEMORY : public DEVICE +class PHC20_MEMORY : public DEVICE { private: DEVICE *d_drec; @@ -35,11 +35,11 @@ private: uint8_t sysport; public: - MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) + PHC20_MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) { set_device_name(_T("Memory Bus")); } - ~MEMORY() {} + ~PHC20_MEMORY() {} // common functions void initialize(); @@ -48,9 +48,7 @@ public: uint32_t read_data8(uint32_t addr); void event_frame(); void write_signal(int id, uint32_t data, uint32_t mask); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // unique functions void set_context_drec(DEVICE* device) diff --git a/source/src/vm/phc20/phc20.cpp b/source/src/vm/phc20/phc20.cpp index d5f0131af..c1a53a6f0 100644 --- a/source/src/vm/phc20/phc20.cpp +++ b/source/src/vm/phc20/phc20.cpp @@ -21,7 +21,7 @@ #include "../debugger.h" #endif -#include "memory.h" +#include "./memory.h" // ---------------------------------------------------------------------------- // initialize @@ -41,7 +41,7 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) drec->set_context_noise_fast(new NOISE(this, emu)); vdp = new MC6847(this, emu); cpu = new Z80(this, emu); - memory = new MEMORY(this, emu); + memory = new PHC20_MEMORY(this, emu); // set contexts event->set_context_cpu(cpu); event->set_context_sound(drec); @@ -77,7 +77,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) for(DEVICE* device = first_device; device; device = device->next_device) { device->initialize(); } - decl_state(); } VM::~VM() @@ -260,71 +259,37 @@ void VM::update_config() #define STATE_VERSION 3 -#include "../../statesub.h" -#include "../../qt/gui/csp_logger.h" -extern CSP_Logger DLL_PREFIX_I *csp_logger; - -void VM::decl_state(void) -{ - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PHC_20_HEAD")), csp_logger); - - for(DEVICE* device = first_device; device; device = device->next_device) { - device->decl_state(); - } -} - -void VM::save_state(FILEIO* state_fio) -{ - //state_fio->FputUint32(STATE_VERSION); - - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } - for(DEVICE* device = first_device; device; device = device->next_device) { - device->save_state(state_fio); - } -} - -bool VM::load_state(FILEIO* state_fio) -{ - //if(state_fio->FgetUint32() != STATE_VERSION) { - // return false; - //} - - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - emu->out_debug_log("INFO: HEADER DATA ERROR"); - return false; - } - for(DEVICE* device = first_device; device; device = device->next_device) { - if(!device->load_state(state_fio)) { - return false; - } - } - return true; -} - 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) { - const char *name = typeid(*device).name() + 6; // skip "class " + 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)) { - return false; - } + 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)) { - return false; - } - } + if(loading) { + printf("Data loading Error: DEVID=%d\n", device->this_device_id); + } + return false; + } + } + // Machine specified. return true; } diff --git a/source/src/vm/phc20/phc20.h b/source/src/vm/phc20/phc20.h index 73232e046..db243520a 100644 --- a/source/src/vm/phc20/phc20.h +++ b/source/src/vm/phc20/phc20.h @@ -55,7 +55,7 @@ class DATAREC; class MC6847; class Z80; -class MEMORY; +class PHC20_MEMORY; class VM : public VM_TEMPLATE { @@ -70,7 +70,7 @@ protected: MC6847* vdp; Z80* cpu; - MEMORY* memory; + PHC20_MEMORY* memory; public: // ---------------------------------------- @@ -122,9 +122,7 @@ public: bool is_frame_skippable(); void update_config(); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // ---------------------------------------- // for each device diff --git a/source/src/vm/phc25/keyboard.cpp b/source/src/vm/phc25/keyboard.cpp index c9547ca15..17574abcb 100644 --- a/source/src/vm/phc25/keyboard.cpp +++ b/source/src/vm/phc25/keyboard.cpp @@ -120,57 +120,6 @@ void KEYBOARD::event_frame() #define STATE_VERSION 1 -#include "../../statesub.h" - -void KEYBOARD::decl_state() -{ - enter_decl_state(STATE_VERSION); -#ifdef _MAP1010 - DECL_STATE_ENTRY_INT32(kana_pressed); -#else - DECL_STATE_ENTRY_1D_ARRAY(status, sizeof(status)); -#endif - leave_decl_state(); -} - -void KEYBOARD::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); -// state_fio->FputInt32(this_device_id); -// -//#ifdef _MAP1010 -// state_fio->FputInt32(kana_pressed); -//#else -// state_fio->Fwrite(status, sizeof(status), 1); -//#endif -} - -bool KEYBOARD::load_state(FILEIO* state_fio) -{ - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - return false; - } -// if(state_fio->FgetUint32() != STATE_VERSION) { -// return false; -// } -// if(state_fio->FgetInt32() != this_device_id) { -// return false; -// } -//#ifdef _MAP1010 -// kana_pressed = state_fio->FgetInt32(); -//#else -// state_fio->Fread(status, sizeof(status), 1); -//#endif - return true; -} - bool KEYBOARD::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/phc25/keyboard.h b/source/src/vm/phc25/keyboard.h index 281f176db..c9c8a0c14 100644 --- a/source/src/vm/phc25/keyboard.h +++ b/source/src/vm/phc25/keyboard.h @@ -38,9 +38,7 @@ public: void reset(); uint32_t read_io8(uint32_t addr); void event_frame(); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); }; #endif diff --git a/source/src/vm/phc25/memory.cpp b/source/src/vm/phc25/memory.cpp index 966f9d655..7ae17e696 100644 --- a/source/src/vm/phc25/memory.cpp +++ b/source/src/vm/phc25/memory.cpp @@ -8,7 +8,7 @@ [ memory ] */ -#include "memory.h" +#include "./memory.h" #define SET_BANK(s, e, w, r) { \ int sb = (s) >> 11, eb = (e) >> 11; \ @@ -26,7 +26,7 @@ } \ } -void MEMORY::initialize() +void PHC25_MEMORY::initialize() { memset(rom, 0xff, sizeof(rom)); memset(rdmy, 0xff, sizeof(rdmy)); @@ -53,13 +53,13 @@ void MEMORY::initialize() #endif } -void MEMORY::reset() +void PHC25_MEMORY::reset() { memset(ram, 0, sizeof(ram)); memset(vram, 0, sizeof(vram)); } -void MEMORY::write_data8(uint32_t addr, uint32_t data) +void PHC25_MEMORY::write_data8(uint32_t addr, uint32_t data) { addr &= 0xffff; #ifdef _MAP1010 @@ -71,7 +71,7 @@ void MEMORY::write_data8(uint32_t addr, uint32_t data) wbank[addr >> 11][addr & 0x7ff] = data; } -uint32_t MEMORY::read_data8(uint32_t addr) +uint32_t PHC25_MEMORY::read_data8(uint32_t addr) { addr &= 0xffff; #ifdef _MAP1010 @@ -87,51 +87,7 @@ uint32_t MEMORY::read_data8(uint32_t addr) #define STATE_VERSION 1 -#include "../../statesub.h" - -void MEMORY::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); - DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram)); - - leave_decl_state(); -} - -void MEMORY::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); -// state_fio->FputInt32(this_device_id); - -// state_fio->Fwrite(ram, sizeof(ram), 1); -// state_fio->Fwrite(vram, sizeof(vram), 1); -} - -bool MEMORY::load_state(FILEIO* state_fio) -{ - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - return false; - } -// if(state_fio->FgetUint32() != STATE_VERSION) { -// return false; -// } -// if(state_fio->FgetInt32() != this_device_id) { -// return false; -// } -// state_fio->Fread(ram, sizeof(ram), 1); -// state_fio->Fread(vram, sizeof(vram), 1); - return true; -} - -bool MEMORY::process_state(FILEIO* state_fio, bool loading) +bool PHC25_MEMORY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { return false; diff --git a/source/src/vm/phc25/memory.h b/source/src/vm/phc25/memory.h index 23ba8a763..1a511662b 100644 --- a/source/src/vm/phc25/memory.h +++ b/source/src/vm/phc25/memory.h @@ -8,14 +8,14 @@ [ memory ] */ -#ifndef _MEMORY_H_ -#define _MEMORY_H_ +#ifndef _PHC25_MEMORY_H_ +#define _PHC25_MEMORY_H_ #include "../vm.h" #include "../../emu.h" #include "../device.h" -class MEMORY : public DEVICE +class PHC25_MEMORY : public DEVICE { private: DEVICE *d_kbd; @@ -34,20 +34,18 @@ private: uint8_t* rbank[32]; public: - MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) + PHC25_MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) { set_device_name(_T("Memory Bus")); } - ~MEMORY() {} + ~PHC25_MEMORY() {} // common functions void initialize(); void reset(); void write_data8(uint32_t addr, uint32_t data); uint32_t read_data8(uint32_t addr); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // unique functions void set_context_keyboard(DEVICE* device) diff --git a/source/src/vm/phc25/phc25.cpp b/source/src/vm/phc25/phc25.cpp index 9d33ded33..0987d12b6 100644 --- a/source/src/vm/phc25/phc25.cpp +++ b/source/src/vm/phc25/phc25.cpp @@ -28,8 +28,8 @@ #include "joystick.h" #include "keyboard.h" -#include "memory.h" -#include "system.h" +#include "./memory.h" +#include "./system.h" // ---------------------------------------------------------------------------- // initialize @@ -57,8 +57,8 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) joystick = new JOYSTICK(this, emu); keyboard = new KEYBOARD(this, emu); - memory = new MEMORY(this, emu); - system = new SYSTEM(this, emu); + memory = new PHC25_MEMORY(this, emu); + system = new PHC25_SYSTEM(this, emu); // set contexts event->set_context_cpu(cpu); event->set_context_sound(psg); @@ -110,7 +110,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) for(DEVICE* device = first_device; device; device = device->next_device) { device->initialize(); } - decl_state(); } VM::~VM() @@ -298,76 +297,37 @@ void VM::update_config() #define STATE_VERSION 4 -#include "../../statesub.h" -#include "../../qt/gui/csp_logger.h" -extern CSP_Logger DLL_PREFIX_I *csp_logger; - -void VM::decl_state(void) -{ -#if defined(_PHC25) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PHC_25_HEAD")), csp_logger); -#elif defined(_MAP1010) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::MAP_1010_HEAD")), csp_logger); -#else - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PHC_25_SERIES_HEAD")), csp_logger); -#endif - - for(DEVICE* device = first_device; device; device = device->next_device) { - device->decl_state(); - } -} - -void VM::save_state(FILEIO* state_fio) -{ - //state_fio->FputUint32(STATE_VERSION); - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } - for(DEVICE* device = first_device; device; device = device->next_device) { - device->save_state(state_fio); - } -} - -bool VM::load_state(FILEIO* state_fio) -{ - //if(state_fio->FgetUint32() != STATE_VERSION) { - // return false; - //} - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - emu->out_debug_log("INFO: HEADER DATA ERROR"); - return false; - } - - for(DEVICE* device = first_device; device; device = device->next_device) { - if(!device->load_state(state_fio)) { - return false; - } - } - return true; -} - 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) { - const char *name = typeid(*device).name() + 6; // skip "class " + 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)) { - return false; - } + 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)) { - return false; - } - } + if(loading) { + printf("Data loading Error: DEVID=%d\n", device->this_device_id); + } + return false; + } + } + // Machine specified. return true; } diff --git a/source/src/vm/phc25/phc25.h b/source/src/vm/phc25/phc25.h index 3e19cc439..72f86983c 100644 --- a/source/src/vm/phc25/phc25.h +++ b/source/src/vm/phc25/phc25.h @@ -71,8 +71,8 @@ class Z80; class JOYSTICK; class KEYBOARD; -class MEMORY; -class SYSTEM; +class PHC25_MEMORY; +class PHC25_SYSTEM; class VM : public VM_TEMPLATE { @@ -93,8 +93,8 @@ protected: JOYSTICK* joystick; KEYBOARD* keyboard; - MEMORY* memory; - SYSTEM* system; + PHC25_MEMORY* memory; + PHC25_SYSTEM* system; public: // ---------------------------------------- @@ -146,9 +146,7 @@ public: bool is_frame_skippable(); void update_config(); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // ---------------------------------------- // for each device diff --git a/source/src/vm/phc25/system.cpp b/source/src/vm/phc25/system.cpp index 79d2569fa..2a6e4734f 100644 --- a/source/src/vm/phc25/system.cpp +++ b/source/src/vm/phc25/system.cpp @@ -8,21 +8,21 @@ [ system port ] */ -#include "system.h" +#include "./system.h" #include "../datarec.h" #include "../mc6847.h" -void SYSTEM::initialize() +void PHC25_SYSTEM::initialize() { sysport = 0; } -void SYSTEM::reset() +void PHC25_SYSTEM::reset() { d_vdp->write_signal(SIG_MC6847_INTEXT, 1, 1); } -void SYSTEM::write_io8(uint32_t addr, uint32_t data) +void PHC25_SYSTEM::write_io8(uint32_t addr, uint32_t data) { d_drec->write_signal(SIG_DATAREC_MIC, data, 0x01); d_drec->write_signal(SIG_DATAREC_REMOTE, ~data, 0x02); @@ -33,12 +33,12 @@ void SYSTEM::write_io8(uint32_t addr, uint32_t data) d_vdp->write_signal(SIG_MC6847_AG, data, 0x80); } -uint32_t SYSTEM::read_io8(uint32_t addr) +uint32_t PHC25_SYSTEM::read_io8(uint32_t addr) { return sysport; } -void SYSTEM::write_signal(int id, uint32_t data, uint32_t mask) +void PHC25_SYSTEM::write_signal(int id, uint32_t data, uint32_t mask) { sysport = (sysport & ~mask) | (data & mask); } @@ -47,7 +47,7 @@ void SYSTEM::write_signal(int id, uint32_t data, uint32_t mask) #include "../../statesub.h" -void SYSTEM::decl_state() +void PHC25_SYSTEM::decl_state() { enter_decl_state(STATE_VERSION); @@ -56,7 +56,7 @@ void SYSTEM::decl_state() leave_decl_state(); } -void SYSTEM::save_state(FILEIO* state_fio) +void PHC25_SYSTEM::save_state(FILEIO* state_fio) { if(state_entry != NULL) { state_entry->save_state(state_fio); @@ -67,7 +67,7 @@ void SYSTEM::save_state(FILEIO* state_fio) // state_fio->FputUint8(sysport); } -bool SYSTEM::load_state(FILEIO* state_fio) +bool PHC25_SYSTEM::load_state(FILEIO* state_fio) { bool mb = false; if(state_entry != NULL) { @@ -86,7 +86,7 @@ bool SYSTEM::load_state(FILEIO* state_fio) return true; } -bool SYSTEM::process_state(FILEIO* state_fio, bool loading) +bool PHC25_SYSTEM::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { return false; diff --git a/source/src/vm/phc25/system.h b/source/src/vm/phc25/system.h index 19196cd55..bf2cdc55f 100644 --- a/source/src/vm/phc25/system.h +++ b/source/src/vm/phc25/system.h @@ -8,8 +8,8 @@ [ system port ] */ -#ifndef _SYSTEM_H_ -#define _SYSTEM_H_ +#ifndef _PHC25_SYSTEM_H_ +#define _PHC25_SYSTEM_H_ #include "../vm.h" #include "../../emu.h" @@ -17,7 +17,7 @@ #define SIG_SYSTEM_PORT 0 -class SYSTEM : public DEVICE +class PHC25_SYSTEM : public DEVICE { private: DEVICE *d_drec, *d_vdp; @@ -25,11 +25,11 @@ private: uint8_t sysport; public: - SYSTEM(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) + PHC25_SYSTEM(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) { set_device_name(_T("System I/O")); } - ~SYSTEM() {} + ~PHC25_SYSTEM() {} // common functions void initialize(); @@ -37,9 +37,7 @@ public: void write_io8(uint32_t addr, uint32_t data); uint32_t read_io8(uint32_t addr); void write_signal(int id, uint32_t data, uint32_t mask); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // unique functions void set_context_drec(DEVICE* device) diff --git a/source/src/vm/pv1000/joystick.cpp b/source/src/vm/pv1000/joystick.cpp index fac275a74..20d94f0b2 100644 --- a/source/src/vm/pv1000/joystick.cpp +++ b/source/src/vm/pv1000/joystick.cpp @@ -7,7 +7,7 @@ [ joystick ] */ -#include "joystick.h" +#include "./joystick.h" void JOYSTICK::initialize() { @@ -86,50 +86,6 @@ void JOYSTICK::event_frame() #define STATE_VERSION 1 -#include "../../statesub.h" - -void JOYSTICK::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT8(column); - DECL_STATE_ENTRY_UINT8(status); - - leave_decl_state(); -} - -void JOYSTICK::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); -// state_fio->FputInt32(this_device_id); - -// state_fio->FputUint8(column); -// state_fio->FputUint8(status); -} - -bool JOYSTICK::load_state(FILEIO* state_fio) -{ - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - return false; - } -// if(state_fio->FgetUint32() != STATE_VERSION) { -// return false; -// } -// if(state_fio->FgetInt32() != this_device_id) { -// return false; -// } -// column = state_fio->FgetUint8(); -// status = state_fio->FgetUint8(); - return true; -} - bool JOYSTICK::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pv1000/joystick.h b/source/src/vm/pv1000/joystick.h index de20c3b1b..b3e271643 100644 --- a/source/src/vm/pv1000/joystick.h +++ b/source/src/vm/pv1000/joystick.h @@ -35,9 +35,7 @@ public: void write_io8(uint32_t addr, uint32_t data); uint32_t read_io8(uint32_t addr); void event_frame(); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); }; #endif diff --git a/source/src/vm/pv1000/psg.cpp b/source/src/vm/pv1000/psg.cpp index 120880c10..9df6995cc 100644 --- a/source/src/vm/pv1000/psg.cpp +++ b/source/src/vm/pv1000/psg.cpp @@ -8,7 +8,7 @@ */ #include -#include "psg.h" +#include "./psg.h" #define PSG_CLOCK #define PSG_VOLUME 8192 @@ -62,51 +62,6 @@ void PSG::set_volume(int ch, int decibel_l, int decibel_r) #define STATE_VERSION 1 -#include "../../statesub.h" - -void PSG::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_INT32_STRIDE((ch[0].period), 3, sizeof(ch[0])); - - leave_decl_state(); -} - -void PSG::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); -// state_fio->FputInt32(this_device_id); - -// for(int i = 0; i < 3; i++) { -// state_fio->FputInt32(ch[i].period); -// } -} - -bool PSG::load_state(FILEIO* state_fio) -{ - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - return false; - } -// if(state_fio->FgetUint32() != STATE_VERSION) { -// return false; -// } -// if(state_fio->FgetInt32() != this_device_id) { -// return false; -// } -// for(int i = 0; i < 3; i++) { -// ch[i].period = state_fio->FgetInt32(); -// } - return true; -} - bool PSG::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pv1000/psg.h b/source/src/vm/pv1000/psg.h index b4a58a0bc..4be84dc2f 100644 --- a/source/src/vm/pv1000/psg.h +++ b/source/src/vm/pv1000/psg.h @@ -38,9 +38,7 @@ public: void write_io8(uint32_t addr, uint32_t data); void mix(int32_t* buffer, int cnt); void set_volume(int ch, int decibel_l, int decibel_r); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // unique function void initialize_sound(int rate); diff --git a/source/src/vm/pv1000/pv1000.cpp b/source/src/vm/pv1000/pv1000.cpp index 9c0695149..d54a5bbaa 100644 --- a/source/src/vm/pv1000/pv1000.cpp +++ b/source/src/vm/pv1000/pv1000.cpp @@ -78,7 +78,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) for(DEVICE* device = first_device; device; device = device->next_device) { device->initialize(); } - decl_state(); inserted = false; } @@ -220,77 +219,39 @@ void VM::update_config() #define STATE_VERSION 2 -#include "../../statesub.h" -#include "../../qt/gui/csp_logger.h" -extern CSP_Logger DLL_PREFIX_I *csp_logger; - -void VM::decl_state(void) -{ - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PV_1000_HEAD")), csp_logger); - - DECL_STATE_ENTRY_1D_ARRAY(mem, sizeof(mem)); - DECL_STATE_ENTRY_BOOL(inserted); - for(DEVICE* device = first_device; device; device = device->next_device) { - device->decl_state(); - } -} - -void VM::save_state(FILEIO* state_fio) -{ - //state_fio->FputUint32(STATE_VERSION); - - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } - for(DEVICE* device = first_device; device; device = device->next_device) { - device->save_state(state_fio); - } - //state_fio->Fwrite(mem, sizeof(mem), 1); - //state_fio->FputBool(inserted); -} - -bool VM::load_state(FILEIO* state_fio) -{ - //if(state_fio->FgetUint32() != STATE_VERSION) { - // return false; - //} - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - emu->out_debug_log("INFO: HEADER DATA ERROR"); - return false; - } - for(DEVICE* device = first_device; device; device = device->next_device) { - if(!device->load_state(state_fio)) { - return false; - } - } - //state_fio->Fread(mem, sizeof(mem), 1); - //inserted = state_fio->FgetBool(); - return true; -} 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) { - const char *name = typeid(*device).name() + 6; // skip "class " + 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)) { - return false; - } + 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)) { - return false; - } - } + if(loading) { + printf("Data loading Error: DEVID=%d\n", device->this_device_id); + } + return false; + } + } + // Machine specified. state_fio->StateBuffer(mem, sizeof(mem), 1); state_fio->StateBool(inserted); return true; diff --git a/source/src/vm/pv1000/pv1000.h b/source/src/vm/pv1000/pv1000.h index 118f9370f..c6c72c9a1 100644 --- a/source/src/vm/pv1000/pv1000.h +++ b/source/src/vm/pv1000/pv1000.h @@ -131,9 +131,7 @@ public: bool is_frame_skippable(); void update_config(); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // ---------------------------------------- // for each device diff --git a/source/src/vm/pv1000/vdp.cpp b/source/src/vm/pv1000/vdp.cpp index 64f0fcc7d..7f49165fe 100644 --- a/source/src/vm/pv1000/vdp.cpp +++ b/source/src/vm/pv1000/vdp.cpp @@ -130,63 +130,6 @@ void VDP::draw_pcg(int x8, int y8, uint16_t top) #define STATE_VERSION 1 -#include "../../statesub.h" - -void VDP::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_INT32(tmp_vram_size); // (int)(vram - base); - DECL_STATE_ENTRY_INT32(tmp_pcg_size); // (int)(pcg - base); - DECL_STATE_ENTRY_INT32(tmp_pattern_size); // (int)(pattern - base); - DECL_STATE_ENTRY_BOOL(force_pattern); - - leave_decl_state(); -} - -void VDP::save_state(FILEIO* state_fio) -{ - tmp_vram_size = (int)(vram - base); - tmp_pcg_size = (int)(pcg - base); - tmp_pattern_size = (int)(pattern - base); - - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); -// state_fio->FputInt32(this_device_id); - -// state_fio->FputInt32((int)(vram - base)); -// state_fio->FputInt32((int)(pcg - base)); -// state_fio->FputInt32((int)(pattern - base)); -// state_fio->FputBool(force_pattern); -} - -bool VDP::load_state(FILEIO* state_fio) -{ - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - return false; - } -// if(state_fio->FgetUint32() != STATE_VERSION) { -// return false; -// } -// if(state_fio->FgetInt32() != this_device_id) { -// return false; -// } -// vram = base + state_fio->FgetInt32(); -// pcg = base + state_fio->FgetInt32(); -// pattern = base + state_fio->FgetInt32(); -// force_pattern = state_fio->FgetBool(); - vram = base + tmp_vram_size; - pcg = base + tmp_pcg_size; - pattern = base + tmp_pattern_size; - return true; -} - bool VDP::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pv1000/vdp.h b/source/src/vm/pv1000/vdp.h index 642e7bebe..16427ccfe 100644 --- a/source/src/vm/pv1000/vdp.h +++ b/source/src/vm/pv1000/vdp.h @@ -46,9 +46,7 @@ public: void write_io8(uint32_t addr, uint32_t data); void event_callback(int event_id, int err); void event_vline(int v, int clock); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // unique functions void set_context_cpu(DEVICE* device) diff --git a/source/src/vm/pv2000/cmt.cpp b/source/src/vm/pv2000/cmt.cpp index 054c60ea5..5840d2dfd 100644 --- a/source/src/vm/pv2000/cmt.cpp +++ b/source/src/vm/pv2000/cmt.cpp @@ -131,62 +131,6 @@ void CMT::close_tape() #define STATE_VERSION 1 -#include "../../statesub.h" - -void CMT::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_INT32(bufcnt); - DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer)); - DECL_STATE_ENTRY_BOOL(play); - DECL_STATE_ENTRY_BOOL(rec); - DECL_STATE_ENTRY_UINT8(start); - DECL_STATE_ENTRY_UINT8(bit); - - leave_decl_state(); -} - -void CMT::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); -// state_fio->FputInt32(this_device_id); - -// state_fio->FputInt32(bufcnt); -// state_fio->Fwrite(buffer, sizeof(buffer), 1); -// state_fio->FputBool(play); -// state_fio->FputBool(rec); -// state_fio->FputUint8(start); -// state_fio->FputUint8(bit); -} - -bool CMT::load_state(FILEIO* state_fio) -{ - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - return false; - } -// if(state_fio->FgetUint32() != STATE_VERSION) { -// return false; -// } -// if(state_fio->FgetInt32() != this_device_id) { -// return false; -// } -// bufcnt = state_fio->FgetInt32(); -// state_fio->Fread(buffer, sizeof(buffer), 1); -// play = state_fio->FgetBool(); -// rec = state_fio->FgetBool(); -// start = state_fio->FgetUint8(); -// bit = state_fio->FgetUint8(); - return true; -} - bool CMT::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pv2000/cmt.h b/source/src/vm/pv2000/cmt.h index ded5ab306..7f0d7edf6 100644 --- a/source/src/vm/pv2000/cmt.h +++ b/source/src/vm/pv2000/cmt.h @@ -40,9 +40,7 @@ public: void reset(); void write_io8(uint32_t addr, uint32_t data); uint32_t read_io8(uint32_t addr); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // unique functions void play_tape(const _TCHAR* file_path); diff --git a/source/src/vm/pv2000/keyboard.cpp b/source/src/vm/pv2000/keyboard.cpp index bed36e739..9e7e71342 100644 --- a/source/src/vm/pv2000/keyboard.cpp +++ b/source/src/vm/pv2000/keyboard.cpp @@ -110,55 +110,6 @@ void KEYBOARD::key_up(int code) #define STATE_VERSION 1 -#include "../../statesub.h" - -void KEYBOARD::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_1D_ARRAY(key_stat, sizeof(key_stat)); - DECL_STATE_ENTRY_INT32(key_no); - DECL_STATE_ENTRY_BOOL(intr_enb); - - leave_decl_state(); -} - -void KEYBOARD::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// if(state_entry != NULL) { -// state_entry->save_state(state_fio); -// } -// state_fio->FputUint32(STATE_VERSION); -// state_fio->FputInt32(this_device_id); - -// state_fio->Fwrite(key_stat, sizeof(key_stat), 1); -// state_fio->FputInt32(key_no); -// state_fio->FputBool(intr_enb); -} - -bool KEYBOARD::load_state(FILEIO* state_fio) -{ - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - return false; - } -// if(state_fio->FgetUint32() != STATE_VERSION) { -// return false; -// } -// if(state_fio->FgetInt32() != this_device_id) { -// return false; -// } -// state_fio->Fread(key_stat, sizeof(key_stat), 1); -// key_no = state_fio->FgetInt32(); -// intr_enb = state_fio->FgetBool(); - return true; -} bool KEYBOARD::process_state(FILEIO* state_fio, bool loading) { diff --git a/source/src/vm/pv2000/keyboard.h b/source/src/vm/pv2000/keyboard.h index 0c6c08ecb..522c0fd30 100644 --- a/source/src/vm/pv2000/keyboard.h +++ b/source/src/vm/pv2000/keyboard.h @@ -36,9 +36,7 @@ public: void reset(); void write_io8(uint32_t addr, uint32_t data); uint32_t read_io8(uint32_t addr); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // unique functions void set_context_cpu(DEVICE* device) diff --git a/source/src/vm/pv2000/printer.cpp b/source/src/vm/pv2000/printer.cpp index a463c7553..c7d3dcdf3 100644 --- a/source/src/vm/pv2000/printer.cpp +++ b/source/src/vm/pv2000/printer.cpp @@ -40,56 +40,6 @@ uint32_t PRINTER::read_io8(uint32_t addr) #define STATE_VERSION 1 -#include "../../statesub.h" - -void PRINTER::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT8(out); - DECL_STATE_ENTRY_UINT8(ctrl0); - DECL_STATE_ENTRY_UINT8(ctrl1); - DECL_STATE_ENTRY_BOOL(busy); - - leave_decl_state(); -} - -void PRINTER::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); -// state_fio->FputInt32(this_device_id); - -// state_fio->FputUint8(out); -// state_fio->FputUint8(ctrl0); -// state_fio->FputUint8(ctrl1); -// state_fio->FputBool(busy); -} - -bool PRINTER::load_state(FILEIO* state_fio) -{ - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - return false; - } -// if(state_fio->FgetUint32() != STATE_VERSION) { -// return false; -// } -// if(state_fio->FgetInt32() != this_device_id) { -// return false; -// } -// out = state_fio->FgetUint8(); -// ctrl0 = state_fio->FgetUint8(); -// ctrl1 = state_fio->FgetUint8(); -// busy = state_fio->FgetBool(); - return true; -} - bool PRINTER::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pv2000/printer.h b/source/src/vm/pv2000/printer.h index 3a60de432..7ad091468 100644 --- a/source/src/vm/pv2000/printer.h +++ b/source/src/vm/pv2000/printer.h @@ -31,9 +31,7 @@ public: void initialize(); void write_io8(uint32_t addr, uint32_t data); uint32_t read_io8(uint32_t addr); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); }; #endif diff --git a/source/src/vm/pv2000/pv2000.cpp b/source/src/vm/pv2000/pv2000.cpp index 886e5d8bc..4d2576050 100644 --- a/source/src/vm/pv2000/pv2000.cpp +++ b/source/src/vm/pv2000/pv2000.cpp @@ -94,7 +94,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) for(DEVICE* device = first_device; device; device = device->next_device) { device->initialize(); } - decl_state(); inserted = false; } @@ -270,80 +269,38 @@ void VM::update_config() #define STATE_VERSION 2 -#include "../../statesub.h" -#include "../../qt/gui/csp_logger.h" -extern CSP_Logger DLL_PREFIX_I *csp_logger; - -void VM::decl_state(void) -{ - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PV_2000_HEAD")), csp_logger); - - DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); - DECL_STATE_ENTRY_1D_ARRAY(ext, sizeof(ext)); - DECL_STATE_ENTRY_BOOL(inserted); - for(DEVICE* device = first_device; device; device = device->next_device) { - device->decl_state(); - } -} - -void VM::save_state(FILEIO* state_fio) -{ - //state_fio->FputUint32(STATE_VERSION); - - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } - for(DEVICE* device = first_device; device; device = device->next_device) { - device->save_state(state_fio); - } - //state_fio->Fwrite(ram, sizeof(ram), 1); - //state_fio->Fwrite(ext, sizeof(ext), 1); - //state_fio->FputBool(inserted); -} - -bool VM::load_state(FILEIO* state_fio) -{ - //if(state_fio->FgetUint32() != STATE_VERSION) { - // return false; - //} - bool mb = false; - if(state_entry != NULL) { - mb = state_entry->load_state(state_fio); - } - if(!mb) { - emu->out_debug_log("INFO: HEADER DATA ERROR"); - return false; - } - for(DEVICE* device = first_device; device; device = device->next_device) { - if(!device->load_state(state_fio)) { - return false; - } - } - //state_fio->Fread(ram, sizeof(ram), 1); - //state_fio->Fread(ext, sizeof(ext), 1); - //inserted = state_fio->FgetBool(); - return true; -} - 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) { - const char *name = typeid(*device).name() + 6; // skip "class " + 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)) { - return false; - } + 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)) { - return false; - } - } + if(loading) { + printf("Data loading Error: DEVID=%d\n", device->this_device_id); + } + return false; + } + } + // Machine specified. state_fio->StateBuffer(ram, sizeof(ram), 1); state_fio->StateBuffer(ext, sizeof(ext), 1); state_fio->StateBool(inserted); diff --git a/source/src/vm/pv2000/pv2000.h b/source/src/vm/pv2000/pv2000.h index 939f2855f..219b183df 100644 --- a/source/src/vm/pv2000/pv2000.h +++ b/source/src/vm/pv2000/pv2000.h @@ -140,9 +140,7 @@ public: bool is_frame_skippable(); void update_config(); - void decl_state(); - void save_state(FILEIO* state_fio); - bool load_state(FILEIO* state_fio); + bool process_state(FILEIO* state_fio, bool loading); // ---------------------------------------- // for each device -- 2.11.0