summaryrefslogtreecommitdiff
path: root/arm9/src/error_message_reset.c
blob: 12af3c6f43391dc97a3adef1c107161e4f109127 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "error_message_reset.h"
#include "GX_layers.h"
#include "gx.h"
#include "unk_02031734.h"
#include "unk_0202F150.h"
#include "bg_window.h"
#include "PAD_pad.h"
#include "font.h"
#include "brightness.h"
#include "render_window.h"


const struct WindowTemplate UNK_020FF49C = {
    .bgId = GF_BG_LYR_MAIN_0,
    .tilemapLeft = 3,
    .tilemapTop = 3,
    .width = 26,
    .height = 18,
    .paletteNum = 1,
    .baseTile = 0x23
};

const struct HeapParam UNK_020FF4A4[] = {
    {0x00020000, OS_ARENA_MAIN}
};

const struct GraphicsModes UNK_020FF4AC = { .dispMode = GX_DISPMODE_GRAPHICS };

const struct BgTemplate UNK_020FF4BC = {
    .x = 0,
    .y = 0,
    .bufferSize = 0x800,
    .baseTile = 0,
    .size = GF_BG_SCR_SIZE_256x256,
    .colorMode = GX_BG_COLORMODE_16,
    .screenBase = GX_BG_SCRBASE_0x0000, .charBase = GX_BG_CHARBASE_0x18000,
    .bgExtPltt = GX_BG_EXTPLTT_01,
    .priority = 1,
    .areaOver = 0,
    .mosaic = FALSE
};

const struct GraphicsBanks UNK_020FF4D8 = { .bg = 3 };

u32 sErrorMessagePrinterLock;

extern void FUN_0200E3A0(PMLCDTarget, int);
extern void FUN_0200E394(u32 param0);

THUMB_FUNC void VBlankHandler()
{
    OS_SetIrqCheckFlag(OS_IE_V_BLANK);
    MI_WaitDma(3);
}

THUMB_FUNC void PrintErrorMessageAndReset()
{

    struct BgConfig *ptr;
    struct Window buf;

    if (sErrorMessagePrinterLock != 1)
    {
        sErrorMessagePrinterLock = 1;
        OS_SetArenaHi(OS_ARENA_MAIN, OS_GetInitArenaHi(OS_ARENA_MAIN));
        OS_SetArenaLo(OS_ARENA_MAIN, OS_GetInitArenaLo(OS_ARENA_MAIN));

        InitHeapSystem(UNK_020FF4A4, NELEMS(UNK_020FF4A4), 1, 0);
        FUN_0200E3A0(PM_LCD_TOP, 0);
        FUN_0200E3A0(PM_LCD_BOTTOM, 0);

        OS_DisableIrqMask(OS_IE_V_BLANK);
        OS_SetIrqFunction(OS_IE_V_BLANK, &VBlankHandler);
        OS_EnableIrqMask(OS_IE_V_BLANK);

        Main_SetVBlankIntrCB(NULL, NULL);

        FUN_02015F34(NULL, NULL);
        GX_DisableEngineALayers();
        GX_DisableEngineBLayers();

        GX_SetVisiblePlane(0);
        GXS_SetVisiblePlane(0);

        SetKeyRepeatTimers(4, 8);

        gMain.screensFlipped = 0;
        GX_SwapDisplay();

        G2_BlendNone();
        G2S_BlendNone();

        GX_SetVisibleWnd(0);
        GXS_SetVisibleWnd(0);

        GX_SetBanks(&UNK_020FF4D8);
        ptr = BgConfig_Alloc(0);
        SetBothScreensModesAndDisable(&UNK_020FF4AC);

        InitBgFromTemplate(ptr, 0, &UNK_020FF4BC, 0);
        BgClearTilemapBufferAndCommit(ptr, 0);

        FUN_0200CB00(ptr, 0, 503, 2, 0, 0);

        FUN_02002ED0(0, 0x20, 0);
        BG_ClearCharDataRange(0, 0x20, 0, 0);
        BG_SetMaskColor(0, 0x6C21);
        BG_SetMaskColor(4, 0x6C21);

        struct MsgData *msg_data = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 0xc8, 0);
        struct String *str = String_ctor(6 << 6, 0);

        FUN_0201BD5C();
        AddWindow(ptr, &buf, &UNK_020FF49C);
        FillWindowPixelRect(&buf, 15, 0, 0, 0xd0, 0x90);
        DrawFrameAndWindow1(&buf, 0, 0x1f7, 2);

        ReadMsgDataIntoString(msg_data, 3, str);

        AddTextPrinterParameterized(&buf, 0, str, 0, 0, 0, NULL);

        String_dtor(str);
        GX_BothDispOn();
        FUN_0200E394(0);
        FUN_0200E394(1);
        SetBrightness(0, 0x3f, 3);
        FUN_02032DAC();

        while (1)
        {
            HandleDSLidAction();
            FUN_0202FB80();
            if (FUN_02033678())
                break;
            OS_WaitIrq(TRUE, OS_IE_V_BLANK);
        }

        while (1)
        {
            HandleDSLidAction();
            if ((PAD_Read() & PAD_BUTTON_A))
                break;
            OS_WaitIrq(TRUE, OS_IE_V_BLANK);
        }
        FUN_0200E3A0(PM_LCD_TOP, 0x7FFF);
        FUN_0200E3A0(PM_LCD_BOTTOM, 0x7FFF);

        RemoveWindow(&buf);

        DestroyMsgData(msg_data);
        FreeToHeap(ptr);

        OS_ResetSystem(0);
    }
}