Ethernet ROM start
[fpgaboy.git] / ethernet.asm
CommitLineData
43282fcf
JW
1ETH_STATUS EQU $FF68
2ETH_DATA EQU $FF69
3
4PUTC: MACRO
5 ld a, \1
6 call putc
7 ENDM
8
9PUTS: MACRO
10 ld hl, \1
11 call puts
12 ENDM
13
14PUTSI: MACRO
15 push hl
16 call putsi
17 db \1, 0
18 pop hl
19 ENDM
20
21PUTSIL: MACRO
22 push hl
23 call putsi
24 db \1, 13, 10, 0
25 pop hl
26 ENDM
27
28PUTHEX: MACRO
29 ld a, \1
30 call puthex
31 ENDM
32
33 SECTION "config", HOME[$0]
34myMAC: db $12, $34, $56, $78, $9A, $00
35myIP: db $0A, $00, $00, $02
36myMask: db $FF, $00, $00, $00
37myGW: db $0A, $00, $00, $01
38
39 SECTION "boot", HOME[$100]
40 jr start
41 nop
42 nop
43
44 db $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83 ;<<< no $00,$c3,$50,$01
45 db $00,$0C,$00,$0D,$00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6
46 db $DD,$DD,$D9,$99,$BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F
47 db $BB,$B9,$33,$3E ; Standard Nintendo DO NOT CHANGE...
48
49 db "GB Ethernet " ; Cart name 16bytes
50 db $00,$00,$00 ; Not used
51 db $00 ; Cart type ROM Only
52 db $00 ; ROM Size 32k
53 db $00 ; RAM Size 0k
54 db $cf,$08 ; Maker ID Matthew Johnson
55 db $01 ; Version =1
56 db $87 ; Complement check (Important)
57 db $ff,$ff ; Cheksum, fix this if you are going to
58
59start:
60 ld sp, $D800
61 PUTSIL "Ethernet test ROM"
62.lp: xor a ; Rest state machines
63 ld [ETH_STATUS], a
64 ld a, [ETH_STATUS] ; New shit?
65 ld [$FF51], a
66 and $02 ; New packet?
67 call nz, getpacket
68 jr .lp
69
70getpacket:
71 ld a, [ETH_DATA]
72 ld b, a
73 ld a, [ETH_DATA]
74 ld c, a
75 push bc
76 ld hl, $D000
77.cplp: ld a, b
78 or c
79 jr z, .done
80 dec bc
81 ld a, [ETH_DATA]
82 ld [hli], a
83 jr .cplp
84.done: pop bc
85 PUTSI "getpacket: Got "
86 PUTHEX b
87 PUTHEX c
88 PUTSIL " byte packet from hardware."
89 ld hl, $D000
90 call ether_input
91 ret
92
93ether_input:
94 push hl
95 PUTSI "ether_input: Packet to "
96 PUTHEX [hli]
97 PUTC $3A
98 PUTHEX [hli]
99 PUTC $3A
100 PUTHEX [hli]
101 PUTC $3A
102 PUTHEX [hli]
103 PUTC $3A
104 PUTHEX [hli]
105 PUTC $3A
106 PUTHEX [hli]
107 PUTSI " from "
108 PUTHEX [hli]
109 PUTC $3A
110 PUTHEX [hli]
111 PUTC $3A
112 PUTHEX [hli]
113 PUTC $3A
114 PUTHEX [hli]
115 PUTC $3A
116 PUTHEX [hli]
117 PUTC $3A
118 PUTHEX [hli]
119 PUTSI " protocol "
120 PUTHEX [hli]
121 PUTHEX [hli]
122 PUTSIL "."
123 pop hl
124
125 ; Verify the destination MAC.
126 push hl
127 ld de, myMAC
128 ld c, $06
129.maclp: ld a, [de]
130 cp [hl]
131 jr nz, .notus
132 inc de
133 inc hl
134 dec c
135 jr nz, .maclp
136 PUTSIL "ether_input: It's to us!"
137 pop hl
138
139 ret
140.notus: PUTSIL "ether_input: Not to us..."
141 pop hl
142 ret
143
144; SERIAL ROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
145
146putc:
147 push af
148.waitport:
149 ld a,[$FF53]
150 and $01
151 jr nz,.waitport
152 pop af
153 ld [$FF52],a
154 ret
155
156puts:
157 ld a, [hli]
158 cp $00
159 ret z
160 call putc
161 jr puts
162
163EX_SP_HL: MACRO
164 push de
165 di
166 add sp, 2
167 pop de
168 push hl
169 ld l, e
170 ld h, d
171 add sp, -2
172 ei
173 pop de
174 ENDM
175
176putsi:
177 pop hl
178 push af
179 push bc
180 push de
181.lp: ld a, [hli]
182 or a
183 jr z, .done
184 call putc
185 jr .lp
186.done: pop de
187 pop bc
188 pop af
189 push hl
190 ret
191
192puthex: ; Put two hex nibbles to the serial console.
193 push bc
194 push hl
195 push af
196 swap a
197 and $0F
198 ld hl,hex
199 ld b,0
200 ld c,a
201 add hl,bc
202 ld a, [hl]
203 call putc
204 pop af
205 and $0F
206 ld hl,hex
207 ld c,a
208 add hl,bc
209 ld a, [hl]
210 call putc
211 pop hl
212 pop bc
213 ret
214hex: db "0123456789ABCDEF"
This page took 0.033117 seconds and 4 git commands to generate.