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 / jx / jx.cpp
index 08b599a..9667c4e 100644 (file)
@@ -348,3 +348,50 @@ void VM::update_config()
        }
 }
 
+#define STATE_VERSION  1
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}