#include "../device.h"
#include "../event.h"
+#include "../harddisk.h"
#include "../hd46505.h"
#ifdef _FMR60
#include "../hd63484.h"
// initialize
// ----------------------------------------------------------------------------
-VM::VM(EMU* parent_emu) : emu(parent_emu)
+VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
{
/*
Machine ID & CPU ID
dummy = new DEVICE(this, emu); // must be 1st device
event = new EVENT(this, emu); // must be 2nd device
dummy->set_device_name(_T("1st Dummy"));
- event->set_device_name(_T("EVENT"));
#if defined(HAS_I286)
cpu = new I286(this, emu);
fdc->set_context_noise_head_up(new NOISE(this, emu));
rtc = new MSM58321(this, emu);
pcm = new PCM1BIT(this, emu);
- pit0->set_device_name(_T("i8253 PIT #0"));
- pit1->set_device_name(_T("i8253 PIT #1"));
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("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));
}
}
+ decl_state();
}
VM::~VM()
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 4
+#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)
{
- 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);
}
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) {
return true;
}
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+ 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 "
+ int len = strlen(name);
+
+ if(!state_fio->StateCheckInt32(len)) {
+ return false;
+ }
+ if(!state_fio->StateCheckBuffer(name, len, 1)) {
+ return false;
+ }
+ if(!device->process_state(state_fio, loading)) {
+ return false;
+ }
+ }
+ return true;
+}