OSDN Git Service

[VM][PC9801] Enable to build PC-9801 with upstream 2018-10-05.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 14 Oct 2018 09:16:24 +0000 (18:16 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 14 Oct 2018 09:16:24 +0000 (18:16 +0900)
24 files changed:
source/src/vm/pc9801/cmt.cpp
source/src/vm/pc9801/cmt.h
source/src/vm/pc9801/cpureg.cpp
source/src/vm/pc9801/cpureg.h
source/src/vm/pc9801/display.cpp
source/src/vm/pc9801/display.h
source/src/vm/pc9801/dmareg.cpp
source/src/vm/pc9801/dmareg.h
source/src/vm/pc9801/floppy.cpp
source/src/vm/pc9801/floppy.h
source/src/vm/pc9801/fmsound.cpp
source/src/vm/pc9801/fmsound.h
source/src/vm/pc9801/joystick.cpp
source/src/vm/pc9801/joystick.h
source/src/vm/pc9801/keyboard.cpp
source/src/vm/pc9801/keyboard.h
source/src/vm/pc9801/membus.cpp
source/src/vm/pc9801/membus.h
source/src/vm/pc9801/mouse.cpp
source/src/vm/pc9801/mouse.h
source/src/vm/pc9801/pc9801.cpp
source/src/vm/pc9801/pc9801.h
source/src/vm/pc9801/sasi.cpp
source/src/vm/pc9801/sasi.h

index bbc1e6c..4196372 100644 (file)
@@ -106,31 +106,19 @@ void CMT::release_tape()
 
 #define STATE_VERSION  1
 
-void CMT::save_state(FILEIO* state_fio)
+bool CMT::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputInt32(bufcnt);
-       state_fio->Fwrite(buffer, sizeof(buffer), 1);
-       state_fio->FputBool(play);
-       state_fio->FputBool(rec);
-       state_fio->FputBool(remote);
-}
-
-bool CMT::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       bufcnt = state_fio->FgetInt32();
-       state_fio->Fread(buffer, sizeof(buffer), 1);
-       play = state_fio->FgetBool();
-       rec = state_fio->FgetBool();
-       remote = state_fio->FgetBool();
+       state_fio->StateInt32(bufcnt);
+       state_fio->StateBuffer(buffer, sizeof(buffer), 1);
+       state_fio->StateBool(play);
+       state_fio->StateBool(rec);
+       state_fio->StateBool(remote);
        return true;
 }
 
index 338396f..2fd5172 100644 (file)
@@ -48,8 +48,7 @@ public:
        void reset();
        void write_io8(uint32_t addr, uint32_t data);
        void write_signal(int id, uint32_t data, uint32_t mask);
-       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_sio(DEVICE* device)
index c589692..c28d0d1 100644 (file)
@@ -106,42 +106,14 @@ uint32_t CPUREG::read_io8(uint32_t addr)
 
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void CPUREG::decl_state()
+bool CPUREG::process_state(FILEIO* state_fio, bool loading)
 {
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_BOOL(nmi_enabled);
-       
-       leave_decl_state();
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(nmi_enabled);
+       return true;
 }
-
-void CPUREG::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_enabled);
-}
-
-bool CPUREG::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_enabled = state_fio->FgetBool();
-       return true;
-}
-
index e1209bc..77982b6 100644 (file)
@@ -45,9 +45,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
 #if defined(SUPPORT_32BIT_ADDRESS)
index 383be19..7b575b6 100644 (file)
@@ -2576,252 +2576,142 @@ void DISPLAY::draw_gfx_screen()
 
 #define STATE_VERSION  3
 
-#include "../statesub.h"
-
-#define DECL_STATE_ENTRY_EGCWORD_T(foo) { \
-               DECL_STATE_ENTRY_UINT16((foo.w));               \
-       }
-
-#define DECL_STATE_ENTRY_EGCQUAD_T(foo) { \
-               DECL_STATE_ENTRY_UINT64((foo.q));               \
-       }
-
-
-void DISPLAY::decl_state()
-{
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_1D_ARRAY(tvram, sizeof(tvram));
-       DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(tvram, sizeof(tvram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
 #if defined(SUPPORT_2ND_VRAM) && !defined(SUPPORT_HIRESO)
-       DECL_STATE_ENTRY_UINT8(vram_disp_sel);
-       DECL_STATE_ENTRY_UINT8(vram_draw_sel);
-#endif
-       DECL_STATE_ENTRY_1D_ARRAY(palette_gfx8, sizeof(palette_gfx8) / sizeof(scrntype_t)); // ToDo
-       DECL_STATE_ENTRY_1D_ARRAY(digipal, sizeof(digipal));
+       state_fio->StateUint8(vram_disp_sel);
+       state_fio->StateUint8(vram_draw_sel);
+#endif
+       //state_fio->StateBuffer(palette_gfx8, sizeof(palette_gfx8), 1);
+       if(loading) {
+               for(int i = 0; i < (sizeof(palette_gfx8) / sizeof(scrntype_t)); i++) {
+                       uint8_t r, g, b;
+                       r = state_fio->FgetUint8();
+                       g = state_fio->FgetUint8();
+                       b = state_fio->FgetUint8();
+                       palette_gfx8[i] = RGB_COLOR(r, g, b);
+               }
+       } else {
+               for(int i = 0; i < (sizeof(palette_gfx8) / sizeof(scrntype_t)); i++) {
+                       uint8_t r, g, b;
+                       r = R_OF_COLOR(palette_gfx8[i]);
+                       g = G_OF_COLOR(palette_gfx8[i]);
+                       b = B_OF_COLOR(palette_gfx8[i]);
+                       state_fio->FputUint8(r);
+                       state_fio->FputUint8(g);
+                       state_fio->FputUint8(b);
+               }
+       }
+       state_fio->StateBuffer(digipal, sizeof(digipal), 1);
 #if defined(SUPPORT_16_COLORS)
-       DECL_STATE_ENTRY_1D_ARRAY(palette_gfx16, sizeof(palette_gfx16) / sizeof(scrntype_t));
-       DECL_STATE_ENTRY_2D_ARRAY(anapal, 16, 3);
-       DECL_STATE_ENTRY_UINT8(anapal_sel);
-#endif
-       DECL_STATE_ENTRY_UINT8(crtv);
-       DECL_STATE_ENTRY_1D_ARRAY(scroll, sizeof(scroll));
-       DECL_STATE_ENTRY_1D_ARRAY(modereg1, sizeof(modereg1));
+       //state_fio->StateBuffer(palette_gfx16, sizeof(palette_gfx16), 1);      
+       if(loading) {
+               for(int i = 0; i < (sizeof(palette_gfx16) / sizeof(scrntype_t)); i++) {
+                       uint8_t r, g, b;
+                       r = state_fio->FgetUint8();
+                       g = state_fio->FgetUint8();
+                       b = state_fio->FgetUint8();
+                       palette_gfx16[i] = RGB_COLOR(r, g, b);
+               }
+       } else {
+               for(int i = 0; i < (sizeof(palette_gfx16) / sizeof(scrntype_t)); i++) {
+                       uint8_t r, g, b;
+                       r = R_OF_COLOR(palette_gfx16[i]);
+                       g = G_OF_COLOR(palette_gfx16[i]);
+                       b = B_OF_COLOR(palette_gfx16[i]);
+                       state_fio->FputUint8(r);
+                       state_fio->FputUint8(g);
+                       state_fio->FputUint8(b);
+               }
+       }
+       state_fio->StateBuffer(anapal, sizeof(anapal), 1);
+       state_fio->StateUint8(anapal_sel);
+#endif
+       state_fio->StateUint8(crtv);
+       state_fio->StateBuffer(scroll, sizeof(scroll), 1);
+       state_fio->StateBuffer(modereg1, sizeof(modereg1), 1);
 #if defined(SUPPORT_16_COLORS)
-       DECL_STATE_ENTRY_1D_ARRAY(modereg2, sizeof(modereg2));
+       state_fio->StateBuffer(modereg2, sizeof(modereg2), 1);
 #endif
 #if defined(SUPPORT_GRCG)
-       DECL_STATE_ENTRY_UINT8(grcg_mode);
-       DECL_STATE_ENTRY_UINT8(grcg_tile_ptr);
-       DECL_STATE_ENTRY_1D_ARRAY(grcg_tile, sizeof(grcg_tile));
-#endif
-#if defined(SUPPORT_EGC)
-       DECL_STATE_ENTRY_UINT16(egc_access);
-       DECL_STATE_ENTRY_UINT16(egc_fgbg);
-       DECL_STATE_ENTRY_UINT16(egc_ope);
-       DECL_STATE_ENTRY_UINT16(egc_fg);
-       DECL_STATE_ENTRY_UINT16(egc_mask.w);
-       DECL_STATE_ENTRY_UINT16(egc_bg);
-       DECL_STATE_ENTRY_UINT16(egc_sft);
-       DECL_STATE_ENTRY_UINT16(egc_leng);
-       DECL_STATE_ENTRY_EGCQUAD_T(egc_lastvram);
-       DECL_STATE_ENTRY_EGCQUAD_T(egc_patreg);
-       DECL_STATE_ENTRY_EGCQUAD_T(egc_fgc);
-       DECL_STATE_ENTRY_EGCQUAD_T(egc_bgc);
-       DECL_STATE_ENTRY_INT32(egc_func);
-       DECL_STATE_ENTRY_UINT32(egc_remain);
-       DECL_STATE_ENTRY_UINT32(egc_stack);
-//     int inptr_ofs = egc_inptr - egc_buf;
-//     int outptr_ofs = egc_outptr - egc_buf;
-       DECL_STATE_ENTRY_INT32(tmp_inptr_ofs);
-       DECL_STATE_ENTRY_INT32(tmp_outptr_ofs);
-       
-       DECL_STATE_ENTRY_EGCWORD_T(egc_mask2);
-       DECL_STATE_ENTRY_EGCWORD_T(egc_srcmask);
-       
-       DECL_STATE_ENTRY_UINT8(egc_srcbit);
-       DECL_STATE_ENTRY_UINT8(egc_dstbit);
-       DECL_STATE_ENTRY_UINT8(egc_sft8bitl);
-       DECL_STATE_ENTRY_UINT8(egc_sft8bitr);
-       DECL_STATE_ENTRY_1D_ARRAY(egc_buf, sizeof(egc_buf));
-       DECL_STATE_ENTRY_EGCQUAD_T(egc_vram_src);
-       DECL_STATE_ENTRY_EGCQUAD_T(egc_vram_data);
-#endif
-       DECL_STATE_ENTRY_UINT16(font_code);
-       DECL_STATE_ENTRY_UINT8(font_line);
-////   DECL_STATE_ENTRY_UINT16(font_lr);
-       leave_decl_state();
-}
-
-void DISPLAY::save_state(FILEIO* state_fio)
-{
-#if defined(SUPPORT_EGC)
-       tmp_inptr_ofs = (int)(egc_inptr - egc_buf);
-       tmp_outptr_ofs = (int)(egc_outptr - egc_buf);
+       state_fio->StateUint8(grcg_mode);
+       state_fio->StateUint8(grcg_tile_ptr);
+       state_fio->StateBuffer(grcg_tile, sizeof(grcg_tile), 1);
 #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(tvram, sizeof(tvram), 1);
-//     state_fio->Fwrite(vram, sizeof(vram), 1);
-//#if defined(SUPPORT_2ND_VRAM) && !defined(SUPPORT_HIRESO)
-//     state_fio->FputUint8(vram_disp_sel);
-//     state_fio->FputUint8(vram_draw_sel);
-//#endif
-//     state_fio->Fwrite(palette_gfx8, sizeof(palette_gfx8), 1);
-//     state_fio->Fwrite(digipal, sizeof(digipal), 1);
-//#if defined(SUPPORT_16_COLORS)
-//     state_fio->Fwrite(palette_gfx16, sizeof(palette_gfx16), 1);
-//     state_fio->Fwrite(anapal, sizeof(anapal), 1);
-//     state_fio->FputUint8(anapal_sel);
-//#endif
-//     state_fio->FputUint8(crtv);
-//     state_fio->Fwrite(scroll, sizeof(scroll), 1);
-//     state_fio->Fwrite(modereg1, sizeof(modereg1), 1);
-//#if defined(SUPPORT_16_COLORS)
-//     state_fio->Fwrite(modereg2, sizeof(modereg2), 1);
-//#endif
-//#if defined(SUPPORT_GRCG)
-//     state_fio->FputUint8(grcg_mode);
-//     state_fio->FputUint8(grcg_tile_ptr);
-//     state_fio->Fwrite(grcg_tile, sizeof(grcg_tile), 1);
-//#endif
-//#if defined(SUPPORT_EGC)
-//     state_fio->FputUint16(egc_access);
-//     state_fio->FputUint16(egc_fgbg);
-//     state_fio->FputUint16(egc_ope);
-//     state_fio->FputUint16(egc_fg);
-//     state_fio->FputUint16(egc_mask.w);
-//     state_fio->FputUint16(egc_bg);
-//     state_fio->FputUint16(egc_sft);
-//     state_fio->FputUint16(egc_leng);
-//     state_fio->FputUint64(egc_lastvram.q);
-//     state_fio->FputUint64(egc_patreg.q);
-//     state_fio->FputUint64(egc_fgc.q);
-//     state_fio->FputUint64(egc_bgc.q);
-//     state_fio->FputInt32(egc_func);
-//     state_fio->FputUint32(egc_remain);
-//     state_fio->FputUint32(egc_stack);
-//     int inptr_ofs = egc_inptr - egc_buf;
-//     int outptr_ofs = egc_outptr - egc_buf;
-//     state_fio->FputInt32(inptr_ofs);
-//     state_fio->FputInt32(outptr_ofs);
-//     state_fio->FputUint16(egc_mask2.w);
-//     state_fio->FputUint16(egc_srcmask.w);
-//     state_fio->FputUint8(egc_srcbit);
-//     state_fio->FputUint8(egc_dstbit);
-//     state_fio->FputUint8(egc_sft8bitl);
-//     state_fio->FputUint8(egc_sft8bitr);
-//     state_fio->Fwrite(egc_buf, sizeof(egc_buf), 1);
-//     state_fio->FputUint64(egc_vram_src.q);
-//     state_fio->FputUint64(egc_vram_data.q);
-//#endif
-//     state_fio->FputUint16(font_code);
-//     state_fio->FputUint8(font_line);
-//     state_fio->FputUint16(font_lr);
-}
-
-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(tvram, sizeof(tvram), 1);
-//     state_fio->Fread(vram, sizeof(vram), 1);
-//#if defined(SUPPORT_2ND_VRAM) && !defined(SUPPORT_HIRESO)
-//     vram_disp_sel = state_fio->FgetUint8();
-//     vram_draw_sel = state_fio->FgetUint8();
-//#endif
-//     state_fio->Fread(palette_gfx8, sizeof(palette_gfx8), 1);
-//     state_fio->Fread(digipal, sizeof(digipal), 1);
-//#if defined(SUPPORT_16_COLORS)
-//     state_fio->Fread(palette_gfx16, sizeof(palette_gfx16), 1);
-//     state_fio->Fread(anapal, sizeof(anapal), 1);
-//     anapal_sel = state_fio->FgetUint8();
-//#endif
-//     crtv = state_fio->FgetUint8();
-//     state_fio->Fread(scroll, sizeof(scroll), 1);
-//     state_fio->Fread(modereg1, sizeof(modereg1), 1);
-//#if defined(SUPPORT_16_COLORS)
-//     state_fio->Fread(modereg2, sizeof(modereg2), 1);
-//#endif
-//#if defined(SUPPORT_GRCG)
-//     grcg_mode = state_fio->FgetUint8();
-//     grcg_tile_ptr = state_fio->FgetUint8();
-//     state_fio->Fread(grcg_tile, sizeof(grcg_tile), 1);
-//#endif
-//#if defined(SUPPORT_EGC)
-//     egc_access = state_fio->FgetUint16();
-//     egc_fgbg = state_fio->FgetUint16();
-//     egc_ope = state_fio->FgetUint16();
-//     egc_fg = state_fio->FgetUint16();
-//     egc_mask.w = state_fio->FgetUint16();
-//     egc_bg = state_fio->FgetUint16();
-//     egc_sft = state_fio->FgetUint16();
-//     egc_leng = state_fio->FgetUint16();
-//     egc_lastvram.q = state_fio->FgetUint64();
-//     egc_patreg.q = state_fio->FgetUint64();
-//     egc_fgc.q = state_fio->FgetUint64();
-//     egc_bgc.q = state_fio->FgetUint64();
-//     egc_func = state_fio->FgetInt32();
-//     egc_remain = state_fio->FgetUint32();
-//     egc_stack = state_fio->FgetUint32();
-//     int inptr_ofs = state_fio->FgetInt32();
-//     int outptr_ofs = state_fio->FgetInt32();
-//     egc_inptr = egc_buf + inptr_ofs;
-//     egc_outptr = egc_buf + outptr_ofs;
-//     egc_mask2.w = state_fio->FgetUint16();
-//     egc_srcmask.w = state_fio->FgetUint16();
-//     egc_srcbit = state_fio->FgetUint8();
-//     egc_dstbit = state_fio->FgetUint8();
-//     egc_sft8bitl = state_fio->FgetUint8();
-//     egc_sft8bitr = state_fio->FgetUint8();
-//     state_fio->Fread(egc_buf, sizeof(egc_buf), 1);
-//     egc_vram_src.q = state_fio->FgetUint64();
-//     egc_vram_data.q = state_fio->FgetUint64();
-//#endif
-//     font_code = state_fio->FgetUint16();
-//     font_line = state_fio->FgetUint8();
-//     font_lr = state_fio->FgetUint16();
-       
-       // post process
 #if defined(SUPPORT_EGC)
-       egc_inptr = egc_buf + tmp_inptr_ofs;
-       egc_outptr = egc_buf + tmp_outptr_ofs;
-#endif
+       state_fio->StateUint16(egc_access);
+       state_fio->StateUint16(egc_fgbg);
+       state_fio->StateUint16(egc_ope);
+       state_fio->StateUint16(egc_fg);
+       state_fio->StateUint16(egc_mask.w);
+       state_fio->StateUint16(egc_bg);
+       state_fio->StateUint16(egc_sft);
+       state_fio->StateUint16(egc_leng);
+       state_fio->StateUint64(egc_lastvram.q);
+       state_fio->StateUint64(egc_patreg.q);
+       state_fio->StateUint64(egc_fgc.q);
+       state_fio->StateUint64(egc_bgc.q);
+       state_fio->StateInt32(egc_func);
+       state_fio->StateUint32(egc_remain);
+       state_fio->StateUint32(egc_stack);
+       if(loading) {
+               int inptr_ofs = state_fio->FgetInt32_LE();
+               int outptr_ofs = state_fio->FgetInt32_LE();
+               egc_inptr = egc_buf + inptr_ofs;
+               egc_outptr = egc_buf + outptr_ofs;
+       } else {
+               int inptr_ofs = egc_inptr - egc_buf;
+               int outptr_ofs = egc_outptr - egc_buf;
+               state_fio->FputInt32_LE(inptr_ofs);
+               state_fio->FputInt32_LE(outptr_ofs);
+       }
+       state_fio->StateUint16(egc_mask2.w);
+       state_fio->StateUint16(egc_srcmask.w);
+       state_fio->StateUint8(egc_srcbit);
+       state_fio->StateUint8(egc_dstbit);
+       state_fio->StateUint8(egc_sft8bitl);
+       state_fio->StateUint8(egc_sft8bitr);
+       state_fio->StateBuffer(egc_buf, sizeof(egc_buf), 1);
+       state_fio->StateUint64(egc_vram_src.q);
+       state_fio->StateUint64(egc_vram_data.q);
+#endif
+       state_fio->StateUint16(font_code);
+       state_fio->StateUint8(font_line);
+//     state_fio->StateUint16(font_lr);
+       
+       // post process
 #if defined(SUPPORT_2ND_VRAM) && !defined(SUPPORT_HIRESO)
-       if(vram_disp_sel & 1) {
-               vram_disp_b = vram + 0x28000;
-               vram_disp_r = vram + 0x30000;
-               vram_disp_g = vram + 0x38000;
+       if(loading) {
+               if(vram_disp_sel & 1) {
+                       vram_disp_b = vram + 0x28000;
+                       vram_disp_r = vram + 0x30000;
+                       vram_disp_g = vram + 0x38000;
 #if defined(SUPPORT_16_COLORS)
-               vram_disp_e = vram + 0x20000;
+                       vram_disp_e = vram + 0x20000;
 #endif
-       } else {
-               vram_disp_b = vram + 0x08000;
-               vram_disp_r = vram + 0x10000;
-               vram_disp_g = vram + 0x18000;
+               } else {
+                       vram_disp_b = vram + 0x08000;
+                       vram_disp_r = vram + 0x10000;
+                       vram_disp_g = vram + 0x18000;
 #if defined(SUPPORT_16_COLORS)
-               vram_disp_e = vram + 0x00000;
+                       vram_disp_e = vram + 0x00000;
 #endif
-       }
-       if(vram_draw_sel & 1) {
-               vram_draw = vram + 0x20000;
-       } else {
-               vram_draw = vram + 0x00000;
-       }
+               }
+               if(vram_draw_sel & 1) {
+                       vram_draw = vram + 0x20000;
+               } else {
+                       vram_draw = vram + 0x00000;
+               }
+       }
 #endif
-       return true;
+       return true;
 }
 
index 0f0e9ba..ae8eff5 100644 (file)
@@ -219,9 +219,7 @@ public:
        void write_dma_io16(uint32_t addr, uint32_t data);
        uint32_t read_dma_io8(uint32_t addr);
        uint32_t read_dma_io16(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_pic(DEVICE *device)
index 236da03..56eabe9 100644 (file)
@@ -82,39 +82,15 @@ uint32_t DMAREG::read_io8(uint32_t addr)
 /*
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void DMAREG::decl_state()
+bool DMAREG::process_state(FILEIO* state_fio, bool loading)
 {
-       enter_decl_state(STATE_VERSION);
-       
-       leave_decl_state();
-}
-
-void DMAREG::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);
-       
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       return true;
 }
 
-bool DMAREG::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;
-//     }
-       return true;
-}
 */
index ea107de..ea3335a 100644 (file)
@@ -33,8 +33,7 @@ public:
        // common functions
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
-//     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_dma(DEVICE* device)
index 2248ed8..fa2bae8 100644 (file)
@@ -319,43 +319,25 @@ void FLOPPY::event_callback(int event_id, int err)
 
 #define STATE_VERSION  1
 
-void FLOPPY::save_state(FILEIO* state_fio)
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-#if defined(SUPPORT_2HD_FDD_IF)
-       state_fio->FputUint8(ctrlreg_2hd);
-#endif
-#if defined(SUPPORT_2DD_FDD_IF)
-       state_fio->FputUint8(ctrlreg_2dd);
-#endif
-#if defined(SUPPORT_2HD_2DD_FDD_IF)
-       state_fio->FputUint8(ctrlreg);
-       state_fio->FputUint8(modereg);
-#endif
-       state_fio->FputInt32(timer_id);
-}
-
-bool FLOPPY::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
 #if defined(SUPPORT_2HD_FDD_IF)
-       ctrlreg_2hd = state_fio->FgetUint8();
+       state_fio->StateUint8(ctrlreg_2hd);
 #endif
 #if defined(SUPPORT_2DD_FDD_IF)
-       ctrlreg_2dd = state_fio->FgetUint8();
+       state_fio->StateUint8(ctrlreg_2dd);
 #endif
 #if defined(SUPPORT_2HD_2DD_FDD_IF)
-       ctrlreg = state_fio->FgetUint8();
-       modereg = state_fio->FgetUint8();
+       state_fio->StateUint8(ctrlreg);
+       state_fio->StateUint8(modereg);
 #endif
-       timer_id = state_fio->FgetInt32();
+       state_fio->StateInt32(timer_id);
        return true;
 }
 
