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
|
|
|
|
.import cursor
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "plus4.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-11-23 19:21:05 +00:00
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
|
2002-11-22 22:24:24 +00:00
|
|
|
.segment "LOWCODE" ; Accesses the ROM - must go into low mem
|
2002-11-22 22:16:20 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
_cgetc: lda KEY_COUNT ; Get number of characters
|
|
|
|
ora FKEY_COUNT ; Or with number of function key chars
|
|
|
|
bne L2 ; Jump if there are already chars waiting
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Switch on the cursor if needed
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy CURS_X
|
|
|
|
lda (CRAM_PTR),y ; Get current char
|
|
|
|
pha ; And save it
|
|
|
|
lda CHARCOLOR
|
|
|
|
sta (CRAM_PTR),y
|
|
|
|
|
|
|
|
lda cursor
|
|
|
|
beq L1 ; Jump if no cursor
|
|
|
|
tya
|
|
|
|
clc
|
|
|
|
adc SCREEN_PTR
|
|
|
|
sta TED_CURSLO
|
|
|
|
lda SCREEN_PTR+1
|
|
|
|
adc #$00
|
|
|
|
sbc #$0B ; + carry = $C00 (screen address)
|
|
|
|
sta TED_CURSHI
|
|
|
|
|
|
|
|
L1: lda KEY_COUNT
|
|
|
|
ora FKEY_COUNT
|
|
|
|
beq L1
|
|
|
|
pla
|
|
|
|
sta (CRAM_PTR),y
|
|
|
|
lda #$ff
|
|
|
|
sta TED_CURSLO ; Cursor off
|
|
|
|
sta TED_CURSHI
|
|
|
|
|
|
|
|
L2: sta ENABLE_ROM ; Bank in the ROM
|
|
|
|
jsr KBDREAD ; Read char and return in A (ROM routine)
|
2002-11-22 22:16:20 +00:00
|
|
|
sta ENABLE_RAM ; Reenable the RAM
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #0
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-11-23 19:21:05 +00:00
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
; Make the function keys return function key codes instead of the current
|
|
|
|
; strings so the program will see and may handle them.
|
|
|
|
; Undo this change when the program ends
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.constructor initkbd
|
|
|
|
.destructor donekbd
|
2000-11-23 19:21:05 +00:00
|
|
|
|
2005-02-26 09:28:46 +00:00
|
|
|
.segment "INIT" ; Special init code segment may get overwritten
|
2002-11-22 22:16:20 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc initkbd
|
2000-11-23 19:21:05 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #15
|
|
|
|
@L1: lda fnkeys,y
|
|
|
|
sta FKEY_SPACE,y
|
|
|
|
dey
|
|
|
|
bpl @L1
|
|
|
|
rts
|
2000-11-23 19:21:05 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
2002-11-22 22:24:24 +00:00
|
|
|
.segment "LOWCODE" ; Accesses the ROM - must go into low mem
|
2002-11-22 22:16:20 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc donekbd
|
2000-11-23 19:21:05 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #$39 ; Copy the original function keys
|
2002-11-22 22:16:20 +00:00
|
|
|
sta ENABLE_ROM ; Bank in the ROM
|
2013-05-09 11:56:54 +00:00
|
|
|
@L1: lda FKEY_ORIG,x
|
|
|
|
sta FKEY_SPACE,x
|
|
|
|
dex
|
|
|
|
bpl @L1
|
2002-11-22 22:16:20 +00:00
|
|
|
sta ENABLE_RAM ; Bank out the ROM
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2000-11-23 19:21:05 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
|
|
|
; Function key table, readonly
|
|
|
|
|
|
|
|
.rodata
|
2013-05-09 11:56:54 +00:00
|
|
|
fnkeys: .byte $01, $01, $01, $01, $01, $01, $01, $01
|
|
|
|
.byte 133, 137, 134, 138, 135, 139, 136, 140
|
2000-11-23 19:21:05 +00:00
|
|
|
|