]> git.sur5r.net Git - cc65/blobdiff - libsrc/cbm510/cgetc.s
remove superfluous ".code" line
[cc65] / libsrc / cbm510 / cgetc.s
index 4cb75ccb46a5e296fe83b4e8016d279b836966b4..5fed54e0a52592d82f29350ca4680803d96287e4 100644 (file)
@@ -5,17 +5,18 @@
 ;
 
        .export         _cgetc
+       .condes         k_blncur, 2
        .import         cursor
 
-       .include        "zeropage.inc"
-       .include        "page3.inc"
+       .include        "cbm510.inc"
+        .include        "extzp.inc"
 
 
 ; ------------------------------------------------------------------------
 
 .proc  _cgetc
 
-       lda     KeyIndex                ; Characters waiting?
+       lda     keyidx                  ; Characters waiting?
                bne     L3                      ; Jump if so
 
 ; Switch on the cursor if needed
@@ -24,7 +25,7 @@
        pha
        lda     cursor
        jsr     setcursor
-L1:    lda     KeyIndex
+L1:    lda     keyidx
        beq     L1
        ldx     #0
        pla
@@ -36,14 +37,14 @@ L2:         txa
 ; Read the character from the keyboard buffer
 
 L3:            ldx     #$00            ; Get index
-               ldy     KeyBuf          ; Get first character in the buffer
+               ldy     keybuf          ; Get first character in the buffer
                sei
-L4:            lda     KeyBuf+1,x      ; Move up the remaining chars
-               sta     KeyBuf,x
+L4:            lda     keybuf+1,x      ; Move up the remaining chars
+               sta     keybuf,x
                inx
-               cpx     KeyIndex
+               cpx     keyidx
                bne     L4
-               dec     KeyIndex
+               dec     keyidx
                cli
 
                ldx     #$00            ; High byte
@@ -61,7 +62,7 @@ L4:           lda     KeyBuf+1,x      ; Move up the remaining chars
                tax                             ; On or off?
                bne     @L9                     ; Go set it on
        lda     CURS_FLAG               ; Is the cursor currently off?
-               bne     @L8                     ; Jump if yes
+               bne     @L8                     ; Jump if yes
        lda     #1
        sta     CURS_FLAG               ; Mark it as off
        lda     CURS_STATE              ; Cursor currently displayed?
@@ -93,3 +94,59 @@ L4:          lda     KeyBuf+1,x      ; Move up the remaining chars
 
 .endproc
 
+
+; ------------------------------------------------------------------------
+; Blink the cursor in the interrupt. A blinking cursor is only available if
+; we use the cgetc() function, so we will export this IRQ handler only in
+; case the module is included into a program.
+
+
+.proc   k_blncur
+
+        lda     CURS_FLAG              ; Is the cursor on?
+        bne     curend                 ; Jump if not
+        dec     CURS_BLINK
+        bne     curend
+
+; Re-initialize the blink counter
+
+        lda     #20                    ; Initial value
+        sta     CURS_BLINK
+
+; Load Y with the cursor X coordinate
+
+       ldy     CURS_X
+
+; Check if the cursor state was on or off before
+
+       lda     CURS_COLOR              ; Load color behind cursor
+       lsr     CURS_STATE              ; Cursor currently displayed?
+       bcs     curset                  ; Jump if yes
+
+; Cursor was off before, switch it on
+
+       inc     CURS_STATE              ; Mark as displayed
+       lda     (CRAM_PTR),y            ; Get color behind cursor...
+       sta     CURS_COLOR              ; ...and remember it
+       lda     CHARCOLOR               ; Use character color
+
+; Set the cursor with color in A
+
+curset:        sta     (CRAM_PTR),y            ; Store cursor color
+       lda     ExecReg
+       sta     IndReg                  ; Switch to our segment
+       lda     (SCREEN_PTR),y
+       eor     #$80                    ; Toggle reverse flag
+       sta     (SCREEN_PTR),y
+
+; Switch back to the system bank
+
+       lda     #$0F
+       sta     IndReg
+
+curend:        rts
+
+.endproc
+
+
+