]> git.sur5r.net Git - cc65/blob - libsrc/atari/cgetc.s
Merge pull request #24 from greg-king5/oric
[cc65] / libsrc / atari / cgetc.s
1 ;
2 ; Christian Groessler, November-2002
3 ;
4 ; get a char from the keyboard
5 ; char cgetc(void)
6 ;
7
8         .include "atari.inc"
9         .export _cgetc,setcursor
10         .import cursor,mul40
11
12 _cgetc:
13         jsr     setcursor
14         jsr     @1
15         ldx     #0
16         rts
17
18 @1:     lda     KEYBDV+5
19         pha
20         lda     KEYBDV+4
21         pha
22         lda     #12
23         sta     ICAX1Z          ; fix problems with direct call to KEYBDV
24         rts
25
26
27 .proc   setcursor
28
29         ldy     #0
30         lda     OLDCHR
31         sta     (OLDADR),y
32
33         lda     ROWCRS
34         jsr     mul40
35         clc
36         adc     SAVMSC          ; add start of screen memory
37         sta     OLDADR
38         txa
39         adc     SAVMSC+1
40         sta     OLDADR+1
41         lda     COLCRS
42         adc     OLDADR
43         sta     OLDADR
44         bcc     nc
45         inc     OLDADR+1
46 nc:     lda     (OLDADR),y
47         sta     OLDCHR
48
49         ldx     cursor          ; current cursor setting as requested by the user
50         beq     off
51         ldx     #0
52         beq     cont
53
54 off:    inx
55 cont:   stx     CRSINH          ; update system variable
56
57         beq     turnon
58         and     #$7f            ; clear high bit / inverse flag
59 finish: sta     (OLDADR),y      ; update on-screen display
60         rts
61
62 turnon: ora     #$80            ; set high bit / inverse flag
63         bne     finish
64
65 .endproc