OSDN Git Service

[VM}[FM7][PC8801][X1] At least enable to build FM7,PC8801 and X1 (excepts X!Twin).
[csp-qt/common_source_project-fm7.git] / source / src / vm / fm7 / fm7.cpp
index deae8cd..adc2ca0 100644 (file)
 #include "hd6844.h"
 #endif
 #if defined(_FM77L4)
-#include "hd46505.h"
+#include "../hd46505.h"
 #endif
 
 #if defined(_FM8)
 #include "./bubblecasette.h"
 #endif
+
 #if defined(_FM8)
 #include "./fm8_mainio.h"
 #else
 #include "./jcommcard.h"
 #endif
 
-VM::VM(EMU* parent_emu): emu(parent_emu)
+#if defined(USE_BUBBLE)
+using FM7::BUBBLECASETTE;
+#endif
+using FM7::DISPLAY;
+#if defined(CAPABLE_JCOMMCARD)
+using FM7::FM7_JCOMMCARD;
+#endif
+
+#if defined(_FM8)
+using FM7::FM8_MAINIO;
+#else
+using FM7::FM7_MAINIO;
+#endif
+using FM7::FM7_MAINMEM;
+using FM7::JOYSTICK;
+using FM7::KEYBOARD;
+using FM7::KANJIROM;
+
+VM::VM(EMU* parent_emu): VM_TEMPLATE(parent_emu)
 {
        
        first_device = last_device = NULL;
@@ -130,24 +149,14 @@ VM::VM(EMU* parent_emu): emu(parent_emu)
        if((config.dipswitch & FM7_DIPSW_MIDI_ON) != 0) uart[2] = new I8251(this, emu);
 
                
+
 #if defined(_FM77AV_VARIANTS)
        alu = new MB61VH010(this, emu);
        keyboard_beep = new BEEP(this, emu);
 #endif 
-       keyboard = new KEYBOARD(this, emu);
-       display = new DISPLAY(this, emu);
-#if defined(_FM8)
-       mainio  = new FM8_MAINIO(this, emu);
-#else
-       mainio  = new FM7_MAINIO(this, emu);
-#endif
-       mainmem = new FM7_MAINMEM(this, emu);
 
        // basic devices
        // I/Os
-#if defined(HAS_DMA)
-       dmac = new HD6844(this, emu);
-#endif   
 #if defined(_FM8)
 #  if defined(USE_AY_3_8910_AS_PSG)
        psg = new AY_3_891X(this, emu);
@@ -166,6 +175,10 @@ VM::VM(EMU* parent_emu): emu(parent_emu)
 #  endif
 # endif        
 #endif
+
+#if defined(HAS_DMA)
+       dmac = new HD6844(this, emu);
+#endif   
 #if defined(_FM8)
        for(int i = 0; i < 2; i++) bubble_casette[i] = new BUBBLECASETTE(this, emu);
 #endif
@@ -228,6 +241,18 @@ VM::VM(EMU* parent_emu): emu(parent_emu)
        kanjiclass2 = new KANJIROM(this, emu, true);
 #endif
 
+
+       keyboard = new KEYBOARD(this, emu);
+       //display = new DISPLAY(this, emu);
+#if defined(_FM8)
+       mainio  = new FM8_MAINIO(this, emu);
+#else
+       mainio  = new FM7_MAINIO(this, emu);
+#endif
+       mainmem = new FM7_MAINMEM(this, emu);
+       display = new DISPLAY(this, emu);
+
+
 # if defined(_FM77AV20) || defined(_FM77AV40) || defined(_FM77AV20EX) || defined(_FM77AV40EX) || defined(_FM77AV40SX)
        g_rs232c_dtr = new AND(this, emu);
        g_rs232c_dtr->set_mask(SIG_AND_BIT_0);
@@ -333,7 +358,6 @@ VM::VM(EMU* parent_emu): emu(parent_emu)
        g_substat_mainhalt->set_device_name(_T("SUBSYSTEM HALT STATUS(AND)"));
 #endif 
        this->connect_bus();
-       decl_state();
 }
 
 VM::~VM()
