]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/cgetc.s
Fixed capslock on startup
[cc65] / libsrc / cbm510 / cgetc.s
1 ;
2 ; Ullrich von Bassewitz, 16.09.2001
3 ;
4 ; char cgetc (void);
5 ;
6
7         .export         _cgetc
8         .condes         k_blncur, 2
9         .import         cursor
10
11         .include        "cbm510.inc"
12
13
14 ; ------------------------------------------------------------------------
15
16 .proc   _cgetc
17
18         lda     KeyIndex                ; Characters waiting?
19         bne     L3                      ; Jump if so
20
21 ; Switch on the cursor if needed
22
23         lda     CURS_FLAG
24         pha
25         lda     cursor
26         jsr     setcursor
27 L1:     lda     KeyIndex
28         beq     L1
29         ldx     #0
30         pla
31         bne     L2
32         inx
33 L2:     txa
34         jsr     setcursor
35
36 ; Read the character from the keyboard buffer
37
38 L3:     ldx     #$00            ; Get index
39         ldy     KeyBuf          ; Get first character in the buffer
40         sei
41 L4:     lda     KeyBuf+1,x      ; Move up the remaining chars
42         sta     KeyBuf,x
43         inx
44         cpx     KeyIndex
45         bne     L4
46         dec     KeyIndex
47         cli
48
49         ldx     #$00            ; High byte
50         tya                     ; First char from buffer
51         rts
52
53 .endproc
54
55 ; ------------------------------------------------------------------------
56 ;
57
58 .proc   setcursor
59
60         ldy     #$00                    ;
61         tax                             ; On or off?
62         bne     @L9                     ; Go set it on
63         lda     CURS_FLAG               ; Is the cursor currently off?
64         bne     @L8                     ; Jump if yes
65         lda     #1
66         sta     CURS_FLAG               ; Mark it as off
67         lda     CURS_STATE              ; Cursor currently displayed?
68         sty     CURS_STATE              ; Cursor will be cleared later
69         beq     @L8                     ; Jump if no
70
71 ; Switch to the system bank, load Y with the cursor X coordinate
72
73         lda     #$0F
74         sta     IndReg                  ; Access system bank
75         ldy     CURS_X
76
77 ; Reset the current cursor
78
79         lda     CURS_COLOR
80         sta     (CRAM_PTR),y            ; Store cursor color
81         lda     ExecReg
82         sta     IndReg                  ; Switch to our segment
83         lda     (SCREEN_PTR),y
84         eor     #$80                    ; Toggle reverse flag
85         sta     (SCREEN_PTR),y
86
87 ; Done
88
89 @L8:    rts
90
91 @L9:    sty     CURS_FLAG               ; Cursor on (Y = 0)
92         rts
93
94 .endproc
95
96
97 ; ------------------------------------------------------------------------
98 ; Blink the cursor in the interrupt. A blinking cursor is only available if
99 ; we use the cgetc() function, so we will export this IRQ handler only in
100 ; case the module is included into a program.
101
102
103 .proc   k_blncur
104
105         lda     CURS_FLAG               ; Is the cursor on?
106         bne     curend                  ; Jump if not
107         dec     CURS_BLINK
108         bne     curend
109
110 ; Re-initialize the blink counter
111
112         lda     #20                     ; Initial value
113         sta     CURS_BLINK
114
115 ; Load Y with the cursor X coordinate
116
117         ldy     CURS_X
118
119 ; Check if the cursor state was on or off before
120
121         lda     CURS_COLOR              ; Load color behind cursor
122         lsr     CURS_STATE              ; Cursor currently displayed?
123         bcs     curset                  ; Jump if yes
124
125 ; Cursor was off before, switch it on
126
127         inc     CURS_STATE              ; Mark as displayed
128         lda     (CRAM_PTR),y            ; Get color behind cursor...
129         sta     CURS_COLOR              ; ...and remember it
130         lda     CHARCOLOR               ; Use character color
131
132 ; Set the cursor with color in A
133
134 curset: sta     (CRAM_PTR),y            ; Store cursor color
135         lda     ExecReg
136         sta     IndReg                  ; Switch to our segment
137         lda     (SCREEN_PTR),y
138         eor     #$80                    ; Toggle reverse flag
139         sta     (SCREEN_PTR),y
140
141 ; Switch back to the system bank
142
143         lda     #$0F
144         sta     IndReg
145
146 curend: rts
147
148 .endproc
149
150