OSDN Git Service

[VM][TK80BS][PC2001][PC8201][PC98HA] Apply new state framework to VMs.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 6 Jul 2018 16:50:21 +0000 (01:50 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 6 Jul 2018 16:50:21 +0000 (01:50 +0900)
26 files changed:
source/src/vm/pc8201/cmt.cpp
source/src/vm/pc8201/cmt.h
source/src/vm/pc8201/keyboard.cpp
source/src/vm/pc8201/keyboard.h
source/src/vm/pc8201/lcd.cpp
source/src/vm/pc8201/lcd.h
source/src/vm/pc8201/memory.cpp
source/src/vm/pc8201/memory.h
source/src/vm/pc98ha/calendar.cpp
source/src/vm/pc98ha/calendar.h
source/src/vm/pc98ha/floppy.cpp
source/src/vm/pc98ha/floppy.h
source/src/vm/pc98ha/keyboard.cpp
source/src/vm/pc98ha/keyboard.h
source/src/vm/pc98ha/memory.cpp
source/src/vm/pc98ha/memory.h
source/src/vm/pc98ha/note.cpp
source/src/vm/pc98ha/note.h
source/src/vm/tk80bs/display.cpp
source/src/vm/tk80bs/display.h
source/src/vm/tk80bs/keyboard.cpp
source/src/vm/tk80bs/keyboard.h
source/src/vm/tk80bs/membus.cpp
source/src/vm/tk80bs/membus.h
source/src/vm/tk80bs/memory.cpp
source/src/vm/tk80bs/memory.h

index c6f91fb..332ca26 100644 (file)
@@ -182,66 +182,96 @@ void CMT::close_tape()
 
 #define STATE_VERSION  1
 
-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);
+
+       DECL_STATE_ENTRY_BOOL(is_wav);
+       DECL_STATE_ENTRY_BOOL(rec);
+       DECL_STATE_ENTRY_BOOL(remote);
+       DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path));
+       DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path);
        
-       state_fio->FputBool(is_wav);
-       state_fio->FputBool(rec);
-       state_fio->FputBool(remote);
-       state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
-       if(rec && fio->IsOpened()) {
-               int length_tmp = (int)fio->Ftell();
-               fio->Fseek(0, FILEIO_SEEK_SET);
-               state_fio->FputInt32(length_tmp);
-               while(length_tmp != 0) {
-                       uint8_t buffer_tmp[1024];
-                       int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
-                       fio->Fread(buffer_tmp, length_rw, 1);
-                       state_fio->Fwrite(buffer_tmp, length_rw, 1);
-                       length_tmp -= length_rw;
-               }
-       } else {
-               state_fio->FputInt32(0);
+       DECL_STATE_ENTRY_INT32(bufcnt);
+       DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
+       DECL_STATE_ENTRY_INT32(prev_signal);
+       DECL_STATE_ENTRY_UINT32(prev_clock);
+
+       leave_decl_state();
+}
+
+void CMT::save_state(FILEIO* state_fio)
+{
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
        }
-       state_fio->FputInt32(bufcnt);
-       state_fio->Fwrite(buffer, sizeof(buffer), 1);
-       state_fio->FputInt32(prev_signal);
-       state_fio->FputUint32(prev_clock);
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
+//     
+//     state_fio->FputBool(is_wav);
+//     state_fio->FputBool(rec);
+//     state_fio->FputBool(remote);
+//     state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
+//     if(rec && fio->IsOpened()) {
+//             int length_tmp = (int)fio->Ftell();
+//             fio->Fseek(0, FILEIO_SEEK_SET);
+//             state_fio->FputInt32(length_tmp);
+//             while(length_tmp != 0) {
+//                     uint8_t buffer_tmp[1024];
+//                     int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+//                     fio->Fread(buffer_tmp, length_rw, 1);
+//                     state_fio->Fwrite(buffer_tmp, length_rw, 1);
+//                     length_tmp -= length_rw;
+//             }
+//     } else {
+//             state_fio->FputInt32(0);
+//     }
+//     state_fio->FputInt32(bufcnt);
+//     state_fio->Fwrite(buffer, sizeof(buffer), 1);
+//     state_fio->FputInt32(prev_signal);
+//     state_fio->FputUint32(prev_clock);
 }
 
 bool CMT::load_state(FILEIO* state_fio)
 {
        close_tape();
        
-       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;
        }
