]> git.sur5r.net Git - cc65/blob - libsrc/c64/cgetc.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / c64 / cgetc.s
1 ;
2 ; Ullrich von Bassewitz, 06.08.1998
3 ;
4 ; char cgetc (void);
5 ;
6
7         .export         _cgetc
8         .import         cursor
9
10         .include        "c64.inc"
11
12 _cgetc: lda     KEY_COUNT       ; Get number of characters
13         bne     L3              ; Jump if there are already chars waiting
14
15 ; Switch on the cursor if needed
16
17         lda     CURS_FLAG
18         pha
19         lda     cursor
20         jsr     setcursor
21 L1:     lda     KEY_COUNT
22         beq     L1
23         ldx     #0
24         pla
25         bne     L2
26         inx
27 L2:     txa
28         jsr     setcursor
29
30 L3:     jsr     KBDREAD         ; Read char and return in A
31         ldx     #0
32         rts
33
34
35 ; Switch the cursor on or off
36
37 .proc   setcursor
38
39         tax                     ; On or off?
40         bne     seton           ; Go set it on
41         lda     CURS_FLAG       ; Is the cursor currently off?
42         bne     crs9            ; Jump if yes
43         lda     #1
44         sta     CURS_FLAG       ; Mark it as off
45         lda     CURS_STATE      ; Cursor currently displayed?
46         beq     crs8            ; Jump if no
47         ldy     CURS_X          ; Get the character column
48         lda     (SCREEN_PTR),y  ; Get character
49         eor     #$80
50         sta     (SCREEN_PTR),y  ; Store character back
51         lda     CURS_COLOR
52         sta     (CRAM_PTR),y    ; Store color back
53 crs8:   lda     #0
54         sta     CURS_STATE      ; Cursor not displayed
55 crs9:   rts
56
57 seton:  lda     #0
58         sta     CURS_FLAG
59         rts
60
61 .endproc