2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 06.08.1998
|
|
|
|
;
|
|
|
|
; char cgetc (void);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _cgetc
|
2002-12-19 22:53:13 +00:00
|
|
|
.constructor initcgetc
|
|
|
|
.destructor donecgetc
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.import cursor
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-11-25 08:46:05 +00:00
|
|
|
.include "cbm_kernal.inc"
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "c128.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-12-19 22:53:13 +00:00
|
|
|
;--------------------------------------------------------------------------
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
_cgetc: lda KEY_COUNT ; Get number of characters
|
|
|
|
bne L2 ; Jump if there are already chars waiting
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-11-25 08:46:05 +00:00
|
|
|
; Switch on the cursor if needed. We MUST always switch the cursor on,
|
|
|
|
; before switching it off, because switching it off will restore the
|
2010-02-18 20:31:50 +00:00
|
|
|
; character attribute remembered when it was switched on. So just switching
|
|
|
|
; it off will restore the wrong character attribute.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-12-21 14:11:32 +00:00
|
|
|
jsr CURS_SET ; Set cursor to current position
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr CURS_ON
|
|
|
|
lda cursor
|
|
|
|
bne L1
|
|
|
|
lda #$01
|
|
|
|
jsr CURS_OFF
|
|
|
|
L1: lda KEY_COUNT ; Check characters again
|
|
|
|
beq L1
|
|
|
|
jsr CURS_OFF ; Switch cursor off, if characters available
|
|
|
|
|
|
|
|
L2: jsr KBDREAD ; Read char and return in A
|
2010-02-18 20:31:50 +00:00
|
|
|
ldx #0
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-12-19 22:53:13 +00:00
|
|
|
;--------------------------------------------------------------------------
|
|
|
|
; Module constructor/destructor
|
|
|
|
|
2016-03-16 15:28:32 +00:00
|
|
|
.segment "INIT"
|
2013-05-09 11:56:54 +00:00
|
|
|
keyvec: .res 2
|
2002-12-19 22:53:13 +00:00
|
|
|
|
2016-03-06 20:26:22 +00:00
|
|
|
.segment "ONCE"
|
2002-12-19 22:53:13 +00:00
|
|
|
initcgetc:
|
|
|
|
|
|
|
|
; Save the old vector
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda KeyStoreVec
|
2016-03-16 15:28:32 +00:00
|
|
|
ldx KeyStoreVec+1
|
2013-05-09 11:56:54 +00:00
|
|
|
sta keyvec
|
2016-03-16 15:28:32 +00:00
|
|
|
stx keyvec+1
|
2002-12-19 22:53:13 +00:00
|
|
|
|
|
|
|
; Set the new vector. I can only hope that this works for other C128
|
|
|
|
; versions...
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #<$C6B7
|
|
|
|
ldx #>$C6B7
|
2005-02-26 09:28:46 +00:00
|
|
|
jmp SetVec
|
2002-12-19 22:53:13 +00:00
|
|
|
|
2005-02-26 09:28:46 +00:00
|
|
|
.code
|
2002-12-19 22:53:13 +00:00
|
|
|
donecgetc:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda keyvec
|
|
|
|
ldx keyvec+1
|
|
|
|
SetVec: sei
|
|
|
|
sta KeyStoreVec
|
|
|
|
stx KeyStoreVec+1
|
|
|
|
cli
|
|
|
|
rts
|