OSDN Git Service

[VM][WIP] Pre-process to apply new state framework.Still not buildable.
[csp-qt/common_source_project-fm7.git] / source / src / vm / jx / jx.cpp
index 66f1b25..9667c4e 100644 (file)
 #include "../i8253.h"
 #include "../i8255.h"
 #include "../i8259.h"
-#include "../i86.h"
+//#include "../i286.h"
+#include "./i286.h"
 #include "../io.h"
 #include "../memory.h"
+#include "../noise.h"
 #include "../pcm1bit.h"
 #include "../sn76489an.h"
 #include "../upd765a.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
        event = new EVENT(this, emu);   // must be 2nd device
+       dummy->set_device_name(_T("1st Dummy"));
        
        crtc = new HD46505(this, emu);
        sio = new I8251(this, emu);
        pit = new I8253(this, emu);
        pio = new I8255(this, emu);
        pic = new I8259(this, emu);
-       cpu = new I86(this, emu);       // 8088
+       cpu = new I286(this, emu);      // 8088
        io = new IO(this, emu);
        mem = new MEMORY(this, emu);
        pcm = new PCM1BIT(this, emu);
        psg = new SN76489AN(this, emu); // SN76496N
        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));
        
        display = new DISPLAY(this, emu);
        floppy = new FLOPPY(this, emu);
        keyboard = new KEYBOARD(this, emu);
        speaker = new SPEAKER(this, emu);
-       
        /* IRQ  0 Timer Clock Interrupt
                1 I/O Channel (Reserved)
                2 I/O Channel
@@ -75,7 +80,10 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        // set contexts
        event->set_context_cpu(cpu);
        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());
+
        // cpu bus
        cpu->set_context_mem(mem);
        cpu->set_context_io(io);
@@ -164,6 +172,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        io->set_iomap_range_rw(0x3d8, 0x3df, display);
        
        // 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();
        }
@@ -240,12 +251,6 @@ void VM::draw_screen()
        display->draw_screen();
 }
 
-int VM::get_access_lamp_status()
-{
-       uint32 status = fdc->read_signal(0);
-       return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
-}
-
 // ----------------------------------------------------------------------------
 // soud manager
 // ----------------------------------------------------------------------------
@@ -260,7 +265,7 @@ void VM::initialize_sound(int rate, int samples)
        psg->initialize_sound(rate, 3579545, 8000);
 }
 
-uint16* VM::create_sound(int* extra_frames)
+uint16_t* VM::create_sound(int* extra_frames)
 {
        return event->create_sound(extra_frames);
 }
@@ -275,6 +280,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
@@ -322,6 +331,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();
@@ -334,3 +348,50 @@ void VM::update_config()
        }
 }
 
+#define STATE_VERSION  1
+
+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;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       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;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}