OSDN Git Service

[VM] .
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmr30 / fmr30.cpp
index cef1fbd..97c2fda 100644 (file)
 #include "cmos.h"
 #include "floppy.h"
 #include "keyboard.h"
-#include "memory.h"
+#include "./memory.h"
 #include "rtc.h"
 #include "scsi.h"
 #include "serial.h"
 #include "system.h"
 #include "timer.h"
 
+//using FMR50::BIOS;
+using FMR30::CMOS;
+using FMR30::FLOPPY;
+using FMR30::KEYBOARD;
+using FMR30::MEMORY;
+using FMR30::RTC;
+using FMR30::SCSI;
+using FMR30::SERIAL;
+using FMR30::SYSTEM;
+using FMR30::TIMER;
+
+
 // ----------------------------------------------------------------------------
 // initialize
 // ----------------------------------------------------------------------------
 
-VM::VM(EMU* parent_emu) : emu(parent_emu)
+VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
 {
        // create devices
        first_device = last_device = NULL;
@@ -197,15 +209,16 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        io->set_iomap_single_rw(0xff00, system);
        
        // 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++) {
@@ -256,17 +269,6 @@ void VM::reset()
        // set devices
        sio_kb->write_signal(SIG_I8251_DSR, 1, 1);
        sio_sub->write_signal(SIG_I8251_DSR, 0, 0);
-       
-#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()
@@ -389,33 +391,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;
 }
@@ -423,36 +413,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();
@@ -467,25 +436,36 @@ void VM::update_config()
 
 #define STATE_VERSION  7
 
-void VM::save_state(FILEIO* state_fio)
+bool VM::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->save_state(state_fio);
-       }
-}
-
-bool VM::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               if(!device->load_state(state_fio)) {
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+               // const char *name = typeid(*device).name();
+               //       But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+               const char *name = device->get_device_name();
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       if(loading) {
+                               printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+                       }
                        return false;
                }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       if(loading) {
+                               printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+                       }
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       if(loading) {
+                               printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+                       }
+                       return false;
+               }
        }
        return true;
 }
-