OSDN Git Service

[VM][DEVICE][WIP] Updating State functions.Still cause FTBFS.
[csp-qt/common_source_project-fm7.git] / source / src / vm / tms3631.cpp
index cda7165..e3773cc 100644 (file)
@@ -33,11 +33,14 @@ void TMS3631::reset()
 void TMS3631::write_signal(int id, uint32_t data, uint32_t mask)
 {
        if(id == SIG_TMS3631_ENVELOP1) {
+               touch_sound();
                envelop1 = (envelop1 & ~mask) | (data & mask);
        } else if(id == SIG_TMS3631_ENVELOP2) {
+               touch_sound();
                envelop2 = (envelop2 & ~mask) | (data & mask);
        } else if(id == SIG_TMS3631_DATAREG) {
                // from board14.c
+               touch_sound();
                data = (datareg & ~mask) | (data & mask);
                if(data & 0x80) {
                        if(!(datareg & 0x80)) {
@@ -53,6 +56,7 @@ void TMS3631::write_signal(int id, uint32_t data, uint32_t mask)
                }
                datareg = data;
        } else if(id == SIG_TMS3631_MASKREG) {
+               touch_sound();
                maskreg = (maskreg & ~mask) | (data & mask);
        }
 }
@@ -115,37 +119,25 @@ void TMS3631::initialize_sound(int rate, int volume)
        vol = volume / 8;
 }
 
-#define STATE_VERSION  1
+#define STATE_VERSION  2
 
-void TMS3631::save_state(FILEIO* state_fio)
+bool TMS3631::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputUint8(envelop1);
-       state_fio->FputUint8(envelop2);
-       state_fio->FputUint8(datareg);
-       state_fio->FputUint8(maskreg);
-       state_fio->Fwrite(ch, sizeof(ch), 1);
-       state_fio->FputUint8(channel);
-       state_fio->FputBool(set_key);
-}
-
-bool TMS3631::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateValue(envelop1);
+       state_fio->StateValue(envelop2);
+       state_fio->StateValue(datareg);
+       state_fio->StateValue(maskreg);
+       for(int i = 0; i < array_length(ch); i++) {
+               state_fio->StateValue(ch[i].freq);
+               state_fio->StateValue(ch[i].count);
        }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
-       }
-       envelop1 = state_fio->FgetUint8();
-       envelop2 = state_fio->FgetUint8();
-       datareg = state_fio->FgetUint8();
-       maskreg = state_fio->FgetUint8();
-       state_fio->Fread(ch, sizeof(ch), 1);
-       channel = state_fio->FgetUint8();
-       set_key = state_fio->FgetBool();
-       return true;
+       state_fio->StateValue(channel);
+       state_fio->StateValue(set_key);
+       return true;
 }
-