]> git.sur5r.net Git - cc65/blob - libsrc/plus4/cgetc.s
lseek: Return EINVAL if new position is less than 0 or greater than 2^24 - 1.
[cc65] / libsrc / plus4 / 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        "plus4.inc"
11
12 ; --------------------------------------------------------------------------
13
14 .segment        "LOWCODE"       ; Accesses the ROM - must go into low mem
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:     sta     ENABLE_ROM      ; Bank in the ROM
49         jsr     KBDREAD         ; Read char and return in A (ROM routine)
50         sta     ENABLE_RAM      ; Reenable the RAM
51         ldx     #0
52         rts
53
54 ; --------------------------------------------------------------------------
55 ; Make the function keys return function key codes instead of the current
56 ; strings so the program will see and may handle them.
57 ; Undo this change when the program ends
58
59         .constructor    initkbd
60         .destructor     donekbd
61
62 .segment        "ONCE"          ; Special init code segment may get overwritten
63
64 .proc   initkbd
65
66         ldy     #7
67 @L1:    lda     fnkeys,y
68         sta     FKEY_SPACE+8,y
69         lda     #$01            ; Lower 8 places are all $01
70         sta     FKEY_SPACE,y
71         dey
72         bpl     @L1
73         rts
74
75 .endproc
76
77 fnkeys: .byte   133, 137, 134, 138, 135, 139, 136, 140
78
79
80 .segment        "LOWCODE"       ; Accesses the ROM - must go into low mem
81
82 .proc   donekbd
83
84         ldx     #$39            ; Copy the original function keys
85         sta     ENABLE_ROM      ; Bank in the ROM
86 @L1:    lda     FKEY_ORIG,x
87         sta     FKEY_SPACE,x
88         dex
89         bpl     @L1
90         sta     ENABLE_RAM      ; Bank out the ROM
91         rts
92
93 .endproc