gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/sm83/duck/megaduck_model.c
1 #include <gbdk/platform.h>
2 #include <stdint.h>
3 #include <stdbool.h>
4
5 #include <duck/model.h>
6
7
8 #define MEGADUCK_MODEL_TILE_ADDR_CHECK 0x8D00u // First tile at 0x8D00, Second tile at 0x8D10
9
10 // 2 consecutive Tiles:
11 // * Spanish model: Upside-down black Question Mark and Exclamation Point
12 // * German model: 2 pixel tall black Underscore and Inverted 0 on dark grey background
13 //
14 // Note: It may be sufficient to just check 1 tile
15 static const uint8_t model_spanish_tiles[32] = {
16 0x00u, 0x00u, 0x18u, 0x18u, 0x00u, 0x00u, 0x38u, 0x38u, 0x70u, 0x70u, 0x72u, 0x72u, 0x76u, 0x76u, 0x3Cu, 0x3Cu, // Upside-down black Question Mark
17 0x00u, 0x00u, 0x18u, 0x18u, 0x00u, 0x00u, 0x18u, 0x18u, 0x3Cu, 0x3Cu, 0x3Cu, 0x3Cu, 0x3Cu, 0x3Cu, 0x18u, 0x18u, // Upside-down black Exclamation Point
18 };
19
20 static const uint8_t model_german_tiles[32] = {
21 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0xFFu, 0xFFu, 0xFFu, 0xFFu, // 2 pixel tall black Underscore
22 0x00u, 0xFFu, 0x00u, 0xC3u, 0x00u, 0x99u, 0x00u, 0x99u, 0x00u, 0x99u, 0x00u, 0x99u, 0x00u, 0xC3u, 0x00u, 0xFFu, // Inverted 0 on dark grey background
23 };
24
25 #define MODEL_SPANISH_TILES_SZ (sizeof(model_spanish_tiles) / sizeof(model_spanish_tiles[0]))
26 #define MODEL_GERMAN_TILES_SZ (sizeof(model_german_tiles) / sizeof(model_german_tiles[0]))
27
28
29 static bool vram_memcmp(const uint8_t * p_buf, uint8_t * p_vram, uint8_t cmp_size) {
30
31 while (cmp_size--) {
32 if (get_vram_byte(p_vram++) != *p_buf++) {
33 return false;
34 }
35 }
36 return true;
37 }
38
39
40 // This detection should be called immediately at the start of
41 // the program for most reliable results, since it relies on
42 // inspecting uncleared VRAM contents.
43 uint8_t duck_check_model(void) {
44
45 if (vram_memcmp(model_spanish_tiles, (uint8_t *)MEGADUCK_MODEL_TILE_ADDR_CHECK, MODEL_SPANISH_TILES_SZ)) {
46 return MEGADUCK_LAPTOP_SPANISH;
47 }
48
49 // Check German
50 if (vram_memcmp(model_german_tiles, (uint8_t *)MEGADUCK_MODEL_TILE_ADDR_CHECK, MODEL_SPANISH_TILES_SZ)) {
51 return MEGADUCK_LAPTOP_GERMAN;
52 }
53
54 return MEGADUCK_HANDHELD_STANDARD; // Default
55 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.