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 / fmr50 / fmr50.cpp
index 28821a0..cf6a1d1 100644 (file)
@@ -52,7 +52,7 @@
 // initialize
 // ----------------------------------------------------------------------------
 
-VM::VM(EMU* parent_emu) : emu(parent_emu)
+VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
 {
 /*
        Machine ID & CPU ID
@@ -315,16 +315,17 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        io->set_iomap_single_rw(0xfda0, memory);        // crtc
        
        // initialize all devices
+#if defined(__GIT_REPO_VERSION)
+       strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
+#endif
        for(DEVICE* device = first_device; device; device = device->next_device) {
                device->initialize();
        }
 
        for(int drv = 0; drv < USE_HARD_DISK; drv++) {
-#ifdef OPEN_HARD_DISK_IN_RESET
-               create_local_path(hd_file_path[drv], _MAX_PATH, _T("SCSI%d.DAT"), drv);
-#else
-               open_hard_disk_tmp(drv, create_local_path(_T("SCSI%d.DAT"), drv));
-#endif
+               if(!(config.last_hard_disk_path[drv][0] != _T('\0') && FILEIO::IsFileExisting(config.last_hard_disk_path[drv]))) {
+                       create_local_path(config.last_hard_disk_path[drv], _MAX_PATH, _T("SCSI%d.DAT"), drv);
+               }
        }
        if(bios) {
                for(int drv = 0; drv < MAX_DRIVE; drv++) {
@@ -372,17 +373,6 @@ void VM::reset()
        for(DEVICE* device = first_device; device; device = device->next_device) {
                device->reset();
        }
-       
-#if defined(OPEN_HARD_DISK_IN_RESET)
-       // open/close hard disk images
-       for(int drv = 0; drv < USE_HARD_DISK; drv++) {
-               if(hd_file_path[drv][0] != _T('\0')) {
-                       open_hard_disk_tmp(drv, hd_file_path[drv]);
-               } else {
-                       close_hard_disk_tmp(drv);
-               }
-       }
-#endif
 }
 
 void VM::run()
@@ -505,33 +495,21 @@ uint32_t VM::is_floppy_disk_accessed()
 void VM::open_hard_disk(int drv, const _TCHAR* file_path)
 {
        if(drv < USE_HARD_DISK) {
-#if defined(OPEN_HARD_DISK_IN_RESET)
-               my_tcscpy_s(hd_file_path[drv], _MAX_PATH, file_path);
-#else
-               open_hard_disk_tmp(drv, file_path);
-#endif
+               scsi_hdd[drv]->open(0, file_path, 512);
        }
 }
 
 void VM::close_hard_disk(int drv)
 {
        if(drv < USE_HARD_DISK) {
-#if defined(OPEN_HARD_DISK_IN_RESET)
-               hd_file_path[drv][0] = _T('\0');
-#else
-               close_hard_disk_tmp(drv);
-#endif
+               scsi_hdd[drv]->close(0);
        }
 }
 
 bool VM::is_hard_disk_inserted(int drv)
 {
        if(drv < USE_HARD_DISK) {
-#if defined(OPEN_HARD_DISK_IN_RESET)
-               return (hd_file_path[drv][0] != _T('\0'));
-#else
-               return is_hard_disk_inserted_tmp(drv);
-#endif
+               return scsi_hdd[drv]->mounted(0);
        }
        return false;
 }
@@ -539,36 +517,15 @@ bool VM::is_hard_disk_inserted(int drv)
 uint32_t VM::is_hard_disk_accessed()
 {
        uint32_t status = 0;
+       
        for(int drv = 0; drv < USE_HARD_DISK; drv++) {
-               if(scsi_hdd[drv]->get_disk_handler(0)->accessed()) {
+               if(scsi_hdd[drv]->accessed(0)) {
                        status |= 1 << drv;
                }
        }
        return status;
 }
 
-void VM::open_hard_disk_tmp(int drv, const _TCHAR* file_path)
-{
-       if(drv < USE_HARD_DISK) {
-               scsi_hdd[drv]->get_disk_handler(0)->open(file_path, 512);
-       }
-}
-
-void VM::close_hard_disk_tmp(int drv)
-{
-       if(drv < USE_HARD_DISK) {
-               scsi_hdd[drv]->get_disk_handler(0)->close();
-       }
-}
-
-bool VM::is_hard_disk_inserted_tmp(int drv)
-{
-       if(drv < USE_HARD_DISK) {
-               return scsi_hdd[drv]->get_disk_handler(0)->mounted();
-       }
-       return false;
-}
-
 bool VM::is_frame_skippable()
 {
        return event->is_frame_skippable();
@@ -653,3 +610,24 @@ bool VM::load_state(FILEIO* state_fio)
        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;
+               }
+       }
+       return true;
+}