index 1149106..4cc7a24 100644 (file)
@@ -71,8 +71,7 @@ public:
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
        void event_callback(int event_id, int err);
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
 #if defined(SUPPORT_2HD_FDD_IF)
index 6135a8a..941bb59 100644 (file)
@@ -84,23 +84,15 @@ uint32_t FMSOUND::read_io8(uint32_t addr)
 #ifdef SUPPORT_PC98_OPNA
 #define STATE_VERSION  1
 
-void FMSOUND::save_state(FILEIO* state_fio)
+bool FMSOUND::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputUint8(mask);
-}
-
-bool FMSOUND::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       mask = state_fio->FgetUint8();
+       state_fio->StateUint8(mask);
        return true;
 }
 #endif
index e3dcd1c..f2aff1c 100644 (file)
@@ -50,8 +50,7 @@ public:
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
 #ifdef SUPPORT_PC98_OPNA
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
 #endif
        
        // unique function
index ff7ba90..8ffe422 100644 (file)
@@ -43,23 +43,15 @@ void JOYSTICK::event_frame()
 
 #define STATE_VERSION  1
 
-void JOYSTICK::save_state(FILEIO* state_fio)
+bool JOYSTICK::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputUint8(select);
-}
-
-bool JOYSTICK::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       select = state_fio->FgetUint8();
+       state_fio->StateUint8(select);
        return true;
 }
 
