Skip to content

Commit

Permalink
Merge pull request #527 from red031000/master
Browse files Browse the repository at this point in the history
cleanup communication_error.c
  • Loading branch information
red031000 authored Jul 12, 2023
2 parents 3612dc5 + ef873e1 commit 69b0762
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 69 deletions.
3 changes: 1 addition & 2 deletions arm7/lib/include/OS_irqTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ void OSi_IrqTimer2(void);
void OSi_IrqTimer3(void);
void OSi_IrqVBlank(void);

static inline void OS_SetIrqCheckFlag(OSIrqMask intr)
{
static inline void OS_SetIrqCheckFlag(OSIrqMask intr) {
*(vu32 *)HW_INTR_CHECK_BUF |= (u32)intr;
}

Expand Down
1 change: 1 addition & 0 deletions arm9/lib/NitroSDK/include/OS_interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define POKEDIAMOND_ARM9_OS_INTERRUPT_H

#include "registers.h"
#include "mmap.h"
#include "nitro/OS_interrupt_shared.h"

#define REG_OS_IME_IME_SHIFT 0
Expand Down
4 changes: 2 additions & 2 deletions arm9/lib/NitroSDK/include/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

#define OSi_TCM_REGION_BASE_MASK 0xfffff000

#define OS_IE_V_BLANK (1UL << 0)
#define OS_IE_H_BLANK (1UL << 1)
#define OS_IE_VBLANK (1UL << 0)
#define OS_IE_HBLANK (1UL << 1)

#define HW_CPU_CLOCK_ARM9 67027964

Expand Down
2 changes: 1 addition & 1 deletion arm9/lib/NitroSDK/src/OS_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ asm void OS_SpinWait(u32 cycles)
void OS_WaitVBlankIntr(void)
{
SVC_WaitByLoop(0x1);
OS_WaitIrq(TRUE, OS_IE_V_BLANK);
OS_WaitIrq(TRUE, OS_IE_VBLANK);
}
4 changes: 2 additions & 2 deletions arm9/overlays/59/src/ov59_Intro.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const struct BgTemplate ov59_021D9EA0 =
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 1,
.areaOver = GX_BG_AREAOVER_XLU,
.unk17 = 0,
.dummy = 0,
.mosaic = FALSE
};

Expand All @@ -206,7 +206,7 @@ const struct BgTemplate ov59_021D9EBC =
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 0,
.areaOver = GX_BG_AREAOVER_XLU,
.unk17 = 0,
.dummy = 0,
.mosaic = FALSE
};

Expand Down
8 changes: 4 additions & 4 deletions arm9/overlays/59/src/ov59_TV.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const struct BgTemplate ov59_021DA080 =
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 1,
.areaOver = GX_BG_AREAOVER_XLU,
.unk17 = 0,
.dummy = 0,
.mosaic = FALSE
};

Expand All @@ -71,7 +71,7 @@ const struct BgTemplate ov59_021DA09C =
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 1,
.areaOver = GX_BG_AREAOVER_XLU,
.unk17 = 0,
.dummy = 0,
.mosaic = FALSE
};

Expand All @@ -89,7 +89,7 @@ const struct BgTemplate ov59_021DA064 =
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 1,
.areaOver = GX_BG_AREAOVER_XLU,
.unk17 = 0,
.dummy = 0,
.mosaic = FALSE
};

Expand All @@ -107,7 +107,7 @@ const struct BgTemplate ov59_021DA0B8 =
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 1,
.areaOver = GX_BG_AREAOVER_XLU,
.unk17 = 0,
.dummy = 0,
.mosaic = FALSE
};

Expand Down
68 changes: 31 additions & 37 deletions arm9/src/communication_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ static const struct BgTemplate sCommunicationErrorBgTemplate = {
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 1,
.areaOver = GX_BG_AREAOVER_XLU,
.unk17 = 0,
.dummy = 0,
.mosaic = FALSE,
};

