OSDN Git Service

[VM][FM7][JCOMMCARD][STATE] Apply to new state saving/loading framework.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 30 May 2018 21:34:52 +0000 (06:34 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 30 May 2018 21:34:52 +0000 (06:34 +0900)
source/src/vm/fm7/jcommcard.cpp
source/src/vm/fm7/jcommcard.h

index 61fa472..a7a64e9 100644 (file)
@@ -203,6 +203,7 @@ void FM7_JCOMMCARD::release(void)
        }
        delete fio;
 #endif
+       if(state_entry != NULL) delete state_entry;
 }
        
 void FM7_JCOMMCARD::reset(void)
@@ -216,45 +217,68 @@ void FM7_JCOMMCARD::reset(void)
 }
 
 #define STATE_VERSION 3
+#include "../../statesub.h"
+
+void FM7_JCOMMCARD::decl_state(void)
+{
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("FM7_JCOMM_CARD"));
+       DECL_STATE_ENTRY_SINGLE(n_bank);
+        DECL_STATE_ENTRY_SINGLE(rcb_address);
+       DECL_STATE_ENTRY_SINGLE(kanji_address);
+       DECL_STATE_ENTRY_SINGLE(halted);
+
+       DECL_STATE_ENTRY_1DARRAY(prog_rom, 0x4000);
+       DECL_STATE_ENTRY_1DARRAY(dict_rom, 0x60000);
+       DECL_STATE_ENTRY_1DARRAY(p_ram, 0x2000);
+       DECL_STATE_ENTRY_BOOL(firmware_ok);
+}
 
 void FM7_JCOMMCARD::save_state(FILEIO *state_fio)
 {
-       state_fio->FputUint32_BE(STATE_VERSION);
-       state_fio->FputInt32_BE(this_device_id);
+       //state_fio->FputUint32_BE(STATE_VERSION);
+       //state_fio->FputInt32_BE(this_device_id);
        this->out_debug_log(_T("Save State: JCOMM CARD: id=%d ver=%d\n"), this_device_id, STATE_VERSION);
 
-       state_fio->FputUint8(n_bank & 0x3f);
-       state_fio->FputUint8(rcb_address);
-       state_fio->FputUint32_BE(kanji_address.d);
+       if(state_entry != NULL) state_entry->save_state(state_fio);
+       //state_fio->FputUint8(n_bank & 0x3f);
+       //state_fio->FputUint8(rcb_address);
+       //state_fio->FputUint32_BE(kanji_address.d);
 
-       state_fio->FputBool(halted);
+       //state_fio->FputBool(halted);
 
-       state_fio->Fwrite(prog_rom, sizeof(prog_rom), 1);
-       state_fio->Fwrite(dict_rom, sizeof(dict_rom), 1);
-       state_fio->Fwrite(p_ram, sizeof(p_ram), 1);
-       state_fio->FputBool(firmware_ok);
+       //state_fio->Fwrite(prog_rom, sizeof(prog_rom), 1);
+       //state_fio->Fwrite(dict_rom, sizeof(dict_rom), 1);
+       //state_fio->Fwrite(p_ram, sizeof(p_ram), 1);
+       //state_fio->FputBool(firmware_ok);
 
 }
 
 bool FM7_JCOMMCARD::load_state(FILEIO *state_fio)
 {
-       uint32_t version;
-       version = state_fio->FgetUint32_BE();
-       if(this_device_id != state_fio->FgetInt32_BE()) return false;
+       //uint32_t version;
+       //version = state_fio->FgetUint32_BE();
+       //if(this_device_id != state_fio->FgetInt32_BE()) return false;
        this->out_debug_log(_T("Load State: JCOMM CARD: id=%d ver=%d\n"), this_device_id, STATE_VERSION);
-
-       if(version >= 1) {
-               n_bank = state_fio->FgetUint8() & 0x3f;
-               rcb_address = state_fio->FgetUint8();
-               kanji_address.d = state_fio->FgetUint32_BE();
-
-               halted = state_fio->FgetBool();
-
-               state_fio->Fread(prog_rom, sizeof(prog_rom), 1);
-               state_fio->Fread(dict_rom, sizeof(dict_rom), 1);
-               state_fio->Fread(p_ram, sizeof(p_ram), 1);
-               firmware_ok = state_fio->FgetBool();
-               //modified = true;
+       if(state_entry != NULL) {
+               if(!(state_entry->load_state(state_fio))) {
+                       return false;
+               }
+       } else {
+               return false;
        }
+       n_bank &= 0x3f;
+
+       //if(version >= 1) {
+       //      n_bank = state_fio->FgetUint8() & 0x3f;
+       //      rcb_address = state_fio->FgetUint8();
+       //      kanji_address.d = state_fio->FgetUint32_BE();
+       //      halted = state_fio->FgetBool();
+       //      state_fio->Fread(prog_rom, sizeof(prog_rom), 1);
+       //      state_fio->Fread(dict_rom, sizeof(dict_rom), 1);
+       //      state_fio->Fread(p_ram, sizeof(p_ram), 1);
+       //      firmware_ok = state_fio->FgetBool();
+       //modified = true; // Abondoned
+       //}
        return true;
 }
index 8717af4..153f3b6 100644 (file)
 
 #include "../device.h"
 #include "../../common.h"
+
+class csp_state_utils;
 class MC6809;
 
 class FM7_JCOMMCARD : public DEVICE {
 private:
        MC6809 *cpu;
-       
+   
+       csp_state_utils* state_entry;   
        uint8_t n_bank;
        uint8_t rcb_address;
        pair_t kanji_address;
@@ -60,10 +63,9 @@ public:
        void set_context_cpu(MC6809 *p) {
                cpu = p;
        }
+       void decl_state();
        void save_state(FILEIO *state_fio);
        bool load_state(FILEIO *state_fio);
-
-       
 };
 
 #endif  /* ___CSP_FM7_JCOMM_CARD_H  */