OSDN Git Service

[VM][General] Apply Upstream 2018-10-07.Still WIP.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmr50 / fmr50.cpp
index 28821a0..e151689 100644 (file)
@@ -43,7 +43,7 @@
 #include "cmos.h"
 #include "floppy.h"
 #include "keyboard.h"
-#include "memory.h"
+#include "./memory.h"
 #include "scsi.h"
 //#include "serial.h"
 #include "timer.h"
 // initialize
 // ----------------------------------------------------------------------------
 
-VM::VM(EMU* parent_emu) : emu(parent_emu)
+using FMR50::BIOS;
+using FMR50::CMOS;
+using FMR50::FLOPPY;
+using FMR50::KEYBOARD;
+using FMR50::MEMORY;
+using FMR50::SCSI;
+using FMR50::TIMER;
+
+VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
 {
 /*
        Machine ID & CPU ID
@@ -315,16 +323,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++) {
@@ -334,7 +343,6 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
                        bios->set_hard_disk_handler(drv, scsi_hdd[drv]->get_disk_handler(0));
                }
        }
-       decl_state();
 }
 
 VM::~VM()
@@ -372,17 +380,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 +502,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 +524,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();
@@ -583,73 +547,37 @@ void VM::update_config()
 
 #define STATE_VERSION  6
 
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
-
-void VM::decl_state(void)
-{
-#if defined(_FMR50)
-#  if defined(HAS_I286)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_50_I286_HEAD")), csp_logger);
-#  elif defined(HAS_I386)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_50_I386_HEAD")), csp_logger);
-#  elif defined(HAS_I486)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_50_I486_HEAD")), csp_logger);
-#  elif defined(HAS_PENTIUM)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_250_HEAD")), csp_logger);
-#  else
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_50_SERIES_HEAD")), csp_logger);
-#  endif       
-#elif defined(_FMR60)
-#  if defined(HAS_I286)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_60_HEAD")), csp_logger);
-#  elif defined(HAS_I386)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_70_HEAD")), csp_logger);
-#  elif defined(HAS_I486)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_80_HEAD")), csp_logger);
-#  elif defined(HAS_PENTIUM)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_280_HEAD")), csp_logger);
-#  else
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_60_SERIES_HEAD")), csp_logger);
-#  endif       
-#endif
-       
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->decl_state();
-       }
-}
-
-void VM::save_state(FILEIO* state_fio)
+bool VM::process_state(FILEIO* state_fio, bool loading)
 {
-       //state_fio->FputUint32(STATE_VERSION);
-       
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-       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) {
-       //      return false;
-       //}
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
-       }
-       if(!mb) {
-               emu->out_debug_log("INFO: HEADER DATA ERROR");
+       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;
+               }
+       }
+       // Machine specified.
        return true;
 }
-