git-svn-id: http://svn.code.sf.net/p/netboot65/code@164 93682198-c243-4bdb-bd91-e943c89aac3b

This commit is contained in:
jonnosan 2009-07-24 00:17:41 +00:00
parent b2b0210657
commit 9492e1cc83
8 changed files with 406 additions and 94 deletions

View File

@ -6,8 +6,11 @@
.export filter_number
.export check_for_abort_key
.export get_key_if_available
.export get_key_ip65
.importzp copy_src
.import ip65_process
.include "../inc/common.i"
.code
@ -25,7 +28,17 @@ get_key:
;inputs: none
;outputs: A contains ASCII value of key just pressed (0 if no key pressed)
get_key_if_available=$ffe4
;process inbound ip packets while waiting for a keypress
get_key_ip65:
jsr ip65_process
jsr $ffe4
beq get_key_ip65
rts
;check whether the RUN/STOP key is being pressed
;inputs: none
@ -49,7 +62,8 @@ check_for_abort_key:
;cribbed from http://codebase64.org/doku.php?id=base:robust_string_input
;======================================================================
;Input a string and store it in GOTINPUT, terminated with a null byte.
;x:a is a pointer to the allowed list of characters, null-terminated.
;AX is a pointer to the allowed list of characters, null-terminated.
;set AX to $0000 for no filter on input
;max # of chars in y returns num of chars entered in y.
;======================================================================
@ -64,35 +78,37 @@ get_filtered_input:
sta INPUT_Y
;Wait for a character.
INPUT_GET:
jsr get_key
@input_get:
jsr get_key_ip65
sta LASTCHAR
cmp #$14 ;Delete
beq DELETE
beq @delete
cmp #$0d ;Return
beq INPUT_DONE
beq @input_done
;End reached?
lda INPUT_Y
cmp MAXCHARS
beq INPUT_GET
beq @input_get
;Check the allowed list of characters.
ldy #$00
CHECKALLOWED:
lda allowed_ptr+1 ;was the input filter point nul?
beq @input_ok
@check_allowed:
lda (allowed_ptr),y ;Overwritten
beq INPUT_GET ;Reached end of list (0)
beq @input_get ;Reached end of list (0)
cmp LASTCHAR
beq INPUTOK ;Match found
beq @input_ok ;Match found
;Not end or match, keep checking
iny
jmp CHECKALLOWED
jmp @check_allowed
INPUTOK:
@input_ok:
lda LASTCHAR ;Get the char back
ldy INPUT_Y
sta GOTINPUT,y ;Add it to string
@ -100,30 +116,29 @@ INPUTOK:
inc INPUT_Y ;Next character
;Not yet.
jmp INPUT_GET
jmp @input_get
INPUT_DONE:
@input_done:
ldy INPUT_Y
beq no_input
beq @no_input
lda #$00
sta GOTINPUT,y ;Zero-terminate
clc
ldax #GOTINPUT
rts
no_input:
@no_input:
sec
rts
; Delete last character.
DELETE:
@delete:
;First, check if we're at the beginning. If so, just exit.
lda INPUT_Y
bne DELETE_OK
jmp INPUT_GET
bne @delete_ok
jmp @input_get
;At least one character entered.
DELETE_OK:
@delete_ok:
;Move pointer back.
dec INPUT_Y
@ -137,7 +152,7 @@ DELETE_OK:
jsr $ffd2
;Wait for next char
jmp INPUT_GET
jmp @input_get
;=================================================
@ -159,4 +174,3 @@ MAXCHARS: .res 1
LASTCHAR: .res 1
INPUT_Y: .res 1
GOTINPUT: .res 40

View File

