2013-12-27 13:57:56 +00:00
|
|
|
; minimal telnet implementation (dumb terminal emulation only)
|
2017-05-18 22:12:42 +00:00
|
|
|
|
2018-02-23 15:36:05 +00:00
|
|
|
.include "../inc/common.inc"
|
|
|
|
.include "../inc/commonprint.inc"
|
|
|
|
.include "../inc/net.inc"
|
|
|
|
.include "../inc/error.inc"
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
.export start
|
|
|
|
|
2017-06-05 15:24:26 +00:00
|
|
|
.import abort_key
|
|
|
|
.importzp abort_key_default
|
|
|
|
.importzp abort_key_disable
|
2019-05-02 12:44:24 +00:00
|
|
|
.importzp eth_init_default
|
2017-05-18 22:12:42 +00:00
|
|
|
.import get_filtered_input
|
|
|
|
.import get_key
|
|
|
|
.import get_key_if_available
|
|
|
|
.import exit_to_basic
|
|
|
|
.import filter_dns
|
|
|
|
.import filter_number
|
|
|
|
.import dns_hostname_is_dotted_quad
|
|
|
|
.import dns_ip
|
|
|
|
.import dns_resolve
|
|
|
|
.import dns_set_hostname
|
|
|
|
.import ip65_process
|
|
|
|
.import native_to_ascii
|
|
|
|
.import parse_integer
|
|
|
|
.import print_cr
|
2013-12-27 13:57:56 +00:00
|
|
|
.import tcp_callback
|
2017-05-18 22:12:42 +00:00
|
|
|
.import tcp_close
|
|
|
|
.import tcp_connect
|
2013-12-27 13:57:56 +00:00
|
|
|
.import tcp_connect_ip
|
|
|
|
.import tcp_inbound_data_ptr
|
|
|
|
.import tcp_inbound_data_length
|
|
|
|
.import tcp_send
|
|
|
|
.import tcp_send_data_len
|
|
|
|
.import tcp_send_keep_alive
|
|
|
|
.import timer_read
|
2017-05-18 22:12:42 +00:00
|
|
|
.import vt100_init_terminal
|
|
|
|
.import vt100_exit_terminal
|
|
|
|
.import vt100_process_inbound_char
|
|
|
|
.import vt100_process_outbound_char
|
|
|
|
.importzp vt100_screen_cols
|
|
|
|
.importzp vt100_screen_rows
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
.export telnet_close
|
|
|
|
.export telnet_send_char
|
|
|
|
.export telnet_send_string
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
buffer_ptr = sreg
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
; keep LD65 happy
|
|
|
|
.segment "INIT"
|
|
|
|
.segment "ONCE"
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
.segment "STARTUP"
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2017-06-03 22:13:08 +00:00
|
|
|
jmp start
|
2019-05-02 12:44:24 +00:00
|
|
|
eth_init_value:
|
|
|
|
.byte eth_init_default
|
2017-06-03 22:13:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
start:
|
2013-12-13 21:24:03 +00:00
|
|
|
jsr vt100_init_terminal
|
2017-05-18 22:12:42 +00:00
|
|
|
|
|
|
|
; initialize stack
|
2017-06-02 17:00:22 +00:00
|
|
|
ldax #welcome_1
|
|
|
|
jsr print_vt100
|
|
|
|
ldax #welcome_2
|
|
|
|
jsr print_vt100
|
2017-05-18 22:12:42 +00:00
|
|
|
ldax #initializing
|
|
|
|
jsr print_ascii_as_native
|
2019-05-02 12:44:24 +00:00
|
|
|
lda eth_init_value
|
2017-05-18 22:12:42 +00:00
|
|
|
jsr ip65_init
|
|
|
|
bcc :+
|
|
|
|
ldax #device_not_found
|
|
|
|
jsr print_ascii_as_native
|
|
|
|
jmp error_exit
|
2019-05-02 12:44:24 +00:00
|
|
|
: ldax #eth_name
|
2017-05-18 22:12:42 +00:00
|
|
|
jsr print_ascii_as_native
|
2019-05-02 12:44:24 +00:00
|
|
|
jsr print_cr
|
2017-05-18 22:12:42 +00:00
|
|
|
|
|
|
|
; get IP addr
|
|
|
|
ldax #obtaining
|
|
|
|
jsr print_ascii_as_native
|
|
|
|
jsr dhcp_init
|
|
|
|
bcc :+
|
|
|
|
jsr print_error
|
|
|
|
jmp error_exit
|
|
|
|
: ldax #cfg_ip
|
|
|
|
jsr print_dotted_quad
|
|
|
|
jsr print_cr
|
|
|
|
|
|
|
|
telnet_main_entry:
|
|
|
|
; enter host name
|
|
|
|
ldax #remote_host
|
|
|
|
jsr print_ascii_as_native
|
|
|
|
ldy #40 ; max chars
|
|
|
|
ldax #filter_dns
|
|
|
|
jsr get_filtered_input
|
|
|
|
bcc :+
|
|
|
|
jmp exit
|
|
|
|
|
|
|
|
; set host name
|
|
|
|
: stax buffer_ptr
|
|
|
|
ldy #$ff
|
|
|
|
: iny
|
|
|
|
lda (buffer_ptr),y
|
|
|
|
jsr native_to_ascii
|
|
|
|
cmp #'a'
|
|
|
|
bcs :+
|
|
|
|
cmp #'A'
|
|
|
|
bcc :+
|
|
|
|
clc
|
|
|
|
adc #'a'-'A'
|
|
|
|
: sta (buffer_ptr),y
|
|
|
|
tax ; set Z flag
|
|
|
|
bne :--
|
|
|
|
ldax buffer_ptr
|
|
|
|
jsr dns_set_hostname
|
|
|
|
bcc :+
|
|
|
|
jsr print_error
|
|
|
|
jmp telnet_main_entry
|
|
|
|
|
|
|
|
; resolve host name
|
|
|
|
: lda dns_hostname_is_dotted_quad
|
|
|
|
bne :++
|
|
|
|
ldax #resolving
|
|
|
|
jsr print_ascii_as_native
|
|
|
|
jsr dns_resolve
|
|
|
|
bcc :+
|
|
|
|
jsr print_error
|
|
|
|
jmp telnet_main_entry
|
|
|
|
: ldax #dns_ip
|
|
|
|
jsr print_dotted_quad
|
|
|
|
|
|
|
|
; enter port
|
|
|
|
: ldax #remote_port
|
|
|
|
jsr print_ascii_as_native
|
|
|
|
ldy #5 ; max chars
|
|
|
|
ldax #filter_number
|
|
|
|
jsr get_filtered_input
|
|
|
|
bcs :+ ; empty -> default
|
|
|
|
jsr parse_integer
|
|
|
|
bcc :++
|
|
|
|
jmp telnet_main_entry
|
|
|
|
: ldax #23 ; default
|
|
|
|
: stax telnet_port
|
|
|
|
|
|
|
|
; connect
|
|
|
|
ldax #connecting
|
|
|
|
jsr print_ascii_as_native
|
|
|
|
ldax #dns_ip
|
|
|
|
jsr print_dotted_quad
|
2019-05-05 09:37:20 +00:00
|
|
|
lda #' '
|
|
|
|
jsr print_a
|
2017-05-18 22:12:42 +00:00
|
|
|
ldax #telnet_callback
|
2013-12-13 21:24:03 +00:00
|
|
|
stax tcp_callback
|
|
|
|
ldx #3
|
2017-05-18 22:12:42 +00:00
|
|
|
: lda dns_ip,x
|
2013-12-13 21:24:03 +00:00
|
|
|
sta tcp_connect_ip,x
|
2013-12-27 13:57:56 +00:00
|
|
|
dex
|
2017-05-18 22:12:42 +00:00
|
|
|
bpl :-
|
2013-12-13 21:24:03 +00:00
|
|
|
ldax telnet_port
|
|
|
|
jsr tcp_connect
|
2017-05-18 22:12:42 +00:00
|
|
|
bcc :+
|
|
|
|
jsr print_error
|
|
|
|
jmp telnet_main_entry
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
; connected
|
|
|
|
: ldax #ok
|
|
|
|
jsr print_ascii_as_native
|
2013-12-13 21:24:03 +00:00
|
|
|
lda #0
|
2017-05-18 22:12:42 +00:00
|
|
|
sta connection_close_requested
|
2013-12-13 21:24:03 +00:00
|
|
|
sta connection_closed
|
2017-05-21 20:39:10 +00:00
|
|
|
sta data_received
|
2013-12-27 13:57:56 +00:00
|
|
|
sta iac_response_buffer_length
|
2017-06-05 15:24:26 +00:00
|
|
|
lda #abort_key_disable
|
|
|
|
sta abort_key
|
2017-06-05 15:41:41 +00:00
|
|
|
ldax #on_connect
|
2017-05-18 22:12:42 +00:00
|
|
|
jsr print_vt100
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
@main_polling_loop:
|
2013-12-13 21:24:03 +00:00
|
|
|
jsr timer_read
|
2017-05-21 20:39:10 +00:00
|
|
|
txa ; 1/1000 * 256 = ~ 1/4 seconds
|
2017-05-18 22:12:42 +00:00
|
|
|
adc #$20 ; 32 x 1/4 = ~ 8 seconds
|
2013-12-13 21:24:03 +00:00
|
|
|
sta telnet_timeout
|
2017-05-21 20:39:10 +00:00
|
|
|
@check_timeout:
|
|
|
|
lda data_received
|
|
|
|
bne :+
|
2013-12-13 21:24:03 +00:00
|
|
|
jsr timer_read
|
|
|
|
cpx telnet_timeout
|
2017-05-18 22:12:42 +00:00
|
|
|
bne :+
|
2013-12-13 21:24:03 +00:00
|
|
|
jsr tcp_send_keep_alive
|
|
|
|
jmp @main_polling_loop
|
2017-05-21 20:39:10 +00:00
|
|
|
: lda #0
|
|
|
|
sta data_received
|
|
|
|
jsr ip65_process
|
2017-05-18 22:12:42 +00:00
|
|
|
lda connection_close_requested
|
|
|
|
beq :+
|
|
|
|
jsr tcp_close
|
|
|
|
jmp :++
|
|
|
|
: lda connection_closed
|
|
|
|
beq :++
|
2017-06-05 15:24:26 +00:00
|
|
|
: lda #abort_key_default
|
|
|
|
sta abort_key
|
2017-06-05 15:41:41 +00:00
|
|
|
ldax #on_disconnect
|
2017-05-18 22:12:42 +00:00
|
|
|
jsr print_vt100
|
2013-12-13 21:24:03 +00:00
|
|
|
ldax #disconnected
|
2017-05-18 22:12:42 +00:00
|
|
|
jsr print_ascii_as_native
|
|
|
|
jmp telnet_main_entry
|
|
|
|
: lda iac_response_buffer_length
|
|
|
|
beq :+
|
2013-12-13 21:24:03 +00:00
|
|
|
ldx #0
|
|
|
|
stax tcp_send_data_len
|
2013-12-27 13:57:56 +00:00
|
|
|
stx iac_response_buffer_length
|
|
|
|
ldax #iac_response_buffer
|
2013-12-13 21:24:03 +00:00
|
|
|
jsr tcp_send
|
2017-05-18 22:12:42 +00:00
|
|
|
: jsr get_key_if_available
|
2017-08-09 19:27:21 +00:00
|
|
|
bcc @check_timeout
|
2013-12-13 21:24:03 +00:00
|
|
|
ldx #0
|
|
|
|
stx tcp_send_data_len
|
|
|
|
stx tcp_send_data_len+1
|
2017-05-18 22:12:42 +00:00
|
|
|
tay
|
|
|
|
jsr vt100_process_outbound_char
|
|
|
|
jmp @main_polling_loop
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
print_vt100:
|
|
|
|
stax buffer_ptr
|
|
|
|
lda #0
|
|
|
|
sta buffer_offset
|
|
|
|
: ldy buffer_offset
|
|
|
|
lda (buffer_ptr),y
|
|
|
|
bne :+
|
|
|
|
rts
|
|
|
|
: tay
|
|
|
|
jsr vt100_process_inbound_char
|
|
|
|
inc buffer_offset
|
|
|
|
jmp :--
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
print_error:
|
|
|
|
lda ip65_error
|
2018-02-23 15:41:33 +00:00
|
|
|
cmp #IP65_ERROR_ABORTED_BY_USER
|
2013-12-27 13:57:56 +00:00
|
|
|
bne :+
|
2017-05-18 22:12:42 +00:00
|
|
|
ldax #abort
|
|
|
|
jmp print_ascii_as_native
|
2018-02-23 15:41:33 +00:00
|
|
|
: cmp #IP65_ERROR_TIMEOUT_ON_RECEIVE
|
2017-05-18 22:12:42 +00:00
|
|
|
bne :+
|
|
|
|
ldax #timeout
|
|
|
|
jmp print_ascii_as_native
|
|
|
|
: ldax #error_prefix
|
|
|
|
jsr print_ascii_as_native
|
|
|
|
lda ip65_error
|
|
|
|
jsr print_hex
|
|
|
|
jmp print_cr
|
|
|
|
|
|
|
|
error_exit:
|
|
|
|
ldax #press_a_key_to_continue
|
|
|
|
jsr print_ascii_as_native
|
|
|
|
jsr get_key
|
|
|
|
exit:
|
|
|
|
jsr vt100_exit_terminal
|
|
|
|
jmp exit_to_basic
|
|
|
|
|
|
|
|
|
|
|
|
; vt100 callback - will be executed when the user requests to close the connection
|
|
|
|
telnet_close:
|
|
|
|
lda #1
|
|
|
|
sta connection_close_requested
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
; vt100 callback - will be executed when sending a char string
|
|
|
|
telnet_send_string:
|
|
|
|
stx buffer_ptr
|
|
|
|
sty buffer_ptr+1
|
2013-12-27 13:57:56 +00:00
|
|
|
ldy #0
|
|
|
|
: lda (buffer_ptr),y
|
2017-05-18 22:12:42 +00:00
|
|
|
beq send_char
|
2013-12-13 21:24:03 +00:00
|
|
|
sta scratch_buffer,y
|
|
|
|
inc tcp_send_data_len
|
|
|
|
iny
|
2013-12-27 13:57:56 +00:00
|
|
|
bne :-
|
2017-05-18 22:12:42 +00:00
|
|
|
jmp send_char
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
|
|
|
|
; vt100 callback - will be executed when sending a single char
|
|
|
|
telnet_send_char:
|
2013-12-13 21:24:03 +00:00
|
|
|
ldy tcp_send_data_len
|
|
|
|
sta scratch_buffer,y
|
|
|
|
inc tcp_send_data_len
|
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
send_char:
|
2013-12-27 13:57:56 +00:00
|
|
|
ldax #scratch_buffer
|
2013-12-13 21:24:03 +00:00
|
|
|
jsr tcp_send
|
2017-05-18 22:12:42 +00:00
|
|
|
bcs :+
|
|
|
|
rts
|
2017-06-05 16:21:59 +00:00
|
|
|
: lda ip65_error
|
2018-02-23 15:41:33 +00:00
|
|
|
cmp #IP65_ERROR_CONNECTION_CLOSED
|
2017-06-05 16:21:59 +00:00
|
|
|
bne :+
|
|
|
|
lda #1
|
|
|
|
sta connection_closed
|
|
|
|
rts
|
2017-05-18 22:12:42 +00:00
|
|
|
: ldax #send_error
|
|
|
|
jsr print_ascii_as_native
|
|
|
|
jmp print_error
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; tcp callback - will be executed whenever data arrives on the TCP connection
|
2013-12-13 21:24:03 +00:00
|
|
|
telnet_callback:
|
|
|
|
lda #1
|
2017-05-21 20:39:10 +00:00
|
|
|
ldx tcp_inbound_data_length+1
|
|
|
|
cpx #$ff
|
|
|
|
bne :+
|
2013-12-13 21:24:03 +00:00
|
|
|
sta connection_closed
|
|
|
|
rts
|
2017-05-21 20:39:10 +00:00
|
|
|
: sta data_received
|
2013-12-13 21:24:03 +00:00
|
|
|
lda tcp_inbound_data_length
|
2017-05-21 20:39:10 +00:00
|
|
|
stax buffer_length
|
|
|
|
ldax tcp_inbound_data_ptr
|
|
|
|
stax buffer_ptr
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2013-12-13 21:24:03 +00:00
|
|
|
@next_byte:
|
|
|
|
ldy #0
|
|
|
|
lda (buffer_ptr),y
|
|
|
|
tax
|
2017-05-18 22:12:42 +00:00
|
|
|
; if we get here, we are in ASCII 'char at a time' mode,
|
|
|
|
; so look for (and process) Telnet style IAC bytes
|
|
|
|
lda telnet_state
|
2013-12-13 21:24:03 +00:00
|
|
|
cmp #telnet_state_got_command
|
|
|
|
bne :+
|
|
|
|
jmp @waiting_for_option
|
2013-12-27 13:57:56 +00:00
|
|
|
: cmp #telnet_state_got_iac
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @waiting_for_command
|
|
|
|
cmp #telnet_state_got_suboption
|
|
|
|
beq @waiting_for_suboption_end
|
2013-12-27 13:57:56 +00:00
|
|
|
; we must be in 'normal' mode
|
2013-12-13 21:24:03 +00:00
|
|
|
txa
|
|
|
|
cmp #255
|
|
|
|
beq :+
|
|
|
|
jmp @not_iac
|
2013-12-27 13:57:56 +00:00
|
|
|
: lda #telnet_state_got_iac
|
2013-12-13 21:24:03 +00:00
|
|
|
sta telnet_state
|
|
|
|
jmp @byte_processed
|
|
|
|
|
|
|
|
@waiting_for_suboption_end:
|
2013-12-27 13:57:56 +00:00
|
|
|
txa
|
|
|
|
ldx iac_suboption_buffer_length
|
2013-12-13 21:24:03 +00:00
|
|
|
sta iac_suboption_buffer,x
|
|
|
|
inc iac_suboption_buffer_length
|
2013-12-27 13:57:56 +00:00
|
|
|
cmp #$f0 ; SE - suboption end
|
2013-12-13 21:24:03 +00:00
|
|
|
bne @exit_suboption
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
lda #telnet_state_normal
|
2013-12-13 21:24:03 +00:00
|
|
|
sta telnet_state
|
|
|
|
lda iac_suboption_buffer
|
|
|
|
cmp #$18
|
|
|
|
bne @not_terminal_type
|
|
|
|
|
|
|
|
ldx #0
|
2013-12-27 13:57:56 +00:00
|
|
|
: lda terminal_type_response,x
|
2013-12-13 21:24:03 +00:00
|
|
|
ldy iac_response_buffer_length
|
|
|
|
inc iac_response_buffer_length
|
|
|
|
sta iac_response_buffer,y
|
2013-12-27 13:57:56 +00:00
|
|
|
inx
|
2013-12-13 21:24:03 +00:00
|
|
|
txa
|
|
|
|
cmp #terminal_type_response_length
|
|
|
|
bne :-
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
@not_terminal_type:
|
2013-12-13 21:24:03 +00:00
|
|
|
@exit_suboption:
|
|
|
|
jmp @byte_processed
|
|
|
|
@waiting_for_command:
|
|
|
|
txa
|
|
|
|
sta telnet_command
|
2013-12-27 13:57:56 +00:00
|
|
|
cmp #$fa ; SB - suboption begin
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @suboption
|
2013-12-27 13:57:56 +00:00
|
|
|
cmp #$fb ; WILL
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @option
|
2013-12-27 13:57:56 +00:00
|
|
|
cmp #$fc ; WONT
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @option
|
2013-12-27 13:57:56 +00:00
|
|
|
cmp #$fd ; DO
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @option
|
2013-12-27 13:57:56 +00:00
|
|
|
cmp #$fe ; DONT
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @option
|
2013-12-27 13:57:56 +00:00
|
|
|
; we got a command we don't understand - just ignore it
|
|
|
|
lda #telnet_state_normal
|
2013-12-13 21:24:03 +00:00
|
|
|
sta telnet_state
|
|
|
|
jmp @byte_processed
|
2017-05-18 22:12:42 +00:00
|
|
|
|
2013-12-13 21:24:03 +00:00
|
|
|
@suboption:
|
|
|
|
lda #telnet_state_got_suboption
|
|
|
|
sta telnet_state
|
|
|
|
lda #0
|
|
|
|
sta iac_suboption_buffer_length
|
|
|
|
jmp @byte_processed
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2013-12-13 21:24:03 +00:00
|
|
|
@option:
|
|
|
|
lda #telnet_state_got_command
|
|
|
|
sta telnet_state
|
|
|
|
jmp @byte_processed
|
|
|
|
|
|
|
|
@waiting_for_option:
|
2013-12-27 13:57:56 +00:00
|
|
|
; we have now got IAC, <command>, <option>
|
|
|
|
txa
|
|
|
|
sta telnet_option
|
2013-12-13 21:24:03 +00:00
|
|
|
lda telnet_command
|
|
|
|
cmp #$fb
|
|
|
|
beq @iac_will
|
|
|
|
cmp #$fc
|
|
|
|
beq @iac_wont
|
|
|
|
cmp #$fe
|
|
|
|
beq @iac_dont
|
2013-12-27 13:57:56 +00:00
|
|
|
; if we get here, then it's a "do"
|
2013-12-13 21:24:03 +00:00
|
|
|
lda telnet_option
|
2013-12-27 13:57:56 +00:00
|
|
|
cmp #$18 ; terminal type
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @do_terminaltype
|
|
|
|
cmp #$1f
|
|
|
|
beq @do_naws
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; if we get here, then it's a "do" command we don't honour
|
2013-12-13 21:24:03 +00:00
|
|
|
@iac_dont:
|
2013-12-27 13:57:56 +00:00
|
|
|
lda #$fc ; WONT
|
|
|
|
@add_iac_response:
|
2013-12-13 21:24:03 +00:00
|
|
|
ldx iac_response_buffer_length
|
|
|
|
sta iac_response_buffer+1,x
|
2017-05-18 22:12:42 +00:00
|
|
|
lda #$ff
|
2013-12-13 21:24:03 +00:00
|
|
|
sta iac_response_buffer,x
|
|
|
|
lda telnet_option
|
|
|
|
sta iac_response_buffer+2,x
|
|
|
|
inc iac_response_buffer_length
|
|
|
|
inc iac_response_buffer_length
|
|
|
|
inc iac_response_buffer_length
|
2013-12-27 13:57:56 +00:00
|
|
|
@after_set_iac_response:
|
2013-12-13 21:24:03 +00:00
|
|
|
lda #telnet_state_normal
|
|
|
|
sta telnet_state
|
|
|
|
jmp @byte_processed
|
|
|
|
@iac_will:
|
|
|
|
lda telnet_option
|
2017-05-18 22:12:42 +00:00
|
|
|
cmp #$01 ; ECHO
|
2013-12-27 13:57:56 +00:00
|
|
|
beq @will_echo
|
|
|
|
cmp #$03 ; DO SUPPRESS GA
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @will_suppress_ga
|
2013-12-27 13:57:56 +00:00
|
|
|
@iac_wont:
|
|
|
|
lda #$fe ; DONT
|
2013-12-13 21:24:03 +00:00
|
|
|
jmp @add_iac_response
|
|
|
|
@will_echo:
|
2013-12-27 13:57:56 +00:00
|
|
|
lda #$fd ; DO
|
2013-12-13 21:24:03 +00:00
|
|
|
jmp @add_iac_response
|
|
|
|
@will_suppress_ga:
|
2013-12-27 13:57:56 +00:00
|
|
|
lda #$fd ; DO
|
2013-12-13 21:24:03 +00:00
|
|
|
jmp @add_iac_response
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
@do_naws:
|
2013-12-13 21:24:03 +00:00
|
|
|
ldx #0
|
2013-12-27 13:57:56 +00:00
|
|
|
: lda naws_response,x
|
2013-12-13 21:24:03 +00:00
|
|
|
ldy iac_response_buffer_length
|
|
|
|
inc iac_response_buffer_length
|
|
|
|
sta iac_response_buffer,y
|
2013-12-27 13:57:56 +00:00
|
|
|
inx
|
2013-12-13 21:24:03 +00:00
|
|
|
txa
|
|
|
|
cmp #naws_response_length
|
|
|
|
bne :-
|
|
|
|
jmp @after_set_iac_response
|
|
|
|
@do_terminaltype:
|
2013-12-27 13:57:56 +00:00
|
|
|
lda #$fb ; WILL
|
2013-12-13 21:24:03 +00:00
|
|
|
jmp @add_iac_response
|
|
|
|
|
|
|
|
@not_iac:
|
2013-12-27 13:57:56 +00:00
|
|
|
txa
|
2017-05-18 22:12:42 +00:00
|
|
|
tay
|
2013-12-13 21:24:03 +00:00
|
|
|
jsr vt100_process_inbound_char
|
2017-05-18 22:12:42 +00:00
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
@byte_processed:
|
2013-12-13 21:24:03 +00:00
|
|
|
inc buffer_ptr
|
|
|
|
bne :+
|
|
|
|
inc buffer_ptr+1
|
2013-12-27 13:57:56 +00:00
|
|
|
: lda buffer_length+1
|
2017-05-18 22:12:42 +00:00
|
|
|
beq :++
|
2013-12-13 21:24:03 +00:00
|
|
|
lda buffer_length
|
2017-05-18 22:12:42 +00:00
|
|
|
bne :+
|
2013-12-13 21:24:03 +00:00
|
|
|
dec buffer_length+1
|
2017-05-18 22:12:42 +00:00
|
|
|
: dec buffer_length
|
2013-12-13 21:24:03 +00:00
|
|
|
jmp @next_byte
|
2017-05-18 22:12:42 +00:00
|
|
|
: dec buffer_length
|
|
|
|
beq :+
|
2013-12-13 21:24:03 +00:00
|
|
|
jmp @next_byte
|
2017-05-18 22:12:42 +00:00
|
|
|
: rts
|
|
|
|
|
|
|
|
|
|
|
|
.rodata
|
|
|
|
|
2017-06-02 17:00:22 +00:00
|
|
|
initializing: .byte 10,"Initializing ",0
|
2017-05-18 22:12:42 +00:00
|
|
|
obtaining: .byte "Obtaining IP address ",0
|
|
|
|
resolving: .byte 10,"Resolving to address ",0
|
|
|
|
connecting: .byte 10,"Connecting to ",0
|
|
|
|
ok: .byte "Ok",10,10,0
|
|
|
|
device_not_found: .byte "- Device not found",10,0
|
|
|
|
abort: .byte "- User abort",10,0
|
|
|
|
timeout: .byte "- Timeout",10,0
|
|
|
|
error_prefix: .byte "- Error $",0
|
|
|
|
remote_host: .byte 10,"Hostname (leave blank to quit)",10,"? ",0
|
|
|
|
remote_port: .byte 10,10,"Port Num (leave blank for default)",10,"? ",0
|
|
|
|
disconnected: .byte 10,"Disconnected",10,0
|
|
|
|
send_error: .byte "Sending ",0
|
2017-06-02 17:00:22 +00:00
|
|
|
|
|
|
|
welcome_1: .byte 27,")0"
|
|
|
|
.byte 14,"lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk"
|
|
|
|
.byte 15,13,10
|
|
|
|
.byte 14,"x x"
|
|
|
|
.byte 15,13,10
|
2019-05-10 15:47:06 +00:00
|
|
|
.byte 14,"x",15," ",27,"[1m","Telnet65 v1.3",27,"[0m"," based on: ",14,"x"
|
2017-06-02 17:00:22 +00:00
|
|
|
.byte 15,13,10
|
|
|
|
.byte 14,"x x"
|
|
|
|
.byte 15,13,10,0
|
2019-05-02 12:44:24 +00:00
|
|
|
welcome_2: .byte 14,"x",15," - IP65 (github.com/cc65/ip65) ",14,"x"
|
2017-06-02 17:00:22 +00:00
|
|
|
.byte 15,13,10
|
2019-05-02 12:44:24 +00:00
|
|
|
.byte 14,"x",15," - CaTer (www.opppf.de/Cater) ",14,"x"
|
2017-06-02 17:00:22 +00:00
|
|
|
.byte 15,13,10
|
|
|
|
.byte 14,"x x"
|
|
|
|
.byte 15,13,10
|
|
|
|
.byte 14,"mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj"
|
|
|
|
.byte 15,13,10
|
|
|
|
.byte 27,")A"
|
|
|
|
.byte 27,"[?25l",0
|
2017-06-05 15:41:41 +00:00
|
|
|
on_connect: .byte 27,"[?25h",0
|
|
|
|
on_disconnect: .byte 27,"[?25l",27,"[0m",27,"(A",15,0
|
2013-12-27 13:57:56 +00:00
|
|
|
|
|
|
|
; initial_telnet_options:
|
|
|
|
; .byte $ff,$fb,$1F ; IAC WILL NAWS
|
|
|
|
; .byte $ff,$fb,$18 ; IAC WILL TERMINAL TYPE
|
|
|
|
; initial_telnet_options_length = *-initial_telnet_options
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
terminal_type_response:
|
2013-12-27 13:57:56 +00:00
|
|
|
.byte $ff ; IAC
|
2017-05-18 22:12:42 +00:00
|
|
|
.byte $fa ; SB
|
|
|
|
.byte $18 ; TERMINAL TYPE
|
|
|
|
.byte $0 ; IS
|
2013-12-27 13:57:56 +00:00
|
|
|
.byte "vt100" ; what we pretend to be
|
|
|
|
.byte $ff ; IAC
|
|
|
|
.byte $f0 ; SE
|
|
|
|
terminal_type_response_length = *-terminal_type_response
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
naws_response:
|
2017-05-18 22:12:42 +00:00
|
|
|
.byte $ff,$fb,$1f ; IAC WILL NAWS
|
2013-12-27 13:57:56 +00:00
|
|
|
.byte $ff ; IAC
|
|
|
|
.byte $fa ; SB
|
2017-05-18 22:12:42 +00:00
|
|
|
.byte $1f ; NAWS
|
2013-12-27 13:57:56 +00:00
|
|
|
.byte $00 ; width (high byte)
|
2017-05-18 22:12:42 +00:00
|
|
|
.byte vt100_screen_cols ; width (low byte)
|
2013-12-27 13:57:56 +00:00
|
|
|
.byte $00 ; height (high byte)
|
2017-05-18 22:12:42 +00:00
|
|
|
.byte vt100_screen_rows ; height (low byte)
|
2013-12-27 13:57:56 +00:00
|
|
|
.byte $ff ; IAC
|
|
|
|
.byte $f0 ; SE
|
|
|
|
naws_response_length = *-naws_response
|
|
|
|
|
|
|
|
|
2017-05-18 22:12:42 +00:00
|
|
|
.bss
|
2013-12-27 13:57:56 +00:00
|
|
|
|
|
|
|
; variables
|
|
|
|
telnet_port: .res 2 ; port number to connect to
|
|
|
|
telnet_timeout: .res 1
|
2017-05-18 22:12:42 +00:00
|
|
|
connection_close_requested: .res 1
|
2013-12-27 13:57:56 +00:00
|
|
|
connection_closed: .res 1
|
2017-05-21 20:39:10 +00:00
|
|
|
data_received: .res 1
|
2013-12-27 13:57:56 +00:00
|
|
|
buffer_offset: .res 1
|
|
|
|
telnet_command: .res 1
|
|
|
|
telnet_option: .res 1
|
|
|
|
|
|
|
|
telnet_state_normal = 0
|
|
|
|
telnet_state_got_iac = 1
|
|
|
|
telnet_state_got_command = 2
|
|
|
|
telnet_state_got_suboption = 3
|
|
|
|
|
|
|
|
buffer_length: .res 2
|
|
|
|
|
|
|
|
telnet_state: .res 1
|
|
|
|
iac_response_buffer: .res 64
|
|
|
|
iac_response_buffer_length: .res 1
|
|
|
|
scratch_buffer : .res 40
|
|
|
|
iac_suboption_buffer: .res 64
|
2017-05-18 22:12:42 +00:00
|
|
|
iac_suboption_buffer_length: .res 1
|
2013-12-27 13:57:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; -- LICENSE FOR telnet.s --
|
2013-12-13 21:24:03 +00:00
|
|
|
; The contents of this file are subject to the Mozilla Public License
|
|
|
|
; 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/
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; 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.
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; The Original Code is ip65.
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; The Initial Developer of the Original Code is Jonno Downes,
|
|
|
|
; jonno@jamtronix.com.
|
|
|
|
; Portions created by the Initial Developer are Copyright (C) 2009
|
2013-12-27 13:57:56 +00:00
|
|
|
; Jonno Downes. All Rights Reserved.
|
2013-12-13 21:24:03 +00:00
|
|
|
; -- LICENSE END --
|