OSDN Git Service

[BUILD] Set SOVERSION and GIT hash automatically.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmr30 / fmr30.cpp
index 13e84bc..636040f 100644 (file)
@@ -12,6 +12,7 @@
 #include "../device.h"
 #include "../event.h"
 
+#include "../harddisk.h"
 #include "../i8237.h"
 #include "../i8251.h"
 #include "../i8253.h"
@@ -47,7 +48,7 @@
 // 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;
@@ -79,16 +80,13 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        cpu->set_device_name(_T("CPU(80C86)"));
        
        scsi_host = new SCSI_HOST(this, emu);
-       for(int i = 0; i < 7; i++) {
-               if(FILEIO::IsFileExisting(create_local_path(_T("SCSI%d.DAT"), i))) {
-                       scsi_hdd[i] = new SCSI_HDD(this, emu);
-                       scsi_hdd[i]->set_device_name(_T("SCSI Hard Disk Drive #%d"), i + 1);
-                       scsi_hdd[i]->scsi_id = i;
-                       scsi_hdd[i]->set_context_interface(scsi_host);
-                       scsi_host->set_context_target(scsi_hdd[i]);
-               } else {
-                       scsi_hdd[i] = NULL;
-               }
+       for(int i = 0; i < USE_HARD_DISK; i++) {
+               scsi_hdd[i] = new SCSI_HDD(this, emu);
+               scsi_hdd[i]->set_device_name(_T("SCSI Hard Disk Drive #%d"), i + 1);
+               scsi_hdd[i]->scsi_id = i;
+               scsi_hdd[i]->set_disk_handler(0, new HARDDISK(emu));
+               scsi_hdd[i]->set_context_interface(scsi_host);
+               scsi_host->set_context_target(scsi_hdd[i]);
        }
        psg = new SN76489AN(this, emu);
        if(FILEIO::IsFileExisting(create_local_path(_T("IPL.ROM")))) {
@@ -199,12 +197,26 @@ 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();
        }
+       decl_state();
+       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(bios) {
-               for(int i = 0; i < MAX_DRIVE; i++) {
-                       bios->set_disk_handler(i, fdc->get_disk_handler(i));
+               for(int drv = 0; drv < MAX_DRIVE; drv++) {
+                       bios->set_floppy_disk_handler(drv, fdc->get_disk_handler(drv));
+               }
+               for(int drv = 0; drv < USE_HARD_DISK; drv++) {
+                       bios->set_hard_disk_handler(drv, scsi_hdd[drv]->get_disk_handler(0));
                }
        }
 }
@@ -248,6 +260,17 @@ 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()
@@ -367,20 +390,73 @@ uint32_t VM::is_floppy_disk_accessed()
        return status;
 }
 
+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
+       }
+}
+
+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
+       }
+}
+
+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 false;
+}
+
 uint32_t VM::is_hard_disk_accessed()
 {
        uint32_t status = 0;
-       for(int i = 0; i < 7; i++) {
-               if(scsi_hdd[i] != NULL && scsi_hdd[i]->read_signal(0) != 0) {
-                       status |= 1 << i;
+       for(int drv = 0; drv < USE_HARD_DISK; drv++) {
+               if(scsi_hdd[drv]->get_disk_handler(0)->accessed()) {
+                       status |= 1 << drv;
                }
        }
-       if(bios) {
-               status |= bios->read_signal(1);
-       }
        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();
@@ -393,12 +469,27 @@ void VM::update_config()
        }
 }
 
-#define STATE_VERSION  6
+#define STATE_VERSION  7
+
+#include "../../statesub.h"
+#include "../../qt/gui/csp_logger.h"
+extern CSP_Logger DLL_PREFIX_I *csp_logger;
+
+void VM::decl_state(void)
+{
+       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR30_SERIES_HEAD")), csp_logger);
+
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               device->decl_state();
+       }
+}
 
 void VM::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       
+       //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);
        }
@@ -406,9 +497,18 @@ void VM::save_state(FILEIO* state_fio)
 
 bool VM::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       //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");
                return false;
        }
+
        for(DEVICE* device = first_device; device; device = device->next_device) {
                if(!device->load_state(state_fio)) {
                        return false;