@ -121,16 +121,9 @@ listen_on_port_80
nb65call #NB65_PRINT_HEX
lda #"!"
jsr print_a
ldaxi #4
ldaxi #html_length
stax nb65_param_buffer+NB65_TCP_PAYLOAD_LENGTH
ldaxi #press_a_key_to_continue
stax nb65_param_buffer+NB65_TCP_PAYLOAD_POINTER
ldaxi #nb65_param_buffer
nb65call #NB65_SEND_TCP_PACKET
ldaxi #4
stax nb65_param_buffer+NB65_TCP_PAYLOAD_LENGTH
ldaxi #nb65_signature
ldaxi #html
stax nb65_param_buffer+NB65_TCP_PAYLOAD_POINTER
ldaxi #nb65_param_buffer
nb65call #NB65_SEND_TCP_PACKET
@ -276,6 +269,10 @@ failed dc.b "FAILED ", 0
ok dc.b "OK ", 0
transmission_error dc.b "ERROR WHILE SENDING ",0
html dc.b "<H1>c64 test page</h1><form method=post>foo:<input type=text name=foo><br>bar:<textarea name=bar></textarea><br><INPUT type=submit value=send>"
html_end
html_length equ html_end-html
;self modifying code
get_next_byte
lda $ffff

View File

@ -53,8 +53,9 @@ NB65_PRINT_DOTTED_QUAD EQU $82 ;inputs: AX=pointer to 4 bytes that will
NB65_PRINT_IP_CONFIG EQU $83 ;no inputs, no outputs, prints to screen current IP configuration
NB65_INPUT_HOSTNAME EQU $90 ;no inputs, outputs: AX = pointer to hostname (which may be IP address).
NB65_INPUT_PORT_NUMBER EQU $91 ;no inputs, outputs: AX = port number entered ($0000..$FFFF)
NB65_INPUT_STRING EQU $90 ;no inputs, outputs: AX = pointer to null terminated string
NB65_INPUT_HOSTNAME EQU $91 ;no inputs, outputs: AX = pointer to hostname (which may be IP address).
NB65_INPUT_PORT_NUMBER EQU $92 ;no inputs, outputs: AX = port number entered ($0000..$FFFF)
NB65_BLOCK_COPY EQU $A0 ;inputs: AX points to a block copy structure, outputs: none

View File

