OSDN Git Service

[BUILD] Set SOVERSION and GIT hash automatically.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmr50 / fmr50.cpp
index 00235cc..c96d49d 100644 (file)
@@ -13,6 +13,7 @@
 #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"
 #include "../upd71071.h"
 
 #ifdef USE_DEBUGGER
@@ -48,7 +52,7 @@
 // initialize
 // ----------------------------------------------------------------------------
 
-VM::VM(EMU* parent_emu) : emu(parent_emu)
+VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
 {
 /*
        Machine ID & CPU ID
@@ -78,9 +82,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        };
        
 #if defined(_FMR60) && (defined(HAS_I386) || defined(HAS_I486) || defined(HAS_PENTIUM))
-       uint8 machine_id = 0xf0;        // FMR-70/80
+       uint8_t machine_id = 0xf0;      // FMR-70/80
 #else
-       uint8 machine_id = 0xf8;        // FMR-50/60
+       uint8_t machine_id = 0xf8;      // FMR-50/60
 #endif
        
        FILEIO* fio = new FILEIO();
@@ -104,27 +108,56 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        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);
-       dma = new UPD71071(this, emu);
        
-       bios = new BIOS(this, emu);
+       scsi_host = new SCSI_HOST(this, emu);
+       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 {
+               bios = new BIOS(this, emu);
+       }
        cmos = new CMOS(this, emu);
        floppy = new FLOPPY(this, emu);
        keyboard = new KEYBOARD(this, emu);
@@ -132,10 +165,12 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        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
@@ -162,7 +197,7 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        crtc->set_context_disp(memory, SIG_MEMORY_DISP, 1);
        crtc->set_context_vsync(memory, SIG_MEMORY_VSYNC, 1);
 #ifdef _FMR60
-       acrtc->set_vram_ptr((uint16*)memory->get_vram(), 0x80000);
+       acrtc->set_vram_ptr((uint16_t*)memory->get_vram(), 0x80000);
 #endif
        pit0->set_context_ch0(timer, SIG_TIMER_CH0, 1);
        pit0->set_context_ch1(timer, SIG_TIMER_CH1, 1);
@@ -176,20 +211,12 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        fdc->set_context_irq(floppy, SIG_FLOPPY_IRQ, 1);
        rtc->set_context_data(timer, SIG_TIMER_RTC, 0x0f, 0);
        rtc->set_context_busy(timer, SIG_TIMER_RTC, 0x80);
+       scsi_host->set_context_irq(scsi, SIG_SCSI_IRQ, 1);
+       scsi_host->set_context_drq(scsi, SIG_SCSI_DRQ, 1);
        dma->set_context_memory(memory);
        dma->set_context_ch0(fdc);
-//     dma->set_context_ch1(scsi);
+       dma->set_context_ch1(scsi_host);
        
-       bios->set_context_mem(memory);
-       bios->set_context_io(io);
-       bios->set_cmos_ptr(cmos->get_cmos());
-       bios->set_vram_ptr(memory->get_vram());
-       bios->set_cvram_ptr(memory->get_cvram());
-#ifdef _FMR60
-       bios->set_avram_ptr(memory->get_avram());
-#else
-       bios->set_kvram_ptr(memory->get_kvram());
-#endif
        floppy->set_context_fdc(fdc);
        floppy->set_context_pic(pic);
        keyboard->set_context_pic(pic);
@@ -197,8 +224,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        memory->set_machine_id(machine_id);
        memory->set_context_crtc(crtc);
        memory->set_chregs_ptr(crtc->get_regs());
-//     scsi->set_context_dma(dma);
-//     scsi->set_context_pic(pic);
+       scsi->set_context_dma(dma);
+       scsi->set_context_pic(pic);
+       scsi->set_context_host(scsi_host);
        timer->set_context_pcm(pcm);
        timer->set_context_pic(pic);
        timer->set_context_rtc(rtc);
@@ -207,7 +235,19 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        cpu->set_context_mem(memory);
        cpu->set_context_io(io);
        cpu->set_context_intr(pic);
-       cpu->set_context_bios(bios);
+       if(bios) {
+               bios->set_context_mem(memory);
+               bios->set_context_io(io);
+               bios->set_cmos_ptr(cmos->get_cmos());
+               bios->set_vram_ptr(memory->get_vram());
+               bios->set_cvram_ptr(memory->get_cvram());
+#ifdef _FMR60
+               bios->set_avram_ptr(memory->get_avram());
+#else
+               bios->set_kvram_ptr(memory->get_kvram());
+#endif
+               cpu->set_context_bios(bios);
+       }
 #ifdef SINGLE_MODE_DMA
        cpu->set_context_dma(dma);
 #endif
@@ -275,12 +315,29 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        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 i = 0; i < MAX_DRIVE; i++) {
-               bios->set_disk_handler(i, fdc->get_disk_handler(i));
+
+       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 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()
@@ -318,6 +375,17 @@ void VM::reset()
        for(DEVICE* device = first_device; device; device = device->next_device) {
                device->reset();
        }
+       
+#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()
@@ -348,12 +416,6 @@ void VM::draw_screen()
        memory->draw_screen();
 }
 
-int VM::access_lamp()
-{
-       uint32 status = fdc->read_signal(0) | bios->read_signal(0);
-       return (status & 0x10) ? 4 : (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
-}
-
 // ----------------------------------------------------------------------------
 // soud manager
 // ----------------------------------------------------------------------------
@@ -364,17 +426,17 @@ void VM::initialize_sound(int rate, int samples)
        event->initialize_sound(rate, samples);
        
        // init sound gen
-       pcm->init(rate, 8000);
+       pcm->initialize_sound(rate, 8000);
 }
 
-uint16* VM::create_sound(int* extra_frames)
+uint16_t* VM::create_sound(int* extra_frames)
 {
        return event->create_sound(extra_frames);
 }
 
-int VM::sound_buffer_ptr()
+int VM::get_sound_buffer_ptr()
 {
-       return event->sound_buffer_ptr();
+       return event->get_sound_buffer_ptr();
 }
 
 #ifdef USE_SOUND_VOLUME
@@ -382,6 +444,10 @@ void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
 {
        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
@@ -404,35 +470,111 @@ void VM::key_up(int code)
 // user interface
 // ----------------------------------------------------------------------------
 
-void VM::open_disk(int drv, const _TCHAR* file_path, int bank)
+void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
 {
        fdc->open_disk(drv, file_path, bank);
        floppy->change_disk(drv);
 }
 
-void VM::close_disk(int drv)
+void VM::close_floppy_disk(int drv)
 {
        fdc->close_disk(drv);
 }
 
-bool VM::disk_inserted(int drv)
+bool VM::is_floppy_disk_inserted(int drv)
+{
+       return fdc->is_disk_inserted(drv);
+}
+
+void VM::is_floppy_disk_protected(int drv, bool value)
+{
+       fdc->is_disk_protected(drv, value);
+}
+
+bool VM::is_floppy_disk_protected(int drv)
+{
+       return fdc->is_disk_protected(drv);
+}
+
+uint32_t VM::is_floppy_disk_accessed()
 {
-       return fdc->disk_inserted(drv);
+       uint32_t status = fdc->read_signal(0);
+       if(bios) {
+               status |= bios->read_signal(0);
+       }
+       return status;
 }
 
-void VM::set_disk_protected(int drv, bool value)
+void VM::open_hard_disk(int drv, const _TCHAR* file_path)
 {
-       fdc->set_disk_protected(drv, value);
+       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
+       }
 }
 
-bool VM::get_disk_protected(int drv)
+void VM::close_hard_disk(int drv)
 {
-       return fdc->get_disk_protected(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::now_skip()
+bool VM::is_hard_disk_inserted(int drv)
 {
-       return event->now_skip();
+       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();
 }
 
 void VM::update_config()
@@ -442,12 +584,52 @@ void VM::update_config()
        }
 }
 
-#define STATE_VERSION  1
+#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);
        }
@@ -455,7 +637,15 @@ void VM::save_state(FILEIO* 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) {