OSDN Git Service

[VM][DEVICE][STATE] Apply new state framework to some devices.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 12 Jun 2018 20:05:35 +0000 (05:05 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 12 Jun 2018 20:05:35 +0000 (05:05 +0900)
25 files changed:
source/src/vm/hd6301.cpp
source/src/vm/hd6301.h
source/src/vm/huc6280.cpp
source/src/vm/huc6280.h
source/src/vm/huc6280_base.cpp
source/src/vm/i8080.cpp
source/src/vm/i8080.h
source/src/vm/i8155.cpp
source/src/vm/i8155.h
source/src/vm/i8237.cpp
source/src/vm/i8237.h
source/src/vm/i8251.cpp
source/src/vm/i8251.h
source/src/vm/i8253.cpp
source/src/vm/i8253.h
source/src/vm/i8255.cpp
source/src/vm/i8255.h
source/src/vm/i8259.cpp
source/src/vm/i8259.h
source/src/vm/mc6800.cpp
source/src/vm/mc6800.h
source/src/vm/mc6801.cpp
source/src/vm/mc6801.h
source/src/vm/ym2203.cpp
source/src/vm/ym2203.h

index 796e333..1c6b05f 100644 (file)
@@ -596,114 +596,182 @@ int HD6301::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
 
 #define STATE_VERSION  2
 
-void HD6301::save_state(FILEIO* state_fio)
+#include "../statesub.h"
+
+void HD6301::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("HD6301"));
        
-       state_fio->FputUint32(pc.d);
-       state_fio->FputUint16(prevpc);
-       state_fio->FputUint32(sp.d);
-       state_fio->FputUint32(ix.d);
-       state_fio->FputUint32(acc_d.d);
-       state_fio->FputUint32(ea.d);
-       state_fio->FputUint8(cc);
-       state_fio->FputInt32(wai_state);
-       state_fio->FputInt32(int_state);
-       if(__USE_DEBUGGER) state_fio->FputUint64(total_icount);
-       state_fio->FputInt32(icount);
+       DECL_STATE_ENTRY_PAIR(pc);
+       DECL_STATE_ENTRY_UINT16(prevpc);
+       DECL_STATE_ENTRY_PAIR(sp);
+       DECL_STATE_ENTRY_PAIR(ix);
+       DECL_STATE_ENTRY_PAIR(acc_d);
+       DECL_STATE_ENTRY_PAIR(ea);
+       DECL_STATE_ENTRY_UINT8(cc);
+       DECL_STATE_ENTRY_INT32(wai_state);
+       DECL_STATE_ENTRY_INT32(int_state);
+       if(__USE_DEBUGGER) {
+               DECL_STATE_ENTRY_UINT64(total_icount);
+       }
+       DECL_STATE_ENTRY_INT32(icount);
 //#if defined(HAS_MC6801) || defined(HAS_HD6301)
        for(int i = 0; i < 4; i++) {
-               state_fio->FputUint8(port[i].wreg);
-               state_fio->FputUint8(port[i].rreg);
-               state_fio->FputUint8(port[i].ddr);
-               state_fio->FputUint8(port[i].latched_data);
-               state_fio->FputBool(port[i].latched);
-               state_fio->FputBool(port[i].first_write);
+               DECL_STATE_ENTRY_UINT8_MEMBER(port[i].wreg, i);
+               DECL_STATE_ENTRY_UINT8_MEMBER(port[i].rreg, i);
+               DECL_STATE_ENTRY_UINT8_MEMBER(port[i].ddr, i);
+               DECL_STATE_ENTRY_UINT8_MEMBER(port[i].latched_data, i);
+               DECL_STATE_ENTRY_BOOL_MEMBER(port[i].latched, i);
+               DECL_STATE_ENTRY_BOOL_MEMBER(port[i].first_write, i);
+       }
+       DECL_STATE_ENTRY_UINT8(p3csr);
+       DECL_STATE_ENTRY_BOOL(p3csr_is3_flag_read);
+       DECL_STATE_ENTRY_BOOL(sc1_state);
+       DECL_STATE_ENTRY_BOOL(sc2_state);
+       DECL_STATE_ENTRY_PAIR(counter);
+       DECL_STATE_ENTRY_PAIR(output_compare);
+       DECL_STATE_ENTRY_PAIR(timer_over);
+       DECL_STATE_ENTRY_UINT8(tcsr);
+       DECL_STATE_ENTRY_UINT8(pending_tcsr);
+       DECL_STATE_ENTRY_UINT16(input_capture);
+//#ifdef HAS_HD6301
+       DECL_STATE_ENTRY_UINT16(latch09);
+//#endif
+       DECL_STATE_ENTRY_UINT32(timer_next);
+       //recv_buffer->save_state((void *)state_fio);
+       DECL_STATE_ENTRY_UINT8(trcsr);
+       DECL_STATE_ENTRY_UINT8(rdr);
+       DECL_STATE_ENTRY_UINT8(tdr);
+       DECL_STATE_ENTRY_BOOL(trcsr_read_tdre);
+       DECL_STATE_ENTRY_BOOL(trcsr_read_orfe);
+       DECL_STATE_ENTRY_BOOL(trcsr_read_rdrf);
+       DECL_STATE_ENTRY_UINT8(rmcr);
+       DECL_STATE_ENTRY_INT32(sio_counter);
+       DECL_STATE_ENTRY_UINT8(ram_ctrl);
+       DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
+//#endif
+       
+}
+
+void HD6301::save_state(FILEIO* state_fio)
+{
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
        }
-       state_fio->FputUint8(p3csr);
-       state_fio->FputBool(p3csr_is3_flag_read);
-       state_fio->FputBool(sc1_state);
-       state_fio->FputBool(sc2_state);
-       state_fio->FputUint32(counter.d);
-       state_fio->FputUint32(output_compare.d);
-       state_fio->FputUint32(timer_over.d);
-       state_fio->FputUint8(tcsr);
-       state_fio->FputUint8(pending_tcsr);
-       state_fio->FputUint16(input_capture);
+       //state_fio->FputUint32(STATE_VERSION);
+       //state_fio->FputInt32(this_device_id);
+       
+       //state_fio->FputUint32(pc.d);
+       //state_fio->FputUint16(prevpc);
+       //state_fio->FputUint32(sp.d);
+       //state_fio->FputUint32(ix.d);
+       //state_fio->FputUint32(acc_d.d);
+       //state_fio->FputUint32(ea.d);
+       //state_fio->FputUint8(cc);
+       //state_fio->FputInt32(wai_state);
+       //state_fio->FputInt32(int_state);
+       //if(__USE_DEBUGGER) state_fio->FputUint64(total_icount);
+       //state_fio->FputInt32(icount);
+//#if defined(HAS_MC6801) || defined(HAS_HD6301)
+       //for(int i = 0; i < 4; i++) {
+       //      state_fio->FputUint8(port[i].wreg);
+       //      state_fio->FputUint8(port[i].rreg);
+       //      state_fio->FputUint8(port[i].ddr);
+       //      state_fio->FputUint8(port[i].latched_data);
+       //      state_fio->FputBool(port[i].latched);
+       //      state_fio->FputBool(port[i].first_write);
+       //}
+       //state_fio->FputUint8(p3csr);
+       //state_fio->FputBool(p3csr_is3_flag_read);
+       //state_fio->FputBool(sc1_state);
+       //state_fio->FputBool(sc2_state);
+       //state_fio->FputUint32(counter.d);
+       //state_fio->FputUint32(output_compare.d);
+       //state_fio->FputUint32(timer_over.d);
+       //state_fio->FputUint8(tcsr);
+       //state_fio->FputUint8(pending_tcsr);
+       //state_fio->FputUint16(input_capture);
 //#ifdef HAS_HD6301
-       state_fio->FputUint16(latch09);
+       //state_fio->FputUint16(latch09);
 //#endif
-       state_fio->FputUint32(timer_next);
+       //state_fio->FputUint32(timer_next);
        recv_buffer->save_state((void *)state_fio);
