From 406f66d64863bffe704d671ac20bff963a67c2d4 Mon Sep 17 00:00:00 2001 From: jonnosan Date: Sun, 20 Dec 2009 08:24:10 +0000 Subject: [PATCH] added xmodem_iac_escape variable which controls whether $FF is escaped in tcp stream handed to xmodem (i.e. if remote end is a real telnet server, not raw RS232<->TCP stream) git-svn-id: http://svn.code.sf.net/p/netboot65/code@229 93682198-c243-4bdb-bd91-e943c89aac3b --- client/carts/kipperterm.s | 4 +++- client/inc/telnet.i | 9 ++++++++ client/ip65/xmodem.s | 44 ++++++++++++++++++++++++++++++++++++--- client/test/test_xmodem.s | 17 +++++++++------ 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/client/carts/kipperterm.s b/client/carts/kipperterm.s index 59b1bdc..fa4c0a6 100644 --- a/client/carts/kipperterm.s +++ b/client/carts/kipperterm.s @@ -15,7 +15,10 @@ KEY_BACK_IN_HISTORY=KEYCODE_F3 KEY_NEW_SERVER=KEYCODE_F5 + XMODEM_IN_TELNET = 1 + .import xmodem_iac_escape + .include "../inc/telnet.i" .import cls @@ -285,7 +288,6 @@ telnet_menu: jsr setup_screen jsr cls - ldax #menu_header_msg jsr print_ascii_as_native ldax #telnet_menu_msg diff --git a/client/inc/telnet.i b/client/inc/telnet.i index 56e32bd..33ba95d 100644 --- a/client/inc/telnet.i +++ b/client/inc/telnet.i @@ -95,6 +95,9 @@ telnet_main_entry: sta telnet_line_mode lda #1 sta telnet_local_echo +.ifdef XMODEM_IN_TELNET + sta xmodem_iac_escape +.endif jmp @after_mode_set @petscii_mode: lda #1 @@ -102,10 +105,16 @@ telnet_main_entry: lda #0 sta telnet_local_echo sta telnet_line_mode +.ifdef XMODEM_IN_TELNET + sta xmodem_iac_escape +.endif jmp @after_mode_set @line_mode: lda #0 sta telnet_use_native_charset +.ifdef XMODEM_IN_TELNET + sta xmodem_iac_escape +.endif lda #1 sta telnet_local_echo sta telnet_line_mode diff --git a/client/ip65/xmodem.s b/client/ip65/xmodem.s index b9722bc..fb91902 100644 --- a/client/ip65/xmodem.s +++ b/client/ip65/xmodem.s @@ -18,6 +18,8 @@ CAN = $18 .export xmodem_receive +.export xmodem_iac_escape ;are IAC bytes ($FF) escaped? + .import ip65_process .import ip65_error .import tcp_callback @@ -77,6 +79,7 @@ xmodem_receive: ;recieve a file via XMODEM (checksum mode only, not CRC) ;assumes that a tcp connection has already been set up, and that the other end is waiting to start sending ;inputs: AX points to routine to call once for each byte in downloaded file (e.g. save to disk, print to screen, whatever) - byte will be in A +; xmodem_iac_escape should be set to non-zero if the remote end escapes $FF bytes (i.e. if it is a real telnet server) ;outputs: none @@ -172,7 +175,9 @@ xmodem_receive: @next_byte: lda #XMODEM_TIMEOUT_SECONDS jsr getc - bcs @exit + bcc :+ + jmp @exit +: ldx block_ptr sta xmodem_block_buffer,x adc checksum @@ -200,6 +205,22 @@ xmodem_receive: lda received_checksum cmp checksum beq @checksum_ok + ;checksum error :-( + inc error_number + ldax #checksum_error_msg + jsr print_ascii_as_native + lda error_number + jsr print_hex + jsr print_cr + lda error_number + cmp #XMODEM_MAX_ERRORS + bcs :+ + jmp @wait_for_block_start +: + lda #KPR_ERROR_TOO_MANY_ERRORS + sta ip65_error + jmp @exit + jsr send_nak jmp @next_block @@ -264,6 +285,22 @@ send_ack: getc: + jsr @real_getc + bcc :+ ;of we got an error, then bail + rts +: + cmp #$ff + beq @got_ff + clc + rts +@got_ff: + lda xmodem_iac_escape + bne @real_getc ;need to skip over the $FF and go read another byte + lda #$ff + clc + rts + +@real_getc: sta getc_timeout_seconds clc @@ -279,7 +316,6 @@ getc: sta getc_timeout_end @poll_loop: -; inc $d021 jsr next_char bcs @no_char rts ;done! @@ -309,7 +345,8 @@ expecting: .byte "expecting",0 receiving: .byte "receiving",0 bad_block_number: .byte "bad block number",0 checksum_msg: .byte "checksum $",0 -timeout_msg: .byte "timeout $",0 +checksum_error_msg : .byte "checksum error - error count $",0 +timeout_msg: .byte "timeout error - error count $",0 .segment "APP_SCRATCH" xmodem_stream_buffer: .res 1600 @@ -321,6 +358,7 @@ received_checksum: .res 1 block_ptr: .res 1 error_number: .res 1 user_abort: .res 1 +xmodem_iac_escape: .res 1 ;-- LICENSE FOR xmodem.s -- ; The contents of this file are subject to the Mozilla Public License diff --git a/client/test/test_xmodem.s b/client/test/test_xmodem.s index 9968f05..9d74c93 100644 --- a/client/test/test_xmodem.s +++ b/client/test/test_xmodem.s @@ -2,8 +2,6 @@ .include "../inc/commonprint.i" .include "../inc/net.i" -; .include "../ip65/xmodem.s" - .import parse_dotted_quad .import dotted_quad_value @@ -18,7 +16,8 @@ .import tcp_inbound_data_ptr .import tcp_inbound_data_length -.import xmodem_receive + .import xmodem_receive + .import xmodem_iac_escape .import tcp_send .import tcp_send_data_len @@ -61,12 +60,18 @@ init: lda #14 jsr print_a ;switch to lower case + + lda #1 +; lda #0 + sta xmodem_iac_escape lda #0 sta $dc08 ;set deciseconds - starts TOD going jsr print_cr init_ip_via_dhcp jsr print_ip_config + ldax #starting + jsr print_ascii_as_native jsr print_cr lda #'1' @@ -175,8 +180,6 @@ open_file: jsr $FFC0 ; call OPEN bcs @error ; if carry set, the file could not be opened - ldx #$02 ; filenumber 2 - jsr $FFC9 ; call CHKOUT (file 2 now used as output) rts @error: sta ip65_error @@ -215,6 +218,8 @@ close_file: .rodata +starting: +.byte "saving to " fname: .byte "@0:XMODEM.TMP,P,W" ; @0: means 'overwrite if existing', ',P,W' is required to make this an output file fname_end: .byte 0 @@ -222,7 +227,7 @@ first_message: .byte "yo!",0 start_download: - .byte "R",0 + .byte "B",0 ;b=Binary, i.e. trigger IAC escape, R=receive text, i.e. no IAC escape .data tcp_dest_ip: