OSDN Git Service

[BUILD] Set SOVERSION and GIT hash automatically.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fm16pi / fm16pi.cpp
index 2e0cd5c..b51963f 100644 (file)
 #include "../device.h"
 #include "../event.h"
 
+#include "../disk.h"
 #include "../i8251.h"
 #include "../i8253.h"
 #include "../i8255.h"
 #include "../i8259.h"
-#include "../i86.h"
+#include "../i286.h"
 #include "../io.h"
 #include "../mb8877.h"
 #include "../memory.h"
 #include "../msm58321.h"
+#include "../noise.h"
 #include "../not.h"
 #include "../pcm1bit.h"
 
@@ -34,7 +36,7 @@
 // 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;
@@ -45,9 +47,12 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        pit = new I8253(this, emu);
        pio = new I8255(this, emu);     // for system port
        pic = new I8259(this, emu);
-       cpu = new I86(this, emu);
+       cpu = new I286(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));
        memory = new MEMORY(this, emu);
        rtc = new MSM58321(this, emu);
        not_pit = new NOT(this, emu);
@@ -62,21 +67,15 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
 
        sio->set_device_name(_T("i8251(RS-232C)"));
        pio->set_device_name(_T("i8259(SYSTEM PORT)"));
-       
-       rtc->set_device_name(_T("MSM58321(RTC)"));
-       memory->set_device_name(_T("MEMORY"));
-
-       sub->set_device_name(_T("SUB SYSTEM"));
 #endif
        
        // set contexts
        event->set_context_cpu(cpu);
        event->set_context_sound(pcm);
-#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());
+
 /*
        IRQ 0   PIT CH.0
        IRQ 1   SIO RXRDY
@@ -236,10 +235,14 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
 */
        
        // 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();
        }
-       pcm->set_realtime_render(true);
+       decl_state();
+       //pcm->set_realtime_render(true);
 }
 
 VM::~VM()
@@ -254,6 +257,9 @@ VM::~VM()
                delete device;
                device = next_device;
        }
+       for(int i = 0; i < MAX_DRIVE; i++) {
+               fdc->set_drive_type(i, DRIVE_TYPE_2D);
+       }
 }
 
 DEVICE* VM::get_device(int id)
@@ -284,7 +290,7 @@ void VM::reset()
 
 void VM::notify_power_off()
 {
-//     emu->out_debug_log(_T("--- POWER OFF ---\n"));
+//     this->out_debug_log(_T("--- POWER OFF ---\n"));
        sub->notify_power_off();
 }
 
@@ -316,12 +322,6 @@ void VM::draw_screen()
        sub->draw_screen();
 }
 
-uint32_t VM::get_access_lamp_status()
-{
-       uint32_t status = fdc->read_signal(0);
-       return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
-}
-
 // ----------------------------------------------------------------------------
 // soud manager
 // ----------------------------------------------------------------------------
@@ -350,12 +350,11 @@ 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);
        }
-#if defined(USE_SOUND_FILES)
-       else if(ch == 1) {
-               fdc->set_volume(0, decibel_l, decibel_r);
-       }
-#endif
 }
 #endif
 
@@ -402,6 +401,11 @@ bool VM::is_floppy_disk_protected(int drv)
        return fdc->is_disk_protected(drv);
 }
 
+uint32_t VM::is_floppy_disk_accessed()
+{
+       return fdc->read_signal(0);
+}
+
 bool VM::is_frame_skippable()
 {
        return event->is_frame_skippable();
@@ -414,21 +418,45 @@ void VM::update_config()
        }
 }
 
-#define STATE_VERSION  1
+#define STATE_VERSION  3
+
+#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::FM16PI_HEAD")), csp_logger);
+       DECL_STATE_ENTRY_MULTI(void, ram, sizeof(ram));
+       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);
        }
-       state_fio->Fwrite(ram, sizeof(ram), 1);
+       //state_fio->Fwrite(ram, sizeof(ram), 1);
 }
 
 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) {
@@ -436,7 +464,7 @@ bool VM::load_state(FILEIO* state_fio)
                        return false;
                }
        }
-       state_fio->Fread(ram, sizeof(ram), 1);
+       //state_fio->Fread(ram, sizeof(ram), 1);
        return true;
 }