OSDN Git Service

[VM] Apply VM_TEMPLATE to all VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / pc100 / pc100.cpp
index 1e2fa0d..ed4352f 100644 (file)
@@ -22,6 +22,7 @@
 #include "../io.h"
 #include "../memory.h"
 #include "../msm58321.h"
+#include "../noise.h"
 #include "../pcm1bit.h"
 #include "../upd765a.h"
 
@@ -37,7 +38,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;
@@ -48,7 +49,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        beep = new BEEP(this, emu);
        sio = new I8251(this, emu);
        pio0 = new I8255(this, emu);
+       pio0->set_device_name(_T("8255 PIO (RTC)"));
        pio1 = new I8255(this, emu);
+       pio1->set_device_name(_T("8255 PIO (CRTC)"));
        pic = new I8259(this, emu);
        cpu = new I286(this, emu);
        io = new IO(this, emu);
@@ -56,6 +59,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        rtc = new MSM58321(this, emu);
        pcm = new PCM1BIT(this, emu);
        fdc = new UPD765A(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));
        
        crtc = new CRTC(this, emu);
        ioctrl = new IOCTRL(this, emu);
@@ -65,6 +71,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        event->set_context_cpu(cpu);
        event->set_context_sound(beep);
        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());
        
        and_drq->set_context_out(cpu, SIG_CPU_NMI, 1);
        and_drq->set_mask(SIG_AND_BIT_0 | SIG_AND_BIT_1);
@@ -145,9 +154,7 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        for(DEVICE* device = first_device; device; device = device->next_device) {
                device->initialize();
        }
-       for(int i = 0; i < 4; i++) {
-               fdc->set_drive_type(i, DRIVE_TYPE_2D);
-       }
+       decl_state();
 }
 
 VM::~VM()
@@ -181,6 +188,13 @@ void VM::reset()
        for(DEVICE* device = first_device; device; device = device->next_device) {
                device->reset();
        }
+       for(int i = 0; i < 4; i++) {
+               if(config.drive_type) {
+                       fdc->set_drive_type(i, DRIVE_TYPE_2DD);
+               } else {
+                       fdc->set_drive_type(i, DRIVE_TYPE_2D);
+               }
+       }
 }
 
 void VM::run()
@@ -211,12 +225,6 @@ void VM::draw_screen()
        crtc->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
 // ----------------------------------------------------------------------------
@@ -248,6 +256,10 @@ void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
                beep->set_volume(0, decibel_l, decibel_r);
        } else if(ch == 1) {
                pcm->set_volume(0, decibel_l, decibel_r);
+       } else if(ch == 2) {
+               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
@@ -266,6 +278,16 @@ void VM::key_up(int code)
        ioctrl->key_up(code);
 }
 
+bool VM::get_caps_locked()
+{
+       return ioctrl->get_caps_locked();
+}
+
+bool VM::get_kana_locked()
+{
+       return ioctrl->get_kana_locked();
+}
+
 // ----------------------------------------------------------------------------
 // user interface
 // ----------------------------------------------------------------------------
@@ -295,6 +317,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();
@@ -307,21 +334,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::PC_100_HEAD")), csp_logger);
+       DECL_STATE_ENTRY_1D_ARRAY(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) {