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 eeeccaf..adc2ca0 100644 (file)
 #if defined(HAS_DMA)
 #include "hd6844.h"
 #endif
+#if defined(_FM77L4)
+#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;
@@ -76,6 +99,7 @@ VM::VM(EMU* parent_emu): emu(parent_emu)
        dummy = new DEVICE(this, emu);  // must be 1st device
        event = new EVENT(this, emu);   // must be 2nd device
 
+       //dummycpu = new DEVICE(this, emu);
        maincpu = new MC6809(this, emu);
        subcpu = new MC6809(this, emu);
        g_substat_display = new AND(this, emu);
@@ -125,11 +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 
+
        // 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);
@@ -148,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
@@ -193,18 +224,9 @@ VM::VM(EMU* parent_emu): emu(parent_emu)
        
        joystick  = new JOYSTICK(this, emu);
        printer = new PRNFILE(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);
+#if defined(_FM77L4)
+       l4crtc = new HD46505(this, emu);;
 #endif
-       mainmem = new FM7_MAINMEM(this, emu);
 
 #if defined(_FM8) || defined(_FM7) || defined(_FMNEW7)
        if((config.dipswitch & FM7_DIPSW_CONNECT_KANJIROM) != 0) {
@@ -219,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);
@@ -310,6 +344,9 @@ VM::VM(EMU* parent_emu): emu(parent_emu)
 # if defined(_FM77AV20) || defined(_FM77AV40) || defined(_FM77AV20EX) || defined(_FM77AV40EX) || defined(_FM77AV40SX)
        g_rs232c_dtr->set_device_name(_T("RS232C DTR(AND)"));
 #endif
+#if defined(_FM77L4)
+       l4crtc->set_device_name(_T("CRTC OF 400LINES BOARD"));
+#endif
 #ifdef WITH_Z80
        if(g_intr != NULL) g_intr->set_device_name(_T("Z80 INTR(OR)"));
        if(g_mainstat != NULL) g_mainstat->set_device_name(_T("Z80 HALT/RUN(AND)"));
@@ -321,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();
-       
 }
 
 VM::~VM()
@@ -368,23 +404,11 @@ void VM::connect_bus(void)
         *  KEYBOARD : R/W
         *
         */
-       //event->set_frames_per_sec(FRAMES_PER_SEC);
+       event->set_frames_per_sec(FRAMES_PER_SEC);
        event->set_lines_per_frame(LINES_PER_FRAME);
-#if defined(_FM8)
-       mainclock = MAINCLOCK_SLOW;
-       subclock = SUBCLOCK_SLOW;
-#else
-       if(config.cpu_type == 0) {
-               // 2MHz
-               subclock = SUBCLOCK_NORMAL;
-               mainclock = MAINCLOCK_NORMAL;
-       } else {
-               // 1.2MHz
-               mainclock = MAINCLOCK_SLOW;
-               subclock = SUBCLOCK_SLOW;
-       }
-       //if((config.dipswitch & FM7_DIPSW_CYCLESTEAL) != 0) subclock = subclock / 3;
-#endif
+       mainclock = CPU_CLOCKS; // Hack
+       subclock = SUBCLOCK_NORMAL;
+
        event->set_context_cpu(maincpu, mainclock);
        event->set_context_cpu(subcpu,  subclock);      
    
@@ -544,7 +568,10 @@ void VM::connect_bus(void)
        display->set_context_mainio(mainio);
        display->set_context_subcpu(subcpu);
        display->set_context_keyboard(keyboard);
-
+#if defined(_FM77L4)
+       display->set_context_l4crtc(l4crtc);
+#endif
+       
        mainio->set_context_clock_status(mainmem, FM7_MAINIO_CLOCKMODE, 0xffffffff);
        mainio->set_context_clock_status(display, SIG_DISPLAY_CLOCK, 0xffffffff);
 
