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