From: Joshua Wise Date: Mon, 26 May 2008 06:02:57 +0000 (-0400) Subject: Ethernet ROM start X-Git-Url: http://git.joshuawise.com/fpgaboy.git/commitdiff_plain/43282fcf13e571f4a57dd8df10ea9b4f7f8d1bca?ds=sidebyside;hp=faa9ae6fee7e9c9f624cafdd0df7be4dc7ca973c Ethernet ROM start --- diff --git a/ethernet.asm b/ethernet.asm new file mode 100644 index 0000000..4bcee82 --- /dev/null +++ b/ethernet.asm @@ -0,0 +1,214 @@ +ETH_STATUS EQU $FF68 +ETH_DATA EQU $FF69 + +PUTC: MACRO + ld a, \1 + call putc + ENDM + +PUTS: MACRO + ld hl, \1 + call puts + ENDM + +PUTSI: MACRO + push hl + call putsi + db \1, 0 + pop hl + ENDM + +PUTSIL: MACRO + push hl + call putsi + db \1, 13, 10, 0 + pop hl + ENDM + +PUTHEX: MACRO + ld a, \1 + call puthex + ENDM + + SECTION "config", HOME[$0] +myMAC: db $12, $34, $56, $78, $9A, $00 +myIP: db $0A, $00, $00, $02 +myMask: db $FF, $00, $00, $00 +myGW: db $0A, $00, $00, $01 + + SECTION "boot", HOME[$100] + jr start + nop + nop + + db $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83 ;<<< no $00,$c3,$50,$01 + db $00,$0C,$00,$0D,$00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6 + db $DD,$DD,$D9,$99,$BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F + db $BB,$B9,$33,$3E ; Standard Nintendo DO NOT CHANGE... + + db "GB Ethernet " ; Cart name 16bytes + db $00,$00,$00 ; Not used + db $00 ; Cart type ROM Only + db $00 ; ROM Size 32k + db $00 ; RAM Size 0k + db $cf,$08 ; Maker ID Matthew Johnson + db $01 ; Version =1 + db $87 ; Complement check (Important) + db $ff,$ff ; Cheksum, fix this if you are going to + +start: + ld sp, $D800 + PUTSIL "Ethernet test ROM" +.lp: xor a ; Rest state machines + ld [ETH_STATUS], a + ld a, [ETH_STATUS] ; New shit? + ld [$FF51], a + and $02 ; New packet? + call nz, getpacket + jr .lp + +getpacket: + ld a, [ETH_DATA] + ld b, a + ld a, [ETH_DATA] + ld c, a + push bc + ld hl, $D000 +.cplp: ld a, b + or c + jr z, .done + dec bc + ld a, [ETH_DATA] + ld [hli], a + jr .cplp +.done: pop bc + PUTSI "getpacket: Got " + PUTHEX b + PUTHEX c + PUTSIL " byte packet from hardware." + ld hl, $D000 + call ether_input + ret + +ether_input: + push hl + PUTSI "ether_input: Packet to " + PUTHEX [hli] + PUTC $3A + PUTHEX [hli] + PUTC $3A + PUTHEX [hli] + PUTC $3A + PUTHEX [hli] + PUTC $3A + PUTHEX [hli] + PUTC $3A + PUTHEX [hli] + PUTSI " from " + PUTHEX [hli] + PUTC $3A + PUTHEX [hli] + PUTC $3A + PUTHEX [hli] + PUTC $3A + PUTHEX [hli] + PUTC $3A + PUTHEX [hli] + PUTC $3A + PUTHEX [hli] + PUTSI " protocol " + PUTHEX [hli] + PUTHEX [hli] + PUTSIL "." + pop hl + + ; Verify the destination MAC. + push hl + ld de, myMAC + ld c, $06 +.maclp: ld a, [de] + cp [hl] + jr nz, .notus + inc de + inc hl + dec c + jr nz, .maclp + PUTSIL "ether_input: It's to us!" + pop hl + + ret +.notus: PUTSIL "ether_input: Not to us..." + pop hl + ret + +; SERIAL ROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +putc: + push af +.waitport: + ld a,[$FF53] + and $01 + jr nz,.waitport + pop af + ld [$FF52],a + ret + +puts: + ld a, [hli] + cp $00 + ret z + call putc + jr puts + +EX_SP_HL: MACRO + push de + di + add sp, 2 + pop de + push hl + ld l, e + ld h, d + add sp, -2 + ei + pop de + ENDM + +putsi: + pop hl + push af + push bc + push de +.lp: ld a, [hli] + or a + jr z, .done + call putc + jr .lp +.done: pop de + pop bc + pop af + push hl + ret + +puthex: ; Put two hex nibbles to the serial console. + push bc + push hl + push af + swap a + and $0F + ld hl,hex + ld b,0 + ld c,a + add hl,bc + ld a, [hl] + call putc + pop af + and $0F + ld hl,hex + ld c,a + add hl,bc + ld a, [hl] + call putc + pop hl + pop bc + ret +hex: db "0123456789ABCDEF"