@@ -613,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)
@@ -625,8 +652,10 @@ void VM::connect_bus(void)
 #endif
        
        // MEMORIES must set before initialize().
+       //dummycpu->set_context_mem(dummy);
        maincpu->set_context_mem(mainmem);
        subcpu->set_context_mem(display);
+       //dummycpu->write_signal(SIG_CPU_BUSREQ, 1, 1);
 #ifdef WITH_Z80
        if(z80cpu != NULL) z80cpu->set_context_mem(mainmem);
 #endif
@@ -647,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();
        }
@@ -719,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()
@@ -816,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, 2000);
+       pcm1bit->initialize_sound(rate, 6000);
+
        //drec->initialize_sound(rate, 0);
 }
 
@@ -919,7 +958,7 @@ bool VM::get_kana_locked()
 }
 
 // Get INS status.Important with FM-7 series (^_^;
-uint32_t VM::get_extra_leds()
+uint32_t VM::get_led_status()
 {
        return keyboard->read_signal(SIG_FM7KEY_LED_STATUS);
 }
@@ -947,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)
@@ -1168,7 +1208,7 @@ void VM::set_cpu_clock(DEVICE *cpu, uint32_t clocks) {
        event->set_secondary_cpu_clock(cpu, clocks);
 }
 
-#if defined(USE_BUBBLE1)
+#if defined(USE_BUBBLE)
 void VM::open_bubble_casette(int drv, const _TCHAR *path, int bank)
 {
        if((drv >= 2) || (drv < 0)) return;
@@ -1205,69 +1245,66 @@ void VM::is_bubble_casette_protected(int drv, bool flag)
 }
 #endif
 
-
-#define STATE_VERSION  8
-void VM::save_state(FILEIO* state_fio)
+void VM::set_vm_frame_rate(double fps)
 {
-       state_fio->FputUint32_BE(STATE_VERSION);
-       state_fio->FputBool(connect_320kfdc);
-       state_fio->FputBool(connect_1Mfdc);
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               const char *name = typeid(*device).name() + 6; // skip "class "
-               int _len = strlen(name);
-               if(_len <= 0) _len = 1;
-               if(_len >= 128) _len = 128;
-               state_fio->FputInt32(_len);
-               state_fio->Fwrite(name, _len, 1);
-               //printf("SAVE State: DEVID=%d NAME=%s\n", device->this_device_id, name);
-               device->save_state(state_fio);
-       }
+   if(event != NULL) event->set_frames_per_sec(fps);
 }
 
-bool VM::load_state(FILEIO* state_fio)
+#define STATE_VERSION  12
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
 {
-       uint32_t version = state_fio->FgetUint32_BE();
-       if(version != STATE_VERSION) {
-               return false;
-       }
-       connect_320kfdc = state_fio->FgetBool();
-       connect_1Mfdc = state_fio->FgetBool();
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               const char *name = typeid(*device).name() + 6; // skip "class "
-               char nr_data[130];
-               int _len;
-               bool b_stat = false;
-               _len = state_fio->FgetInt32();
-               if(_len > 0) {
-                       if(_len >= 128) _len = 128;
-                       memset(nr_data, 0x00, sizeof(nr_data));
-                       state_fio->Fread(nr_data, _len, 1);
-                       int stat = strncmp(name, nr_data, _len);
-                       if(stat == 0) b_stat = true;
-               } 
-               if(!b_stat) {
-                       //printf("Load Error: DEVID=%d NAME=%s\n", device->this_device_id, name);
-                       return false;
-               }
-               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;
                }
-       }
-       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)
 {
        switch(display->get_screen_mode()) {
        case DISPLAY_MODE_8_200L:
-       case DISPLAY_MODE_8_200L_TEXT:
                *w = 640;
                *h = 200;
                break;
        case DISPLAY_MODE_8_400L:
-       case DISPLAY_MODE_8_400L_TEXT:
+       case DISPLAY_MODE_1_400L:
                *w = 640;
                *h = 400;
                break;