File: cgetc.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (71 lines) | stat: -rw-r--r-- 1,808 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;
; Ullrich von Bassewitz, 06.08.1998
;
; char cgetc (void);
;

        .export         _cgetc
        .constructor    initcgetc
        .destructor     donecgetc

        .import         cursor

        .include        "cbm_kernal.inc"
        .include        "c128.inc"

;--------------------------------------------------------------------------

_cgetc: lda     KEY_COUNT       ; Get number of characters
        bne     L2              ; Jump if there are already chars waiting

; Switch on the cursor if needed. We MUST always switch the cursor on,
; before switching it off, because switching it off will restore the
; character attribute remembered when it was switched on. So just switching
; it off will restore the wrong character attribute.

        jsr     CURS_SET        ; Set cursor to current position
        jsr     CURS_ON
        lda     cursor
        bne     L1
        lda     #$01
        jsr     CURS_OFF
L1:     lda     KEY_COUNT       ; Check characters again
        beq     L1
        jsr     CURS_OFF        ; Switch cursor off, if characters available

L2:     jsr     KBDREAD         ; Read char and return in A
        ldx     #0
        rts

;--------------------------------------------------------------------------
; Module constructor/destructor

.segment        "INIT"
keyvec: .res    2

.segment        "ONCE"
initcgetc:

; Save the old vector

        lda     KeyStoreVec
        ldx     KeyStoreVec+1
        sta     keyvec
        stx     keyvec+1

; Set the new vector. I can only hope that this works for other C128
; versions...

        lda     #<$C6B7
        ldx     #>$C6B7
        jmp     SetVec

.code
donecgetc:
        lda     keyvec
        ldx     keyvec+1
SetVec: sei
        sta     KeyStoreVec
        stx     KeyStoreVec+1
        cli
        rts