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-04-10 04:07:27 +00:00
.ifndef NB65_API_VERSION_NUMBER
.define EQU =
.include " . . / inc/ n b65 _ c o n s t a n t s . i "
.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-03-28 12:57:24 +00:00
.export nb65_dispatcher
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 tftp_directory_listing
.import ip65_error
.import tftp_clear_callbacks
.import tftp_download
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
.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-04-05 10:10:53 +00:00
.import copymem
.import cfg_mac
.importzp copy_src
.importzp copy_dest
2009-04-12 12:45:25 +00:00
;reuse the copy_src zero page location
nb6 5 _ p a r a m s = c o p y _ s r c
2009-03-28 06:13:14 +00:00
2009-04-04 05:14:06 +00:00
.data
2009-04-12 12:45:25 +00:00
old_ax : .res 2
2009-04-04 05:14:06 +00:00
jmp_old_irq :
jmp $ 0 0 0 0
irq_handler_installed_flag :
.byte 0
2009-03-28 06:13:14 +00:00
.code
2009-04-04 05:14:06 +00:00
irq_handler :
jsr N B 6 5 _ V B L _ V E C T O R
jmp j m p _ o l d _ i r q
2009-03-28 12:57:24 +00:00
set_tftp_params :
ldy #N B 65 _ T F T P _ I P
lda ( n b65 _ p a r a m s ) ,y
sta t f t p _ i p
iny
lda ( n b65 _ p a r a m s ) ,y
sta t f t p _ i p + 1
iny
lda ( n b65 _ p a r a m s ) ,y
sta t f t p _ i p + 2
iny
lda ( n b65 _ p a r a m s ) ,y
sta t f t p _ i p + 3
ldy #N B 65 _ T F T P _ F I L E N A M E
lda ( n b65 _ p a r a m s ) ,y
sta t f t p _ f i l e n a m e
iny
lda ( n b65 _ p a r a m s ) ,y
sta t f t p _ f i l e n a m e + 1
ldy #N B 65 _ T F T P _ P O I N T E R
lda ( n b65 _ p a r a m s ) ,y
sta t f t p _ l o a d _ a d d r e s s
iny
lda ( n b65 _ p a r a m s ) ,y
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
clc
rts
nb65_dispatcher :
2009-04-04 05:14:06 +00:00
stax n b65 _ p a r a m s
2009-04-12 12:45:25 +00:00
stax o l d _ a x
2009-04-05 10:10:53 +00:00
2009-03-28 09:59:53 +00:00
2009-04-10 01:19:42 +00:00
cpy #N B 65 _ I N I T I A L I Z E
2009-03-28 06:13:14 +00:00
bne : +
2009-04-04 05:14:06 +00:00
lda i r q _ h a n d l e r _ i n s t a l l e d _ f l a g
bne i r q _ h a n d l e r _ i n s t a l l e d
;install our IRQ handler
ldax $ 3 1 4 ;previous IRQ handler
stax j m p _ o l d _ i r q + 1
sei ;don't want any interrupts while we fiddle with the vector
ldax #i r q _ h a n d l e r
stax $ 3 1 4 ;previous IRQ handler
cli
sta i r q _ h a n d l e r _ i n s t a l l e d _ f l a g
irq_handler_installed :
2009-04-10 01:19:42 +00:00
jsr i p65 _ i n i t
jmp d h c p _ i n i t
2009-03-28 06:13:14 +00:00
:
2009-04-10 01:19:42 +00:00
cpy #N B 65 _ 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-04-10 01:19:42 +00:00
2009-03-28 12:57:24 +00:00
cpy #N B 65 _ T F T P _ D I R E C T O R Y _ L I S T I N G
bne : +
jsr s e t _ t f t p _ p a r a m s
bcs @tftp_error
jsr t f t p _ d i r e c t o r y _ l i s t i n g
@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)
bcs @tftp_error
2009-04-12 12:45:25 +00:00
ldax o l d _ a x
stax n b65 _ p a r a m s
2009-03-28 12:57:24 +00:00
ldy #N B 65 _ T F T P _ P O I N T E R
lda t f t p _ l o a d _ a d d r e s s
sta ( n b65 _ p a r a m s ) ,y
iny
lda t f t p _ l o a d _ a d d r e s s + 1
2009-04-12 12:45:25 +00:00
sta ( n b65 _ p a r a m s ) ,y
2009-03-28 12:57:24 +00:00
clc
@tftp_error:
2009-04-04 05:14:06 +00:00
@dns_error:
2009-03-28 12:57:24 +00:00
rts
:
cpy #N B 65 _ T F T P _ D O W N L O A D
bne : +
jsr s e t _ t f t p _ p a r a m s
bcs @tftp_error
jsr t f t p _ d o w n l o a d
jmp @after_tftp_call
:
2009-04-10 01:19:42 +00:00
cpy #N B 65 _ D N S _ R E S O L V E
2009-04-04 05:14:06 +00:00
bne : +
ldy #N B 65 _ D N S _ H O S T N A M E + 1
lda ( n b65 _ p a r a m s ) ,y
tax
dey
lda ( n b65 _ p a r a m s ) ,y
jsr d n s _ s e t _ h o s t n a m e
bcs @dns_error
jsr d n s _ r e s o l v e
bcs @dns_error
ldy #N B 65 _ D N S _ H O S T N A M E _ I P
ldx #4
@copy_dns_ip:
lda d n s _ i p ,y
sta ( n b65 _ p a r a m s ) ,y
iny
dex
bne @copy_dns_ip
rts
:
cpy #N B 65 _ U D P _ A D D _ L I S T E N E R
bne : +
ldy #N B 65 _ U D P _ L I S T E N E R _ C A L L B A C K
lda ( n b65 _ p a r a m s ) ,y
sta u d p _ c a l l b a c k
iny
lda ( n b65 _ p a r a m s ) ,y
sta u d p _ c a l l b a c k + 1
ldy #N B 65 _ U D P _ L I S T E N E R _ P O R T + 1
lda ( n b65 _ p a r a m s ) ,y
tax
dey
2009-04-05 02:46:32 +00:00
lda ( n b65 _ p a r a m s ) ,y
2009-04-04 05:14:06 +00:00
jmp u d p _ a d d _ l i s t e n e r
:
2009-04-05 10:10:53 +00:00
cpy #N B 65 _ 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
sta ( n b65 _ p a r a m s ) ,y
dey
bpl @copy_src_ip
ldy #N B 65 _ R E M O T E _ P O R T
lda u d p _ i n p + 1 ;src port (lo byte)
sta ( n b65 _ p a r a m s ) ,y
iny
lda u d p _ i n p + 0 ;src port (high byte)
sta ( n b65 _ p a r a m s ) ,y
iny
lda u d p _ i n p + 3 ;dest port (lo byte)
sta ( n b65 _ p a r a m s ) ,y
iny
lda u d p _ i n p + 2 ;dest port (high byte)
sta ( n b65 _ p a r a m s ) ,y
iny
sec
lda u d p _ i n p + 5 ;payload length (lo byte)
sbc #8 ;to remove length of header
sta ( n b65 _ p a r a m s ) ,y
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
sta ( n b65 _ p a r a m s ) ,y
iny
2009-04-06 07:31:45 +00:00
lda #< ( u d p _ i n p + 8 ) ;payload ptr (lo byte)
2009-04-05 11:34:20 +00:00
sta ( n b65 _ p a r a m s ) ,y
iny
2009-04-06 07:31:45 +00:00
lda #> ( u d p _ i n p + 8 ) ;payload ptr (hi byte)
2009-04-05 11:34:20 +00:00
sta ( n b65 _ p a r a m s ) ,y
2009-04-05 02:46:32 +00:00
clc
rts
:
2009-04-06 07:31:45 +00:00
cpy #N B 65 _ S E N D _ U D P _ P A C K E T
bne : +
ldy #3
@copy_dest_ip:
lda ( n b65 _ p a r a m s ) ,y
sta u d p _ s e n d _ d e s t ,y
dey
bpl @copy_dest_ip
ldy #N B 65 _ R E M O T E _ P O R T
lda ( n b65 _ p a r a m s ) ,y
sta u d p _ s e n d _ d e s t _ p o r t
iny
lda ( n b65 _ p a r a m s ) ,y
sta u d p _ s e n d _ d e s t _ p o r t + 1
iny
lda ( n b65 _ p a r a m s ) ,y
sta u d p _ s e n d _ s r c _ p o r t
iny
lda ( n b65 _ p a r a m s ) ,y
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-04-06 07:31:45 +00:00
lda ( n b65 _ p a r a m s ) ,y
sta u d p _ s e n d _ l e n
iny
lda ( n b65 _ p a r a m s ) ,y
sta u d p _ s e n d _ l e n + 1
iny
;AX should point at data to send
lda ( n b65 _ p a r a m s ) ,y
pha
iny
lda ( n b65 _ p a r a m s ) ,y
tax
pla
jmp u d p _ s e n d
:
2009-04-06 11:10:49 +00:00
2009-04-10 01:19:42 +00:00
cpy #N B 65 _ D E A C T I V A T E
2009-04-05 02:46:32 +00:00
bne : +
ldax j m p _ o l d _ i r q + 1
sei ;don't want any interrupts while we fiddle with the vector
stax $ 3 1 4 ;previous IRQ handler
cli
clc
rts
:
2009-04-05 10:10:53 +00:00
cpy #N B 65 _ P R I N T _ A S C I I Z
bne : +
jsr p r i n t
clc
rts
:
2009-04-05 11:34:20 +00:00
cpy #N B 65 _ 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
:
cpy #N B 65 _ P R I N T _ D O T T E D _ Q U A D
bne : +
jsr p r i n t _ d o t t e d _ q u a d
clc
rts
:
cpy #N B 65 _ P R I N T _ I P _ C O N F I G
bne : +
jsr p r i n t _ i p _ c o n f i g
clc
rts
:
cpy #N B 65 _ G E T _ L A S T _ E R R O R
bne : +
lda i p65 _ e r r o r
clc
rts
:
2009-03-28 06:13:14 +00:00
;default function handler
2009-03-28 12:57:24 +00:00
lda #N B 65 _ 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
sta i p65 _ e r r o r
2009-03-28 06:13:14 +00:00
sec ;carry flag set = error
rts