]> git.sur5r.net Git - cc65/blob - libsrc/c16/cgetc.s
Fixed problems that were introduced with r4287.
[cc65] / libsrc / c16 / 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        "plus4.inc"
11
12
13 ; --------------------------------------------------------------------------
14
15 _cgetc: lda     KEY_COUNT       ; Get number of characters
16         ora     FKEY_COUNT      ; Or with number of function key chars
17         bne     L2              ; Jump if there are already chars waiting
18
19 ; Switch on the cursor if needed
20
21         ldy     CURS_X
22         lda     (CRAM_PTR),y    ; Get current char
23         pha                     ; And save it
24         lda     CHARCOLOR
25         sta     (CRAM_PTR),y
26
27         lda     cursor
28         beq     L1              ; Jump if no cursor
29         tya
30         clc
31         adc     SCREEN_PTR
32         sta     TED_CURSLO
33         lda     SCREEN_PTR+1
34         adc     #$00
35         sbc     #$0B            ; + carry = $C00 (screen address)
36         sta     TED_CURSHI
37
38 L1:     lda     KEY_COUNT
39         ora     FKEY_COUNT
40         beq     L1
41         pla
42         sta     (CRAM_PTR),y
43         lda     #$ff
44         sta     TED_CURSLO      ; Cursor off
45         sta     TED_CURSHI
46
47 L2:     jsr     KBDREAD         ; Read char and return in A
48         ldx     #0
49         rts
50
51 ; --------------------------------------------------------------------------
52 ; Make the function keys return function key codes instead of the current
53 ; strings so the program will see and may handle them.
54 ; Undo this change when the program ends
55
56         .constructor    initkbd
57         .destructor     donekbd
58
59 .segment        "INIT"
60
61 .proc   initkbd
62
63         ldy     #15
64 @L1:    lda     fnkeys,y
65         sta     FKEY_SPACE,y
66         dey
67         bpl     @L1
68         rts
69
70 .endproc
71
72
73 .code
74
75 .proc   donekbd
76
77         ldx     #$39            ; Copy the original function keys
78 @L1:    lda     FKEY_ORIG,x
79         sta     FKEY_SPACE,x
80         dex
81         bpl     @L1
82         rts
83
84 .endproc
85
86
87 ; Function key table, readonly
88
89 .rodata
90 fnkeys: .byte   $01, $01, $01, $01, $01, $01, $01, $01
91         .byte   133, 137, 134, 138, 135, 139, 136, 140
92