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