Character input loop enables IRQs

Character input loop enables IRQs.
Fixed bug where cursor keys all returned TAB if *FX4,2 active.
This commit is contained in:
jgharston 2022-10-16 00:54:55 +01:00 committed by GitHub
parent 480576693a
commit 7112146a0d

View File

@ -1,5 +1,5 @@
* AUXMEM.CHARIO.S
* (c) Bobbi 2021 GPLv3
* (c) Bobbi 2021,2022 GPLv3
*
* AppleMOS Character I/O
@ -27,10 +27,17 @@
* 12-Sep-2021 COPY calls new VDU entry point.
* 15-Sep-2021 INKEY(0) tests once and returns immediately.
* 30-Nov-2021 With *FX4,<>0 TAB returns $09, allows eg VIEW to work.
* 13-Sep-2022 Fix bug in INKEY with misbalanced stack when Escape pressed
* TO DO: CHKESC should go through translations before testing.
* 15-Oct-2022 Replace calling KBDCHKESC with ESCPOLL, does translations, etc.
* Fixed bug with cursor keys after *FX4,2. OSRDCH enables IRQs.
* Hardware locations
KBDDATA EQU $C000 ; Read Keyboard data
KBDACK EQU $C010 ; Acknowledge keyboard data
KBDAPPLFT EQU $C061 ; Left Apple key
KBDAPPRGT EQU $C062 ; Right Apple key
IOVBLNK EQU $C019 ; VBLNK pulse
FLASHER EQU BYTEVARBASE+176 ; VSync counter for flashing cursor
FXEXEC EQU BYTEVARBASE+198
FXSPOOL EQU BYTEVARBASE+199
@ -56,23 +63,23 @@ WRCHHND PHA
PHX
PHY
PHA
JSR OUTCHAR
* TO DO Check any output redirections
* TO DO Check any printer output
* BCC WRCHHND3
* PLA
JSR OUTCHAR ; Send to VDU driver
* BCC WRCHHND3 ; VDU driver says skip printer
* PLA ; Get character back
* PHA
* JSR PRNCHAR
* JSR PRNCHAR ; Send to printer
* WRCHHND3
* Check FX3VAR
* Bxx WRCHHND4 ; Spool disabled
LDY FXSPOOL ; See if *SPOOL is in effect
BEQ WRCHHND4
BEQ WRCHHND4 ; No, skip sending to spool file
PLA
PHA
JSR OSBPUT ; Write char to spool file
WRCHHND4 PLA
PLY
JSR OSBPUT ; Write character to spool file
WRCHHND4 PLA ; Drop stacked character
PLY ; Restore everything
PLX
PLA
RTS
@ -102,10 +109,10 @@ KBDINIT LDX #DEFBYTEEND-DEFBYTE-1
BPL :KBDINITLP
LDX #$C0
STX FX254VAR ; b7-b4=default KBD map, b3-b0=default MODE
BIT SETV
JSR KBDTEST
BIT SETV ; Set V
JSR KBDTEST ; Test if key being pressed
BCS :KBDINITOK ; Return default MODE=0
STA KBDSTRB ; Ack. keypress
STA KBDACK ; Ack. keypress
TAX ; Use keypress as default MODE
:KBDINITOK TXA
RTS
@ -115,6 +122,7 @@ KBDINIT LDX #DEFBYTEEND-DEFBYTE-1
* Read a character from current input
* All registers preserved except A, Carry
* Flashes a soft cursor while waiting for input
* *NB* OSRDCH returns with IRQs enabled, INKEY returns with IRQs preserved
*
RDCHHND LDA #$80 ; flag=wait forever
PHY
@ -123,7 +131,8 @@ RDCHHND LDA #$80 ; flag=wait forever
* XY<$8000 - wait for a keypress
INKEY PHY ; Dummy PHY to balance RDCH
INKEYGO PHX ; Save registers
INKEYGO CLI ; Enable IRQs
PHX ; Save registers
PHY
BIT VDUSTATUS ; Enable editing cursor
BVC INKEYGO2 ; No editing cursor
@ -169,17 +178,16 @@ INKEY5 DEX
INKEY6 PHY
*
* VBLK pulses at 50Hz/60Hz, toggles at 100Hz/120Hz
LDX RDVBL ; Get initial VBLK state
INKEY8 BIT KEYBOARD
LDX IOVBLNK ; Get initial VBLK state
INKEY8 BIT KBDDATA
BMI INKEY4 ; Key pressed
TXA
EOR RDVBL
EOR IOVBLNK
BPL INKEY8 ; Wait for VBLK change
BMI INKEYLP ; Loop back to key test
INKEYOUT PLA ; Drop stacked Y
LDA #$FF ; Prepare to stack $FF
*
INKEYOK PHA ; Save key or timeout
PHP ; Save CC=key, CS=timeout
LDA OLDCHAR ; Prepare for main cursor
@ -226,11 +234,7 @@ BYTE81DONE RTS
NEGINKEY CPX #$01
LDX #$00 ; Unimplemented
BCS NEGINKEY0
JSR NEGCALL ; Read machine ID from aux
TAX ; *TEST*
BIT $E0 ; *TEST*
BVS NEGINKEY1 ; *TEST*
JSR NEGCALL ; Read machine ID from mainmem
LDX #$2C
TAY
BEQ NEGINKEY0 ; $00 = Apple IIc -> INKEY-256 = $2C
@ -256,15 +260,14 @@ NEGCALL >>> XF2MAIN,MACHRD ; Try to read Machine ID
* On exit, CS=no keypress
* CC=keypress
* A =keycode, X,Y=corrupted
KEYREAD LDY FXEXEC ; See if *EXEC file is open
BEQ KEYREAD1
JSR OSBGET ; Read keypress from file
BCC KEYREADOK
LDA #0 ; EOF, close *EXEC file
STA FXEXEC
JSR OSFIND
KEYREAD LDY FXEXEC ; See if EXEC file is open
BEQ KEYREAD1 ; No, skip past
JSR OSBGET ; Read character from file
BCC KEYREADOK ; Not EOF, return it
LDA #$00 ; EOF, close EXEC file
STA FXEXEC ; Clear EXEC handle
JSR OSFIND ; And close it
KEYREAD1
*
* TO DO: expand current soft key
* LDA SOFTKEYLEN
@ -279,31 +282,30 @@ KEYREAD1
*
JSR KBDREAD ; Fetch character from KBD "buffer"
BCS KEYREADOK ; Nothing pending
TAY
TAY ; Y=unmodified character
BPL KEYREADOK ; Not top-bit key
AND #$CF
AND #$CF ; Drop Shift/Ctrl bits
CMP #$C9
BCC KEYSOFT ; Not cursor key
BCC KEYSOFTY ; Not cursor key
LDX FX4VAR
BEQ KEYCURSOR ; *FX4,0 - editing keys
LDY FXTABCHAR
CMP #$C9
BEQ KEYREADOKY ; TAB key
CPY #$C9
CLV
BEQ KEYCOPYTAB ; TAB key
DEX
BNE KEYSOFT1 ; Not *FX4,1 - soft key
BNE KEYSOFTHI ; Not *FX4,1 - soft key
SBC #$44 ; Return $88-$8B
TAY
KEYREADOKY TYA
KEYREADOK1 CLC
KEYREADOK RTS
*
* Process soft key
KEYSOFT1 LDX FX254VAR
KEYSOFTHI LDX FX254VAR
CPX #$C0
BCC KEYSOFT
BCC KEYSOFTY
TYA
AND #$BF
TAY
KEYSOFT TYA
KEYSOFTY TYA ; Get key including Shift/Ctrl
LSR A
LSR A
LSR A
@ -337,8 +339,8 @@ KEYCURSOR CMP #$C9
KEYNONE SEC
RTS
KEYCOPY LDA FXTABCHAR ; Prepare TAB if no copy cursor
BIT VDUSTATUS
KEYCOPY BIT VDUSTATUS
KEYCOPYTAB LDA FXTABCHAR ; Prepare TAB if no copy cursor
BVC KEYREADOK1 ; No copy cursor, return TAB
LDA OLDCHAR ; Get the char under cursor
PHA
@ -364,15 +366,15 @@ KEYCOPY LDA FXTABCHAR ; Prepare TAB if no copy cursor
* Cursors -> $CC-$CF
*
KBDREAD CLV ; VC=return keypress
KBDTEST LDA KEYBOARD ; VS here to test for keypress
KBDTEST LDA KBDDATA ; VS here to test for keypress
EOR #$80 ; Toggle bit 7
CMP #$80
BCS KBDDONE ; No key pressed
BVS KBDDONE ; VS=test for keypress
STA KBDSTRB ; Ack. keypress
BIT BUTTON0
STA KBDACK ; Ack. keypress
KBDREAD2 BIT KBDAPPLFT
BMI KBDLALT ; Left Apple pressed
BIT BUTTON1
BIT KBDAPPRGT
BMI KBDRALT ; Right Apple pressed
CMP #$09
BEQ KBDTAB ; TAB is dual action TAB/COPY
@ -398,17 +400,17 @@ KBDLALT CMP #$40 ; Left Apple key pressed
BCS KBDCHKESC ; >'9'
KBDFUNC AND #$0F ; Convert Apple-Num to function key
ORA #$80
BIT BUTTON1
KBDFUNC2 BIT KBDAPPRGT
BPL KBDCHKESC ; Left+Digit -> $8x
ORA #$90 ; Right+Digit -> $9x
BIT BUTTON0
BIT KBDAPPLFT
BPL KBDCHKESC
EOR #$30 ; Left+Right+Digit -> $Ax
BRA KBDCHKESC
KBDCTRL AND #$1F ; Apple-Letter -> Ctrl-Letter
*
* Test for Escape key
* Test for Escape character
KBDCHKESC TAX ; X=keycode
EOR FXESCCHAR ; Current ESCAPE char?
ORA FXESCON ; Is ESCAPE an ASCII char?