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