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