Skip to content

Commit 0141153

Browse files
committed
Discern between devices with CPU CGB A and B revision SOCs
1 parent 33a0840 commit 0141153

File tree

3 files changed

+75
-7
lines changed

3 files changed

+75
-7
lines changed

LICENSE

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

3-
Copyright (c) 2020 Matt Currie
3+
Copyright (c) 2020-2022 Matt Currie
4+
Copyright (c) 2022 Lior Halphon (LIJI32)
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Just a little Game Boy ROM which tries to determine which model/revision your device is.
44

5-
It makes use of register values at boot, "extra OAM" differences, PPU quirks, and APU quirks that differ between device revisions.
5+
It makes use of register values at boot, "extra OAM" differences, PPU quirks, APU quirks, and OAM DMA bus conflicts that differ between device revisions.
66

77
## Limitations
88

@@ -16,7 +16,8 @@ Currently it cannot discern between all SoC revisions. Devices will be reported
1616
- SGB-CPU 01
1717
- CPU SGB2
1818
- CPU CGB
19-
- CPU CGB A/B
19+
- CPU CGB A
20+
- CPU CGB B
2021
- CPU CGB C
2122
- CPU CGB D
2223
- CPU CGB E
@@ -25,6 +26,10 @@ Currently it cannot discern between all SoC revisions. Devices will be reported
2526

2627
## Release Notes
2728

29+
v0.4
30+
31+
- Use an OAM DMA bus conflict to discern between devices with CPU CGB A and CPU CGB B revision SOCs. Thanks to [LIJI32](https://github.com/LIJI32/) for discovering this!
32+
2833
v0.3
2934

3035
- 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
@@ -43,6 +48,7 @@ v0.2
4348

4449
## Credits
4550

51+
- Thanks to Lior Halphon (LIJI32) for his research and [SameSuite](https://github.com/LIJI32/SameSuite) test ROMs.
4652
- Thanks to authors of [Gameboy sound hardware](https://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware) on the Gameboy Development Wiki.
4753
- Thanks to Joonas Javanainen (gekkio) for his [mooneye-gb](https://github.com/Gekkio/mooneye-gb/) test ROMs which document the register values at boot.
4854
- Written by Matt Currie.

src/which.asm

+65-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ SECTION "main", ROM0[$150]
5858

5959
main::
6060
di
61-
ld sp, $cfff
61+
ld sp, $ffff
6262

6363
ld [wInitialA], a
6464
ld a, b
@@ -70,7 +70,7 @@ main::
7070
call ResetCursor
7171
call LoadFont
7272

73-
print_string_literal "which.gb v0.3\n-------------\n\nseems to be a...\n\n"
73+
print_string_literal "which.gb v0.4\n-------------\n\nseems to be a...\n\n"
7474

7575
ld a, [wInitialA]
7676
cp $01
@@ -182,7 +182,16 @@ is_cgbABC::
182182
jr nz, is_cgbC
183183

184184
is_cgbAB::
185-
print_string_literal "CPU CGB A/B"
185+
call check_cgb_a_or_b
186+
cp $aa
187+
jr nz, is_cgbB
188+
189+
is_cgbA::
190+
print_string_literal "CPU CGB A"
191+
jp done
192+
193+
is_cgbB::
194+
print_string_literal "CPU CGB B"
186195
jp done
187196

188197
is_cgbC::
@@ -322,4 +331,56 @@ check_agb_or_ags::
322331
ldh [rSCX], a
323332
pop af
324333

325-
ret
334+
ret
335+
336+
337+
; Check some OAM DMA bus conflict behavior to test if it is a CGB CPU A or B.
338+
; Code lifted from LIJI32's `dma_write_timing-wram-C0ACA.asm`
339+
;
340+
; @return a `$aa` on CPU CGB A, or `$00` on CPU CGB B
341+
check_cgb_a_or_b::
342+
ld hl, ._HRAMRoutine
343+
ld de, HRAMRoutine
344+
ld bc, ._HRAMRoutineEnd - ._HRAMRoutine
345+
call MemCopy
346+
347+
ld hl, ._VRAMRoutine
348+
ld de, VRAMRoutine
349+
ld bc, ._VRAMRoutineEnd - ._VRAMRoutine
350+
call MemCopy
351+
352+
call .ResetWRAM
353+
jp VRAMRoutine
354+
355+
._HRAMRoutine::
356+
ld b, $40
357+
.wait:
358+
dec b
359+
jr nz, .wait
360+
ret
361+
._HRAMRoutineEnd:
362+
363+
._VRAMRoutine::
364+
ld a, $c1
365+
ld b, $aa
366+
ld hl, $c155
367+
ldh [rDMA], a
368+
ld [hl], b
369+
call HRAMRoutine
370+
ld a, [$fe00]
371+
ret
372+
._VRAMRoutineEnd:
373+
374+
HRAMRoutine EQU $ff80
375+
VRAMRoutine EQU $a000 - (._VRAMRoutineEnd - ._VRAMRoutine)
376+
377+
.ResetWRAM::
378+
ld a, $f0
379+
ld [$fe00], a
380+
ld hl, $c100
381+
ld a, $10
382+
.loop:
383+
ld [hl+], a
384+
inc a
385+
jr nz, .loop
386+
ret

0 commit comments

Comments
 (0)