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

This commit is contained in:
jonnosan 2009-09-22 09:49:37 +00:00
parent 6ed284f42e
commit 58160a34e8
25 changed files with 883 additions and 478 deletions

View File

@ -1,10 +1,10 @@
TARGET=c64
.PHONY: ip65 drivers test clean distclean nb65 examples
.PHONY: ip65 drivers test clean distclean carts examples
all: ip65 drivers test nb65 examples
all: ip65 drivers test carts examples
ip65:
make -C ip65 all
@ -18,21 +18,18 @@ examples:
test:
make -C test TARGET=$(TARGET) all
nb65:
make -C nb65 all
carts:
make -C carts all
clean:
make -C ip65 clean
make -C drivers clean
make -C test clean
make -C nb65 clean
make -C kipper clean
make -C carts clean
distclean:
make -C ip65 distclean
make -C drivers clean
make -C test distclean
make -C nb65 distclean
make -C kipper distclean
make -C carts distclean
rm -f *~

21
client/cfg/c64_8kcart.cfg Normal file
View File

@ -0,0 +1,21 @@
# CA65 config for a Retro Replay cartridge
# default is for GAME=1, EXROM=0,
MEMORY {
IP65ZP: start = $A3, size = $0E, type = rw, define = yes;
HEADER: start = $8000, size = $09, file = %O;
DEFAULTS: start = $8009, size = $1E, file = %O;
ROM: start = $8027, size = $1FCA, define = yes, file = %O;
RAM: start = $C010, size = $0fE0, define = yes;
}
SEGMENTS {
CARTRIDGE_HEADER: load = HEADER, type = ro;
IP65_DEFAULTS: load = DEFAULTS, type = ro;
CODE: load = ROM, type = ro;
RODATA: load = ROM, run=ROM, type = ro;
DATA: load = ROM, run = RAM, type = rw, define = yes;
BSS: load = RAM, type = bss;
IP65ZP: load = IP65ZP, type = zp;
}

View File

@ -2,9 +2,9 @@
;
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.include "../inc/common.i"
@ -171,7 +171,7 @@ io_read_file_with_callback:
beq @was_not_an_error
@readerror:
lda #NB65_ERROR_FILE_ACCESS_FAILURE
lda #KPR_ERROR_FILE_ACCESS_FAILURE
sta ip65_error
sec
rts
@ -216,7 +216,7 @@ io_read_file_with_callback:
clc
rts
@device_error:
lda #NB65_ERROR_DEVICE_FAILURE
lda #KPR_ERROR_DEVICE_FAILURE
sta ip65_error
ldx #$00
jsr CHKIN
@ -403,7 +403,7 @@ io_read_sector:
clc
rts
@error:
lda #NB65_ERROR_DEVICE_FAILURE
lda #KPR_ERROR_DEVICE_FAILURE
sta ip65_error
jsr @close
sec

View File

@ -1,6 +1,6 @@
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.export print_hex
@ -10,6 +10,7 @@
.export failed_msg
.export init_msg
.export print
.export print_ascii_as_native
.export print_integer
.export print_dotted_quad
.export print_arp_cache
@ -24,7 +25,10 @@
.export press_a_key_to_continue
.import arp_cache
.importzp ac_size
.import ascii_to_native
.import cs_driver_name
.importzp copy_src
.import cfg_tftp_server
@ -88,7 +92,7 @@ print_ip_config:
ldax #ip_address_msg
jsr print
jsr cfg_get_configuration_ptr ;ax=base config, carry flag clear
adc #NB65_CFG_IP
adc #KPR_CFG_IP
bcc :+
inx
:
@ -98,7 +102,7 @@ print_ip_config:
ldax #netmask_msg
jsr print
jsr cfg_get_configuration_ptr ;ax=base config, carry flag clear
adc #NB65_CFG_NETMASK
adc #KPR_CFG_NETMASK
bcc :+
inx
:
@ -108,7 +112,7 @@ print_ip_config:
ldax #gateway_msg
jsr print
jsr cfg_get_configuration_ptr ;ax=base config, carry flag clear
adc #NB65_CFG_GATEWAY
adc #KPR_CFG_GATEWAY
bcc :+
inx
:
@ -118,7 +122,7 @@ print_ip_config:
ldax #dns_server_msg
jsr print
jsr cfg_get_configuration_ptr ;ax=base config, carry flag clear
adc #NB65_CFG_DNS_SERVER
adc #KPR_CFG_DNS_SERVER
bcc :+
inx
: jsr print_dotted_quad
@ -133,7 +137,7 @@ print_ip_config:
ldax #dhcp_server_msg
jsr print
jsr cfg_get_configuration_ptr ;ax=base config, carry flag clear
adc #NB65_CFG_DHCP_SERVER
adc #KPR_CFG_DHCP_SERVER
bcc :+
inx
:
@ -159,6 +163,24 @@ print:
@done_print:
rts
print_ascii_as_native:
sta pptr
stx pptr + 1
@print_loop:
ldy #0
lda (pptr),y
beq @done_print
jsr ascii_to_native
jsr print_a
inc pptr
bne @print_loop
inc pptr+1
bne @print_loop ;if we ever get to $ffff, we've probably gone far enough ;-)
@done_print:
rts
print_arp_cache:
ldax #arp_cache_header
jsr print

View File

