mirror of
https://github.com/cc65/cc65.git
synced 2024-06-07 07:29:33 +00:00
Implemented a one-character buffer for kbhit() and cgetc().
If kbhit() detects that a key is pressed, it fetches and buffers the character. If cgetc() detects a buffered character, this one is returned instead of fetching one with the PROM routine.
This commit is contained in:
parent
b1969ac16a
commit
222668c016
|
@ -7,7 +7,7 @@ SYMBOLS {
|
||||||
}
|
}
|
||||||
MEMORY {
|
MEMORY {
|
||||||
# for size of ZP see runtime/zeropage.s and c1p/extzp.s
|
# for size of ZP see runtime/zeropage.s and c1p/extzp.s
|
||||||
ZP: file = "", define = yes, start = $0002, size = $001A + $0004;
|
ZP: file = "", define = yes, start = $0002, size = $001A + $0005;
|
||||||
RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S;
|
RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S;
|
||||||
}
|
}
|
||||||
SEGMENTS {
|
SEGMENTS {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
;
|
;
|
||||||
; char cgetc (void);
|
; char cgetc (void);
|
||||||
;
|
;
|
||||||
|
|
||||||
|
.constructor initcgetc
|
||||||
.export _cgetc
|
.export _cgetc
|
||||||
.import cursor
|
.import cursor
|
||||||
|
|
||||||
|
@ -8,8 +10,21 @@
|
||||||
.include "extzp.inc"
|
.include "extzp.inc"
|
||||||
.include "zeropage.inc"
|
.include "zeropage.inc"
|
||||||
|
|
||||||
|
; Initialize one-character buffer that is filled by kbhit()
|
||||||
|
initcgetc:
|
||||||
|
lda #$00
|
||||||
|
sta CHARBUF ; No character in buffer initially
|
||||||
|
rts
|
||||||
|
|
||||||
; Input routine from 65V PROM MONITOR, show cursor if enabled
|
; Input routine from 65V PROM MONITOR, show cursor if enabled
|
||||||
_cgetc:
|
_cgetc:
|
||||||
|
lda CHARBUF ; character in buffer available?
|
||||||
|
beq nobuffer
|
||||||
|
tax ; save character in X
|
||||||
|
lda #$00
|
||||||
|
sta CHARBUF ; empty buffer
|
||||||
|
jmp restorex ; restore X and return
|
||||||
|
nobuffer:
|
||||||
lda cursor ; show cursor?
|
lda cursor ; show cursor?
|
||||||
beq nocursor
|
beq nocursor
|
||||||
ldy CURS_X
|
ldy CURS_X
|
||||||
|
@ -25,7 +40,9 @@ nocursor:
|
||||||
lda tmp1 ; fetch saved character
|
lda tmp1 ; fetch saved character
|
||||||
ldy CURS_X
|
ldy CURS_X
|
||||||
sta (SCREEN_PTR),y ; store at cursor position
|
sta (SCREEN_PTR),y ; store at cursor position
|
||||||
|
|
||||||
|
restorex:
|
||||||
txa ; restore saved character from X
|
txa ; restore saved character from X
|
||||||
ldx #$00 ; high byte of int return value
|
|
||||||
done:
|
done:
|
||||||
|
ldx #$00 ; high byte of int return value
|
||||||
rts
|
rts
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
|
|
||||||
.globalzp CURS_X, CURS_Y, SCREEN_PTR
|
.globalzp CURS_X, CURS_Y, SCREEN_PTR, CHARBUF
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
CURS_X: .res 1
|
CURS_X: .res 1
|
||||||
CURS_Y: .res 1
|
CURS_Y: .res 1
|
||||||
SCREEN_PTR: .res 2
|
SCREEN_PTR: .res 2
|
||||||
|
CHARBUF: .res 1
|
||||||
|
|
||||||
; size 4
|
; size 5
|
||||||
; Adjust size of this segment in osic1p.cfg if the size changes
|
; Adjust size of the ZP segment in osic1p.cfg if the size changes
|
||||||
|
|
|
@ -19,10 +19,13 @@ scan:
|
||||||
rol a ; Rotate row select to next bit position
|
rol a ; Rotate row select to next bit position
|
||||||
cmp #$FF ; Done?
|
cmp #$FF ; Done?
|
||||||
bne scan ; If not, continue
|
bne scan ; If not, continue
|
||||||
ldx #$00 ; High byte of return is always zero
|
|
||||||
lda #$00 ; Return false
|
lda #$00 ; Return false
|
||||||
|
tax ; High byte of return is also zero
|
||||||
|
sta CHARBUF ; No character in buffer
|
||||||
rts
|
rts
|
||||||
keypressed:
|
keypressed:
|
||||||
|
jsr INPUTC ; Get input character in A
|
||||||
|
sta CHARBUF ; Save in buffer
|
||||||
ldx #$00 ; High byte of return is always zero
|
ldx #$00 ; High byte of return is always zero
|
||||||
lda #$01 ; Return true
|
lda #$01 ; Return true
|
||||||
rts
|
rts
|
||||||
|
|
Loading…
Reference in New Issue
Block a user