summaryrefslogtreecommitdiff
path: root/src/boot/z_locale.c
blob: a517f561ced62c71976d8db4a3c8ad39cd818685 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "libu64/debug.h"
#include "alignment.h"
#include "carthandle.h"
#include "line_numbers.h"
#include "padmgr.h"
#include "printf.h"
#include "region.h"
#include "terminal.h"
#include "translation.h"
#include "versions.h"
#include "vi_mode.h"
#include "z_locale.h"

s32 gCurrentRegion = 0;

typedef struct LocaleCartInfo {
    /* 0x00 */ char name[0x18];
    /* 0x18 */ u32 mediaFormat;
    /* 0x1C */ union {
        struct {
            u16 cartId;
            u8 countryCode;
            u8 version;
        };
        u32 regionInfo;
    };
} LocaleCartInfo; // size = 0x20

void Locale_Init(void) {
#if !PLATFORM_GC
    ALIGNED(4) u8 regionInfo[4];
    u8 countryCode;

    osEPiReadIo(gCartHandle, 0x3C, (u32*)regionInfo);

    countryCode = regionInfo[2];
#else
    static LocaleCartInfo sCartInfo;
    u8 countryCode;

    osEPiReadIo(gCartHandle, 0x38, &sCartInfo.mediaFormat);
    osEPiReadIo(gCartHandle, 0x3C, &sCartInfo.regionInfo);

    countryCode = sCartInfo.countryCode;
#endif

#if !PLATFORM_IQUE
    switch (countryCode) {
        case 'J': // "NTSC-J (Japan)"
            gCurrentRegion = REGION_JP;
            break;
        case 'E': // "NTSC-U (North America)"
            gCurrentRegion = REGION_US;
            break;
#if OOT_VERSION >= PAL_1_0
        case 'P': // "PAL (Europe)"
            gCurrentRegion = REGION_EU;
            break;
#endif
        default:
            PRINTF_COLOR_ERROR();
            PRINTF(T("z_locale_init: 日本用かアメリカ用か判別できません\n",
                     "z_locale_init: Can't tell if it's for Japan or America\n"));
            LogUtils_HungupThread("../z_locale.c", LN4(86, 92, 101, UNK_LINE, 118));
            PRINTF(VT_RST);
            break;
    }

    PRINTF(T("z_locale_init:日本用かアメリカ用か3コンで判断させる\n",
             "z_locale_init: Determine whether it is for Japan or America using 3 controls\n"));
#else
    gCurrentRegion = REGION_US;
#endif
}

void Locale_ResetRegion(void) {
    gCurrentRegion = REGION_NULL;
}

#if DEBUG_FEATURES
u32 func_80001F48(void) {
    if (gCurrentRegion == OOT_REGION) {
        return 0;
    }

    if (gPadMgr.validCtrlrsMask & 4) {
        return 0;
    }

    return 1;
}

u32 func_80001F8C(void) {
    if (gCurrentRegion == OOT_REGION) {
        return 0;
    }

    if (gPadMgr.validCtrlrsMask & 4) {
        return 1;
    }

    return 0;
}

// This function appears to be unused?
u32 Locale_IsRegionNative(void) {
    return gCurrentRegion == OOT_REGION;
}
#endif