-       state_fio->FputUint8(trcsr);
-       state_fio->FputUint8(rdr);
-       state_fio->FputUint8(tdr);
-       state_fio->FputBool(trcsr_read_tdre);
-       state_fio->FputBool(trcsr_read_orfe);
-       state_fio->FputBool(trcsr_read_rdrf);
-       state_fio->FputUint8(rmcr);
-       state_fio->FputInt32(sio_counter);
-       state_fio->FputUint8(ram_ctrl);
-       state_fio->Fwrite(ram, sizeof(ram), 1);
+       //state_fio->FputUint8(trcsr);
+       //state_fio->FputUint8(rdr);
+       //state_fio->FputUint8(tdr);
+       //state_fio->FputBool(trcsr_read_tdre);
+       //state_fio->FputBool(trcsr_read_orfe);
+       //state_fio->FputBool(trcsr_read_rdrf);
+       //state_fio->FputUint8(rmcr);
+       //state_fio->FputInt32(sio_counter);
+       //state_fio->FputUint8(ram_ctrl);
+       //state_fio->Fwrite(ram, sizeof(ram), 1);
 //#endif
 }
 
 bool HD6301::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) {
-               return false;
-       }
-       pc.d = state_fio->FgetUint32();
-       prevpc = state_fio->FgetUint16();
-       sp.d = state_fio->FgetUint32();
-       ix.d = state_fio->FgetUint32();
-       acc_d.d = state_fio->FgetUint32();
-       ea.d = state_fio->FgetUint32();
-       cc = state_fio->FgetUint8();
-       wai_state = state_fio->FgetInt32();
-       int_state = state_fio->FgetInt32();
-       if(__USE_DEBUGGER) { total_icount = prev_total_icount = state_fio->FgetUint64(); }
-       icount = state_fio->FgetInt32();
+       if(!mb) return false;
+       //if(state_fio->FgetUint32() != STATE_VERSION) {
+       //      return false;
+       //}
+       //if(state_fio->FgetInt32() != this_device_id) {
+       //      return false;
+       //}
+       //pc.d = state_fio->FgetUint32();
+       //prevpc = state_fio->FgetUint16();
+       //sp.d = state_fio->FgetUint32();
+       //ix.d = state_fio->FgetUint32();
+       //acc_d.d = state_fio->FgetUint32();
+       //ea.d = state_fio->FgetUint32();
+       //cc = state_fio->FgetUint8();
+       //wai_state = state_fio->FgetInt32();
+       //int_state = state_fio->FgetInt32();
+       //if(__USE_DEBUGGER) { total_icount = prev_total_icount = state_fio->FgetUint64(); }
+       //icount = state_fio->FgetInt32();
 //#if defined(HAS_MC6801) || defined(HAS_HD6301)
-       for(int i = 0; i < 4; i++) {
-               port[i].wreg = state_fio->FgetUint8();
-               port[i].rreg = state_fio->FgetUint8();
-               port[i].ddr = state_fio->FgetUint8();
-               port[i].latched_data = state_fio->FgetUint8();
-               port[i].latched = state_fio->FgetBool();
-               port[i].first_write = state_fio->FgetBool();
-       }
-       p3csr = state_fio->FgetUint8();
-       p3csr_is3_flag_read = state_fio->FgetBool();
-       sc1_state = state_fio->FgetBool();
-       sc2_state = state_fio->FgetBool();
-       counter.d = state_fio->FgetUint32();
-       output_compare.d = state_fio->FgetUint32();
-       timer_over.d = state_fio->FgetUint32();
-       tcsr = state_fio->FgetUint8();
-       pending_tcsr = state_fio->FgetUint8();
-       input_capture = state_fio->FgetUint16();
+       //for(int i = 0; i < 4; i++) {
+       //      port[i].wreg = state_fio->FgetUint8();
+       //      port[i].rreg = state_fio->FgetUint8();
+       //      port[i].ddr = state_fio->FgetUint8();
+       //      port[i].latched_data = state_fio->FgetUint8();
+       //      port[i].latched = state_fio->FgetBool();
+       //      port[i].first_write = state_fio->FgetBool();
+       //}
+       //p3csr = state_fio->FgetUint8();
+       //p3csr_is3_flag_read = state_fio->FgetBool();
+       //sc1_state = state_fio->FgetBool();
+       //sc2_state = state_fio->FgetBool();
+       //counter.d = state_fio->FgetUint32();
+       //output_compare.d = state_fio->FgetUint32();
+       //timer_over.d = state_fio->FgetUint32();
+       //tcsr = state_fio->FgetUint8();
+       //pending_tcsr = state_fio->FgetUint8();
+       //input_capture = state_fio->FgetUint16();
 //#ifdef HAS_HD6301
-       latch09 = state_fio->FgetUint16();
+       //latch09 = state_fio->FgetUint16();
 //#endif
-       timer_next = state_fio->FgetUint32();
+       //timer_next = state_fio->FgetUint32();
+       if(__USE_DEBUGGER) {
+               prev_total_icount = total_icount;
+       }
        if(!recv_buffer->load_state((void *)state_fio)) {
                return false;
        }
-       trcsr = state_fio->FgetUint8();
-       rdr = state_fio->FgetUint8();
-       tdr = state_fio->FgetUint8();
-       trcsr_read_tdre = state_fio->FgetBool();
-       trcsr_read_orfe = state_fio->FgetBool();
-       trcsr_read_rdrf = state_fio->FgetBool();
-       rmcr = state_fio->FgetUint8();
-       sio_counter = state_fio->FgetInt32();
-       ram_ctrl = state_fio->FgetUint8();
-       state_fio->Fread(ram, sizeof(ram), 1);
+       //trcsr = state_fio->FgetUint8();
+       //rdr = state_fio->FgetUint8();
+       //tdr = state_fio->FgetUint8();
+       //trcsr_read_tdre = state_fio->FgetBool();
+       //trcsr_read_orfe = state_fio->FgetBool();
+       //trcsr_read_rdrf = state_fio->FgetBool();
+       //rmcr = state_fio->FgetUint8();
+       //sio_counter = state_fio->FgetInt32();
+       //ram_ctrl = state_fio->FgetUint8();
+       //state_fio->Fread(ram, sizeof(ram), 1);
 //#endif
        return true;
 }
index f715bf3..6a7702f 100644 (file)
@@ -59,6 +59,7 @@ public:
                set_device_name(_T("HD6301 MPU"));
        }
        ~HD6301() {}
+       void decl_state();
        void save_state(FILEIO* state_fio) override;
        bool load_state(FILEIO* state_fio) override;
 
index e08502e..ed98bed 100644 (file)
@@ -117,34 +117,57 @@ int HUC6280::run_one_opecode()
 
 #define STATE_VERSION  5
 
-void HUC6280::save_state(FILEIO* state_fio)
+#include "../statesub.h"
+
+void HUC6280::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       // You should call this after initialize().
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("HuC6280"));
+       
+       decl_state_registers();
        
-
-       save_state_registers(state_fio);
 #ifdef USE_DEBUGGER
-       state_fio->FputUint64(total_icount);
+       DECL_STATE_ENTRY_UINT64(total_icount);
 #endif
-       state_fio->FputInt32(icount);
-       state_fio->FputBool(busreq);
+       DECL_STATE_ENTRY_INT32(icount);
+       DECL_STATE_ENTRY_BOOL(busreq);
+       
+}
+void HUC6280::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);
+
+       //save_state_registers(state_fio);
+//#ifdef USE_DEBUGGER
+       //state_fio->FputUint64(total_icount);
+//#endif
+       //state_fio->FputInt32(icount);
+       //state_fio->FputBool(busreq);
 }
 
 bool HUC6280::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-#ifdef USE_DEBUGGER
-       total_icount = prev_total_icount = state_fio->FgetUint64();
-#endif
-       load_state_registers(state_fio);
-       icount = state_fio->FgetInt32();
-       busreq = state_fio->FgetBool();
+       if(!mb) return false;
+       //if(state_fio->FgetUint32() != STATE_VERSION) {
+       //      return false;
+       //}
+       //if(state_fio->FgetInt32() != this_device_id) {
+       //      return false;
+       //}
+//#ifdef USE_DEBUGGER
+       //total_icount = prev_total_icount = state_fio->FgetUint64();
+//#endif
+       //load_state_registers(state_fio);
+       //icount = state_fio->FgetInt32();
+       //busreq = state_fio->FgetBool();
 
        // post process   
        h6280_Regs *cpustate = (h6280_Regs *)opaque;
@@ -155,6 +178,7 @@ bool HUC6280::load_state(FILEIO* state_fio)
        cpustate->debugger = d_debugger;
        cpustate->program_stored = d_mem;
        cpustate->io_stored = d_io;
+       prev_total_icount = total_icount;
 #endif
        return true;
 }
index 98fc0ba..5e565f8 100644 (file)
@@ -72,6 +72,7 @@ public:
        void get_debug_regs_info(_TCHAR *buffer, size_t buffer_len);
        int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
 //#endif
+       void decl_state_registers();
        void save_state_registers(FILEIO* state_fio);
        void load_state_registers(FILEIO* state_fio);
        
@@ -106,7 +107,8 @@ public:
        void release();
        void reset();
        int run(int clock);
-       
+
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 0e3bc21..8148ad9 100644 (file)
@@ -245,6 +245,36 @@ int HUC6280_BASE::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
 }
 //#endif
 
