reg [2:0] transition_timeout;
always @(posedge rxclk) if(in_data[2]^in_data[1]) transition_timeout<=0; else if(~&cnt) transition_timeout<=transition_timeout+1;
always @(posedge rxclk) end_of_Ethernet_frame <= &transition_timeout;
+ reg [11:0] iaddr;
/////////////////////////////////////////////////
always @(posedge rxclk)
if (new_byte_available && !pktrdy) begin
odata <= data;
- oaddr <= oaddr + 1;
+ oaddr <= iaddr;
+ iaddr <= iaddr + 1;
wr <= 1;
- end else if (end_of_Ethernet_frame && (oaddr > 1)) begin
- olength <= oaddr;
- oaddr <= 0;
+ end else if (end_of_Ethernet_frame && (iaddr > 1)) begin
+ olength <= iaddr;
+ iaddr <= 0;
wr <= 0;
pktrdy <= 1;
end else if (pktclear) begin
start:
ld sp, $D800
+ call zerobss
PUTSIL "Ethernet test ROM"
-.lp: xor a ; Rest state machines
+.lp: xor a ; Reset state machines
ld [ETH_STATUS], a
- ld a, [ETH_STATUS] ; New shit?
+ ld a, [ETH_STATUS] ; Load current status
ld [$FF51], a
and $02 ; New packet?
call nz, getpacket
jr .lp
+zerobss:
+ ld hl, bssstart
+ ld bc, bssend - bssstart
+.lp: ld a, b
+ or c
+ ret z
+ dec bc
+ xor a
+ ld [hli], a
+ ld a, h
+ jr .lp
+
getpacket:
ld a, [ETH_DATA]
ld b, a
ld a, [ETH_DATA]
ld c, a
push bc
- ld hl, $D000
+ ld hl, packet
.cplp: ld a, b
or c
jr z, .done
inc hl
dec c
jr nz, .maclp
- PUTSIL "ether_input: It's to us!"
+ ; Done? Then it was to us!
+ jr .us
+.notus: ; Was it to broadcast?
pop hl
+ push hl
+ ld c, $06
+.bclp: ld a, [hli]
+ cp $FF
+ jr nz, .notbc
+ dec c
+ jr nz, .bclp
+
+.us: PUTSIL "ether_input: It's to us!"
+ ; Which protocol does it belong to?
+ pop hl
+ ld b, $00
+ ld c, 12
+ add hl, bc ; Skip source and dest MAC.
+ ld a, [hli]
+ cp $08
+ jr nz, .unknownproto
+ ld a, [hli]
+ cp $06
+ jr z, .arp
+ cp $00
+ jp z, .ip
+ jr .unknownproto
+
+.notbc: pop hl
+ PUTSIL "ether_input: Not addressed to us and not broadcast."
+ ret
+.unknownproto:
+ PUTSIL "ether_input: Unknown protocol; dropping"
ret
-.notus: PUTSIL "ether_input: Not to us..."
- pop hl
+
+.arp:
+ PUTSIL "ether_input: ARP packet"
+ call arp_input
+ ret
+.ip:
+ PUTSIL "ether_input: IP packet"
+ call ip_input
ret
+arp_input:
+ ret
+
+ip_input:
+ ret
+
+ SECTION "ethdata", BSS
+bssstart DS 0
+packet DS 1552
+bssend DS 0
+
+
; SERIAL ROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ SECTION "serial", HOME
putc:
push af