OSDN Git Service

[VM][STATE][PHC20][PHC25]PV1000][PV2000][PYUTA][QC10][RX78][SC3000] Apply new state...
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 11 Jul 2018 08:28:37 +0000 (17:28 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 11 Jul 2018 08:28:37 +0000 (17:28 +0900)
[VM][STATE][TK80BS] CMT: OOPs.

46 files changed:
source/src/vm/phc20/memory.cpp
source/src/vm/phc20/memory.h
source/src/vm/phc25/keyboard.cpp
source/src/vm/phc25/keyboard.h
source/src/vm/phc25/memory.cpp
source/src/vm/phc25/memory.h
source/src/vm/phc25/system.cpp
source/src/vm/phc25/system.h
source/src/vm/pv1000/joystick.cpp
source/src/vm/pv1000/joystick.h
source/src/vm/pv1000/psg.cpp
source/src/vm/pv1000/psg.h
source/src/vm/pv1000/vdp.cpp
source/src/vm/pv1000/vdp.h
source/src/vm/pv2000/cmt.cpp
source/src/vm/pv2000/cmt.h
source/src/vm/pv2000/keyboard.cpp
source/src/vm/pv2000/keyboard.h
source/src/vm/pv2000/printer.cpp
source/src/vm/pv2000/printer.h
source/src/vm/pyuta/memory.cpp
source/src/vm/pyuta/memory.h
source/src/vm/qc10/display.cpp
source/src/vm/qc10/display.h
source/src/vm/qc10/keyboard.cpp
source/src/vm/qc10/keyboard.h
source/src/vm/qc10/memory.cpp
source/src/vm/qc10/memory.h
source/src/vm/qc10/mfont.cpp
source/src/vm/qc10/mfont.h
source/src/vm/rx78/cmt.cpp
source/src/vm/rx78/cmt.h
source/src/vm/rx78/keyboard.cpp
source/src/vm/rx78/keyboard.h
source/src/vm/rx78/memory.cpp
source/src/vm/rx78/memory.h
source/src/vm/rx78/printer.cpp
source/src/vm/rx78/printer.h
source/src/vm/rx78/vdp.cpp
source/src/vm/rx78/vdp.h
source/src/vm/sc3000/keyboard.cpp
source/src/vm/sc3000/keyboard.h
source/src/vm/sc3000/memory.cpp
source/src/vm/sc3000/memory.h
source/src/vm/tk80bs/cmt.cpp
source/src/vm/tk80bs/cmt.h

index ff6b884..8febde0 100644 (file)
@@ -158,29 +158,53 @@ void MEMORY::write_signal(int id, uint32_t data, uint32_t mask)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void MEMORY::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
+       DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
+       DECL_STATE_ENTRY_1D_ARRAY(status, sizeof(status));
+       DECL_STATE_ENTRY_UINT8(sysport);
+       
+       leave_decl_state();
+}
+
 void MEMORY::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->Fwrite(ram, sizeof(ram), 1);
-       state_fio->Fwrite(vram, sizeof(vram), 1);
-       state_fio->Fwrite(status, sizeof(status), 1);
-       state_fio->FputUint8(sysport);
+//     state_fio->Fwrite(ram, sizeof(ram), 1);
+//     state_fio->Fwrite(vram, sizeof(vram), 1);
+//     state_fio->Fwrite(status, sizeof(status), 1);
+//     state_fio->FputUint8(sysport);
 }
 
 bool MEMORY::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       state_fio->Fread(ram, sizeof(ram), 1);
-       state_fio->Fread(vram, sizeof(vram), 1);
-       state_fio->Fread(status, sizeof(status), 1);
-       sysport = state_fio->FgetUint8();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     state_fio->Fread(ram, sizeof(ram), 1);
+//     state_fio->Fread(vram, sizeof(vram), 1);
+//     state_fio->Fread(status, sizeof(status), 1);
+//     sysport = state_fio->FgetUint8();
        return true;
 }
 
index 3fba932..f39bee1 100644 (file)
@@ -48,6 +48,7 @@ public:
        uint32_t read_data8(uint32_t addr);
        void event_frame();
        void write_signal(int id, uint32_t data, uint32_t mask);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 307b620..2d4b321 100644 (file)
@@ -120,31 +120,54 @@ void KEYBOARD::event_frame()
 
 #define STATE_VERSION  1
 
-void KEYBOARD::save_state(FILEIO* state_fio)
+#include "../../statesub.h"
+
+void KEYBOARD::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
+       enter_decl_state(STATE_VERSION);
 #ifdef _MAP1010
-       state_fio->FputInt32(kana_pressed);
+       DECL_STATE_ENTRY_INT32(kana_pressed);
 #else
-       state_fio->Fwrite(status, sizeof(status), 1);
+       DECL_STATE_ENTRY_1D_ARRAY(status, sizeof(status));
 #endif
+       leave_decl_state();
+}
+
+void KEYBOARD::save_state(FILEIO* state_fio)
+{
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
+//     
+//#ifdef _MAP1010
+//     state_fio->FputInt32(kana_pressed);
+//#else
+//     state_fio->Fwrite(status, sizeof(status), 1);
+//#endif
 }
 
 bool KEYBOARD::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-#ifdef _MAP1010
-       kana_pressed = state_fio->FgetInt32();
-#else
-       state_fio->Fread(status, sizeof(status), 1);
-#endif
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//#ifdef _MAP1010
+//     kana_pressed = state_fio->FgetInt32();
+//#else
+//     state_fio->Fread(status, sizeof(status), 1);
+//#endif
        return true;
 }
 
index ec74048..c4685e5 100644 (file)
@@ -38,6 +38,7 @@ public:
        void reset();
        uint32_t read_io8(uint32_t addr);
        void event_frame();
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
 };
index 41067cb..1c6c299 100644 (file)
@@ -87,25 +87,47 @@ uint32_t MEMORY::read_data8(uint32_t addr)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void MEMORY::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
+       DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
+       
+       leave_decl_state();
+}
+
 void MEMORY::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       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(ram, sizeof(ram), 1);
+//     state_fio->Fwrite(vram, sizeof(vram), 1);
 }
 
 bool MEMORY::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       state_fio->Fread(ram, sizeof(ram), 1);
-       state_fio->Fread(vram, sizeof(vram), 1);
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     state_fio->Fread(ram, sizeof(ram), 1);
+//     state_fio->Fread(vram, sizeof(vram), 1);
        return true;
 }
 
index b4fdee9..4a81cb9 100644 (file)
@@ -45,6 +45,7 @@ public:
        void reset();
        void write_data8(uint32_t addr, uint32_t data);
        uint32_t read_data8(uint32_t addr);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 1ba5a5d..3319098 100644 (file)
@@ -45,23 +45,44 @@ void SYSTEM::write_signal(int id, uint32_t data, uint32_t mask)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void SYSTEM::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_UINT8(sysport);
+       
+       leave_decl_state();
+}
+
 void SYSTEM::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->FputUint8(sysport);
+//     state_fio->FputUint8(sysport);
 }
 
 bool SYSTEM::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       sysport = state_fio->FgetUint8();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     sysport = state_fio->FgetUint8();
        return true;
 }
 
index 1ade96c..7b0e986 100644 (file)
@@ -37,6 +37,7 @@ public:
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 706d921..dd2d9ab 100644 (file)
@@ -86,25 +86,47 @@ void JOYSTICK::event_frame()
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void JOYSTICK::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_UINT8(column);
+       DECL_STATE_ENTRY_UINT8(status);
+       
+       leave_decl_state();
+}
+
 void JOYSTICK::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->FputUint8(column);
-       state_fio->FputUint8(status);
+//     state_fio->FputUint8(column);
+//     state_fio->FputUint8(status);
 }
 
 bool JOYSTICK::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       column = state_fio->FgetUint8();
-       status = state_fio->FgetUint8();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     column = state_fio->FgetUint8();
+//     status = state_fio->FgetUint8();
        return true;
 }
 
index 5ff9f94..3b7301e 100644 (file)
@@ -35,6 +35,7 @@ public:
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
        void event_frame();
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
 };
index 0029aee..a9b13c7 100644 (file)
@@ -62,27 +62,48 @@ void PSG::set_volume(int ch, int decibel_l, int decibel_r)
 
 #define STATE_VERSION  1
 
-void PSG::save_state(FILEIO* state_fio)
+#include "../../statesub.h"
+
+void PSG::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_INT32_STRIDE((ch[0].period), 3, sizeof(ch[0]));
        
-       for(int i = 0; i < 3; i++) {
-               state_fio->FputInt32(ch[i].period);
+       leave_decl_state();
+}
+
+void PSG::save_state(FILEIO* state_fio)
+{
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
        }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
+       
+//     for(int i = 0; i < 3; i++) {
+//             state_fio->FputInt32(ch[i].period);
+//     }
 }
 
 bool PSG::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       for(int i = 0; i < 3; i++) {
-               ch[i].period = state_fio->FgetInt32();
-       }
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     for(int i = 0; i < 3; i++) {
+//             ch[i].period = state_fio->FgetInt32();
+//     }
        return true;
 }
 
index 6881cb5..96261d1 100644 (file)
@@ -38,6 +38,7 @@ public:
        void write_io8(uint32_t addr, uint32_t data);
        void mix(int32_t* buffer, int cnt);
        void set_volume(int ch, int decibel_l, int decibel_r);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 449cd73..560d07b 100644 (file)
@@ -130,29 +130,60 @@ void VDP::draw_pcg(int x8, int y8, uint16_t top)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void VDP::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_INT32(tmp_vram_size);    // (int)(vram - base);
+       DECL_STATE_ENTRY_INT32(tmp_pcg_size);     // (int)(pcg - base);
+       DECL_STATE_ENTRY_INT32(tmp_pattern_size); // (int)(pattern - base);
+       DECL_STATE_ENTRY_BOOL(force_pattern);
+       
+       leave_decl_state();
+}
+
 void VDP::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       tmp_vram_size = (int)(vram - base);
+       tmp_pcg_size = (int)(pcg - base);
+       tmp_pattern_size = (int)(pattern - base);
+
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->FputInt32((int)(vram - base));
-       state_fio->FputInt32((int)(pcg - base));
-       state_fio->FputInt32((int)(pattern - base));
-       state_fio->FputBool(force_pattern);
+//     state_fio->FputInt32((int)(vram - base));
+//     state_fio->FputInt32((int)(pcg - base));
+//     state_fio->FputInt32((int)(pattern - base));
+//     state_fio->FputBool(force_pattern);
 }
 
 bool VDP::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       vram = base + state_fio->FgetInt32();
-       pcg = base + state_fio->FgetInt32();
-       pattern = base + state_fio->FgetInt32();
-       force_pattern = state_fio->FgetBool();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     vram = base + state_fio->FgetInt32();
+//     pcg = base + state_fio->FgetInt32();
+//     pattern = base + state_fio->FgetInt32();
+//     force_pattern = state_fio->FgetBool();
+       vram = base + tmp_vram_size;
+       pcg = base + tmp_pcg_size;
+       pattern = base + tmp_pattern_size;
        return true;
 }
 
index 7af5018..7c847e6 100644 (file)
@@ -25,6 +25,10 @@ private:
        uint8_t* pattern;
        uint8_t* base;
        bool force_pattern;
+
+       int tmp_vram_size;
+       int tmp_pcg_size;
+       int tmp_pattern_size;
        
        void draw_pattern(int x8, int y8, uint16_t top);
        void draw_pcg(int x8, int y8, uint16_t top);
@@ -42,6 +46,7 @@ public:
        void write_io8(uint32_t addr, uint32_t data);
        void event_callback(int event_id, int err);
        void event_vline(int v, int clock);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 05621a0..9c6d67f 100644 (file)
@@ -131,33 +131,59 @@ void CMT::close_tape()
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void CMT::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+       
+       DECL_STATE_ENTRY_INT32(bufcnt);
+       DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
+       DECL_STATE_ENTRY_BOOL(play);
+       DECL_STATE_ENTRY_BOOL(rec);
+       DECL_STATE_ENTRY_UINT8(start);
+       DECL_STATE_ENTRY_UINT8(bit);
+
+       leave_decl_state();
+}
+
 void CMT::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->FputInt32(bufcnt);
-       state_fio->Fwrite(buffer, sizeof(buffer), 1);
-       state_fio->FputBool(play);
-       state_fio->FputBool(rec);
-       state_fio->FputUint8(start);
-       state_fio->FputUint8(bit);
+//     state_fio->FputInt32(bufcnt);
+//     state_fio->Fwrite(buffer, sizeof(buffer), 1);
+//     state_fio->FputBool(play);
+//     state_fio->FputBool(rec);
+//     state_fio->FputUint8(start);
+//     state_fio->FputUint8(bit);
 }
 
 bool CMT::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       bufcnt = state_fio->FgetInt32();
-       state_fio->Fread(buffer, sizeof(buffer), 1);
-       play = state_fio->FgetBool();
-       rec = state_fio->FgetBool();
-       start = state_fio->FgetUint8();
-       bit = state_fio->FgetUint8();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     bufcnt = state_fio->FgetInt32();
+//     state_fio->Fread(buffer, sizeof(buffer), 1);
+//     play = state_fio->FgetBool();
+//     rec = state_fio->FgetBool();
+//     start = state_fio->FgetUint8();
+//     bit = state_fio->FgetUint8();
        return true;
 }
 
index 3c7e41c..bf33e67 100644 (file)
@@ -40,6 +40,7 @@ public:
        void reset();
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 9cb08be..4d74b70 100644 (file)
@@ -110,27 +110,53 @@ void KEYBOARD::key_up(int code)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void KEYBOARD::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+       
+       DECL_STATE_ENTRY_1D_ARRAY(key_stat, sizeof(key_stat));
+       DECL_STATE_ENTRY_INT32(key_no);
+       DECL_STATE_ENTRY_BOOL(intr_enb);
+
+       leave_decl_state();
+}
+
 void KEYBOARD::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     if(state_entry != NULL) {
+//             state_entry->save_state(state_fio);
+//     }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->Fwrite(key_stat, sizeof(key_stat), 1);
-       state_fio->FputInt32(key_no);
-       state_fio->FputBool(intr_enb);
+//     state_fio->Fwrite(key_stat, sizeof(key_stat), 1);
+//     state_fio->FputInt32(key_no);
+//     state_fio->FputBool(intr_enb);
 }
 
 bool KEYBOARD::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       state_fio->Fread(key_stat, sizeof(key_stat), 1);
-       key_no = state_fio->FgetInt32();
-       intr_enb = state_fio->FgetBool();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     state_fio->Fread(key_stat, sizeof(key_stat), 1);
+//     key_no = state_fio->FgetInt32();
+//     intr_enb = state_fio->FgetBool();
        return true;
 }
 
index 39853d8..a10612c 100644 (file)
@@ -36,6 +36,7 @@ public:
        void reset();
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 066c852..a194e1c 100644 (file)
@@ -40,29 +40,53 @@ uint32_t PRINTER::read_io8(uint32_t addr)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void PRINTER::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+       
+       DECL_STATE_ENTRY_UINT8(out);
+       DECL_STATE_ENTRY_UINT8(ctrl0);
+       DECL_STATE_ENTRY_UINT8(ctrl1);
+       DECL_STATE_ENTRY_BOOL(busy);
+
+       leave_decl_state();
+}
+
 void PRINTER::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->FputUint8(out);
-       state_fio->FputUint8(ctrl0);
-       state_fio->FputUint8(ctrl1);
-       state_fio->FputBool(busy);
+//     state_fio->FputUint8(out);
+//     state_fio->FputUint8(ctrl0);
+//     state_fio->FputUint8(ctrl1);
+//     state_fio->FputBool(busy);
 }
 
 bool PRINTER::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       out = state_fio->FgetUint8();
-       ctrl0 = state_fio->FgetUint8();
-       ctrl1 = state_fio->FgetUint8();
-       busy = state_fio->FgetBool();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     out = state_fio->FgetUint8();
+//     ctrl0 = state_fio->FgetUint8();
+//     ctrl1 = state_fio->FgetUint8();
+//     busy = state_fio->FgetBool();
        return true;
 }
 
index 9e363cf..66bea6b 100644 (file)
@@ -31,6 +31,7 @@ public:
        void initialize();
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
 };
index 96386e8..b6beffb 100644 (file)
@@ -314,31 +314,56 @@ void MEMORY::close_cart()
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void MEMORY::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+       
+       DECL_STATE_ENTRY_BOOL(cmt_signal);
+       DECL_STATE_ENTRY_BOOL(cmt_remote);
+       DECL_STATE_ENTRY_BOOL(has_extrom);
+       DECL_STATE_ENTRY_BOOL(cart_enabled);
+       DECL_STATE_ENTRY_INT32(ctype);
+
+       leave_decl_state();
+}
+
 void MEMORY::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->FputBool(cmt_signal);
-       state_fio->FputBool(cmt_remote);
-       state_fio->FputBool(has_extrom);
-       state_fio->FputBool(cart_enabled);
-       state_fio->FputInt32(ctype);
+//     state_fio->FputBool(cmt_signal);
+//     state_fio->FputBool(cmt_remote);
+//     state_fio->FputBool(has_extrom);
+//     state_fio->FputBool(cart_enabled);
+//     state_fio->FputInt32(ctype);
 }
 
 bool MEMORY::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       cmt_signal = state_fio->FgetBool();
-       cmt_remote = state_fio->FgetBool();
-       has_extrom = state_fio->FgetBool();
-       cart_enabled = state_fio->FgetBool();
-       ctype = state_fio->FgetInt32();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     cmt_signal = state_fio->FgetBool();
+//     cmt_remote = state_fio->FgetBool();
+//     has_extrom = state_fio->FgetBool();
+//     cart_enabled = state_fio->FgetBool();
+//     ctype = state_fio->FgetInt32();
        
        // post process
        if(cart_enabled) {
index f620778..acede30 100644 (file)
@@ -50,6 +50,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);
        
index 4b3db31..9632bd2 100644 (file)
@@ -307,39 +307,68 @@ void DISPLAY::draw_screen()
 
 #define STATE_VERSION  1
 
-void DISPLAY::save_state(FILEIO* state_fio)
+#include "../../statesub.h"
+
+void DISPLAY::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
+       enter_decl_state(STATE_VERSION);
+
 #ifdef _COLOR_MONITOR
-       state_fio->Fwrite(vram_r, sizeof(vram_r), 1);
-       state_fio->Fwrite(vram_g, sizeof(vram_g), 1);
-       state_fio->Fwrite(vram_b, sizeof(vram_b), 1);
+       DECL_STATE_ENTRY_1D_ARRAY(vram_r, sizeof(vram_r));
+       DECL_STATE_ENTRY_1D_ARRAY(vram_g, sizeof(vram_g));
+       DECL_STATE_ENTRY_1D_ARRAY(vram_b, sizeof(vram_b));
 #else
-       state_fio->Fwrite(vram, sizeof(vram), 1);
+       DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
 #endif
-       state_fio->FputUint8(bank);
-       state_fio->FputInt32(blink);
+       DECL_STATE_ENTRY_UINT8(bank);
+       DECL_STATE_ENTRY_INT32(blink);
+       
+       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);
+       
+//#ifdef _COLOR_MONITOR
+//     state_fio->Fwrite(vram_r, sizeof(vram_r), 1);
+//     state_fio->Fwrite(vram_g, sizeof(vram_g), 1);
+//     state_fio->Fwrite(vram_b, sizeof(vram_b), 1);
+//#else
+//     state_fio->Fwrite(vram, sizeof(vram), 1);
+//#endif
+//     state_fio->FputUint8(bank);
+//     state_fio->FputInt32(blink);
 }
 
 bool DISPLAY::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-#ifdef _COLOR_MONITOR
-       state_fio->Fread(vram_r, sizeof(vram_r), 1);
-       state_fio->Fread(vram_g, sizeof(vram_g), 1);
-       state_fio->Fread(vram_b, sizeof(vram_b), 1);
-#else
-       state_fio->Fread(vram, sizeof(vram), 1);
-#endif
-       bank = state_fio->FgetUint8();
-       blink = state_fio->FgetInt32();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//#ifdef _COLOR_MONITOR
+//     state_fio->Fread(vram_r, sizeof(vram_r), 1);
+//     state_fio->Fread(vram_g, sizeof(vram_g), 1);
+//     state_fio->Fread(vram_b, sizeof(vram_b), 1);
+//#else
+//     state_fio->Fread(vram, sizeof(vram), 1);
+//#endif
+//     bank = state_fio->FgetUint8();
+//     blink = state_fio->FgetInt32();
        return true;
 }
 
index 053cdc5..457a33d 100644 (file)
@@ -54,6 +54,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);
        
index 3fcb1cd..0b04471 100644 (file)
@@ -148,27 +148,50 @@ void KEYBOARD::process_cmd(uint8_t val)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void KEYBOARD::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_1D_ARRAY(led, sizeof(led) / sizeof(bool));
+       DECL_STATE_ENTRY_BOOL(repeat);
+       DECL_STATE_ENTRY_BOOL(enable);
+       
+       leave_decl_state();
+}
+
 void KEYBOARD::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->Fwrite(led, sizeof(led), 1);
-       state_fio->FputBool(repeat);
-       state_fio->FputBool(enable);
+//     state_fio->Fwrite(led, sizeof(led), 1);
+//     state_fio->FputBool(repeat);
+//     state_fio->FputBool(enable);
 }
 
 bool KEYBOARD::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       state_fio->Fread(led, sizeof(led), 1);
-       repeat = state_fio->FgetBool();
-       enable = state_fio->FgetBool();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     state_fio->Fread(led, sizeof(led), 1);
+//     repeat = state_fio->FgetBool();
+//     enable = state_fio->FgetBool();
        return true;
 }
 
index d312db5..538ff94 100644 (file)
@@ -36,6 +36,7 @@ public:
        // common functions
        void initialize();
        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);
        
index e09936d..83b7177 100644 (file)
@@ -182,43 +182,74 @@ void MEMORY::update_pcm()
 
 #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(cmos, sizeof(cmos));
+       DECL_STATE_ENTRY_UINT32(cmos_crc32);
+       DECL_STATE_ENTRY_UINT8(bank);
+       DECL_STATE_ENTRY_UINT8(psel);
+       DECL_STATE_ENTRY_UINT8(csel);
+       DECL_STATE_ENTRY_BOOL(pcm_on);
+       DECL_STATE_ENTRY_BOOL(pcm_cont);
+       DECL_STATE_ENTRY_BOOL(pcm_pit);
+       DECL_STATE_ENTRY_BOOL(fdc_irq);
+       DECL_STATE_ENTRY_BOOL(motor);
+       
+       leave_decl_state();
+}
+
 void MEMORY::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       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(cmos, sizeof(cmos), 1);
-       state_fio->FputUint32(cmos_crc32);
-       state_fio->FputUint8(bank);
-       state_fio->FputUint8(psel);
-       state_fio->FputUint8(csel);
-       state_fio->FputBool(pcm_on);
-       state_fio->FputBool(pcm_cont);
-       state_fio->FputBool(pcm_pit);
-       state_fio->FputBool(fdc_irq);
-       state_fio->FputBool(motor);
+//     state_fio->Fwrite(ram, sizeof(ram), 1);
+//     state_fio->Fwrite(cmos, sizeof(cmos), 1);
+//     state_fio->FputUint32(cmos_crc32);
+//     state_fio->FputUint8(bank);
+//     state_fio->FputUint8(psel);
+//     state_fio->FputUint8(csel);
+//     state_fio->FputBool(pcm_on);
+//     state_fio->FputBool(pcm_cont);
+//     state_fio->FputBool(pcm_pit);
+//     state_fio->FputBool(fdc_irq);
+//     state_fio->FputBool(motor);
 }
 
 bool MEMORY::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       state_fio->Fread(ram, sizeof(ram), 1);
-       state_fio->Fread(cmos, sizeof(cmos), 1);
-       cmos_crc32 = state_fio->FgetUint32();
-       bank = state_fio->FgetUint8();
-       psel = state_fio->FgetUint8();
-       csel = state_fio->FgetUint8();
-       pcm_on = state_fio->FgetBool();
-       pcm_cont = state_fio->FgetBool();
-       pcm_pit = state_fio->FgetBool();
-       fdc_irq = state_fio->FgetBool();
-       motor = state_fio->FgetBool();
+//     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(cmos, sizeof(cmos), 1);
+//     cmos_crc32 = state_fio->FgetUint32();
+//     bank = state_fio->FgetUint8();
+//     psel = state_fio->FgetUint8();
+//     csel = state_fio->FgetUint8();
+//     pcm_on = state_fio->FgetBool();
+//     pcm_cont = state_fio->FgetBool();
+//     pcm_pit = state_fio->FgetBool();
+//     fdc_irq = state_fio->FgetBool();
+//     motor = state_fio->FgetBool();
        
        // post process
        update_map();
index 6208cc0..c142f21 100644 (file)
@@ -58,6 +58,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);
        
index 8795ed0..bf592bc 100644 (file)
@@ -94,31 +94,54 @@ uint32_t MFONT::read_io8(uint32_t addr)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void MFONT::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_UINT8(status);
+       DECL_STATE_ENTRY_FIFO(cmd);
+       DECL_STATE_ENTRY_FIFO(res);
+       
+       leave_decl_state();
+}
+
 void MFONT::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->FputUint8(status);
-       cmd->save_state((void *)state_fio);
-       res->save_state((void *)state_fio);
+//     state_fio->FputUint8(status);
+//     cmd->save_state((void *)state_fio);
+//     res->save_state((void *)state_fio);
 }
 
 bool MFONT::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
-       }
-       status = state_fio->FgetUint8();
-       if(!cmd->load_state((void *)state_fio)) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       if(!res->load_state((void *)state_fio)) {
+       if(!mb) {
                return false;
        }
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     status = state_fio->FgetUint8();
+//     if(!cmd->load_state((void *)state_fio)) {
+//             return false;
+//     }
+//     if(!res->load_state((void *)state_fio)) {
+//             return false;
+//     }
        return true;
 }
 
index 0acc235..68d9e8c 100644 (file)
@@ -38,6 +38,7 @@ public:
        void release();
        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);
        
index 5b20c98..e1e2d2f 100644 (file)
@@ -70,31 +70,56 @@ void CMT::event_frame()
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void CMT::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_BOOL(in);
+       DECL_STATE_ENTRY_BOOL(out);
+       DECL_STATE_ENTRY_BOOL(remote);
+       DECL_STATE_ENTRY_BOOL(now_acc);
+       DECL_STATE_ENTRY_INT32(framecnt);
+       
+       leave_decl_state();
+}
+
 void CMT::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->FputBool(in);
-       state_fio->FputBool(out);
-       state_fio->FputBool(remote);
-       state_fio->FputBool(now_acc);
-       state_fio->FputInt32(framecnt);
+//     state_fio->FputBool(in);
+//     state_fio->FputBool(out);
+//     state_fio->FputBool(remote);
+//     state_fio->FputBool(now_acc);
+//     state_fio->FputInt32(framecnt);
 }
 
 bool CMT::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       in = state_fio->FgetBool();
-       out = state_fio->FgetBool();
-       remote = state_fio->FgetBool();
-       now_acc = state_fio->FgetBool();
-       framecnt = state_fio->FgetInt32();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     in = state_fio->FgetBool();
+//     out = state_fio->FgetBool();
+//     remote = state_fio->FgetBool();
+//     now_acc = state_fio->FgetBool();
+//     framecnt = state_fio->FgetInt32();
        return true;
 }
 
index 921167c..7ef5ec1 100644 (file)
@@ -38,6 +38,7 @@ public:
        uint32_t read_io8(uint32_t addr);
        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);
        
index cbc4b50..3cb0140 100644 (file)
@@ -94,25 +94,47 @@ void KEYBOARD::event_frame()
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void KEYBOARD::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_1D_ARRAY(status, sizeof(status));
+       DECL_STATE_ENTRY_UINT8(column);
+       
+       leave_decl_state();
+}
+
 void KEYBOARD::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->Fwrite(status, sizeof(status), 1);
-       state_fio->FputUint8(column);
+//     state_fio->Fwrite(status, sizeof(status), 1);
+//     state_fio->FputUint8(column);
 }
 
 bool KEYBOARD::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       state_fio->Fread(status, sizeof(status), 1);
-       column = state_fio->FgetUint8();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     state_fio->Fread(status, sizeof(status), 1);
+//     column = state_fio->FgetUint8();
        return true;
 }
 
index ac993ca..af6a473 100644 (file)
@@ -33,6 +33,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);
 };
index b19042e..6ce0fd0 100644 (file)
@@ -137,33 +137,59 @@ 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(ram, sizeof(ram));
+       DECL_STATE_ENTRY_1D_ARRAY(ext, sizeof(ext));
+       DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
+       DECL_STATE_ENTRY_INT32(rpage);
+       DECL_STATE_ENTRY_INT32(wpage);
+       DECL_STATE_ENTRY_BOOL(inserted);
+       
+       leave_decl_state();
+}
+
 void MEMORY::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       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(ext, sizeof(ext), 1);
-       state_fio->Fwrite(vram, sizeof(vram), 1);
-       state_fio->FputInt32(rpage);
-       state_fio->FputInt32(wpage);
-       state_fio->FputBool(inserted);
+//     state_fio->Fwrite(ram, sizeof(ram), 1);
+//     state_fio->Fwrite(ext, sizeof(ext), 1);
+//     state_fio->Fwrite(vram, sizeof(vram), 1);
+//     state_fio->FputInt32(rpage);
+//     state_fio->FputInt32(wpage);
+//     state_fio->FputBool(inserted);
 }
 
 bool MEMORY::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       state_fio->Fread(ram, sizeof(ram), 1);
-       state_fio->Fread(ext, sizeof(ext), 1);
-       state_fio->Fread(vram, sizeof(vram), 1);
-       rpage = state_fio->FgetInt32();
-       wpage = state_fio->FgetInt32();
-       inserted = state_fio->FgetBool();
+//     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(ext, sizeof(ext), 1);
+//     state_fio->Fread(vram, sizeof(vram), 1);
+//     rpage = state_fio->FgetInt32();
+//     wpage = state_fio->FgetInt32();
+//     inserted = state_fio->FgetBool();
        return true;
 }
 
index 796e882..05f786b 100644 (file)
@@ -46,6 +46,7 @@ public:
        void write_data8(uint32_t addr, uint32_t data);
        uint32_t read_data8(uint32_t addr);
        void write_io8(uint32_t addr, uint32_t data);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index ee4f1fd..35020d9 100644 (file)
@@ -44,27 +44,50 @@ void PRINTER::write_signal(int id, uint32_t data, uint32_t mask)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void PRINTER::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_BOOL(strobe);
+       DECL_STATE_ENTRY_BOOL(busy);
+       DECL_STATE_ENTRY_UINT8(out);
+       
+       leave_decl_state();
+}
+
 void PRINTER::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->FputBool(strobe);
-       state_fio->FputBool(busy);
-       state_fio->FputUint8(out);
+//     state_fio->FputBool(strobe);
+//     state_fio->FputBool(busy);
+//     state_fio->FputUint8(out);
 }
 
 bool PRINTER::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       strobe = state_fio->FgetBool();
-       busy = state_fio->FgetBool();
-       out = state_fio->FgetUint8();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     strobe = state_fio->FgetBool();
+//     busy = state_fio->FgetBool();
+//     out = state_fio->FgetUint8();
        return true;
 }
 
index 1a4a2b7..c3f4f73 100644 (file)
@@ -34,6 +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);
 };
index d1543df..b822e32 100644 (file)
@@ -158,31 +158,56 @@ void VDP::create_bg()
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void VDP::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_SCRNTYPE_T_1D_ARRAY(palette_pc, 17);
+       DECL_STATE_ENTRY_1D_ARRAY(reg, sizeof(reg));
+       DECL_STATE_ENTRY_UINT8(bg);
+       DECL_STATE_ENTRY_UINT8(cmask);
+       DECL_STATE_ENTRY_UINT8(pmask);
+       
+       leave_decl_state();
+}
+
 void VDP::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       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(reg, sizeof(reg), 1);
-       state_fio->FputUint8(bg);
-       state_fio->FputUint8(cmask);
-       state_fio->FputUint8(pmask);
+//     state_fio->Fwrite(palette_pc, sizeof(palette_pc), 1);
+//     state_fio->Fwrite(reg, sizeof(reg), 1);
+//     state_fio->FputUint8(bg);
+//     state_fio->FputUint8(cmask);
+//     state_fio->FputUint8(pmask);
 }
 
 bool VDP::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       state_fio->Fread(palette_pc, sizeof(palette_pc), 1);
-       state_fio->Fread(reg, sizeof(reg), 1);
-       bg = state_fio->FgetUint8();
-       cmask = state_fio->FgetUint8();
-       pmask = state_fio->FgetUint8();
+//     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(reg, sizeof(reg), 1);
+//     bg = state_fio->FgetUint8();
+//     cmask = state_fio->FgetUint8();
+//     pmask = state_fio->FgetUint8();
        return true;
 }
 
index 2cbc9b6..8850a8a 100644 (file)
@@ -40,6 +40,7 @@ public:
        void initialize();
        void write_io8(uint32_t addr, uint32_t data);
        void event_vline(int v, int clock);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index f8d3193..7fe256a 100644 (file)
@@ -80,25 +80,47 @@ void KEYBOARD::update_keyboard()
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void KEYBOARD::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_UINT8(column);
+       DECL_STATE_ENTRY_BOOL(break_pressed);
+       
+       leave_decl_state();
+}
+
 void KEYBOARD::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->FputUint8(column);
-       state_fio->FputBool(break_pressed);
+//     state_fio->FputUint8(column);
+//     state_fio->FputBool(break_pressed);
 }
 
 bool KEYBOARD::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       column = state_fio->FgetUint8();
-       break_pressed = state_fio->FgetBool();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     column = state_fio->FgetUint8();
+//     break_pressed = state_fio->FgetBool();
        return true;
 }
 
index 4ec1be9..44429f0 100644 (file)
@@ -39,6 +39,7 @@ public:
        void initialize();
        void event_frame();
        void write_signal(int id, uint32_t data, uint32_t mask);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 95220bc..1b942bb 100644 (file)
@@ -138,29 +138,53 @@ void MEMORY::update_bank()
 
 #define STATE_VERSION  2
 
+#include "../../statesub.h"
+
+void MEMORY::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
+       DECL_STATE_ENTRY_BOOL(inserted);
+       DECL_STATE_ENTRY_BOOL(ram_selected);
+       DECL_STATE_ENTRY_1D_ARRAY(bank, sizeof(bank));
+       
+       leave_decl_state();
+}
+
 void MEMORY::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       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->FputBool(inserted);
-       state_fio->FputBool(ram_selected);
-       state_fio->Fwrite(bank, sizeof(bank), 1);
+//     state_fio->Fwrite(ram, sizeof(ram), 1);
+//     state_fio->FputBool(inserted);
+//     state_fio->FputBool(ram_selected);
+//     state_fio->Fwrite(bank, sizeof(bank), 1);
 }
 
 bool MEMORY::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(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       state_fio->Fread(ram, sizeof(ram), 1);
-       inserted = state_fio->FgetBool();
-       ram_selected = state_fio->FgetBool();
-       state_fio->Fread(bank, sizeof(bank), 1);
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     state_fio->Fread(ram, sizeof(ram), 1);
+//     inserted = state_fio->FgetBool();
+//     ram_selected = state_fio->FgetBool();
+//     state_fio->Fread(bank, sizeof(bank), 1);
        
        // post process
        update_bank();
index e63b65b..869d8b6 100644 (file)
@@ -47,6 +47,7 @@ public:
        void write_data8(uint32_t addr, uint32_t data);
        uint32_t read_data8(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);
        
index c81dad5..4ea045f 100644 (file)
@@ -142,35 +142,61 @@ void CMT::release_tape()
 
 #define STATE_VERSION  2
 
-void CMT::save_state(FILEIO* state_fio)
+#include "../../statesub.h"
+
+void CMT::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       enter_decl_state(STATE_VERSION);
        
-       state_fio->FputBool(mic);
-       state_fio->FputBool(ear);
-       state_fio->FputBool(pulse);
-       state_fio->FputInt32(pulse_count);
+       DECL_STATE_ENTRY_BOOL(mic);
+       DECL_STATE_ENTRY_BOOL(ear);
+       DECL_STATE_ENTRY_BOOL(pulse);
+       DECL_STATE_ENTRY_INT32(pulse_count);
 #if defined(_TK80BS)
-       state_fio->FputBool(play);
-       state_fio->FputBool(rec);
-       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);
+       DECL_STATE_ENTRY_BOOL(play);
+       DECL_STATE_ENTRY_BOOL(rec);
+       DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path) / sizeof(_TCHAR));
+
+       DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path);
+
+       DECL_STATE_ENTRY_INT32(bufcnt);
+       DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
+#endif
+       leave_decl_state();
+}
+
+void CMT::save_state(FILEIO* state_fio)
+{
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
        }
-       state_fio->FputInt32(bufcnt);
-       state_fio->Fwrite(buffer, sizeof(buffer), 1);
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
+       
+//     state_fio->FputBool(mic);
+//     state_fio->FputBool(ear);
+//     state_fio->FputBool(pulse);
+//     state_fio->FputInt32(pulse_count);
+#if defined(_TK80BS)
+//     state_fio->FputBool(play);
+//     state_fio->FputBool(rec);
+//     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);
 #endif
 }
 
@@ -178,36 +204,43 @@ bool CMT::load_state(FILEIO* state_fio)
 {
        release_tape();
        
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       mic = state_fio->FgetBool();
-       ear = state_fio->FgetBool();
-       pulse = state_fio->FgetBool();
-       pulse_count = state_fio->FgetInt32();
-#if defined(_TK80BS)
-       play = state_fio->FgetBool();
-       rec = 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);
-#endif
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     mic = state_fio->FgetBool();
+//     ear = state_fio->FgetBool();
+//     pulse = state_fio->FgetBool();
+//     pulse_count = state_fio->FgetInt32();
+//#if defined(_TK80BS)
+//     play = state_fio->FgetBool();
+//     rec = 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);
+//#endif
        return true;
 }
 
index f4f9ec6..d7dddba 100644 (file)
@@ -61,6 +61,7 @@ public:
 #endif
        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);