+#include "../statesub.h"
+
+void HUC6280_BASE::decl_state_registers()
+{
+       // You should call this after initialize().
+       h6280_Regs *cpustate = (h6280_Regs *)opaque;
+
+       DECL_STATE_ENTRY_INT32((cpustate->ICount));
+       DECL_STATE_ENTRY_PAIR((cpustate->ppc));
+       DECL_STATE_ENTRY_PAIR((cpustate->pc));
+       DECL_STATE_ENTRY_PAIR((cpustate->sp));
+       DECL_STATE_ENTRY_PAIR((cpustate->zp));
+       DECL_STATE_ENTRY_PAIR((cpustate->ea));
+       DECL_STATE_ENTRY_UINT8((cpustate->a));
+       DECL_STATE_ENTRY_UINT8((cpustate->x));
+       DECL_STATE_ENTRY_UINT8((cpustate->y));
+       DECL_STATE_ENTRY_UINT8((cpustate->p));
+       DECL_STATE_ENTRY_1D_ARRAY(cpustate->mmr, sizeof(uint8_t) * 8);
+       DECL_STATE_ENTRY_UINT8((cpustate->irq_mask));
+       DECL_STATE_ENTRY_UINT8((cpustate->timer_status));
+       DECL_STATE_ENTRY_UINT8((cpustate->timer_ack));
+       DECL_STATE_ENTRY_UINT8((cpustate->clocks_per_cycle));
+       DECL_STATE_ENTRY_INT32((cpustate->timer_value));
+       DECL_STATE_ENTRY_INT32((cpustate->timer_load));
+       DECL_STATE_ENTRY_UINT8(cpustate->nmi_state);
+       DECL_STATE_ENTRY_1D_ARRAY(cpustate->irq_state, sizeof(uint8_t) * 3);
+       DECL_STATE_ENTRY_UINT8((cpustate->irq_pending));
+}
+
+       
 void HUC6280_BASE::save_state_registers(FILEIO* state_fio)
 {
        h6280_Regs *cpustate = (h6280_Regs *)opaque;
index c53cb2e..2ee941c 100644 (file)
@@ -572,52 +572,83 @@ void I8080::check_interrupt()
 }
 
 
-
 #define STATE_VERSION  2
 
-void I8080::save_state(FILEIO* state_fio)
+#include "../statesub.h"
+
+void I8080::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("i8080"));
+
 #ifdef USE_DEBUGGER
-       state_fio->FputUint64(total_count);
+       DECL_STATE_ENTRY_UINT64(total_count);
 #endif
-       state_fio->FputInt32(count);
-       state_fio->Fwrite(regs, sizeof(regs), 1);
-       state_fio->FputUint16(SP);
-       state_fio->FputUint16(PC);
-       state_fio->FputUint16(prevPC);
-       state_fio->FputUint16(IM);
-       state_fio->FputUint16(RIM_IEN);
-       state_fio->FputBool(afterHALT);
-       state_fio->FputBool(BUSREQ);
-       state_fio->FputBool(SID);
-       state_fio->FputBool(afterEI);
+       DECL_STATE_ENTRY_INT32(count);
+       DECL_STATE_ENTRY_1D_ARRAY(regs, sizeof(regs) / sizeof(pair_t));
+       DECL_STATE_ENTRY_UINT16(SP);
+       DECL_STATE_ENTRY_UINT16(PC);
+       DECL_STATE_ENTRY_UINT16(prevPC);
+       DECL_STATE_ENTRY_UINT16(IM);
+       DECL_STATE_ENTRY_UINT16(RIM_IEN);
+       DECL_STATE_ENTRY_BOOL(afterHALT);
+       DECL_STATE_ENTRY_BOOL(BUSREQ);
+       DECL_STATE_ENTRY_BOOL(SID);
+       DECL_STATE_ENTRY_BOOL(afterEI);
+
+}
+void I8080::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 USE_DEBUGGER
+//     state_fio->FputUint64(total_count);
+//#endif
+//     state_fio->FputInt32(count);
+//     state_fio->Fwrite(regs, sizeof(regs), 1);
+//     state_fio->FputUint16(SP);
+//     state_fio->FputUint16(PC);
+//     state_fio->FputUint16(prevPC);
+//     state_fio->FputUint16(IM);
+//     state_fio->FputUint16(RIM_IEN);
+//     state_fio->FputBool(afterHALT);
+//     state_fio->FputBool(BUSREQ);
+//     state_fio->FputBool(SID);
+//     state_fio->FputBool(afterEI);
 }
 
 bool I8080::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) {
-               return false;
-       }
-#ifdef USE_DEBUGGER
-       total_count = prev_total_count = state_fio->FgetUint64();
-#endif
-       count = state_fio->FgetInt32();
-       state_fio->Fread(regs, sizeof(regs), 1);
-       SP = state_fio->FgetUint16();
-       PC = state_fio->FgetUint16();
-       prevPC = state_fio->FgetUint16();
-       IM = state_fio->FgetUint16();
-       RIM_IEN = state_fio->FgetUint16();
-       afterHALT = state_fio->FgetBool();
-       BUSREQ = state_fio->FgetBool();
-       SID = state_fio->FgetBool();
-       afterEI = state_fio->FgetBool();
+       if(!mb) return false;
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//#ifdef USE_DEBUGGER
+//     total_count = prev_total_count = state_fio->FgetUint64();
+//#endif
+//     count = state_fio->FgetInt32();
+//     state_fio->Fread(regs, sizeof(regs), 1);
+//     SP = state_fio->FgetUint16();
+//     PC = state_fio->FgetUint16();
+//     prevPC = state_fio->FgetUint16();
+//     IM = state_fio->FgetUint16();
+//     RIM_IEN = state_fio->FgetUint16();
+//     afterHALT = state_fio->FgetBool();
+//     BUSREQ = state_fio->FgetBool();
+//     SID = state_fio->FgetBool();
+//     afterEI = state_fio->FgetBool();
+//
+       prev_total_count = total_count;
        return true;
 }
 
index 4a2e78f..dcb346d 100644 (file)
@@ -195,6 +195,7 @@ public:
        void reset();
        int run(int clock);
        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 7500477..c6a42a5 100644 (file)
@@ -318,67 +318,105 @@ void I8155::set_pio(int ch, uint8_t data)
 
 #define STATE_VERSION  1
 
-void I8155::save_state(FILEIO* state_fio)
+#include "../statesub.h"
+
+void I8155::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputUint16(count);
-       state_fio->FputUint16(countreg);
-       state_fio->FputBool(now_count);
-       state_fio->FputBool(stop_tc);
-       state_fio->FputBool(half);
-       state_fio->FputBool(prev_out);
-       state_fio->FputBool(prev_in);
-       state_fio->FputUint64(freq);
-       state_fio->FputInt32(register_id);
-       state_fio->FputUint32(input_clk);
-       state_fio->FputUint32(prev_clk);
-       state_fio->FputInt32(period);
-       state_fio->FputUint64(cpu_clocks);
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("i8155"));
+
+       DECL_STATE_ENTRY_UINT16(count);
+       DECL_STATE_ENTRY_UINT16(countreg);
+       DECL_STATE_ENTRY_BOOL(now_count);
+       DECL_STATE_ENTRY_BOOL(stop_tc);
+       DECL_STATE_ENTRY_BOOL(half);
+       DECL_STATE_ENTRY_BOOL(prev_out);
+       DECL_STATE_ENTRY_BOOL(prev_in);
+       DECL_STATE_ENTRY_UINT64(freq);
+       DECL_STATE_ENTRY_INT32(register_id);
+       DECL_STATE_ENTRY_UINT32(input_clk);
+       DECL_STATE_ENTRY_UINT32(prev_clk);
+       DECL_STATE_ENTRY_INT32(period);
+       DECL_STATE_ENTRY_UINT64(cpu_clocks);
        for(int i = 0; i < 3; i++) {
-               state_fio->FputUint8(pio[i].wreg);
-               state_fio->FputUint8(pio[i].rreg);
-               state_fio->FputUint8(pio[i].rmask);
-               state_fio->FputUint8(pio[i].mode);
-               state_fio->FputBool(pio[i].first);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pio[i].wreg), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pio[i].rreg), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pio[i].rmask), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pio[i].mode), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((pio[i].first), i);
+       }
+       DECL_STATE_ENTRY_UINT8(cmdreg);
+       DECL_STATE_ENTRY_UINT8(statreg);
+       DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
+}
+void I8155::save_state(FILEIO* state_fio)
+{
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
        }