index b2eeeda..22a9e38 100644 (file)
@@ -45,8 +45,7 @@ public:
        void initialize();
        void write_signal(int id, uint32_t data, uint32_t mask);
        void event_frame();
-       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_opn(DEVICE* device)
index e0061c6..d6107ba 100644 (file)
@@ -85,27 +85,17 @@ void KEYBOARD::key_up(int code)
 
 #define STATE_VERSION  1
 
-void KEYBOARD::save_state(FILEIO* state_fio)
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputBool(kana);
-       state_fio->FputBool(caps);
-       state_fio->Fwrite(flag, sizeof(flag), 1);
-}
-
-bool KEYBOARD::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       kana = state_fio->FgetBool();
-       caps = state_fio->FgetBool();
-       state_fio->Fread(flag, sizeof(flag), 1);
+       state_fio->StateBool(kana);
+       state_fio->StateBool(caps);
+       state_fio->StateBuffer(flag, sizeof(flag), 1);
        return true;
 }
 
index 72c5a04..b3f99f8 100644 (file)
@@ -44,8 +44,7 @@ public:
        // common functions
        void initialize();
        void reset();
-       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_sio(DEVICE* device)
index 88dad9f..485d041 100644 (file)
@@ -535,172 +535,73 @@ void MEMBUS::update_nec_ems()
 
 #define STATE_VERSION  4
 