-       is_wav = state_fio->FgetBool();
-       rec = state_fio->FgetBool();
-       remote = state_fio->FgetBool();
-       state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
-       int length_tmp = state_fio->FgetInt32();
-       if(rec) {
-               fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
-               while(length_tmp != 0) {
-                       uint8_t buffer_tmp[1024];
-                       int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
-                       state_fio->Fread(buffer_tmp, length_rw, 1);
-                       if(fio->IsOpened()) {
-                               fio->Fwrite(buffer_tmp, length_rw, 1);
-                       }
-                       length_tmp -= length_rw;
-               }
-       }
-       bufcnt = state_fio->FgetInt32();
-       state_fio->Fread(buffer, sizeof(buffer), 1);
-       prev_signal = state_fio->FgetInt32();
-       prev_clock = state_fio->FgetUint32();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     is_wav = state_fio->FgetBool();
+//     rec = state_fio->FgetBool();
+//     remote = state_fio->FgetBool();
+//     state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
+//     int length_tmp = state_fio->FgetInt32();
+//     if(rec) {
+//             fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+//             while(length_tmp != 0) {
+//                     uint8_t buffer_tmp[1024];
+//                     int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+//                     state_fio->Fread(buffer_tmp, length_rw, 1);
+//                     if(fio->IsOpened()) {
+//                             fio->Fwrite(buffer_tmp, length_rw, 1);
+//                     }
+//                     length_tmp -= length_rw;
+//             }
+//     }
+//     bufcnt = state_fio->FgetInt32();
+//     state_fio->Fread(buffer, sizeof(buffer), 1);
+//     prev_signal = state_fio->FgetInt32();
+//     prev_clock = state_fio->FgetUint32();
        return true;
 }
 
index 2721997..d4dd2c6 100644 (file)
@@ -46,6 +46,7 @@ public:
        void release();
        void reset();
        void write_signal(int id, uint32_t data, uint32_t mask);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 495faad..c645d49 100644 (file)
@@ -83,27 +83,50 @@ void KEYBOARD::key_down(int code)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void KEYBOARD::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_UINT16(column);
+       DECL_STATE_ENTRY_BOOL(caps);
+       DECL_STATE_ENTRY_BOOL(kana);
+
+       leave_decl_state();
+}
+
 void KEYBOARD::save_state(FILEIO* state_fio)
 {
-       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->FputUint16(column);
-       state_fio->FputBool(caps);
-       state_fio->FputBool(kana);
+//     state_fio->FputUint16(column);
+//     state_fio->FputBool(caps);
+//     state_fio->FputBool(kana);
 }
 
 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->FgetUint16();
-       caps = state_fio->FgetBool();
-       kana = state_fio->FgetBool();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     column = state_fio->FgetUint16();
+//     caps = state_fio->FgetBool();
+//     kana = state_fio->FgetBool();
        return true;
 }
 
index e0e80a2..48ff922 100644 (file)
@@ -35,6 +35,7 @@ public:
        void initialize();
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 10d9a3b..87b6346 100644 (file)
@@ -163,25 +163,55 @@ void LCD::draw_screen()
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void LCD::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       for(int i = 0; i < 10; i++) {
+               DECL_STATE_ENTRY_2D_ARRAY_MEMBER((seg[i].vram), 4, 50, i);
+               DECL_STATE_ENTRY_INT32_MEMBER((seg[i].updown), i);
+               DECL_STATE_ENTRY_INT32_MEMBER((seg[i].disp), i);
+               DECL_STATE_ENTRY_INT32_MEMBER((seg[i].spg), i);
+               DECL_STATE_ENTRY_INT32_MEMBER((seg[i].page), i);
+               DECL_STATE_ENTRY_INT32_MEMBER((seg[i].ofs), i);
+               DECL_STATE_ENTRY_INT32_MEMBER((seg[i].ofs2), i);
+       }
+       DECL_STATE_ENTRY_UINT16(sel);
+
+       leave_decl_state();
+}
+
 void LCD::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->Fwrite(seg, sizeof(seg), 1);
-       state_fio->FputUint16(sel);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
+//     
+//     state_fio->Fwrite(seg, sizeof(seg), 1);
+//     state_fio->FputUint16(sel);
 }
 
 bool LCD::load_state(FILEIO* state_fio)
 {
-       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(seg, sizeof(seg), 1);
-       sel = state_fio->FgetUint16();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     state_fio->Fread(seg, sizeof(seg), 1);
+//     sel = state_fio->FgetUint16();
        return true;
 }
 
index 58af897..bd87002 100644 (file)
@@ -40,6 +40,7 @@ public:
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 94e532d..e5635e9 100644 (file)
@@ -144,27 +144,50 @@ void MEMORY::update_bank()
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void MEMORY::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
+       DECL_STATE_ENTRY_UINT8(sio);
+       DECL_STATE_ENTRY_UINT8(bank);
+
+       leave_decl_state();
+}
+
 void MEMORY::save_state(FILEIO* state_fio)
 {
-       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->FputUint8(sio);
-       state_fio->FputUint8(bank);
+//     state_fio->Fwrite(ram, sizeof(ram), 1);
+//     state_fio->FputUint8(sio);
+//     state_fio->FputUint8(bank);
 }
 
 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);
-       sio = state_fio->FgetUint8();
-       bank = 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);
+//     sio = state_fio->FgetUint8();
+//     bank = state_fio->FgetUint8();
        
        // post process
        update_bank();
index 671823f..5d6ebe6 100644 (file)
@@ -45,6 +45,7 @@ public:
        uint32_t read_data8(uint32_t addr);
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 45ee505..26a1875 100644 (file)
@@ -55,23 +55,44 @@ uint32_t CALENDAR::read_io8(uint32_t addr)
 #ifdef _PC98HA
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void CALENDAR::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_UINT8(ch);
+
+       leave_decl_state();
+}
+
 void CALENDAR::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(ch);
+//     state_fio->FputUint8(ch);
 }
 
 bool CALENDAR::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;
        }
-       ch = state_fio->FgetUint8();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     ch = state_fio->FgetUint8();
        return true;
 }
 #endif
index aa45b1b..71a9ab6 100644 (file)
@@ -35,6 +35,7 @@ public:
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
 #ifdef _PC98HA
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
 #endif
index abec137..db86866 100644 (file)
@@ -69,25 +69,48 @@ uint32_t FLOPPY::read_io8(uint32_t addr)
 
 #define STATE_VERSION  1
 
+
+#include "../../statesub.h"
+
+void FLOPPY::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_UINT8(ctrlreg);
+       DECL_STATE_ENTRY_UINT8(modereg);
+
+       leave_decl_state();
+}
+
 void FLOPPY::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(ctrlreg);
-       state_fio->FputUint8(modereg);
+//     state_fio->FputUint8(ctrlreg);
+//     state_fio->FputUint8(modereg);
 }
 
 bool FLOPPY::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;
        }
-       ctrlreg = state_fio->FgetUint8();
-       modereg = state_fio->FgetUint8();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     ctrlreg = state_fio->FgetUint8();
+//     modereg = state_fio->FgetUint8();
        return true;
 }
 
index 205bc82..db40934 100644 (file)
@@ -37,6 +37,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 cd45efd..976a5bb 100644 (file)
@@ -72,27 +72,50 @@ 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_BOOL(kana);
+       DECL_STATE_ENTRY_BOOL(caps);
+       DECL_STATE_ENTRY_1D_ARRAY(flag, sizeof(flag));
+
+       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->FputBool(kana);
-       state_fio->FputBool(caps);
-       state_fio->Fwrite(flag, sizeof(flag), 1);
+//     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) {
-               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;
        }
-       kana = state_fio->FgetBool();
-       caps = state_fio->FgetBool();
-       state_fio->Fread(flag, sizeof(flag), 1);
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     kana = state_fio->FgetBool();
+//     caps = state_fio->FgetBool();
+//     state_fio->Fread(flag, sizeof(flag), 1);
        return true;
 }
 
index 864e035..c1b35d0 100644 (file)
@@ -35,6 +35,7 @@ public:
        // common functions
        void initialize();
        void reset();
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 1230c6b..8433223 100644 (file)
@@ -278,65 +278,107 @@ void MEMORY::draw_screen()
 
 #define STATE_VERSION  1
 
-void MEMORY::save_state(FILEIO* state_fio)
+#include "../../statesub.h"
+
+void MEMORY::decl_state()
 {
-       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(learn, sizeof(learn), 1);
+       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(learn, sizeof(learn));
 #ifdef _PC98HA
-       state_fio->Fwrite(ramdrv, sizeof(ramdrv), 1);
-       state_fio->Fwrite(ems, sizeof(ems), 1);
-       state_fio->Fwrite(memcard, sizeof(memcard), 1);
+       DECL_STATE_ENTRY_1D_ARRAY(ramdrv, sizeof(ramdrv));
+       DECL_STATE_ENTRY_1D_ARRAY(ems, sizeof(ems));
+       DECL_STATE_ENTRY_1D_ARRAY(memcard, sizeof(memcard));
 #endif
-       state_fio->FputUint32(learn_crc32);
+       DECL_STATE_ENTRY_UINT32(learn_crc32);
 #ifdef _PC98HA
-       state_fio->FputUint32(ramdrv_crc32);
-       state_fio->FputUint32(memcard_crc32);
+       DECL_STATE_ENTRY_UINT32(ramdrv_crc32);
+       DECL_STATE_ENTRY_UINT32(memcard_crc32);
 #endif
-       state_fio->FputUint8(learn_bank);
-       state_fio->FputUint8(dic_bank);
-       state_fio->FputUint8(kanji_bank);
-       state_fio->FputUint8(romdrv_bank);
+       DECL_STATE_ENTRY_UINT8(learn_bank);
+       DECL_STATE_ENTRY_UINT8(dic_bank);
+       DECL_STATE_ENTRY_UINT8(kanji_bank);
+       DECL_STATE_ENTRY_UINT8(romdrv_bank);
 #ifdef _PC98HA
-       state_fio->FputUint8(ramdrv_bank);
-       state_fio->FputUint8(ramdrv_sel);
-       state_fio->Fwrite(ems_bank, sizeof(ems_bank), 1);
+       DECL_STATE_ENTRY_UINT8(ramdrv_bank);
+       DECL_STATE_ENTRY_UINT8(ramdrv_sel);
+       DECL_STATE_ENTRY_1D_ARRAY(ems_bank, sizeof(ems_bank));
 #endif
+
+       leave_decl_state();
+}
+
+void MEMORY::save_state(FILEIO* state_fio)
+{
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
+       
+//     state_fio->Fwrite(ram, sizeof(ram), 1);
+//     state_fio->Fwrite(vram, sizeof(vram), 1);
+//     state_fio->Fwrite(learn, sizeof(learn), 1);
+//#ifdef _PC98HA
+//     state_fio->Fwrite(ramdrv, sizeof(ramdrv), 1);
+//     state_fio->Fwrite(ems, sizeof(ems), 1);
+//     state_fio->Fwrite(memcard, sizeof(memcard), 1);
+//#endif
+//     state_fio->FputUint32(learn_crc32);
+//#ifdef _PC98HA
+//     state_fio->FputUint32(ramdrv_crc32);
+//     state_fio->FputUint32(memcard_crc32);
+//#endif
+//     state_fio->FputUint8(learn_bank);
+//     state_fio->FputUint8(dic_bank);
+//     state_fio->FputUint8(kanji_bank);
+//     state_fio->FputUint8(romdrv_bank);
+//#ifdef _PC98HA
+//     state_fio->FputUint8(ramdrv_bank);
+//     state_fio->FputUint8(ramdrv_sel);
+//     state_fio->Fwrite(ems_bank, sizeof(ems_bank), 1);
+//#endif
 }
 
 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(learn, sizeof(learn), 1);
-#ifdef _PC98HA
-       state_fio->Fread(ramdrv, sizeof(ramdrv), 1);
-       state_fio->Fread(ems, sizeof(ems), 1);
-       state_fio->Fread(memcard, sizeof(memcard), 1);
-#endif
-       learn_crc32 = state_fio->FgetUint32();
-#ifdef _PC98HA
-       ramdrv_crc32 = state_fio->FgetUint32();
-       memcard_crc32 = state_fio->FgetUint32();
-#endif
-       learn_bank = state_fio->FgetUint8();
-       dic_bank = state_fio->FgetUint8();
-       kanji_bank = state_fio->FgetUint8();
-       romdrv_bank = state_fio->FgetUint8();
-#ifdef _PC98HA
-       ramdrv_bank = state_fio->FgetUint8();
-       ramdrv_sel = state_fio->FgetUint8();
-       state_fio->Fread(ems_bank, sizeof(ems_bank), 1);
-#endif
+//     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(learn, sizeof(learn), 1);
+//#ifdef _PC98HA
+//     state_fio->Fread(ramdrv, sizeof(ramdrv), 1);
+//     state_fio->Fread(ems, sizeof(ems), 1);
+//     state_fio->Fread(memcard, sizeof(memcard), 1);
+//#endif
+//     learn_crc32 = state_fio->FgetUint32();
+//#ifdef _PC98HA
+//     ramdrv_crc32 = state_fio->FgetUint32();
+//     memcard_crc32 = state_fio->FgetUint32();
+//#endif
+//     learn_bank = state_fio->FgetUint8();
+//     dic_bank = state_fio->FgetUint8();
+//     kanji_bank = state_fio->FgetUint8();
+//     romdrv_bank = state_fio->FgetUint8();
+//#ifdef _PC98HA
+//     ramdrv_bank = state_fio->FgetUint8();
+//     ramdrv_sel = state_fio->FgetUint8();
+//     state_fio->Fread(ems_bank, sizeof(ems_bank), 1);
+//#endif
        
        // post process
        update_bank();
index 771b37f..d8362c6 100644 (file)
@@ -71,6 +71,7 @@ public:
        uint32_t read_data8(uint32_t addr);
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 5b49cc7..666f56b 100644 (file)
@@ -80,25 +80,47 @@ uint32_t NOTE::read_io8(uint32_t addr)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void NOTE::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_UINT8(ch);
+       DECL_STATE_ENTRY_1D_ARRAY(regs, sizeof(regs));
+
+       leave_decl_state();
+}
+
 void NOTE::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(ch);
-       state_fio->Fwrite(regs, sizeof(regs), 1);
+//     state_fio->FputUint8(ch);
+//     state_fio->Fwrite(regs, sizeof(regs), 1);
 }
 
 bool NOTE::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;
        }
-       ch = state_fio->FgetUint8();
-       state_fio->Fread(regs, sizeof(regs), 1);
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     ch = state_fio->FgetUint8();
+//     state_fio->Fread(regs, sizeof(regs), 1);
        return true;
 }
 
index 127087f..7147d0f 100644 (file)
@@ -32,6 +32,7 @@ public:
        void initialize();
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 309b799..b4899db 100644 (file)
@@ -210,29 +210,53 @@ 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);
+
 #if defined(_TK80BS)
-       state_fio->FputInt32(mode);
+       DECL_STATE_ENTRY_INT32(mode);
 #endif
-       state_fio->FputBool(dma);
+       DECL_STATE_ENTRY_BOOL(dma);
+       
+       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);
+//     
+//#if defined(_TK80BS)
+//     state_fio->FputInt32(mode);
+//#endif
+//     state_fio->FputBool(dma);
 }
 
 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;
        }
-#if defined(_TK80BS)
-       mode = state_fio->FgetInt32();
-#endif
-       dma = state_fio->FgetBool();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//#if defined(_TK80BS)
+//     mode = state_fio->FgetInt32();
+//#endif
+//     dma = state_fio->FgetBool();
        return true;
 }
 
index e21ceb8..d7dd365 100644 (file)
@@ -40,6 +40,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 9ec50b6..646de09 100644 (file)
@@ -283,37 +283,65 @@ void KEYBOARD::update_tk80()
 
 #define STATE_VERSION  2
 
-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);
+
 #if defined(_TK80BS)