-       state_fio->FputUint8(cmdreg);
-       state_fio->FputUint8(statreg);
-       state_fio->Fwrite(ram, sizeof(ram), 1);
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
+       
+//     state_fio->FputUint16(count);
+//     state_fio->FputUint16(countreg);
+//     state_fio->FputBool(now_count);
+//     state_fio->FputBool(stop_tc);
+//     state_fio->FputBool(half);
+//     state_fio->FputBool(prev_out);
+//     state_fio->FputBool(prev_in);
+//     state_fio->FputUint64(freq);
+//     state_fio->FputInt32(register_id);
+//     state_fio->FputUint32(input_clk);
+//     state_fio->FputUint32(prev_clk);
+//     state_fio->FputInt32(period);
+//     state_fio->FputUint64(cpu_clocks);
+//     for(int i = 0; i < 3; i++) {
+//             state_fio->FputUint8(pio[i].wreg);
+//             state_fio->FputUint8(pio[i].rreg);
+//             state_fio->FputUint8(pio[i].rmask);
+//             state_fio->FputUint8(pio[i].mode);
+//             state_fio->FputBool(pio[i].first);
+//     }
+//     state_fio->FputUint8(cmdreg);
+//     state_fio->FputUint8(statreg);
+//     state_fio->Fwrite(ram, sizeof(ram), 1);
 }
 
 bool I8155::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
-       }
-       count = state_fio->FgetUint16();
-       countreg = state_fio->FgetUint16();
-       now_count = state_fio->FgetBool();
-       stop_tc = state_fio->FgetBool();
-       half = state_fio->FgetBool();
-       prev_out = state_fio->FgetBool();
-       prev_in = state_fio->FgetBool();
-       freq = state_fio->FgetUint64();
-       register_id = state_fio->FgetInt32();
-       input_clk = state_fio->FgetUint32();
-       prev_clk = state_fio->FgetUint32();
-       period = state_fio->FgetInt32();
-       cpu_clocks = state_fio->FgetUint64();
-       for(int i = 0; i < 3; i++) {
-               pio[i].wreg = state_fio->FgetUint8();
-               pio[i].rreg = state_fio->FgetUint8();
-               pio[i].rmask = state_fio->FgetUint8();
-               pio[i].mode = state_fio->FgetUint8();
-               pio[i].first = state_fio->FgetBool();
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       cmdreg = state_fio->FgetUint8();
-       statreg = state_fio->FgetUint8();
-       state_fio->Fread(ram, sizeof(ram), 1);
+       if(!mb) return false;
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     count = state_fio->FgetUint16();
+//     countreg = state_fio->FgetUint16();
+//     now_count = state_fio->FgetBool();
+//     stop_tc = state_fio->FgetBool();
+//     half = state_fio->FgetBool();
+//     prev_out = state_fio->FgetBool();
+//     prev_in = state_fio->FgetBool();
+//     freq = state_fio->FgetUint64();
+//     register_id = state_fio->FgetInt32();
+//     input_clk = state_fio->FgetUint32();
+//     prev_clk = state_fio->FgetUint32();
+//     period = state_fio->FgetInt32();
+//     cpu_clocks = state_fio->FgetUint64();
+//     for(int i = 0; i < 3; i++) {
+//             pio[i].wreg = state_fio->FgetUint8();
+//             pio[i].rreg = state_fio->FgetUint8();
+//             pio[i].rmask = state_fio->FgetUint8();
+//             pio[i].mode = state_fio->FgetUint8();
+//             pio[i].first = state_fio->FgetBool();
+//     }
+//     cmdreg = state_fio->FgetUint8();
+//     statreg = state_fio->FgetUint8();
+//     state_fio->Fread(ram, sizeof(ram), 1);
        return true;
 }
 
index 527cd7f..b058a2e 100644 (file)
@@ -83,6 +83,7 @@ public:
        {
                cpu_clocks = new_clocks;
        }
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index c046440..c2b311c 100644 (file)
@@ -209,55 +209,88 @@ void I8237::do_dma()
 
 #define STATE_VERSION  2
 
-void I8237::save_state(FILEIO* state_fio)
+#include "../statesub.h"
+
+void I8237::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("i8237"));
        
        for(int i = 0; i < 4; i++) {
-               state_fio->FputUint16(dma[i].areg);
-               state_fio->FputUint16(dma[i].creg);
-               state_fio->FputUint16(dma[i].bareg);
-               state_fio->FputUint16(dma[i].bcreg);
-               state_fio->FputUint8(dma[i].mode);
-               state_fio->FputUint16(dma[i].bankreg);
-               state_fio->FputUint16(dma[i].incmask);
+               DECL_STATE_ENTRY_UINT16_MEMBER((dma[i].areg), i);
+               DECL_STATE_ENTRY_UINT16_MEMBER((dma[i].creg), i);
+               DECL_STATE_ENTRY_UINT16_MEMBER((dma[i].bareg), i);
+               DECL_STATE_ENTRY_UINT16_MEMBER((dma[i].bcreg), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((dma[i].mode), i);
+               DECL_STATE_ENTRY_UINT16_MEMBER((dma[i].bankreg), i);
+               DECL_STATE_ENTRY_UINT16_MEMBER((dma[i].incmask), i);
        }
-       state_fio->FputBool(low_high);
-       state_fio->FputUint8(cmd);
-       state_fio->FputUint8(req);
-       state_fio->FputUint8(mask);
-       state_fio->FputUint8(tc);
-       state_fio->FputUint32(tmp);
-       state_fio->FputBool(mode_word);
-       state_fio->FputUint32(addr_mask);
+       DECL_STATE_ENTRY_BOOL(low_high);
+       DECL_STATE_ENTRY_UINT8(cmd);
+       DECL_STATE_ENTRY_UINT8(req);
+       DECL_STATE_ENTRY_UINT8(mask);
+       DECL_STATE_ENTRY_UINT8(tc);
+       DECL_STATE_ENTRY_UINT32(tmp);
+       DECL_STATE_ENTRY_BOOL(mode_word);
+       DECL_STATE_ENTRY_UINT32(addr_mask);
+
+}
+void I8237::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 < 4; i++) {
+//             state_fio->FputUint16(dma[i].areg);
+//             state_fio->FputUint16(dma[i].creg);
+//             state_fio->FputUint16(dma[i].bareg);
+//             state_fio->FputUint16(dma[i].bcreg);
+//             state_fio->FputUint8(dma[i].mode);
+//             state_fio->FputUint16(dma[i].bankreg);
+//             state_fio->FputUint16(dma[i].incmask);
+//     }
+//     state_fio->FputBool(low_high);
+//     state_fio->FputUint8(cmd);
+//     state_fio->FputUint8(req);
+//     state_fio->FputUint8(mask);
+//     state_fio->FputUint8(tc);
+//     state_fio->FputUint32(tmp);
+//     state_fio->FputBool(mode_word);
+//     state_fio->FputUint32(addr_mask);
 }
 
 bool I8237::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
-       }
-       for(int i = 0; i < 4; i++) {
-               dma[i].areg = state_fio->FgetUint16();
-               dma[i].creg = state_fio->FgetUint16();
-               dma[i].bareg = state_fio->FgetUint16();
-               dma[i].bcreg = state_fio->FgetUint16();
-               dma[i].mode = state_fio->FgetUint8();
-               dma[i].bankreg = state_fio->FgetUint16();
-               dma[i].incmask = state_fio->FgetUint16();
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       low_high = state_fio->FgetBool();
-       cmd = state_fio->FgetUint8();
-       req = state_fio->FgetUint8();
-       mask = state_fio->FgetUint8();
-       tc = state_fio->FgetUint8();
-       tmp = state_fio->FgetUint32();
-       mode_word = state_fio->FgetBool();
-       addr_mask = state_fio->FgetUint32();
+       if(!mb) return false;
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     for(int i = 0; i < 4; i++) {
+//             dma[i].areg = state_fio->FgetUint16();
+//             dma[i].creg = state_fio->FgetUint16();
+//             dma[i].bareg = state_fio->FgetUint16();
+//             dma[i].bcreg = state_fio->FgetUint16();
+//             dma[i].mode = state_fio->FgetUint8();
+//             dma[i].bankreg = state_fio->FgetUint16();
+//             dma[i].incmask = state_fio->FgetUint16();
+//     }
+//     low_high = state_fio->FgetBool();
+//     cmd = state_fio->FgetUint8();
+//     req = state_fio->FgetUint8();
+//     mask = state_fio->FgetUint8();
+//     tc = state_fio->FgetUint8();
+//     tmp = state_fio->FgetUint32();
+//     mode_word = state_fio->FgetBool();
+//     addr_mask = state_fio->FgetUint32();
        return true;
 }
 
index 2bcae34..f903a69 100644 (file)
@@ -84,6 +84,7 @@ public:
        uint32_t read_io8(uint32_t addr);
        virtual void write_signal(int id, uint32_t data, uint32_t mask);
        virtual void do_dma();
+       
        virtual void save_state(FILEIO* state_fio) {};
        virtual bool load_state(FILEIO* state_fio) { return false;}
        
@@ -147,6 +148,7 @@ public:
        void write_signal(int id, uint32_t data, uint32_t mask);
        uint32_t read_signal(int id);
        void do_dma();
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
 #ifdef SINGLE_MODE_DMA
index 1c4c145..4face6b 100644 (file)
@@ -231,45 +231,71 @@ void I8251::event_callback(int event_id, int err)
 
 #define STATE_VERSION  1
 
+#include "../statesub.h"
+
+void I8251::decl_state()
+{
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("i8251"));
+
+       DECL_STATE_ENTRY_UINT8(recv);
+       DECL_STATE_ENTRY_UINT8(status);
+       DECL_STATE_ENTRY_UINT8(mode);
+       DECL_STATE_ENTRY_BOOL(txen);
+       DECL_STATE_ENTRY_BOOL(rxen);
+       DECL_STATE_ENTRY_BOOL(loopback);
+       //recv_buffer->save_state((void *)state_fio);
+       //send_buffer->save_state((void *)state_fio);
+       DECL_STATE_ENTRY_INT32(recv_id);
+       DECL_STATE_ENTRY_INT32(send_id);
+       
+}
 void I8251::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(recv);
