Up one Vic 20 network - software by Lee Davison Up to top

Address resolution protocol

If you want to talk IP over an ethernet network this is probably one of the most important protocols to implement. What it does is allow other machines to discover your hardware address automatically and talk to you. It's not absolutely necessary but without it you will need to do a lot of manual configuration.


; *********************************************************************		
; construct a reply to an ARP request aimed at us
; see RFC826 for a description of the ARP packet

LAB_21000
	LDA	arp_buff+ARP_hrdsp_l	; hardware type - always $01
	CMP	#$01			; check type
	BNE	LAB_20350		; exit if incorrect

	LDA	arp_buff+ARP_prtsp_h	; hardware protocol high byte
	CMP	#$08			; check protocol
	BNE	LAB_20350		; exit if incorrect

	LDA	arp_buff+ARP_prtsp_l	; hardware protocol low byte
	BNE	LAB_20350		; exit if incorrect

	LDA	arp_buff+ARP_hrd_len	; hardware (MAC) address length
	CMP	#$06			; check length
	BNE	LAB_20350		; exit if incorrect

	LDA	arp_buff+ARP_prt_len	; protocol (IP) address length
	CMP	#$04			; check length
	BNE	LAB_20350		; exit if incorrect

	LDA	arp_buff+ARP_code_l	; type of packet
	CMP	#$01			; check type
	BNE	LAB_20350		; exit if incorrect

	LDX	#arp_ofs+ARP_dst_ip	; index protocol destination address
	JSR	match_ip		; compare with our IP address
	BNE	LAB_20350		; exit if not for us

; we have recognised the packet as correct and the target as us
; so set up the buffer for transmit

					; do MAC addresses
	LDX	#$05			; set index/count
LAB_21050
	LDA	arp_buff+ARP_src_mac,X	; copy source MAC address byte
	STA	pk_buff+ET_dst_adr,X	; save destiantion MAC address byte
	STA	arp_buff+ARP_dst_mac,X	; save destiantion MAC address byte
	LDA	mac_ours,X		; get our MAC address byte
	STA	pk_buff+ET_src_adr,X	; save source MAC address byte
	STA	arp_buff+ARP_src_mac,X	; save source MAC address byte
	DEX
	BPL	LAB_21050		; loop if not all done

					; do IP addresses
	LDX	#$03			; set index/count
LAB_21055
	LDA	arp_buff+ARP_src_ip,X	; get source IP address byte
	STA	arp_buff+ARP_dst_ip,X	; save destination IP address byte
	LDA	ip_ours,X		; get our IP address byte
	STA	arp_buff+ARP_src_ip,X	; save source IP address byte
	DEX				; increment index
	BPL	LAB_21055		; loop if not all done

					; make it an ARP reply
	LDA	#$02			; set op type to reply
	STA	arp_buff+ARP_code_l	; save op type

	LDA	#$2A			; ARP reply length low byte
	STA	tx_len_l		; set Tx length low byte
	LDA	#$00			; ARP reply length high byte
	STA	tx_len_h		; set Tx length high byte

					; packet set up, now Tx it

; *********************************************************************

Constructing the reply leads straight into transmitting the packet. With the 3Com card packets do not have to be padded out to minimum size, this is done by the card, but they do need to be a whole number of longwords (32 bits) in length. To ensure this the routine pads out any short packets with null bytes.

This is the routine that is used to transmit all the packets over the network.


; *********************************************************************		
; Tx ethernet packet, tx_len is the packet length

LAB_21200
	LDA	tx_len_l		; get Tx length low byte
	STA	tc_l			; save to temp count
	STA	data_reg		; save to NIC
	LDA	tx_len_h		; get Tx length high byte
	STA	tc_h			; save to temp count
	ORA	#$80			; generates an interrupt when sent
	STA	data_reg		; save to NIC
	LDY	#$00			; clear index
	STY	data_reg		; save to NIC
	STY	data_reg		; save to NIC

					; header written, now write data
	LDA	#>pk_buff		; get buffer pointer high byte
	STA	tp_h			; save to temp pointer high byte
	LDA	#<pk_buff		; get IP buffer pointer low byte
	STA	tp_l			; save to temp pointer low byte
LAB_22105
	LDA	(tp_l),Y		; get byte from IP buffer
	STA	data_reg		; save to NIC
	INY				; increment index (pointer low byte)
	BNE	LAB_22110		; branch if no overflow

	INC	tp_h			; else increment pointer high byte
LAB_22110
	DEC	tc_l			; decrement count low byte
	BNE	LAB_22105		; loop if not all done

	DEC	tc_h			; else decrement count high byte
	BPL	LAB_22105		; loop if not all done

					; now calculate longword remainder
	LDA	tx_len_l		; get count low byte
	AND	#$03			; do MOD 4
	BEQ	LAB_21220		; exit if no remainder

					; else pad to next longword
	EOR	#$03			; do 3-MOD
	TAX				; copy to index
	LDA	#$00			; clear A
LAB_21215
	STA	data_reg		; save to NIC
	DEX				; decrement count
	BPL	LAB_21215		; loop if not all done

LAB_21220
	RTS

; *********************************************************************


Last page update: 29th February, 2004. e-mail me e-mail