OSDN Git Service

[VM][WIP] Pre-process to apply new state framework.Still not buildable.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmr30 / rtc.cpp
index 0e52a96..dcc1a19 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "rtc.h"
 #include "../i8259.h"
-#include "../../fileio.h"
 
 #define EVENT_1HZ      0
 #define EVENT_32HZ     1
@@ -23,6 +22,9 @@
 #define POFMI  37
 #define POFH   38
 #define POFD   39
+#if defined(Q_OS_WIN)
+DLL_PREFIX_I struct cur_time_s cur_time;
+#endif
 
 void RTC::initialize()
 {
@@ -31,7 +33,7 @@ void RTC::initialize()
        regs[POWON] = 0x10;     // cleared
        
        FILEIO* fio = new FILEIO();
-       if(fio->Fopen(emu->bios_path(_T("RTC.BIN")), FILEIO_READ_BINARY)) {
+       if(fio->Fopen(create_local_path(_T("RTC.BIN")), FILEIO_READ_BINARY)) {
                fio->Fread(regs + 8, 32, 1);
                fio->Fclose();
        }
@@ -48,7 +50,7 @@ void RTC::initialize()
        rtcmr = rtdsr = 0;
        
        // update calendar
-       emu->get_host_time(&cur_time);
+       get_host_time(&cur_time);
        read_from_cur_time();
        
        // register event
@@ -65,14 +67,14 @@ void RTC::release()
        
        // save rtc regs image
        FILEIO* fio = new FILEIO();
-       if(fio->Fopen(emu->bios_path(_T("RTC.BIN")), FILEIO_WRITE_BINARY)) {
+       if(fio->Fopen(create_local_path(_T("RTC.BIN")), FILEIO_WRITE_BINARY)) {
                fio->Fwrite(regs + 8, 32, 1);
                fio->Fclose();
        }
        delete fio;
 }
 
-void RTC::write_io16(uint32 addr, uint32 data)
+void RTC::write_io16(uint32_t addr, uint32_t data)
 {
        switch(addr) {
        case 0:
@@ -97,7 +99,7 @@ void RTC::write_io16(uint32 addr, uint32 data)
        }
 }
 
-uint32 RTC::read_io16(uint32 addr)
+uint32_t RTC::read_io16(uint32_t addr)
 {
        switch(addr) {
        case 2:
@@ -115,7 +117,7 @@ void RTC::event_callback(int event_id, int err)
                if(cur_time.initialized) {
                        cur_time.increment();
                } else {
-                       emu->get_host_time(&cur_time);  // resync
+                       get_host_time(&cur_time);       // resync
                        cur_time.initialized = true;
                }
                read_from_cur_time();
@@ -133,7 +135,7 @@ void RTC::event_callback(int event_id, int err)
                } else if(rtadr & 0x80) {
                        // write
                        if(ch <= 6) {
-                               regs[ch] = (uint8)rtobr;
+                               regs[ch] = (uint8_t)rtobr;
                                write_to_cur_time();
                        } else if(ch == POWON) {
                                regs[ch] = (regs[ch] & 0xe0) | (rtobr & 0x1f);
@@ -147,7 +149,7 @@ void RTC::event_callback(int event_id, int err)
                                }
                                update_checksum();
                        } else if(7 <= ch && ch < 32) {
-                               regs[ch] = (uint8)rtobr;
+                               regs[ch] = (uint8_t)rtobr;
                                update_checksum();
                        }
                } else {
@@ -198,9 +200,9 @@ void RTC::update_checksum()
                sum += regs[i] & 0xf;
                sum += (regs[i] >> 4) & 0xf;
        }
-       uint8 ckh = (sum >> 6) & 0xf;
-       uint8 ckm = (sum >> 2) & 0xf;
-       uint8 ckl = (sum >> 0) & 3;
+       uint8_t ckh = (sum >> 6) & 0xf;
+       uint8_t ckm = (sum >> 2) & 0xf;
+       uint8_t ckl = (sum >> 0) & 3;
        
        regs[CKHM] = ckh | (ckm << 4);
        regs[CKL] = (regs[CKL] & 0xf0) | ckl | 0xc;
@@ -210,3 +212,92 @@ void RTC::update_intr()
 {
        d_pic->write_signal(SIG_I8259_CHIP0 | SIG_I8259_IR1, (rtcmr & rtdsr & 0xe) ? 1 : 0, 1);
 }
+
+#define STATE_VERSION  1
+
+#include "../../statesub.h"
+
+void RTC::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_CUR_TIME_T(cur_time);
+       DECL_STATE_ENTRY_INT32(register_id);
+       DECL_STATE_ENTRY_UINT16(rtcmr);
+       DECL_STATE_ENTRY_UINT16(rtdsr);
+       DECL_STATE_ENTRY_UINT16(rtadr);
+       DECL_STATE_ENTRY_UINT16(rtobr);
+       DECL_STATE_ENTRY_UINT16(rtibr);
+       DECL_STATE_ENTRY_1D_ARRAY(regs, sizeof(regs));
+
+       leave_decl_state();
+}
+
+void RTC::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);
+       
+//     cur_time.save_state((void *)state_fio);
+//     state_fio->FputInt32(register_id);
+//     state_fio->FputUint16(rtcmr);
+//     state_fio->FputUint16(rtdsr);
+//     state_fio->FputUint16(rtadr);
+//     state_fio->FputUint16(rtobr);
+//     state_fio->FputUint16(rtibr);
+//     state_fio->Fwrite(regs, sizeof(regs), 1);
+}
+
+bool RTC::load_state(FILEIO* state_fio)
+{
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
+       }
+       if(!mb) {
+               return false;
+       }
+
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     if(!cur_time.load_state((void *)state_fio)) {
+//             return false;
+//     }
+//     register_id = state_fio->FgetInt32();
+//     rtcmr = state_fio->FgetUint16();
+//     rtdsr = state_fio->FgetUint16();
+//     rtadr = state_fio->FgetUint16();
+//     rtobr = state_fio->FgetUint16();
+//     rtibr = state_fio->FgetUint16();
+//     state_fio->Fread(regs, sizeof(regs), 1);
+       return true;
+}
+
+bool RTC::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!cur_time.process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(register_id);
+       state_fio->StateUint16(rtcmr);
+       state_fio->StateUint16(rtdsr);
+       state_fio->StateUint16(rtadr);
+       state_fio->StateUint16(rtobr);
+       state_fio->StateUint16(rtibr);
+       state_fio->StateBuffer(regs, sizeof(regs), 1);
+       return true;
+}