OSDN Git Service

[VM] .
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmr30 / fmr30.cpp
index 69d6bb6..97c2fda 100644 (file)
 #include "../device.h"
 #include "../event.h"
 
+#include "../harddisk.h"
 #include "../i8237.h"
 #include "../i8251.h"
 #include "../i8253.h"
 #include "../i8259.h"
-#if defined(HAS_I86)
-#include "../i86.h"
-#else
+//#if defined(HAS_I86)
+//#include "../i86.h"
+//#else
 #include "../i286.h"
-#endif
+//#endif
 #include "../io.h"
 #include "../mb8877.h"
 #include "../noise.h"
 #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;
        dummy = new DEVICE(this, emu);  // must be 1st device
+       dummy->set_device_name(_T("1st dummy"));
        event = new EVENT(this, emu);   // must be 2nd device
        
        dma = new I8237(this, emu);
@@ -65,28 +79,26 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        sio_ch2->set_device_name(_T("8251 SIO (RS-232C #2)"));
        pit = new I8253(this, emu);
        pic = new I8259(this, emu);
-#if defined(HAS_I86)
-       cpu = new I86(this, emu);
-#else
+//#if defined(HAS_I86)
+//     cpu = new I86(this, emu);
+//#else
        cpu = new I286(this, emu);
-#endif
+//#endif
        io = new IO(this, emu);
        fdc = new MB8877(this, emu);
        fdc->set_context_noise_seek(new NOISE(this, emu));
        fdc->set_context_noise_head_down(new NOISE(this, emu));
        fdc->set_context_noise_head_up(new NOISE(this, emu));
-       dummy->set_device_name(_T("1st Dummy"));
        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* scsi_hdd = new SCSI_HDD(this, emu);
-                       scsi_hdd->set_device_name("SCSI Hard Disk Drive #%d", i + 1);
-                       scsi_hdd->scsi_id = i;
-                       scsi_hdd->set_context_interface(scsi_host);
-                       scsi_host->set_context_target(scsi_hdd);
-               }
+       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")))) {
@@ -197,12 +209,23 @@ 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++) {
+               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 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));
                }
        }
 }
@@ -276,18 +299,6 @@ void VM::draw_screen()
        memory->draw_screen();
 }
 
-uint32_t VM::get_access_lamp_status()
-{
-       uint32_t status_fdd = fdc->read_signal(0);
-       uint32_t status_hdd = scsi_host->read_signal(0);
-       if(bios) {
-               uint32_t status = bios->read_signal(0);
-               status_fdd |= status & 0x0f;
-               status_hdd |= status >> 4;
-       }
-       return (status_hdd) ? 4 : (status_fdd & (1 | 4)) ? 1 : (status_fdd & (2 | 8)) ? 2 : 0;
-}
-
 // ----------------------------------------------------------------------------
 // soud manager
 // ----------------------------------------------------------------------------
@@ -368,39 +379,93 @@ bool VM::is_floppy_disk_protected(int drv)
        return fdc->is_disk_protected(drv);
 }
 
-bool VM::is_frame_skippable()
+uint32_t VM::is_floppy_disk_accessed()
 {
-       return event->is_frame_skippable();
+       uint32_t status = fdc->read_signal(0);
+       if(bios) {
+               status |= bios->read_signal(0);
+       }
+       return status;
 }
 
-void VM::update_config()
+void VM::open_hard_disk(int drv, const _TCHAR* file_path)
 {
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->update_config();
+       if(drv < USE_HARD_DISK) {
+               scsi_hdd[drv]->open(0, file_path, 512);
        }
 }
 
-#define STATE_VERSION  5
+void VM::close_hard_disk(int drv)
+{
+       if(drv < USE_HARD_DISK) {
+               scsi_hdd[drv]->close(0);
+       }
+}
+
+bool VM::is_hard_disk_inserted(int drv)
+{
+       if(drv < USE_HARD_DISK) {
+               return scsi_hdd[drv]->mounted(0);
+       }
+       return false;
+}
 
-void VM::save_state(FILEIO* state_fio)
+uint32_t VM::is_hard_disk_accessed()
 {
-       state_fio->FputUint32(STATE_VERSION);
+       uint32_t status = 0;
        
+       for(int drv = 0; drv < USE_HARD_DISK; drv++) {
+               if(scsi_hdd[drv]->accessed(0)) {
+                       status |= 1 << drv;
+               }
+       }
+       return status;
+}
+
+bool VM::is_frame_skippable()
+{
+       return event->is_frame_skippable();
+}
+
+void VM::update_config()
+{
        for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->save_state(state_fio);
+               device->update_config();
        }
 }
 
-bool VM::load_state(FILEIO* state_fio)
+#define STATE_VERSION  7
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
 {
-       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;
 }
-