1 /***************************************************************************
2 * Nintendo GameCube/Wii disc-header classifier *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #include "nintendo_disc_header.h"
12 #define NINTENDO_WII_MAGIC 0x5d1c9ea3u
13 #define NINTENDO_GAMECUBE_MAGIC 0xc2339f3du
15 static uint32_t nintendo_read_be32(const uint8_t *data) {
16 return ((uint32_t)data[0] << 24) |
17 ((uint32_t)data[1] << 16) |
18 ((uint32_t)data[2] << 8) |
22 nintendo_disc_header_type nintendo_disc_header_detect(
23 const uint8_t *sector,
26 if (!sector || sector_length < 0x20)
27 return NINTENDO_DISC_HEADER_UNKNOWN;
29 if (nintendo_read_be32(sector + 0x18) == NINTENDO_WII_MAGIC)
30 return NINTENDO_DISC_HEADER_WII;
32 if (nintendo_read_be32(sector + 0x1c) == NINTENDO_GAMECUBE_MAGIC)
33 return NINTENDO_DISC_HEADER_GAMECUBE;
35 return NINTENDO_DISC_HEADER_UNKNOWN;
38 const char *nintendo_disc_header_type_name(
39 nintendo_disc_header_type type
42 case NINTENDO_DISC_HEADER_GAMECUBE:
44 case NINTENDO_DISC_HEADER_WII: