;------------
;MFF0DRVR.SC4 - KARAOKE SCAN AHEAD LOGIC
;------------
; THIS LOGIC IS CALLED WHENEVER A CARRIAGE RETURN ($0D) IS FOUND.
; IT WILL SCAN AHEAD IN THE BUFFER TO FIND THE NEXT CARRIAGE RETURN
; BY LOOKING FOR TEXT META EVENTS.  IT WILL PRINT UP TO 79 CHARACTERS.
; IT WILL EXIT WHEN EITHER A NEW CARRIAGE RETURN IS FOUND, 79 CHARACTERS
; HAVE BEEN PRINTED, THE END OF TRACK MARKER (FF 2F) IS FOUND, OR THE
; POINTER REACHES THE END OF THE CURRENT BUFFER.
;
MYPTR    EQU $08
MYXCOORD DFB $00
MYENDFLG DFB $00
MYBYTE   DFB $00
MYLENGTH DFB $00
MYSTOP   DFB $00
;
KARASCAN LDA PLAYPTR         ;SET OUR POINTER TO CURRENT POSITION
         STA MYPTR
         LDA PLAYPTR+1
         STA MYPTR+1
         LDA #$00
         STA MYXCOORD
         STA MYENDFLG
         LDA PLAYSTOP+1      
         STA MYSTOP
KARALOOP LDY #$00
         LDA (MYPTR),Y
         CMP #$FF
         BEQ FOUNDFF
KARALOO1 JSR INCMYPT
         LDA MYENDFLG
         BEQ KARALOOP
KARADONE LDA #$8D            ;PRINT CR
         JSR COUT
         RTS
;
FOUNDFF  JSR INCMYPT
         LDA MYENDFLG
         BNE KARADONE
         LDA MYBYTE
         CMP #$2F
         BEQ KARADONE
         CMP #$10
         BCS KARALOO1        ;NOT TEXT EVENT
         JSR INCMYPT
         LDA MYENDFLG
         BNE KARADONE
         LDA MYBYTE
         BMI KARALOO1        ;DON'T SUPPORT META > 127 CHARS-LOOK FOR MORE
         BEQ KARALOO1        ;TEXT LEN OF 0 
         STA MYLENGTH
PRLOOP   JSR INCMYPT
         LDA MYENDFLG
         BNE KARADONE
         JSR PRINT24         ;PRINT THE CHAR
         LDA MYENDFLG
         BNE KARADONE
         DEC MYLENGTH
         LDA MYLENGTH
         BNE PRLOOP
         BEQ KARALOO1
;
INCMYPT  INC MYPTR
         BNE INCMYP2
         INC MYPTR+1
         LDA MYPTR+1
         CMP MYSTOP
         BCC INCMYP2
         INC MYENDFLG
         RTS
INCMYP2  LDY #$00
         LDA (MYPTR),Y
         STA MYBYTE
         RTS
;
PRINT24  LDY #23
         LDX MYXCOORD
         LDA MYBYTE
         CMP #$0D
         BEQ SETEND
         CMP #$20            ;DON'T PRINT CONTROL CHARS
         BCC PRINT24A
         ORA #$80
         JSR COUT
         INX
         STX MYXCOORD
         CPX #79
         BNE PRINT24A
SETEND   INC MYENDFLG
PRINT24A RTS
;
         CHN MFF0DRVR.SC5
