]> git.sur5r.net Git - cc65/blob - libsrc/c16/cgetc.s
New loadable mouse drivers
[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/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 .proc   initkbd
60
61         ldy     #15
62 @L1:    lda     fnkeys,y
63         sta     FKEY_SPACE,y
64         dey
65         bpl     @L1
66         rts
67
68 .endproc
69
70
71 .proc   donekbd
72
73         ldx     #$39            ; Copy the original function keys
74 @L1:    lda     FKEY_ORIG,x
75         sta     FKEY_SPACE,x
76         dex
77         bpl     @L1
78         rts
79
80 .endproc
81
82
83 ; Function key table, readonly
84
85 .rodata
86 fnkeys: .byte   $01, $01, $01, $01, $01, $01, $01, $01
87         .byte   133, 137, 134, 138, 135, 139, 136, 140
88