@ -9,7 +9,7 @@
; .include "../inc/c64keycodes.i"
; 3) define a routine called 'exit_telnet'
; 4) define a buffer called 'scratch_buffer'
; 5) define a zero page var called temp_ptr
; 5) define a zero page var called buffer_ptr
.code
telnet_main_entry:
;prompt for a hostname, then resolve to an IP address
@ -68,22 +68,30 @@ telnet_main_entry:
beq @petscii_mode
jmp @char_mode_input
@ascii_mode:
; lda #14
; jsr print_a ;switch to lower case
lda #0
jmp @character_mode_set
@petscii_mode:
; lda #142
; jsr print_a ;switch to upper case
sta character_set
sta line_mode
lda #1
@character_mode_set:
sta character_mode
sta local_echo
lda #telnet_state_normal
sta telnet_state
jmp @after_mode_set
@petscii_mode:
lda #1
sta character_set
lda #0
sta local_echo
sta line_mode
@after_mode_set:
lda #147 ; 'CLR/HOME'
jsr print_a
ldax #connecting_in
jsr print
lda character_mode
lda character_set
beq @a_mode
ldax #petscii
jsr print
@ -127,6 +135,35 @@ telnet_connect:
jsr print
jmp telnet_main_entry
@not_disconnected:
lda line_mode
beq @not_line_mode
nb65call #NB65_INPUT_STRING
stax buffer_ptr
ldy #0
@copy_one_char:
lda (buffer_ptr),y
tax
lda petscii_to_ascii_table,x
beq @end_of_input_string
sta scratch_buffer,y
iny
bne @copy_one_char
@end_of_input_string:
lda #$0d
sta scratch_buffer,y
iny
lda #$0a
sta scratch_buffer,y
iny
sty nb65_param_buffer+NB65_TCP_PAYLOAD_LENGTH
lda #0
sta nb65_param_buffer+NB65_TCP_PAYLOAD_LENGTH+1
jmp @no_more_input
@not_line_mode:
;is there anything in the input buffer?
lda $c6 ;NDX - chars in keyboard buffer
beq @main_polling_loop
@ -135,6 +172,9 @@ telnet_connect:
sta nb65_param_buffer+NB65_TCP_PAYLOAD_LENGTH+1
@get_next_char:
jsr $ffe4 ;getkey - 0 means no input
; pha
; jsr print_hex
; pla
tax
beq @no_more_input
cmp #$03 ;RUN/STOP
@ -153,9 +193,20 @@ telnet_connect:
jsr print_errorcode
jsr print_cr
jmp telnet_main_entry
@not_runstop:
lda character_mode
@not_runstop:
lda character_set
bne @no_conversion_required
txa
cmp #$0d
bne @not_cr
;if we get a CR in ascii mode, send CR/LF
ldy nb65_param_buffer+NB65_TCP_PAYLOAD_LENGTH
sta scratch_buffer,y
inc nb65_param_buffer+NB65_TCP_PAYLOAD_LENGTH
ldx #$0a
jmp @no_conversion_required
@not_cr:
lda petscii_to_ascii_table,x
tax
@no_conversion_required:
@ -202,11 +253,104 @@ telnet_callback:
dec buffer_length+1
:
ldy #0
sty iac_response_buffer_length
@next_byte:
lda (buffer_ptr),y
tax
lda character_mode
bne @no_conversion_req
lda character_set
beq :+
jmp @no_conversion_req
:
lda telnet_state
cmp #telnet_state_got_command
beq @waiting_for_option
cmp #telnet_state_got_iac
beq @waiting_for_command
; we must be in 'normal' mode
txa
cmp #255
beq :+
jmp @not_iac
:
lda #telnet_state_got_iac
sta telnet_state
jmp @byte_processed
@waiting_for_command:
txa
sta telnet_command
cmp #$fb ;WILL
beq @option
cmp #$fc ;WONT
beq @option
cmp #$fd ; DO
beq @option
cmp #$fe ;DONT
beq @option
;we got a command we don't understand - just ignore it
lda #telnet_state_normal
sta telnet_state
jmp @byte_processed
@option:
lda #telnet_state_got_command
sta telnet_state
jmp @byte_processed
@waiting_for_option:
;we have now got IAC, <command>, <option>
txa
sta telnet_option
lda telnet_command
cmp #$fb
beq @iac_will
cmp #$fc
beq @iac_wont
;if we get here, then it's a "do" or "don't", both of which we should send a "wont" back for
;(since there are no "do" options we actually honour)
lda #$fc ;wont
@add_iac_response:
ldx iac_response_buffer_length
sta iac_response_buffer+1,x
lda #255
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
lda #telnet_state_normal
sta telnet_state
jmp @byte_processed
@iac_will:
lda telnet_option
cmp #$01 ;ECHO
beq @will_echo
cmp #$03 ;DO SUPPRESS GA
beq @will_suppress_ga
@iac_wont:
lda #$fe ;dont
jmp @add_iac_response
@will_echo:
lda #0
sta local_echo
lda #$fd ;DO
jmp @add_iac_response
@will_suppress_ga:
lda #0
sta line_mode
lda #$fd ;DO
jmp @add_iac_response
@not_iac:
lda ascii_to_petscii_table,x
tax
@no_conversion_req:
@ -216,17 +360,30 @@ telnet_callback:
jsr print_a
pla
tay
@byte_processed:
iny
dec buffer_length
lda #$ff
cmp buffer_length
bne @next_byte
beq :+
jmp @next_byte
:
inc buffer_ptr+1
dec buffer_length+1
bmi @finished
ldy #0
jmp @next_byte
@finished:
lda iac_response_buffer_length
beq @no_iac_response
ldx #0
stax nb65_param_buffer+NB65_TCP_PAYLOAD_LENGTH
ldax #iac_response_buffer
stax nb65_param_buffer+NB65_TCP_PAYLOAD_POINTER
ldax #nb65_param_buffer
nb65call #NB65_SEND_TCP_PACKET
@no_iac_response:
rts
;constants
@ -248,8 +405,20 @@ telnet_ip: .res 4
telnet_port: .res 2
connection_closed: .res 1
character_mode: .res 1
character_set: .res 1
buffer_offset: .res 1
local_echo: .res 1
line_mode: .res 1
telnet_state: .res 1
telnet_command: .res 1
telnet_option: .res 1
telnet_state_normal = 0
telnet_state_got_iac = 1
telnet_state_got_command = 2
;nb65_param_buffer DS.B $20
buffer_length: .res 2
iac_response_buffer: .res 256
iac_response_buffer_length: .res 1

View File

@ -506,6 +506,14 @@ ip_configured:
.import filter_dns
.import get_filtered_input
.import filter_number
cpy #NB65_INPUT_STRING
bne :+
ldy #40 ;max chars
ldax #$0000
jmp get_filtered_input
:
cpy #NB65_INPUT_HOSTNAME
bne :+
ldy #40 ;max chars

View File

@ -64,7 +64,8 @@
.import arp_calculate_gateway_mask
.import parse_dotted_quad
.import dotted_quad_value
.import get_key_ip65
.import cfg_ip
.import cfg_netmask
.import cfg_gateway
@ -159,11 +160,11 @@ init:
LDA #$00 ;black
STA $D021 ;background
.if (BANKSWITCH_SUPPORT=$03)
lda #$9c ;petscii for purple text
lda #$9c ;petscii for purple text
.else
lda #$1E ;petscii for green text
.endif
lda #$05 ;petscii for white text
jsr print_a
;relocate our r/w data
@ -216,8 +217,7 @@ main_menu:
jsr print_cr
@get_key:
jsr ip65_process
jsr get_key
jsr get_key_ip65
cmp #KEYCODE_F1
bne @not_tftp
jmp @tftp_boot
@ -255,9 +255,8 @@ main_menu:
jsr print
jsr print_ip_config
jsr print_cr
@get_key_config_menu:
jsr ip65_process
jsr get_key
@get_key_config_menu:
jsr get_key_ip65
cmp #KEYCODE_ABORT
bne @not_abort
jmp main_menu
@ -549,9 +548,8 @@ net_apps_menu:
ldax #net_apps_menu_msg
jsr print
@get_key:
jsr ip65_process
jsr get_key
cmp #KEYCODE_ABORT
jsr get_key_ip65
cmp #KEYCODE_ABORT
bne @not_abort
jmp main_menu
@not_abort:

View File

