]> git.sur5r.net Git - cc65/blob - libsrc/c128/cgetc.s
Removed a "cc65_" prefix.
[cc65] / libsrc / c128 / cgetc.s
1 ;
2 ; Ullrich von Bassewitz, 06.08.1998
3 ;
4 ; char cgetc (void);
5 ;
6
7         .export         _cgetc
8         .constructor    initcgetc
9         .destructor     donecgetc
10
11         .import         cursor
12
13         .include        "cbm_kernal.inc"
14         .include        "c128.inc"
15
16 ;--------------------------------------------------------------------------
17
18 _cgetc: lda     KEY_COUNT       ; Get number of characters
19         bne     L2              ; Jump if there are already chars waiting
20
21 ; Switch on the cursor if needed. We MUST always switch the cursor on,
22 ; before switching it off, because switching it off will restore the
23 ; character attribute remembered when it was switched on. So just switching
24 ; it off will restore the wrong character attribute.
25
26         jsr     CURS_SET        ; Set cursor to current position
27         jsr     CURS_ON
28         lda     cursor
29         bne     L1
30         lda     #$01
31         jsr     CURS_OFF
32 L1:     lda     KEY_COUNT       ; Check characters again
33         beq     L1
34         jsr     CURS_OFF        ; Switch cursor off, if characters available
35
36 L2:     jsr     KBDREAD         ; Read char and return in A
37         ldx     #0
38         rts
39
40 ;--------------------------------------------------------------------------
41 ; Module constructor/destructor
42
43 .segment        "INIT"
44 keyvec: .res    2
45
46 .segment        "ONCE"
47 initcgetc:
48
49 ; Save the old vector
50
51         lda     KeyStoreVec
52         ldx     KeyStoreVec+1
53         sta     keyvec
54         stx     keyvec+1
55
56 ; Set the new vector. I can only hope that this works for other C128
57 ; versions...
58
59         lda     #<$C6B7
60         ldx     #>$C6B7
61         jmp     SetVec
62
63 .code
64 donecgetc:
65         lda     keyvec
66         ldx     keyvec+1
67 SetVec: sei
68         sta     KeyStoreVec
69         stx     KeyStoreVec+1
70         cli
71         rts