-#include "../statesub.h"
-
-void MEMBUS::decl_state()
+bool MEMBUS::process_state(FILEIO* state_fio, bool loading)
 {
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
 #if defined(SUPPORT_BIOS_RAM)
-       DECL_STATE_ENTRY_1D_ARRAY(bios_ram, sizeof(bios_ram));
-       DECL_STATE_ENTRY_BOOL(bios_ram_selected);
+       state_fio->StateBuffer(bios_ram, sizeof(bios_ram), 1);
+       state_fio->StateBool(bios_ram_selected);
 #endif
 #if defined(SUPPORT_ITF_ROM)
-       DECL_STATE_ENTRY_BOOL(itf_selected);
+       state_fio->StateBool(itf_selected);
 #endif
 #if !defined(SUPPORT_HIRESO)
-//     DECL_STATE_ENTRY_1D_ARRAY(sound_bios_ram, sizeof(sound_bios_ram), 1);
-       DECL_STATE_ENTRY_BOOL(sound_bios_selected);
-//     DECL_STATE_ENTRY_BOOL(sound_bios_ram_selected);
+//     state_fio->StateBuffer(sound_bios_ram, sizeof(sound_bios_ram), 1);
+       state_fio->StateBool(sound_bios_selected);
+//     state_fio->StateBool(sound_bios_ram_selected);
 #if defined(SUPPORT_SASI_IF)
-       DECL_STATE_ENTRY_1D_ARRAY(sasi_bios_ram, sizeof(sasi_bios_ram));
-       DECL_STATE_ENTRY_BOOL(sasi_bios_selected);
-       DECL_STATE_ENTRY_BOOL(sasi_bios_ram_selected);
+       state_fio->StateBuffer(sasi_bios_ram, sizeof(sasi_bios_ram), 1);
+       state_fio->StateBool(sasi_bios_selected);
+       state_fio->StateBool(sasi_bios_ram_selected);
 #endif
 #if defined(SUPPORT_SCSI_IF)
-       DECL_STATE_ENTRY_1D_ARRAY(scsi_bios_ram, sizeof(scsi_bios_ram));
-       DECL_STATE_ENTRY_BOOL(scsi_bios_selected);
-       DECL_STATE_ENTRY_BOOL(scsi_bios_ram_selected);
+       state_fio->StateBuffer(scsi_bios_ram, sizeof(scsi_bios_ram), 1);
+       state_fio->StateBool(scsi_bios_selected);
+       state_fio->StateBool(scsi_bios_ram_selected);
 #endif
 #if defined(SUPPORT_IDE_IF)
-//     DECL_STATE_ENTRY_1D_ARRAY(ide_bios_ram, sizeof(ide_bios_ram), 1);
-       DECL_STATE_ENTRY_BOOL(ide_bios_selected);
-//     DECL_STATE_ENTRY_BOOL(ide_bios_ram_selected);
+//     state_fio->StateBuffer(ide_bios_ram, sizeof(ide_bios_ram), 1);
+       state_fio->StateBool(ide_bios_selected);
+//     state_fio->StateBool(ide_bios_ram_selected);
 #endif
 #if defined(SUPPORT_NEC_EMS)
-       DECL_STATE_ENTRY_1D_ARRAY(nec_ems, sizeof(nec_ems));
-       DECL_STATE_ENTRY_BOOL(nec_ems_selected);
+       state_fio->StateBuffer(nec_ems, sizeof(nec_ems), 1);
+       state_fio->StateBool(nec_ems_selected);
 #endif
 #endif
 #if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
-       DECL_STATE_ENTRY_UINT8(dma_access_ctrl);
-       DECL_STATE_ENTRY_UINT32(window_80000h);
-       DECL_STATE_ENTRY_UINT32(window_a0000h);
-#endif
-       leave_decl_state();
-
-       // ToDo: Helper.
-//     MEMORY::decl_state();
-}
-
-void MEMBUS::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);
-//#if defined(SUPPORT_BIOS_RAM)
-//     state_fio->Fwrite(bios_ram, sizeof(bios_ram), 1);
-//     state_fio->FputBool(bios_ram_selected);
-//#endif
-//#if defined(SUPPORT_ITF_ROM)
-//     state_fio->FputBool(itf_selected);
-//#endif
-//#if !defined(SUPPORT_HIRESO)
-////   state_fio->Fwrite(sound_bios_ram, sizeof(sound_bios_ram), 1);
-//     state_fio->FputBool(sound_bios_selected);
-////   state_fio->FputBool(sound_bios_ram_selected);
-//#if defined(SUPPORT_SASI_IF)
-//     state_fio->Fwrite(sasi_bios_ram, sizeof(sasi_bios_ram), 1);
-//     state_fio->FputBool(sasi_bios_selected);
-//     state_fio->FputBool(sasi_bios_ram_selected);
-//#endif
-//#if defined(SUPPORT_SCSI_IF)
-//     state_fio->Fwrite(scsi_bios_ram, sizeof(scsi_bios_ram), 1);
-//     state_fio->FputBool(scsi_bios_selected);
-//     state_fio->FputBool(scsi_bios_ram_selected);
-//#endif
-//#if defined(SUPPORT_IDE_IF)
-//     state_fio->Fwrite(ide_bios_ram, sizeof(ide_bios_ram), 1);
-//     state_fio->FputBool(ide_bios_selected);
-//     state_fio->FputBool(ide_bios_ram_selected);
-//#endif
-//#if defined(SUPPORT_NEC_EMS)
-//     state_fio->Fwrite(nec_ems, sizeof(nec_ems), 1);
-//     state_fio->FputBool(nec_ems_selected);
-//#endif
-//#endif
-//#if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
-//     state_fio->FputUint8(dma_access_ctrl);
-//     state_fio->FputInt32(window_80000h);
-//     state_fio->FputInt32(window_a0000h);
-//#endif
-       
-//     MEMORY::save_state(state_fio);
-}
-
-bool MEMBUS::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);
-//#if defined(SUPPORT_BIOS_RAM)
-//     state_fio->Fwrite(bios_ram, sizeof(bios_ram), 1);
-//     bios_ram_selected = state_fio->FgetBool();
-//#endif
-//#if defined(SUPPORT_ITF_ROM)
-//     itf_selected = state_fio->FgetBool();
-//#endif
-//#if !defined(SUPPORT_HIRESO)
-////   state_fio->Fread(sound_bios_ram, sizeof(sound_bios_ram), 1);
-//     sound_bios_selected = state_fio->FgetBool();
-////   sound_bios_ram_selected = state_fio->FgetBool();
-//#if defined(SUPPORT_SASI_IF)
-//     state_fio->Fread(sasi_bios_ram, sizeof(sasi_bios_ram), 1);
-//     sasi_bios_selected = state_fio->FgetBool();
-//     sasi_bios_ram_selected = state_fio->FgetBool();
-//#endif
-//#if defined(SUPPORT_SCSI_IF)
-//     state_fio->Fread(scsi_bios_ram, sizeof(scsi_bios_ram), 1);
-//     scsi_bios_selected = state_fio->FgetBool();
-//     scsi_bios_ram_selected = state_fio->FgetBool();
-//#endif
-//#if defined(SUPPORT_IDE_IF)
-////   state_fio->Fread(ide_bios_ram, sizeof(ide_bios_ram), 1);
-//     ide_bios_selected = state_fio->FgetBool();
-////   ide_bios_ram_selected = state_fio->FgetBool();
-//#endif
-//#if defined(SUPPORT_NEC_EMS)
-//     state_fio->Fread(nec_ems, sizeof(nec_ems), 1);
-//     nec_ems_selected = state_fio->FgetBool();
-//#endif
-//#endif
-//#if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
-//     dma_access_ctrl = state_fio->FgetUint8();
-//     window_80000h = state_fio->FgetUint32();
-//     window_a0000h = state_fio->FgetUint32();
-//#endif
-       
-       // post process
-       update_bios();
+       state_fio->StateUint8(dma_access_ctrl);
+       state_fio->StateUint32(window_80000h);
+       state_fio->StateUint32(window_a0000h);
+#endif
+       if(!MEMORY::process_state(state_fio, loading)) {
+               return false;
+       }
+       
+       // post process
+       if(loading) {
+               update_bios();
 #if !defined(SUPPORT_HIRESO)
-       update_sound_bios();
+               update_sound_bios();
 #if defined(SUPPORT_SASI_IF)
-       update_sasi_bios();
+               update_sasi_bios();
 #endif
 #if defined(SUPPORT_SCSI_IF)
-       update_scsi_bios();
+               update_scsi_bios();
 #endif
 #if defined(SUPPORT_IDE_IF)
-       update_ide_bios();
+               update_ide_bios();
 #endif
 #if defined(SUPPORT_EMS)
-       update_nec_ems();
+               update_nec_ems();
 #endif
 #endif
-//     return MEMORY::load_state(state_fio);
-       return true;
+       }
+       return true;
 }
index 210e586..8380d31 100644 (file)
@@ -129,9 +129,7 @@ public:
        uint32_t read_dma_data8(uint32_t addr);
        void write_dma_data8(uint32_t addr, uint32_t data);
 #endif
-       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_display(DISPLAY* device)
index cd4101f..7d03df0 100644 (file)
@@ -127,37 +127,22 @@ void MOUSE::update_mouse()
 
 #define STATE_VERSION  2
 
-void MOUSE::save_state(FILEIO* state_fio)
+bool MOUSE::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputInt32(ctrlreg);
-       state_fio->FputInt32(freq);
-       state_fio->FputInt32(cur_freq);
-       state_fio->FputInt32(dx);
-       state_fio->FputInt32(dy);
-       state_fio->FputInt32(lx);
-       state_fio->FputInt32(ly);
-       state_fio->FputInt32(register_id);
-}
-
-bool MOUSE::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       ctrlreg = state_fio->FgetInt32();
-       freq = state_fio->FgetInt32();
-       cur_freq = state_fio->FgetInt32();
-       dx = state_fio->FgetInt32();
-       dy = state_fio->FgetInt32();
-       lx = state_fio->FgetInt32();
-       ly = state_fio->FgetInt32();
-       register_id = state_fio->FgetInt32();
+       state_fio->StateInt32(ctrlreg);
+       state_fio->StateInt32(freq);
+       state_fio->StateInt32(cur_freq);
+       state_fio->StateInt32(dx);
+       state_fio->StateInt32(dy);
+       state_fio->StateInt32(lx);
+       state_fio->StateInt32(ly);
+       state_fio->StateInt32(register_id);
        return true;
 }
 
