#include "../device.h"
#include "../event.h"
+#include "../harddisk.h"
#include "../hd46505.h"
#ifdef _FMR60
#include "../hd63484.h"
#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
pcm = new PCM1BIT(this, emu);
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]);
}
dma = new UPD71071(this, emu);
if(FILEIO::IsFileExisting(create_local_path(_T("IPL.ROM")))) {
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++) {
+ 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));
}
}
}
return status;
}
+void VM::open_hard_disk(int drv, const _TCHAR* file_path)
+{
+ if(drv < USE_HARD_DISK) {
+ scsi_hdd[drv]->open(0, file_path, 512);
+ }
+}
+
+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;
+}
+
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]->accessed(0)) {
+ status |= 1 << drv;
}
}
- if(bios) {
- status |= bios->read_signal(1);
- }
return status;
}
}
}
-#define STATE_VERSION 5
+#define STATE_VERSION 6
-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) {
- const char *name = typeid(*device).name() + 6; // skip "class "
-
- state_fio->FputInt32(strlen(name));
- state_fio->Fwrite(name, strlen(name), 1);
- 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) {
- const char *name = typeid(*device).name() + 6; // skip "class "
+ 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->FgetInt32() == strlen(name) && state_fio->Fcompare(name, 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(!device->load_state(state_fio)) {
- 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;
}
-