]> git.sur5r.net Git - cc65/blob - libsrc/pet/cgetc.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / pet / 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        "pet.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 ; Fetch the character from the keyboard buffer
31
32 L3:     sei
33         ldy     KEY_BUF
34         ldx     #$00
35 L4:     lda     KEY_BUF+1,x
36         sta     KEY_BUF,x
37         inx
38         cpx     KEY_COUNT
39         bne     L4
40         dec     KEY_COUNT
41         cli
42         ldx     #$00            ; Clear high byte
43         tya
44         rts
45
46 ; Switch the cursor on or off
47
48 setcursor:
49         tax                     ; On or off?
50         bne     seton           ; Go set it on
51         lda     CURS_FLAG       ; Is the cursor currently off?
52         bne     crs9            ; Jump if yes
53         lda     #1
54         sta     CURS_FLAG       ; Mark it as off
55         lda     CURS_STATE      ; Cursor currently displayed?
56         beq     crs8            ; Jump if no
57         ldy     CURS_X          ; Get the character column
58         lda     (SCREEN_PTR),y  ; Get character
59         eor     #$80
60         sta     (SCREEN_PTR),y  ; Store character back
61 crs8:   lda     #0
62         sta     CURS_STATE      ; Cursor not displayed
63 crs9:   rts
64
65 seton:  lda     #0
66         sta     CURS_FLAG
67         rts
68