]>
Commit | Line | Data |
---|---|---|
1 | ETH_STATUS EQU $FF68 | |
2 | ETH_DATA EQU $FF69 | |
3 | ||
4 | PUTC: MACRO | |
5 | ld a, \1 | |
6 | call putc | |
7 | ENDM | |
8 | ||
9 | PUTS: MACRO | |
10 | ld hl, \1 | |
11 | call puts | |
12 | ENDM | |
13 | ||
14 | PUTSI: MACRO | |
15 | push hl | |
16 | call putsi | |
17 | db \1, 0 | |
18 | pop hl | |
19 | ENDM | |
20 | ||
21 | PUTSIL: MACRO | |
22 | push hl | |
23 | call putsi | |
24 | db \1, 13, 10, 0 | |
25 | pop hl | |
26 | ENDM | |
27 | ||
28 | PUTHEX: MACRO | |
29 | ld a, \1 | |
30 | call puthex | |
31 | ENDM | |
32 | ||
33 | SECTION "config", HOME[$0] | |
34 | myMAC: db $12, $34, $56, $78, $9A, $00 | |
35 | myIP: db $0A, $00, $00, $02 | |
36 | myMask: db $FF, $00, $00, $00 | |
37 | myGW: 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 | ||
59 | start: | |
60 | ld sp, $D800 | |
61 | call zerobss | |
62 | PUTSIL "Ethernet test ROM" | |
63 | .lp: xor a ; Reset state machines | |
64 | ld [ETH_STATUS], a | |
65 | ld a, [ETH_STATUS] ; Load current status | |
66 | ld [$FF51], a | |
67 | and $02 ; New packet? | |
68 | call nz, getpacket | |
69 | jr .lp | |
70 | ||
71 | zerobss: | |
72 | ld hl, bssstart | |
73 | ld bc, bssend - bssstart | |
74 | .lp: ld a, b | |
75 | or c | |
76 | ret z | |
77 | dec bc | |
78 | xor a | |
79 | ld [hli], a | |
80 | ld a, h | |
81 | jr .lp | |
82 | ||
83 | getpacket: | |
84 | ld a, [ETH_DATA] | |
85 | ld b, a | |
86 | ld a, [ETH_DATA] | |
87 | ld c, a | |
88 | push bc | |
89 | ld hl, packet | |
90 | .cplp: ld a, b | |
91 | or c | |
92 | jr z, .done | |
93 | dec bc | |
94 | ld a, [ETH_DATA] | |
95 | ld [hli], a | |
96 | jr .cplp | |
97 | .done: pop bc | |
98 | PUTSI "getpacket: Got " | |
99 | PUTHEX b | |
100 | PUTHEX c | |
101 | PUTSIL " byte packet from hardware." | |
102 | ld hl, $D000 | |
103 | call ether_input | |
104 | ret | |
105 | ||
106 | ether_input: | |
107 | push hl | |
108 | PUTSI "ether_input: Packet to " | |
109 | PUTHEX [hli] | |
110 | PUTC $3A | |
111 | PUTHEX [hli] | |
112 | PUTC $3A | |
113 | PUTHEX [hli] | |
114 | PUTC $3A | |
115 | PUTHEX [hli] | |
116 | PUTC $3A | |
117 | PUTHEX [hli] | |
118 | PUTC $3A | |
119 | PUTHEX [hli] | |
120 | PUTSI " from " | |
121 | PUTHEX [hli] | |
122 | PUTC $3A | |
123 | PUTHEX [hli] | |
124 | PUTC $3A | |
125 | PUTHEX [hli] | |
126 | PUTC $3A | |
127 | PUTHEX [hli] | |
128 | PUTC $3A | |
129 | PUTHEX [hli] | |
130 | PUTC $3A | |
131 | PUTHEX [hli] | |
132 | PUTSI " protocol " | |
133 | PUTHEX [hli] | |
134 | PUTHEX [hli] | |
135 | PUTSIL "." | |
136 | pop hl | |
137 | ||
138 | ; Verify the destination MAC. | |
139 | push hl | |
140 | ld de, myMAC | |
141 | ld c, $06 | |
142 | .maclp: ld a, [de] | |
143 | cp [hl] | |
144 | jr nz, .notus | |
145 | inc de | |
146 | inc hl | |
147 | dec c | |
148 | jr nz, .maclp | |
149 | ; Done? Then it was to us! | |
150 | jr .us | |
151 | .notus: ; Was it to broadcast? | |
152 | pop hl | |
153 | push hl | |
154 | ld c, $06 | |
155 | .bclp: ld a, [hli] | |
156 | cp $FF | |
157 | jr nz, .notbc | |
158 | dec c | |
159 | jr nz, .bclp | |
160 | ||
161 | .us: PUTSIL "ether_input: It's to us!" | |
162 | ; Which protocol does it belong to? | |
163 | pop hl | |
164 | ld b, $00 | |
165 | ld c, 12 | |
166 | add hl, bc ; Skip source and dest MAC. | |
167 | ld a, [hli] | |
168 | cp $08 | |
169 | jr nz, .unknownproto | |
170 | ld a, [hli] | |
171 | cp $06 | |
172 | jr z, .arp | |
173 | cp $00 | |
174 | jp z, .ip | |
175 | jr .unknownproto | |
176 | ||
177 | .notbc: pop hl | |
178 | PUTSIL "ether_input: Not addressed to us and not broadcast." | |
179 | ret | |
180 | ||
181 | .unknownproto: | |
182 | PUTSIL "ether_input: Unknown protocol; dropping" | |
183 | ret | |
184 | ||
185 | .arp: | |
186 | PUTSIL "ether_input: ARP packet" | |
187 | call arp_input | |
188 | ret | |
189 | .ip: | |
190 | PUTSIL "ether_input: IP packet" | |
191 | call ip_input | |
192 | ret | |
193 | ||
194 | arp_input: | |
195 | ret | |
196 | ||
197 | ip_input: | |
198 | ret | |
199 | ||
200 | SECTION "ethdata", BSS | |
201 | bssstart DS 0 | |
202 | packet DS 1552 | |
203 | bssend DS 0 | |
204 | ||
205 | ||
206 | ; SERIAL ROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
207 | SECTION "serial", HOME | |
208 | ||
209 | putc: | |
210 | push af | |
211 | .waitport: | |
212 | ld a,[$FF53] | |
213 | and $01 | |
214 | jr nz,.waitport | |
215 | pop af | |
216 | ld [$FF52],a | |
217 | ret | |
218 | ||
219 | puts: | |
220 | ld a, [hli] | |
221 | cp $00 | |
222 | ret z | |
223 | call putc | |
224 | jr puts | |
225 | ||
226 | EX_SP_HL: MACRO | |
227 | push de | |
228 | di | |
229 | add sp, 2 | |
230 | pop de | |
231 | push hl | |
232 | ld l, e | |
233 | ld h, d | |
234 | add sp, -2 | |
235 | ei | |
236 | pop de | |
237 | ENDM | |
238 | ||
239 | putsi: | |
240 | pop hl | |
241 | push af | |
242 | push bc | |
243 | push de | |
244 | .lp: ld a, [hli] | |
245 | or a | |
246 | jr z, .done | |
247 | call putc | |
248 | jr .lp | |
249 | .done: pop de | |
250 | pop bc | |
251 | pop af | |
252 | push hl | |
253 | ret | |
254 | ||
255 | puthex: ; Put two hex nibbles to the serial console. | |
256 | push bc | |
257 | push hl | |
258 | push af | |
259 | swap a | |
260 | and $0F | |
261 | ld hl,hex | |
262 | ld b,0 | |
263 | ld c,a | |
264 | add hl,bc | |
265 | ld a, [hl] | |
266 | call putc | |
267 | pop af | |
268 | and $0F | |
269 | ld hl,hex | |
270 | ld c,a | |
271 | add hl,bc | |
272 | ld a, [hl] | |
273 | call putc | |
274 | pop hl | |
275 | pop bc | |
276 | ret | |
277 | hex: db "0123456789ABCDEF" |