2009-04-04 05:14:06 +00:00
;this is some very quick and dirty glue to make the most useful IP65 functions available via a single entry point.
;this allows user applications to be developed that don't link ip65 in directly, rather they use an instance of ip65 that is preloaded (or in a cartridge/ROM)
;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.
2009-09-22 09:49:37 +00:00
.ifndef KPR_API_VERSION_NUMBER
2009-04-10 04:07:27 +00:00
.define EQU =
2009-09-22 09:49:37 +00:00
.include " . . / inc/ k i p p e r _ c o n s t a n t s . i "
2009-04-10 04:07:27 +00:00
.endif
2009-03-28 09:59:53 +00:00
.include " . . / inc/ c o m m o n . i "
2009-04-05 10:10:53 +00:00
.include " . . / inc/ c o m m o n p r i n t . i "
2009-09-22 09:49:37 +00:00
.export kipper_dispatcher
2009-03-28 12:57:24 +00:00
2009-03-28 06:13:14 +00:00
.import ip65_init
.import dhcp_init
2009-03-28 09:59:53 +00:00
.import cfg_get_configuration_ptr
2009-03-28 12:57:24 +00:00
.import tftp_load_address
.importzp tftp_filename
.import tftp_ip
.import ip65_error
.import tftp_clear_callbacks
.import tftp_download
2009-04-16 23:40:10 +00:00
.import tftp_upload
2009-04-16 05:40:40 +00:00
.import tftp_set_callback_vector
2009-04-17 01:50:21 +00:00
.import tftp_filesize
2009-04-04 05:14:06 +00:00
.import dns_ip
.import dns_resolve
.import dns_set_hostname
2009-04-05 02:46:32 +00:00
.import udp_callback
.import udp_add_listener
2009-04-24 22:37:22 +00:00
.import udp_remove_listener
2009-04-05 02:46:32 +00:00
.import ip_inp
2009-04-05 11:34:20 +00:00
.import udp_inp
2009-04-06 07:31:45 +00:00
.import udp_send
.import udp_send_src
.import udp_send_src_port
.import udp_send_dest
.import udp_send_dest_port
.import udp_send_len
2009-07-17 02:53:46 +00:00
2009-04-05 10:10:53 +00:00
.import copymem
.import cfg_mac
2009-04-18 12:59:10 +00:00
.import cfg_tftp_server
2009-04-05 10:10:53 +00:00
.importzp copy_src
.importzp copy_dest
2009-04-12 12:45:25 +00:00
;reuse the copy_src zero page location
2009-09-22 09:49:37 +00:00
kipper_ p a r a m s = c o p y _ s r c
2009-07-17 02:53:46 +00:00
buffer_ p t r = c o p y _ d e s t
2009-04-04 05:14:06 +00:00
.data
2009-04-12 12:45:25 +00:00
2009-04-17 01:50:21 +00:00
2009-04-18 12:59:10 +00:00
ip_configured_flag :
.byte 0
2009-03-28 06:13:14 +00:00
.code
2009-03-28 12:57:24 +00:00
set_tftp_params :
2009-04-18 12:59:10 +00:00
ldx #$ 03
:
lda c f g _ t f t p _ s e r v e r ,x
sta t f t p _ i p ,x
dex
bpl : -
2009-03-28 12:57:24 +00:00
2009-09-22 09:49:37 +00:00
ldy #K P R _ T F T P _ F I L E N A M E
lda ( k i p p e r _ p a r a m s ) ,y
2009-03-28 12:57:24 +00:00
sta t f t p _ f i l e n a m e
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-03-28 12:57:24 +00:00
sta t f t p _ f i l e n a m e + 1
2009-09-22 09:49:37 +00:00
ldy #K P R _ T F T P _ P O I N T E R
lda ( k i p p e r _ p a r a m s ) ,y
2009-03-28 12:57:24 +00:00
sta t f t p _ l o a d _ a d d r e s s
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-03-28 12:57:24 +00:00
sta t f t p _ l o a d _ a d d r e s s + 1
jsr t f t p _ c l e a r _ c a l l b a c k s
rts
2009-04-16 23:40:10 +00:00
set_tftp_callback_vector :
2009-09-22 09:49:37 +00:00
ldy #K P R _ T F T P _ P O I N T E R + 1
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-16 23:40:10 +00:00
tax
dey
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-16 23:40:10 +00:00
jmp t f t p _ s e t _ c a l l b a c k _ v e c t o r
2009-09-22 09:49:37 +00:00
kipper_dispatcher :
stax k i p p e r _ p a r a m s
2009-04-05 10:10:53 +00:00
2009-03-28 09:59:53 +00:00
2009-09-22 09:49:37 +00:00
cpy #K P R _ I N I T I A L I Z E
2009-03-28 06:13:14 +00:00
bne : +
2009-04-18 12:59:10 +00:00
lda i p _ c o n f i g u r e d _ f l a g
bne i p _ c o n f i g u r e d
2009-04-17 10:59:03 +00:00
jsr i p65 _ i n i t
bcs i n i t _ f a i l e d
2009-04-17 13:02:02 +00:00
jsr d h c p _ i n i t
bcc d h c p _ o k
2009-04-18 12:59:10 +00:00
jsr i p65 _ i n i t ;if DHCP failed, then reinit the IP stack (which will reset IP address etc that DHCP messed with to cartridge default values)
2009-07-17 02:53:46 +00:00
dhcp_ok :
2009-04-18 12:59:10 +00:00
lda #1
sta i p _ c o n f i g u r e d _ f l a g
2009-04-12 22:58:20 +00:00
clc
2009-04-17 10:59:03 +00:00
init_failed :
2009-04-12 22:58:20 +00:00
rts
2009-04-18 12:59:10 +00:00
ip_configured :
2009-07-17 02:53:46 +00:00
clc
2009-04-18 12:59:10 +00:00
rts
2009-03-28 06:13:14 +00:00
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ G E T _ I P _ C O N F I G
2009-03-28 06:13:14 +00:00
bne : +
2009-04-10 01:19:42 +00:00
ldax #c f g _ m a c
clc
rts
2009-03-28 06:13:14 +00:00
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ D N S _ R E S O L V E
2009-04-04 05:14:06 +00:00
bne : +
2009-04-17 13:02:02 +00:00
phax
2009-09-22 09:49:37 +00:00
ldy #K P R _ D N S _ H O S T N A M E + 1
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-04 05:14:06 +00:00
tax
dey
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-17 11:21:00 +00:00
jsr d n s _ s e t _ h o s t n a m e
bcs @dns_error
2009-04-04 05:14:06 +00:00
jsr d n s _ r e s o l v e
bcs @dns_error
2009-04-17 11:21:00 +00:00
2009-09-22 09:49:37 +00:00
ldy #K P R _ D N S _ H O S T N A M E _ I P
2009-04-17 13:02:02 +00:00
plax
2009-09-22 09:49:37 +00:00
stax k i p p e r _ p a r a m s
2009-08-16 04:15:43 +00:00
ldx #4
2009-04-04 05:14:06 +00:00
@copy_dns_ip:
lda d n s _ i p ,y
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-04 05:14:06 +00:00
iny
dex
bne @copy_dns_ip
2009-04-17 13:02:02 +00:00
rts
2009-04-17 01:50:21 +00:00
@dns_error:
2009-04-17 13:02:02 +00:00
plax
2009-04-04 05:14:06 +00:00
rts
2009-04-17 01:50:21 +00:00
2009-04-04 05:14:06 +00:00
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ U D P _ A D D _ L I S T E N E R
2009-04-04 05:14:06 +00:00
bne : +
2009-09-22 09:49:37 +00:00
ldy #K P R _ U D P _ L I S T E N E R _ C A L L B A C K
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-04 05:14:06 +00:00
sta u d p _ c a l l b a c k
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-04 05:14:06 +00:00
sta u d p _ c a l l b a c k + 1
2009-09-22 09:49:37 +00:00
ldy #K P R _ U D P _ L I S T E N E R _ P O R T + 1
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-04 05:14:06 +00:00
tax
dey
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-05 02:46:32 +00:00
2009-04-04 05:14:06 +00:00
jmp u d p _ a d d _ l i s t e n e r
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ G E T _ I N P U T _ P A C K E T _ I N F O
2009-04-05 02:46:32 +00:00
bne : +
2009-04-05 11:34:20 +00:00
ldy #3
@copy_src_ip:
lda i p _ i n p + 1 2 ,y ;src IP
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-05 11:34:20 +00:00
dey
bpl @copy_src_ip
2009-09-22 09:49:37 +00:00
ldy #K P R _ R E M O T E _ P O R T
2009-04-05 11:34:20 +00:00
lda u d p _ i n p + 1 ;src port (lo byte)
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-05 11:34:20 +00:00
iny
lda u d p _ i n p + 0 ;src port (high byte)
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-05 11:34:20 +00:00
iny
lda u d p _ i n p + 3 ;dest port (lo byte)
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-05 11:34:20 +00:00
iny
lda u d p _ i n p + 2 ;dest port (high byte)
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-05 11:34:20 +00:00
iny
sec
lda u d p _ i n p + 5 ;payload length (lo byte)
sbc #8 ;to remove length of header
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-05 11:34:20 +00:00
iny
lda u d p _ i n p + 4 ;payload length (hi byte)
sbc #0 ;in case there was a carry from the lo byte
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-05 11:34:20 +00:00
iny
2009-04-06 07:31:45 +00:00
lda #< ( u d p _ i n p + 8 ) ;payload ptr (lo byte)
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-05 11:34:20 +00:00
iny
2009-04-06 07:31:45 +00:00
lda #> ( u d p _ i n p + 8 ) ;payload ptr (hi byte)
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-05 11:34:20 +00:00
2009-07-17 05:31:54 +00:00
.import tcp_inbound_data_ptr
.import tcp_inbound_data_length
lda i p _ i n p + 9 ;proto number
cmp #6 ;TCP
bne @not_tcp
2009-09-22 09:49:37 +00:00
ldy #K P R _ P A Y L O A D _ L E N G T H
2009-07-17 05:31:54 +00:00
lda t c p _ i n b o u n d _ d a t a _ l e n g t h
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-07-17 05:31:54 +00:00
iny
lda t c p _ i n b o u n d _ d a t a _ l e n g t h + 1
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-07-17 05:31:54 +00:00
2009-09-22 09:49:37 +00:00
ldy #K P R _ P A Y L O A D _ P O I N T E R
2009-07-17 05:31:54 +00:00
lda t c p _ i n b o u n d _ d a t a _ p t r
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-07-17 05:31:54 +00:00
iny
lda t c p _ i n b o u n d _ d a t a _ p t r + 1
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-07-17 05:31:54 +00:00
@not_tcp:
2009-04-05 02:46:32 +00:00
clc
rts
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ S E N D _ U D P _ P A C K E T
2009-04-06 07:31:45 +00:00
bne : +
ldy #3
@copy_dest_ip:
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-06 07:31:45 +00:00
sta u d p _ s e n d _ d e s t ,y
dey
bpl @copy_dest_ip
2009-09-22 09:49:37 +00:00
ldy #K P R _ R E M O T E _ P O R T
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-06 07:31:45 +00:00
sta u d p _ s e n d _ d e s t _ p o r t
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-06 07:31:45 +00:00
sta u d p _ s e n d _ d e s t _ p o r t + 1
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-06 07:31:45 +00:00
sta u d p _ s e n d _ s r c _ p o r t
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-06 07:31:45 +00:00
sta u d p _ s e n d _ s r c _ p o r t + 1
iny
2009-03-28 12:57:24 +00:00
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-06 07:31:45 +00:00
sta u d p _ s e n d _ l e n
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-06 07:31:45 +00:00
sta u d p _ s e n d _ l e n + 1
iny
;AX should point at data to send
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-06 07:31:45 +00:00
pha
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-06 07:31:45 +00:00
tax
pla
jmp u d p _ s e n d
2009-04-24 22:37:22 +00:00
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ U D P _ R E M O V E _ L I S T E N E R
2009-04-24 22:37:22 +00:00
bne : +
jmp u d p _ r e m o v e _ l i s t e n e r
2009-04-06 07:31:45 +00:00
:
2009-04-06 11:10:49 +00:00
2009-04-24 22:37:22 +00:00
2009-09-22 09:49:37 +00:00
cpy #K P R _ D E A C T I V A T E
2009-10-05 03:01:58 +00:00
;nothing to do now we don't use IRQ
2009-04-05 02:46:32 +00:00
bne : +
clc
rts
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ T F T P _ S E T _ S E R V E R
2009-04-18 12:59:10 +00:00
bne : +
ldy #3
@copy_tftp_server_ip:
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-18 12:59:10 +00:00
sta c f g _ t f t p _ s e r v e r ,y
dey
bpl @copy_tftp_server_ip
clc
rts
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ T F T P _ D O W N L O A D
2009-04-17 01:50:21 +00:00
bne : +
phax
jsr s e t _ t f t p _ p a r a m s
2009-05-02 13:14:59 +00:00
jsr t f t p _ d o w n l o a d
2009-04-17 01:50:21 +00:00
@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
2009-09-22 09:49:37 +00:00
stax k i p p e r _ p a r a m s
2009-04-17 01:50:21 +00:00
2009-09-22 09:49:37 +00:00
ldy #K P R _ T F T P _ P O I N T E R
2009-04-17 01:50:21 +00:00
lda t f t p _ l o a d _ a d d r e s s
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-17 01:50:21 +00:00
iny
lda t f t p _ l o a d _ a d d r e s s + 1
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-17 01:50:21 +00:00
2009-09-22 09:49:37 +00:00
ldy #K P R _ T F T P _ F I L E S I Z E
2009-04-17 01:50:21 +00:00
lda t f t p _ f i l e s i z e
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-17 01:50:21 +00:00
iny
lda t f t p _ f i l e s i z e + 1
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-04-17 01:50:21 +00:00
clc
@tftp_error:
rts
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ T F T P _ C A L L B A C K _ D O W N L O A D
2009-04-15 21:39:33 +00:00
bne : +
2009-04-17 01:50:21 +00:00
phax
2009-04-15 21:39:33 +00:00
jsr s e t _ t f t p _ p a r a m s
2009-04-16 23:40:10 +00:00
jsr s e t _ t f t p _ c a l l b a c k _ v e c t o r
2009-04-17 01:50:21 +00:00
jsr t f t p _ d o w n l o a d
jmp @after_tftp_call
2009-04-15 21:39:33 +00:00
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ T F T P _ U P L O A D
2009-04-17 15:48:31 +00:00
bne : +
phax
jsr s e t _ t f t p _ p a r a m s
2009-09-22 09:49:37 +00:00
ldy #K P R _ T F T P _ P O I N T E R
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-17 15:48:31 +00:00
sta t f t p _ f i l e s i z e
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-04-17 15:48:31 +00:00
sta t f t p _ f i l e s i z e + 1
jsr t f t p _ d o w n l o a d
jmp @after_tftp_call
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ T F T P _ C A L L B A C K _ U P L O A D
2009-04-16 23:40:10 +00:00
bne : +
jsr s e t _ t f t p _ p a r a m s
jsr s e t _ t f t p _ c a l l b a c k _ v e c t o r
jmp t f t p _ u p l o a d
:
2009-04-15 21:39:33 +00:00
2009-09-22 09:49:37 +00:00
cpy #K P R _ P R I N T _ A S C I I Z
2009-04-05 10:10:53 +00:00
bne : +
jsr p r i n t
clc
rts
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ P R I N T _ H E X
2009-04-05 10:10:53 +00:00
bne : +
jsr p r i n t _ h e x
clc
rts
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ P R I N T _ D O T T E D _ Q U A D
2009-04-05 10:10:53 +00:00
bne : +
jsr p r i n t _ d o t t e d _ q u a d
clc
rts
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ P R I N T _ I P _ C O N F I G
2009-04-05 10:10:53 +00:00
bne : +
jsr p r i n t _ i p _ c o n f i g
clc
rts
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ P R I N T _ I N T E G E R
2009-08-21 13:21:14 +00:00
bne : +
jsr p r i n t _ i n t e g e r
clc
rts
:
2009-07-17 02:53:46 +00:00
.segment " TCP_ V A R S "
port_number : .res 2
2009-07-18 13:24:52 +00:00
nonzero_octets : .res 1
2009-07-17 02:53:46 +00:00
.code
2009-09-22 09:49:37 +00:00
cpy #K P R _ D O W N L O A D _ R E S O U R C E
2009-08-20 10:06:33 +00:00
bne : +
.import url_download
.import url_download_buffer
.import url_download_buffer_length
2009-09-22 09:49:37 +00:00
ldy #K P R _ U R L _ D O W N L O A D _ B U F F E R
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-20 10:06:33 +00:00
sta u r l _ d o w n l o a d _ b u f f e r
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-20 10:06:33 +00:00
sta u r l _ d o w n l o a d _ b u f f e r + 1
2009-09-22 09:49:37 +00:00
ldy #K P R _ U R L _ D O W N L O A D _ B U F F E R _ L E N G T H
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-20 10:06:33 +00:00
sta u r l _ d o w n l o a d _ b u f f e r _ l e n g t h
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-20 10:06:33 +00:00
sta u r l _ d o w n l o a d _ b u f f e r _ l e n g t h + 1
2009-09-22 09:49:37 +00:00
ldy #K P R _ U R L + 1
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-20 10:06:33 +00:00
tax
dey
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-20 10:06:33 +00:00
jmp u r l _ d o w n l o a d
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ F I L E _ L O A D
2009-08-24 10:20:21 +00:00
bne : +
.import io_device_no
.import io_read_file
.import io_filename
.import io_filesize
.import io_load_address
phax
2009-09-22 09:49:37 +00:00
ldy #K P R _ F I L E _ A C C E S S _ F I L E N A M E
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-24 10:20:21 +00:00
sta i o _ f i l e n a m e
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-24 10:20:21 +00:00
sta i o _ f i l e n a m e + 1
2009-09-22 09:49:37 +00:00
ldy #K P R _ F I L E _ A C C E S S _ D E V I C E
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-24 10:20:21 +00:00
sta i o _ d e v i c e _ n o
2009-09-22 09:49:37 +00:00
ldy #K P R _ F I L E _ A C C E S S _ P O I N T E R + 1
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-24 10:20:21 +00:00
tax
dey
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-24 10:20:21 +00:00
jsr i o _ r e a d _ f i l e
plax
bcc @read_file_ok
rts
@read_file_ok:
2009-09-22 09:49:37 +00:00
stax k i p p e r _ p a r a m s
2009-08-24 10:20:21 +00:00
2009-09-22 09:49:37 +00:00
ldy #K P R _ F I L E _ A C C E S S _ P O I N T E R
2009-08-24 10:20:21 +00:00
lda i o _ l o a d _ a d d r e s s
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-08-24 10:20:21 +00:00
iny
lda i o _ l o a d _ a d d r e s s + 1
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-08-24 10:20:21 +00:00
2009-09-22 09:49:37 +00:00
ldy #K P R _ F I L E _ A C C E S S _ F I L E S I Z E
2009-08-24 10:20:21 +00:00
lda i o _ f i l e s i z e
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-08-24 10:20:21 +00:00
iny
lda i o _ f i l e s i z e + 1
2009-09-22 09:49:37 +00:00
sta ( k i p p e r _ p a r a m s ) ,y
2009-08-24 10:20:21 +00:00
rts
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ P I N G _ H O S T
2009-08-21 13:21:14 +00:00
.import icmp_echo_ip
.import icmp_ping
bne : +
ldy #3
@copy_ping_ip_loop:
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-08-21 13:21:14 +00:00
sta i c m p _ e c h o _ i p ,y
dey
bpl @copy_ping_ip_loop
jmp i c m p _ p i n g
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ T C P _ C O N N E C T
2009-07-18 13:24:52 +00:00
bne : +
2009-07-17 02:53:46 +00:00
.import tcp_connect
.import tcp_callback
.import tcp_connect_ip
2009-07-18 13:24:52 +00:00
.import tcp_listen
2009-07-17 02:53:46 +00:00
ldy #3
2009-07-18 13:24:52 +00:00
lda #0
sta n o n z e r o _ o c t e t s
2009-07-17 02:53:46 +00:00
@copy_dest_ip:
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-18 13:24:52 +00:00
beq @octet_was_zero
inc n o n z e r o _ o c t e t s
@octet_was_zero:
2009-07-17 02:53:46 +00:00
sta t c p _ c o n n e c t _ i p ,y
dey
bpl @copy_dest_ip
2009-09-22 09:49:37 +00:00
ldy #K P R _ T C P _ C A L L B A C K
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-17 02:53:46 +00:00
sta t c p _ c a l l b a c k
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-17 02:53:46 +00:00
sta t c p _ c a l l b a c k + 1
2009-09-22 09:49:37 +00:00
ldy #K P R _ T C P _ P O R T + 1
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-17 02:53:46 +00:00
tax
dey
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-18 13:24:52 +00:00
ldy n o n z e r o _ o c t e t s
bne @outbound_tcp_connection
jmp t c p _ l i s t e n
@outbound_tcp_connection:
2009-07-17 02:53:46 +00:00
jmp t c p _ c o n n e c t
:
2009-07-17 05:31:54 +00:00
.import tcp_send
.import tcp_send_data_len
2009-09-22 09:49:37 +00:00
cpy #K P R _ S E N D _ T C P _ P A C K E T
2009-07-17 05:31:54 +00:00
bne : +
2009-09-22 09:49:37 +00:00
ldy #K P R _ T C P _ P A Y L O A D _ L E N G T H
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-17 05:31:54 +00:00
sta t c p _ s e n d _ d a t a _ l e n
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-17 05:31:54 +00:00
sta t c p _ s e n d _ d a t a _ l e n + 1
2009-09-22 09:49:37 +00:00
ldy #K P R _ T C P _ P A Y L O A D _ P O I N T E R + 1
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-17 05:31:54 +00:00
tax
dey
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-17 05:31:54 +00:00
jmp t c p _ s e n d
2009-07-17 02:53:46 +00:00
2009-07-17 05:31:54 +00:00
:
2009-07-17 02:53:46 +00:00
2009-07-17 13:10:44 +00:00
.import tcp_close
2009-09-22 09:49:37 +00:00
cpy #K P R _ T C P _ C L O S E _ C O N N E C T I O N
2009-07-17 13:10:44 +00:00
bne : +
jmp t c p _ c l o s e
:
2009-07-17 02:53:46 +00:00
.import filter_dns
.import get_filtered_input
.import filter_number
2009-07-24 00:17:41 +00:00
2009-09-22 09:49:37 +00:00
cpy #K P R _ I N P U T _ S T R I N G
2009-07-24 00:17:41 +00:00
bne : +
ldy #40 ;max chars
ldax #$ 0000
jmp g e t _ f i l t e r e d _ i n p u t
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ I N P U T _ H O S T N A M E
2009-07-17 02:53:46 +00:00
bne : +
ldy #40 ;max chars
ldax #f i l t e r _ d n s
jmp g e t _ f i l t e r e d _ i n p u t
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ I N P U T _ P O R T _ N U M B E R
2009-07-17 02:53:46 +00:00
bne : +
ldy #5 ;max chars
ldax #f i l t e r _ n u m b e r
jsr g e t _ f i l t e r e d _ i n p u t
bcs @no_port_entered
2009-08-11 11:32:06 +00:00
;AX now points a string containing port number
.import parse_integer
jmp p a r s e _ i n t e g e r
2009-07-17 02:53:46 +00:00
@no_port_entered:
rts
:
2009-07-19 10:57:28 +00:00
2009-09-22 09:49:37 +00:00
cpy #K P R _ B L O C K _ C O P Y
2009-07-19 10:57:28 +00:00
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!
.segment " TCP_ V A R S "
tmp_copy_src : .res 2
tmp_copy_dest : .res 2
tmp_copy_length : .res 2
.code
2009-09-22 09:49:37 +00:00
ldy #K P R _ B L O C K _ S R C
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-19 10:57:28 +00:00
sta t m p _ c o p y _ s r c
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-19 10:57:28 +00:00
sta t m p _ c o p y _ s r c + 1
2009-09-22 09:49:37 +00:00
ldy #K P R _ B L O C K _ D E S T
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-19 10:57:28 +00:00
sta t m p _ c o p y _ d e s t
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-19 10:57:28 +00:00
sta t m p _ c o p y _ d e s t + 1
2009-09-22 09:49:37 +00:00
ldy #K P R _ B L O C K _ S I Z E
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-19 10:57:28 +00:00
sta t m p _ c o p y _ l e n g t h
iny
2009-09-22 09:49:37 +00:00
lda ( k i p p e r _ p a r a m s ) ,y
2009-07-19 10:57:28 +00:00
sta t m p _ c o p y _ l e n g t h + 1
ldax t m p _ c o p y _ s r c
stax c o p y _ s r c
ldax t m p _ c o p y _ d e s t
stax c o p y _ d e s t
ldax t m p _ c o p y _ l e n g t h
jmp c o p y m e m
:
2009-08-20 14:03:02 +00:00
2009-09-22 09:49:37 +00:00
cpy #K P R _ P A R S E R _ I N I T
2009-08-20 14:03:02 +00:00
bne : +
.import parser_init
jmp p a r s e r _ i n i t
:
2009-09-22 09:49:37 +00:00
cpy #K P R _ P A R S E R _ S K I P _ N E X T
2009-08-20 14:03:02 +00:00
bne : +
.import parser_skip_next
jmp p a r s e r _ s k i p _ n e x t
:
2009-04-05 10:10:53 +00:00
2009-09-22 09:49:37 +00:00
cpy #K P R _ G E T _ L A S T _ E R R O R
2009-04-05 10:10:53 +00:00
bne : +
lda i p65 _ e r r o r
clc
rts
:
2009-03-28 06:13:14 +00:00
;default function handler
2009-09-22 09:49:37 +00:00
lda #K P R _ E R R O R _ F U N C T I O N _ N O T _ S U P P O R T E D
2009-03-28 12:57:24 +00:00
sta i p65 _ e r r o r
2009-03-28 06:13:14 +00:00
sec ;carry flag set = error
rts