2017-03-10 10:21:14 +00:00
|
|
|
;
|
|
|
|
; char cgetc (void);
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _cgetc
|
|
|
|
.import cursor
|
2019-09-02 18:52:16 +00:00
|
|
|
.import _kbhit
|
2017-03-10 10:21:14 +00:00
|
|
|
|
|
|
|
.include "osic1p.inc"
|
|
|
|
.include "extzp.inc"
|
|
|
|
.include "zeropage.inc"
|
|
|
|
|
2019-09-02 18:52:16 +00:00
|
|
|
; Input routine, show cursor if enabled
|
2017-03-10 10:21:14 +00:00
|
|
|
.code
|
|
|
|
_cgetc:
|
2019-09-02 18:52:16 +00:00
|
|
|
ldx CHARBUF ; character in buffer available?
|
|
|
|
bne done
|
2017-03-10 10:21:14 +00:00
|
|
|
lda cursor ; show cursor?
|
|
|
|
beq nocursor
|
|
|
|
ldy CURS_X
|
|
|
|
lda (SCREEN_PTR),y ; fetch current character
|
|
|
|
sta tmp1 ; save it
|
|
|
|
lda #$A1 ; full white square
|
2019-09-17 18:03:51 +00:00
|
|
|
sta (SCREEN_PTR),y ; store at cursor position
|
2019-09-02 18:52:16 +00:00
|
|
|
|
2017-03-10 10:21:14 +00:00
|
|
|
nocursor:
|
2019-09-02 18:52:16 +00:00
|
|
|
jsr _kbhit ; get input character in A
|
|
|
|
tax ; save A in X, set flags
|
|
|
|
beq nocursor ; until a key is actually pressed
|
|
|
|
lda cursor
|
2017-03-10 10:21:14 +00:00
|
|
|
beq done ; was cursor on?
|
|
|
|
lda tmp1 ; fetch saved character
|
|
|
|
ldy CURS_X
|
|
|
|
sta (SCREEN_PTR),y ; store at cursor position
|
|
|
|
|
|
|
|
done:
|
2018-01-05 00:04:13 +00:00
|
|
|
lda #$00
|
2019-09-02 18:52:16 +00:00
|
|
|
sta CHARBUF ; empty buffer
|
|
|
|
txa ; restore saved character from X
|
|
|
|
ldx #$00 ; high byte of int return value
|
2018-01-05 00:04:13 +00:00
|
|
|
rts
|