OSDN Git Service

[VM][FM7][IO][DISPLAY] Try to push out hand-shake lines via SUB-MAIN to event_vline();
authorK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 13 Apr 2015 20:48:29 +0000 (05:48 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 13 Apr 2015 20:48:29 +0000 (05:48 +0900)
source/src/vm/fm7/display.cpp
source/src/vm/fm7/fm7.cpp
source/src/vm/fm7/fm7_display.h
source/src/vm/fm7/fm7_mainio.cpp
source/src/vm/fm7/fm7_mainio.h
source/src/vm/mc6809.cpp
source/src/vm/mc6809.h

index 60b1a2a..32f172a 100644 (file)
@@ -83,6 +83,7 @@ void DISPLAY::reset()
        hblank = true;
        halt_flag = false;
        cancel_request = false;
+       cancel_bak = false;
        firq_backup = false;
        irq_backup = false;
        displine = 0;
@@ -118,6 +119,9 @@ void DISPLAY::reset()
        register_event(this, EVENT_FM7SUB_VSTART, 10.0, false, &vstart_event_id);   
        register_event(this, EVENT_FM7SUB_DISPLAY_NMI, 20000.0, true, &nmi_event_id); // NEXT CYCLE_
        sub_busy = true;
+       sub_busy_bak = !sub_busy;
+       do_attention = false;
+       mainio->write_signal(FM7_MAINIO_SUB_BUSY, 0xff, 0xff);
 //     subcpu->reset();
 }
 
@@ -541,8 +545,8 @@ void DISPLAY::reset_crtflag(void)
 //SUB:D402:R
 uint8 DISPLAY::acknowledge_irq(void)
 {
-       this->do_irq(false);
        cancel_request = false;
+       //do_irq(false);
        return 0xff;
 }
 
@@ -557,8 +561,9 @@ uint8 DISPLAY::beep(void)
 // SUB:D404 : R 
 uint8 DISPLAY::attention_irq(void)
 {
-       mainio->write_signal(FM7_MAINIO_SUB_ATTENTION, 0x01, 0x01);
+       do_attention = true;
        //printf("DISPLAY: ATTENTION TO MAIN\n");
+       //mainio->write_signal(FM7_MAINIO_SUB_ATTENTION, 0x01, 0x01);
        return 0xff;
 }
 
@@ -593,6 +598,7 @@ void DISPLAY::reset_vramaccess(void)
 uint8 DISPLAY::reset_subbusy(void)
 {
        sub_busy = false;
+//     mainio->write_signal(FM7_MAINIO_SUB_BUSY, 0, 0xff);
        return 0xff;
 }
 
@@ -600,6 +606,7 @@ uint8 DISPLAY::reset_subbusy(void)
 void DISPLAY::set_subbusy(void)
 {
        sub_busy = true;
+//     mainio->write_signal(FM7_MAINIO_SUB_BUSY, 0xff, 0xff);
 }
 
 
@@ -1033,6 +1040,16 @@ void DISPLAY::event_frame()
 
 void DISPLAY::event_vline(int v, int clock)
 {
+       if(sub_busy_bak != sub_busy) {
+                mainio->write_signal(FM7_MAINIO_SUB_BUSY, sub_busy ? 0xff : 0x00, 0xff);
+       }
+       sub_busy_bak = sub_busy;
+       if(cancel_request != cancel_bak) {   
+               do_irq(cancel_request);
+       }
+       cancel_bak = cancel_request;   
+       if(do_attention) mainio->write_signal(FM7_MAINIO_SUB_ATTENTION, 0x01, 0x01);
+       do_attention = false;
 }
 
 uint32 DISPLAY::read_signal(int id)
@@ -1097,13 +1114,14 @@ void DISPLAY::write_signal(int id, uint32 data, uint32 mask)
                case SIG_FM7_SUB_HALT:
                        if(flag) {
                                sub_busy = true;
+                               //mainio->write_signal(FM7_MAINIO_SUB_BUSY, 0xff, 0xff);
                        }
-                       if(cancel_request && flag) {
-                               restart_subsystem();
-                               halt_flag = false;
-                               printf("SUB: HALT : CANCEL\n");
-                               return;
-                       }
+                       //if(cancel_request && flag) {
+                       //      restart_subsystem();
+                       //      halt_flag = false;
+                       //      printf("SUB: HALT : CANCEL\n");
+                       //      return;
+                       //}
                        halt_flag = flag;
                        //printf("SUB: HALT : DID STAT=%d\n", flag);   
                        break;
