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