-       state_fio->FputUint8(status);
-       state_fio->FputUint8(mode);
-       state_fio->FputBool(txen);
-       state_fio->FputBool(rxen);
-       state_fio->FputBool(loopback);
+//     state_fio->FputUint8(recv);
+//     state_fio->FputUint8(status);
+//     state_fio->FputUint8(mode);
+//     state_fio->FputBool(txen);
+//     state_fio->FputBool(rxen);
+//     state_fio->FputBool(loopback);
        recv_buffer->save_state((void *)state_fio);
        send_buffer->save_state((void *)state_fio);
-       state_fio->FputInt32(recv_id);
-       state_fio->FputInt32(send_id);
+//     state_fio->FputInt32(recv_id);
+//     state_fio->FputInt32(send_id);
 }
 
 bool I8251::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       recv = state_fio->FgetUint8();
-       status = state_fio->FgetUint8();
-       mode = state_fio->FgetUint8();
-       txen = state_fio->FgetBool();
-       rxen = state_fio->FgetBool();
-       loopback = state_fio->FgetBool();
+       if(!mb) return false;
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     recv = state_fio->FgetUint8();
+//     status = state_fio->FgetUint8();
+//     mode = state_fio->FgetUint8();
+//     txen = state_fio->FgetBool();
+//     rxen = state_fio->FgetBool();
+//     loopback = state_fio->FgetBool();
        if(!recv_buffer->load_state((void *)state_fio)) {
                return false;
        }
        if(!send_buffer->load_state((void *)state_fio)) {
                return false;
        }
-       recv_id = state_fio->FgetInt32();
-       send_id = state_fio->FgetInt32();
+//     recv_id = state_fio->FgetInt32();
+//     send_id = state_fio->FgetInt32();
        return true;
 }
 
index 527aada..d9c59f8 100644 (file)
@@ -66,6 +66,7 @@ public:
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
        void event_callback(int event_id, int err);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index 543005d..679dd67 100644 (file)
@@ -416,80 +416,126 @@ int I8253::get_next_count(int ch)
 
 #define STATE_VERSION  1
 
-void I8253::save_state(FILEIO* state_fio)
+#include "../statesub.h"
+
+void I8253::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("i8253"));
+
        for(int i = 0; i < 3; i++) {
-               state_fio->FputBool(counter[i].prev_out);
-               state_fio->FputBool(counter[i].prev_in);
-               state_fio->FputBool(counter[i].gate);
-               state_fio->FputInt32(counter[i].count);
-               state_fio->FputUint16(counter[i].latch);
-               state_fio->FputUint16(counter[i].count_reg);
-               state_fio->FputUint8(counter[i].ctrl_reg);
-               state_fio->FputBool(counter[i].count_latched);
-               state_fio->FputBool(counter[i].low_read);
-               state_fio->FputBool(counter[i].high_read);
-               state_fio->FputBool(counter[i].low_write);
-               state_fio->FputBool(counter[i].high_write);
-               state_fio->FputInt32(counter[i].mode);
-               state_fio->FputBool(counter[i].delay);
-               state_fio->FputBool(counter[i].start);
+               DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].prev_out), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].prev_in), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].gate), i);
+               DECL_STATE_ENTRY_INT32_MEMBER((counter[i].count), i);
+               DECL_STATE_ENTRY_UINT16_MEMBER((counter[i].latch), i);
+               DECL_STATE_ENTRY_UINT16_MEMBER((counter[i].count_reg), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((counter[i].ctrl_reg), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].count_latched), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].low_read), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].high_read), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].low_write), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].high_write), i);
+               DECL_STATE_ENTRY_INT32_MEMBER((counter[i].mode), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].delay), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].start), i);
 //#ifdef HAS_I8254
                if(__HAS_I8254) {
-                       state_fio->FputBool(counter[i].null_count);
-                       state_fio->FputBool(counter[i].status_latched);
-                       state_fio->FputUint8(counter[i].status);
+                       DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].null_count), i);
+                       DECL_STATE_ENTRY_BOOL_MEMBER((counter[i].status_latched), i);
+                       DECL_STATE_ENTRY_UINT8_MEMBER((counter[i].status), i);
                }
 //#endif
-               state_fio->FputUint64(counter[i].freq);
-               state_fio->FputInt32(counter[i].register_id);
-               state_fio->FputUint32(counter[i].input_clk);
-               state_fio->FputInt32(counter[i].period);
-               state_fio->FputUint32(counter[i].prev_clk);
+               DECL_STATE_ENTRY_UINT64_MEMBER((counter[i].freq), i);
+               DECL_STATE_ENTRY_INT32_MEMBER((counter[i].register_id), i);
+               DECL_STATE_ENTRY_UINT32_MEMBER((counter[i].input_clk), i);
+               DECL_STATE_ENTRY_INT32_MEMBER((counter[i].period), i);
+               DECL_STATE_ENTRY_UINT32_MEMBER((counter[i].prev_clk), i);
        }
-       state_fio->FputUint64(cpu_clocks);
+       DECL_STATE_ENTRY_UINT64(cpu_clocks);
 }
 
-bool I8253::load_state(FILEIO* state_fio)
+void I8253::save_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
        }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