@@ -1139,7 +1157,7 @@ void DISPLAY::write_signal(int id, uint32 data, uint32 mask)
                        //printf("MAIN: CANCEL REQUEST TO SUB\n");
                        if(flag) {
                                cancel_request = true;
-                               do_irq(true);
+                               //do_irq(true);
                        }
                        break;
                case SIG_DISPLAY_CLOCK:
@@ -2074,6 +2092,8 @@ void DISPLAY::initialize()
        tmp_offset_point.d = 0;
        offset_point = 0;
        halt_flag = false;
+       sub_busy_bak = false;
+       do_attention = false;
 }
 
 void DISPLAY::release()
index 94546ab..902a833 100644 (file)
@@ -178,6 +178,8 @@ void VM::connect_bus(void)
        event->set_context_sound(opn[1]);
        event->set_context_sound(opn[2]);
        event->set_context_sound(drec);
+       event->register_vline_event(display);
+       event->register_vline_event(mainio);
    
        mainio->set_context_maincpu(maincpu);
        mainio->set_context_subcpu(subcpu);
index 9217571..2a07235 100644 (file)
@@ -86,6 +86,8 @@ class DISPLAY: public DEVICE
 
  private:
        bool sub_busy;
+       bool sub_busy_bak;
+       bool do_attention; 
        uint32  disp_mode;
        bool vblank;
        bool vsync;
@@ -99,6 +101,7 @@ class DISPLAY: public DEVICE
        bool subcpu_resetreq;
        bool power_on_reset;
        bool cancel_request;
+       bool cancel_bak;
 
        DEVICE *ins_led;
        DEVICE *kana_led;
index 9c72067..03209a3 100644 (file)
@@ -16,7 +16,7 @@
 #include "../datarec.h"
 
 // TEST
-//#include <SDL2/SDL.h>
+#include <SDL2/SDL.h>
 
 void FM7_MAINIO::initialize()
 {
@@ -54,6 +54,7 @@ void FM7_MAINIO::initialize()
                        break;
        }
        this->write_signal(FM7_MAINIO_CLOCKMODE, clock_fast ? 1 : 0, 1);
+       sub_busy = false;
 }
 
 void FM7_MAINIO::reset()
@@ -85,6 +86,8 @@ void FM7_MAINIO::reset()
 #if defined(_FM77AV_VARIANTS)
        mode320 = false;
        sub_monitor_type = 0x00;
+       sub_monitor_bak = sub_monitor_type;
+       display->write_signal(SIG_FM7_SUB_BANK, sub_monitor_type, 0x07);
 #endif
        
 #ifdef HAS_MMR
@@ -113,16 +116,20 @@ void FM7_MAINIO::reset()
        // FD04
        //firq_break_key = false; // bit1, ON = '0'.
        firq_sub_attention = false; // bit0, ON = '0'.
+       firq_sub_attention_bak = false; // bit0, ON = '0'.
        // FD05
        extdet_neg = false;
        sub_cancel = false; // bit6 : '1' Cancel req.
-
+       sub_halt = false; // bit6 : '1' Cancel req.
+       sub_cancel_bak = !sub_cancel; // bit6 : '1' Cancel req.
+       sub_halt_bak = !sub_halt; // bit6 : '1' Cancel req.
        nmi_count = 0;
        reset_fdc();
    
        register_event(this, EVENT_TIMERIRQ_ON, 10000.0 / 4.9152, true, &event_timerirq); // TIMER IRQ
        mainmem->reset();
        memset(io_w_latch, 0x00, 0x100);
+       sub_busy = (read_signal(SIG_DISPLAY_BUSY) == 0) ? false : true;  
        //maincpu->reset();
 }
 