@ -0,0 +1,152 @@
;constants for accessing the KPR API file
;to use this file under CA65, then add " .define EQU =" to your code before this file is included.
KPR_API_VERSION_NUMBER EQU $01
KPR_CART_SIGNATURE EQU $8009
KPR_DISPATCH_VECTOR EQU $800f
KPR_PERIODIC_PROCESSING_VECTOR EQU $8012
KPR_VBL_VECTOR EQU $8015
;function numbers
;to make a function call:
; Y EQU function number
; AX EQU pointer to parameter buffer (for functions that take parameters)
; then JSR KPR_DISPATCH_VECTOR
; on return, carry flag is set if there is an error, or clear otherwise
; some functions return results in AX directly, others will update the parameter buffer they were called with.
; any register not specified in outputs will have an undefined value on exit
KPR_INITIALIZE EQU $01 ;no inputs or outputs - initializes IP stack, also sets IRQ chain to call KPR_VBL_VECTOR at @ 60hz
KPR_GET_IP_CONFIG EQU $02 ;no inputs, outputs AX=pointer to IP configuration structure
KPR_DEACTIVATE EQU $0F ;inputs: none, outputs: none (removes call to KPR_VBL_VECTOR on IRQ chain)
KPR_UDP_ADD_LISTENER EQU $10 ;inputs: AX points to a UDP listener parameter structure, outputs: none
KPR_GET_INPUT_PACKET_INFO EQU $11 ;inputs: AX points to a UDP/TCP packet parameter structure, outputs: UDP/TCP packet structure filled in
KPR_SEND_UDP_PACKET EQU $12 ;inputs: AX points to a UDP packet parameter structure, outputs: none packet is sent
KPR_UDP_REMOVE_LISTENER EQU $13 ;inputs: AX contains UDP port number that listener will be removed from
KPR_TCP_CONNECT EQU $14 ;inputs: AX points to a TCP connect parameter structure, outputs: none
KPR_SEND_TCP_PACKET EQU $15 ;inputs: AX points to a TCP send parameter structure, outputs: none packet is sent
KPR_TCP_CLOSE_CONNECTION EQU $16 ;inputs: none outputs: none
KPR_TFTP_SET_SERVER EQU $20 ;inputs: AX points to a TFTP server parameter structure, outputs: none
KPR_TFTP_DOWNLOAD EQU $22 ;inputs: AX points to a TFTP transfer parameter structure, outputs: TFTP param structure updated with
;KPR_TFTP_POINTER updated to reflect actual load address (if load address $0000 originally passed in)
KPR_TFTP_CALLBACK_DOWNLOAD EQU $23 ;inputs: AX points to a TFTP transfer parameter structure, outputs: none
KPR_TFTP_UPLOAD EQU $24 ;upload: AX points to a TFTP transfer parameter structure, outputs: none
KPR_TFTP_CALLBACK_UPLOAD EQU $25 ;upload: AX points to a TFTP transfer parameter structure, outputs: none
KPR_DNS_RESOLVE EQU $30 ;inputs: AX points to a DNS parameter structure, outputs: DNS param structure updated with
;KPR_DNS_HOSTNAME_IP updated with IP address corresponding to hostname.
KPR_DOWNLOAD_RESOURCE EQU $31 ;inputs: AX points to a URL download structure, outputs: none
KPR_PING_HOST EQU $32 ;inputs: AX points to destination IP address for ping, outputs: AX=time (in milliseconds) to get response
KPR_FILE_LOAD EQU $40 ;inputs: AX points to a file access parameter structure, outputs: none
KPR_PRINT_ASCIIZ EQU $80 ;inputs: AX=pointer to null terminated string to be printed to screen, outputs: none
KPR_PRINT_HEX EQU $81 ;inputs: A=byte digit to be displayed on screen as (zero padded) hex digit, outputs: none
KPR_PRINT_DOTTED_QUAD EQU $82 ;inputs: AX=pointer to 4 bytes that will be displayed as a decimal dotted quad (e.g. 192.168.1.1)
KPR_PRINT_IP_CONFIG EQU $83 ;no inputs, no outputs, prints to screen current IP configuration
KPR_PRINT_INTEGER EQU $84 ;inputs: AX=16 byte number that will be printed as an unsigned decimal
KPR_INPUT_STRING EQU $90 ;no inputs, outputs: AX = pointer to null terminated string
KPR_INPUT_HOSTNAME EQU $91 ;no inputs, outputs: AX = pointer to hostname (which may be IP address).
KPR_INPUT_PORT_NUMBER EQU $92 ;no inputs, outputs: AX = port number entered ($0000..$FFFF)
KPR_BLOCK_COPY EQU $A0 ;inputs: AX points to a block copy structure, outputs: none
KPR_PARSER_INIT EQU $A1 ;inputs: AX points to a null terminated string, outputs: none
KPR_PARSER_SKIP_NEXT EQU $A2 ;inputs: AX points to a null terminated substring, outputs: AX points to
;previously loaded string that is just past the next occurance of substring
KPR_GET_LAST_ERROR EQU $FF ;no inputs, outputs A EQU error code (from last function that set the global error value, not necessarily the
;last function that was called)
;offsets in IP configuration structure (used by KPR_GET_IP_CONFIG)
KPR_CFG_MAC EQU $00 ;6 byte MAC address
KPR_CFG_IP EQU $06 ;4 byte local IP address (will be overwritten by DHCP)
KPR_CFG_NETMASK EQU $0A ;4 byte local netmask (will be overwritten by DHCP)
KPR_CFG_GATEWAY EQU $0E ;4 byte local gateway (will be overwritten by DHCP)
KPR_CFG_DNS_SERVER EQU $12 ;4 byte IP address of DNS server (will be overwritten by DHCP)
KPR_CFG_DHCP_SERVER EQU $16 ;4 byte IP address of DHCP server (will only be set by DHCP initialisation)
KPR_DRIVER_NAME EQU $1A ;2 byte pointer to name of driver
;offsets in TFTP transfer parameter structure (used by KPR_TFTP_DOWNLOAD, KPR_TFTP_CALLBACK_DOWNLOAD, KPR_TFTP_UPLOAD, KPR_TFTP_CALLBACK_UPLOAD)
KPR_TFTP_FILENAME EQU $00 ;2 byte pointer to asciiz filename (or filemask)
KPR_TFTP_POINTER EQU $02 ;2 byte pointer to memory location data to be stored in OR address of callback function
KPR_TFTP_FILESIZE EQU $04 ;2 byte file length (filled in by KPR_TFTP_DOWNLOAD, must be passed in to KPR_TFTP_UPLOAD)
;offsets in TFTP Server parameter structure (used by KPR_TFTP_SET_SERVER)
KPR_TFTP_SERVER_IP EQU $00 ;4 byte IP address of TFTP server
;offsets in DNS parameter structure (used by KPR_DNS_RESOLVE)
KPR_DNS_HOSTNAME EQU $00 ;2 byte pointer to asciiz hostname to resolve (can also be a dotted quad string)
KPR_DNS_HOSTNAME_IP EQU $00 ;4 byte IP address (filled in on succesful resolution of hostname)
;offsets in UDP listener parameter structure
KPR_UDP_LISTENER_PORT EQU $00 ;2 byte port number
KPR_UDP_LISTENER_CALLBACK EQU $02 ;2 byte address of routine to call when UDP packet arrives for specified port
;offsets in block copy parameter structure
KPR_BLOCK_SRC EQU $00 ;2 byte address of start of source block
KPR_BLOCK_DEST EQU $02 ;2 byte address of start of destination block
KPR_BLOCK_SIZE EQU $04 ;2 byte length of block to be copied (in bytes
;offsets in TCP connect parameter structure
KPR_TCP_REMOTE_IP EQU $00 ;4 byte IP address of remote host (0.0.0.0 means wait for inbound i.e. server mode)
KPR_TCP_PORT EQU $04 ;2 byte port number (to listen on, if ip address was 0.0.0.0, or connect to otherwise)
KPR_TCP_CALLBACK EQU $06 ;2 byte address of routine to be called whenever a new packet arrives
;offsets in TCP send parameter structure
KPR_TCP_PAYLOAD_LENGTH EQU $00 ;2 byte length of payload of packet (after all ethernet,IP,UDP/TCP headers)
KPR_TCP_PAYLOAD_POINTER EQU $02 ;2 byte pointer to payload of packet (after all headers)
;offsets in TCP/UDP packet parameter structure
KPR_REMOTE_IP EQU $00 ;4 byte IP address of remote machine (src of inbound packets, dest of outbound packets)
KPR_REMOTE_PORT EQU $04 ;2 byte port number of remote machine (src of inbound packets, dest of outbound packets)
KPR_LOCAL_PORT EQU $06 ;2 byte port number of local machine (src of outbound packets, dest of inbound packets)
KPR_PAYLOAD_LENGTH EQU $08 ;2 byte length of payload of packet (after all ethernet,IP,UDP/TCP headers)
; in a TCP connection, if the length is $FFFF, this actually means "end of connection"
KPR_PAYLOAD_POINTER EQU $0A ;2 byte pointer to payload of packet (after all headers)
;offsets in ICMP listener parameter structure
KPR_ICMP_LISTENER_TYPE EQU $00 ;ICMP type
KPR_ICMP_LISTENER_CALLBACK EQU $01 ;2 byte address of routine to call when ICMP packet of specified type arrives
;offsets in URL download structure
;inputs:
KPR_URL EQU $00 ;2 byte pointer to null terminated URL (NB - must be ASCII not "native" string)
KPR_URL_DOWNLOAD_BUFFER EQU $02 ;2 byte pointer to buffer that resource specified by URL will be downloaded into
KPR_URL_DOWNLOAD_BUFFER_LENGTH EQU $04 ;2 byte length of buffer (download will truncate when buffer is full)
;offsets in file access parameter structure (used by KPR_FILE_LOAD)
KPR_FILE_ACCESS_FILENAME EQU $00 ;2 byte pointer to asciiz filename (or filemask)
KPR_FILE_ACCESS_POINTER EQU $02 ;2 byte pointer to memory location data to be stored in OR address of callback function
KPR_FILE_ACCESS_FILESIZE EQU $04 ;2 byte file length (filled in by KPR_FILE_ACCESS)
KPR_FILE_ACCESS_DEVICE EQU $06 ;1 byte device number (set to $00 to use last accessed device)
;error codes (as returned by KPR_GET_LAST_ERROR)
KPR_ERROR_PORT_IN_USE EQU $80
KPR_ERROR_TIMEOUT_ON_RECEIVE EQU $81
KPR_ERROR_TRANSMIT_FAILED EQU $82
KPR_ERROR_TRANSMISSION_REJECTED_BY_PEER EQU $83
KPR_ERROR_INPUT_TOO_LARGE EQU $84
KPR_ERROR_DEVICE_FAILURE EQU $85
KPR_ERROR_ABORTED_BY_USER EQU $86
KPR_ERROR_LISTENER_NOT_AVAILABLE EQU $87
KPR_ERROR_NO_SUCH_LISTENER EQU $88
KPR_ERROR_CONNECTION_RESET_BY_PEER EQU $89
KPR_ERROR_CONNECTION_CLOSED EQU $8A
KPR_ERROR_FILE_ACCESS_FAILURE EQU $90
KPR_ERROR_MALFORMED_URL EQU $A0
KPR_ERROR_DNS_LOOKUP_FAILED EQU $A1
KPR_ERROR_OPTION_NOT_SUPPORTED EQU $FE
KPR_ERROR_FUNCTION_NOT_SUPPORTED EQU $FF

View File

@ -1,7 +1,6 @@
;REQUIRES KEYCODES TO BE DEFINED
OPTIONS_PER_PAGE = $10
.bss
@ -140,7 +139,7 @@ select_option_from_menu:
lda get_current_byte+1
ldx get_current_byte+2
jsr print
jsr print_ascii_as_native
jsr print_cr
jsr @skip_past_next_null_byte
inc current_option

View File

@ -1,156 +0,0 @@
;constants for accessing the NB65 API file
;to use this file under CA65, then add " .define EQU =" to your code before this file is included.
NB65_API_VERSION_NUMBER EQU $02
NB65_CART_SIGNATURE EQU $8009
NB65_API_VERSION EQU $800d
NB65_BANKSWITCH_SUPPORT EQU $800e
NB65_DISPATCH_VECTOR EQU $800f
NB65_PERIODIC_PROCESSING_VECTOR EQU $8012
NB65_VBL_VECTOR EQU $8015
NB65_RAM_STUB_SIGNATURE EQU $C000
NB65_RAM_STUB_ACTIVATE EQU $C004
;function numbers
;to make a function call:
; Y EQU function number
; AX EQU pointer to parameter buffer (for functions that take parameters)
; then JSR NB65_DISPATCH_VECTOR
; on return, carry flag is set if there is an error, or clear otherwise
; some functions return results in AX directly, others will update the parameter buffer they were called with.
; any register not specified in outputs will have an undefined value on exit
NB65_INITIALIZE EQU $01 ;no inputs or outputs - initializes IP stack, also sets IRQ chain to call NB65_VBL_VECTOR at @ 60hz
NB65_GET_IP_CONFIG EQU $02 ;no inputs, outputs AX=pointer to IP configuration structure
NB65_DEACTIVATE EQU $0F ;inputs: none, outputs: none (removes call to NB65_VBL_VECTOR on IRQ chain)
NB65_UDP_ADD_LISTENER EQU $10 ;inputs: AX points to a UDP listener parameter structure, outputs: none
NB65_GET_INPUT_PACKET_INFO EQU $11 ;inputs: AX points to a UDP/TCP packet parameter structure, outputs: UDP/TCP packet structure filled in
NB65_SEND_UDP_PACKET EQU $12 ;inputs: AX points to a UDP packet parameter structure, outputs: none packet is sent
NB65_UDP_REMOVE_LISTENER EQU $13 ;inputs: AX contains UDP port number that listener will be removed from
NB65_TCP_CONNECT EQU $14 ;inputs: AX points to a TCP connect parameter structure, outputs: none
NB65_SEND_TCP_PACKET EQU $15 ;inputs: AX points to a TCP send parameter structure, outputs: none packet is sent
NB65_TCP_CLOSE_CONNECTION EQU $16 ;inputs: none outputs: none
NB65_TFTP_SET_SERVER EQU $20 ;inputs: AX points to a TFTP server parameter structure, outputs: none
NB65_TFTP_DOWNLOAD EQU $22 ;inputs: AX points to a TFTP transfer parameter structure, outputs: TFTP param structure updated with
;NB65_TFTP_POINTER updated to reflect actual load address (if load address $0000 originally passed in)
NB65_TFTP_CALLBACK_DOWNLOAD EQU $23 ;inputs: AX points to a TFTP transfer parameter structure, outputs: none
NB65_TFTP_UPLOAD EQU $24 ;upload: AX points to a TFTP transfer parameter structure, outputs: none
NB65_TFTP_CALLBACK_UPLOAD EQU $25 ;upload: AX points to a TFTP transfer parameter structure, outputs: none
NB65_DNS_RESOLVE EQU $30 ;inputs: AX points to a DNS parameter structure, outputs: DNS param structure updated with
;NB65_DNS_HOSTNAME_IP updated with IP address corresponding to hostname.
NB65_DOWNLOAD_RESOURCE EQU $31 ;inputs: AX points to a URL download structure, outputs: none
NB65_PING_HOST EQU $32 ;inputs: AX points to destination IP address for ping, outputs: AX=time (in milliseconds) to get response
NB65_FILE_LOAD EQU $40 ;inputs: AX points to a file access parameter structure, outputs: none
NB65_PRINT_ASCIIZ EQU $80 ;inputs: AX=pointer to null terminated string to be printed to screen, outputs: none
NB65_PRINT_HEX EQU $81 ;inputs: A=byte digit to be displayed on screen as (zero padded) hex digit, outputs: none
NB65_PRINT_DOTTED_QUAD EQU $82 ;inputs: AX=pointer to 4 bytes that will be displayed as a decimal dotted quad (e.g. 192.168.1.1)
NB65_PRINT_IP_CONFIG EQU $83 ;no inputs, no outputs, prints to screen current IP configuration
NB65_PRINT_INTEGER EQU $84 ;inputs: AX=16 byte number that will be printed as an unsigned decimal
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
NB65_PARSER_INIT EQU $A1 ;inputs: AX points to a null terminated string, outputs: none
NB65_PARSER_SKIP_NEXT EQU $A2 ;inputs: AX points to a null terminated substring, outputs: AX points to
;previously loaded string that is just past the next occurance of substring
NB65_GET_LAST_ERROR EQU $FF ;no inputs, outputs A EQU error code (from last function that set the global error value, not necessarily the
;last function that was called)
;offsets in IP configuration structure (used by NB65_GET_IP_CONFIG)
NB65_CFG_MAC EQU $00 ;6 byte MAC address
NB65_CFG_IP EQU $06 ;4 byte local IP address (will be overwritten by DHCP)
NB65_CFG_NETMASK EQU $0A ;4 byte local netmask (will be overwritten by DHCP)
NB65_CFG_GATEWAY EQU $0E ;4 byte local gateway (will be overwritten by DHCP)
NB65_CFG_DNS_SERVER EQU $12 ;4 byte IP address of DNS server (will be overwritten by DHCP)
NB65_CFG_DHCP_SERVER EQU $16 ;4 byte IP address of DHCP server (will only be set by DHCP initialisation)
NB65_DRIVER_NAME EQU $1A ;2 byte pointer to name of driver
;offsets in TFTP transfer parameter structure (used by NB65_TFTP_DOWNLOAD, NB65_TFTP_CALLBACK_DOWNLOAD, NB65_TFTP_UPLOAD, NB65_TFTP_CALLBACK_UPLOAD)
NB65_TFTP_FILENAME EQU $00 ;2 byte pointer to asciiz filename (or filemask)
NB65_TFTP_POINTER EQU $02 ;2 byte pointer to memory location data to be stored in OR address of callback function
NB65_TFTP_FILESIZE EQU $04 ;2 byte file length (filled in by NB65_TFTP_DOWNLOAD, must be passed in to NB65_TFTP_UPLOAD)
;offsets in TFTP Server parameter structure (used by NB65_TFTP_SET_SERVER)
NB65_TFTP_SERVER_IP EQU $00 ;4 byte IP address of TFTP server
;offsets in DNS parameter structure (used by NB65_DNS_RESOLVE)
NB65_DNS_HOSTNAME EQU $00 ;2 byte pointer to asciiz hostname to resolve (can also be a dotted quad string)
NB65_DNS_HOSTNAME_IP EQU $00 ;4 byte IP address (filled in on succesful resolution of hostname)
;offsets in UDP listener parameter structure
NB65_UDP_LISTENER_PORT EQU $00 ;2 byte port number
NB65_UDP_LISTENER_CALLBACK EQU $02 ;2 byte address of routine to call when UDP packet arrives for specified port
;offsets in block copy parameter structure
NB65_BLOCK_SRC EQU $00 ;2 byte address of start of source block
NB65_BLOCK_DEST EQU $02 ;2 byte address of start of destination block
NB65_BLOCK_SIZE EQU $04 ;2 byte length of block to be copied (in bytes
;offsets in TCP connect parameter structure
NB65_TCP_REMOTE_IP EQU $00 ;4 byte IP address of remote host (0.0.0.0 means wait for inbound i.e. server mode)
NB65_TCP_PORT EQU $04 ;2 byte port number (to listen on, if ip address was 0.0.0.0, or connect to otherwise)
NB65_TCP_CALLBACK EQU $06 ;2 byte address of routine to be called whenever a new packet arrives
;offsets in TCP send parameter structure
NB65_TCP_PAYLOAD_LENGTH EQU $00 ;2 byte length of payload of packet (after all ethernet,IP,UDP/TCP headers)
NB65_TCP_PAYLOAD_POINTER EQU $02 ;2 byte pointer to payload of packet (after all headers)
;offsets in TCP/UDP packet parameter structure
NB65_REMOTE_IP EQU $00 ;4 byte IP address of remote machine (src of inbound packets, dest of outbound packets)
NB65_REMOTE_PORT EQU $04 ;2 byte port number of remote machine (src of inbound packets, dest of outbound packets)
NB65_LOCAL_PORT EQU $06 ;2 byte port number of local machine (src of outbound packets, dest of inbound packets)
NB65_PAYLOAD_LENGTH EQU $08 ;2 byte length of payload of packet (after all ethernet,IP,UDP/TCP headers)
; in a TCP connection, if the length is $FFFF, this actually means "end of connection"
NB65_PAYLOAD_POINTER EQU $0A ;2 byte pointer to payload of packet (after all headers)
;offsets in ICMP listener parameter structure
NB65_ICMP_LISTENER_TYPE EQU $00 ;ICMP type
NB65_ICMP_LISTENER_CALLBACK EQU $01 ;2 byte address of routine to call when ICMP packet of specified type arrives
;offsets in URL download structure
;inputs:
NB65_URL EQU $00 ;2 byte pointer to null terminated URL (NB - must be ASCII not "native" string)
NB65_URL_DOWNLOAD_BUFFER EQU $02 ;2 byte pointer to buffer that resource specified by URL will be downloaded into
NB65_URL_DOWNLOAD_BUFFER_LENGTH EQU $04 ;2 byte length of buffer (download will truncate when buffer is full)
;offsets in file access parameter structure (used by NB65_FILE_LOAD)
NB65_FILE_ACCESS_FILENAME EQU $00 ;2 byte pointer to asciiz filename (or filemask)
NB65_FILE_ACCESS_POINTER EQU $02 ;2 byte pointer to memory location data to be stored in OR address of callback function
NB65_FILE_ACCESS_FILESIZE EQU $04 ;2 byte file length (filled in by NB65_FILE_ACCESS)
NB65_FILE_ACCESS_DEVICE EQU $06 ;1 byte device number (set to $00 to use last accessed device)
;error codes (as returned by NB65_GET_LAST_ERROR)
NB65_ERROR_PORT_IN_USE EQU $80
NB65_ERROR_TIMEOUT_ON_RECEIVE EQU $81
NB65_ERROR_TRANSMIT_FAILED EQU $82
NB65_ERROR_TRANSMISSION_REJECTED_BY_PEER EQU $83
NB65_ERROR_INPUT_TOO_LARGE EQU $84
NB65_ERROR_DEVICE_FAILURE EQU $85
NB65_ERROR_ABORTED_BY_USER EQU $86
NB65_ERROR_LISTENER_NOT_AVAILABLE EQU $87
NB65_ERROR_NO_SUCH_LISTENER EQU $88
NB65_ERROR_CONNECTION_RESET_BY_PEER EQU $89
NB65_ERROR_CONNECTION_CLOSED EQU $8A
NB65_ERROR_FILE_ACCESS_FAILURE EQU $90
NB65_ERROR_MALFORMED_URL EQU $A0
NB65_ERROR_DNS_LOOKUP_FAILED EQU $A1
NB65_ERROR_OPTION_NOT_SUPPORTED EQU $FE
NB65_ERROR_FUNCTION_NOT_SUPPORTED EQU $FF

View File

@ -9,20 +9,20 @@ ping_retries: .res 1
ping_loop:
ldax #remote_host
jsr print
nb65call #NB65_INPUT_HOSTNAME
kippercall #KPR_INPUT_HOSTNAME
bcc @host_entered
;if no host entered, then bail.
rts
@host_entered:
stax nb65_param_buffer
stax kipper_param_buffer
jsr print_cr
ldax #resolving
jsr print
ldax nb65_param_buffer
nb65call #NB65_PRINT_ASCIIZ
ldax kipper_param_buffer
kippercall #KPR_PRINT_ASCIIZ
jsr print_cr
ldax #nb65_param_buffer
nb65call #NB65_DNS_RESOLVE
ldax #kipper_param_buffer
kippercall #KPR_DNS_RESOLVE
bcc @resolved_ok
@failed:
print_failed
@ -36,7 +36,7 @@ ping_loop:
@ping_once:
ldax #pinging
jsr print
ldax #nb65_param_buffer
ldax #kipper_param_buffer
jsr print_dotted_quad
lda #' '
jsr print_a
@ -45,8 +45,8 @@ ping_loop:
lda #' '
jsr print_a
ldax #nb65_param_buffer
nb65call #NB65_PING_HOST
ldax #kipper_param_buffer
kippercall #KPR_PING_HOST
bcs @ping_error
jsr print_integer

View File

@ -21,20 +21,20 @@ telnet_main_entry:
ldax #remote_host
jsr print
nb65call #NB65_INPUT_HOSTNAME
kippercall #KPR_INPUT_HOSTNAME
bcc @host_entered
;if no host entered, then bail.
jmp exit_telnet
@host_entered:
stax nb65_param_buffer
stax kipper_param_buffer
jsr print_cr
ldax #resolving
jsr print
ldax nb65_param_buffer
nb65call #NB65_PRINT_ASCIIZ
ldax kipper_param_buffer
kippercall #KPR_PRINT_ASCIIZ
jsr print_cr
ldax #nb65_param_buffer
nb65call #NB65_DNS_RESOLVE
ldax #kipper_param_buffer
kippercall #KPR_DNS_RESOLVE
bcc @resolved_ok
print_failed
jsr print_cr
@ -43,14 +43,14 @@ telnet_main_entry:
@resolved_ok:
ldx #3
@copy_telnet_ip_loop:
lda nb65_param_buffer,x
lda kipper_param_buffer,x
sta telnet_ip,x
dex
bpl @copy_telnet_ip_loop
@get_port:
ldax #remote_port
jsr print
nb65call #NB65_INPUT_PORT_NUMBER
kippercall #KPR_INPUT_PORT_NUMBER
bcc @port_entered
;if no port entered, then assume port 23
ldax #23

View File

@ -3,9 +3,9 @@
; Based on Doc Bacardi's tftp source
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.include "../inc/common.i"
@ -206,7 +206,7 @@ eth_tx:
sta cs_tx_len + 1
cmp #6
bmi :+
lda #NB65_ERROR_INPUT_TOO_LARGE
lda #KPR_ERROR_INPUT_TOO_LARGE
sta ip65_error
sec ; oversized packet
rts

View File

@ -10,9 +10,9 @@
MAX_DHCP_MESSAGES_SENT=12 ;timeout after sending 12 messages will be about 15 seconds (1+2+3...)/4
.include "../inc/common.i"
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.export dhcp_init
@ -159,7 +159,7 @@ dhcp_init:
jsr ip65_process
jsr check_for_abort_key
bcc @no_abort
lda #NB65_ERROR_ABORTED_BY_USER
lda #KPR_ERROR_ABORTED_BY_USER
sta ip65_error
rts
@no_abort:
@ -204,7 +204,7 @@ dhcp_init:
rts
@too_many_messages_sent:
lda #NB65_ERROR_TIMEOUT_ON_RECEIVE
lda #KPR_ERROR_TIMEOUT_ON_RECEIVE
sta ip65_error
jsr @bound ;to remove the listener ( thanks to ShadowM for bug report)
sec ;signal an error

View File

@ -3,9 +3,9 @@
MAX_DNS_MESSAGES_SENT=8 ;timeout after sending 8 messages will be about 7 seconds (1+2+3+4+5+6+7+8)/4
.include "../inc/common.i"
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.export dns_set_hostname
@ -175,7 +175,7 @@ dns_set_hostname:
rts
@hostname_too_long:
lda #NB65_ERROR_INPUT_TOO_LARGE
lda #KPR_ERROR_INPUT_TOO_LARGE
sta ip65_error
sec
rts
@ -225,7 +225,7 @@ dns_resolve:
jsr ip65_process
jsr check_for_abort_key
bcc @no_abort
lda #NB65_ERROR_ABORTED_BY_USER
lda #KPR_ERROR_ABORTED_BY_USER
sta ip65_error
rts
@no_abort:
@ -266,7 +266,7 @@ dns_resolve:
lda #53
ldx dns_client_port_low_byte
jsr udp_remove_listener
lda #NB65_ERROR_TIMEOUT_ON_RECEIVE
lda #KPR_ERROR_TIMEOUT_ON_RECEIVE
sta ip65_error
sec ;signal an error
rts
@ -293,7 +293,7 @@ send_dns_query:
sta output_buffer+dns_qname,x
inx
bpl @hostname_still_ok
lda #NB65_ERROR_INPUT_TOO_LARGE
lda #KPR_ERROR_INPUT_TOO_LARGE
sta ip65_error
jmp @error_on_send ;if we got past 128 bytes, there's a problem
@hostname_still_ok:

View File

@ -3,13 +3,14 @@
;this whole file could (and should) be greatly optimised by making it all table driven, but since this file is probably only going to be used in a bankswitched ROM where
;space is not at such a premium, I'll go with the gross hack for now.
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.include "../inc/common.i"
.include "../inc/commonprint.i"
.export nb65_dispatcher
.export kipper_dispatcher
.import ip65_init
.import dhcp_init
@ -45,7 +46,7 @@
.importzp copy_dest
;reuse the copy_src zero page location
nb65_params = copy_src
kipper_params = copy_src
buffer_ptr= copy_dest
.data
@ -62,7 +63,7 @@ ip_configured_flag:
.code
irq_handler:
jsr NB65_VBL_VECTOR
jsr KPR_VBL_VECTOR
jmp jmp_old_irq
@ -84,18 +85,18 @@ set_tftp_params:
dex
bpl :-
ldy #NB65_TFTP_FILENAME
lda (nb65_params),y
ldy #KPR_TFTP_FILENAME
lda (kipper_params),y
sta tftp_filename
iny
lda (nb65_params),y
lda (kipper_params),y
sta tftp_filename+1
ldy #NB65_TFTP_POINTER
lda (nb65_params),y
ldy #KPR_TFTP_POINTER
lda (kipper_params),y
sta tftp_load_address
iny
lda (nb65_params),y
lda (kipper_params),y
sta tftp_load_address+1
jsr tftp_clear_callbacks
@ -103,18 +104,18 @@ set_tftp_params:
rts
set_tftp_callback_vector:
ldy #NB65_TFTP_POINTER+1
lda (nb65_params),y
ldy #KPR_TFTP_POINTER+1
lda (kipper_params),y
tax
dey
lda (nb65_params),y
lda (kipper_params),y
jmp tftp_set_callback_vector
nb65_dispatcher:
stax nb65_params
kipper_dispatcher:
stax kipper_params
cpy #NB65_INITIALIZE
cpy #KPR_INITIALIZE
bne :+
lda ip_configured_flag
bne ip_configured
@ -140,33 +141,33 @@ ip_configured:
rts
:
cpy #NB65_GET_IP_CONFIG
cpy #KPR_GET_IP_CONFIG
bne :+
ldax #cfg_mac
clc
rts
:
cpy #NB65_DNS_RESOLVE
cpy #KPR_DNS_RESOLVE
bne :+
phax
ldy #NB65_DNS_HOSTNAME+1
lda (nb65_params),y
ldy #KPR_DNS_HOSTNAME+1
lda (kipper_params),y
tax
dey
lda (nb65_params),y
lda (kipper_params),y
jsr dns_set_hostname
bcs @dns_error
jsr dns_resolve
bcs @dns_error
ldy #NB65_DNS_HOSTNAME_IP
ldy #KPR_DNS_HOSTNAME_IP
plax
stax nb65_params
stax kipper_params
ldx #4
@copy_dns_ip:
lda dns_ip,y
sta (nb65_params),y
sta (kipper_params),y
iny
dex
bne @copy_dns_ip
@ -177,143 +178,138 @@ ip_configured:
:
cpy #NB65_UDP_ADD_LISTENER
cpy #KPR_UDP_ADD_LISTENER
bne :+
ldy #NB65_UDP_LISTENER_CALLBACK
lda (nb65_params),y
ldy #KPR_UDP_LISTENER_CALLBACK
lda (kipper_params),y
sta udp_callback
iny
lda (nb65_params),y
lda (kipper_params),y
sta udp_callback+1
ldy #NB65_UDP_LISTENER_PORT+1
lda (nb65_params),y
ldy #KPR_UDP_LISTENER_PORT+1
lda (kipper_params),y
tax
dey
lda (nb65_params),y
lda (kipper_params),y
jmp udp_add_listener
:
cpy #NB65_GET_INPUT_PACKET_INFO
cpy #KPR_GET_INPUT_PACKET_INFO
bne :+
ldy #3
@copy_src_ip:
lda ip_inp+12,y ;src IP
sta (nb65_params),y
sta (kipper_params),y
dey
bpl @copy_src_ip
ldy #NB65_REMOTE_PORT
ldy #KPR_REMOTE_PORT
lda udp_inp+1 ;src port (lo byte)
sta (nb65_params),y
sta (kipper_params),y
iny
lda udp_inp+0 ;src port (high byte)
sta (nb65_params),y
sta (kipper_params),y
iny
lda udp_inp+3 ;dest port (lo byte)
sta (nb65_params),y
sta (kipper_params),y
iny
lda udp_inp+2 ;dest port (high byte)
sta (nb65_params),y
sta (kipper_params),y
iny
sec
lda udp_inp+5 ;payload length (lo byte)
sbc #8 ;to remove length of header
sta (nb65_params),y
sta (kipper_params),y
iny
lda udp_inp+4 ;payload length (hi byte)
sbc #0 ;in case there was a carry from the lo byte
sta (nb65_params),y
sta (kipper_params),y
iny
lda #<(udp_inp+8) ;payload ptr (lo byte)
sta (nb65_params),y
sta (kipper_params),y
iny
lda #>(udp_inp+8) ;payload ptr (hi byte)
sta (nb65_params),y
sta (kipper_params),y
.ifdef API_VERSION
.if (API_VERSION>1)
.import tcp_inbound_data_ptr
.import tcp_inbound_data_length
;for API V2+, we need to check if this is a TCP packet
lda ip_inp+9 ;proto number
cmp #6 ;TCP
bne @not_tcp
ldy #NB65_PAYLOAD_LENGTH
ldy #KPR_PAYLOAD_LENGTH
lda tcp_inbound_data_length
sta (nb65_params),y
sta (kipper_params),y
iny
lda tcp_inbound_data_length+1
sta (nb65_params),y
sta (kipper_params),y
ldy #NB65_PAYLOAD_POINTER
ldy #KPR_PAYLOAD_POINTER
lda tcp_inbound_data_ptr
sta (nb65_params),y
sta (kipper_params),y
iny
lda tcp_inbound_data_ptr+1
sta (nb65_params),y
sta (kipper_params),y
@not_tcp:
.endif
.endif
clc
rts
:
cpy #NB65_SEND_UDP_PACKET
cpy #KPR_SEND_UDP_PACKET
bne :+
ldy #3
@copy_dest_ip:
lda (nb65_params),y
lda (kipper_params),y
sta udp_send_dest,y
dey
bpl @copy_dest_ip
ldy #NB65_REMOTE_PORT
lda (nb65_params),y
ldy #KPR_REMOTE_PORT
lda (kipper_params),y
sta udp_send_dest_port
iny
lda (nb65_params),y
lda (kipper_params),y
sta udp_send_dest_port+1
iny
lda (nb65_params),y
lda (kipper_params),y
sta udp_send_src_port
iny
lda (nb65_params),y
lda (kipper_params),y
sta udp_send_src_port+1
iny
lda (nb65_params),y
lda (kipper_params),y
sta udp_send_len
iny
lda (nb65_params),y
lda (kipper_params),y
sta udp_send_len+1
iny
;AX should point at data to send
lda (nb65_params),y
lda (kipper_params),y
pha
iny
lda (nb65_params),y
lda (kipper_params),y
tax
pla
jmp udp_send
:
cpy #NB65_UDP_REMOVE_LISTENER
cpy #KPR_UDP_REMOVE_LISTENER
bne :+
jmp udp_remove_listener
:
cpy #NB65_DEACTIVATE
cpy #KPR_DEACTIVATE
bne :+
ldax jmp_old_irq+1
sei ;don't want any interrupts while we fiddle with the vector
@ -325,11 +321,11 @@ ip_configured:
rts
:
cpy #NB65_TFTP_SET_SERVER
cpy #KPR_TFTP_SET_SERVER
bne :+
ldy #3
@copy_tftp_server_ip:
lda (nb65_params),y
lda (kipper_params),y
sta cfg_tftp_server,y
dey
bpl @copy_tftp_server_ip
@ -337,7 +333,7 @@ ip_configured:
rts
:
cpy #NB65_TFTP_DOWNLOAD
cpy #KPR_TFTP_DOWNLOAD
bne :+
phax
jsr set_tftp_params
@ -346,21 +342,21 @@ ip_configured:
@after_tftp_call: ;write the current load address back to the param buffer (so if $0000 was passed in, the caller can find out the actual value used)
plax
bcs @tftp_error
stax nb65_params
stax kipper_params
ldy #NB65_TFTP_POINTER
ldy #KPR_TFTP_POINTER
lda tftp_load_address
sta (nb65_params),y
sta (kipper_params),y
iny
lda tftp_load_address+1
sta (nb65_params),y
sta (kipper_params),y
ldy #NB65_TFTP_FILESIZE
ldy #KPR_TFTP_FILESIZE
lda tftp_filesize
sta (nb65_params),y
sta (kipper_params),y
iny
lda tftp_filesize+1
sta (nb65_params),y
sta (kipper_params),y
clc
@tftp_error:
rts
@ -368,7 +364,7 @@ ip_configured:
cpy #NB65_TFTP_CALLBACK_DOWNLOAD
cpy #KPR_TFTP_CALLBACK_DOWNLOAD
bne :+
phax
jsr set_tftp_params
@ -377,103 +373,99 @@ ip_configured:
jmp @after_tftp_call
:
cpy #NB65_TFTP_UPLOAD
cpy #KPR_TFTP_UPLOAD
bne :+
phax
jsr set_tftp_params
ldy #NB65_TFTP_POINTER
lda (nb65_params),y
ldy #KPR_TFTP_POINTER
lda (kipper_params),y
sta tftp_filesize
iny
lda (nb65_params),y
lda (kipper_params),y
sta tftp_filesize+1
jsr tftp_download
jmp @after_tftp_call
:
cpy #NB65_TFTP_CALLBACK_UPLOAD
cpy #KPR_TFTP_CALLBACK_UPLOAD
bne :+
jsr set_tftp_params
jsr set_tftp_callback_vector
jmp tftp_upload
:
cpy #NB65_PRINT_ASCIIZ
cpy #KPR_PRINT_ASCIIZ
bne :+
jsr print
clc
rts
:
cpy #NB65_PRINT_HEX
cpy #KPR_PRINT_HEX
bne :+
jsr print_hex
clc
rts
:
cpy #NB65_PRINT_DOTTED_QUAD
cpy #KPR_PRINT_DOTTED_QUAD
bne :+
jsr print_dotted_quad
clc
rts
:
cpy #NB65_PRINT_IP_CONFIG
cpy #KPR_PRINT_IP_CONFIG
bne :+
jsr print_ip_config
clc
rts
:
cpy #NB65_PRINT_INTEGER
cpy #KPR_PRINT_INTEGER
bne :+
jsr print_integer
clc
rts
:
;these are the API "version 2" functions
.ifdef API_VERSION
.if (API_VERSION>1)
.segment "TCP_VARS"
port_number: .res 2
nonzero_octets: .res 1
.code
cpy #NB65_DOWNLOAD_RESOURCE
cpy #KPR_DOWNLOAD_RESOURCE
bne :+
.import url_download
.import url_download_buffer
.import url_download_buffer_length
ldy #NB65_URL_DOWNLOAD_BUFFER
lda (nb65_params),y
ldy #KPR_URL_DOWNLOAD_BUFFER
lda (kipper_params),y
sta url_download_buffer
iny
lda (nb65_params),y
lda (kipper_params),y
sta url_download_buffer+1
ldy #NB65_URL_DOWNLOAD_BUFFER_LENGTH
lda (nb65_params),y
ldy #KPR_URL_DOWNLOAD_BUFFER_LENGTH
lda (kipper_params),y
sta url_download_buffer_length
iny
lda (nb65_params),y
lda (kipper_params),y
sta url_download_buffer_length+1
ldy #NB65_URL+1
lda (nb65_params),y
ldy #KPR_URL+1
lda (kipper_params),y
tax
dey
lda (nb65_params),y
lda (kipper_params),y
jmp url_download
:
cpy #NB65_FILE_LOAD
cpy #KPR_FILE_LOAD
bne :+
.import io_device_no
.import io_read_file
@ -481,60 +473,60 @@ bne :+
.import io_filesize
.import io_load_address
phax
ldy #NB65_FILE_ACCESS_FILENAME
lda (nb65_params),y
ldy #KPR_FILE_ACCESS_FILENAME
lda (kipper_params),y
sta io_filename
iny
lda (nb65_params),y
lda (kipper_params),y
sta io_filename+1
ldy #NB65_FILE_ACCESS_DEVICE
lda (nb65_params),y
ldy #KPR_FILE_ACCESS_DEVICE
lda (kipper_params),y
sta io_device_no
ldy #NB65_FILE_ACCESS_POINTER+1
lda (nb65_params),y
ldy #KPR_FILE_ACCESS_POINTER+1
lda (kipper_params),y
tax
dey
lda (nb65_params),y
lda (kipper_params),y
jsr io_read_file
plax
bcc @read_file_ok
rts
@read_file_ok:
stax nb65_params
stax kipper_params
ldy #NB65_FILE_ACCESS_POINTER
ldy #KPR_FILE_ACCESS_POINTER
lda io_load_address
sta (nb65_params),y
sta (kipper_params),y
iny
lda io_load_address+1
sta (nb65_params),y
sta (kipper_params),y
ldy #NB65_FILE_ACCESS_FILESIZE
ldy #KPR_FILE_ACCESS_FILESIZE
lda io_filesize
sta (nb65_params),y
sta (kipper_params),y
iny
lda io_filesize+1
sta (nb65_params),y
sta (kipper_params),y
rts
:
cpy #NB65_PING_HOST
cpy #KPR_PING_HOST
.import icmp_echo_ip
.import icmp_ping
bne :+
ldy #3
@copy_ping_ip_loop:
lda (nb65_params),y
lda (kipper_params),y
sta icmp_echo_ip,y
dey
bpl @copy_ping_ip_loop
jmp icmp_ping
:
cpy #NB65_TCP_CONNECT
cpy #KPR_TCP_CONNECT
bne :+
.import tcp_connect
.import tcp_callback
@ -544,7 +536,7 @@ bne :+
lda #0
sta nonzero_octets
@copy_dest_ip:
lda (nb65_params),y
lda (kipper_params),y
beq @octet_was_zero
inc nonzero_octets
@octet_was_zero:
@ -552,18 +544,18 @@ bne :+
dey
bpl @copy_dest_ip
ldy #NB65_TCP_CALLBACK
lda (nb65_params),y
ldy #KPR_TCP_CALLBACK
lda (kipper_params),y
sta tcp_callback
iny
lda (nb65_params),y
lda (kipper_params),y
sta tcp_callback+1
ldy #NB65_TCP_PORT+1
lda (nb65_params),y
ldy #KPR_TCP_PORT+1
lda (kipper_params),y
tax
dey
lda (nb65_params),y
lda (kipper_params),y
ldy nonzero_octets
bne @outbound_tcp_connection
jmp tcp_listen
@ -575,26 +567,26 @@ bne :+
.import tcp_send
.import tcp_send_data_len
cpy #NB65_SEND_TCP_PACKET
cpy #KPR_SEND_TCP_PACKET
bne :+
ldy #NB65_TCP_PAYLOAD_LENGTH
lda (nb65_params),y
ldy #KPR_TCP_PAYLOAD_LENGTH
lda (kipper_params),y
sta tcp_send_data_len
iny
lda (nb65_params),y
lda (kipper_params),y
sta tcp_send_data_len+1
ldy #NB65_TCP_PAYLOAD_POINTER+1
lda (nb65_params),y
ldy #KPR_TCP_PAYLOAD_POINTER+1
lda (kipper_params),y
tax
dey
lda (nb65_params),y
lda (kipper_params),y
jmp tcp_send
:
.import tcp_close
cpy #NB65_TCP_CLOSE_CONNECTION
cpy #KPR_TCP_CLOSE_CONNECTION
bne :+
jmp tcp_close
:
@ -604,21 +596,21 @@ bne :+
.import get_filtered_input
.import filter_number
cpy #NB65_INPUT_STRING
cpy #KPR_INPUT_STRING
bne :+
ldy #40 ;max chars
ldax #$0000
jmp get_filtered_input
:
cpy #NB65_INPUT_HOSTNAME
cpy #KPR_INPUT_HOSTNAME
bne :+
ldy #40 ;max chars
ldax #filter_dns
jmp get_filtered_input
:
cpy #NB65_INPUT_PORT_NUMBER
cpy #KPR_INPUT_PORT_NUMBER
bne :+
ldy #5 ;max chars
ldax #filter_number
@ -633,7 +625,7 @@ cpy #NB65_INPUT_PORT_NUMBER
rts
:
cpy #NB65_BLOCK_COPY
cpy #KPR_BLOCK_COPY
bne :+
;this is where we pay the price for trying to save a few 'zero page' pointers
;by reusing the 'copy_src' and 'copy_dest' addresses!
@ -643,25 +635,25 @@ cpy #NB65_BLOCK_COPY
tmp_copy_length: .res 2
.code
ldy #NB65_BLOCK_SRC
lda (nb65_params),y
ldy #KPR_BLOCK_SRC
lda (kipper_params),y
sta tmp_copy_src
iny
lda (nb65_params),y
lda (kipper_params),y
sta tmp_copy_src+1
ldy #NB65_BLOCK_DEST
lda (nb65_params),y
ldy #KPR_BLOCK_DEST
lda (kipper_params),y
sta tmp_copy_dest
iny
lda (nb65_params),y
lda (kipper_params),y
sta tmp_copy_dest+1
ldy #NB65_BLOCK_SIZE
lda (nb65_params),y
ldy #KPR_BLOCK_SIZE
lda (kipper_params),y
sta tmp_copy_length
iny
lda (nb65_params),y
lda (kipper_params),y
sta tmp_copy_length+1
ldax tmp_copy_src
@ -672,22 +664,21 @@ cpy #NB65_BLOCK_COPY
jmp copymem
:
cpy #NB65_PARSER_INIT
cpy #KPR_PARSER_INIT
bne :+
.import parser_init
jmp parser_init
:
cpy #NB65_PARSER_SKIP_NEXT
cpy #KPR_PARSER_SKIP_NEXT
bne :+
.import parser_skip_next
jmp parser_skip_next
:
.endif
.endif
cpy #NB65_GET_LAST_ERROR
cpy #KPR_GET_LAST_ERROR
bne :+
lda ip65_error
clc
@ -696,7 +687,7 @@ cpy #NB65_BLOCK_COPY
;default function handler
lda #NB65_ERROR_FUNCTION_NOT_SUPPORTED
lda #KPR_ERROR_FUNCTION_NOT_SUPPORTED
sta ip65_error
sec ;carry flag set = error
rts

View File

@ -2,9 +2,9 @@
;
.include "../inc/common.i"
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.export icmp_init
@ -381,7 +381,7 @@ icmp_ping:
jsr icmp_send_echo
bcc @message_sent_ok
;still can't send? then give up
lda #NB65_ERROR_TRANSMIT_FAILED
lda #KPR_ERROR_TRANSMIT_FAILED
sta ip65_error
rts
@message_sent_ok:
@ -412,7 +412,7 @@ icmp_ping:
jsr timer_timeout
bcs @loop_till_get_ping_response
lda #NB65_ERROR_TIMEOUT_ON_RECEIVE
lda #KPR_ERROR_TIMEOUT_ON_RECEIVE
sta ip65_error
lda #icmp_msg_type_echo_reply
jsr icmp_remove_listener

View File

@ -2,9 +2,9 @@
.include "../inc/common.i"
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.export ip65_init
@ -81,7 +81,7 @@ ip65_init:
jsr eth_init ; initialize ethernet driver
bcc @ok
lda #NB65_ERROR_DEVICE_FAILURE
lda #KPR_ERROR_DEVICE_FAILURE
sta ip65_error
rts
@ok:

View File

@ -12,9 +12,9 @@ target_string=copy_src
search_string=copy_dest
.include "../inc/common.i"
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.bss

190
client/ip65/sntp.s Normal file
View File

@ -0,0 +1,190 @@
; Simple Network Time Protocol implementation - per RFC 2030
MAX_SNTP_MESSAGES_SENT=8
.include "../inc/common.i"
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/kipper_constants.i"
.endif
.export sntp_ip
.export sntp_utc_timestamp
.export sntp_get_time
.import ip65_process
.import ip65_error
.import udp_add_listener
.import udp_remove_listener
.import udp_callback
.import udp_send
.import udp_inp
.import output_buffer
.importzp udp_data
.import udp_send_dest
.import udp_send_src_port
.import udp_send_dest_port
.import udp_send_len
.import check_for_abort_key
.import timer_read
.segment "IP65ZP" : zeropage
.data
sntp_ip: .byte $ff,$ff,$ff,$ff ;can be set to ip address of server that will be queried via sntp (default is a local LAN broadcast)
.bss
; sntp packet offsets
sntp_inp = udp_inp + udp_data
sntp_server_port=123
sntp_client_port=55123
sntp_utc_timestamp: .res 4 ; will be set to seconds (only) part of utc timestamp (seconds since 00:00 on Jan 1, 1900)
; sntp state machine
sntp_initializing = 1 ; initial state
sntp_query_sent = 2 ; sent a query, waiting for a response
sntp_completed = 3 ; got a good response
sntp_timer: .res 1
sntp_loop_count: .res 1
sntp_break_polling_loop: .res 1
sntp_state: .res 1
sntp_message_sent_count: .res 1
.code
; query an sntp server for current UTC time
; inputs:
; sntp_ip must point to an SNTP server
; outputs:
; carry flag is set if there was an error, clear otherwise
; sntp_utc_timestamp: set to the number of seconds (seconds since 00:00 on Jan 1, 1900) - timezone is UTC
sntp_get_time:
ldax #sntp_in
stax udp_callback
ldax #sntp_client_port
jsr udp_add_listener
bcc :+
rts
:
lda #sntp_initializing
sta sntp_state
lda #0 ;reset the "message sent" counter
sta sntp_message_sent_count
jsr send_sntp_query
@sntp_polling_loop:
lda sntp_message_sent_count
adc #1
sta sntp_loop_count ;we wait a bit longer between each resend
@outer_delay_loop:
lda #0
sta sntp_break_polling_loop
jsr timer_read
stx sntp_timer ;we only care about the high byte
@inner_delay_loop:
jsr ip65_process
jsr check_for_abort_key
bcc @no_abort
lda #KPR_ERROR_ABORTED_BY_USER
sta ip65_error
rts
@no_abort:
lda sntp_state
cmp #sntp_completed
beq @complete
lda sntp_break_polling_loop
bne @break_polling_loop
jsr timer_read
cpx sntp_timer ;this will tick over after about 1/4 of a second
beq @inner_delay_loop
dec sntp_loop_count
bne @outer_delay_loop
@break_polling_loop:
jsr send_sntp_query
inc sntp_message_sent_count
lda sntp_message_sent_count
cmp #MAX_SNTP_MESSAGES_SENT-1
bpl @too_many_messages_sent
jmp @sntp_polling_loop
@complete:
ldax #sntp_client_port
jsr udp_remove_listener
rts
@too_many_messages_sent:
@failed:
ldax #sntp_client_port
jsr udp_remove_listener
lda #KPR_ERROR_TIMEOUT_ON_RECEIVE
sta ip65_error
sec ;signal an error
rts
send_sntp_query:
lda #$1B ;LI=00, VN=011,MODE=011
stax output_buffer
lda #$0
ldx #$30 ;pad remainder of query packet with 0 bytes
stx udp_send_len
sta udp_send_len+1
:
sta output_buffer+1,x
dex
bpl :-
ldax #sntp_client_port
stax udp_send_src_port
ldax #sntp_server_port
stax udp_send_dest_port
ldx #3 ; set destination address
: lda sntp_ip,x
sta udp_send_dest,x
dex
bpl :-
ldax #output_buffer
jsr udp_send
bcs @error_on_send
lda #sntp_query_sent
sta sntp_state
@error_on_send:
rts
sntp_in:
ldx #3
ldy #0
:
lda sntp_inp+$28,x ;the 'transmit' timestamp (in big end order)
sta sntp_utc_timestamp,y
iny
dex
bpl :-
inc sntp_break_polling_loop
lda #sntp_completed
sta sntp_state
rts

View File

@ -9,9 +9,9 @@
MAX_TCP_PACKETS_SENT=8 ;timeout after sending 8 messages will be about 7 seconds (1+2+3+4+5+6+7+8)/4
.include "../inc/common.i"
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.import ip65_error
@ -181,7 +181,7 @@ tcp_listen:
jsr ip65_process
jsr check_for_abort_key
bcc @no_abort
lda #NB65_ERROR_ABORTED_BY_USER
lda #KPR_ERROR_ABORTED_BY_USER
sta ip65_error
rts
@no_abort:
@ -248,7 +248,7 @@ tcp_connect:
jsr ip65_process
jsr check_for_abort_key
bcc @no_abort
lda #NB65_ERROR_ABORTED_BY_USER
lda #KPR_ERROR_ABORTED_BY_USER
sta ip65_error
rts
@no_abort:
@ -274,7 +274,7 @@ tcp_connect:
@failed:
lda #tcp_cxn_state_closed
sta tcp_state
lda #NB65_ERROR_TIMEOUT_ON_RECEIVE
lda #KPR_ERROR_TIMEOUT_ON_RECEIVE
sta ip65_error
sec ;signal an error
rts
@ -363,7 +363,7 @@ tcp_close:
@failed:
lda #tcp_cxn_state_closed
sta tcp_state
lda #NB65_ERROR_TIMEOUT_ON_RECEIVE
lda #KPR_ERROR_TIMEOUT_ON_RECEIVE
sta ip65_error
sec ;signal an error
rts
@ -410,7 +410,7 @@ tcp_send:
lda tcp_state
cmp #tcp_cxn_state_established
beq @connection_established
lda #NB65_ERROR_CONNECTION_CLOSED
lda #KPR_ERROR_CONNECTION_CLOSED
sta ip65_error
sec
rts
@ -462,7 +462,7 @@ tcp_send:
jsr ip65_process
jsr check_for_abort_key
bcc @no_abort
lda #NB65_ERROR_ABORTED_BY_USER
lda #KPR_ERROR_ABORTED_BY_USER
sta ip65_error
rts
@no_abort:
@ -491,7 +491,7 @@ tcp_send:
@failed:
lda #tcp_cxn_state_closed
sta tcp_state
lda #NB65_ERROR_TIMEOUT_ON_RECEIVE
lda #KPR_ERROR_TIMEOUT_ON_RECEIVE
sta ip65_error
sec ;signal an error
rts
@ -690,7 +690,7 @@ tcp_process:
;connection has been reset so mark it as closed
lda #tcp_cxn_state_closed
sta tcp_state
lda #NB65_ERROR_CONNECTION_RESET_BY_PEER
lda #KPR_ERROR_CONNECTION_RESET_BY_PEER
sta ip65_error
lda #$ff

View File

@ -6,9 +6,9 @@
TFTP_TIMER_MASK=$F8 ;mask lower two bits, means we wait for 8 x1/4 seconds
.include "../inc/common.i"
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.exportzp tftp_filename
@ -169,7 +169,7 @@ set_tftp_opcode:
jsr udp_add_listener
bcc :+ ;bail if we couldn't listen on the port we want
lda #NB65_ERROR_PORT_IN_USE
lda #KPR_ERROR_PORT_IN_USE
sta ip65_error
rts
:
@ -222,7 +222,7 @@ set_tftp_opcode:
jsr ip65_process
jsr check_for_abort_key
bcc @no_abort
lda #NB65_ERROR_ABORTED_BY_USER
lda #KPR_ERROR_ABORTED_BY_USER
sta ip65_error
jmp @exit_with_error
@no_abort:
@ -236,7 +236,7 @@ set_tftp_opcode:
dec tftp_resend_counter
bne @outer_delay_loop
lda #NB65_ERROR_TIMEOUT_ON_RECEIVE
lda #KPR_ERROR_TIMEOUT_ON_RECEIVE
sta ip65_error
jmp @exit_with_error
@ -288,7 +288,7 @@ send_request_packet:
sta tftp_state
rts
@error_in_send:
lda #NB65_ERROR_TRANSMIT_FAILED
lda #KPR_ERROR_TRANSMIT_FAILED
sta ip65_error
sec
rts
@ -355,7 +355,7 @@ tftp_in:
@recv_error:
lda #tftp_error
sta tftp_state
lda #NB65_ERROR_TRANSMISSION_REJECTED_BY_PEER
lda #KPR_ERROR_TRANSMISSION_REJECTED_BY_PEER
sta ip65_error
rts
@not_an_error:

View File

@ -1,9 +1,9 @@
;UDP (user datagram protocol) functions
.include "../inc/common.i"
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
;.import dbg_dump_udp_header
@ -136,7 +136,7 @@ udp_process:
bpl @checkport
@drop:
lda #NB65_ERROR_NO_SUCH_LISTENER
lda #KPR_ERROR_NO_SUCH_LISTENER
sta ip65_error
sec
rts
@ -190,7 +190,7 @@ udp_add_listener:
rts
@full:
@busy:
lda #NB65_ERROR_LISTENER_NOT_AVAILABLE
lda #KPR_ERROR_LISTENER_NOT_AVAILABLE
sta ip65_error
sec
sec

View File

@ -3,9 +3,9 @@
.include "../inc/common.i"
.ifndef NB65_API_VERSION_NUMBER
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
TIMEOUT_SECONDS=15
@ -109,7 +109,7 @@ url_parse:
cmp #'H'
beq @http
@exit_with_error:
lda #NB65_ERROR_MALFORMED_URL
lda #KPR_ERROR_MALFORMED_URL
sta ip65_error
@exit_with_sec:
sec
@ -134,7 +134,7 @@ lda #url_type_gopher
bcs @exit_with_sec
jsr dns_resolve
bcc :+
lda #NB65_ERROR_DNS_LOOKUP_FAILED
lda #KPR_ERROR_DNS_LOOKUP_FAILED
sta ip65_error
jmp @exit_with_sec
:
@ -353,7 +353,7 @@ resource_download:
rts
lda #NB65_ERROR_FILE_ACCESS_FAILURE
lda #KPR_ERROR_FILE_ACCESS_FAILURE
sta ip65_error
sec
rts

View File

@ -1 +1 @@
start c:\temp\WinVICE-2.1\x64.exe -cart16 nb65\nb65_tcp_cart.bin
start c:\temp\WinVICE-2.1\x64.exe -cart16 nb65\kippernet.bin

View File

@ -1,7 +1,7 @@
;test the "NETBOOT65 Cartridge API"
.ifndef NB65_API_VERSION_NUMBER
;test the "Kipper Kartridge API"
.ifndef KPR_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.include "../ip65/copymem.s"
@ -34,7 +34,7 @@ print_a = $ffd2
temp_ptr: .res 2
.bss
nb65_param_buffer: .res $20
kipper_param_buffer: .res $20
block_number: .res $0
.segment "STARTUP" ;this is what gets put at the start of the file on the C64
@ -43,8 +43,8 @@ print_a = $ffd2
.macro print arg
ldax arg
ldy #NB65_PRINT_ASCIIZ
jsr NB65_DISPATCH_VECTOR
ldy #KPR_PRINT_ASCIIZ
jsr KPR_DISPATCH_VECTOR
.endmacro
.macro print_cr
@ -54,7 +54,7 @@ print_a = $ffd2
.macro call arg
ldy arg
jsr NB65_DISPATCH_VECTOR
jsr KPR_DISPATCH_VECTOR
.endmacro
basicstub:
@ -70,13 +70,13 @@ basicstub:
.word 0
;look for NB65 signature at location pointed at by AX
;look for KIPPER signature at location pointed at by AX
look_for_signature:
stax temp_ptr
ldy #3
ldy #5
@check_one_byte:
lda (temp_ptr),y
cmp nb65_signature,y
cmp kipper_signature,y
bne @bad_match
dey
bpl@check_one_byte
@ -89,23 +89,17 @@ look_for_signature:
init:
ldax #NB65_CART_SIGNATURE ;where signature should be in cartridge
ldax #KPR_CART_SIGNATURE ;where signature should be in cartridge
jsr look_for_signature
bcc @found_nb65_signature
ldax #NB65_RAM_STUB_SIGNATURE ;where signature should be in RAM
jsr look_for_signature
bcc :+
jmp nb65_signature_not_found
:
jsr NB65_RAM_STUB_ACTIVATE ;we need to turn on NB65 cartridge
bcc @found_kipper_signature
jmp kipper_signature_not_found
@found_nb65_signature:
@found_kipper_signature:
print #initializing
ldy #NB65_INITIALIZE
jsr NB65_DISPATCH_VECTOR
ldy #KPR_INITIALIZE
jsr KPR_DISPATCH_VECTOR
bcc :+
print #failed
jsr print_errorcode
@ -115,32 +109,32 @@ init:
print #ok
print_cr
call #NB65_PRINT_IP_CONFIG
call #KPR_PRINT_IP_CONFIG
;DNS resolution test
ldax #test_hostname
stax nb65_param_buffer+NB65_DNS_HOSTNAME
stax kipper_param_buffer+KPR_DNS_HOSTNAME
call #NB65_PRINT_ASCIIZ
call #KPR_PRINT_ASCIIZ
cout #' '
cout #':'
cout #' '
ldax #nb65_param_buffer
call #NB65_DNS_RESOLVE
ldax #kipper_param_buffer
call #KPR_DNS_RESOLVE
bcc :+
print #dns_lookup_failed_msg
print_cr
jmp print_errorcode
:
ldax #nb65_param_buffer+NB65_DNS_HOSTNAME_IP
call #NB65_PRINT_DOTTED_QUAD
ldax #kipper_param_buffer+KPR_DNS_HOSTNAME_IP
call #KPR_PRINT_DOTTED_QUAD
print_cr
ldax #64
call #NB65_UDP_REMOVE_LISTENER ;should generate an error since there is no listener on port 64
call #KPR_UDP_REMOVE_LISTENER ;should generate an error since there is no listener on port 64
jsr print_errorcode
@ -148,11 +142,11 @@ init:
lda #0
sta block_number
ldax #test_file
stax nb65_param_buffer+NB65_TFTP_FILENAME
stax kipper_param_buffer+KPR_TFTP_FILENAME
ldax #tftp_upload_callback
stax nb65_param_buffer+NB65_TFTP_POINTER
ldax #nb65_param_buffer
call #NB65_TFTP_CALLBACK_UPLOAD
stax kipper_param_buffer+KPR_TFTP_POINTER
ldax #kipper_param_buffer
call #KPR_TFTP_CALLBACK_UPLOAD
bcc :+
jmp print_errorcode
:
@ -163,19 +157,19 @@ init:
lda #0
sta block_number
ldax #test_file
stax nb65_param_buffer+NB65_TFTP_FILENAME
stax kipper_param_buffer+KPR_TFTP_FILENAME
ldax #tftp_download_callback
stax nb65_param_buffer+NB65_TFTP_POINTER
ldax #nb65_param_buffer
call #NB65_TFTP_CALLBACK_DOWNLOAD
stax kipper_param_buffer+KPR_TFTP_POINTER
ldax #kipper_param_buffer
call #KPR_TFTP_CALLBACK_DOWNLOAD
bcc :+
jmp print_errorcode
:
lda #'$'
jsr print_a
lda nb65_param_buffer+NB65_TFTP_FILESIZE+1
lda kipper_param_buffer+KPR_TFTP_FILESIZE+1
jsr print_hex
lda nb65_param_buffer+NB65_TFTP_FILESIZE
lda kipper_param_buffer+KPR_TFTP_FILESIZE
jsr print_hex
print #bytes_download
print_cr
@ -183,11 +177,11 @@ init:
;udp callback test
ldax #64 ;listen on port 64
stax nb65_param_buffer+NB65_UDP_LISTENER_PORT
stax kipper_param_buffer+KPR_UDP_LISTENER_PORT
ldax #udp_callback
stax nb65_param_buffer+NB65_UDP_LISTENER_CALLBACK
ldax #nb65_param_buffer
call #NB65_UDP_ADD_LISTENER
stax kipper_param_buffer+KPR_UDP_LISTENER_CALLBACK
ldax #kipper_param_buffer
call #KPR_UDP_ADD_LISTENER
bcc :+
print #failed
jsr print_errorcode
@ -198,7 +192,7 @@ init:
@loop_forever:
jsr NB65_PERIODIC_PROCESSING_VECTOR
jsr KPR_PERIODIC_PROCESSING_VECTOR
jmp @loop_forever
@ -239,49 +233,49 @@ tftp_download_callback:
udp_callback:
ldax #nb65_param_buffer
call #NB65_GET_INPUT_PACKET_INFO
ldax #kipper_param_buffer
call #KPR_GET_INPUT_PACKET_INFO
print #port
lda nb65_param_buffer+NB65_LOCAL_PORT+1
call #NB65_PRINT_HEX
lda kipper_param_buffer+KPR_LOCAL_PORT+1
call #KPR_PRINT_HEX
lda nb65_param_buffer+NB65_LOCAL_PORT
call #NB65_PRINT_HEX
lda kipper_param_buffer+KPR_LOCAL_PORT
call #KPR_PRINT_HEX
print_cr
print #received
print #from
ldax #nb65_param_buffer+NB65_REMOTE_IP
call #NB65_PRINT_DOTTED_QUAD
ldax #kipper_param_buffer+KPR_REMOTE_IP
call #KPR_PRINT_DOTTED_QUAD
cout #' '
print #port
lda nb65_param_buffer+NB65_REMOTE_PORT+1
call #NB65_PRINT_HEX
lda nb65_param_buffer+NB65_REMOTE_PORT
call #NB65_PRINT_HEX
lda kipper_param_buffer+KPR_REMOTE_PORT+1
call #KPR_PRINT_HEX
lda kipper_param_buffer+KPR_REMOTE_PORT
call #KPR_PRINT_HEX
print_cr
print #length
lda nb65_param_buffer+NB65_PAYLOAD_LENGTH+1
call #NB65_PRINT_HEX
lda nb65_param_buffer+NB65_PAYLOAD_LENGTH
call #NB65_PRINT_HEX
lda kipper_param_buffer+KPR_PAYLOAD_LENGTH+1
call #KPR_PRINT_HEX
lda kipper_param_buffer+KPR_PAYLOAD_LENGTH
call #KPR_PRINT_HEX
print_cr
print #data
ldax nb65_param_buffer+NB65_PAYLOAD_POINTER
ldax kipper_param_buffer+KPR_PAYLOAD_POINTER
stax temp_ptr
ldx nb65_param_buffer+NB65_PAYLOAD_LENGTH ;assumes length is < 255
ldx kipper_param_buffer+KPR_PAYLOAD_LENGTH ;assumes length is < 255
ldy #0
:
lda (temp_ptr),y
@ -294,13 +288,13 @@ udp_callback:
;make and send reply
ldax #reply_message
stax nb65_param_buffer+NB65_PAYLOAD_POINTER
stax kipper_param_buffer+KPR_PAYLOAD_POINTER
ldax #reply_message_length
stax nb65_param_buffer+NB65_PAYLOAD_LENGTH
stax kipper_param_buffer+KPR_PAYLOAD_LENGTH
ldax #nb65_param_buffer
call #NB65_SEND_UDP_PACKET
ldax #kipper_param_buffer
call #KPR_SEND_UDP_PACKET
bcc :+
jmp print_errorcode
:
@ -316,16 +310,16 @@ restart:
print_errorcode:
print #error_code
call #NB65_GET_LAST_ERROR
call #NB65_PRINT_HEX
call #KPR_GET_LAST_ERROR
call #KPR_PRINT_HEX
print_cr
rts
nb65_signature_not_found:
kipper_signature_not_found:
ldy #0
:
lda nb65_signature_not_found_message,y
lda kipper_signature_not_found_message,y
beq restart
jsr print_a
iny
@ -407,8 +401,8 @@ failed:
ok:
.byte "OK ", 0
nb65_signature_not_found_message:
.byte "NO NB65 API FOUND",13,"PRESS ANY KEY TO RESET", 0
kipper_signature_not_found_message:
.byte "NO KIPPER API FOUND",13,"PRESS ANY KEY TO RESET", 0
dns_lookup_failed_msg:
.byte "DNS LOOKUP FAILED", 0
@ -423,5 +417,5 @@ reply_message_length=reply_message_end-reply_message
test_file:
.byte "TESTFILE.BIN",0
nb65_signature:
.byte $4E,$42,$36,$35 ; "NB65" - API signature
kipper_signature:
.byte "KIPPER" ; API signature

View File

@ -1,7 +1,7 @@
.ifndef NB65_API_VERSION_NUMBER
.ifndef KIPPER_API_VERSION_NUMBER
.define EQU =
.include "../inc/nb65_constants.i"
.include "../inc/kipper_constants.i"
.endif
.include "../inc/common.i"

195
client/test/test_sntp.s Normal file
View File

@ -0,0 +1,195 @@
.include "../inc/common.i"
.include "../inc/commonprint.i"
.include "../inc/net.i"
.import exit_to_basic
.import cfg_get_configuration_ptr
.import dns_set_hostname
.import dns_resolve
.import dns_ip
.import dns_status
.import sntp_ip
.import sntp_utc_timestamp
.import sntp_get_time
.import __CODE_LOAD__
.import __CODE_SIZE__
.import __RODATA_SIZE__
.import __DATA_SIZE__
.segment "STARTUP" ;this is what gets put at the start of the file on the C64
.word basicstub ; load address
basicstub:
.word @nextline
.word 2003
.byte $9e
.byte <(((init / 1000) .mod 10) + $30)
.byte <(((init / 100 ) .mod 10) + $30)
.byte <(((init / 10 ) .mod 10) + $30)
.byte <(((init ) .mod 10) + $30)
.byte 0
@nextline:
.word 0
.segment "EXEHDR" ;this is what gets put an the start of the file on the Apple 2
.addr __CODE_LOAD__-$11 ; Start address
.word __CODE_SIZE__+__RODATA_SIZE__+__DATA_SIZE__+4 ; Size
jmp init
.code
init:
jsr test_vlb
jsr print_cr
init_ip_via_dhcp
jsr print_ip_config
ldax #time_server_msg
jsr print
ldax #time_server_host
jsr print
jsr print_cr
ldax #time_server_host
jsr dns_set_hostname
bcs @dns_error
jsr dns_resolve
bcs @dns_error
ldx #3 ; set destination address
: lda dns_ip,x
sta sntp_ip,x
dex
bpl :-
ldax #sending_query
jsr print
ldax #sntp_ip
jsr print_dotted_quad
jsr print_cr
jsr sntp_get_time
bcc @ok
ldax #sntp_error
jmp @print_error
@ok:
ldy #3
:
lda sntp_utc_timestamp,y
jsr print_hex
dey
bpl :-
jmp exit_to_basic
@dns_error:
ldax #dns_error
@print_error:
jsr print
jsr print_errorcode
jmp exit_to_basic
.bss
vla: .res 4
vlb: .res 4
quotient: .res 4
remainder: .res 4
.code
div_32_32:
lda #0
sta remainder
sta remainder+1
sta remainder+2
sta remainder+3
ldx #32
@loop:
asl vla
rol vla+1
rol vla+2
rol vla+3
rol remainder
rol remainder+1
rol remainder+2
rol remainder+3
sec
lda remainder+0
sbc vlb+0
sta remainder+0
lda remainder+1
sbc vlb+1
sta remainder+1
lda remainder+2
sbc vlb+2
sta remainder+2
lda remainder+3
sbc vlb+3
sta remainder+3
bcs @next
lda remainder
adc vlb
sta remainder
lda remainder+1
adc vlb+1
sta remainder+1
lda remainder+2
adc vlb+2
sta remainder+2
lda remainder+3
adc vlb+3
sta remainder+3
@next:
rol quotient
rol quotient+1
rol quotient+2
rol quotient+3
dex
bpl @loop
rts
.rodata
test_vlb:
ldx #7
:
lda divs,x
sta vla,x
dex
bpl :-
jsr div_32_32
.byte $92
time_server_msg:
.byte "TIME SERVER : ",0
time_server_host:
.byte "202.174.101.10",0
.byte "1.AU.POOL.SNTP.ORG",0
sending_query:
.byte "SENDING SNTP QUERY TO ",0
sntp_error:
.byte "ERROR DURING SNTP QUERY",13,0
dns_error:
.byte "ERROR RESOLVING HOSTNAME",13,0
divs:
.byte $02,$30,$00,$00
.byte $05,$00,$00,$00