#include "../device.h"
#include "../event.h"
+#include "../harddisk.h"
#include "../hd46505.h"
#ifdef _FMR60
#include "../hd63484.h"
#include "../io.h"
#include "../mb8877.h"
#include "../msm58321.h"
+#include "../noise.h"
#include "../pcm1bit.h"
#include "../scsi_hdd.h"
#include "../scsi_host.h"
// initialize
// ----------------------------------------------------------------------------
-VM::VM(EMU* parent_emu) : emu(parent_emu)
+VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
{
/*
Machine ID & CPU ID
first_device = last_device = NULL;
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"));
+
#if defined(HAS_I286)
cpu = new I286(this, emu);
#else
cpu = new I386(this, emu);
#endif
+#if defined(HAS_I286)
+ cpu->set_device_name(_T("CPU(i286)"));
+#elif defined(HAS_I386)
+ cpu->set_device_name(_T("CPU(i386)"));
+#elif defined(HAS_I486)
+ cpu->set_device_name(_T("CPU(i486)"));
+#elif defined(HAS_PENTIUM)
+ cpu->set_device_name(_T("CPU(Pentium)"));
+#endif
crtc = new HD46505(this, emu);
#ifdef _FMR60
acrtc = new HD63484(this, emu);
#endif
+
sio = new I8251(this, emu);
pit0 = new I8253(this, emu);
+ pit0->set_device_name(_T("8253 PIT #0"));
pit1 = new I8253(this, emu);
+ pit1->set_device_name(_T("8253 PIT #1"));
pic = new I8259(this, emu);
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));
rtc = new MSM58321(this, emu);
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* scsi_hdd = new SCSI_HDD(this, emu);
- 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]);
}
dma = new UPD71071(this, emu);
-
if(FILEIO::IsFileExisting(create_local_path(_T("IPL.ROM")))) {
bios = NULL;
} else {
scsi = new SCSI(this, emu);
// serial = new SERIAL(this, emu);
timer = new TIMER(this, emu);
-
// set contexts
event->set_context_cpu(cpu, cpu_clock[config.cpu_type & 1]);
event->set_context_sound(pcm);
+ event->set_context_sound(fdc->get_context_noise_seek());
+ event->set_context_sound(fdc->get_context_noise_head_down());
+ event->set_context_sound(fdc->get_context_noise_head_up());
/* pic 0 timer
1 keyboard
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()
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
// ----------------------------------------------------------------------------
{
if(ch == 0) {
pcm->set_volume(0, decibel_l, decibel_r);
+ } else if(ch == 1) {
+ fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
+ fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
+ fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
}
}
#endif
return fdc->is_disk_protected(drv);
}
+uint32_t VM::is_floppy_disk_accessed()
+{
+ uint32_t status = fdc->read_signal(0);
+ if(bios) {
+ status |= bios->read_signal(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 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();
}
}
-#define STATE_VERSION 3
+#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;
+}