]> git.sur5r.net Git - cc65/blob - libsrc/c64/soft80_cgetc.s
size optimization
[cc65] / libsrc / c64 / soft80_cgetc.s
1 ;
2 ; Groepaz/Hitmen, 11.10.2015
3 ;
4 ; char cgetc (void);
5 ;
6
7         .export         soft80_cgetc
8         .import         soft80_internal_cursorxlsb
9         .import         cursor
10         .importzp       tmp1
11
12         .include        "c64.inc"
13         .include        "soft80.inc"
14
15 soft80_cgetc:
16         lda     KEY_COUNT       ; Get number of characters
17         bne     L3              ; Jump if there are already chars waiting
18
19         sec
20         jsr     invertcursor    ; set cursor on or off accordingly
21
22 L1:     lda     KEY_COUNT       ; wait for key
23         beq     L1
24
25         clc
26         jsr     invertcursor    ; set cursor on or off accordingly
27
28 L3:     jsr     KBDREAD         ; Read char and return in A
29         ldx     #0
30         rts
31
32 ; Switch the cursor on or off (invert)
33
34 invertcursor:
35         lda     cursor
36         bne     @invert
37         rts
38 @invert:
39
40         sei
41         lda     $01             ; enable RAM under I/O
42         pha
43         lda     #$34
44         sta     $01
45
46         ldy     #$00
47         jsr     setcolor
48
49         ;lda     CURS_X
50         ;and     #$01
51         ;tax
52         ldx     soft80_internal_cursorxlsb
53 @lp1:
54         lda     (SCREEN_PTR),y
55         eor     nibble,x
56         sta     (SCREEN_PTR),y
57         iny
58         cpy     #8
59         bne     @lp1
60
61         pla
62         sta     $01             ; enable I/O
63         cli
64         rts
65
66         ; do not use soft80_putcolor here to make sure the cursor is always
67         ; shown using the current textcolor without disturbing the "color voodoo"
68         ; in soft80_cputc
69 setcolor:
70         ;ldy     #0              ; is 0
71         bcs     @set
72         ; restore old value
73         lda     tmp1
74         sta     (CRAM_PTR),y    ; vram
75         rts
76 @set:
77         lda     (CRAM_PTR),y    ; vram
78         sta     tmp1
79         lda     CHARCOLOR
80         sta     (CRAM_PTR),y    ; vram
81         rts
82
83         .rodata
84 nibble: .byte $f0, $0f
85
86 ;-------------------------------------------------------------------------------
87 ; force the init constructor to be imported
88
89         .import soft80_init
90 conio_init      = soft80_init