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-03-28 09:59:53 +00:00
.include " . . / inc/ n b65 _ c o n s t a n t s . i "
.include " . . / inc/ c o m m o n . i "
2009-03-28 06:13:14 +00:00
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 cs_driver_name
.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-03-28 12:57:24 +00:00
.zeropage
nb65_params : .res 2
2009-03-28 06:13:14 +00:00
2009-04-04 05:14:06 +00:00
.data
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-03-28 09:59:53 +00:00
cpy #N B 65 _ G E T _ A P I _ V E R S I O N
bne : +
ldax #N B 65 _ A P I _ V E R S I O N
clc
rts
:
cpy #N B 65 _ G E T _ D R I V E R _ N A M E
bne : +
ldax #c s _ d r i v e r _ n a m e
clc
rts
:
cpy #N B 65 _ G E T _ I P _ C O N F I G _ P T R
bne : +
jmp c f g _ g e t _ c o n f i g u r a t i o n _ p t r
:
cpy #N B 65 _ I N I T _ I P
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-03-28 06:13:14 +00:00
jmp i p65 _ i n i t
:
2009-03-28 09:59:53 +00:00
cpy #N B 65 _ I N I T _ D H C P
2009-03-28 06:13:14 +00:00
bne : +
jmp d h c p _ i n i t
:
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
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
sta ( n b65 _ p a r a m s ) ,y
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-04 05:14:06 +00:00
cpy #N B 65 _ D N S _ R E S O L V E _ H O S T N A M E
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
jmp u d p _ a d d _ l i s t e n e r
:
2009-03-28 12:57:24 +00:00
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