OSDN Git Service

[VM][General] Merge Upstream 2017-12-15.
[csp-qt/common_source_project-fm7.git] / source / src / vm / z80tvgame / z80tvgame.cpp
index 6ca7571..932a080 100644 (file)
@@ -214,13 +214,17 @@ void VM::update_config()
        }
 }
 
-#define STATE_VERSION  1
+#define STATE_VERSION  2
 
 void VM::save_state(FILEIO* state_fio)
 {
        state_fio->FputUint32(STATE_VERSION);
        
        for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               
+               state_fio->FputInt32(strlen(name));
+               state_fio->Fwrite(name, strlen(name), 1);
                device->save_state(state_fio);
        }
 }
@@ -231,6 +235,11 @@ bool VM::load_state(FILEIO* state_fio)
                return false;
        }
        for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               
+               if(!(state_fio->FgetInt32() == strlen(name) && state_fio->Fcompare(name, strlen(name)))) {
+                       return false;
+               }
                if(!device->load_state(state_fio)) {
                        return false;
                }