]> git.sur5r.net Git - cc65/blob - libsrc/c16/cgetc.s
Saved 3 bytes for the C16 target.
[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        "ONCE"
60
61 .proc   initkbd
62
63         ldy     #7
64 @L1:    lda     fnkeys,y
65         sta     FKEY_SPACE+8,y
66         lda     #$01            ; Lower 8 places are all $01
67         sta     FKEY_SPACE,y
68         dey
69         bpl     @L1
70         rts
71
72 .endproc
73
74 fnkeys: .byte   133, 137, 134, 138, 135, 139, 136, 140
75
76
77 .code
78
79 .proc   donekbd
80
81         ldx     #$39            ; Copy the original function keys
82 @L1:    lda     FKEY_ORIG,x
83         sta     FKEY_SPACE,x
84         dex
85         bpl     @L1
86         rts
87
88 .endproc