2013-12-13 21:24:03 +00:00
|
|
|
; ip65 main routines
|
|
|
|
|
2018-02-23 15:36:05 +00:00
|
|
|
.include "../inc/common.inc"
|
|
|
|
.include "../inc/error.inc"
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
.export ip65_init
|
|
|
|
.export ip65_process
|
|
|
|
.export ip65_random_word
|
|
|
|
.export ip65_ctr
|
|
|
|
.export ip65_ctr_arp
|
|
|
|
.export ip65_ctr_ip
|
|
|
|
|
|
|
|
.export ip65_error
|
|
|
|
|
|
|
|
.import eth_init
|
|
|
|
.import timer_init
|
|
|
|
.import arp_init
|
|
|
|
.import ip_init
|
|
|
|
.import timer_read
|
|
|
|
|
|
|
|
.import eth_inp
|
|
|
|
.import eth_outp
|
|
|
|
.import eth_rx
|
|
|
|
|
|
|
|
.import ip_process
|
|
|
|
.import arp_process
|
|
|
|
|
|
|
|
.importzp eth_proto_arp
|
|
|
|
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
ip65_error: .res 1 ; last error code
|
|
|
|
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
; 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
|
2013-12-13 21:24:03 +00:00
|
|
|
ip65_random_word:
|
|
|
|
jsr timer_read ;sets AX
|
2015-02-16 16:48:48 +00:00
|
|
|
adc $4e ; on an Apple 2, this is RNDL
|
2013-12-27 13:57:56 +00:00
|
|
|
adc $9004 ; on a VIC 20, this is the raster register
|
2015-02-16 16:48:48 +00:00
|
|
|
adc $d41b ; on a C64, this is a 'random' number from the SID
|
2018-09-09 23:09:14 +00:00
|
|
|
adc $d20a ; on an Atari, this is a 'random' number from the POKEY
|
2013-12-13 21:24:03 +00:00
|
|
|
pha
|
|
|
|
adc ip65_ctr_arp
|
2013-12-27 13:57:56 +00:00
|
|
|
ora #$08 ; make sure we grab at least 8 bytes from eth_inp
|
|
|
|
tax
|
|
|
|
: adc eth_inp,x
|
2013-12-13 21:24:03 +00:00
|
|
|
adc eth_outp,x
|
|
|
|
dex
|
|
|
|
bne :-
|
|
|
|
tax
|
|
|
|
pla
|
|
|
|
adc ip65_ctr
|
|
|
|
eor ip65_ctr_ip
|
|
|
|
rts
|
|
|
|
|
|
|
|
; 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
|
2019-05-02 12:44:24 +00:00
|
|
|
; inputs: A = adaptor specific initialisation value or 'eth_init_default'
|
2015-02-16 21:35:29 +00:00
|
|
|
; outputs: carry flag is set if there was an error, clear otherwise
|
2013-12-13 21:24:03 +00:00
|
|
|
ip65_init:
|
2013-12-27 13:57:56 +00:00
|
|
|
jsr eth_init ; initialize ethernet driver
|
|
|
|
|
|
|
|
bcc @ok
|
2018-02-23 15:41:33 +00:00
|
|
|
lda #IP65_ERROR_DEVICE_FAILURE
|
2013-12-13 21:24:03 +00:00
|
|
|
sta ip65_error
|
|
|
|
rts
|
2013-12-27 13:57:56 +00:00
|
|
|
@ok:
|
|
|
|
jsr timer_init ; initialize timer
|
|
|
|
jsr arp_init ; initialize arp
|
|
|
|
jsr ip_init ; initialize ip, icmp, udp, and tcp
|
|
|
|
clc
|
|
|
|
rts
|
|
|
|
|
|
|
|
; 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.
|
2013-12-13 21:24:03 +00:00
|
|
|
ip65_process:
|
2013-12-27 13:57:56 +00:00
|
|
|
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
|
2013-12-13 21:24:03 +00:00
|
|
|
@done:
|
2013-12-27 13:57:56 +00:00
|
|
|
rts
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
@arp:
|
2013-12-27 13:57:56 +00:00
|
|
|
inc ip65_ctr_arp
|
|
|
|
jmp arp_process
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
@ip:
|
2013-12-27 13:57:56 +00:00
|
|
|
inc ip65_ctr_ip
|
|
|
|
jmp ip_process
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; -- LICENSE FOR ip65.s --
|
2013-12-13 21:24:03 +00:00
|
|
|
; The contents of this file are subject to the Mozilla Public License
|
|
|
|
; Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
; compliance with the License. You may obtain a copy of the License at
|
|
|
|
; http://www.mozilla.org/MPL/
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; Software distributed under the License is distributed on an "AS IS"
|
|
|
|
; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
; License for the specific language governing rights and limitations
|
|
|
|
; under the License.
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; The Original Code is ip65.
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; The Initial Developer of the Original Code is Per Olofsson,
|
|
|
|
; MagerValp@gmail.com.
|
|
|
|
; Portions created by the Initial Developer are Copyright (C) 2009
|
2013-12-27 13:57:56 +00:00
|
|
|
; Per Olofsson. All Rights Reserved.
|
2013-12-13 21:24:03 +00:00
|
|
|
; -- LICENSE END --
|