]> git.sur5r.net Git - cc65/blob - libsrc/cbm610/cgetc.s
Invalid error codes will set errno
[cc65] / libsrc / cbm610 / cgetc.s
1 ;
2 ; Ullrich von Bassewitz, 06.08.1998
3 ;
4 ; char cgetc (void);
5 ;
6
7         .export         _cgetc
8         .import         plot, write_crtc
9         .import         cursor
10
11         .include        "cbm610.inc"
12
13
14 _cgetc: lda     KeyIndex        ; Get number of characters
15         bne     L2              ; Jump if there are already chars waiting
16
17 ; Switch on the cursor if needed
18
19         lda     cursor
20         beq     L1              ; Jump if no cursor
21
22         jsr     plot            ; Set the current cursor position
23         ldy     #10
24         lda     Config          ; Cursor format
25         jsr     write_crtc      ; Set the cursor formar
26
27 L1:     lda     KeyIndex
28         beq     L1
29
30         ldy     #10
31         lda     #$20            ; Cursor off
32         jsr     write_crtc
33
34 L2:     ldx     #$00            ; Get index
35         ldy     KeyBuf          ; Get first character in the buffer
36         sei
37 L3:     lda     KeyBuf+1,x      ; Move up the remaining chars
38         sta     KeyBuf,x
39         inx
40         cpx     KeyIndex
41         bne     L3
42         dec     KeyIndex
43         cli
44
45         ldx     #$00            ; High byte
46         tya                     ; First char from buffer
47         rts
48