]> git.sur5r.net Git - cc65/blob - libsrc/c64/soft80mono_cgetc.s
Saved 2 bytes and fixed error in case of negative result.
[cc65] / libsrc / c64 / soft80mono_cgetc.s
1 ;
2 ; Groepaz/Hitmen, 19.10.2015
3 ;
4 ; high level implementation for the monochrome soft80 implementation
5 ;
6 ; char cgetc (void);
7 ;
8
9         .export         soft80mono_cgetc
10         .import         soft80mono_internal_cellcolor, soft80mono_internal_cursorxlsb
11         .import         soft80mono_internal_nibble
12         .import         cursor
13         .importzp       tmp1
14
15         .include        "c64.inc"
16         .include        "soft80.inc"
17
18 soft80mono_cgetc:
19         lda     KEY_COUNT       ; Get number of characters
20         bne     @L3             ; Jump if there are already chars waiting
21
22         jsr     invertcursor    ; set cursor on or off accordingly
23
24 @L1:    lda     KEY_COUNT       ; wait for key
25         beq     @L1
26
27         jsr     invertcursor    ; set cursor on or off accordingly
28
29 @L3:    jsr     KBDREAD         ; Read char and return in A
30         ldx     #0
31         rts
32
33 ; Switch the cursor on or off (invert)
34
35 invertcursor:
36         lda     cursor
37         bne     @invert
38         rts
39 @invert:
40
41         sei
42         lda     $01             ; enable RAM under I/O
43         pha
44         lda     #$34
45         sta     $01
46
47         ldy     #$00
48         ldx     soft80mono_internal_cursorxlsb
49 @lp1:
50         lda     (SCREEN_PTR),y
51         eor     soft80mono_internal_nibble,x
52         sta     (SCREEN_PTR),y
53         iny
54         cpy     #8
55         bne     @lp1
56
57         pla
58         sta     $01             ; enable I/O
59         cli
60         rts
61
62 ;-------------------------------------------------------------------------------
63 ; force the init constructor to be imported
64
65         .import soft80mono_init
66 conio_init      = soft80mono_init