2009-01-22 01:27:03 +00:00
|
|
|
; ip65 main routines
|
|
|
|
|
|
|
|
.include "../inc/common.i"
|
2009-04-17 10:59:03 +00:00
|
|
|
|
|
|
|
.ifndef NB65_API_VERSION_NUMBER
|
|
|
|
.define EQU =
|
|
|
|
.include "../inc/nb65_constants.i"
|
|
|
|
.endif
|
2009-01-22 01:27:03 +00:00
|
|
|
|
|
|
|
.export ip65_init
|
|
|
|
.export ip65_process
|
2009-06-28 08:36:49 +00:00
|
|
|
.export ip65_random_word
|
2009-01-22 01:27:03 +00:00
|
|
|
.export ip65_ctr
|
|
|
|
.export ip65_ctr_arp
|
2009-03-28 11:26:03 +00:00
|
|
|
.export ip65_ctr_ip
|
|
|
|
|
|
|
|
.export ip65_error
|
2009-04-17 10:59:03 +00:00
|
|
|
|
|
|
|
.import cfg_init
|
2009-03-28 11:26:03 +00:00
|
|
|
|
2009-01-22 01:27:03 +00:00
|
|
|
.import eth_init
|
|
|
|
.import timer_init
|
|
|
|
.import arp_init
|
|
|
|
.import ip_init
|
2009-06-28 08:36:49 +00:00
|
|
|
.import timer_read
|
2009-01-22 01:27:03 +00:00
|
|
|
|
2009-06-28 08:36:49 +00:00
|
|
|
.import eth_inp
|
|
|
|
.import eth_outp
|
2009-01-22 01:27:03 +00:00
|
|
|
.import eth_rx
|
|
|
|
|
|
|
|
.import ip_process
|
|
|
|
.import arp_process
|
|
|
|
|
|
|
|
.importzp eth_proto_arp
|
|
|
|
|
2009-06-28 08:36:49 +00:00
|
|
|
.export ip65_random_word
|
|
|
|
|
2009-01-22 01:27:03 +00:00
|
|
|
.bss
|
2009-06-28 08:36:49 +00:00
|
|
|
|
2009-01-22 01:27:03 +00:00
|
|
|
|
|
|
|
ip65_ctr: .res 1 ; incremented for every incoming packet
|
|
|
|
ip65_ctr_arp: .res 1 ; incremented for every incoming arp packet
|
|
|
|
ip65_ctr_ip: .res 1 ; incremented for every incoming ip packet
|
|
|
|
|
2009-03-28 11:26:03 +00:00
|
|
|
ip65_error: .res 1 ;last error code
|
2009-01-22 01:27:03 +00:00
|
|
|
|
|
|
|
.code
|
2009-06-28 08:36:49 +00:00
|
|
|
|
|
|
|
;generate a 'random' 16 bit word
|
|
|
|
;entropy comes from the last ethernet frame, counters, and timer
|
|
|
|
;inputs: none
|
|
|
|
;outputs: AX set to a pseudo-random 16 bit number
|
|
|
|
ip65_random_word:
|
|
|
|
jsr timer_read ;sets AX
|
2009-08-17 04:23:05 +00:00
|
|
|
; adc $d018 ;on a c64, this is the raster register
|
|
|
|
adc $d41b; on a c64, this is a 'random' number from the SID
|
2009-06-28 08:36:49 +00:00
|
|
|
pha
|
|
|
|
adc ip65_ctr_arp
|
|
|
|
ora #$08 ;make sure we grab at least 8 bytes from eth_inp
|
|
|
|
tax
|
|
|
|
:
|
|
|
|
adc eth_inp,x
|
|
|
|
adc eth_outp,x
|
|
|
|
dex
|
|
|
|
bne :-
|
|
|
|
tax
|
|
|
|
pla
|
|
|
|
adc ip65_ctr
|
|
|
|
eor ip65_ctr_ip
|
|
|
|
rts
|
2009-01-22 01:27:03 +00:00
|
|
|
|
2009-03-21 06:40:53 +00:00
|
|
|
; initialise the IP stack
|
|
|
|
; this calls the individual protocol & driver initialisations, so this is
|
|
|
|
; the only *_init routine that must be called by a user application,
|
|
|
|
; except for dhcp_init which must also be called if the application
|
|
|
|
; is using dhcp rather than hardcoded ip configuration
|
|
|
|
; inputs: none
|
|
|
|
; outputs: none
|
2009-01-22 01:27:03 +00:00
|
|
|
ip65_init:
|
2009-04-17 10:59:03 +00:00
|
|
|
jsr cfg_init ;copy default values (including MAC address) to RAM
|
2009-01-22 01:27:03 +00:00
|
|
|
jsr eth_init ; initialize ethernet driver
|
|
|
|
|
2009-04-17 10:59:03 +00:00
|
|
|
bcc @ok
|
|
|
|
lda #NB65_ERROR_DEVICE_FAILURE
|
|
|
|
sta ip65_error
|
|
|
|
rts
|
|
|
|
@ok:
|
2009-01-22 01:27:03 +00:00
|
|
|
jsr timer_init ; initialize timer
|
|
|
|
jsr arp_init ; initialize arp
|
|
|
|
jsr ip_init ; initialize ip, icmp, udp, and tcp
|
2009-04-17 10:59:03 +00:00
|
|
|
clc
|
2009-01-22 01:27:03 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
|
2009-03-21 06:40:53 +00:00
|
|
|
;main ip polling loop
|
|
|
|
;this routine should be periodically called by an application at any time
|
|
|
|
;that an inbound packet needs to be handled.
|
|
|
|
;it is 'non-blocking', i.e. it will return if there is no packet waiting to be
|
|
|
|
;handled. any inbound packet will be handed off to the appropriate handler.
|
|
|
|
;inputs: none
|
|
|
|
;outputs: carry flag set if no packet was waiting, or packet handling caused error.
|
|
|
|
; since the inbound packet may trigger generation of an outbound, eth_outp
|
|
|
|
; and eth_outp_len may be overwriiten.
|
2009-01-22 01:27:03 +00:00
|
|
|
ip65_process:
|
|
|
|
jsr eth_rx ; check for incoming packets
|
|
|
|
bcs @done
|
|
|
|
|
|
|
|
lda eth_inp + 12 ; type should be 08xx
|
|
|
|
cmp #8
|
|
|
|
bne @done
|
|
|
|
|
|
|
|
lda eth_inp + 13
|
|
|
|
; cmp #eth_proto_ip ; ip = 00
|
|
|
|
beq @ip
|
|
|
|
cmp #eth_proto_arp ; arp = 06
|
|
|
|
beq @arp
|
|
|
|
@done:
|
|
|
|
rts
|
|
|
|
|
|
|
|
@arp:
|
|
|
|
inc ip65_ctr_arp
|
|
|
|
jmp arp_process
|
|
|
|
|
|
|
|
@ip:
|
|
|
|
inc ip65_ctr_ip
|
|
|
|
jmp ip_process
|