index 1e81a3c..03d7c93 100644 (file)
@@ -55,8 +55,7 @@ public:
        void event_callback(int event_id, int err);
        void event_frame();
        void write_signal(int id, uint32_t data, uint32_t mask);
-       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)
index aa2021b..0326bff 100644 (file)
@@ -908,7 +908,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
        for(DEVICE* device = first_device; device; device = device->next_device) {
                device->initialize();
        }
-       decl_state();
        
 #if defined(_PC9801) || defined(_PC9801E)
        fdc_2hd->get_disk_handler(0)->drive_num = 0;
@@ -1580,78 +1579,40 @@ void VM::update_config()
 
 #define STATE_VERSION  13
 
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
-
-void VM::decl_state(void)
-{
-#if defined(_PC9801)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC9801_HEAD")), csp_logger);
-#elif defined(_PC9801E)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC9801E_HEAD")), csp_logger);
-#elif defined(_PC9801U)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC9801U_HEAD")), csp_logger);
-#elif defined(_PC9801VF)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC9801VF_HEAD")), csp_logger);
-#elif defined(_PC9801VM)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC9801VF_HEAD")), csp_logger);
-#elif defined(_PC98DO)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC98DO_HEAD")), csp_logger);
-#elif defined(_PC9801DOPLUS)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC98DO_PLUS_HEAD")), csp_logger);
-#elif defined(_PC9801VX)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC9801VX_HEAD")), csp_logger);
-#elif defined(_PC98XL)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC98XL_HEAD")), csp_logger);
-#elif defined(_PC98XA)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC98XA_HEAD")), csp_logger);
-#elif defined(_PC9801RA)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC9801RA_HEAD")), csp_logger);
-#elif defined(_PC98RL)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC98RL_HEAD")), csp_logger);
-#else
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC9801_SERIES_HEAD")), csp_logger);
-#endif
-       
-       DECL_STATE_ENTRY_BOOL(pit_clock_8mhz);
-#if defined(_PC98DO) || defined(_PC98DOPLUS)
-       DECL_STATE_ENTRY_INT32(boot_mode);
-#endif
-       DECL_STATE_ENTRY_INT32(sound_type);
-#if defined(USE_HARD_DISK) && defined(OPEN_HARD_DISK_IN_RESET)
-       DECL_STATE_ENTRY_MULTI(void, hd_file_path, sizeof(hd_file_path));
-#endif
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->decl_state();
-       }
-}
-
-void VM::save_state(FILEIO* state_fio)
+bool VM::process_state(FILEIO* state_fio, bool loading)
 {
-       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)
-{
-       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)) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+               // const char *name = typeid(*device).name();
+               //       But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+               const char *name = device->get_device_name();
+               int len = strlen(name);
+               if(!state_fio->StateCheckInt32(len)) {
+                       if(loading) {
+                               printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+                       }
                        return false;
                }
