]> Joshua Wise's Git repositories - fpgaboy.git/blobdiff - ethernet.asm
New ethernet code
[fpgaboy.git] / ethernet.asm
index 4bcee8263505e3741c7987b02117263358d3434c..85d66e1b38e1a1fe8d2528e50719eaf5e29dd379 100644 (file)
@@ -58,22 +58,35 @@ myGW:       db $0A, $00, $00, $01
 
 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
@@ -133,15 +146,65 @@ ether_input:
        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
This page took 0.025912 seconds and 4 git commands to generate.