]> git.sur5r.net Git - cc65/blob - libsrc/c16/cgetc.s
atari5200: add alternative conio screen (20x12 resolution)
[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        "cbm_kernal.inc"
11         .include        "plus4.inc"
12
13
14 ; --------------------------------------------------------------------------
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:     jsr     KBDREAD         ; Read char and return in A
49         ldx     #0
50         rts
51
52 ; --------------------------------------------------------------------------
53 ; Make the function keys return function key codes instead of the current
54 ; strings so the program will see and may handle them.
55 ; Undo this change when the program ends
56
57         .constructor    initkbd
58         .destructor     donekbd
59
60 .segment        "ONCE"
61
62 .proc   initkbd
63
64         ldy     #7
65 @L1:    lda     fnkeys,y
66         sta     FKEY_SPACE+8,y
67         lda     #$01            ; Lower 8 places are all $01
68         sta     FKEY_SPACE,y
69         dey
70         bpl     @L1
71         rts
72
73 .endproc
74
75 fnkeys: .byte   133, 137, 134, 138, 135, 139, 136, 140
76
77
78 .code
79
80 .proc   donekbd
81
82         ldx     #$39            ; Copy the original function keys
83 @L1:    lda     FKEY_ORIG,x
84         sta     FKEY_SPACE,x
85         dex
86         bpl     @L1
87         rts
88
89 .endproc