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 (94 lines) | stat: -rw-r--r-- 2,542 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;
; Ullrich von Bassewitz, 06.08.1998
;
; char cgetc (void);
;

        .export         _cgetc
        .import         cursor

        .include        "cbm_kernal.inc"
        .include        "plus4.inc"

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

.segment        "LOWCODE"       ; Accesses the ROM - must go into low mem

_cgetc: lda     KEY_COUNT       ; Get number of characters
        ora     FKEY_COUNT      ; Or with number of function key chars
        bne     L2              ; Jump if there are already chars waiting

; Switch on the cursor if needed

        ldy     CURS_X
        lda     (CRAM_PTR),y    ; Get current char
        pha                     ; And save it
        lda     CHARCOLOR
        sta     (CRAM_PTR),y

        lda     cursor
        beq     L1              ; Jump if no cursor
        tya
        clc
        adc     SCREEN_PTR
        sta     TED_CURSLO
        lda     SCREEN_PTR+1
        adc     #$00
        sbc     #$0B            ; + carry = $C00 (screen address)
        sta     TED_CURSHI

L1:     lda     KEY_COUNT
        ora     FKEY_COUNT
        beq     L1
        pla
        sta     (CRAM_PTR),y
        lda     #$ff
        sta     TED_CURSLO      ; Cursor off
        sta     TED_CURSHI

L2:     sta     ENABLE_ROM      ; Bank in the ROM
        jsr     KBDREAD         ; Read char and return in A (ROM routine)
        sta     ENABLE_RAM      ; Reenable the RAM
        ldx     #0
        rts

; --------------------------------------------------------------------------
; Make the function keys return function key codes instead of the current
; strings so the program will see and may handle them.
; Undo this change when the program ends

        .constructor    initkbd
        .destructor     donekbd

.segment        "ONCE"          ; Special init code segment may get overwritten

.proc   initkbd

        ldy     #7
@L1:    lda     fnkeys,y
        sta     FKEY_SPACE+8,y
        lda     #$01            ; Lower 8 places are all $01
        sta     FKEY_SPACE,y
        dey
        bpl     @L1
        rts

.endproc

fnkeys: .byte   133, 137, 134, 138, 135, 139, 136, 140


.segment        "LOWCODE"       ; Accesses the ROM - must go into low mem

.proc   donekbd

        ldx     #$39            ; Copy the original function keys
        sta     ENABLE_ROM      ; Bank in the ROM
@L1:    lda     FKEY_ORIG,x
        sta     FKEY_SPACE,x
        dex
        bpl     @L1
        sta     ENABLE_RAM      ; Bank out the ROM
        rts

.endproc