-       }
-       for(int i = 0; i < 3; i++) {
-               counter[i].prev_out = state_fio->FgetBool();
-               counter[i].prev_in = state_fio->FgetBool();
-               counter[i].gate = state_fio->FgetBool();
-               counter[i].count = state_fio->FgetInt32();
-               counter[i].latch = state_fio->FgetUint16();
-               counter[i].count_reg = state_fio->FgetUint16();
-               counter[i].ctrl_reg = state_fio->FgetUint8();
-               counter[i].count_latched = state_fio->FgetBool();
-               counter[i].low_read = state_fio->FgetBool();
-               counter[i].high_read = state_fio->FgetBool();
-               counter[i].low_write = state_fio->FgetBool();
-               counter[i].high_write = state_fio->FgetBool();
-               counter[i].mode = state_fio->FgetInt32();
-               counter[i].delay = state_fio->FgetBool();
-               counter[i].start = state_fio->FgetBool();
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
+//     
+//     for(int i = 0; i < 3; i++) {
+//             state_fio->FputBool(counter[i].prev_out);
+//             state_fio->FputBool(counter[i].prev_in);
+//             state_fio->FputBool(counter[i].gate);
+//             state_fio->FputInt32(counter[i].count);
+//             state_fio->FputUint16(counter[i].latch);
+//             state_fio->FputUint16(counter[i].count_reg);
+//             state_fio->FputUint8(counter[i].ctrl_reg);
+//             state_fio->FputBool(counter[i].count_latched);
+//             state_fio->FputBool(counter[i].low_read);
+//             state_fio->FputBool(counter[i].high_read);
+//             state_fio->FputBool(counter[i].low_write);
+//             state_fio->FputBool(counter[i].high_write);
+//             state_fio->FputInt32(counter[i].mode);
+//             state_fio->FputBool(counter[i].delay);
+//             state_fio->FputBool(counter[i].start);
 //#ifdef HAS_I8254
-               if(__HAS_I8254) {
-                       counter[i].null_count = state_fio->FgetBool();
-                       counter[i].status_latched = state_fio->FgetBool();
-                       counter[i].status = state_fio->FgetUint8();
-               }
+//             if(__HAS_I8254) {
+//                     state_fio->FputBool(counter[i].null_count);
+//                     state_fio->FputBool(counter[i].status_latched);
+//                     state_fio->FputUint8(counter[i].status);
+//             }
 //#endif
-               counter[i].freq = state_fio->FgetUint64();
-               counter[i].register_id = state_fio->FgetInt32();
-               counter[i].input_clk = state_fio->FgetUint32();
-               counter[i].period = state_fio->FgetInt32();
-               counter[i].prev_clk = state_fio->FgetUint32();
+//             state_fio->FputUint64(counter[i].freq);
+//             state_fio->FputInt32(counter[i].register_id);
+//             state_fio->FputUint32(counter[i].input_clk);
+//             state_fio->FputInt32(counter[i].period);
+//             state_fio->FputUint32(counter[i].prev_clk);
+//     }
+//     state_fio->FputUint64(cpu_clocks);
+}
+
+bool I8253::load_state(FILEIO* state_fio)
+{
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       cpu_clocks = state_fio->FgetUint64();
+       if(!mb) return false;
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     for(int i = 0; i < 3; i++) {
+//             counter[i].prev_out = state_fio->FgetBool();
+//             counter[i].prev_in = state_fio->FgetBool();
+//             counter[i].gate = state_fio->FgetBool();
+//             counter[i].count = state_fio->FgetInt32();
+//             counter[i].latch = state_fio->FgetUint16();
+//             counter[i].count_reg = state_fio->FgetUint16();
+//             counter[i].ctrl_reg = state_fio->FgetUint8();
+//             counter[i].count_latched = state_fio->FgetBool();
+//             counter[i].low_read = state_fio->FgetBool();
+//             counter[i].high_read = state_fio->FgetBool();
+//             counter[i].low_write = state_fio->FgetBool();
+//             counter[i].high_write = state_fio->FgetBool();
+//             counter[i].mode = state_fio->FgetInt32();
+//             counter[i].delay = state_fio->FgetBool();
+//             counter[i].start = state_fio->FgetBool();
+//#ifdef HAS_I8254
+//             if(__HAS_I8254) {
+//                     counter[i].null_count = state_fio->FgetBool();
+//                     counter[i].status_latched = state_fio->FgetBool();
+//                     counter[i].status = state_fio->FgetUint8();
+//             }
+//#endif
+//             counter[i].freq = state_fio->FgetUint64();
+//             counter[i].register_id = state_fio->FgetInt32();
+//             counter[i].input_clk = state_fio->FgetUint32();
+//             counter[i].period = state_fio->FgetInt32();
+//             counter[i].prev_clk = state_fio->FgetUint32();
+//     }
+//     cpu_clocks = state_fio->FgetUint64();
        return true;
 }
index 125d9ea..c635d3d 100644 (file)
@@ -87,6 +87,7 @@ public:
        {
                cpu_clocks = new_clocks;
        }
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        
index fd25f7d..d218173 100644 (file)
@@ -243,35 +243,58 @@ uint32_t I8255::read_signal(int id)
 
 #define STATE_VERSION  1
 
-void I8255::save_state(FILEIO* state_fio)
+#include "../statesub.h"
+
+void I8255::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("i8255"));
        
        for(int i = 0; i < 3; i++) {
-               state_fio->FputUint8(port[i].wreg);
-               state_fio->FputUint8(port[i].rreg);
-               state_fio->FputUint8(port[i].rmask);
-               state_fio->FputUint8(port[i].mode);
-               state_fio->FputBool(port[i].first);
+               DECL_STATE_ENTRY_UINT8_MEMBER((port[i].wreg), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((port[i].rreg), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((port[i].rmask), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((port[i].mode), i);
+               DECL_STATE_ENTRY_BOOL_MEMBER((port[i].first), i);
        }
+       
+}
+void I8255::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->FputUint8(port[i].wreg);
+//             state_fio->FputUint8(port[i].rreg);
+//             state_fio->FputUint8(port[i].rmask);
+//             state_fio->FputUint8(port[i].mode);
+//             state_fio->FputBool(port[i].first);
+//     }
 }
 
 bool I8255::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
-       }
-       for(int i = 0; i < 3; i++) {
-               port[i].wreg = state_fio->FgetUint8();
-               port[i].rreg = state_fio->FgetUint8();
-               port[i].rmask = state_fio->FgetUint8();
-               port[i].mode = state_fio->FgetUint8();
-               port[i].first = state_fio->FgetBool();
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
+       if(!mb) return false;
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     for(int i = 0; i < 3; i++) {
+//             port[i].wreg = state_fio->FgetUint8();
+//             port[i].rreg = state_fio->FgetUint8();
+//             port[i].rmask = state_fio->FgetUint8();
+//             port[i].mode = state_fio->FgetUint8();
+//             port[i].first = state_fio->FgetBool();
+//     }
        return true;
 }
 
index 13ed801..b07aa97 100644 (file)
@@ -52,6 +52,7 @@ public:
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
        uint32_t read_signal(int id);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        // unique functions
index 67eba1b..14cc129 100644 (file)
@@ -279,29 +279,68 @@ uint32_t I8259::get_intr_ack()
 
 #define STATE_VERSION  1
 
+#include "../statesub.h"
+
+void I8259::decl_state()
+{
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("i8259"));
+       
+       for(int i = 0; i < __I8259_MAX_CHIPS; i++) {
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].imr), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].isr), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].irr), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].irr_tmp), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].prio), i);
+               
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].icw1), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].icw2), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].icw3), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].icw4), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].ocw3), i);
+               
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].icw2_r), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].icw3_r), i);
+               DECL_STATE_ENTRY_UINT8_MEMBER((pic[i].icw4_r), i);
+
+               DECL_STATE_ENTRY_INT32_MEMBER((pic[i].irr_tmp_id), i);
+       }
+
+       DECL_STATE_ENTRY_INT32(req_chip);
+       DECL_STATE_ENTRY_INT32(req_level);
+       DECL_STATE_ENTRY_UINT8(req_bit);
+}
+
 void I8259::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);
        
-       for(int i = 0; i < __I8259_MAX_CHIPS; i++) state_fio->Fwrite(&pic[i], sizeof(struct i8259_pic_t), 1);
-       state_fio->FputInt32(req_chip);
-       state_fio->FputInt32(req_level);
-       state_fio->FputUint8(req_bit);
+       //for(int i = 0; i < __I8259_MAX_CHIPS; i++) state_fio->Fwrite(&pic[i], sizeof(struct i8259_pic_t), 1);
+       //state_fio->FputInt32(req_chip);
+       //state_fio->FputInt32(req_level);
+       //state_fio->FputUint8(req_bit);
 }
 
 bool I8259::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       for(int i = 0; i < __I8259_MAX_CHIPS; i++) state_fio->Fread(&pic[i], sizeof(struct i8259_pic_t), 1);
-       req_chip = state_fio->FgetInt32();
-       req_level = state_fio->FgetInt32();
-       req_bit = state_fio->FgetUint8();
+       if(!mb) return false;
+       //if(state_fio->FgetUint32() != STATE_VERSION) {
+       //      return false;
+       //}
+       //if(state_fio->FgetInt32() != this_device_id) {
+       //      return false;
+       //}
+       //for(int i = 0; i < __I8259_MAX_CHIPS; i++) state_fio->Fread(&pic[i], sizeof(struct i8259_pic_t), 1);
+       //req_chip = state_fio->FgetInt32();
+       //req_level = state_fio->FgetInt32();
+       //req_bit = state_fio->FgetUint8();
        return true;
 }
 
index cfd30df..87736d0 100644 (file)
@@ -74,6 +74,7 @@ public:
        void write_signal(int id, uint32_t data, uint32_t mask);
        uint32_t read_signal(int id);
        void event_callback(int event_id, int err);
+       void decl_state();
        void save_state(FILEIO* state_fio);
        bool load_state(FILEIO* state_fio);
        // interrupt common functions
index e3c16ee..be9d6ef 100644 (file)
@@ -3049,47 +3049,79 @@ void MC6800::stx_ex()
 
 #define STATE_VERSION  2
 
+#include "../statesub.h"
+
+void MC6800::decl_state()
+{
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("MC6800"));
+       
+       DECL_STATE_ENTRY_PAIR(pc);
+       DECL_STATE_ENTRY_UINT16(prevpc);
+       DECL_STATE_ENTRY_PAIR(sp);
+       DECL_STATE_ENTRY_PAIR(ix);
+       DECL_STATE_ENTRY_PAIR(acc_d);
+       DECL_STATE_ENTRY_PAIR(ea);
+       DECL_STATE_ENTRY_UINT8(cc);
+       DECL_STATE_ENTRY_INT32(wai_state);
+       DECL_STATE_ENTRY_INT32(int_state);
+       if(__USE_DEBUGGER) {
+               DECL_STATE_ENTRY_UINT64(total_icount);
+       }
+       DECL_STATE_ENTRY_INT32(icount);
+}
+
 void MC6800::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->FputUint32(pc.d);
-       state_fio->FputUint16(prevpc);
-       state_fio->FputUint32(sp.d);
-       state_fio->FputUint32(ix.d);
-       state_fio->FputUint32(acc_d.d);
-       state_fio->FputUint32(ea.d);
-       state_fio->FputUint8(cc);
-       state_fio->FputInt32(wai_state);
-       state_fio->FputInt32(int_state);
+//     state_fio->FputUint32(pc.d);
+//     state_fio->FputUint16(prevpc);
+//     state_fio->FputUint32(sp.d);
+//     state_fio->FputUint32(ix.d);
+//     state_fio->FputUint32(acc_d.d);
+//     state_fio->FputUint32(ea.d);
+//     state_fio->FputUint8(cc);
+//     state_fio->FputInt32(wai_state);
+//     state_fio->FputInt32(int_state);
 //#ifdef USE_DEBUGGER
-       if(__USE_DEBUGGER) state_fio->FputUint64(total_icount);
+//     if(__USE_DEBUGGER) state_fio->FputUint64(total_icount);
 //#endif
-       state_fio->FputInt32(icount);
+//     state_fio->FputInt32(icount);
 }
 
 bool MC6800::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       pc.d = state_fio->FgetUint32();
-       prevpc = state_fio->FgetUint16();
-       sp.d = state_fio->FgetUint32();
-       ix.d = state_fio->FgetUint32();
-       acc_d.d = state_fio->FgetUint32();
-       ea.d = state_fio->FgetUint32();
-       cc = state_fio->FgetUint8();
-       wai_state = state_fio->FgetInt32();
-       int_state = state_fio->FgetInt32();
+       if(!mb) return false;
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     pc.d = state_fio->FgetUint32();
+//     prevpc = state_fio->FgetUint16();
+//     sp.d = state_fio->FgetUint32();
+//     ix.d = state_fio->FgetUint32();
+//     acc_d.d = state_fio->FgetUint32();
+//     ea.d = state_fio->FgetUint32();
+//     cc = state_fio->FgetUint8();
+//     wai_state = state_fio->FgetInt32();
+//     int_state = state_fio->FgetInt32();
 //#ifdef USE_DEBUGGER
-       if(__USE_DEBUGGER) { total_icount = prev_total_icount = state_fio->FgetUint64(); }
+//     if(__USE_DEBUGGER) { total_icount = prev_total_icount = state_fio->FgetUint64(); }
 //#endif
-       icount = state_fio->FgetInt32();
+//     icount = state_fio->FgetInt32();
+       if(__USE_DEBUGGER) {
+               prev_total_icount = total_icount;
+       }
        return true;
 }
 
index 62b5afc..545e004 100644 (file)
@@ -368,6 +368,7 @@ public:
        void get_debug_regs_info(_TCHAR *buffer, size_t buffer_len);
        virtual int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
 //#endif
+       virtual void decl_state();
        virtual void save_state(FILEIO* state_fio);
        virtual bool load_state(FILEIO* state_fio);
        
index 34c8390..0572ace 100644 (file)
@@ -1245,114 +1245,177 @@ void MC6801::std_ex()
 
 #define STATE_VERSION  2
 
-void MC6801::save_state(FILEIO* state_fio)
+#include "../statesub.h"
+
+void MC6801::decl_state()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("MC6801"));
        
-       state_fio->FputUint32(pc.d);
-       state_fio->FputUint16(prevpc);
-       state_fio->FputUint32(sp.d);
-       state_fio->FputUint32(ix.d);
-       state_fio->FputUint32(acc_d.d);
-       state_fio->FputUint32(ea.d);
-       state_fio->FputUint8(cc);
-       state_fio->FputInt32(wai_state);
-       state_fio->FputInt32(int_state);
-       if(__USE_DEBUGGER) state_fio->FputUint64(total_icount);
-       state_fio->FputInt32(icount);
+       DECL_STATE_ENTRY_PAIR(pc);
+       DECL_STATE_ENTRY_UINT16(prevpc);
+       DECL_STATE_ENTRY_PAIR(sp);
+       DECL_STATE_ENTRY_PAIR(ix);
+       DECL_STATE_ENTRY_PAIR(acc_d);
+       DECL_STATE_ENTRY_PAIR(ea);
+       DECL_STATE_ENTRY_UINT8(cc);
+       DECL_STATE_ENTRY_INT32(wai_state);
+       DECL_STATE_ENTRY_INT32(int_state);
+       if(__USE_DEBUGGER) {
+               DECL_STATE_ENTRY_UINT64(total_icount);
+       }
+       DECL_STATE_ENTRY_INT32(icount);
 //#if defined(HAS_MC6801) || defined(HAS_HD6301)
        for(int i = 0; i < 4; i++) {
-               state_fio->FputUint8(port[i].wreg);
-               state_fio->FputUint8(port[i].rreg);
-               state_fio->FputUint8(port[i].ddr);
-               state_fio->FputUint8(port[i].latched_data);
-               state_fio->FputBool(port[i].latched);
-               state_fio->FputBool(port[i].first_write);
+               DECL_STATE_ENTRY_UINT8_MEMBER(port[i].wreg, i);
+               DECL_STATE_ENTRY_UINT8_MEMBER(port[i].rreg, i);
+               DECL_STATE_ENTRY_UINT8_MEMBER(port[i].ddr, i);
+               DECL_STATE_ENTRY_UINT8_MEMBER(port[i].latched_data, i);
+               DECL_STATE_ENTRY_BOOL_MEMBER(port[i].latched, i);
+               DECL_STATE_ENTRY_BOOL_MEMBER(port[i].first_write, i);
        }
-       state_fio->FputUint8(p3csr);
-       state_fio->FputBool(p3csr_is3_flag_read);
-       state_fio->FputBool(sc1_state);
-       state_fio->FputBool(sc2_state);
-       state_fio->FputUint32(counter.d);
-       state_fio->FputUint32(output_compare.d);
-       state_fio->FputUint32(timer_over.d);
-       state_fio->FputUint8(tcsr);
-       state_fio->FputUint8(pending_tcsr);
-       state_fio->FputUint16(input_capture);
-//#ifdef HAS_HD6301
-//     state_fio->FputUint16(latch09);
+       DECL_STATE_ENTRY_UINT8(p3csr);
+       DECL_STATE_ENTRY_BOOL(p3csr_is3_flag_read);
+       DECL_STATE_ENTRY_BOOL(sc1_state);
+       DECL_STATE_ENTRY_BOOL(sc2_state);
+       DECL_STATE_ENTRY_PAIR(counter);
+       DECL_STATE_ENTRY_PAIR(output_compare);
+       DECL_STATE_ENTRY_PAIR(timer_over);
+       DECL_STATE_ENTRY_UINT8(tcsr);
+       DECL_STATE_ENTRY_UINT8(pending_tcsr);
+       DECL_STATE_ENTRY_UINT16(input_capture);
+       DECL_STATE_ENTRY_UINT32(timer_next);
+       //recv_buffer->save_state((void *)state_fio);
+       DECL_STATE_ENTRY_UINT8(trcsr);
+       DECL_STATE_ENTRY_UINT8(rdr);
+       DECL_STATE_ENTRY_UINT8(tdr);
+       DECL_STATE_ENTRY_BOOL(trcsr_read_tdre);
+       DECL_STATE_ENTRY_BOOL(trcsr_read_orfe);
+       DECL_STATE_ENTRY_BOOL(trcsr_read_rdrf);
+       DECL_STATE_ENTRY_UINT8(rmcr);
+       DECL_STATE_ENTRY_INT32(sio_counter);
+       DECL_STATE_ENTRY_UINT8(ram_ctrl);
+       DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
 //#endif
-       state_fio->FputUint32(timer_next);
+       
+
+}
+
+void MC6801::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->FputUint32(pc.d);
+//     state_fio->FputUint16(prevpc);
+//     state_fio->FputUint32(sp.d);
+//     state_fio->FputUint32(ix.d);
+//     state_fio->FputUint32(acc_d.d);
+//     state_fio->FputUint32(ea.d);
+//     state_fio->FputUint8(cc);
+//     state_fio->FputInt32(wai_state);
+//     state_fio->FputInt32(int_state);
+//     if(__USE_DEBUGGER) state_fio->FputUint64(total_icount);
+//     state_fio->FputInt32(icount);
+//#if defined(HAS_MC6801) || defined(HAS_HD6301)
+//     for(int i = 0; i < 4; i++) {
+//             state_fio->FputUint8(port[i].wreg);
+//             state_fio->FputUint8(port[i].rreg);
+//             state_fio->FputUint8(port[i].ddr);
+//             state_fio->FputUint8(port[i].latched_data);
+//             state_fio->FputBool(port[i].latched);
+//             state_fio->FputBool(port[i].first_write);
+//     }
+//     state_fio->FputUint8(p3csr);
+//     state_fio->FputBool(p3csr_is3_flag_read);
+//     state_fio->FputBool(sc1_state);
+//     state_fio->FputBool(sc2_state);
+//     state_fio->FputUint32(counter.d);
+//     state_fio->FputUint32(output_compare.d);
+//     state_fio->FputUint32(timer_over.d);
+//     state_fio->FputUint8(tcsr);
+//     state_fio->FputUint8(pending_tcsr);
+//     state_fio->FputUint16(input_capture);
+//     state_fio->FputUint32(timer_next);
        recv_buffer->save_state((void *)state_fio);
