From 39f83b7709e9a72b1d46122adb5e1bd27e31fd03 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 9 Aug 2017 21:27:21 +0200 Subject: [PATCH 1/3] 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 From 463904988bef0825134bc85d000dfe4f16cc8791 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 9 Aug 2017 21:50:23 +0200 Subject: [PATCH 2/3] Use symbols instead of hard coded constants for screen dimensions MkII. --- drivers/a2vt100.s | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/a2vt100.s b/drivers/a2vt100.s index 7d92e40..cce324e 100644 --- a/drivers/a2vt100.s +++ b/drivers/a2vt100.s @@ -1249,7 +1249,7 @@ DEL2 ; first col ldx CV beq DELee ; odd: top left corner dex - ldy #79 + ldy #Cols-1 jsr Plot ldy CH @@ -1316,14 +1316,14 @@ US1 ; -- new line: -- jsr SLV ; -- copy even col chars -- bit $c055 - ldy #$27 ; even col 39 + ldy #Cols/2-1 ; even col 39 US2 lda (xVector),y ; copy char sta (zVector),y dey bpl US2 ; -- copy odd col chars -- bit $c054 - ldy #$27 ; odd col 39 + ldy #Cols/2-1 ; odd col 39 US3 lda (xVector),y ; copy char sta (zVector),y dey @@ -1370,14 +1370,14 @@ DS1 ; -- new line: -- jsr SLV ; -- copy even col chars -- bit $c055 - ldy #$27 ; even col 39 + ldy #Cols/2-1 ; even col 39 DS2 lda (xVector),y ; copy char sta (zVector),y dey bpl DS2 ; -- copy odd col chars -- bit $c054 - ldy #$27 ; odd col 39 + ldy #Cols/2-1 ; odd col 39 DS3 lda (xVector),y ; copy char sta (zVector),y dey @@ -1451,7 +1451,7 @@ ErLn jsr SLV ; line start in xVector ; -- erase even col chars -- ErLn_ bit $c055 - ldy #$27 ; even col 39 + ldy #Cols/2-1 ; even col 39 lda #$20|$80 ; load space EL1 sta (xVector),y ; clear char dey @@ -1459,7 +1459,7 @@ EL1 sta (xVector),y ; clear char ; -- erase odd col chars -- bit $c054 - ldy #$27 ; odd col 39 + ldy #Cols/2-1 ; odd col 39 EL2 sta (xVector),y ; clear char dey bpl EL2 @@ -1485,7 +1485,7 @@ ErEnLn bcs EEL2 ; odd crsr col EEL1 sta (BASL),y ; clear char EEL2 iny - cpy #$28 ; even pos 40? + cpy #Cols/2 ; even pos 40? bne EEL1 ; next char ; -- erase odd col chars -- @@ -1493,7 +1493,7 @@ EEL2 iny ldy tmp1 ; restore start EEL3 sta (BASL),y ; clear char iny - cpy #$28 ; odd pos 40? + cpy #Cols/2 ; odd pos 40? bne EEL3 ; next char sta sCrsrChar ; del char .. From 3541c20ba23eab75a6dc3bb0ff515c5418c5f4b2 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sat, 12 Aug 2017 17:02:56 +0200 Subject: [PATCH 3/3] Fixed sequence number of initial TCP ACK packet on tcp_connect. So far the sequence number for the first packet after the initial SYN packet was calculated directly before returning from tcp_connect. This is however far to late as the ACK packet to be send as response for the SYN,ACK packet sent by the server already needs that sequence number. Therefore it is now calculated right after a successful reception of the SYN,ACK packet is detected. --- ip65/tcp.s | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/ip65/tcp.s b/ip65/tcp.s index 89b2d5e..3b3dfa1 100644 --- a/ip65/tcp.s +++ b/ip65/tcp.s @@ -185,7 +185,20 @@ tcp_listen: cmp tcp_state beq @listen_loop - jmp tcp_connection_established +tcp_connection_established: + ; inc the sequence number to cover the SYN we have sent + ldax #tcp_connect_sequence_number + stax acc32 + ldax #$01 + jsr add_16_32 + +set_expected_ack: + ; set the expected ack number with current seq number + ldx #3 +: lda tcp_connect_sequence_number,x + sta tcp_connect_expected_ack_number,x + dex + bpl :- rts ; make outbound tcp connection @@ -278,20 +291,6 @@ tcp_connect: sec ; if we got here, then the other side sent a RST or FIN, so signal an error to the caller rts @was_accepted: -tcp_connection_established: - ; inc the sequence number to cover the SYN we have sent - ldax #tcp_connect_sequence_number - stax acc32 - ldax #$01 - jsr add_16_32 - -set_expected_ack: - ; set the expected ack number with current seq number - ldx #3 -: lda tcp_connect_sequence_number,x - sta tcp_connect_expected_ack_number,x - dex - bpl :- clc rts @@ -726,6 +725,8 @@ tcp_process: ldax #$0001 jsr add_16_32 ; increment the ACK counter by 1, for the SYN we just received + jsr tcp_connection_established + lda #tcp_cxn_state_established sta tcp_state