Skip to content

Commit 7d8f188

Browse files
committed
Discern between devices with CPU AGB 0/A/A E and CPU AGB B/B E revisions
1 parent c580219 commit 7d8f188

File tree

2 files changed

+85
-13
lines changed

2 files changed

+85
-13
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ Currently it cannot discern between all SoC revisions. Devices will be reported
2020
- CPU CGB C
2121
- CPU CGB D
2222
- CPU CGB E
23-
- CPU AGB ?
23+
- CPU AGB 0/A/A E
24+
- CPU AGB B/B E
2425

2526
## Release Notes
2627

28+
v0.3
29+
30+
- Use VRAM reads at the transition from PPU mode 3 to mode 0 discern between devices with CPU AGB 0/A/A E (AGB and GB Player) and CPU AGB B/B E (AGS) revisions
31+
2732
v0.2.2
2833

2934
- Discern between CPU CGB 0/A/B/C, CPU CGB D, and CPU CGB E revisions using more simple "extra OAM" test

src/which.asm

+79-12
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ main::
6666
call ResetCursor
6767
call LoadFont
6868

69-
lcd_on
70-
71-
print_string_literal "which.gb v0.2.2\\n---------------\\n\\nseems to be a...\\n\\n"
69+
print_string_literal "which.gb v0.3\\n-------------\\n\\nseems to be a...\\n\\n"
7270

7371
ld a, [wInitialA]
7472
cp $01
@@ -78,7 +76,7 @@ main::
7876
jp z, is_mgb_or_sgb2
7977

8078
cp $11
81-
jp z, is_cgb_or_agb
79+
jp z, is_cgb_or_agb_or_ags
8280

8381
print_string_literal "Unknown!"
8482
jp done
@@ -123,14 +121,10 @@ is_mgb::
123121

124122

125123

126-
is_cgb_or_agb::
124+
is_cgb_or_agb_or_ags::
127125
ld a, [wInitialB]
128126
cp $00
129-
jr z, is_cgb
130-
131-
is_agb::
132-
print_string_literal "CPU AGB ?"
133-
jp done
127+
jp nz, is_agb_or_ags
134128

135129
is_cgb::
136130
; wave ram is not initialised on cgb0
@@ -204,8 +198,25 @@ is_cgb0::
204198
jp done
205199

206200

207-
done:
208-
jr done
201+
is_agb_or_ags::
202+
call check_agb_or_ags
203+
cp $22
204+
jr z, is_ags
205+
206+
is_agb::
207+
print_string_literal "CPU AGB 0/A/A E"
208+
jp done
209+
210+
is_ags::
211+
print_string_literal "CPU AGB B/B E"
212+
jp done
213+
214+
215+
done::
216+
lcd_on
217+
218+
.forever:
219+
jr .forever
209220

210221

211222

@@ -252,3 +263,59 @@ check_cgb_ab_or_c::
252263
ld a, [hl]
253264

254265
ret
266+
267+
268+
; Check how VRAM reads behave at the transition from mode 3 to mode 0.
269+
; Assumes LCD is off, and leaves LCD on afterwards.
270+
;
271+
; @return a `$11` on AGB devices, or `$22` on AGS devices
272+
check_agb_or_ags::
273+
; fill tile data from $8000-8fff with alternating $11 and $22 values
274+
ld hl, $8000
275+
ld bc, $1000 / 2
276+
.tile_data_loop:
277+
ld a, $11
278+
ld [hl+], a
279+
ld a, $22
280+
ld [hl+], a
281+
dec bc
282+
ld a, b
283+
or c
284+
jr nz, .tile_data_loop
285+
286+
; fill first row of tile map with $00
287+
xor a
288+
ld hl, $9c00
289+
ld bc, 32
290+
call MemSetSmall
291+
292+
; configure ppu registers
293+
bg_map_9c00
294+
bg_tile_data_8800
295+
xor a
296+
ldh [rSCY], a
297+
ld a, 3
298+
ldh [rSCX], a ; SCX must be 3 to get the correct timing
299+
300+
; turn on the lcd
301+
ld hl, rLCDC
302+
set 7, [hl]
303+
304+
ld hl, $8000
305+
delay 172
306+
307+
; first read is $00
308+
ld a, [hl]
309+
310+
; second read is $11 or $22
311+
delay 114 - 2
312+
ld a, [hl]
313+
314+
; reset registers to original values
315+
push af
316+
bg_map_9800
317+
xor a
318+
ldh [rSCX], a
319+
pop af
320+
321+
ret

0 commit comments

Comments
 (0)