-       state_fio->FputUint8(trcsr);
-       state_fio->FputUint8(rdr);
-       state_fio->FputUint8(tdr);
-       state_fio->FputBool(trcsr_read_tdre);
-       state_fio->FputBool(trcsr_read_orfe);
-       state_fio->FputBool(trcsr_read_rdrf);
-       state_fio->FputUint8(rmcr);
-       state_fio->FputInt32(sio_counter);
-       state_fio->FputUint8(ram_ctrl);
-       state_fio->Fwrite(ram, sizeof(ram), 1);
+//     state_fio->FputUint8(trcsr);
+//     state_fio->FputUint8(rdr);
+//     state_fio->FputUint8(tdr);
+//     state_fio->FputBool(trcsr_read_tdre);
+//     state_fio->FputBool(trcsr_read_orfe);
+//     state_fio->FputBool(trcsr_read_rdrf);
+//     state_fio->FputUint8(rmcr);
+//     state_fio->FputInt32(sio_counter);
+//     state_fio->FputUint8(ram_ctrl);
+//     state_fio->Fwrite(ram, sizeof(ram), 1);
 //#endif
 }
 
 bool MC6801::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       pc.d = state_fio->FgetUint32();
-       prevpc = state_fio->FgetUint16();
-       sp.d = state_fio->FgetUint32();
-       ix.d = state_fio->FgetUint32();
-       acc_d.d = state_fio->FgetUint32();
-       ea.d = state_fio->FgetUint32();
-       cc = state_fio->FgetUint8();
-       wai_state = state_fio->FgetInt32();
-       int_state = state_fio->FgetInt32();
-       if(__USE_DEBUGGER) { total_icount = prev_total_icount = state_fio->FgetUint64(); }
-       icount = state_fio->FgetInt32();
+       if(!mb) return false;
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     pc.d = state_fio->FgetUint32();
+//     prevpc = state_fio->FgetUint16();
+//     sp.d = state_fio->FgetUint32();
+//     ix.d = state_fio->FgetUint32();
+//     acc_d.d = state_fio->FgetUint32();
+//     ea.d = state_fio->FgetUint32();
+//     cc = state_fio->FgetUint8();
+//     wai_state = state_fio->FgetInt32();
+//     int_state = state_fio->FgetInt32();
+//     if(__USE_DEBUGGER) { total_icount = prev_total_icount = state_fio->FgetUint64(); }
+//     icount = state_fio->FgetInt32();
 //#if defined(HAS_MC6801) || defined(HAS_HD6301)
-       for(int i = 0; i < 4; i++) {
-               port[i].wreg = state_fio->FgetUint8();
-               port[i].rreg = state_fio->FgetUint8();
-               port[i].ddr = state_fio->FgetUint8();
-               port[i].latched_data = state_fio->FgetUint8();
-               port[i].latched = state_fio->FgetBool();
-               port[i].first_write = state_fio->FgetBool();
-       }
-       p3csr = state_fio->FgetUint8();
-       p3csr_is3_flag_read = state_fio->FgetBool();
-       sc1_state = state_fio->FgetBool();
-       sc2_state = state_fio->FgetBool();
-       counter.d = state_fio->FgetUint32();
-       output_compare.d = state_fio->FgetUint32();
-       timer_over.d = state_fio->FgetUint32();
-       tcsr = state_fio->FgetUint8();
-       pending_tcsr = state_fio->FgetUint8();
-       input_capture = state_fio->FgetUint16();
+//     for(int i = 0; i < 4; i++) {
+//             port[i].wreg = state_fio->FgetUint8();
+//             port[i].rreg = state_fio->FgetUint8();
+//             port[i].ddr = state_fio->FgetUint8();
+//             port[i].latched_data = state_fio->FgetUint8();
+//             port[i].latched = state_fio->FgetBool();
+//             port[i].first_write = state_fio->FgetBool();
+//     }
+//     p3csr = state_fio->FgetUint8();
+//     p3csr_is3_flag_read = state_fio->FgetBool();
+//     sc1_state = state_fio->FgetBool();
+//     sc2_state = state_fio->FgetBool();
+//     counter.d = state_fio->FgetUint32();
+//     output_compare.d = state_fio->FgetUint32();
+//     timer_over.d = state_fio->FgetUint32();
+//     tcsr = state_fio->FgetUint8();
+//     pending_tcsr = state_fio->FgetUint8();
+//     input_capture = state_fio->FgetUint16();
 //#ifdef HAS_HD6301
 //     latch09 = state_fio->FgetUint16();
 //#endif
-       timer_next = state_fio->FgetUint32();
+//     timer_next = state_fio->FgetUint32();
+       if(__USE_DEBUGGER) {
+               prev_total_icount = total_icount;
+       }
        if(!recv_buffer->load_state((void *)state_fio)) {
                return false;
        }
-       trcsr = state_fio->FgetUint8();
-       rdr = state_fio->FgetUint8();
-       tdr = state_fio->FgetUint8();
-       trcsr_read_tdre = state_fio->FgetBool();
-       trcsr_read_orfe = state_fio->FgetBool();
-       trcsr_read_rdrf = state_fio->FgetBool();
-       rmcr = state_fio->FgetUint8();
-       sio_counter = state_fio->FgetInt32();
-       ram_ctrl = state_fio->FgetUint8();
-       state_fio->Fread(ram, sizeof(ram), 1);
+//     trcsr = state_fio->FgetUint8();
+//     rdr = state_fio->FgetUint8();
+//     tdr = state_fio->FgetUint8();
+//     trcsr_read_tdre = state_fio->FgetBool();
+//     trcsr_read_orfe = state_fio->FgetBool();
+//     trcsr_read_rdrf = state_fio->FgetBool();
+//     rmcr = state_fio->FgetUint8();
+//     sio_counter = state_fio->FgetInt32();
+//     ram_ctrl = state_fio->FgetUint8();
+//     state_fio->Fread(ram, sizeof(ram), 1);
 //#endif
        return true;
 }
index 527f92c..77d219a 100644 (file)
@@ -151,6 +151,7 @@ public:
        void reset() override;
        int run(int clock) override;
        void write_signal(int id, uint32_t data, uint32_t mask) override;
+       void decl_state();
        void save_state(FILEIO* state_fio) override;
        bool load_state(FILEIO* state_fio) override;
 
index 356844e..a039b01 100644 (file)
@@ -24,11 +24,11 @@ void YM2203::initialize()
 {
        DEVICE::initialize();
        _HAS_YM2608 = osd->check_feature(_T("HAS_YM2608"));
-       if(_HAS_YM2608) {
-               is_ym2608 = true;
-       } else {
-               is_ym2608 = false;
-       }
+//     if(_HAS_YM2608) {
+//             is_ym2608 = true;
+//     } else {
+//             is_ym2608 = false;
+//     }
        _HAS_AY_3_8910 = osd->check_feature(_T("HAS_AY_3_8910"));
        _HAS_AY_3_8912 = osd->check_feature(_T("HAS_AY_3_8912"));
        _HAS_AY_3_8913 = osd->check_feature(_T("HAS_AY_3_8913"));
@@ -62,16 +62,16 @@ void YM2203::initialize()
 //#ifdef HAS_YM2608
 //             is_ym2608 = true;
 //#endif
-       _amask = (is_ym2608) ? 3 : 1;
+       _amask = ((is_ym2608) && (_HAS_YM2608)) ? 3 : 1;
 //#ifdef HAS_YM2608
-       if(is_ym2608) {
+       if((_HAS_YM2608) && (is_ym2608)) {
                opna = new FM::OPNA;
        } else {
 //#endif
                opn = new FM::OPN;
        }
 //#ifdef HAS_YM2608
-       if(_HAS_YM2608) {
+       if((_HAS_YM2608) && (is_ym2608)) {
                set_device_name(_T("YM2608 OPNA"));
        } else {
 //#else                
index 7c812f5..effb9c7 100644 (file)
@@ -125,6 +125,7 @@ public:
                _IS_YM2203_PORT_MODE = false;
                _YM2203_PORT_MODE = 0xff;
                _SUPPORT_YM2203_PORT_A = _SUPPORT_YM2203_PORT_B = false;
+               is_ym2608 = false;
                //if(_SUPPORT_YM2203_PORT) {
                for(int i = 0; i < 2; i++) {
                        initialize_output_signals(&port[i].outputs);