-       state_fio->FputUint8(prev_type);
-       state_fio->FputUint8(prev_brk);
-       state_fio->FputUint8(prev_kana);
-       state_fio->FputBool(kana_lock);
-       state_fio->FputUint32(kb_type);
+       DECL_STATE_ENTRY_UINT8(prev_type);
+       DECL_STATE_ENTRY_UINT8(prev_brk);
+       DECL_STATE_ENTRY_UINT8(prev_kana);
+       DECL_STATE_ENTRY_BOOL(kana_lock);
+       DECL_STATE_ENTRY_UINT32(kb_type);
 #endif
-       state_fio->FputUint32(column);
+       DECL_STATE_ENTRY_UINT32(column);
+       
+       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);
+       
+//#if defined(_TK80BS)
+//     state_fio->FputUint8(prev_type);
+//     state_fio->FputUint8(prev_brk);
+//     state_fio->FputUint8(prev_kana);
+//     state_fio->FputBool(kana_lock);
+//     state_fio->FputUint32(kb_type);
+//#endif
+//     state_fio->FputUint32(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;
        }
-#if defined(_TK80BS)
-       prev_type = state_fio->FgetUint8();
-       prev_brk = state_fio->FgetUint8();
-       prev_kana = state_fio->FgetUint8();
-       kana_lock = state_fio->FgetBool();
-       kb_type = state_fio->FgetUint32();
-#endif
-       column = state_fio->FgetUint32();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//#if defined(_TK80BS)
+//     prev_type = state_fio->FgetUint8();
+//     prev_brk = state_fio->FgetUint8();
+//     prev_kana = state_fio->FgetUint8();
+//     kana_lock = state_fio->FgetBool();
+//     kb_type = state_fio->FgetUint32();
+//#endif
+//     column = state_fio->FgetUint32();
        return true;
 }
 
index 1826b9c..88cee9c 100644 (file)
@@ -54,6 +54,7 @@ public:
                return kb_type & 3;
        }
 #endif
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index a1df97e..3b46bd8 100644 (file)
@@ -51,29 +51,44 @@ void MEMBUS::write_signal(int id, uint32_t data, uint32_t mask)
 
 #define STATE_VERSION  1
 
-void MEMBUS::save_state(FILEIO* state_fio)
+#include "../../statesub.h"
+
+void MEMBUS::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
+       enter_decl_state(STATE_VERSION);
+
 #if defined(_TK85)
-       state_fio->FputUint32(pc7);
-       state_fio->FputUint32(count);
+       DECL_STATE_ENTRY_UINT32(pc7);
+       DECL_STATE_ENTRY_UINT32(count);
 #endif
+       MEMORY::decl_state();
+       
+       leave_decl_state();
+}
+
+void MEMBUS::save_state(FILEIO* state_fio)
+{
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
+       
+//#if defined(_TK85)
+//     state_fio->FputUint32(pc7);
+//     state_fio->FputUint32(count);
+//#endif
        MEMORY::save_state(state_fio);
 }
 
 bool MEMBUS::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
-       }
-#if defined(_TK85)
-       pc7 = state_fio->FgetUint32();
-       count = state_fio->FgetUint32();
-#endif
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//#if defined(_TK85)
+//     pc7 = state_fio->FgetUint32();
+//     count = state_fio->FgetUint32();
+//#endif
        return MEMORY::load_state(state_fio);
 }
index 16fdd8c..a3f62b1 100644 (file)
@@ -44,6 +44,7 @@ public:
 #if defined(_TK85)
        void write_signal(int id, uint32_t data, uint32_t mask);
 #endif
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index ca29a94..f837380 100644 (file)
@@ -161,24 +161,44 @@ void MEMORY::save_binary(const _TCHAR* file_path)
 
 #define STATE_VERSION  1
 
+void MEMORY::decl_state(FILEIO* state_fio)
+{
+       // 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 02fde18..29bcfd1 100644 (file)
@@ -46,8 +46,9 @@ public:
        void write_data8(uint32_t addr, uint32_t data);
        uint32_t read_data8(uint32_t addr);
        uint32_t fetch_op(uint32_t addr, int *wait);
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       virtual void decl_state();
+       virtual void save_state(FILEIO* state_fio);
+       virtual bool load_state(FILEIO* state_fio);
        
        // unique functions
        void set_context_cpu(DEVICE* device)