-       }
-       return true;
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       if(loading) {
+                               printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+                       }
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       if(loading) {
+                               printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+                       }
+                       return false;
+               }
+       }
+       state_fio->StateBool(pit_clock_8mhz);
+#if defined(_PC98DO) || defined(_PC98DOPLUS)
+       state_fio->StateInt32(boot_mode);
+#endif
+       state_fio->StateInt32(sound_type);
+       return true;
 }
-
index bdfd8a3..df1aacb 100644 (file)
@@ -609,9 +609,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
index 04df07c..67da952 100644 (file)
@@ -197,27 +197,17 @@ void SASI::write_signal(int id, uint32_t data, uint32_t mask)
 
 #define STATE_VERSION  2
 
-void SASI::save_state(FILEIO* state_fio)
+bool SASI::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputUint8(ocr);
-       state_fio->FputBool(irq_status);
-       state_fio->FputBool(drq_status);
-}
-
-bool SASI::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       ocr = state_fio->FgetUint8();
-       irq_status = state_fio->FgetBool();
-       drq_status = state_fio->FgetBool();
+       state_fio->StateUint8(ocr);
+       state_fio->StateBool(irq_status);
+       state_fio->StateBool(drq_status);
        return true;
 }
 
index 8f3fc37..eaca08d 100644 (file)
@@ -49,8 +49,7 @@ public:
 //     void write_dma_io8(uint32_t addr, uint32_t data);
 //     uint32_t read_dma_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
-       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_host(DEVICE* device)