#include "../device.h"
#include "../event.h"
+#include "../harddisk.h"
#include "../i8237.h"
#include "../i8251.h"
#include "../i8253.h"
#include "../i8259.h"
-#include "../i86.h"
+//#if defined(HAS_I86)
+//#include "../i86.h"
+//#else
+#include "../i286.h"
+//#endif
#include "../io.h"
#include "../mb8877.h"
+#include "../noise.h"
#include "../scsi_hdd.h"
#include "../scsi_host.h"
#include "../sn76489an.h"
// 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);
sio_kb = new I8251(this, emu); // keyboard
+ sio_kb->set_device_name(_T("8251 SIO (Keyboard)"));
sio_sub = new I8251(this, emu); // sub display
+ sio_sub->set_device_name(_T("8251 SIO (Sub System)"));
sio_ch1 = new I8251(this, emu); // RS-232C ch.1
+ sio_ch1->set_device_name(_T("8251 SIO (RS-232C #1)"));
sio_ch2 = new I8251(this, emu); // RS-232C ch.2
+ sio_ch2->set_device_name(_T("8251 SIO (RS-232C #2)"));
pit = new I8253(this, emu);
pic = new I8259(this, emu);
- cpu = new I86(this, emu);
+//#if defined(HAS_I86)
+// cpu = new I86(this, emu);
+//#else
+ cpu = new I286(this, emu);
+//#endif
io = new IO(this, emu);
fdc = new MB8877(this, emu);
-#if defined(_USE_QT)
- dummy->set_device_name(_T("1st Dummy"));
- event->set_device_name(_T("EVENT"));
-
- dma->set_device_name(_T("i8237 DMAC"));
- sio_kb->set_device_name(_T("i8251 SIO(KEYBOARD)"));
- sio_sub->set_device_name(_T("i8251 SIO(SUB SYSTEM)"));
- sio_ch1->set_device_name(_T("i8251 SIO(RS-232C #1)"));
- sio_ch2->set_device_name(_T("i8251 SIO(RS-232C #2)"));
- pit->set_device_name(_T("i8253 PIT"));
- pic->set_device_name(_T("i8259 PIC"));
+ 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));
cpu->set_device_name(_T("CPU(80C86)"));
-#endif
scsi_host = new SCSI_HOST(this, emu);
-#if defined(_USE_QT)
- scsi_host->set_device_name(_T("SCSI HOST"));
-#endif
- 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);
-#if defined(_USE_QT)
- char d_name[64] = {0};
- snprintf(d_name, 64, "SCSI DISK #%d", i + 1);
- scsi_hdd->set_device_name(d_name);
-#endif
- 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 defined(_USE_QT)
- psg->set_device_name(_T("SN76489 PSG"));
-#endif
if(FILEIO::IsFileExisting(create_local_path(_T("IPL.ROM")))) {
bios = NULL;
} else {
bios = new BIOS(this, emu);
-#if defined(_USE_QT)
- bios->set_device_name(_T("PSEUDO BIOS"));
-#endif
}
cmos = new CMOS(this, emu);
floppy = new FLOPPY(this, emu);
serial = new SERIAL(this, emu);
system = new SYSTEM(this, emu);
timer = new TIMER(this, emu);
-#if defined(_USE_QT)
- cmos->set_device_name(_T("CMOS RAM"));
- floppy->set_device_name(_T("FLOPPY I/F"));
- keyboard->set_device_name(_T("KEYBOARD"));
- memory->set_device_name(_T("MEMORY"));
- rtc->set_device_name(_T("RTC"));
- scsi->set_device_name(_T("SCSI I/F"));
- serial->set_device_name(_T("SERIAL I/F"));
- system->set_device_name(_T("SYSTEM I/O"));
- timer->set_device_name(_T("TIMER I/F"));
-#endif
// set contexts
event->set_context_cpu(cpu);
event->set_context_sound(psg);
-#if defined(USE_SOUND_FILES)
- if(fdc->load_sound_data(MB8877_SND_TYPE_SEEK, _T("FDDSEEK.WAV"))) {
- event->set_context_sound(fdc);
- }
-#endif
+ 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());
dma->set_context_memory(memory);
dma->set_context_ch0(fdc);
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));
}
}
}
// 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()
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) {
psg->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);
}
-#if defined(USE_SOUND_FILES)
- else if(ch == 1) {
- fdc->set_volume(0, decibel_l, decibel_r);
- }
-#endif
}
#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) {
+#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 drv = 0; drv < USE_HARD_DISK; drv++) {
+ if(scsi_hdd[drv]->get_disk_handler(0)->accessed()) {
+ status |= 1 << drv;
+ }
+ }
+ 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();
}
}
-#define STATE_VERSION 3
+#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);
}
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;