From 3e8704fe77f88cddb27bc131d058e48015df6eff Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Wed, 9 Aug 2017 21:27:21 +0200
Subject: [PATCH] Allow Telnet65 to send ASCII code 0 - on the Apple II.
Chris made me aware that ASCII code 0 actually is a valid character (usually entered as Ctrl-Space or Ctrl-@) and that it is actually used (i.e. by EMACS).
The Apple II allows to natively enter the ASCII code 0 via Ctrl-@. However so far get_key_if_available returned 0 in accumulator to signal that no key was pressed. In order to allow the Apple II get_key_if_available to return the ASCII code 0 in the accumulator I changed it to use the carry flag to signal that no key was pressed.
Because get_key_if_available needs of course to behave the same on all targets I changed the other implementations to use the carry flag too.
Unfortunately I don't know enough about input capabilities of the C64 to decide on how to best get Telnet65 to send ASCII code 0 there.
---
apps/telnet65.s | 2 +-
drivers/a2input.s | 8 +++++---
drivers/a2vt100.s | 5 +++--
drivers/atrinput.s | 22 +++++++++++-----------
drivers/c64input.s | 19 ++++++++++++-------
drivers/vic20input.s | 21 +++++++++++++--------
6 files changed, 45 insertions(+), 32 deletions(-)
diff --git a/apps/telnet65.s b/apps/telnet65.s
index 1484931..938023d 100644
--- a/apps/telnet65.s
+++ b/apps/telnet65.s
@@ -228,7 +228,7 @@ telnet_main_entry:
ldax #iac_response_buffer
jsr tcp_send
: jsr get_key_if_available
- beq @check_timeout
+ bcc @check_timeout
ldx #0
stx tcp_send_data_len
stx tcp_send_data_len+1
diff --git a/drivers/a2input.s b/drivers/a2input.s
index 6ed4a78..f0897ab 100644
--- a/drivers/a2input.s
+++ b/drivers/a2input.s
@@ -18,15 +18,17 @@ abort_key: .byte $9b ; ESC
; use Apple 2 monitor ROM function to read from keyboard
; inputs: none
-; outputs: A contains ASCII code of key pressed
+; outputs: A contains ASCII value of key just pressed
get_key = $fd0c
; inputs: none
-; outputs: A contains ASCII value of key just pressed (0 if no key pressed)
+; outputs: sec if key pressed, clear otherwise
+; A contains ASCII value of key just pressed
get_key_if_available:
+ sec
lda $c000 ; current key pressed
bmi got_key
- lda #0
+ clc
rts
; process inbound ip packets while waiting for a keypress
diff --git a/drivers/a2vt100.s b/drivers/a2vt100.s
index ce47802..7d92e40 100644
--- a/drivers/a2vt100.s
+++ b/drivers/a2vt100.s
@@ -879,6 +879,7 @@ aDDigE rts
ProcOut
lda kta,y ; keyboard to ASCII
+ cmp #$ff
beq POrts ; ignore key
cmp #$fe
beq CmdKey ; command key
@@ -1710,7 +1711,7 @@ ltsc;_0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f
; input for sending over the serial
; line.
;
-; ascii = $00 means ignore key
+; ascii = $ff means ignore key
; ascii = $fe means do something
; complicated (command key)
; -------------------------------------
@@ -1719,7 +1720,7 @@ kta ;_0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f
; --- Control chars ------------------------------------------------
; {←} {↓} {↑}
-; ^A ^B ^C ^D ^E ^F ^G ^H ^I ^J ^K ^L ^M ^N ^O
+; ^@ ^A ^B ^C ^D ^E ^F ^G ^H ^I ^J ^K ^L ^M ^N ^O
.byt $00,$01,$02,$03,$04,$05,$06,$07,$fe,$09,$fe,$fe,$0c,$0d,$0e,$0f ; 0_
; {→}
; ^P ^Q ^R ^S ^T ^U ^V ^W ^X ^Y ^Z ^[ ^\ ^] ^^ ^_
diff --git a/drivers/atrinput.s b/drivers/atrinput.s
index ca41dd1..0d7e2e1 100644
--- a/drivers/atrinput.s
+++ b/drivers/atrinput.s
@@ -24,15 +24,16 @@ kname: .byte "K:",155
; outputs: A contains ASCII value of key just pressed
get_key:
jsr get_key_if_available
- beq get_key
+ bcc get_key
rts
; inputs: none
-; outputs: A contains ASCII value of key just pressed (0 if no key pressed)
+; outputs: sec if key pressed, clear otherwise
+; A contains ASCII value of key just pressed
get_key_if_available:
lda CH ; GLOBAL VARIABLE FOR KEYBOARD
cmp #255
- beq @nokey
+ beq no_key
ldx iocb ; K: already open?
bne @read
ldx #$40 ; IOCB to use for keyboard input
@@ -55,16 +56,14 @@ get_key_if_available:
jsr CIOV ; vector to CIO
ldx #255
stx CH ; GLOBAL VARIABLE FOR KEYBOARD
- rts
-@nokey:
- lda #0
+ sec
rts
; process inbound ip packets while waiting for a keypress
get_key_ip65:
jsr ip65_process
jsr get_key_if_available
- beq get_key_ip65
+ bcc get_key_ip65
rts
;check whether the abort key is being pressed
@@ -72,6 +71,7 @@ get_key_ip65:
;outputs: sec if abort key pressed, clear otherwise
check_for_abort_key:
; TODO: implement actual check
+no_key:
clc
rts
@@ -82,16 +82,16 @@ check_for_abort_key:
; Version 1.1 (the "License"); you may not use this file except in
; compliance with the License. You may obtain a copy of the License at
; http://www.mozilla.org/MPL/
-;
+;
; Software distributed under the License is distributed on an "AS IS"
; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
; License for the specific language governing rights and limitations
; under the License.
-;
+;
; The Original Code is ip65.
-;
+;
; The Initial Developer of the Original Code is Jonno Downes,
; jonno@jamtronix.com.
; Portions created by the Initial Developer are Copyright (C) 2009
-; Jonno Downes. All Rights Reserved.
+; Jonno Downes. All Rights Reserved.
; -- LICENSE END --
diff --git a/drivers/c64input.s b/drivers/c64input.s
index 95c3642..72c8a3b 100644
--- a/drivers/c64input.s
+++ b/drivers/c64input.s
@@ -24,21 +24,26 @@ get_key:
sty $cc ; cursor on
@loop:
jsr get_key_if_available
- beq @loop
+ bcc @loop
ldy #1
sty $cc ; cursor off
rts
; use C64 Kernel ROM function to read a key
; inputs: none
-; outputs: A contains ASCII value of key just pressed (0 if no key pressed)
-get_key_if_available = $f142 ; not officially documented - where F13E (GETIN) falls through to if device # is 0 (KEYBD)
+; outputs: sec if key pressed, clear otherwise
+; A contains ASCII value of key just pressed
+get_key_if_available:
+ jsr $f142 ; not officially documented - where F13E (GETIN) falls through to if device # is 0 (KEYBD)
+ beq no_key
+ sec
+ rts
; process inbound ip packets while waiting for a keypress
get_key_ip65:
jsr ip65_process
jsr get_key_if_available
- beq get_key_ip65
+ bcc get_key_ip65
rts
; check whether the abort key is being pressed
@@ -47,16 +52,16 @@ get_key_ip65:
check_for_abort_key:
lda $cb ; current key pressed
cmp abort_key
- bne @not_abort
+ bne no_key
@flush_loop:
jsr get_key_if_available
- bne @flush_loop
+ bcs @flush_loop
lda $cb ; current key pressed
cmp abort_key
beq @flush_loop
sec
rts
-@not_abort:
+no_key:
clc
rts
diff --git a/drivers/vic20input.s b/drivers/vic20input.s
index 7d9fdd3..6c84d9d 100644
--- a/drivers/vic20input.s
+++ b/drivers/vic20input.s
@@ -16,7 +16,7 @@ abort_key: .byte $18 ; RUN/STOP
.code
-; use Vic 20 Kernel ROM function to read a key
+; use VIC 20 Kernel ROM function to read a key
; inputs: none
; outputs: A contains ASCII value of key just pressed
get_key:
@@ -24,21 +24,26 @@ get_key:
sty $cc ; cursor on
@loop:
jsr get_key_if_available
- beq @loop
+ bcc @loop
ldy #1
sty $cc ; cursor off
rts
; use VIC 20 Kernel ROM function to read a key
; inputs: none
-; outputs: A contains ASCII value of key just pressed (0 if no key pressed)
-get_key_if_available = $f1f9 ; not officially documented - where F1f5 (GETIN) falls through to if device # is 0 (KEYBD)
+; outputs: sec if key pressed, clear otherwise
+; A contains ASCII value of key just pressed
+get_key_if_available:
+ jsr $f1f9 ; not officially documented - where F1F5 (GETIN) falls through to if device # is 0 (KEYBD)
+ beq no_key
+ sec
+ rts
; process inbound ip packets while waiting for a keypress
get_key_ip65:
jsr ip65_process
jsr get_key_if_available
- beq get_key_ip65
+ bcc get_key_ip65
rts
; check whether the abort key is being pressed
@@ -47,16 +52,16 @@ get_key_ip65:
check_for_abort_key:
lda $cb ; current key pressed
cmp abort_key
- bne @not_abort
+ bne no_key
@flush_loop:
jsr get_key_if_available
- bne @flush_loop
+ bcs @flush_loop
lda $cb ; current key pressed
cmp abort_key
beq @flush_loop
sec
rts
-@not_abort:
+no_key:
clc
rts