From e4bf0bb6c5867c5e224272c397d193948c5bb27e Mon Sep 17 00:00:00 2001 From: "K.Ohta" Date: Sun, 21 Oct 2018 12:54:18 +0900 Subject: [PATCH] [VM][STATE] Apply new framework to some VMs. --- source/src/vm/mz3500/keyboard.cpp | 73 ----------- source/src/vm/mz3500/keyboard.h | 4 +- source/src/vm/mz3500/main.cpp | 113 ----------------- source/src/vm/mz3500/main.h | 4 +- source/src/vm/mz3500/mz3500.cpp | 77 +++-------- source/src/vm/mz3500/mz3500.h | 4 +- source/src/vm/mz3500/sub.cpp | 56 -------- source/src/vm/mz3500/sub.h | 4 +- source/src/vm/mz5500/display.cpp | 103 ++++----------- source/src/vm/mz5500/display.h | 4 +- source/src/vm/mz5500/keyboard.cpp | 81 ------------ source/src/vm/mz5500/keyboard.h | 4 +- source/src/vm/mz5500/memory.cpp | 89 ++----------- source/src/vm/mz5500/memory.h | 14 +- source/src/vm/mz5500/mz5500.cpp | 85 +++---------- source/src/vm/mz5500/mz5500.h | 8 +- source/src/vm/mz5500/sysport.cpp | 45 ------- source/src/vm/mz5500/sysport.h | 4 +- source/src/vm/n5200/memory.cpp | 16 +-- source/src/vm/n5200/memory.h | 10 +- source/src/vm/n5200/n5200.cpp | 52 ++++---- source/src/vm/n5200/n5200.h | 4 +- source/src/vm/pasopia/display.cpp | 47 ------- source/src/vm/pasopia/display.h | 4 +- source/src/vm/pasopia/floppy.cpp | 44 ------- source/src/vm/pasopia/floppy.h | 4 +- source/src/vm/pasopia/kanjipac2.cpp | 35 ----- source/src/vm/pasopia/kanjipac2.h | 4 +- source/src/vm/pasopia/keyboard.cpp | 39 ------ source/src/vm/pasopia/keyboard.h | 4 +- source/src/vm/pasopia/memory.cpp | 79 ++---------- source/src/vm/pasopia/memory.h | 14 +- source/src/vm/pasopia/pac2.cpp | 57 --------- source/src/vm/pasopia/pac2.h | 4 +- source/src/vm/pasopia/pac2dev.h | 4 +- source/src/vm/pasopia/pasopia.cpp | 86 ++++--------- source/src/vm/pasopia/pasopia.h | 8 +- source/src/vm/pasopia/rampac2.cpp | 45 ------- source/src/vm/pasopia/rampac2.h | 4 +- source/src/vm/pasopia7/display.cpp | 57 --------- source/src/vm/pasopia7/display.h | 4 +- source/src/vm/pasopia7/floppy.cpp | 39 ------ source/src/vm/pasopia7/floppy.h | 4 +- source/src/vm/pasopia7/iobus.cpp | 39 ------ source/src/vm/pasopia7/iobus.h | 4 +- source/src/vm/pasopia7/iotrap.cpp | 42 ------ source/src/vm/pasopia7/iotrap.h | 4 +- source/src/vm/pasopia7/kanjipac2.cpp | 35 ----- source/src/vm/pasopia7/kanjipac2.h | 4 +- source/src/vm/pasopia7/keyboard.cpp | 39 ------ source/src/vm/pasopia7/keyboard.h | 4 +- source/src/vm/pasopia7/memory.cpp | 87 ++----------- source/src/vm/pasopia7/memory.h | 14 +- source/src/vm/pasopia7/pac2.cpp | 65 ---------- source/src/vm/pasopia7/pac2.h | 4 +- source/src/vm/pasopia7/pac2dev.h | 4 +- source/src/vm/pasopia7/pasopia7.cpp | 79 +++--------- source/src/vm/pasopia7/pasopia7.h | 8 +- source/src/vm/pasopia7/rampac2.cpp | 44 ------- source/src/vm/pasopia7/rampac2.h | 4 +- source/src/vm/pc100/crtc.cpp | 104 ++++----------- source/src/vm/pc100/crtc.h | 4 +- source/src/vm/pc100/ioctrl.cpp | 71 ----------- source/src/vm/pc100/ioctrl.h | 4 +- source/src/vm/pc100/kanji.cpp | 44 ------- source/src/vm/pc100/kanji.h | 4 +- source/src/vm/pc100/pc100.cpp | 76 +++-------- source/src/vm/pc100/pc100.h | 4 +- source/src/vm/pc2001/io.cpp | 78 ++---------- source/src/vm/pc2001/io.h | 14 +- source/src/vm/pc2001/pc2001.cpp | 53 +------- source/src/vm/pc2001/pc2001.h | 8 +- source/src/vm/pc6001/display.cpp | 44 ------- source/src/vm/pc6001/display.h | 4 +- source/src/vm/pc6001/floppy.cpp | 141 +++++---------------- source/src/vm/pc6001/floppy.h | 4 +- source/src/vm/pc6001/memory.cpp | 239 ++--------------------------------- source/src/vm/pc6001/memory.h | 14 +- source/src/vm/pc6001/memory_draw.cpp | 40 +++--- source/src/vm/pc6001/pc6001.cpp | 90 +++---------- source/src/vm/pc6001/pc6001.h | 8 +- source/src/vm/pc6001/psub.cpp | 137 -------------------- source/src/vm/pc6001/psub.h | 4 +- source/src/vm/pc6001/sub.cpp | 110 ---------------- source/src/vm/pc6001/sub.h | 4 +- source/src/vm/pc6001/timer.cpp | 84 +----------- source/src/vm/pc6001/timer.h | 10 +- source/src/vm/pc8201/cmt.cpp | 93 -------------- source/src/vm/pc8201/cmt.h | 4 +- source/src/vm/pc8201/keyboard.cpp | 47 ------- source/src/vm/pc8201/keyboard.h | 4 +- source/src/vm/pc8201/lcd.cpp | 63 ++------- source/src/vm/pc8201/lcd.h | 4 +- source/src/vm/pc8201/memory.cpp | 68 ++-------- source/src/vm/pc8201/memory.h | 14 +- source/src/vm/pc8201/pc8201.cpp | 84 ++++-------- source/src/vm/pc8201/pc8201.h | 8 +- 97 files changed, 450 insertions(+), 3256 deletions(-) diff --git a/source/src/vm/mz3500/keyboard.cpp b/source/src/vm/mz3500/keyboard.cpp index f75ec30b3..eabcaa5c9 100644 --- a/source/src/vm/mz3500/keyboard.cpp +++ b/source/src/vm/mz3500/keyboard.cpp @@ -462,79 +462,6 @@ void KEYBOARD::set_dk(bool value) #define STATE_VERSION 3 -#include "../../statesub.h" - -void KEYBOARD::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_FIFO(key_buf); - DECL_STATE_ENTRY_INT32(phase); - DECL_STATE_ENTRY_UINT16(send_data); - DECL_STATE_ENTRY_UINT32(stc_clock); - DECL_STATE_ENTRY_UINT8(recv_data); - DECL_STATE_ENTRY_BOOL(recv_ok); - DECL_STATE_ENTRY_BOOL(stc); - DECL_STATE_ENTRY_BOOL(dc); - DECL_STATE_ENTRY_BOOL(caps); - DECL_STATE_ENTRY_BOOL(kana); - DECL_STATE_ENTRY_BOOL(pro_mode); - - 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); - -// key_buf->save_state((void *)state_fio); -// state_fio->FputInt32(phase); -// state_fio->FputUint16(send_data); -// state_fio->FputUint32(stc_clock); -// state_fio->FputUint8(recv_data); -// state_fio->FputBool(recv_ok); -// state_fio->FputBool(stc); -// state_fio->FputBool(dc); -// state_fio->FputBool(caps); -// state_fio->FputBool(kana); -// state_fio->FputBool(pro_mode); -} - -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; -// } -// if(!key_buf->load_state((void *)state_fio)) { -// return false; -// } -// phase = state_fio->FgetInt32(); -// send_data = state_fio->FgetUint16(); -// stc_clock = state_fio->FgetUint32(); -// recv_data = state_fio->FgetUint8(); -// recv_ok = state_fio->FgetBool(); -// stc = state_fio->FgetBool(); -// dc = state_fio->FgetBool(); -// caps = state_fio->FgetBool(); -// kana = state_fio->FgetBool(); -// pro_mode = state_fio->FgetBool(); - return true; -} - bool KEYBOARD::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/mz3500/keyboard.h b/source/src/vm/mz3500/keyboard.h index 1db617707..31c677037 100644 --- a/source/src/vm/mz3500/keyboard.h +++ b/source/src/vm/mz3500/keyboard.h @@ -54,9 +54,7 @@ public: void write_signal(int id, uint32_t data, uint32_t mask); void event_callback(int event_id, int err); 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); // unique functions void set_context_subcpu(DEVICE* device) diff --git a/source/src/vm/mz3500/main.cpp b/source/src/vm/mz3500/main.cpp index 23c610eae..88233d60c 100644 --- a/source/src/vm/mz3500/main.cpp +++ b/source/src/vm/mz3500/main.cpp @@ -391,119 +391,6 @@ void MAIN::update_bank() #define STATE_VERSION 2 -#include "../../statesub.h" - -void MAIN::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); - DECL_STATE_ENTRY_1D_ARRAY(common, sizeof(common)); - DECL_STATE_ENTRY_UINT8(ma); - DECL_STATE_ENTRY_UINT8(ms); - DECL_STATE_ENTRY_UINT8(mo); - DECL_STATE_ENTRY_BOOL(me1); - DECL_STATE_ENTRY_BOOL(me2); - DECL_STATE_ENTRY_UINT8(srqb); - DECL_STATE_ENTRY_UINT8(sres); - DECL_STATE_ENTRY_BOOL(sack); - DECL_STATE_ENTRY_BOOL(srdy); - DECL_STATE_ENTRY_BOOL(intfd); - DECL_STATE_ENTRY_BOOL(int0); - DECL_STATE_ENTRY_BOOL(int1); - DECL_STATE_ENTRY_BOOL(int2); - DECL_STATE_ENTRY_BOOL(int3); - DECL_STATE_ENTRY_BOOL(int4); - DECL_STATE_ENTRY_BOOL(me); - DECL_STATE_ENTRY_BOOL(e1); - DECL_STATE_ENTRY_UINT8(inp); - DECL_STATE_ENTRY_BOOL(motor); - DECL_STATE_ENTRY_BOOL(drq); - DECL_STATE_ENTRY_BOOL(index); - DECL_STATE_ENTRY_BOOL(crt_400line); - - leave_decl_state(); -} - -void MAIN::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(common, sizeof(common), 1); -// state_fio->FputUint8(ma); -// state_fio->FputUint8(ms); -// state_fio->FputUint8(mo); -// state_fio->FputBool(me1); -// state_fio->FputBool(me2); -// state_fio->FputUint8(srqb); -// state_fio->FputUint8(sres); -// state_fio->FputBool(sack); -// state_fio->FputBool(srdy); -// state_fio->FputBool(intfd); -// state_fio->FputBool(int0); -// state_fio->FputBool(int1); -// state_fio->FputBool(int2); -// state_fio->FputBool(int3); -// state_fio->FputBool(int4); -// state_fio->FputBool(me); -// state_fio->FputBool(e1); -// state_fio->FputUint8(inp); -// state_fio->FputBool(motor); -// state_fio->FputBool(drq); -// state_fio->FputBool(index); -// state_fio->FputBool(crt_400line); -} - -bool MAIN::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(common, sizeof(common), 1); -// ma = state_fio->FgetUint8(); -// ms = state_fio->FgetUint8(); -// mo = state_fio->FgetUint8(); -// me1 = state_fio->FgetBool(); -// me2 = state_fio->FgetBool(); -// srqb = state_fio->FgetUint8(); -// sres = state_fio->FgetUint8(); -// sack = state_fio->FgetBool(); -// srdy = state_fio->FgetBool(); -// intfd = state_fio->FgetBool(); -// int0 = state_fio->FgetBool(); -// int1 = state_fio->FgetBool(); -// int2 = state_fio->FgetBool(); -// int3 = state_fio->FgetBool(); -// int4 = state_fio->FgetBool(); -// me = state_fio->FgetBool(); -// e1 = state_fio->FgetBool(); -// inp = state_fio->FgetUint8(); -// motor = state_fio->FgetBool(); -// drq = state_fio->FgetBool(); -// index = state_fio->FgetBool(); -// crt_400line = state_fio->FgetBool(); - - // post process - update_bank(); - return true; -} - bool MAIN::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/mz3500/main.h b/source/src/vm/mz3500/main.h index b9abadbfb..8d1314d52 100644 --- a/source/src/vm/mz3500/main.h +++ b/source/src/vm/mz3500/main.h @@ -73,9 +73,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_maincpu(DEVICE* device) diff --git a/source/src/vm/mz3500/mz3500.cpp b/source/src/vm/mz3500/mz3500.cpp index eab892d21..dea738d94 100644 --- a/source/src/vm/mz3500/mz3500.cpp +++ b/source/src/vm/mz3500/mz3500.cpp @@ -249,7 +249,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) for(DEVICE* device = first_device; device; device = device->next_device) { device->initialize(); } - decl_state(); for(int i = 0; i < 4; i++) { fdc->set_drive_type(i, DRIVE_TYPE_2D); } @@ -462,74 +461,38 @@ void VM::update_config() #define STATE_VERSION 5 -#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::MZ_3500_HEAD")), csp_logger); - DECL_STATE_ENTRY_UINT8(halt); - - 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->FputUint8(halt); -} - -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; - } - } - //halt = state_fio->FgetUint8(); - 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->StateUint8(halt); return true; } diff --git a/source/src/vm/mz3500/mz3500.h b/source/src/vm/mz3500/mz3500.h index f898b6dac..bdaaa80f8 100644 --- a/source/src/vm/mz3500/mz3500.h +++ b/source/src/vm/mz3500/mz3500.h @@ -172,9 +172,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/mz3500/sub.cpp b/source/src/vm/mz3500/sub.cpp index cdc2745f4..fd7de6e75 100644 --- a/source/src/vm/mz3500/sub.cpp +++ b/source/src/vm/mz3500/sub.cpp @@ -569,62 +569,6 @@ void SUB::draw_gfx_200line_8bit() #define STATE_VERSION 3 -#include "../../statesub.h" - -void SUB::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); - DECL_STATE_ENTRY_1D_ARRAY(vram_chr, sizeof(vram_chr)); - DECL_STATE_ENTRY_1D_ARRAY(vram_gfx, sizeof(vram_gfx)); - DECL_STATE_ENTRY_1D_ARRAY(disp, sizeof(disp)); - DECL_STATE_ENTRY_INT32(cblink); - DECL_STATE_ENTRY_BOOL(crt_400line); - - leave_decl_state(); -} - -void SUB::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_chr, sizeof(vram_chr), 1); -// state_fio->Fwrite(vram_gfx, sizeof(vram_gfx), 1); -// state_fio->Fwrite(disp, sizeof(disp), 1); -// state_fio->FputInt32(cblink); -// state_fio->FputBool(crt_400line); -} - -bool SUB::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_chr, sizeof(vram_chr), 1); -// state_fio->Fread(vram_gfx, sizeof(vram_gfx), 1); -// state_fio->Fread(disp, sizeof(disp), 1); -// cblink = state_fio->FgetInt32(); -// crt_400line = state_fio->FgetBool(); - return true; -} - bool SUB::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/mz3500/sub.h b/source/src/vm/mz3500/sub.h index 0f53606b5..92bb0d2f5 100644 --- a/source/src/vm/mz3500/sub.h +++ b/source/src/vm/mz3500/sub.h @@ -65,9 +65,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); // unique functions void set_context_main(DEVICE* device) diff --git a/source/src/vm/mz5500/display.cpp b/source/src/vm/mz5500/display.cpp index ca3bca178..5a0a84668 100644 --- a/source/src/vm/mz5500/display.cpp +++ b/source/src/vm/mz5500/display.cpp @@ -500,80 +500,6 @@ void DISPLAY::update_palette() #define STATE_VERSION 1 -#include "../../statesub.h" - -void DISPLAY::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_SCRNTYPE_T_1D_ARRAY(palette_pc, sizeof(palette_pc) / sizeof(scrntype_t)); - DECL_STATE_ENTRY_1D_ARRAY(palette, sizeof(palette)); - DECL_STATE_ENTRY_1D_ARRAY(back, sizeof(back)); - DECL_STATE_ENTRY_1D_ARRAY(reverse, sizeof(reverse)); - DECL_STATE_ENTRY_UINT8(rno); - DECL_STATE_ENTRY_1D_ARRAY(wregs, sizeof(wregs)); - DECL_STATE_ENTRY_1D_ARRAY(pri, sizeof(pri) / sizeof(int)); - DECL_STATE_ENTRY_1D_ARRAY(vma, sizeof(vma) / sizeof(int)); - DECL_STATE_ENTRY_1D_ARRAY(vds, sizeof(vds)); - DECL_STATE_ENTRY_UINT8(mode_r); - DECL_STATE_ENTRY_UINT8(mode_c); - DECL_STATE_ENTRY_UINT8(mode_p); - - leave_decl_state(); -} - -void DISPLAY::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(palette_pc, sizeof(palette_pc), 1); -// state_fio->Fwrite(palette, sizeof(palette), 1); -// state_fio->Fwrite(back, sizeof(back), 1); -// state_fio->Fwrite(reverse, sizeof(reverse), 1); -// state_fio->FputUint8(rno); -// state_fio->Fwrite(wregs, sizeof(wregs), 1); -// state_fio->Fwrite(pri, sizeof(pri), 1); -// state_fio->Fwrite(vma, sizeof(vma), 1); -// state_fio->Fwrite(vds, sizeof(vds), 1); -// state_fio->FputUint8(mode_r); -// state_fio->FputUint8(mode_c); -// state_fio->FputUint8(mode_p); -} - -bool DISPLAY::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(palette_pc, sizeof(palette_pc), 1); -// state_fio->Fread(palette, sizeof(palette), 1); -// state_fio->Fread(back, sizeof(back), 1); -// state_fio->Fread(reverse, sizeof(reverse), 1); -// rno = state_fio->FgetUint8(); -// state_fio->Fread(wregs, sizeof(wregs), 1); -// state_fio->Fread(pri, sizeof(pri), 1); -// state_fio->Fread(vma, sizeof(vma), 1); -// state_fio->Fread(vds, sizeof(vds), 1); -// mode_r = state_fio->FgetUint8(); -// mode_c = state_fio->FgetUint8(); -// mode_p = state_fio->FgetUint8(); - return true; -} - bool DISPLAY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { @@ -582,14 +508,37 @@ bool DISPLAY::process_state(FILEIO* state_fio, bool loading) if(!state_fio->StateCheckInt32(this_device_id)) { return false; } - state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1); + //state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1); + for(int i = 0; i < (sizeof(palette) / sizeof(scrntype_t)); i++) { + if(loading) { + uint8_t r, g, b; + r = state_fio->FgetUint8(); + g = state_fio->FgetUint8(); + b = state_fio->FgetUint8(); + palette[i] = RGB_COLOR(r, g, b); + } else { + uint8_t r, g, b; + r = R_OF_COLOR(palette[i]); + g = G_OF_COLOR(palette[i]); + b = B_OF_COLOR(palette[i]); + state_fio->FputUint8(r); + state_fio->FputUint8(g); + state_fio->FputUint8(b); + } + } state_fio->StateBuffer(palette, sizeof(palette), 1); state_fio->StateBuffer(back, sizeof(back), 1); state_fio->StateBuffer(reverse, sizeof(reverse), 1); state_fio->StateUint8(rno); state_fio->StateBuffer(wregs, sizeof(wregs), 1); - state_fio->StateBuffer(pri, sizeof(pri), 1); - state_fio->StateBuffer(vma, sizeof(vma), 1); + //state_fio->StateBuffer(pri, sizeof(pri), 1); + for(int i = 0; i < (sizeof(pri) / sizeof(int)); i++) { + state_fio->StateInt32(pri[i]); + } + //state_fio->StateBuffer(vma, sizeof(vma), 1); + for(int i = 0; i < (sizeof(vma) / sizeof(int)); i++) { + state_fio->StateInt32(vma[i]); + } state_fio->StateBuffer(vds, sizeof(vds), 1); state_fio->StateUint8(mode_r); state_fio->StateUint8(mode_c); diff --git a/source/src/vm/mz5500/display.h b/source/src/vm/mz5500/display.h index 3287fcead..65d76b3a5 100644 --- a/source/src/vm/mz5500/display.h +++ b/source/src/vm/mz5500/display.h @@ -53,9 +53,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); // unique functions void set_vram_ptr(uint8_t* ptr) diff --git a/source/src/vm/mz5500/keyboard.cpp b/source/src/vm/mz5500/keyboard.cpp index 691d1c8f7..312a96f76 100644 --- a/source/src/vm/mz5500/keyboard.cpp +++ b/source/src/vm/mz5500/keyboard.cpp @@ -466,87 +466,6 @@ void KEYBOARD::process(int cmd) #define STATE_VERSION 1 -#include "../../statesub.h" - -void KEYBOARD::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_FIFO(key_buf); - DECL_STATE_ENTRY_FIFO(rsp_buf); - DECL_STATE_ENTRY_BOOL(caps); - DECL_STATE_ENTRY_BOOL(kana); - DECL_STATE_ENTRY_BOOL(graph); - DECL_STATE_ENTRY_INT32(dk); - DECL_STATE_ENTRY_INT32(srk); - DECL_STATE_ENTRY_INT32(dc); - DECL_STATE_ENTRY_INT32(stc); - DECL_STATE_ENTRY_INT32(send); - DECL_STATE_ENTRY_INT32(recv); - DECL_STATE_ENTRY_INT32(phase); - DECL_STATE_ENTRY_INT32(timeout); - - 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); - -// key_buf->save_state((void *)state_fio); -// rsp_buf->save_state((void *)state_fio); -// state_fio->FputBool(caps); -// state_fio->FputBool(kana); -// state_fio->FputBool(graph); -// state_fio->FputInt32(dk); -// state_fio->FputInt32(srk); -// state_fio->FputInt32(dc); -// state_fio->FputInt32(stc); -// state_fio->FputInt32(send); -// state_fio->FputInt32(recv); -// state_fio->FputInt32(phase); -// state_fio->FputInt32(timeout); -} - -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; -// } -// if(!key_buf->load_state((void *)state_fio)) { -// return false; -// } -// if(!rsp_buf->load_state((void *)state_fio)) { -// return false; -// } -// caps = state_fio->FgetBool(); -// kana = state_fio->FgetBool(); -// graph = state_fio->FgetBool(); -// dk = state_fio->FgetInt32(); -// srk = state_fio->FgetInt32(); -// dc = state_fio->FgetInt32(); -// stc = state_fio->FgetInt32(); -// send = state_fio->FgetInt32(); -// recv = state_fio->FgetInt32(); -// phase = state_fio->FgetInt32(); -// timeout = state_fio->FgetInt32(); - return true; -} - bool KEYBOARD::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/mz5500/keyboard.h b/source/src/vm/mz5500/keyboard.h index 21883ea63..4233cef15 100644 --- a/source/src/vm/mz5500/keyboard.h +++ b/source/src/vm/mz5500/keyboard.h @@ -48,9 +48,7 @@ public: void reset(); void write_signal(int id, uint32_t data, uint32_t mask); 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); // unique functions void set_context_pio(DEVICE* device) diff --git a/source/src/vm/mz5500/memory.cpp b/source/src/vm/mz5500/memory.cpp index 5741a537d..812364991 100644 --- a/source/src/vm/mz5500/memory.cpp +++ b/source/src/vm/mz5500/memory.cpp @@ -7,7 +7,7 @@ [ memory ] */ -#include "memory.h" +#include "./memory.h" #define SET_BANK(s, e, w, r) { \ int sb = (s) >> 14, eb = (e) >> 14; \ @@ -25,7 +25,7 @@ } \ } -void MEMORY::initialize() +void MZ5500_MEMORY::initialize() { // init memory memset(ram, 0, sizeof(ram)); @@ -84,14 +84,14 @@ void MEMORY::initialize() haddr = 0; } -void MEMORY::reset() +void MZ5500_MEMORY::reset() { bank1 = 0xe0; bank2 = 0; update_bank(); } -void MEMORY::write_data8(uint32_t addr, uint32_t data) +void MZ5500_MEMORY::write_data8(uint32_t addr, uint32_t data) { addr &= 0xfffff; // if((0x80000 <= addr && addr < 0xa0000) || (0xf0000 <= addr && addr < 0xfc000)) { @@ -100,7 +100,7 @@ void MEMORY::write_data8(uint32_t addr, uint32_t data) wbank[addr >> 14][addr & 0x3fff] = data; } -uint32_t MEMORY::read_data8(uint32_t addr) +uint32_t MZ5500_MEMORY::read_data8(uint32_t addr) { addr &= 0xfffff; // if((0x80000 <= addr && addr < 0xa0000) || (0xf0000 <= addr && addr < 0xfc000)) { @@ -109,7 +109,7 @@ uint32_t MEMORY::read_data8(uint32_t addr) return rbank[addr >> 14][addr & 0x3fff]; } -void MEMORY::write_dma_data8(uint32_t addr, uint32_t data) +void MZ5500_MEMORY::write_dma_data8(uint32_t addr, uint32_t data) { addr = (addr & 0xffff) | haddr; // if((0x80000 <= addr && addr < 0xa0000) || (0xf0000 <= addr && addr < 0xfc000)) { @@ -118,7 +118,7 @@ void MEMORY::write_dma_data8(uint32_t addr, uint32_t data) wbank[addr >> 14][addr & 0x3fff] = data; } -uint32_t MEMORY::read_dma_data8(uint32_t addr) +uint32_t MZ5500_MEMORY::read_dma_data8(uint32_t addr) { addr = (addr & 0xffff) | haddr; // if((0x80000 <= addr && addr < 0xa0000) || (0xf0000 <= addr && addr < 0xfc000)) { @@ -127,7 +127,7 @@ uint32_t MEMORY::read_dma_data8(uint32_t addr) return rbank[addr >> 14][addr & 0x3fff]; } -void MEMORY::write_io8(uint32_t addr, uint32_t data) +void MZ5500_MEMORY::write_io8(uint32_t addr, uint32_t data) { switch(addr & 0xff) { case 0x50: @@ -145,12 +145,12 @@ void MEMORY::write_io8(uint32_t addr, uint32_t data) } } -uint32_t MEMORY::read_io8(uint32_t addr) +uint32_t MZ5500_MEMORY::read_io8(uint32_t addr) { return 0xf0 | bank2; // ??? } -void MEMORY::write_signal(int id, uint32_t data, uint32_t mask) +void MZ5500_MEMORY::write_signal(int id, uint32_t data, uint32_t mask) { if(bank1 != data) { bank1 = data; @@ -158,7 +158,7 @@ void MEMORY::write_signal(int id, uint32_t data, uint32_t mask) } } -void MEMORY::update_bank() +void MZ5500_MEMORY::update_bank() { switch(bank1 & 0xe0) { case 0xe0: @@ -190,72 +190,7 @@ void MEMORY::update_bank() #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)); -#if defined(_MZ6500) || defined(_MZ6550) - DECL_STATE_ENTRY_1D_ARRAY(mz1r32, sizeof(mz1r32)); -#endif - DECL_STATE_ENTRY_UINT8(bank1); - DECL_STATE_ENTRY_UINT8(bank2); - DECL_STATE_ENTRY_UINT32(haddr); - - 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); -//#if defined(_MZ6500) || defined(_MZ6550) -// state_fio->Fwrite(mz1r32, sizeof(mz1r32), 1); -//#endif -// state_fio->FputUint8(bank1); -// state_fio->FputUint8(bank2); -// state_fio->FputUint32(haddr); -} - -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); -//#if defined(_MZ6500) || defined(_MZ6550) -// state_fio->Fread(mz1r32, sizeof(mz1r32), 1); -//#endif -// bank1 = state_fio->FgetUint8(); -// bank2 = state_fio->FgetUint8(); -// haddr = state_fio->FgetUint32(); - - // post process - update_bank(); - return true; -} - -bool MEMORY::process_state(FILEIO* state_fio, bool loading) +bool MZ5500_MEMORY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { return false; diff --git a/source/src/vm/mz5500/memory.h b/source/src/vm/mz5500/memory.h index b16fa7219..779ddd032 100644 --- a/source/src/vm/mz5500/memory.h +++ b/source/src/vm/mz5500/memory.h @@ -7,8 +7,8 @@ [ memory ] */ -#ifndef _MEMORY_H_ -#define _MEMORY_H_ +#ifndef _MZ5500_MEMORY_H_ +#define _MZ5500_MEMORY_H_ #include "../vm.h" #include "../../emu.h" @@ -16,7 +16,7 @@ #define SIG_MEMORY_BANK 0 -class MEMORY : public DEVICE +class MZ5500_MEMORY : public DEVICE { private: DEVICE* d_cpu; @@ -50,11 +50,11 @@ private: void update_bank(); public: - MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) + MZ5500_MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) { set_device_name(_T("Memory Bus")); } - ~MEMORY() {} + ~MZ5500_MEMORY() {} // common functions void initialize(); @@ -66,9 +66,7 @@ public: void write_signal(int id, uint32_t data, uint32_t mask); 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/mz5500/mz5500.cpp b/source/src/vm/mz5500/mz5500.cpp index 19584b41d..3f7e3e717 100644 --- a/source/src/vm/mz5500/mz5500.cpp +++ b/source/src/vm/mz5500/mz5500.cpp @@ -41,7 +41,7 @@ #include "display.h" #include "keyboard.h" -#include "memory.h" +#include "./memory.h" #include "sysport.h" // ---------------------------------------------------------------------------- @@ -107,7 +107,7 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) display = new DISPLAY(this, emu); keyboard = new KEYBOARD(this, emu); - memory = new MEMORY(this, emu); + memory = new MZ5500_MEMORY(this, emu); sysport = new SYSPORT(this, emu); // set contexts @@ -237,7 +237,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) for(DEVICE* device = first_device; device; device = device->next_device) { device->initialize(); } - decl_state(); for(int i = 0; i < 4; i++) { #if defined(_MZ6500) || defined(_MZ6550) fdc->set_drive_type(i, DRIVE_TYPE_2HD); @@ -431,78 +430,36 @@ void VM::update_config() #define STATE_VERSION 5 -#include "../../statesub.h" -#include "../../qt/gui/csp_logger.h" -extern CSP_Logger DLL_PREFIX_I *csp_logger; - -void VM::decl_state(void) -{ -#if defined(_MZ5500) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::MZ_5500_HEAD")), csp_logger); -#elif defined(_MZ6500) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::MZ_6500_HEAD")), csp_logger); -#elif defined(_MZ6550) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::MZ_6550_HEAD")), csp_logger); -#else - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::MZ_5500_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; + } + } return true; } diff --git a/source/src/vm/mz5500/mz5500.h b/source/src/vm/mz5500/mz5500.h index 9759207ff..b67aebd21 100644 --- a/source/src/vm/mz5500/mz5500.h +++ b/source/src/vm/mz5500/mz5500.h @@ -103,7 +103,7 @@ class Z80SIO; class DISPLAY; class KEYBOARD; -class MEMORY; +class MZ5500_MEMORY; class SYSPORT; class VM : public VM_TEMPLATE @@ -148,7 +148,7 @@ protected: DISPLAY* display; KEYBOARD* keyboard; - MEMORY* memory; + MZ5500_MEMORY* memory; SYSPORT* sysport; public: @@ -201,9 +201,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/mz5500/sysport.cpp b/source/src/vm/mz5500/sysport.cpp index 5aca551b4..96a9b49ce 100644 --- a/source/src/vm/mz5500/sysport.cpp +++ b/source/src/vm/mz5500/sysport.cpp @@ -68,51 +68,6 @@ void SYSPORT::event_frame() #define STATE_VERSION 1 -#include "../../statesub.h" - -void SYSPORT::decl_state() -{ - - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_INT32(rst); - DECL_STATE_ENTRY_INT32(highden); - - leave_decl_state(); -} - -void SYSPORT::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(rst); -// state_fio->FputInt32(highden); -} - -bool SYSPORT::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; -// } -// rst = state_fio->FgetInt32(); -// highden = state_fio->FgetInt32(); - return true; -} - bool SYSPORT::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/mz5500/sysport.h b/source/src/vm/mz5500/sysport.h index f363010b8..3bcc4be40 100644 --- a/source/src/vm/mz5500/sysport.h +++ b/source/src/vm/mz5500/sysport.h @@ -32,9 +32,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); // unique functions void set_context_fdc(DEVICE* device) diff --git a/source/src/vm/n5200/memory.cpp b/source/src/vm/n5200/memory.cpp index 6914ae1ec..40d602ad7 100644 --- a/source/src/vm/n5200/memory.cpp +++ b/source/src/vm/n5200/memory.cpp @@ -7,7 +7,7 @@ [ memory ] */ -#include "memory.h" +#include "./memory.h" #define SET_BANK(s, e, w, r) { \ int sb = (s) >> 11, eb = (e) >> 11; \ @@ -25,7 +25,7 @@ } \ } -void MEMORY::initialize() +void N5200_MEMORY::initialize() { // init memory memset(ram, 0, sizeof(ram)); @@ -48,7 +48,7 @@ void MEMORY::initialize() delete fio; } -void MEMORY::release() +void N5200_MEMORY::release() { // save ram image FILEIO* fio = new FILEIO(); @@ -59,7 +59,7 @@ void MEMORY::release() delete fio; } -void MEMORY::reset() +void N5200_MEMORY::reset() { SET_BANK(0x000000, 0xffffff, wdmy, rdmy); SET_BANK(0x000000, 0x0bffff, ram, ram); @@ -73,7 +73,7 @@ void MEMORY::reset() protect = true; } -void MEMORY::write_data8(uint32_t addr, uint32_t data) +void N5200_MEMORY::write_data8(uint32_t addr, uint32_t data) { addr &= 0xffffff; if(0xe7800 <= addr && addr < 0xf0000 && protect) { @@ -82,13 +82,13 @@ 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 N5200_MEMORY::read_data8(uint32_t addr) { addr &= 0xffffff; return rbank[addr >> 11][addr & 0x7ff]; } -void MEMORY::write_io8(uint32_t addr, uint32_t data) +void N5200_MEMORY::write_io8(uint32_t addr, uint32_t data) { switch(addr) { case 0x74: @@ -97,7 +97,7 @@ void MEMORY::write_io8(uint32_t addr, uint32_t data) } } -uint32_t MEMORY::read_io8(uint32_t addr) +uint32_t N5200_MEMORY::read_io8(uint32_t addr) { return 0xff; } diff --git a/source/src/vm/n5200/memory.h b/source/src/vm/n5200/memory.h index fbca66e56..1ecc5a69f 100644 --- a/source/src/vm/n5200/memory.h +++ b/source/src/vm/n5200/memory.h @@ -7,14 +7,14 @@ [ memory ] */ -#ifndef _MEMORY_H_ -#define _MEMORY_H_ +#ifndef _N5200_MEMORY_H_ +#define _N5200_MEMORY_H_ #include "../vm.h" #include "../../emu.h" #include "../device.h" -class MEMORY : public DEVICE +class N5200_MEMORY : public DEVICE { private: uint8_t* rbank[8192]; // 16MB / 2KB @@ -32,11 +32,11 @@ private: bool protect; public: - MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) + N5200_MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) { set_device_name(_T("Memory Bus")); } - ~MEMORY() {} + ~N5200_MEMORY() {} // common functions void initialize(); diff --git a/source/src/vm/n5200/n5200.cpp b/source/src/vm/n5200/n5200.cpp index 864cfe4bc..20fcba8d8 100644 --- a/source/src/vm/n5200/n5200.cpp +++ b/source/src/vm/n5200/n5200.cpp @@ -32,7 +32,7 @@ #include "display.h" #include "floppy.h" #include "keyboard.h" -#include "memory.h" +#include "./memory.h" #include "system.h" // ---------------------------------------------------------------------------- @@ -74,7 +74,7 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) display = new DISPLAY(this, emu); floppy = new FLOPPY(this, emu); keyboard = new KEYBOARD(this, emu); - memory = new MEMORY(this, emu); + memory = new N5200_MEMORY(this, emu); system = new SYSTEM(this, emu); // set contexts @@ -431,41 +431,33 @@ 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; } -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 " - int len = strlen(name); - - if(!state_fio->StateCheckInt32(len)) { - return false; - } - if(!state_fio->StateCheckBuffer(name, len, 1)) { - return false; - } - if(!device->process_state(state_fio, loading)) { - return false; - } - } - return true; -} diff --git a/source/src/vm/n5200/n5200.h b/source/src/vm/n5200/n5200.h index f53593b38..0a9cfb20f 100644 --- a/source/src/vm/n5200/n5200.h +++ b/source/src/vm/n5200/n5200.h @@ -68,7 +68,7 @@ class UPD765A; class DISPLAY; class FLOPPY; class KEYBOARD; -class MEMORY; +class N5200_MEMORY; class SYSTEM; class VM : public VM_TEMPLATE @@ -97,7 +97,7 @@ protected: DISPLAY* display; FLOPPY* floppy; KEYBOARD* keyboard; - MEMORY* memory; + N5200_MEMORY* memory; SYSTEM* system; public: diff --git a/source/src/vm/pasopia/display.cpp b/source/src/vm/pasopia/display.cpp index 2f4dd474d..e2d3fc23d 100644 --- a/source/src/vm/pasopia/display.cpp +++ b/source/src/vm/pasopia/display.cpp @@ -631,53 +631,6 @@ void DISPLAY::draw_screen15_wide(uint16_t src) #define STATE_VERSION 1 -#include "../../statesub.h" - -void DISPLAY::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT8(mode); - DECL_STATE_ENTRY_UINT16(cursor); - DECL_STATE_ENTRY_UINT16(cblink); - - leave_decl_state(); -} - -void DISPLAY::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(mode); -// state_fio->FputUint16(cursor); -// state_fio->FputUint16(cblink); -} - -bool DISPLAY::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; -// } -// mode = state_fio->FgetUint8(); -// cursor = state_fio->FgetUint16(); -// cblink = state_fio->FgetUint16(); - return true; -} - bool DISPLAY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia/display.h b/source/src/vm/pasopia/display.h index 51a78ce31..346ea70d3 100644 --- a/source/src/vm/pasopia/display.h +++ b/source/src/vm/pasopia/display.h @@ -52,9 +52,7 @@ public: void write_io8(uint32_t addr, uint32_t data); void write_signal(int id, uint32_t data, uint32_t mask); 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); // unique functions void set_context_crtc(DEVICE* device) diff --git a/source/src/vm/pasopia/floppy.cpp b/source/src/vm/pasopia/floppy.cpp index cf4bd5482..d6a875bd2 100644 --- a/source/src/vm/pasopia/floppy.cpp +++ b/source/src/vm/pasopia/floppy.cpp @@ -73,50 +73,6 @@ void FLOPPY::write_signal(int id, uint32_t data, uint32_t mask) #define STATE_VERSION 1 -#include "../../statesub.h" - -void FLOPPY::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_BOOL(intr); - DECL_STATE_ENTRY_BOOL(supported); - - leave_decl_state(); -} - -void FLOPPY::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->FputBool(intr); -// state_fio->FputBool(supported); -} - -bool FLOPPY::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; -// } -// intr = state_fio->FgetBool(); -// supported = state_fio->FgetBool(); - return true; -} - bool FLOPPY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia/floppy.h b/source/src/vm/pasopia/floppy.h index 7aebf184b..45a46e50f 100644 --- a/source/src/vm/pasopia/floppy.h +++ b/source/src/vm/pasopia/floppy.h @@ -34,9 +34,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_fdc(DEVICE* device) diff --git a/source/src/vm/pasopia/kanjipac2.cpp b/source/src/vm/pasopia/kanjipac2.cpp index 119d33f61..47927ee0a 100644 --- a/source/src/vm/pasopia/kanjipac2.cpp +++ b/source/src/vm/pasopia/kanjipac2.cpp @@ -44,41 +44,6 @@ uint32_t KANJIPAC2::read_io8(uint32_t addr) #define STATE_VERSION 1 -#include "../../statesub.h" - -void KANJIPAC2::decl_state() -{ - state_entry = new csp_state_utils(STATE_VERSION, 0, (const _TCHAR *)_T("PAC2SLOT::KANJIPAC2"), NULL); - - DECL_STATE_ENTRY_UINT32(ptr); - - //leave_decl_state(); -} - -void KANJIPAC2::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); - -// state_fio->FputUint32(ptr); -} - -bool KANJIPAC2::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; -// } -// ptr = state_fio->FgetUint32(); - return true; -} - bool KANJIPAC2::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia/kanjipac2.h b/source/src/vm/pasopia/kanjipac2.h index a03ac7c67..6b9741e99 100644 --- a/source/src/vm/pasopia/kanjipac2.h +++ b/source/src/vm/pasopia/kanjipac2.h @@ -31,9 +31,7 @@ public: void initialize(int id); 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/pasopia/keyboard.cpp b/source/src/vm/pasopia/keyboard.cpp index 256a7c7a3..0a38215a9 100644 --- a/source/src/vm/pasopia/keyboard.cpp +++ b/source/src/vm/pasopia/keyboard.cpp @@ -74,45 +74,6 @@ void KEYBOARD::create_key() #define STATE_VERSION 1 -#include "../../statesub.h" - -void KEYBOARD::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT8(sel); - - 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); - -// state_fio->FputUint8(sel); -} - -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; -// } -// sel = state_fio->FgetUint8(); - return true; -} - bool KEYBOARD::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia/keyboard.h b/source/src/vm/pasopia/keyboard.h index 1f4943ec1..1076d596d 100644 --- a/source/src/vm/pasopia/keyboard.h +++ b/source/src/vm/pasopia/keyboard.h @@ -36,9 +36,7 @@ public: void initialize(); void write_signal(int id, uint32_t data, uint32_t mask); 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); // unique function void set_context_pio(DEVICE* device) diff --git a/source/src/vm/pasopia/memory.cpp b/source/src/vm/pasopia/memory.cpp index af1c862ad..7be0c14df 100644 --- a/source/src/vm/pasopia/memory.cpp +++ b/source/src/vm/pasopia/memory.cpp @@ -7,7 +7,7 @@ [ memory ] */ -#include "memory.h" +#include "./memory.h" #include "../i8255.h" #define SET_BANK(s, e, w, r) { \ @@ -26,7 +26,7 @@ } \ } -void MEMORY::initialize() +void PASOPIA_MEMORY::initialize() { // load ipl memset(rdmy, 0xff, sizeof(rdmy)); @@ -39,7 +39,7 @@ void MEMORY::initialize() vram_data = mem_map = 0; } -void MEMORY::load_ipl() +void PASOPIA_MEMORY::load_ipl() { // load ipl memset(rom, 0xff, sizeof(rom)); @@ -76,24 +76,24 @@ void MEMORY::load_ipl() } -void MEMORY::reset() +void PASOPIA_MEMORY::reset() { memset(vram, 0, sizeof(vram)); } -void MEMORY::write_data8(uint32_t addr, uint32_t data) +void PASOPIA_MEMORY::write_data8(uint32_t addr, uint32_t data) { addr &= 0xffff; wbank[addr >> 12][addr & 0xfff] = data; } -uint32_t MEMORY::read_data8(uint32_t addr) +uint32_t PASOPIA_MEMORY::read_data8(uint32_t addr) { addr &= 0xffff; return rbank[addr >> 12][addr & 0xfff]; } -void MEMORY::write_io8(uint32_t addr, uint32_t data) +void PASOPIA_MEMORY::write_io8(uint32_t addr, uint32_t data) { mem_map = data; @@ -109,7 +109,7 @@ void MEMORY::write_io8(uint32_t addr, uint32_t data) d_pio2->write_signal(SIG_I8255_PORT_C, (mem_map & 2) ? 4 : 0, 4); } -void MEMORY::write_signal(int id, uint32_t data, uint32_t mask) +void PASOPIA_MEMORY::write_signal(int id, uint32_t data, uint32_t mask) { // vram control if(id == SIG_MEMORY_I8255_0_A) { @@ -141,68 +141,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(attr, sizeof(attr)); - DECL_STATE_ENTRY_UINT16(vram_ptr); - DECL_STATE_ENTRY_UINT8(vram_data); - DECL_STATE_ENTRY_UINT8(mem_map); - - 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(attr, sizeof(attr), 1); -// state_fio->FputUint16(vram_ptr); -// state_fio->FputUint8(vram_data); -// state_fio->FputUint8(mem_map); -} - -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(attr, sizeof(attr), 1); -// vram_ptr = state_fio->FgetUint16(); -// vram_data = state_fio->FgetUint8(); -// mem_map = state_fio->FgetUint8(); - - // post process - if(mem_map & 2) { - SET_BANK(0x0000, 0x7fff, ram, ram); - } else { - SET_BANK(0x0000, 0x7fff, ram, rom); - } - return true; -} - -bool MEMORY::process_state(FILEIO* state_fio, bool loading) +bool PASOPIA_MEMORY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { return false; diff --git a/source/src/vm/pasopia/memory.h b/source/src/vm/pasopia/memory.h index a73601686..610119d15 100644 --- a/source/src/vm/pasopia/memory.h +++ b/source/src/vm/pasopia/memory.h @@ -7,8 +7,8 @@ [ memory ] */ -#ifndef _MEMORY_H_ -#define _MEMORY_H_ +#ifndef _PASOPIA_MEMORY_H_ +#define _PASOPIA_MEMORY_H_ #include "../vm.h" #include "../../emu.h" @@ -18,7 +18,7 @@ #define SIG_MEMORY_I8255_0_B 1 #define SIG_MEMORY_I8255_1_C 2 -class MEMORY : public DEVICE +class PASOPIA_MEMORY : public DEVICE { private: DEVICE *d_pio0, *d_pio1, *d_pio2; @@ -35,11 +35,11 @@ private: uint8_t vram_data, mem_map; public: - MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) + PASOPIA_MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) { set_device_name(_T("Memory Bus")); } - ~MEMORY() {} + ~PASOPIA_MEMORY() {} // common functions void initialize(); @@ -48,9 +48,7 @@ public: uint32_t read_data8(uint32_t addr); void write_io8(uint32_t addr, uint32_t data); 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_pio0(DEVICE* device) diff --git a/source/src/vm/pasopia/pac2.cpp b/source/src/vm/pasopia/pac2.cpp index 78082d61f..10de0a455 100644 --- a/source/src/vm/pasopia/pac2.cpp +++ b/source/src/vm/pasopia/pac2.cpp @@ -77,63 +77,6 @@ void PAC2::open_rampac2(const _TCHAR* file_path) #define STATE_VERSION 1 -#include "../../statesub.h" - -void PAC2::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_INT32(device_type); - - if(rampac2 != NULL) { - rampac2->decl_state(); - } - if(kanji != NULL) { - kanji->decl_state(); - } - if(joy != NULL) { - joy->decl_state(); - } - if(dummy != NULL) { - dummy->decl_state(); - } - - - leave_decl_state(); -} - -void PAC2::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(device_type); - get_device()->save_state(state_fio); -} - -bool PAC2::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; -// } -// device_type = state_fio->FgetInt32(); - if(!get_device()->load_state(state_fio)) { - return false; - } - return true; -} - bool PAC2::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia/pac2.h b/source/src/vm/pasopia/pac2.h index 42dad2de5..c7e052dd6 100644 --- a/source/src/vm/pasopia/pac2.h +++ b/source/src/vm/pasopia/pac2.h @@ -44,9 +44,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 function void open_rampac2(const _TCHAR* file_path); diff --git a/source/src/vm/pasopia/pac2dev.h b/source/src/vm/pasopia/pac2dev.h index bdc8687fd..a08f00aa8 100644 --- a/source/src/vm/pasopia/pac2dev.h +++ b/source/src/vm/pasopia/pac2dev.h @@ -34,9 +34,7 @@ public: virtual void reset() {} virtual void write_io8(uint32_t addr, uint32_t data) {} virtual uint32_t read_io8(uint32_t addr) { return 0xff; } - virtual void decl_state() { state_entry = NULL; } - virtual void save_state(FILEIO* state_fio) { } - virtual bool load_state(FILEIO* state_fio) { return true; } + virtual bool process_state(FILEIO* state_fio, bool loading) { return true; } virtual void set_device_name(const _TCHAR* format, ...) { diff --git a/source/src/vm/pasopia/pasopia.cpp b/source/src/vm/pasopia/pasopia.cpp index 3b8e7b145..b3edcfb30 100644 --- a/source/src/vm/pasopia/pasopia.cpp +++ b/source/src/vm/pasopia/pasopia.cpp @@ -33,7 +33,7 @@ #include "floppy.h" #include "display.h" #include "keyboard.h" -#include "memory.h" +#include "./memory.h" #include "pac2.h" // ---------------------------------------------------------------------------- @@ -76,7 +76,7 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) floppy = new FLOPPY(this, emu); display = new DISPLAY(this, emu); key = new KEYBOARD(this, emu); - memory = new MEMORY(this, emu); + memory = new PASOPIA_MEMORY(this, emu); pac2 = new PAC2(this, emu); // set contexts event->set_context_cpu(cpu); @@ -189,7 +189,6 @@ pio2 20 8255 out cmt, sound for(DEVICE* device = first_device; device; device = device->next_device) { device->initialize(); } - decl_state(); for(int i = 0; i < 4; i++) { fdc->set_drive_type(i, DRIVE_TYPE_2D); } @@ -443,79 +442,38 @@ 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) -{ -#if defined(_LCD) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PASOPIA_WITH_LCD_HEAD")), csp_logger); -#else - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PASOPIA_HEAD")), csp_logger); -#endif - DECL_STATE_ENTRY_INT32(boot_mode); - 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->FputInt32(boot_mode); -} - -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)) { - //printf("LOAD ERROR at DEVID#%d\n", device->this_device_id); - return false; - } - } - //boot_mode = state_fio->FgetInt32(); - //printf("LOAD STATE OK\n"); - 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->StateInt32(boot_mode); return true; } diff --git a/source/src/vm/pasopia/pasopia.h b/source/src/vm/pasopia/pasopia.h index 94e1eb158..f31d6fa9d 100644 --- a/source/src/vm/pasopia/pasopia.h +++ b/source/src/vm/pasopia/pasopia.h @@ -103,7 +103,7 @@ class Z80PIO; class FLOPPY; class DISPLAY; class KEYBOARD; -class MEMORY; +class PASOPIA_MEMORY; class PAC2; class VM : public VM_TEMPLATE @@ -132,7 +132,7 @@ protected: FLOPPY* floppy; DISPLAY* display; KEYBOARD* key; - MEMORY* memory; + PASOPIA_MEMORY* memory; PAC2* pac2; int boot_mode; @@ -196,9 +196,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/pasopia/rampac2.cpp b/source/src/vm/pasopia/rampac2.cpp index a46ddbd7d..f09139073 100644 --- a/source/src/vm/pasopia/rampac2.cpp +++ b/source/src/vm/pasopia/rampac2.cpp @@ -96,51 +96,6 @@ void RAMPAC2::open_file(const _TCHAR* file_path) #define STATE_VERSION 1 -#include "../../statesub.h" - -void RAMPAC2::decl_state() -{ - state_entry = new csp_state_utils(STATE_VERSION, 1, (const _TCHAR *)_T("PAC2SLOT::RAMPAC2"), NULL); - - DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); - DECL_STATE_ENTRY_UINT32(ptr); - - DECL_STATE_ENTRY_BOOL(opened); - DECL_STATE_ENTRY_BOOL(modified); - //leave_decl_state(); -} - - -void RAMPAC2::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); - -// state_fio->Fwrite(ram, sizeof(ram), 1); -// state_fio->FputUint32(ptr); -// state_fio->FputBool(opened); -// state_fio->FputBool(modified); -} - -bool RAMPAC2::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; -// } -// state_fio->Fread(ram, sizeof(ram), 1); -// ptr = state_fio->FgetUint32(); -// opened = state_fio->FgetBool(); -// modified = state_fio->FgetBool(); - return true; -} - bool RAMPAC2::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia/rampac2.h b/source/src/vm/pasopia/rampac2.h index dfd2d5702..d26ed7e1d 100644 --- a/source/src/vm/pasopia/rampac2.h +++ b/source/src/vm/pasopia/rampac2.h @@ -37,9 +37,7 @@ public: void write_io8(uint32_t addr, uint32_t data); uint32_t read_io8(uint32_t addr); void open_file(const _TCHAR* file_path); - 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/pasopia7/display.cpp b/source/src/vm/pasopia7/display.cpp index 03db5fc2f..5889a5d81 100644 --- a/source/src/vm/pasopia7/display.cpp +++ b/source/src/vm/pasopia7/display.cpp @@ -757,63 +757,6 @@ void DISPLAY::draw_fine_lcd(uint16_t src) #define STATE_VERSION 1 -#include "../../statesub.h" - -void DISPLAY::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT8(mode); - DECL_STATE_ENTRY_UINT8(text_page); - DECL_STATE_ENTRY_UINT16(cursor); - DECL_STATE_ENTRY_UINT16(cblink); - DECL_STATE_ENTRY_UINT16(flash_cnt); - DECL_STATE_ENTRY_BOOL(blink); - DECL_STATE_ENTRY_BOOL(pal_dis); - - leave_decl_state(); -} - -void DISPLAY::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(mode); -// state_fio->FputUint8(text_page); -// state_fio->FputUint16(cursor); -// state_fio->FputUint16(cblink); -// state_fio->FputUint16(flash_cnt); -// state_fio->FputBool(blink); -// state_fio->FputBool(pal_dis); -} - -bool DISPLAY::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; -// } -// mode = state_fio->FgetUint8(); -// text_page = state_fio->FgetUint8(); -// cursor = state_fio->FgetUint16(); -// cblink = state_fio->FgetUint16(); -// flash_cnt = state_fio->FgetUint16(); -// blink = state_fio->FgetBool(); -// pal_dis = state_fio->FgetBool(); - return true; -} - bool DISPLAY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia7/display.h b/source/src/vm/pasopia7/display.h index 4a0f883c6..a6662695a 100644 --- a/source/src/vm/pasopia7/display.h +++ b/source/src/vm/pasopia7/display.h @@ -53,9 +53,7 @@ public: void initialize(); void write_signal(int id, uint32_t data, uint32_t mask); 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); // unique functions void set_vram_ptr(uint8_t* ptr) diff --git a/source/src/vm/pasopia7/floppy.cpp b/source/src/vm/pasopia7/floppy.cpp index 4aafcb18a..28fdf6f0b 100644 --- a/source/src/vm/pasopia7/floppy.cpp +++ b/source/src/vm/pasopia7/floppy.cpp @@ -56,45 +56,6 @@ void FLOPPY::write_signal(int id, uint32_t data, uint32_t mask) #define STATE_VERSION 1 -#include "../../statesub.h" - -void FLOPPY::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_BOOL(intr); - - leave_decl_state(); -} - -void FLOPPY::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->FputBool(intr); -} - -bool FLOPPY::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; -// } -// intr = state_fio->FgetBool(); - return true; -} - bool FLOPPY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia7/floppy.h b/source/src/vm/pasopia7/floppy.h index 2af396566..7e2ffbd24 100644 --- a/source/src/vm/pasopia7/floppy.h +++ b/source/src/vm/pasopia7/floppy.h @@ -34,9 +34,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 function void set_context_fdc(DEVICE* device) diff --git a/source/src/vm/pasopia7/iobus.cpp b/source/src/vm/pasopia7/iobus.cpp index 27263d30b..7a6e203e8 100644 --- a/source/src/vm/pasopia7/iobus.cpp +++ b/source/src/vm/pasopia7/iobus.cpp @@ -43,45 +43,6 @@ void IOBUS::write_signal(int id, uint32_t data, uint32_t mask) #define STATE_VERSION 1 -#include "../../statesub.h" - -void IOBUS::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_BOOL(mio); - - leave_decl_state(); -} - -void IOBUS::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->FputBool(mio); -} - -bool IOBUS::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; -// } -// mio = state_fio->FgetBool(); - return true; -} - bool IOBUS::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia7/iobus.h b/source/src/vm/pasopia7/iobus.h index 35192cf6b..ac8fd9729 100644 --- a/source/src/vm/pasopia7/iobus.h +++ b/source/src/vm/pasopia7/iobus.h @@ -35,9 +35,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_io(DEVICE* device) diff --git a/source/src/vm/pasopia7/iotrap.cpp b/source/src/vm/pasopia7/iotrap.cpp index 8205fca43..38c870f31 100644 --- a/source/src/vm/pasopia7/iotrap.cpp +++ b/source/src/vm/pasopia7/iotrap.cpp @@ -79,48 +79,6 @@ void IOTRAP::do_reset() #define STATE_VERSION 1 -#include "../../statesub.h" - -void IOTRAP::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_BOOL(nmi_mask); - DECL_STATE_ENTRY_BOOL(pasopia); - - leave_decl_state(); -} - -void IOTRAP::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->FputBool(nmi_mask); -// state_fio->FputBool(pasopia); -} - -bool IOTRAP::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; -// } -// nmi_mask = state_fio->FgetBool(); -// pasopia = state_fio->FgetBool(); - return true; -} - bool IOTRAP::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia7/iotrap.h b/source/src/vm/pasopia7/iotrap.h index 0b0ed436a..d927494e7 100644 --- a/source/src/vm/pasopia7/iotrap.h +++ b/source/src/vm/pasopia7/iotrap.h @@ -35,9 +35,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_cpu(DEVICE* device) diff --git a/source/src/vm/pasopia7/kanjipac2.cpp b/source/src/vm/pasopia7/kanjipac2.cpp index cc4275912..3d6ea5dc8 100644 --- a/source/src/vm/pasopia7/kanjipac2.cpp +++ b/source/src/vm/pasopia7/kanjipac2.cpp @@ -47,41 +47,6 @@ uint32_t KANJIPAC2::read_io8(uint32_t addr) #define STATE_VERSION 1 -#include "../../statesub.h" - -void KANJIPAC2::decl_state() -{ - state_entry = new csp_state_utils(STATE_VERSION, 0, (const _TCHAR *)_T("PAC2SLOT::KANJIPAC2"), NULL); - - DECL_STATE_ENTRY_UINT32(ptr); - - //leave_decl_state(); -} - -void KANJIPAC2::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); - -// state_fio->FputUint32(ptr); -} - -bool KANJIPAC2::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; -// } -// ptr = state_fio->FgetUint32(); - return true; -} - bool KANJIPAC2::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia7/kanjipac2.h b/source/src/vm/pasopia7/kanjipac2.h index 510f77d4b..95a9d6ca3 100644 --- a/source/src/vm/pasopia7/kanjipac2.h +++ b/source/src/vm/pasopia7/kanjipac2.h @@ -32,9 +32,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); }; #endif diff --git a/source/src/vm/pasopia7/keyboard.cpp b/source/src/vm/pasopia7/keyboard.cpp index 361b69cf6..9e3723254 100644 --- a/source/src/vm/pasopia7/keyboard.cpp +++ b/source/src/vm/pasopia7/keyboard.cpp @@ -79,45 +79,6 @@ void KEYBOARD::create_key() #define STATE_VERSION 1 -#include "../../statesub.h" - -void KEYBOARD::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT8(sel); - - 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); - - //state_fio->FputUint8(sel); -} - -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; - //} - //sel = state_fio->FgetUint8(); - return true; -} - bool KEYBOARD::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia7/keyboard.h b/source/src/vm/pasopia7/keyboard.h index d9fc5c888..9c5ab3055 100644 --- a/source/src/vm/pasopia7/keyboard.h +++ b/source/src/vm/pasopia7/keyboard.h @@ -36,9 +36,7 @@ public: void initialize(); void write_signal(int id, uint32_t data, uint32_t mask); 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); // unique function void set_context_pio(DEVICE* device) diff --git a/source/src/vm/pasopia7/memory.cpp b/source/src/vm/pasopia7/memory.cpp index c0f2aa9a9..312dc7544 100644 --- a/source/src/vm/pasopia7/memory.cpp +++ b/source/src/vm/pasopia7/memory.cpp @@ -7,7 +7,7 @@ [ memory ] */ -#include "memory.h" +#include "./memory.h" #include "iobus.h" #include "../i8255.h" @@ -27,7 +27,7 @@ } \ } -void MEMORY::initialize() +void PASOPIA7_MEMORY::initialize() { memset(bios, 0xff, sizeof(bios)); memset(basic, 0xff, sizeof(basic)); @@ -52,12 +52,12 @@ void MEMORY::initialize() vram_sel = pal_sel = attr_wrap = false; } -void MEMORY::reset() +void PASOPIA7_MEMORY::reset() { memset(vram, 0, sizeof(vram)); } -void MEMORY::write_data8(uint32_t addr, uint32_t data) +void PASOPIA7_MEMORY::write_data8(uint32_t addr, uint32_t data) { addr &= 0xffff; if(vram_sel && (addr & 0xc000) == 0x8000) { @@ -84,7 +84,7 @@ void MEMORY::write_data8(uint32_t addr, uint32_t data) wbank[addr >> 12][addr & 0xfff] = data; } -uint32_t MEMORY::read_data8(uint32_t addr) +uint32_t PASOPIA7_MEMORY::read_data8(uint32_t addr) { addr &= 0xffff; if(vram_sel && (addr & 0xc000) == 0x8000) { @@ -109,7 +109,7 @@ uint32_t MEMORY::read_data8(uint32_t addr) return rbank[addr >> 12][addr & 0xfff]; } -void MEMORY::write_io8(uint32_t addr, uint32_t data) +void PASOPIA7_MEMORY::write_io8(uint32_t addr, uint32_t data) { if(mem_map != (data & 7)) { mem_map = data & 7; @@ -124,7 +124,7 @@ void MEMORY::write_io8(uint32_t addr, uint32_t data) d_pio2->write_signal(SIG_I8255_PORT_C, data, 3); } -void MEMORY::write_signal(int id, uint32_t data, uint32_t mask) +void PASOPIA7_MEMORY::write_signal(int id, uint32_t data, uint32_t mask) { if(id == SIG_MEMORY_I8255_1_A) { plane = data; @@ -136,7 +136,7 @@ void MEMORY::write_signal(int id, uint32_t data, uint32_t mask) } } -void MEMORY::update_memory_map() +void PASOPIA7_MEMORY::update_memory_map() { if(mem_map == 0xff) { SET_BANK(0x0000, 0x3fff, wdmy, bios); @@ -167,76 +167,7 @@ void MEMORY::update_memory_map() #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(pal, sizeof(pal)); - DECL_STATE_ENTRY_UINT8(mem_map); - DECL_STATE_ENTRY_UINT8(plane); - DECL_STATE_ENTRY_UINT8(attr_data); - DECL_STATE_ENTRY_UINT8(attr_latch); - DECL_STATE_ENTRY_BOOL(vram_sel); - DECL_STATE_ENTRY_BOOL(pal_sel); - DECL_STATE_ENTRY_BOOL(attr_wrap); - - 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(pal, sizeof(pal), 1); -// state_fio->FputUint8(mem_map); -// state_fio->FputUint8(plane); -// state_fio->FputUint8(attr_data); -// state_fio->FputUint8(attr_latch); -// state_fio->FputBool(vram_sel); -// state_fio->FputBool(pal_sel); -// state_fio->FputBool(attr_wrap); -} - -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(pal, sizeof(pal), 1); -// mem_map = state_fio->FgetUint8(); -// plane = state_fio->FgetUint8(); -// attr_data = state_fio->FgetUint8(); -// attr_latch = state_fio->FgetUint8(); -// vram_sel = state_fio->FgetBool(); -// pal_sel = state_fio->FgetBool(); -// attr_wrap = state_fio->FgetBool(); - - // post process - update_memory_map(); - return true; -} - -bool MEMORY::process_state(FILEIO* state_fio, bool loading) +bool PASOPIA7_MEMORY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { return false; diff --git a/source/src/vm/pasopia7/memory.h b/source/src/vm/pasopia7/memory.h index 02bdc022d..04d3bf8f0 100644 --- a/source/src/vm/pasopia7/memory.h +++ b/source/src/vm/pasopia7/memory.h @@ -7,8 +7,8 @@ [ memory ] */ -#ifndef _MEMORY_H_ -#define _MEMORY_H_ +#ifndef _PASOPIA7_MEMORY_H_ +#define _PASOPIA7_MEMORY_H_ #include "../vm.h" #include "../../emu.h" @@ -18,7 +18,7 @@ #define SIG_MEMORY_I8255_1_B 1 #define SIG_MEMORY_I8255_1_C 2 -class MEMORY : public DEVICE +class PASOPIA7_MEMORY : public DEVICE { private: DEVICE *d_iobus, *d_pio0, *d_pio2; @@ -39,11 +39,11 @@ private: void update_memory_map(); public: - MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) + PASOPIA7_MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) { set_device_name(_T("Memory Bus")); } - ~MEMORY() {} + ~PASOPIA7_MEMORY() {} // common functions void initialize(); @@ -52,9 +52,7 @@ public: uint32_t read_data8(uint32_t addr); void write_io8(uint32_t addr, uint32_t data); 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_iobus(DEVICE* device) diff --git a/source/src/vm/pasopia7/pac2.cpp b/source/src/vm/pasopia7/pac2.cpp index d174081b6..0400d9575 100644 --- a/source/src/vm/pasopia7/pac2.cpp +++ b/source/src/vm/pasopia7/pac2.cpp @@ -90,71 +90,6 @@ void PAC2::open_rampac2(int drv, const _TCHAR* file_path) #define STATE_VERSION 1 -#include "../../statesub.h" - -void PAC2::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_INT32(sel); - - if(dummy != NULL) { - dummy->decl_state(); - } - if(kanji != NULL) { - kanji->decl_state(); - } - if(joy != NULL) { - joy->decl_state(); - } - for(int i = 0; i < 2; i++) { - if(rampac2[i] != NULL) { - rampac2[i]->decl_state(); - } - } - leave_decl_state(); -} - -void PAC2::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(sel); - rampac2[0]->save_state(state_fio); - rampac2[1]->save_state(state_fio); - kanji->save_state(state_fio); -} - -bool PAC2::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; -// } -// sel = state_fio->FgetInt32(); - if(!rampac2[0]->load_state(state_fio)) { - return false; - } - if(!rampac2[1]->load_state(state_fio)) { - return false; - } - if(!kanji->load_state(state_fio)) { - return false; - } - return true; -} - bool PAC2::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia7/pac2.h b/source/src/vm/pasopia7/pac2.h index d990a4a75..d300ea2a1 100644 --- a/source/src/vm/pasopia7/pac2.h +++ b/source/src/vm/pasopia7/pac2.h @@ -43,9 +43,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 function void open_rampac2(int drv, const _TCHAR* file_path); diff --git a/source/src/vm/pasopia7/pac2dev.h b/source/src/vm/pasopia7/pac2dev.h index d4c6ad68b..a0fb49ee9 100644 --- a/source/src/vm/pasopia7/pac2dev.h +++ b/source/src/vm/pasopia7/pac2dev.h @@ -33,9 +33,7 @@ public: virtual void reset() {} virtual void write_io8(uint32_t addr, uint32_t data) {} virtual uint32_t read_io8(uint32_t addr) { return 0xff; } - virtual void decl_state() { state_entry = NULL; } - virtual void save_state(FILEIO* state_fio) {} - virtual bool load_state(FILEIO* state_fio) { return true; } + virtual bool process_state(FILEIO* state_fio, bool loading) { return true; } virtual void set_device_name(const _TCHAR* format, ...) { diff --git a/source/src/vm/pasopia7/pasopia7.cpp b/source/src/vm/pasopia7/pasopia7.cpp index c824d5188..a2c988dae 100644 --- a/source/src/vm/pasopia7/pasopia7.cpp +++ b/source/src/vm/pasopia7/pasopia7.cpp @@ -36,7 +36,7 @@ #include "iobus.h" #include "iotrap.h" #include "keyboard.h" -#include "memory.h" +#include "./memory.h" #include "pac2.h" // ---------------------------------------------------------------------------- @@ -82,7 +82,7 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) iobus = new IOBUS(this, emu); iotrap = new IOTRAP(this, emu); key = new KEYBOARD(this, emu); - memory = new MEMORY(this, emu); + memory = new PASOPIA7_MEMORY(this, emu); pac2 = new PAC2(this, emu); // set contexts @@ -177,7 +177,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) for(DEVICE* device = first_device; device; device = device->next_device) { device->initialize(); } - decl_state(); for(DEVICE* device = first_device; device; device = device->next_device) { // if(device->this_device_id != event->this_device_id) { device->reset(); @@ -434,72 +433,36 @@ 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) -{ -#if defined(_LCD) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PASOPIA7_WITH_LCD_HEAD")), csp_logger); -#else - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PASOPIA7_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; + } + } return true; } diff --git a/source/src/vm/pasopia7/pasopia7.h b/source/src/vm/pasopia7/pasopia7.h index 0fdf68c01..ac289623a 100644 --- a/source/src/vm/pasopia7/pasopia7.h +++ b/source/src/vm/pasopia7/pasopia7.h @@ -94,7 +94,7 @@ class DISPLAY; class IOBUS; class IOTRAP; class KEYBOARD; -class MEMORY; +class PASOPIA7_MEMORY; class PAC2; class VM : public VM_TEMPLATE @@ -127,7 +127,7 @@ protected: IOBUS* iobus; IOTRAP* iotrap; KEYBOARD* key; - MEMORY* memory; + PASOPIA7_MEMORY* memory; PAC2* pac2; public: @@ -189,9 +189,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/pasopia7/rampac2.cpp b/source/src/vm/pasopia7/rampac2.cpp index ca144376c..f09139073 100644 --- a/source/src/vm/pasopia7/rampac2.cpp +++ b/source/src/vm/pasopia7/rampac2.cpp @@ -96,50 +96,6 @@ void RAMPAC2::open_file(const _TCHAR* file_path) #define STATE_VERSION 1 -#include "../../statesub.h" - -void RAMPAC2::decl_state() -{ - state_entry = new csp_state_utils(STATE_VERSION, this_device_id, (const _TCHAR *)_T("PAC2SLOT::RAMPAC2"), NULL); - - DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); - DECL_STATE_ENTRY_UINT32(ptr); - - DECL_STATE_ENTRY_BOOL(opened); - DECL_STATE_ENTRY_BOOL(modified); - //leave_decl_state(); -} - -void RAMPAC2::save_state(FILEIO* state_fio) -{ - if(state_entry != NULL) { - state_entry->save_state(state_fio); - } -// state_fio->FputUint32(STATE_VERSION); -// -// state_fio->Fwrite(ram, sizeof(ram), 1); -// state_fio->FputUint32(ptr); -// state_fio->FputBool(opened); -// state_fio->FputBool(modified); -} - -bool RAMPAC2::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; -// } -// state_fio->Fread(ram, sizeof(ram), 1); -// ptr = state_fio->FgetUint32(); -// opened = state_fio->FgetBool(); -// modified = state_fio->FgetBool(); - return true; -} - bool RAMPAC2::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pasopia7/rampac2.h b/source/src/vm/pasopia7/rampac2.h index b7d899f11..d7a30ba64 100644 --- a/source/src/vm/pasopia7/rampac2.h +++ b/source/src/vm/pasopia7/rampac2.h @@ -39,9 +39,7 @@ public: void write_io8(uint32_t addr, uint32_t data); uint32_t read_io8(uint32_t addr); void open_file(const _TCHAR* file_path); - 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/pc100/crtc.cpp b/source/src/vm/pc100/crtc.cpp index 6aca8eba0..ecf3eb015 100644 --- a/source/src/vm/pc100/crtc.cpp +++ b/source/src/vm/pc100/crtc.cpp @@ -310,86 +310,6 @@ void CRTC::update_palette(int num) #define STATE_VERSION 1 -#include "../../statesub.h" - -void CRTC::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_SCRNTYPE_T_1D_ARRAY(palette_pc, 16); - DECL_STATE_ENTRY_1D_ARRAY(palette, 16); - DECL_STATE_ENTRY_UINT8(sel); - DECL_STATE_ENTRY_1D_ARRAY(regs, sizeof(regs)); - DECL_STATE_ENTRY_UINT16(vs); - DECL_STATE_ENTRY_UINT16(cmd); - DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram)); - DECL_STATE_ENTRY_UINT32(shift); - DECL_STATE_ENTRY_UINT32(maskl); - DECL_STATE_ENTRY_UINT32(maskh); - DECL_STATE_ENTRY_UINT32(busl); - DECL_STATE_ENTRY_UINT32(bush); - DECL_STATE_ENTRY_UINT32(write_plane); - DECL_STATE_ENTRY_UINT32(read_plane); - - leave_decl_state(); -} - -void CRTC::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(palette_pc, sizeof(palette_pc), 1); -// state_fio->Fwrite(palette, sizeof(palette), 1); -// state_fio->FputUint8(sel); -// state_fio->Fwrite(regs, sizeof(regs), 1); -// state_fio->FputUint16(vs); -// state_fio->FputUint16(cmd); -// state_fio->Fwrite(vram, sizeof(vram), 1); -// state_fio->FputUint32(shift); -// state_fio->FputUint32(maskl); -// state_fio->FputUint32(maskh); -// state_fio->FputUint32(busl); -// state_fio->FputUint32(bush); -// state_fio->FputUint32(write_plane); -// state_fio->FputUint32(read_plane); -} - -bool CRTC::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(palette_pc, sizeof(palette_pc), 1); -// state_fio->Fread(palette, sizeof(palette), 1); -// sel = state_fio->FgetUint8(); -// state_fio->Fread(regs, sizeof(regs), 1); -// vs = state_fio->FgetUint16(); -// cmd = state_fio->FgetUint16(); -// state_fio->Fread(vram, sizeof(vram), 1); -// shift = state_fio->FgetUint32(); -// maskl = state_fio->FgetUint32(); -// maskh = state_fio->FgetUint32(); -// busl = state_fio->FgetUint32(); -// bush = state_fio->FgetUint32(); -// write_plane = state_fio->FgetUint32(); -// read_plane = state_fio->FgetUint32(); - return true; -} - bool CRTC::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { @@ -398,8 +318,28 @@ bool CRTC::process_state(FILEIO* state_fio, bool loading) if(!state_fio->StateCheckInt32(this_device_id)) { return false; } - state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1); - state_fio->StateBuffer(palette, sizeof(palette), 1); + //state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1); + for(int i = 0; i < (sizeof(palette_pc) / sizeof(scrntype_t)); i++) { + if(loading) { + uint8_t r, g, b; + r = state_fio->FgetUint8(); + g = state_fio->FgetUint8(); + b = state_fio->FgetUint8(); + palette_pc[i] = RGB_COLOR(r, g, b); + } else { + uint8_t r, g, b; + r = R_OF_COLOR(palette_pc[i]); + g = G_OF_COLOR(palette_pc[i]); + b = B_OF_COLOR(palette_pc[i]); + state_fio->FputUint8(r); + state_fio->FputUint8(g); + state_fio->FputUint8(b); + } + } + //state_fio->StateBuffer(palette, sizeof(palette), 1); + for(int i = 0; i < (sizeof(palette) / sizeof(uint16_t)); i++) { + state_fio->StateUint16(palette[i]); + } state_fio->StateUint8(sel); state_fio->StateBuffer(regs, sizeof(regs), 1); state_fio->StateUint16(vs); diff --git a/source/src/vm/pc100/crtc.h b/source/src/vm/pc100/crtc.h index 078ef337e..5e49d7687 100644 --- a/source/src/vm/pc100/crtc.h +++ b/source/src/vm/pc100/crtc.h @@ -51,9 +51,7 @@ public: void write_memory_mapped_io16(uint32_t addr, uint32_t data); uint32_t read_memory_mapped_io16(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_pic(DEVICE* device) diff --git a/source/src/vm/pc100/ioctrl.cpp b/source/src/vm/pc100/ioctrl.cpp index eb5c2d6e7..df8204f1b 100644 --- a/source/src/vm/pc100/ioctrl.cpp +++ b/source/src/vm/pc100/ioctrl.cpp @@ -219,77 +219,6 @@ void IOCTRL::update_key() #define STATE_VERSION 1 -#include "../../statesub.h" - -void IOCTRL::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_BOOL(caps); - DECL_STATE_ENTRY_BOOL(kana); - DECL_STATE_ENTRY_FIFO(key_buf); - DECL_STATE_ENTRY_UINT32(key_val); - DECL_STATE_ENTRY_UINT32(key_mouse); - DECL_STATE_ENTRY_INT32(key_prev); - DECL_STATE_ENTRY_BOOL(key_res); - DECL_STATE_ENTRY_BOOL(key_done); - DECL_STATE_ENTRY_INT32(register_id); - DECL_STATE_ENTRY_UINT8(ts); - - leave_decl_state(); -} - - -void IOCTRL::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->FputBool(caps); -// state_fio->FputBool(kana); -// key_buf->save_state((void *)state_fio); -// state_fio->FputUint32(key_val); -// state_fio->FputUint32(key_mouse); -// state_fio->FputInt32(key_prev); -// state_fio->FputBool(key_res); -// state_fio->FputBool(key_done); -// state_fio->FputInt32(register_id); -// state_fio->FputUint8(ts); -} - -bool IOCTRL::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; -// } -// caps = state_fio->FgetBool(); -// kana = state_fio->FgetBool(); -// if(!key_buf->load_state((void *)state_fio)) { -// return false; -// } -// key_val = state_fio->FgetUint32(); -// key_mouse = state_fio->FgetUint32(); -// key_prev = state_fio->FgetInt32(); -// key_res = state_fio->FgetBool(); -// key_done = state_fio->FgetBool(); -// register_id = state_fio->FgetInt32(); -// ts = state_fio->FgetUint8(); - return true; -} - bool IOCTRL::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pc100/ioctrl.h b/source/src/vm/pc100/ioctrl.h index a36c7a914..9dfa96fa2 100644 --- a/source/src/vm/pc100/ioctrl.h +++ b/source/src/vm/pc100/ioctrl.h @@ -50,9 +50,7 @@ public: uint32_t read_io8(uint32_t addr); void event_callback(int event_id, int err); 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_pic(DEVICE* device) diff --git a/source/src/vm/pc100/kanji.cpp b/source/src/vm/pc100/kanji.cpp index 2dca822ca..2139a11e5 100644 --- a/source/src/vm/pc100/kanji.cpp +++ b/source/src/vm/pc100/kanji.cpp @@ -57,50 +57,6 @@ uint32_t KANJI::read_io8(uint32_t addr) #define STATE_VERSION 1 -#include "../../statesub.h" - -void KANJI::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT16(ptr); - DECL_STATE_ENTRY_BOOL(strobe); - - leave_decl_state(); -} - -void KANJI::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->FputUint16(ptr); -// state_fio->FputBool(strobe); -} - -bool KANJI::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; -// } -// ptr = state_fio->FgetUint16(); -// strobe = state_fio->FgetBool(); - return true; -} - bool KANJI::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pc100/kanji.h b/source/src/vm/pc100/kanji.h index 968cab860..57eddea76 100644 --- a/source/src/vm/pc100/kanji.h +++ b/source/src/vm/pc100/kanji.h @@ -32,9 +32,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/pc100/pc100.cpp b/source/src/vm/pc100/pc100.cpp index ade2c387d..8b63c15c8 100644 --- a/source/src/vm/pc100/pc100.cpp +++ b/source/src/vm/pc100/pc100.cpp @@ -157,7 +157,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() @@ -339,73 +338,38 @@ 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::PC_100_HEAD")), csp_logger); - DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); - 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); -} - -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); - 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); return true; } diff --git a/source/src/vm/pc100/pc100.h b/source/src/vm/pc100/pc100.h index 08dcbcf72..08dba065e 100644 --- a/source/src/vm/pc100/pc100.h +++ b/source/src/vm/pc100/pc100.h @@ -158,9 +158,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/pc2001/io.cpp b/source/src/vm/pc2001/io.cpp index 5bc182dd6..0cd908843 100644 --- a/source/src/vm/pc2001/io.cpp +++ b/source/src/vm/pc2001/io.cpp @@ -8,7 +8,7 @@ [ i/o ] */ -#include "io.h" +#include "./io.h" #include "../datarec.h" #include "../upd16434.h" #include "../upd1990a.h" @@ -17,20 +17,20 @@ #define EVENT_TIMER 0 -void IO::initialize() +void PC2001_IO::initialize() { register_event(this, EVENT_TIMER, 20000, true, NULL); key_stat = emu->get_key_buffer(); } -void IO::reset() +void PC2001_IO::reset() { port_a = port_b = port_s = 0xff; drec_in = rtc_in = false; key_strobe = 0xffff; } -void IO::write_io8(uint32_t addr, uint32_t data) +void PC2001_IO::write_io8(uint32_t addr, uint32_t data) { switch(addr) { case UPD7807_PORTA: @@ -81,7 +81,7 @@ void IO::write_io8(uint32_t addr, uint32_t data) } } -uint32_t IO::read_io8(uint32_t addr) +uint32_t PC2001_IO::read_io8(uint32_t addr) { uint32_t value = 0xff; @@ -110,7 +110,7 @@ uint32_t IO::read_io8(uint32_t addr) return value; } -void IO::write_io16(uint32_t addr, uint32_t data) +void PC2001_IO::write_io16(uint32_t addr, uint32_t data) { switch(addr) { case UPD7807_PORTE: @@ -122,7 +122,7 @@ void IO::write_io16(uint32_t addr, uint32_t data) } } -void IO::write_signal(int id, uint32_t data, uint32_t mask) +void PC2001_IO::write_signal(int id, uint32_t data, uint32_t mask) { switch(id) { case SIG_IO_DREC_IN: @@ -135,14 +135,14 @@ void IO::write_signal(int id, uint32_t data, uint32_t mask) } } -void IO::event_callback(int event_id, int err) +void PC2001_IO::event_callback(int event_id, int err) { if(event_id == EVENT_TIMER) { d_cpu->write_signal(SIG_UPD7810_INTF1, 1, 1); } } -uint8_t IO::get_key() +uint8_t PC2001_IO::get_key() { uint8_t data = 0x3f; @@ -267,7 +267,7 @@ uint8_t IO::get_key() return data; } -bool IO::key_hit(int code) +bool PC2001_IO::key_hit(int code) { bool value = (key_stat[code] != 0); return value; @@ -275,63 +275,7 @@ bool IO::key_hit(int code) #define STATE_VERSION 2 -#include "../../statesub.h" - -void IO::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT8(port_a); - DECL_STATE_ENTRY_UINT8(port_b); - DECL_STATE_ENTRY_UINT8(port_s); - DECL_STATE_ENTRY_BOOL(drec_in); - DECL_STATE_ENTRY_BOOL(rtc_in); - DECL_STATE_ENTRY_UINT16(key_strobe); - - leave_decl_state(); -} - -void IO::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(port_a); -// state_fio->FputUint8(port_b); -// state_fio->FputUint8(port_s); -// state_fio->FputBool(drec_in); -// state_fio->FputBool(rtc_in); -// state_fio->FputUint16(key_strobe); -} - -bool IO::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; -// } -// port_a = state_fio->FgetUint8(); -// port_b = state_fio->FgetUint8(); -// port_s = state_fio->FgetUint8(); -// drec_in = state_fio->FgetBool(); -// rtc_in = state_fio->FgetBool(); -// key_strobe = state_fio->FgetUint16(); - return true; -} - -bool IO::process_state(FILEIO* state_fio, bool loading) +bool PC2001_IO::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { return false; diff --git a/source/src/vm/pc2001/io.h b/source/src/vm/pc2001/io.h index c3de10aa7..11b4ff764 100644 --- a/source/src/vm/pc2001/io.h +++ b/source/src/vm/pc2001/io.h @@ -8,8 +8,8 @@ [ i/o ] */ -#ifndef _IO_H_ -#define _IO_H_ +#ifndef _PC2001_IO_H_ +#define _PC2001_IO_H_ #include "../vm.h" #include "../../emu.h" @@ -20,7 +20,7 @@ class UPD16434; -class IO : public DEVICE +class PC2001_IO : public DEVICE { private: UPD16434 *d_lcd[4]; @@ -38,11 +38,11 @@ private: bool key_hit(int code); public: - IO(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) + PC2001_IO(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) { set_device_name(_T("I/O Bus")); } - ~IO() {} + ~PC2001_IO() {} // common functions void initialize(); @@ -52,9 +52,7 @@ public: void write_io16(uint32_t addr, uint32_t data); void write_signal(int id, uint32_t data, uint32_t mask); void event_callback(int event_id, int err); - 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_lcd(int index, UPD16434* device) diff --git a/source/src/vm/pc2001/pc2001.cpp b/source/src/vm/pc2001/pc2001.cpp index 4c97260bd..a2c5b5575 100644 --- a/source/src/vm/pc2001/pc2001.cpp +++ b/source/src/vm/pc2001/pc2001.cpp @@ -25,7 +25,7 @@ #include "../debugger.h" #endif -#include "io.h" +#include "./io.h" // ---------------------------------------------------------------------------- // initialize @@ -55,7 +55,7 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) rtc = new UPD1990A(this, emu); cpu = new UPD7810(this, emu); - io = new IO(this, emu); + io = new PC2001_IO(this, emu); // set contexts event->set_context_cpu(cpu); @@ -104,7 +104,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() @@ -294,54 +293,6 @@ 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::PC_2001_HEAD")), csp_logger); - DECL_STATE_ENTRY_MULTI(void, ram, sizeof(ram)); - 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); -} - -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); - return true; -} - bool VM::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pc2001/pc2001.h b/source/src/vm/pc2001/pc2001.h index 2b9362111..1dee026e9 100644 --- a/source/src/vm/pc2001/pc2001.h +++ b/source/src/vm/pc2001/pc2001.h @@ -61,7 +61,7 @@ class UPD16434; class UPD1990A; class UPD7810; -class IO; +class PC2001_IO; class VM : public VM_TEMPLATE { protected: @@ -78,7 +78,7 @@ protected: UPD1990A* rtc; UPD7810* cpu; - IO* io; + PC2001_IO* io; // memory uint8_t ram[0x5000]; @@ -135,9 +135,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/pc6001/display.cpp b/source/src/vm/pc6001/display.cpp index 2ae8b7b28..4b71ce7ca 100644 --- a/source/src/vm/pc6001/display.cpp +++ b/source/src/vm/pc6001/display.cpp @@ -46,50 +46,6 @@ void DISPLAY::draw_screen() #define STATE_VERSION 1 -#include "../../statesub.h" - -void DISPLAY::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_INT32(tmp_vram_size); - - leave_decl_state(); -} - -void DISPLAY::save_state(FILEIO* state_fio) -{ - tmp_vram_size = (int)(vram_ptr - ram_ptr); - - 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_ptr - ram_ptr)); -} - -bool DISPLAY::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_ptr = ram_ptr + state_fio->FgetInt32(); - vram_ptr = ram_ptr + tmp_vram_size; - return true; -} - bool DISPLAY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pc6001/display.h b/source/src/vm/pc6001/display.h index 3882cc25f..0110dac2d 100644 --- a/source/src/vm/pc6001/display.h +++ b/source/src/vm/pc6001/display.h @@ -37,9 +37,7 @@ public: // common functions void reset(); void write_io8(uint32_t addr, uint32_t data); - 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_vdp(MC6847* device) diff --git a/source/src/vm/pc6001/floppy.cpp b/source/src/vm/pc6001/floppy.cpp index d68eff705..033687d0e 100644 --- a/source/src/vm/pc6001/floppy.cpp +++ b/source/src/vm/pc6001/floppy.cpp @@ -599,110 +599,6 @@ void FLOPPY::update_config() #define STATE_VERSION 1 -#include "../../statesub.h" - -void FLOPPY::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT8(io_B1H); - DECL_STATE_ENTRY_1D_ARRAY(cur_trk, 2); - DECL_STATE_ENTRY_1D_ARRAY(cur_sct, 2); - DECL_STATE_ENTRY_1D_ARRAY(cur_pos, 2); - DECL_STATE_ENTRY_1D_ARRAY(access, 2); - DECL_STATE_ENTRY_2D_ARRAY(Data, 4, 256); - DECL_STATE_ENTRY_1D_ARRAY(Index, 4); - { - DECL_STATE_ENTRY_1D_ARRAY((CmdIn.Data), 10 * sizeof(unsigned char)); - DECL_STATE_ENTRY_INT32((CmdIn.Index)); - } - { - DECL_STATE_ENTRY_1D_ARRAY((CmdOut.Data), 10 * sizeof(unsigned char)); - DECL_STATE_ENTRY_INT32((CmdOut.Index)); - } - - DECL_STATE_ENTRY_UINT8(SeekST0); - DECL_STATE_ENTRY_UINT8(LastCylinder); - DECL_STATE_ENTRY_INT32(SeekEnd); - DECL_STATE_ENTRY_UINT8(SendSectors); - DECL_STATE_ENTRY_INT32(DIO); - DECL_STATE_ENTRY_UINT8(Status); - leave_decl_state(); - - for(int i = 0; i < 2; i++) { - disk[i]->decl_state(p_logger); - } - -} - - -void FLOPPY::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(io_B1H); - for(int i = 0; i < 2; i++) { - disk[i]->save_state(state_fio); - } -// state_fio->Fwrite(cur_trk, sizeof(cur_trk), 1); -// state_fio->Fwrite(cur_sct, sizeof(cur_sct), 1); -// state_fio->Fwrite(cur_pos, sizeof(cur_pos), 1); -// state_fio->Fwrite(access, sizeof(access), 1); -// state_fio->Fwrite(Data, sizeof(Data), 1); -// state_fio->Fwrite(Index, sizeof(Index), 1); -// state_fio->Fwrite(&CmdIn, sizeof(CmdBuffer), 1); -// state_fio->Fwrite(&CmdOut, sizeof(CmdBuffer), 1); - -// state_fio->FputUint8(SeekST0); -// state_fio->FputUint8(LastCylinder); -// state_fio->FputInt32(SeekEnd); -// state_fio->FputUint8(SendSectors); -// state_fio->FputInt32(DIO); -// state_fio->FputUint8(Status); -} - -bool FLOPPY::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; -// } -// io_B1H = state_fio->FgetUint8(); - for(int i = 0; i < 2; i++) { - if(!disk[i]->load_state(state_fio)) { - return false; - } - } -// state_fio->Fread(cur_trk, sizeof(cur_trk), 1); -// state_fio->Fread(cur_sct, sizeof(cur_sct), 1); -// state_fio->Fread(cur_pos, sizeof(cur_pos), 1); -// state_fio->Fread(access, sizeof(access), 1); -// state_fio->Fread(Data, sizeof(Data), 1); -// state_fio->Fread(Index, sizeof(Index), 1); -// state_fio->Fread(&CmdIn, sizeof(CmdBuffer), 1); -// state_fio->Fread(&CmdOut, sizeof(CmdBuffer), 1); -// SeekST0 = state_fio->FgetUint8(); -// LastCylinder = state_fio->FgetUint8(); -// SeekEnd = state_fio->FgetInt32(); -// SendSectors = state_fio->FgetUint8(); -// DIO = state_fio->FgetInt32(); -// Status = state_fio->FgetUint8(); - return true; -} - bool FLOPPY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { @@ -717,14 +613,37 @@ bool FLOPPY::process_state(FILEIO* state_fio, bool loading) return false; } } - state_fio->StateBuffer(cur_trk, sizeof(cur_trk), 1); - state_fio->StateBuffer(cur_sct, sizeof(cur_sct), 1); - state_fio->StateBuffer(cur_pos, sizeof(cur_pos), 1); - state_fio->StateBuffer(access, sizeof(access), 1); + //state_fio->StateBuffer(cur_trk, sizeof(cur_trk), 1); + for(int i = 0; i < (sizeof(cur_trk) / sizeof(int)); i++) { + state_fio->StateInt32(cur_trk[i]); + } + //state_fio->StateBuffer(cur_sct, sizeof(cur_sct), 1); + for(int i = 0; i < (sizeof(cur_sct) / sizeof(int)); i++) { + state_fio->StateInt32(cur_sct[i]); + } + //state_fio->StateBuffer(cur_pos, sizeof(cur_pos), 1); + for(int i = 0; i < (sizeof(cur_pos) / sizeof(int)); i++) { + state_fio->StateInt32(cur_pos[i]); + } + //state_fio->StateBuffer(access, sizeof(access), 1); + for(int i = 0; i < (sizeof(access) / sizeof(bool)); i++) { + state_fio->StateBool(access[i]); + } state_fio->StateBuffer(Data, sizeof(Data), 1); - state_fio->StateBuffer(Index, sizeof(Index), 1); - state_fio->StateBuffer(&CmdIn, sizeof(CmdBuffer), 1); - state_fio->StateBuffer(&CmdOut, sizeof(CmdBuffer), 1); + //state_fio->StateBuffer(Index, sizeof(Index), 1); + for(int i = 0; i < (sizeof(Index) / sizeof(int)); i++) { + state_fio->StateInt32(Index[i]); + } + //state_fio->StateBuffer(&CmdIn, sizeof(CmdBuffer), 1); + { + state_fio->StateBuffer(CmdIn.Data, sizeof(CmdIn.Data), 1); + state_fio->StateInt32(CmdIn.Index); + } + //state_fio->StateBuffer(&CmdOut, sizeof(CmdBuffer), 1); + { + state_fio->StateBuffer(CmdOut.Data, sizeof(CmdOut.Data), 1); + state_fio->StateInt32(CmdOut.Index); + } state_fio->StateUint8(SeekST0); state_fio->StateUint8(LastCylinder); state_fio->StateInt32(SeekEnd); diff --git a/source/src/vm/pc6001/floppy.h b/source/src/vm/pc6001/floppy.h index 2693032ea..e2c3d8c9c 100644 --- a/source/src/vm/pc6001/floppy.h +++ b/source/src/vm/pc6001/floppy.h @@ -118,9 +118,7 @@ public: uint32_t read_io8(uint32_t addr); uint32_t read_signal(int ch); 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); // unique functions void set_context_ext(DEVICE* device) diff --git a/source/src/vm/pc6001/memory.cpp b/source/src/vm/pc6001/memory.cpp index f78d49a8b..d69686886 100644 --- a/source/src/vm/pc6001/memory.cpp +++ b/source/src/vm/pc6001/memory.cpp @@ -21,7 +21,7 @@ [ memory ] */ -#include "memory.h" +#include "./memory.h" #include "timer.h" #define RAM (MEMORY_BASE + RAM_BASE) @@ -39,7 +39,7 @@ #define SYSTEMROM2 (MEMORY_BASE + SYSTEMROM2_BASE) #define CGROM6 (MEMORY_BASE + CGROM6_BASE) -void MEMORY::initialize() +void PC6001_MEMORY::initialize() { FILEIO* fio = new FILEIO(); #if defined(_PC6001) @@ -167,7 +167,7 @@ void MEMORY::initialize() #endif } -void MEMORY::reset() +void PC6001_MEMORY::reset() { #ifdef _PC6001 int J; @@ -256,7 +256,7 @@ void MEMORY::reset() #endif } -void MEMORY::write_data8(uint32_t addr, uint32_t data) +void PC6001_MEMORY::write_data8(uint32_t addr, uint32_t data) { #if defined(_PC6601SR) || defined(_PC6001MK2SR) /* Graphics Vram Write (SR basic) */ @@ -269,7 +269,7 @@ void MEMORY::write_data8(uint32_t addr, uint32_t data) WrMem[addr >> 13][addr & 0x1FFF] = data; } -uint32_t MEMORY::read_data8(uint32_t addr) +uint32_t PC6001_MEMORY::read_data8(uint32_t addr) { #if defined(_PC6601SR) || defined(_PC6001MK2SR) /* Graphics Vram Read (SR basic) */ @@ -279,7 +279,7 @@ uint32_t MEMORY::read_data8(uint32_t addr) return(RdMem[addr >> 13][addr & 0x1FFF]); } -void MEMORY::write_io8(uint32_t addr, uint32_t data) +void PC6001_MEMORY::write_io8(uint32_t addr, uint32_t data) { unsigned int VRAMHead[2][4] = { { 0xc000, 0xe000, 0x8000, 0xa000 }, @@ -581,7 +581,7 @@ void MEMORY::write_io8(uint32_t addr, uint32_t data) } #ifndef _PC6001 -uint32_t MEMORY::read_io8(uint32_t addr) +uint32_t PC6001_MEMORY::read_io8(uint32_t addr) { uint16_t port=(addr & 0x00ff); uint8_t Value=0xff; @@ -604,7 +604,7 @@ uint32_t MEMORY::read_io8(uint32_t addr) #define EVENT_HBLANK 1 -void MEMORY::event_vline(int v, int clock) +void PC6001_MEMORY::event_vline(int v, int clock) { #if defined(_PC6601SR) || defined(_PC6001MK2SR) if(static_cast(vm)->sr_mode) { @@ -626,7 +626,7 @@ void MEMORY::event_vline(int v, int clock) } } -void MEMORY::event_callback(int event_id, int err) +void PC6001_MEMORY::event_callback(int event_id, int err) { if(event_id == EVENT_HBLANK) { d_cpu->write_signal(SIG_CPU_BUSREQ, 0, 0); @@ -634,7 +634,7 @@ void MEMORY::event_callback(int event_id, int err) } #endif -void MEMORY::write_signal(int id, uint32_t data, uint32_t mask) +void PC6001_MEMORY::write_signal(int id, uint32_t data, uint32_t mask) { if(id == SIG_MEMORY_PIO_PORT_C) { #ifdef _PC6001 @@ -654,7 +654,7 @@ void MEMORY::write_signal(int id, uint32_t data, uint32_t mask) } } -void MEMORY::open_cart(const _TCHAR* file_path) +void PC6001_MEMORY::open_cart(const _TCHAR* file_path) { FILEIO* fio = new FILEIO(); if(fio->Fopen(file_path, FILEIO_READ_BINARY)) { @@ -674,7 +674,7 @@ void MEMORY::open_cart(const _TCHAR* file_path) delete fio; } -void MEMORY::close_cart() +void PC6001_MEMORY::close_cart() { /// EXTROM1 = EXTROM2 = EmptyRAM; EXTROM1 = RAM + 0x4000; @@ -685,220 +685,7 @@ void MEMORY::close_cart() #define STATE_VERSION 1 -#include "../../statesub.h" - -void MEMORY::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_1D_ARRAY(&(MEMORY_BASE[RAM_BASE]), RAM_SIZE); -// state_fio->FputInt32((int)(CGROM - MEMORY_BASE)); -// state_fio->FputInt32((int)(EXTROM1 - MEMORY_BASE)); -// state_fio->FputInt32((int)(EXTROM2 - MEMORY_BASE)); -// for(int i = 0; i < 8; i++) { -// state_fio->FputInt32((int)(RdMem[i] - MEMORY_BASE)); -// state_fio->FputInt32((int)(WrMem[i] - MEMORY_BASE)); -// } -// state_fio->FputInt32((int)(VRAM - MEMORY_BASE)); - DECL_STATE_ENTRY_1D_ARRAY(EnWrite, sizeof(EnWrite)); - DECL_STATE_ENTRY_UINT8(CGSW93); - DECL_STATE_ENTRY_BOOL(inserted); -#ifndef _PC6001 - DECL_STATE_ENTRY_UINT8(CRTKILL); -// DECL_STATE_ENTRY_INT32((int)(CurKANJIROM - MEMORY_BASE)); - DECL_STATE_ENTRY_UINT8(CRTMode1); - DECL_STATE_ENTRY_UINT8(CRTMode2); - DECL_STATE_ENTRY_UINT8(CRTMode3); - DECL_STATE_ENTRY_UINT8(CSS1); - DECL_STATE_ENTRY_UINT8(CSS2); - DECL_STATE_ENTRY_UINT8(CSS3); - DECL_STATE_ENTRY_UINT8(portF0); - DECL_STATE_ENTRY_UINT8(portF1); -#if defined(_PC6601SR) || defined(_PC6001MK2SR) - DECL_STATE_ENTRY_INT32(bitmap); - DECL_STATE_ENTRY_INT32(cols); - DECL_STATE_ENTRY_INT32(rows); - DECL_STATE_ENTRY_INT32(lines); -// state_fio->FputInt32((int)(TEXTVRAM - MEMORY_BASE)); -// state_fio->FputInt32((int)(SYSROM2 - MEMORY_BASE)); - DECL_STATE_ENTRY_1D_ARRAY(&(MEMORY_BASE[EXTRAM_BASE]), EXTRAM_SIZE); - DECL_STATE_ENTRY_1D_ARRAY(port60, sizeof(port60)); - DECL_STATE_ENTRY_UINT8(portC1); - DECL_STATE_ENTRY_UINT8(portC8); - DECL_STATE_ENTRY_UINT8(portCA); - DECL_STATE_ENTRY_UINT8(portCB); - DECL_STATE_ENTRY_UINT8(portCC); - DECL_STATE_ENTRY_UINT8(portCE); - DECL_STATE_ENTRY_UINT8(portCF); - DECL_STATE_ENTRY_1D_ARRAY(palet, sizeof(palet) / sizeof(int)); -#endif -#endif - // Pointer Values - DECL_STATE_ENTRY_INT32(tmp_cgrom_ptr); - DECL_STATE_ENTRY_INT32(tmp_extrom1_ptr); - DECL_STATE_ENTRY_INT32(tmp_extrom2_ptr); - { - DECL_STATE_ENTRY_1D_ARRAY(tmp_rdmem_ptr, 8); - DECL_STATE_ENTRY_1D_ARRAY(tmp_wrmem_ptr, 8); - } - DECL_STATE_ENTRY_INT32(tmp_vram_ptr); -#ifndef _PC6001 - DECL_STATE_ENTRY_INT32(tmp_kanjirom_ptr); -#if defined(_PC6601SR) || defined(_PC6001MK2SR) - DECL_STATE_ENTRY_INT32(tmp_textvram_ptr); - DECL_STATE_ENTRY_INT32(tmp_sysrom2_ptr); -#endif -#endif - - leave_decl_state(); -} - -void MEMORY::save_state(FILEIO* state_fio) -{ - tmp_cgrom_ptr = (int)(CGROM - MEMORY_BASE); - tmp_extrom1_ptr = (int)(EXTROM1 - MEMORY_BASE); - tmp_extrom2_ptr = (int)(EXTROM2 - MEMORY_BASE); - for(int i = 0; i < 8; i++) { - tmp_rdmem_ptr[i] = (int)(RdMem[i] - MEMORY_BASE); - tmp_wrmem_ptr[i] = (int)(WrMem[i] - MEMORY_BASE); - } - tmp_vram_ptr =(int)(VRAM - MEMORY_BASE); -#ifndef _PC6001 - tmp_kanjirom_ptr = (int)(CurKANJIROM - MEMORY_BASE); -#if defined(_PC6601SR) || defined(_PC6001MK2SR) - tmp_textvram_ptr = (int)(TEXTVRAM - MEMORY_BASE); - tmp_sysrom2_ptr = (int)(SYSROM2 - MEMORY_BASE); -#endif -#endif - - 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, RAM_SIZE, 1); -// state_fio->FputInt32((int)(CGROM - MEMORY_BASE)); -// state_fio->FputInt32((int)(EXTROM1 - MEMORY_BASE)); -// state_fio->FputInt32((int)(EXTROM2 - MEMORY_BASE)); -// for(int i = 0; i < 8; i++) { -// state_fio->FputInt32((int)(RdMem[i] - MEMORY_BASE)); -// state_fio->FputInt32((int)(WrMem[i] - MEMORY_BASE)); -// } -// state_fio->FputInt32((int)(VRAM - MEMORY_BASE)); -// state_fio->Fwrite(EnWrite, sizeof(EnWrite), 1); -// state_fio->FputUint8(CGSW93); -// state_fio->FputBool(inserted); -#ifndef _PC6001 -// state_fio->FputUint8(CRTKILL); -// state_fio->FputInt32((int)(CurKANJIROM - MEMORY_BASE)); -// state_fio->FputUint8(CRTMode1); -// state_fio->FputUint8(CRTMode2); -// state_fio->FputUint8(CRTMode3); -// state_fio->FputUint8(CSS1); -// state_fio->FputUint8(CSS2); -// state_fio->FputUint8(CSS3); -// state_fio->FputUint8(portF0); -// state_fio->FputUint8(portF1); -#if defined(_PC6601SR) || defined(_PC6001MK2SR) -// state_fio->FputInt32(bitmap); -// state_fio->FputInt32(cols); -// state_fio->FputInt32(rows); -// state_fio->FputInt32(lines); -// state_fio->FputInt32((int)(TEXTVRAM - MEMORY_BASE)); -// state_fio->FputInt32((int)(SYSROM2 - MEMORY_BASE)); -// state_fio->Fwrite(EXTRAM, EXTRAM_SIZE, 1); -// state_fio->Fwrite(port60, sizeof(port60), 1); -// state_fio->FputUint8(portC1); -// state_fio->FputUint8(portC8); -// state_fio->FputUint8(portCA); -// state_fio->FputUint8(portCB); -// state_fio->FputUint8(portCC); -// state_fio->FputUint8(portCE); -// state_fio->FputUint8(portCF); -// state_fio->Fwrite(palet, sizeof(palet), 1); -#endif -#endif -} - -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, RAM_SIZE, 1); -// CGROM = MEMORY_BASE + state_fio->FgetInt32(); -// EXTROM1 = MEMORY_BASE + state_fio->FgetInt32(); -// EXTROM2 = MEMORY_BASE + state_fio->FgetInt32(); -// for(int i = 0; i < 8; i++) { -// RdMem[i] = MEMORY_BASE + state_fio->FgetInt32(); -// WrMem[i] = MEMORY_BASE + state_fio->FgetInt32(); -// } -// VRAM = MEMORY_BASE + state_fio->FgetInt32(); -// state_fio->Fread(EnWrite, sizeof(EnWrite), 1); -// CGSW93 = state_fio->FgetUint8(); -// inserted = state_fio->FgetBool(); -//#ifndef _PC6001 -// CRTKILL = state_fio->FgetUint8(); -// CurKANJIROM = MEMORY_BASE + state_fio->FgetInt32(); -// CRTMode1 = state_fio->FgetUint8(); -// CRTMode2 = state_fio->FgetUint8(); -// CRTMode3 = state_fio->FgetUint8(); -// CSS1 = state_fio->FgetUint8(); -// CSS2 = state_fio->FgetUint8(); -// CSS3 = state_fio->FgetUint8(); -// portF0 = state_fio->FgetUint8(); -// portF1 = state_fio->FgetUint8(); -//#if defined(_PC6601SR) || defined(_PC6001MK2SR) -// bitmap = state_fio->FgetInt32(); -// cols = state_fio->FgetInt32(); -// rows = state_fio->FgetInt32(); -// lines = state_fio->FgetInt32(); -// TEXTVRAM = MEMORY_BASE + state_fio->FgetInt32(); -// SYSROM2 = MEMORY_BASE + state_fio->FgetInt32(); -// state_fio->Fread(EXTRAM, EXTRAM_SIZE, 1); -// state_fio->Fread(port60, sizeof(port60), 1); -// portC1 = state_fio->FgetUint8(); -// portC8 = state_fio->FgetUint8(); -// portCA = state_fio->FgetUint8(); -// portCB = state_fio->FgetUint8(); -// portCC = state_fio->FgetUint8(); -// portCE = state_fio->FgetUint8(); -// portCF = state_fio->FgetUint8(); -// state_fio->Fread(palet, sizeof(palet), 1); -//#endif -//#endif - - // Post Process - CGROM = MEMORY_BASE + tmp_cgrom_ptr; - EXTROM1 = MEMORY_BASE + tmp_extrom1_ptr; - EXTROM2 = MEMORY_BASE + tmp_extrom2_ptr; - for(int i = 0; i < 8; i++) { - RdMem[i] = MEMORY_BASE + tmp_rdmem_ptr[i]; - WrMem[i] = MEMORY_BASE + tmp_wrmem_ptr[i]; - } - VRAM = MEMORY_BASE + tmp_vram_ptr; -#ifndef _PC6001 - CurKANJIROM = MEMORY_BASE + tmp_kanjirom_ptr; -#if defined(_PC6601SR) || defined(_PC6001MK2SR) - TEXTVRAM = MEMORY_BASE + tmp_textvram_ptr; - SYSROM2 = MEMORY_BASE + tmp_sysrom2_ptr; -#endif -#endif - return true; -} - -bool MEMORY::process_state(FILEIO* state_fio, bool loading) +bool PC6001_MEMORY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { return false; diff --git a/source/src/vm/pc6001/memory.h b/source/src/vm/pc6001/memory.h index 9dee407f1..5b6982702 100644 --- a/source/src/vm/pc6001/memory.h +++ b/source/src/vm/pc6001/memory.h @@ -17,8 +17,8 @@ [ memory ] */ -#ifndef _MEMORY_H_ -#define _MEMORY_H_ +#ifndef _PC6001_MEMORY_H_ +#define _PC6001_MEMORY_H_ #include "../vm.h" #include "../../emu.h" @@ -65,7 +65,7 @@ class TIMER; #define MEMORY_SIZE (CGROM6_BASE + CGROM6_SIZE) #endif -class MEMORY : public DEVICE +class PC6001_MEMORY : public DEVICE { private: DEVICE *d_cpu; @@ -165,12 +165,12 @@ private: #endif public: - MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) + PC6001_MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) { inserted = false; set_device_name(_T("Memory Bus")); } - ~MEMORY() {} + ~PC6001_MEMORY() {} // common functions void initialize(); @@ -184,9 +184,7 @@ public: void event_callback(int event_id, int err); #endif 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 #ifndef _PC6001 diff --git a/source/src/vm/pc6001/memory_draw.cpp b/source/src/vm/pc6001/memory_draw.cpp index 66357375f..db21fe555 100644 --- a/source/src/vm/pc6001/memory_draw.cpp +++ b/source/src/vm/pc6001/memory_draw.cpp @@ -35,7 +35,7 @@ #define SeqPix21(c) dest[X*8+W]=c;W++; #define SeqPix41(c) dest[X*8+W]=c;W++;dest[X*8+W]=c;W++; -void MEMORY::draw_screen() +void PC6001_MEMORY::draw_screen() { if (CRTKILL) { for(int y = 0; y < 400; y++) { @@ -137,7 +137,7 @@ void MEMORY::draw_screen() } // RefreshScr10: N60-BASIC select function -void MEMORY::RefreshScr10() +void PC6001_MEMORY::RefreshScr10() { if ((*VRAM&0x80) == 0x00) RefreshScr11(); @@ -159,7 +159,7 @@ void MEMORY::RefreshScr10() } // RefreshScr11: N60-BASIC screen 1,2 -void MEMORY::RefreshScr11() +void PC6001_MEMORY::RefreshScr11() { uint8_t X,Y,K; int FC,BC; @@ -197,7 +197,7 @@ W=0; } // RefreshScr13: N60-BASIC screen 3,4 -void MEMORY::RefreshScr13() +void PC6001_MEMORY::RefreshScr13() { uint8_t X,Y; uint8_t *T1,*T2; @@ -233,7 +233,7 @@ W=0; } // RefreshScr13a: N60-BASIC screen 3,4 -void MEMORY::RefreshScr13a() /* 64x 64 color / 128x 64 */ +void PC6001_MEMORY::RefreshScr13a() /* 64x 64 color / 128x 64 */ { uint8_t X,Y; uint8_t *T1,*T2; @@ -275,7 +275,7 @@ W=0; } // RefreshScr13b: N60-BASIC screen 3,4 -void MEMORY::RefreshScr13b() /* 128x 64 color */ +void PC6001_MEMORY::RefreshScr13b() /* 128x 64 color */ { uint8_t X,Y; uint8_t *T1,*T2; @@ -299,7 +299,7 @@ W=0; } // RefreshScr13c: N60-BASIC screen 3,4 -void MEMORY::RefreshScr13c() /* 128x 96 */ +void PC6001_MEMORY::RefreshScr13c() /* 128x 96 */ { uint8_t X,Y; uint8_t *T1,*T2; @@ -327,7 +327,7 @@ W=0; } // RefreshScr13d: N60-BASIC screen 3,4 -void MEMORY::RefreshScr13d() /* 128x 96 color */ +void PC6001_MEMORY::RefreshScr13d() /* 128x 96 color */ { uint8_t X,Y; uint8_t *T1,*T2; @@ -351,7 +351,7 @@ W=0; } // RefreshScr13e: N60-BASIC screen 3,4 -void MEMORY::RefreshScr13e() /* 128x192 */ +void PC6001_MEMORY::RefreshScr13e() /* 128x192 */ { uint8_t X,Y; uint8_t *T1,*T2; @@ -378,7 +378,7 @@ W=0; } // RefreshScr51: N60m/66-BASIC screen 1,2 -void MEMORY::RefreshScr51() +void PC6001_MEMORY::RefreshScr51() { uint8_t X,Y,K; int FC,BC; @@ -406,7 +406,7 @@ W=0; } // RefreshScr53: N60m/66-BASIC screen 3 -void MEMORY::RefreshScr53() +void PC6001_MEMORY::RefreshScr53() { uint8_t X,Y; uint8_t *T1,*T2; @@ -427,7 +427,7 @@ W=0; } // RefreshScr54: N60m/66-BASIC screen 4 -void MEMORY::RefreshScr54() +void PC6001_MEMORY::RefreshScr54() { uint8_t X,Y; uint8_t *T1,*T2; @@ -456,7 +456,7 @@ W=0; #if defined(_PC6601SR) || defined(_PC6001MK2SR) // RefreshScr61: N66-SR BASIC screen 1 -void MEMORY::RefreshScr61() +void PC6001_MEMORY::RefreshScr61() { uint8_t X,Y,K; register int FC,BC; @@ -490,7 +490,7 @@ W=0; } // RefreshScr62 N66-SR BASIC screen 2 -void MEMORY::RefreshScr62() +void PC6001_MEMORY::RefreshScr62() { uint8_t X,Y; uint8_t *T1,*T2; @@ -524,7 +524,7 @@ W=0; } // RefreshScr63 N66-SR BASIC screen 3 -void MEMORY::RefreshScr63() +void PC6001_MEMORY::RefreshScr63() { uint8_t X,Y; uint8_t *T1,*T2; @@ -566,7 +566,7 @@ W=0; } } -void MEMORY::do_palet(int dest,int src) +void PC6001_MEMORY::do_palet(int dest,int src) { int textpalet2[16]={0,4,1,5,2,6,3,7,8,12,9,13,10,14,11,15}; /* color code-> VRAM code*/ // *************** for RefreshScr 53/54/62/63 *************************** @@ -596,7 +596,7 @@ void MEMORY::do_palet(int dest,int src) BPal[textpalet2[dest]]= BPal61[ textpalet2[src]]; } -void MEMORY::make_semigraph(void) +void PC6001_MEMORY::make_semigraph(void) { uint8_t *P; unsigned int i, j, m1, m2; @@ -638,14 +638,14 @@ void MEMORY::make_semigraph(void) } } -int MEMORY::chk_gvram(uint32_t A,int flag) +int PC6001_MEMORY::chk_gvram(uint32_t A,int flag) { if (port60[ (A>>13)+flag ]==0x00 && bitmap) // VRAM ‚̐擪‚©‚ACRT‚ª BITMAP mode return 1; return 0; } -uint8_t MEMORY::gvram_read(uint32_t A) +uint8_t PC6001_MEMORY::gvram_read(uint32_t A) { uint8_t* adr; uint8_t ret; @@ -669,7 +669,7 @@ uint8_t MEMORY::gvram_read(uint32_t A) return (ret); } -void MEMORY::gvram_write(uint32_t A, uint32_t V) +void PC6001_MEMORY::gvram_write(uint32_t A, uint32_t V) { uint8_t* adr; int x,y,z,w,off; diff --git a/source/src/vm/pc6001/pc6001.cpp b/source/src/vm/pc6001/pc6001.cpp index 3ff8a0b40..54c86dff8 100644 --- a/source/src/vm/pc6001/pc6001.cpp +++ b/source/src/vm/pc6001/pc6001.cpp @@ -96,7 +96,7 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) // floppy->set_context_noise_head_up(noise_head_up); #endif joystick = new JOYSTICK(this, emu); - memory = new MEMORY(this, emu); + memory = new PC6001_MEMORY(this, emu); timer = new TIMER(this, emu); // set contexts @@ -297,7 +297,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) pc6031->get_disk_handler(0)->drive_num = drive_num++; pc6031->get_disk_handler(1)->drive_num = drive_num++; } - decl_state(); } VM::~VM() @@ -700,85 +699,38 @@ void VM::update_config() #define STATE_VERSION 6 -#include "../../statesub.h" -#include "../../qt/gui/csp_logger.h" -extern CSP_Logger DLL_PREFIX_I *csp_logger; - -void VM::decl_state(void) -{ -#if defined(_PC6001) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_6001_HEAD")), csp_logger); -#elif defined(_PC6001MK2) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_6001_MK2_HEAD")), csp_logger); -#elif defined(_PC6001MK2SR) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_6001_MK2_SR_HEAD")), csp_logger); -#elif defined(_PC6601) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_6601_HEAD")), csp_logger); -#elif defined(_PC601SR) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_6601_SR_HEAD")), csp_logger); -#else - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_6001_SERIES_HEAD")), csp_logger); -#endif - DECL_STATE_ENTRY_INT32(sr_mode); - 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->FputInt32(sr_mode); -} - -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; - } - } - //sr_mode = state_fio->FgetInt32(); - 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->StateInt32(sr_mode); return true; } diff --git a/source/src/vm/pc6001/pc6001.h b/source/src/vm/pc6001/pc6001.h index 7100ee226..4f7fa0705 100644 --- a/source/src/vm/pc6001/pc6001.h +++ b/source/src/vm/pc6001/pc6001.h @@ -155,7 +155,7 @@ class DISPLAY; class FLOPPY; #endif class JOYSTICK; -class MEMORY; +class PC6001_MEMORY; class PSUB; class SUB; class TIMER; @@ -193,7 +193,7 @@ protected: FLOPPY* floppy; #endif JOYSTICK* joystick; - MEMORY* memory; + PC6001_MEMORY* memory; PSUB* psub; TIMER* timer; @@ -274,9 +274,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/pc6001/psub.cpp b/source/src/vm/pc6001/psub.cpp index ff46d2f86..349762c22 100644 --- a/source/src/vm/pc6001/psub.cpp +++ b/source/src/vm/pc6001/psub.cpp @@ -1103,143 +1103,6 @@ void PSUB::key_up(int code) #define STATE_VERSION 1 -#include "../../statesub.h" - -void PSUB::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_BOOL(play); - DECL_STATE_ENTRY_BOOL(rec); - DECL_STATE_ENTRY_BOOL(is_wav); - DECL_STATE_ENTRY_BOOL(is_p6t); - DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path)); - DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path); - DECL_STATE_ENTRY_INT32(CasIntFlag); - DECL_STATE_ENTRY_INT32(CasIndex); - DECL_STATE_ENTRY_INT32(CasRecv); - DECL_STATE_ENTRY_INT32(CasMode); - DECL_STATE_ENTRY_INT32(CasBaud); - DECL_STATE_ENTRY_INT32(FileBaud); - DECL_STATE_ENTRY_1D_ARRAY(CasData, sizeof(CasData)); - DECL_STATE_ENTRY_INT32(CasLength); - DECL_STATE_ENTRY_INT32(CasSkipFlag); - DECL_STATE_ENTRY_INT32(kbFlagFunc); - DECL_STATE_ENTRY_INT32(kbFlagGraph); - DECL_STATE_ENTRY_INT32(kbFlagCtrl); - DECL_STATE_ENTRY_INT32(kanaMode); - DECL_STATE_ENTRY_INT32(katakana); - DECL_STATE_ENTRY_INT32(p6key); - DECL_STATE_ENTRY_INT32(stick0); - DECL_STATE_ENTRY_INT32(StrigIntFlag); - DECL_STATE_ENTRY_INT32(StrigEventID); - - leave_decl_state(); -} - -void PSUB::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->FputBool(play); -// state_fio->FputBool(rec); -// state_fio->FputBool(is_wav); -// state_fio->FputBool(is_p6t); -// state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1); -// if(rec && fio->IsOpened()) { -// int length_tmp = (int)fio->Ftell(); -// fio->Fseek(0, FILEIO_SEEK_SET); -// state_fio->FputInt32(length_tmp); -// while(length_tmp != 0) { -// uint8_t buffer_tmp[1024]; -// int length_rw = min(length_tmp, (int)sizeof(buffer_tmp)); -// fio->Fread(buffer_tmp, length_rw, 1); -// state_fio->Fwrite(buffer_tmp, length_rw, 1); -// length_tmp -= length_rw; -// } -// } else { -// state_fio->FputInt32(0); -// } -// state_fio->FputInt32(CasIntFlag); -// state_fio->FputInt32(CasIndex); -// state_fio->FputInt32(CasRecv); -// state_fio->FputInt32(CasMode); -// state_fio->FputInt32(CasBaud); -// state_fio->FputInt32(FileBaud); -// state_fio->Fwrite(CasData, sizeof(CasData), 1); -// state_fio->FputInt32(CasLength); -// state_fio->FputInt32(CasSkipFlag); -// state_fio->FputInt32(kbFlagFunc); -// state_fio->FputInt32(kbFlagGraph); -// state_fio->FputInt32(kbFlagCtrl); -// state_fio->FputInt32(kanaMode); -// state_fio->FputInt32(katakana); -// state_fio->FputInt32(p6key); -// state_fio->FputInt32(stick0); -// state_fio->FputInt32(StrigIntFlag); -// state_fio->FputInt32(StrigEventID); -} - -bool PSUB::load_state(FILEIO* state_fio) -{ - close_tape(); - - 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; -// } -// play = state_fio->FgetBool(); -// rec = state_fio->FgetBool(); -// is_wav = state_fio->FgetBool(); -// is_p6t = state_fio->FgetBool(); -// state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1); -// int length_tmp = state_fio->FgetInt32(); -// if(rec) { -// fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY); -// while(length_tmp != 0) { -// uint8_t buffer_tmp[1024]; -// int length_rw = min(length_tmp, (int)sizeof(buffer_tmp)); -// state_fio->Fread(buffer_tmp, length_rw, 1); -// if(fio->IsOpened()) { -// fio->Fwrite(buffer_tmp, length_rw, 1); -// } -// length_tmp -= length_rw; -// } -// } -// CasIntFlag = state_fio->FgetInt32(); -// CasIndex = state_fio->FgetInt32(); -// CasRecv = state_fio->FgetInt32(); -// CasMode = state_fio->FgetInt32(); -// CasBaud = state_fio->FgetInt32(); -// FileBaud = state_fio->FgetInt32(); -// state_fio->Fread(CasData, sizeof(CasData), 1); -// CasLength = state_fio->FgetInt32(); -// CasSkipFlag = state_fio->FgetInt32(); -// kbFlagFunc = state_fio->FgetInt32(); -// kbFlagGraph = state_fio->FgetInt32(); -// kbFlagCtrl = state_fio->FgetInt32(); -// kanaMode = state_fio->FgetInt32(); -// katakana = state_fio->FgetInt32(); -// p6key = state_fio->FgetInt32(); -// stick0 = state_fio->FgetInt32(); -// StrigIntFlag = state_fio->FgetInt32(); -// StrigEventID = state_fio->FgetInt32(); - return true; -} - bool PSUB::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pc6001/psub.h b/source/src/vm/pc6001/psub.h index c0611f342..fa8e66bc7 100644 --- a/source/src/vm/pc6001/psub.h +++ b/source/src/vm/pc6001/psub.h @@ -67,9 +67,7 @@ public: void event_frame(); void event_callback(int event_id, int err); uint32_t get_intr_ack(); - 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_pio(DEVICE* device) diff --git a/source/src/vm/pc6001/sub.cpp b/source/src/vm/pc6001/sub.cpp index 4d6c42592..bbac82910 100644 --- a/source/src/vm/pc6001/sub.cpp +++ b/source/src/vm/pc6001/sub.cpp @@ -387,116 +387,6 @@ void SUB::close_tape() #define STATE_VERSION 1 -#include "../../statesub.h" - -void SUB::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_INT32(p1_out); - DECL_STATE_ENTRY_INT32(p2_in); - DECL_STATE_ENTRY_BOOL(drec_in); - DECL_STATE_ENTRY_BOOL(rxrdy_in); - DECL_STATE_ENTRY_BOOL(update_key); - DECL_STATE_ENTRY_BOOL(rec); - DECL_STATE_ENTRY_BOOL(is_wav); - DECL_STATE_ENTRY_BOOL(is_p6t); - DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path)); - DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path); - DECL_STATE_ENTRY_INT32(prev_command); - DECL_STATE_ENTRY_INT32(baud); - DECL_STATE_ENTRY_INT32(index); - DECL_STATE_ENTRY_BOOL(skip); - DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer)); - - leave_decl_state(); -} - -void SUB::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(p1_out); -// state_fio->FputInt32(p2_in); -// state_fio->FputBool(drec_in); -// state_fio->FputBool(rxrdy_in); -// state_fio->FputBool(update_key); -// state_fio->FputBool(rec); -// state_fio->FputBool(is_wav); -// state_fio->FputBool(is_p6t); -// state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1); -// if(rec && fio->IsOpened()) { -// int length_tmp = (int)fio->Ftell(); -// fio->Fseek(0, FILEIO_SEEK_SET); -// state_fio->FputInt32(length_tmp); -// while(length_tmp != 0) { -// uint8_t buffer_tmp[1024]; -// int length_rw = min(length_tmp, (int)sizeof(buffer_tmp)); -// fio->Fread(buffer_tmp, length_rw, 1); -// state_fio->Fwrite(buffer_tmp, length_rw, 1); -// length_tmp -= length_rw; -// } -// } else { -// state_fio->FputInt32(0); -// } -// state_fio->FputInt32(prev_command); -// state_fio->FputInt32(baud); -// state_fio->FputInt32(index); -// state_fio->FputBool(skip); -// state_fio->Fwrite(buffer, sizeof(buffer), 1); -} - -bool SUB::load_state(FILEIO* state_fio) -{ - close_tape(); - - 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; -// } -// p1_out = state_fio->FgetInt32(); -// p2_in = state_fio->FgetInt32(); -// drec_in = state_fio->FgetBool(); -// rxrdy_in = state_fio->FgetBool(); -// update_key = state_fio->FgetBool(); -// rec = state_fio->FgetBool(); -// is_wav = state_fio->FgetBool(); -// is_p6t = state_fio->FgetBool(); -// state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1); -// int length_tmp = state_fio->FgetInt32(); -// if(rec) { -// fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY); -// while(length_tmp != 0) { -// uint8_t buffer_tmp[1024]; -// int length_rw = min(length_tmp, (int)sizeof(buffer_tmp)); -// state_fio->Fread(buffer_tmp, length_rw, 1); -// if(fio->IsOpened()) { -// fio->Fwrite(buffer_tmp, length_rw, 1); -// } -// length_tmp -= length_rw; -// } -// } -// prev_command = state_fio->FgetInt32(); -// baud = state_fio->FgetInt32(); -// index = state_fio->FgetInt32(); -// skip = state_fio->FgetBool(); -// state_fio->Fread(buffer, sizeof(buffer), 1); - return true; -} - bool SUB::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pc6001/sub.h b/source/src/vm/pc6001/sub.h index 05a4b0135..2401fe409 100644 --- a/source/src/vm/pc6001/sub.h +++ b/source/src/vm/pc6001/sub.h @@ -56,9 +56,7 @@ public: void event_frame(); void event_callback(int event_id, int err); 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_pio(DEVICE* device) diff --git a/source/src/vm/pc6001/timer.cpp b/source/src/vm/pc6001/timer.cpp index b562dcf40..deb4b57fb 100644 --- a/source/src/vm/pc6001/timer.cpp +++ b/source/src/vm/pc6001/timer.cpp @@ -13,7 +13,7 @@ #include "timer.h" #ifndef _PC6001 -#include "memory.h" +#include "./memory.h" #endif #define EVENT_TIMER 0 @@ -281,88 +281,6 @@ void TIMER::update_intr() #define STATE_VERSION 1 -#include "../../statesub.h" - -void TIMER::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT8(IRQ); - DECL_STATE_ENTRY_UINT8(NewIRQ); - DECL_STATE_ENTRY_INT32(timer_id); -#ifndef _PC6001 -#if defined(_PC6601SR) || defined(_PC6001MK2SR) - DECL_STATE_ENTRY_1D_ARRAY(sr_vectors, sizeof(sr_vectors)); - DECL_STATE_ENTRY_UINT8(portFA); - DECL_STATE_ENTRY_UINT8(portFB); -#endif - DECL_STATE_ENTRY_UINT8(portF3); - DECL_STATE_ENTRY_UINT8(portF4); - DECL_STATE_ENTRY_UINT8(portF5); - DECL_STATE_ENTRY_UINT8(portF6); - DECL_STATE_ENTRY_UINT8(portF7); -#endif - - leave_decl_state(); -} -void TIMER::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(IRQ); -// state_fio->FputUint8(NewIRQ); -// state_fio->FputInt32(timer_id); -//#ifndef _PC6001 -//#if defined(_PC6601SR) || defined(_PC6001MK2SR) -// state_fio->Fwrite(sr_vectors, sizeof(sr_vectors), 1); -// state_fio->FputUint8(portFA); -// state_fio->FputUint8(portFB); -//#endif -// state_fio->FputUint8(portF3); -// state_fio->FputUint8(portF4); -// state_fio->FputUint8(portF5); -// state_fio->FputUint8(portF6); -// state_fio->FputUint8(portF7); -//#endif -} - -bool TIMER::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; -// } -// IRQ = state_fio->FgetUint8(); -// NewIRQ = state_fio->FgetUint8(); -// timer_id = state_fio->FgetInt32(); -//#ifndef _PC6001 -//#if defined(_PC6601SR) || defined(_PC6001MK2SR) -// state_fio->Fread(sr_vectors, sizeof(sr_vectors), 1); -// portFA = state_fio->FgetUint8(); -// portFB = state_fio->FgetUint8(); -//#endif -// portF3 = state_fio->FgetUint8(); -// portF4 = state_fio->FgetUint8(); -// portF5 = state_fio->FgetUint8(); -// portF6 = state_fio->FgetUint8(); -// portF7 = state_fio->FgetUint8(); -//#endif - return true; -} - bool TIMER::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pc6001/timer.h b/source/src/vm/pc6001/timer.h index 197f47418..f050867a3 100644 --- a/source/src/vm/pc6001/timer.h +++ b/source/src/vm/pc6001/timer.h @@ -28,7 +28,7 @@ #define SIG_TIMER_IRQ_EXT_INT 7 #ifndef _PC6001 -class MEMORY; +class PC6001_MEMORY; #endif class TIMER : public DEVICE @@ -36,7 +36,7 @@ class TIMER : public DEVICE private: DEVICE *d_cpu, *d_sub; #ifndef _PC6001 - MEMORY *d_mem; + PC6001_MEMORY *d_mem; #endif uint8_t IRQ, NewIRQ; @@ -71,9 +71,7 @@ public: void write_signal(int id, uint32_t data, uint32_t mask); uint32_t get_intr_ack(); void notify_intr_reti(); - 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) @@ -85,7 +83,7 @@ public: d_sub = device; } #ifndef _PC6001 - void set_context_memory(MEMORY* device) + void set_context_memory(PC6001_MEMORY* device) { d_mem = device; } diff --git a/source/src/vm/pc8201/cmt.cpp b/source/src/vm/pc8201/cmt.cpp index 455c548cb..7b98ca553 100644 --- a/source/src/vm/pc8201/cmt.cpp +++ b/source/src/vm/pc8201/cmt.cpp @@ -182,99 +182,6 @@ void CMT::close_tape() #define STATE_VERSION 1 -#include "../../statesub.h" - -void CMT::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_BOOL(is_wav); - DECL_STATE_ENTRY_BOOL(rec); - DECL_STATE_ENTRY_BOOL(remote); - DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path)); - DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path); - - DECL_STATE_ENTRY_INT32(bufcnt); - DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer)); - DECL_STATE_ENTRY_INT32(prev_signal); - DECL_STATE_ENTRY_UINT32(prev_clock); - - 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->FputBool(is_wav); -// state_fio->FputBool(rec); -// state_fio->FputBool(remote); -// state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1); -// if(rec && fio->IsOpened()) { -// int length_tmp = (int)fio->Ftell(); -// fio->Fseek(0, FILEIO_SEEK_SET); -// state_fio->FputInt32(length_tmp); -// while(length_tmp != 0) { -// uint8_t buffer_tmp[1024]; -// int length_rw = min(length_tmp, (int)sizeof(buffer_tmp)); -// fio->Fread(buffer_tmp, length_rw, 1); -// state_fio->Fwrite(buffer_tmp, length_rw, 1); -// length_tmp -= length_rw; -// } -// } else { -// state_fio->FputInt32(0); -// } -// state_fio->FputInt32(bufcnt); -// state_fio->Fwrite(buffer, sizeof(buffer), 1); -// state_fio->FputInt32(prev_signal); -// state_fio->FputUint32(prev_clock); -} - -bool CMT::load_state(FILEIO* state_fio) -{ - close_tape(); - - 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; -// } -// is_wav = state_fio->FgetBool(); -// rec = state_fio->FgetBool(); -// remote = state_fio->FgetBool(); -// state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1); -// int length_tmp = state_fio->FgetInt32(); -// if(rec) { -// fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY); -// while(length_tmp != 0) { -// uint8_t buffer_tmp[1024]; -// int length_rw = min(length_tmp, (int)sizeof(buffer_tmp)); -// state_fio->Fread(buffer_tmp, length_rw, 1); -// if(fio->IsOpened()) { -// fio->Fwrite(buffer_tmp, length_rw, 1); -// } -// length_tmp -= length_rw; -// } -// } -// bufcnt = state_fio->FgetInt32(); -// state_fio->Fread(buffer, sizeof(buffer), 1); -// prev_signal = state_fio->FgetInt32(); -// prev_clock = state_fio->FgetUint32(); - return true; -} - bool CMT::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pc8201/cmt.h b/source/src/vm/pc8201/cmt.h index f8fd198ac..377fb0b48 100644 --- a/source/src/vm/pc8201/cmt.h +++ b/source/src/vm/pc8201/cmt.h @@ -46,9 +46,7 @@ public: void release(); void reset(); 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 rec_tape(const _TCHAR* file_path); diff --git a/source/src/vm/pc8201/keyboard.cpp b/source/src/vm/pc8201/keyboard.cpp index 4fbe852c7..73fa4966f 100644 --- a/source/src/vm/pc8201/keyboard.cpp +++ b/source/src/vm/pc8201/keyboard.cpp @@ -83,53 +83,6 @@ void KEYBOARD::key_down(int code) #define STATE_VERSION 1 -#include "../../statesub.h" - -void KEYBOARD::decl_state() -{ - enter_decl_state(STATE_VERSION); - - DECL_STATE_ENTRY_UINT16(column); - DECL_STATE_ENTRY_BOOL(caps); - DECL_STATE_ENTRY_BOOL(kana); - - 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); - -// state_fio->FputUint16(column); -// state_fio->FputBool(caps); -// state_fio->FputBool(kana); -} - -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; -// } -// column = state_fio->FgetUint16(); -// caps = state_fio->FgetBool(); -// kana = state_fio->FgetBool(); - return true; -} - bool KEYBOARD::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { diff --git a/source/src/vm/pc8201/keyboard.h b/source/src/vm/pc8201/keyboard.h index 31d959d6e..c965c49dd 100644 --- a/source/src/vm/pc8201/keyboard.h +++ b/source/src/vm/pc8201/keyboard.h @@ -35,9 +35,7 @@ public: void initialize(); 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 key_down(int code); diff --git a/source/src/vm/pc8201/lcd.cpp b/source/src/vm/pc8201/lcd.cpp index b766c3011..4bf0f97ac 100644 --- a/source/src/vm/pc8201/lcd.cpp +++ b/source/src/vm/pc8201/lcd.cpp @@ -163,58 +163,6 @@ void LCD::draw_screen() #define STATE_VERSION 1 -#include "../../statesub.h" - -void LCD::decl_state() -{ - enter_decl_state(STATE_VERSION); - - for(int i = 0; i < 10; i++) { - DECL_STATE_ENTRY_2D_ARRAY_MEMBER((seg[i].vram), 4, 50, i); - DECL_STATE_ENTRY_INT32_MEMBER((seg[i].updown), i); - DECL_STATE_ENTRY_INT32_MEMBER((seg[i].disp), i); - DECL_STATE_ENTRY_INT32_MEMBER((seg[i].spg), i); - DECL_STATE_ENTRY_INT32_MEMBER((seg[i].page), i); - DECL_STATE_ENTRY_INT32_MEMBER((seg[i].ofs), i); - DECL_STATE_ENTRY_INT32_MEMBER((seg[i].ofs2), i); - } - DECL_STATE_ENTRY_UINT16(sel); - - leave_decl_state(); -} - -void LCD::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(seg, sizeof(seg), 1); -// state_fio->FputUint16(sel); -} - -bool LCD::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(seg, sizeof(seg), 1); -// sel = state_fio->FgetUint16(); - return true; -} - bool LCD::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { @@ -223,7 +171,16 @@ bool LCD::process_state(FILEIO* state_fio, bool loading) if(!state_fio->StateCheckInt32(this_device_id)) { return false; } - state_fio->StateBuffer(seg, sizeof(seg), 1); + //state_fio->StateBuffer(seg, sizeof(seg), 1); + for(int i = 0; i < 10; i++) { + state_fio->StateBuffer(&(seg[i].vram[0][0]), sizeof(seg[i].vram), 1); + state_fio->StateInt32(seg[i].updown); + state_fio->StateInt32(seg[i].disp); + state_fio->StateInt32(seg[i].spg); + state_fio->StateInt32(seg[i].page); + state_fio->StateInt32(seg[i].ofs); + state_fio->StateInt32(seg[i].ofs2); + } state_fio->StateUint16(sel); return true; } diff --git a/source/src/vm/pc8201/lcd.h b/source/src/vm/pc8201/lcd.h index 0e08a27f8..d7e2fa870 100644 --- a/source/src/vm/pc8201/lcd.h +++ b/source/src/vm/pc8201/lcd.h @@ -40,9 +40,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 function void draw_screen(); diff --git a/source/src/vm/pc8201/memory.cpp b/source/src/vm/pc8201/memory.cpp index 92aecc25a..b2f197ace 100644 --- a/source/src/vm/pc8201/memory.cpp +++ b/source/src/vm/pc8201/memory.cpp @@ -28,7 +28,7 @@ } \ } -void MEMORY::initialize() +void PC8201_MEMORY::initialize() { // init memory memset(ram, 0, sizeof(ram)); @@ -53,7 +53,7 @@ void MEMORY::initialize() delete fio; } -void MEMORY::release() +void PC8201_MEMORY::release() { // save ram image FILEIO* fio = new FILEIO(); @@ -64,25 +64,25 @@ void MEMORY::release() delete fio; } -void MEMORY::reset() +void PC8201_MEMORY::reset() { sio = bank = 0; update_bank(); } -void MEMORY::write_data8(uint32_t addr, uint32_t data) +void PC8201_MEMORY::write_data8(uint32_t addr, uint32_t data) { addr &= 0xffff; wbank[addr >> 12][addr & 0xfff] = data; } -uint32_t MEMORY::read_data8(uint32_t addr) +uint32_t PC8201_MEMORY::read_data8(uint32_t addr) { addr &= 0xffff; return rbank[addr >> 12][addr & 0xfff]; } -void MEMORY::write_io8(uint32_t addr, uint32_t data) +void PC8201_MEMORY::write_io8(uint32_t addr, uint32_t data) { switch(addr & 0xf0) { case 0x90: @@ -104,13 +104,13 @@ void MEMORY::write_io8(uint32_t addr, uint32_t data) } } -uint32_t MEMORY::read_io8(uint32_t addr) +uint32_t PC8201_MEMORY::read_io8(uint32_t addr) { // $A0: bank status return (sio & 0xc0) | (bank & 0xf); } -void MEMORY::update_bank() +void PC8201_MEMORY::update_bank() { switch(bank & 3) { case 0: @@ -144,57 +144,7 @@ void MEMORY::update_bank() #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_UINT8(sio); - DECL_STATE_ENTRY_UINT8(bank); - - 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->FputUint8(sio); -// state_fio->FputUint8(bank); -} - -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); -// sio = state_fio->FgetUint8(); -// bank = state_fio->FgetUint8(); - - // post process - update_bank(); - return true; -} - -bool MEMORY::process_state(FILEIO* state_fio, bool loading) +bool PC8201_MEMORY::process_state(FILEIO* state_fio, bool loading) { if(!state_fio->StateCheckUint32(STATE_VERSION)) { return false; diff --git a/source/src/vm/pc8201/memory.h b/source/src/vm/pc8201/memory.h index f35751ccf..26869aaeb 100644 --- a/source/src/vm/pc8201/memory.h +++ b/source/src/vm/pc8201/memory.h @@ -7,14 +7,14 @@ [ memory ] */ -#ifndef _MEMORY_H_ -#define _MEMORY_H_ +#ifndef _PC8201_MEMORY_H_ +#define _PC8201_MEMORY_H_ #include "../vm.h" #include "../../emu.h" #include "../device.h" -class MEMORY : public DEVICE +class PC8201_MEMORY : public DEVICE { private: DEVICE *d_cmt, *d_drec, *d_rtc; @@ -31,11 +31,11 @@ private: void update_bank(); public: - MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) + PC8201_MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) { set_device_name(_T("Memory Bus")); } - ~MEMORY() {} + ~PC8201_MEMORY() {} // common functions void initialize(); @@ -45,9 +45,7 @@ public: uint32_t read_data8(uint32_t addr); 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_cmt(DEVICE* device) diff --git a/source/src/vm/pc8201/pc8201.cpp b/source/src/vm/pc8201/pc8201.cpp index e8ade1e89..e2055eca0 100644 --- a/source/src/vm/pc8201/pc8201.cpp +++ b/source/src/vm/pc8201/pc8201.cpp @@ -27,7 +27,7 @@ #include "cmt.h" #include "keyboard.h" #include "lcd.h" -#include "memory.h" +#include "./memory.h" // ---------------------------------------------------------------------------- // initialize @@ -53,7 +53,7 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) cmt = new CMT(this, emu); keyboard = new KEYBOARD(this, emu); lcd = new LCD(this, emu); - memory = new MEMORY(this, emu); + memory = new PC8201_MEMORY(this, emu); // set contexts event->set_context_cpu(cpu); @@ -106,7 +106,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu) for(DEVICE* device = first_device; device; device = device->next_device) { device->initialize(); } - decl_state(); rtc->write_signal(SIG_UPD1990A_STB, 0, 0); } @@ -347,76 +346,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) -{ -#if defined(_PC8201) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_8201_HEAD")), csp_logger); -#elif defined(_PC8201A) - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_8201A_HEAD")), csp_logger); -#else - state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_8201_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/pc8201/pc8201.h b/source/src/vm/pc8201/pc8201.h index ca5b62917..d5e30d29d 100644 --- a/source/src/vm/pc8201/pc8201.h +++ b/source/src/vm/pc8201/pc8201.h @@ -66,7 +66,7 @@ class UPD1990A; class CMT; class KEYBOARD; class LCD; -class MEMORY; +class PC8201_MEMORY; class VM :public VM_TEMPLATE { @@ -87,7 +87,7 @@ protected: CMT* cmt; KEYBOARD* keyboard; LCD* lcd; - MEMORY* memory; + PC8201_MEMORY* memory; public: // ---------------------------------------- @@ -145,9 +145,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