static const struct GraphicsBanks sCommunicationErrorGraphicsBanks = {
static const GraphicsBanks sCommunicationErrorGraphicsBanks = {
.bg = GX_VRAM_BG_256_AB,
.bgextpltt = GX_VRAM_BGEXTPLTT_NONE,
.subbg = GX_VRAM_SUB_BG_NONE,
Expand All @@ -61,43 +61,40 @@ static const struct GraphicsBanks sCommunicationErrorGraphicsBanks = {

static void VBlankIntr(void);

static void VBlankIntr(void)
{
DTCM.intr_check |= OS_IE_V_BLANK;
static void VBlankIntr(void) {
OS_SetIrqCheckFlag(OS_IE_VBLANK);
MI_WaitDma(GX_DEFAULT_DMAID);
}

void ShowCommunicationError(HeapID heapId, u32 error, u32 error_code)
{
struct Window window;
void ShowCommunicationError(HeapID heapId, u32 error, u32 errorCode) {
Window window;

u32 error_message_no;
switch (error)
{
u32 msgNo;
switch (error) {
default:
case 0:
error_message_no = narc_0200_00001; //A communication error has occurred. If you were in the Union Room...
msgNo = narc_0200_00001; //A communication error has occurred. If you were in the Union Room...
break;
case 1:
error_message_no = narc_0200_00002; //An error occurred while attempting to communicate. ({STRVAR_1 54, 0}) Please turn off the power...
msgNo = narc_0200_00002; //An error occurred while attempting to communicate. ({STRVAR_1 54, 0}) Please turn off the power...
break;
case 2:
error_message_no = narc_0200_00003; //A communication error has occurred. You will be returned to the title screen...
msgNo = narc_0200_00003; //A communication error has occurred. You will be returned to the title screen...
break;
case 3:
error_message_no = narc_0200_00004; //The GTS is extremely busy now. Please wait a while and try again.
msgNo = narc_0200_00004; //The GTS is extremely busy now. Please wait a while and try again.
break;
case 4:
error_message_no = narc_0200_00005; //An error occurred while attempting\nto communicate.\nPlease turn off the power...
msgNo = narc_0200_00005; //An error occurred while attempting\nto communicate.\nPlease turn off the power...
break;
}

sub_0200E3A0(PM_LCD_TOP, 0);
sub_0200E3A0(PM_LCD_BOTTOM, 0);

OS_DisableIrqMask(OS_IE_V_BLANK);
OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
OS_EnableIrqMask(OS_IE_V_BLANK);
OS_DisableIrqMask(OS_IE_VBLANK);
OS_SetIrqFunction(OS_IE_VBLANK, VBlankIntr);
OS_EnableIrqMask(OS_IE_VBLANK);

Main_SetVBlankIntrCB(NULL, NULL);
Main_SetHBlankIntrCB(NULL, NULL);
Expand All @@ -118,34 +115,31 @@ void ShowCommunicationError(HeapID heapId, u32 error, u32 error_code)
GXS_SetVisibleWnd(0);
GX_SetBanks(&sCommunicationErrorGraphicsBanks);

struct BgConfig* bg_config = BgConfig_Alloc(heapId);

BgConfig* bgConfig = BgConfig_Alloc(heapId);
SetBothScreensModesAndDisable(&sCommunicationErrorGraphicsModes);

InitBgFromTemplate(bg_config, 0, &sCommunicationErrorBgTemplate, GX_BGMODE_0);
BgClearTilemapBufferAndCommit(bg_config, GF_BG_LYR_MAIN_0);
LoadUserFrameGfx1(bg_config, GF_BG_LYR_MAIN_0, 0x01F7, 2, 0, heapId);
InitBgFromTemplate(bgConfig, 0, &sCommunicationErrorBgTemplate, GX_BGMODE_0);
BgClearTilemapBufferAndCommit(bgConfig, GF_BG_LYR_MAIN_0);
LoadUserFrameGfx1(bgConfig, GF_BG_LYR_MAIN_0, 0x01F7, 2, 0, heapId);
LoadFontPal0(GF_PAL_LOCATION_MAIN_BG, GF_PAL_SLOT_OFFSET_1, heapId);
BG_ClearCharDataRange(GF_BG_LYR_MAIN_0, 0x20, 0, heapId);
BG_SetMaskColor(GF_BG_LYR_MAIN_0, GX_RGB(1, 1, 27));
BG_SetMaskColor(GF_BG_LYR_SUB_0, GX_RGB(1, 1, 27));

struct MsgData* error_message_data = NewMsgDataFromNarc(MSGDATA_LOAD_LAZY, NARC_MSGDATA_MSG, NARC_msg_narc_0200_bin, heapId);
struct String* error_message_str = String_New(384, heapId);
struct String* tmp_str = String_New(384, heapId);
MsgData* errorMessageData = NewMsgDataFromNarc(MSGDATA_LOAD_LAZY, NARC_MSGDATA_MSG, NARC_msg_narc_0200_bin, heapId);
String* errorMessageStr = String_New(384, heapId);
String* tmpStr = String_New(384, heapId);
ResetAllTextPrinters();
MessageFormat* messageFormat = MessageFormat_New(heapId);

AddWindow(bg_config, &window, &sCommunicationErrorWindowTemplate);
AddWindow(bgConfig, &window, &sCommunicationErrorWindowTemplate);
FillWindowPixelRect(&window, 0xF, 0, 0, 208, 144);
DrawFrameAndWindow1(&window, FALSE, 0x01F7, 2);

BufferIntegerAsString(messageFormat, 0, (s32)error_code, 5, PRINTING_MODE_LEADING_ZEROS, TRUE);
ReadMsgDataIntoString(error_message_data, error_message_no, tmp_str);
StringExpandPlaceholders(messageFormat, error_message_str, tmp_str);

AddTextPrinterParameterized(&window, 0, error_message_str, 0, 0, 0, NULL);
String_Delete(error_message_str);
BufferIntegerAsString(messageFormat, 0, errorCode, 5, PRINTING_MODE_LEADING_ZEROS, TRUE);
ReadMsgDataIntoString(errorMessageData, msgNo, tmpStr);
StringExpandPlaceholders(messageFormat, errorMessageStr, tmpStr);
AddTextPrinterParameterized(&window, 0, errorMessageStr, 0, 0, 0, NULL);
String_Delete(errorMessageStr);
// BUG: tmp_str is never destroyed.

GX_BothDispOn();
Expand All @@ -154,7 +148,7 @@ void ShowCommunicationError(HeapID heapId, u32 error, u32 error_code)
SetBlendBrightness(0, (GXBlendPlaneMask)(GX_BLEND_PLANEMASK_BD | GX_BLEND_PLANEMASK_OBJ | GX_BLEND_PLANEMASK_BG3 | GX_BLEND_PLANEMASK_BG2 | GX_BLEND_PLANEMASK_BG1 | GX_BLEND_PLANEMASK_BG0), SCREEN_MASK_MAIN | SCREEN_MASK_SUB);

RemoveWindow(&window);
DestroyMsgData(error_message_data);
DestroyMsgData(errorMessageData);
MessageFormat_Delete(messageFormat);
FreeToHeap(bg_config);
FreeToHeap(bgConfig);
}
12 changes: 6 additions & 6 deletions arm9/src/error_message_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extern void SetMasterBrightnessNeutral(u32 screen);

void VBlankHandler()
{
OS_SetIrqCheckFlag(OS_IE_V_BLANK);
OS_SetIrqCheckFlag(OS_IE_VBLANK);
MI_WaitDma(GX_DEFAULT_DMAID);
}

Expand All @@ -90,9 +90,9 @@ void PrintErrorMessageAndReset()
sub_0200E3A0(PM_LCD_TOP, 0);
sub_0200E3A0(PM_LCD_BOTTOM, 0);

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

Main_SetVBlankIntrCB(NULL, NULL);
Main_SetHBlankIntrCB(NULL, NULL);
Expand Down Expand Up @@ -153,15 +153,15 @@ void PrintErrorMessageAndReset()
sub_0202FB80();
if (sub_02033678())
break;
OS_WaitIrq(TRUE, OS_IE_V_BLANK);
OS_WaitIrq(TRUE, OS_IE_VBLANK);
}

while (TRUE)
{
HandleDSLidAction();
if ((PAD_Read() & PAD_BUTTON_A))
break;
OS_WaitIrq(TRUE, OS_IE_V_BLANK);
OS_WaitIrq(TRUE, OS_IE_VBLANK);
}
sub_0200E3A0(PM_LCD_TOP, 0x7FFF);
sub_0200E3A0(PM_LCD_BOTTOM, 0x7FFF);
Expand Down
6 changes: 3 additions & 3 deletions arm9/src/game_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ void Main_ToggleHBlankInterrupt(BOOL enableFlag)
if (!enableFlag)
{
(void)OS_GetIrqMask();
OS_DisableIrqMask(OS_IE_H_BLANK);
OS_DisableIrqMask(OS_IE_HBLANK);
GX_HBlankIntr(FALSE);
}
else
{
(void)OS_GetIrqMask();
OS_SetIrqFunction(OS_IE_H_BLANK, Main_CallHBlankCallback);
OS_EnableIrqMask(OS_IE_H_BLANK);
OS_SetIrqFunction(OS_IE_HBLANK, Main_CallHBlankCallback);
OS_EnableIrqMask(OS_IE_HBLANK);
GX_HBlankIntr(TRUE);
}
(void)OS_EnableIrq();
Expand Down
2 changes: 1 addition & 1 deletion arm9/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void RegisterMainOverlay(FSOverlayID id, const struct OverlayManagerTemplate *te
void sub_02000E9C(void)
{
sub_0202FB80();
OS_WaitIrq(TRUE, OS_IE_V_BLANK);
OS_WaitIrq(TRUE, OS_IE_VBLANK);
gSystem.unk2C++;
gSystem.unk30 = 0;
if (gSystem.vBlankIntr != NULL)
Expand Down
6 changes: 3 additions & 3 deletions arm9/src/save_data_read_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static const struct BgTemplate sSaveDataReadErrorBgTemplate = {
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 1,
.areaOver = GX_BG_AREAOVER_XLU,
.unk17 = 0,
.dummy = 0,
.mosaic = FALSE,
};

Expand Down Expand Up @@ -118,7 +118,7 @@ void ShowSaveDataReadError(HeapID heapId)
while (TRUE)
{
HandleDSLidAction();
OS_WaitIrq(TRUE, OS_IE_V_BLANK);
OS_WaitIrq(TRUE, OS_IE_VBLANK);
}
}

Expand Down Expand Up @@ -181,6 +181,6 @@ void ShowGBACartRemovedError(HeapID heapId)
while (TRUE)
{
HandleDSLidAction();
OS_WaitIrq(TRUE, OS_IE_V_BLANK);
OS_WaitIrq(TRUE, OS_IE_VBLANK);
}
}
4 changes: 2 additions & 2 deletions arm9/src/save_data_write_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static const struct BgTemplate sSaveDataWriteErrorBgTemplate = {
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 1,
.areaOver = GX_BG_AREAOVER_XLU,
.unk17 = 0,
.dummy = 0,
.mosaic = FALSE,
};

Expand Down Expand Up @@ -126,6 +126,6 @@ void ShowSaveDataWriteError(HeapID heapId, u32 err_no)
while (TRUE)
{
HandleDSLidAction();
OS_WaitIrq(TRUE, OS_IE_V_BLANK);
OS_WaitIrq(TRUE, OS_IE_VBLANK);
}
}
4 changes: 2 additions & 2 deletions arm9/src/wfc_user_info_warning.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static const struct BgTemplate sWFCWarningMsgBgTemplate = {
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 1,
.areaOver = GX_BG_AREAOVER_XLU,
.unk17 = 0,
.dummy = 0,
.mosaic = FALSE,
};

Expand Down Expand Up @@ -131,7 +131,7 @@ void ShowWFCUserInfoWarning(HeapID heapId, u32 a1)
break;
}

OS_WaitIrq(TRUE, OS_IE_V_BLANK);
OS_WaitIrq(TRUE, OS_IE_VBLANK);
}

RemoveWindow(&window);
Expand Down
4 changes: 2 additions & 2 deletions include/GX_layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef enum {
GX_LAYER_TOGGLE_ON,
} GXLayerToggle;

struct GraphicsBanks
typedef struct GraphicsBanks
{
s32 bg;
s32 bgextpltt;
Expand All @@ -23,7 +23,7 @@ struct GraphicsBanks
s32 subobjextpltt;
s32 tex;
s32 texpltt;
};
} GraphicsBanks;

typedef struct GraphicsModes {
GXDispMode dispMode;
Expand Down
2 changes: 1 addition & 1 deletion include/bg_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef struct BgTemplate {
u8 bgExtPltt;
u8 priority;
u8 areaOver;
u8 unk17; // probably paddding
u8 dummy; // probably paddding
u32 mosaic;
} BgTemplate;

Expand Down
2 changes: 1 addition & 1 deletion include/communication_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#include "heap.h"

void ShowCommunicationError(HeapID heapId, u32 error, u32 error_code);
void ShowCommunicationError(HeapID heapId, u32 error, u32 errorCode);

#endif

0 comments on commit 69b0762

Please sign in to comment.