@ -44,6 +44,10 @@ basicstub:
.word 0
init:
; jsr dump_dir
jsr dump_file
rts
lda #01
sta io_track_no
@ -69,6 +73,9 @@ init:
bcs @error
jsr dump_sector ;DEBUG
rts
@error:
jsr print_cr
lda ip65_error
@ -90,6 +97,154 @@ dump_sector:
rts
dump_dir:
LDA #dirname_end-dirname
LDX #<dirname
LDY #>dirname
JSR $FFBD ; call SETNAM
LDA #$02 ; filenumber 2
LDX $BA
BNE @skip
LDX #$08 ; default to device number 8
@skip:
LDY #$00 ; secondary address 0 (required for dir reading!)
JSR $FFBA ; call SETLFS
JSR $FFC0 ; call OPEN (open the directory)
BCS @error ; quit if OPEN failed
LDX #$02 ; filenumber 2
JSR $FFC6 ; call CHKIN
LDY #$04 ; skip 4 bytes on the first dir line
BNE @skip2
@next:
LDY #$02 ; skip 2 bytes on all other lines
@skip2:
JSR getbyte ; get a byte from dir and ignore it
DEY
BNE @skip2
JSR getbyte ; get low byte of basic line number
TAY
JSR getbyte ; get high byte of basic line number
PHA
TYA ; transfer Y to X without changing Akku
TAX
PLA
JSR $BDCD ; print basic line number
JSR getbyte
JSR getbyte
LDA #'#' ; print a space first
@char:
JSR $FFD2 ; call CHROUT (print character)
JSR getbyte
BNE @char ; continue until end of line
LDA #$0D
JSR $FFD2 ; print RETURN
JSR $FFE1 ; RUN/STOP pressed?
BNE @next ; no RUN/STOP -> continue
@error:
; Akkumulator contains BASIC error code
; most likely error:
; A = $05 (DEVICE NOT PRESENT)
exit:
LDA #$02 ; filenumber 2
JSR $FFC3 ; call CLOSE
LDX #$00
JSR $FFC9 ; call CHKIN (keyboard now input device again)
RTS
getbyte:
JSR $FFB7 ; call READST (read status byte)
BNE @end ; read error or end of file
JMP $FFCF ; call CHRIN (read byte from directory)
@end:
PLA ; don't return to dir reading loop
PLA
JMP exit
dump_file:
LDA #fname_end-fname
LDX #<fname
LDY #>fname
JSR $FFBD ; call SETNAM
LDA #$02 ; file number 2
LDX $BA ; last used device number
BNE @skip
LDX #$08 ; default to device 8
@skip:
LDY #$02 ; secondary address 2
JSR $FFBA ; call SETLFS
JSR $FFC0 ; call OPEN
BCS @error ; if carry set, the file could not be opened
; check drive error channel here to test for
; FILE NOT FOUND error etc.
LDX #$02 ; filenumber 2
JSR $FFC6 ; call CHKIN (file 2 now used as input)
@loop:
JSR $FFB7 ; call READST (read status byte)
BNE @eof ; either EOF or read error
JSR $FFCF ; call CHRIN (get a byte from file)
JSR $FFD2 ; call CHROUT (print character)
JMP @loop ; next byte
@eof:
AND #$40 ; end of file?
BEQ @readerror
@close:
LDA #$02 ; filenumber 2
JSR $FFC3 ; call CLOSE
LDX #$00 ; filenumber 0 = keyboard
JSR $FFC6 ; call CHKIN (keyboard now input device again)
RTS
@error:
; Akkumulator contains BASIC error code
; most likely errors:
; A = $05 (DEVICE NOT PRESENT)
pha
ldax #error_code
jsr print
pla
jsr print_hex
JMP @close ; even if OPEN failed, the file has to be closed
@readerror:
; for further information, the drive error channel has to be read
jsr print_error
JMP @close
print_error:
LDX #$0F ; filenumber 15
JSR $FFC6 ; call CHKIN (file 15 now used as input)
@loop:
JSR $FFB7 ; call READST (read status byte)
BNE @end ; read error or end of file
JMP $FFCF ; call CHRIN (read byte from directory)
jsr print_a
JMP @loop ; next byte
@end:
.byte $92
rts
fname: .byte "tcp.s"
fname_end:
.rodata
error_code:
@ -103,38 +258,8 @@ failed:
ok:
.byte "OK ", 0
initializing:
.byte "INITIALIZING ",0
track_no:
.byte "TRACK ",0
sector_no:
.byte " SECTOR ",0
signon_message:
.byte "D64 UPLOADER V0.1",13,0
enter_filename:
.byte "SEND AS: ",0
drive_error:
.byte "DRIVE ACCESS ERROR - ",0
nb65_signature_not_found_message:
.byte "NO NB65 API FOUND",13,"PRESS ANY KEY TO RESET", 0
error_opening_channel:
.byte "ERROR OPENING CHANNEL $",0
disk_access:
.byte 13,13,13,13,13,"SENDING TO CHANNEL $",0
nb65_signature:
.byte $4E,$42,$36,$35 ; "NB65" - API signature
.byte ' ',0 ; so we can use this as a string
position_cursor_for_track_display:
; .byte $13,13,13,13,13,13,13,13,13,13,13," SENDING ",0
.byte $13,13,13,"SENDING ",0
position_cursor_for_error_display:
.byte $13,13,13,13,"LAST ",0
dirname:
.byte "$" ; filename used to access directory
dirname_end:
cname: .byte '#'

Binary file not shown.