@@ -616,7 +640,7 @@ void VM::connect_bus(void)
        opn[2]->set_context_irq(mainio, FM7_MAINIO_THG_IRQ, 0xffffffff);
        mainio->set_context_opn(opn[2], 2);
 #endif   
-       subcpu->set_context_bus_clr(display, SIG_FM7_SUB_USE_CLR, 0x0000000f);
+       //subcpu->set_context_bus_clr(display, SIG_FM7_SUB_USE_CLR, 0x0000000f);
    
        event->register_frame_event(joystick);
 #if defined(HAS_DMA)
@@ -652,6 +676,14 @@ void VM::connect_bus(void)
        }
 # endif
 #endif
+
+#if defined(__GIT_REPO_VERSION)
+       strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
+#endif
+
+#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();
        }
@@ -724,6 +756,7 @@ void VM::reset()
                opn[i]->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
        }
 #endif
+       //display->reset(); // 20180618 K.O for RELICS
 }
 
 void VM::special_reset()
@@ -821,7 +854,8 @@ void VM::initialize_sound(int rate, int samples)
        keyboard_beep->initialize_sound(rate, 2400.0, 512);
 # endif
 #endif 
-       pcm1bit->initialize_sound(rate, 8000);
+       pcm1bit->initialize_sound(rate, 6000);
+
        //drec->initialize_sound(rate, 0);
 }
 
@@ -952,6 +986,7 @@ void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
                fdc->open_disk(drv, file_path, bank);
        }
 #endif
+       //display->reset(); // 20180618 K.O for RELICS
 }
 
 void VM::close_floppy_disk(int drv)
@@ -1215,74 +1250,51 @@ void VM::set_vm_frame_rate(double fps)
    if(event != NULL) event->set_frames_per_sec(fps);
 }
 
-#define STATE_VERSION  10
-#include "../../statesub.h"
-
-void VM::decl_state(void)
-{
-#if defined(_FM8)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM8_HEAD")));
-#elif defined(_FM7) || defined(_FMNEW7)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM7_HEAD")));
-#elif defined(_FM77) || defined(_FM77L2)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77_HEAD")));
-#elif defined(_FM77L4)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77L4_HEAD")));
-#elif defined(_FM77AV)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV_HEAD")));
-#elif defined(_FM77AV20)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV20_HEAD")));
-#elif defined(_FM77AV40)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV40_HEAD")));
-#elif defined(_FM77AV20EX)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV20EX_HEAD")));
-#elif defined(_FM77AV40EX)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV40EX_HEAD")));
-#elif defined(_FM77AV40SX)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV40SX_HEAD")));
-#else
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM7_SERIES_HEAD")));
-#endif
-       DECL_STATE_ENTRY_BOOL(connect_320kfdc);
-       DECL_STATE_ENTRY_BOOL(connect_1Mfdc);
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->decl_state();
-       }
-}
-
-void VM::save_state(FILEIO* state_fio)
-{
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               emu->out_debug_log("SAVE State: DEVID=%d", device->this_device_id);
-               device->save_state(state_fio);
-       }
-}
+#define STATE_VERSION  12
 
-bool VM::load_state(FILEIO* state_fio)
+bool VM::process_state(FILEIO* state_fio, bool loading)
 {
-       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)) {
-                       printf("Load Error: DEVID=%d\n", device->this_device_id);
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+               // const char *name = typeid(*device).name();
+               //       But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+               const char *name = device->get_device_name();
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       if(loading) {
+                               printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+                       }
                        return false;
                }
-       }
-       update_config();
-       mainio->restore_opn();
-       
-       return true;
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       if(loading) {
+                               printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+                       }
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       if(loading) {
+                               printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+                       }
+                       return false;
+               }
+       }
+       // Machine specified.
+       state_fio->StateValue(connect_320kfdc);
+       state_fio->StateValue(connect_1Mfdc);
+       if(loading) {
+               update_config();
+       }
+       //mainio->restore_opn();
+       return true;
 }
 
+
+
 #ifdef USE_DIG_RESOLUTION
 void VM::get_screen_resolution(int *w, int *h)
 {