@@ -230,7 +237,7 @@ void FM7_MAINIO::set_irq_timer(bool flag)
 {
        uint8 backup = irqstat_reg0;
        if(flag && !(irqmask_timer)) {
-               irqstat_reg0 &= ~0x04;
+               irqstat_reg0 &= 0xfb; //~0x04;
                irqstat_timer = true;      
                if(backup != irqstat_reg0) do_irq();
        } else {
@@ -341,8 +348,8 @@ void FM7_MAINIO::set_sub_attention(bool flag)
 
 uint8 FM7_MAINIO::get_fd04(void)
 {
-       uint8 val = 0xfc;
-       if(display->read_signal(SIG_DISPLAY_BUSY) != 0) val |= 0x80;
+       uint8 val = 0x7c;
+       if(sub_busy) val |= 0x80;
        if(!firq_break_key)     val |= 0x02;
        if(!firq_sub_attention) {
                val |= 0x01;
@@ -363,15 +370,23 @@ void FM7_MAINIO::set_fd04(uint8 val)
  uint8 FM7_MAINIO::get_fd05(void)
 {
        uint8 val;
-       val = (display->read_signal(SIG_DISPLAY_BUSY) != 0) ? 0xfe : 0x7e;
+       val = (sub_busy) ? 0xfe : 0x7e;
        if(!extdet_neg) val |= 0x01;
+       //printf("FD05: READ: %d VAL=%02x\n", SDL_GetTicks(), val);
        return val;
 }
 
  void FM7_MAINIO::set_fd05(uint8 val)
 {
-       display->write_signal(SIG_FM7_SUB_CANCEL, val, 0x40); // HACK
-       display->write_signal(SIG_DISPLAY_HALT,   val, 0x80);
+       sub_cancel = ((val & 0x40) != 0) ? true : false;
+       sub_halt   = ((val & 0x80) != 0) ? true : false;
+       //display->write_signal(SIG_FM7_SUB_CANCEL, (sub_cancel) ? 0xff : 0x00, 0xff); // HACK
+       //if(sub_halt != sub_halt_bak) display->write_signal(SIG_DISPLAY_HALT, (sub_halt) ? 0xff : 0x00, 0xff); // HACK
+       if(sub_cancel != sub_cancel_bak) {
+               display->write_signal(SIG_FM7_SUB_CANCEL, (sub_cancel) ? 0xff : 0x00, 0xff); // HACK
+       }
+       sub_cancel_bak = sub_cancel;
+       //sub_halt_bak = sub_halt;
 #ifdef WITH_Z80
        if((val & 0x01) != 0) {
                //maincpu->write_signal(SIG_CPU_BUSREQ, 1, 1);
@@ -485,6 +500,9 @@ void FM7_MAINIO::write_signal(int id, uint32 data, uint32 mask)
        val_b = ((data & mask) != 0);
   
        switch(id) {
+               case FM7_MAINIO_SUB_BUSY:
+                       sub_busy = val_b;
+                       break;
                case FM7_MAINIO_CLOCKMODE: // fd00
                        if(val_b) {
                                clock_fast = true;
@@ -952,7 +970,7 @@ void FM7_MAINIO::write_data8(uint32 addr, uint32 data)
                        display->write_signal(SIG_DISPLAY_MODE320, data,  0x40);
                        break;
                case 0x13:
-                       display->write_signal(SIG_FM7_SUB_BANK, data, 0x07);
+                       sub_monitor_type = data & 0x07;
                        break;
 #endif
                case 0x15: // OPN CMD
@@ -1103,7 +1121,7 @@ void FM7_MAINIO::event_callback(int event_id, int err)
                        break;
                case EVENT_TIMERIRQ_ON:
                        if(!irqmask_timer) set_irq_timer(true);
-                       //register_event(this, EVENT_TIMERIRQ_OFF, 10000.0 / (4.9152 * 2.0) , false, NULL); // TIMER IRQ
+                       register_event(this, EVENT_TIMERIRQ_OFF, 10000.0 / (4.9152 * 2.0) , false, NULL); // TIMER IRQ
                        break;
                case EVENT_TIMERIRQ_OFF:
                        if(!irqmask_timer) set_irq_timer(false);
@@ -1133,3 +1151,24 @@ void FM7_MAINIO::update_config()
        }
        //      this->write_signal(FM7_MAINIO_CLOCKMODE, clock_fast ? 1 : 0, 1);
 }
+
+void FM7_MAINIO::event_vline(int v, int clock)
+{
+       if(sub_halt != sub_halt_bak) {
+               display->write_signal(SIG_DISPLAY_HALT,  (sub_halt) ? 0xff : 0x00, 0xff);
+       }
+       sub_halt_bak = sub_halt;
+       //if(firq_sub_attention != firq_sub_attention_bak){
+       //      do_firq();
+       //}
+       //firq_sub_attention_bak = firq_sub_attention;
+
+#if defined(_FM77AV_VARIANTS)
+       if(sub_monitor_type != sub_monitor_bak) {
+               display->write_signal(SIG_FM7_SUB_BANK, sub_monitor_type, 0x07);
+       }
+       sub_monitor_bak = sub_monitor_type;
+#endif
+}
+
+       
\ No newline at end of file
index f874b4f..4b0ff82 100644 (file)
@@ -83,13 +83,18 @@ class FM7_MAINIO : public DEVICE {
        bool stat_400linemode; // R/W : bit3, '0' = 400line, '1' = 200line.
        bool firq_break_key; // bit1, ON = '0'.
        bool firq_sub_attention; // bit0, ON = '0'.
+       bool firq_sub_attention_bak; // bit0, ON = '0'.
        /* FD04 : W */
        bool intmode_fdc; // bit2, '0' = normal, '1' = SFD.
 
        /* FD05 : R */
        bool extdet_neg; // bit0 : '1' = none , '0' = exists.
+       bool sub_busy;
        /* FD05 : W */
+       bool sub_halt; // bit7 : '1' Halt req.
        bool sub_cancel; // bit6 : '1' Cancel req.
+       bool sub_halt_bak; // bit7 : shadow.
+       bool sub_cancel_bak; // bit6 : shadow.
        bool z80_sel;    // bit0 : '1' = Z80. Maybe only FM-7/77.
 
        /* FD06 : R/W : RS-232C */
@@ -119,6 +124,7 @@ class FM7_MAINIO : public DEVICE {
        bool mode320; // bit6 : true = 320, false = 640
        /* FD13 : WO */
        uint8 sub_monitor_type; // bit 2 - 0: default = 0.
+       uint8 sub_monitor_bak; // bit 2 - 0: default = 0.
 #endif
        
        /* FD15 / FD46 / FD51 : W */
@@ -417,6 +423,8 @@ class FM7_MAINIO : public DEVICE {
                memset(io_w_latch, 0x00, 0x100);
        }
        ~FM7_MAINIO(){}
+       void event_vline(int v, int clock);
+
        uint8  opn_regs[4][0x100];
        uint32 read_io8(uint32 addr) { // This is only for debug.
                addr = addr & 0xfff;
index f5efbe9..d7c8c98 100644 (file)
@@ -66,7 +66,7 @@
 
 /* macros to access memory */
 #define IMMBYTE(b)     b = ROP_ARG(PCD); PC++
-#define IMMWORD(w)     w.d = (ROP_ARG(PCD) << 8) | ROP_ARG((PCD + 1) & 0xffff); PC += 2
+#define IMMWORD(w)     w.b.h = ROP_ARG(PCD) ; w.b.l = ROP_ARG((PCD + 1) & 0xffff); PC += 2
 
 #define PUSHBYTE(b)    --S; WM(SD,b)
 #define PUSHWORD(w)    --S; WM(SD, w.b.l); --S; WM(SD, w.b.h)
     tmpea.d = 0;                               \
     tmpea.b.h = DP;                            \
     IMMBYTE(tmpea.b.l);                                \
-    EAP = tmpea; }
+    EAD = tmpea.w.l; }
 
 #define IMM8           EAD = PCD; PC++
 #define IMM16          EAD = PCD; PC += 2
 /* macros for branch instructions */
 inline void MC6809::BRANCH(bool cond)
 {
-       uint8 t;
+       volatile uint8 t;
        IMMBYTE(t);
        if(!cond) return;
-       //if(t >= 0x80) {
-       //      PC = PC - 0x0100 + t;
-       //} else {
-       //      PC = PC + t;
-       //}
-       PC = PC + SIGNED(t);
+       if(t >= 0x80) {
+               PC = PC - 0x0100 + t;
+       } else {
+               PC = PC + t;
+       }
+       //PC = PC + SIGNED(t);
        PC = PC & 0xffff;
 }
 
@@ -618,7 +618,7 @@ void MC6809::run_one_opecode()
                if(d_debugger->now_suspended) {
                        emu->mute_sound();
                        while(d_debugger->now_debugging && d_debugger->now_suspended) {
-                               Sleep(10);
+                         Sleep(10);
                        }
                }
                if(d_debugger->now_debugging) {
@@ -3728,10 +3728,10 @@ OP_HANDLER(cmps_ix) {
 
 /* $aD JSR indexed ----- */
 OP_HANDLER(jsr_ix) {
-               fetch_effective_address();
-               PUSHWORD(pPC);
-               PCD = EAD;
-       }
+       fetch_effective_address();
+       PUSHWORD(pPC);
+       PCD = EAD;
+}
 
 /* $aE LDX (LDY) indexed -**0- */
 OP_HANDLER(ldx_ix) {
index b0e89be..371a4a2 100644 (file)
@@ -41,7 +41,7 @@ private:
        pair dp;        /* Direct Page register (page in MSB) */
        pair u, s;      /* Stack pointers */
        pair x, y;      /* Index registers */
-       volatile uint8 cc;
+       uint8 cc;
        pair ea;        /* effective address */
        
        uint8 int_state;