From ef873e11320fcd39c249030c9bc67e87af190e6d Mon Sep 17 00:00:00 2001 From: red031000 Date: Wed, 12 Jul 2023 15:41:39 +0100 Subject: [PATCH] cleanup communication_error.c --- arm7/lib/include/OS_irqTable.h | 3 +- arm9/lib/NitroSDK/include/OS_interrupt.h | 1 + arm9/lib/NitroSDK/include/consts.h | 4 +- arm9/lib/NitroSDK/src/OS_system.c | 2 +- arm9/overlays/59/src/ov59_Intro.c | 4 +- arm9/overlays/59/src/ov59_TV.c | 8 +-- arm9/src/communication_error.c | 68 +++++++++++------------- arm9/src/error_message_reset.c | 12 ++--- arm9/src/game_init.c | 6 +-- arm9/src/main.c | 2 +- arm9/src/save_data_read_error.c | 6 +-- arm9/src/save_data_write_error.c | 4 +- arm9/src/wfc_user_info_warning.c | 4 +- include/GX_layers.h | 4 +- include/bg_window.h | 2 +- include/communication_error.h | 2 +- 16 files changed, 63 insertions(+), 69 deletions(-) diff --git a/arm7/lib/include/OS_irqTable.h b/arm7/lib/include/OS_irqTable.h index 523b96ae6..ffae9d9e4 100644 --- a/arm7/lib/include/OS_irqTable.h +++ b/arm7/lib/include/OS_irqTable.h @@ -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; } diff --git a/arm9/lib/NitroSDK/include/OS_interrupt.h b/arm9/lib/NitroSDK/include/OS_interrupt.h index 19dd0da24..edda76362 100644 --- a/arm9/lib/NitroSDK/include/OS_interrupt.h +++ b/arm9/lib/NitroSDK/include/OS_interrupt.h @@ -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 diff --git a/arm9/lib/NitroSDK/include/consts.h b/arm9/lib/NitroSDK/include/consts.h index 127339ca2..e3034f9bc 100644 --- a/arm9/lib/NitroSDK/include/consts.h +++ b/arm9/lib/NitroSDK/include/consts.h @@ -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 diff --git a/arm9/lib/NitroSDK/src/OS_system.c b/arm9/lib/NitroSDK/src/OS_system.c index 81a578d7e..9c3e1c3c3 100644 --- a/arm9/lib/NitroSDK/src/OS_system.c +++ b/arm9/lib/NitroSDK/src/OS_system.c @@ -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); } diff --git a/arm9/overlays/59/src/ov59_Intro.c b/arm9/overlays/59/src/ov59_Intro.c index 030de05a0..19a3e2143 100644 --- a/arm9/overlays/59/src/ov59_Intro.c +++ b/arm9/overlays/59/src/ov59_Intro.c @@ -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 }; @@ -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 }; diff --git a/arm9/overlays/59/src/ov59_TV.c b/arm9/overlays/59/src/ov59_TV.c index a1e2e3a9d..ec257fc53 100644 --- a/arm9/overlays/59/src/ov59_TV.c +++ b/arm9/overlays/59/src/ov59_TV.c @@ -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 }; @@ -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 }; @@ -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 }; @@ -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 }; diff --git a/arm9/src/communication_error.c b/arm9/src/communication_error.c index 94b9cc781..06f40e397 100644 --- a/arm9/src/communication_error.c +++ b/arm9/src/communication_error.c @@ -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, @@ -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); @@ -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(); @@ -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); } diff --git a/arm9/src/error_message_reset.c b/arm9/src/error_message_reset.c index 4870fb987..d98c31015 100644 --- a/arm9/src/error_message_reset.c +++ b/arm9/src/error_message_reset.c @@ -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); } @@ -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); @@ -153,7 +153,7 @@ void PrintErrorMessageAndReset() sub_0202FB80(); if (sub_02033678()) break; - OS_WaitIrq(TRUE, OS_IE_V_BLANK); + OS_WaitIrq(TRUE, OS_IE_VBLANK); } while (TRUE) @@ -161,7 +161,7 @@ void PrintErrorMessageAndReset() 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); diff --git a/arm9/src/game_init.c b/arm9/src/game_init.c index bbc188055..07a07fd66 100644 --- a/arm9/src/game_init.c +++ b/arm9/src/game_init.c @@ -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(); diff --git a/arm9/src/main.c b/arm9/src/main.c index 8b582b592..d8f850f7b 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -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) diff --git a/arm9/src/save_data_read_error.c b/arm9/src/save_data_read_error.c index 4078108f3..e85d8b178 100644 --- a/arm9/src/save_data_read_error.c +++ b/arm9/src/save_data_read_error.c @@ -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, }; @@ -118,7 +118,7 @@ void ShowSaveDataReadError(HeapID heapId) while (TRUE) { HandleDSLidAction(); - OS_WaitIrq(TRUE, OS_IE_V_BLANK); + OS_WaitIrq(TRUE, OS_IE_VBLANK); } } @@ -181,6 +181,6 @@ void ShowGBACartRemovedError(HeapID heapId) while (TRUE) { HandleDSLidAction(); - OS_WaitIrq(TRUE, OS_IE_V_BLANK); + OS_WaitIrq(TRUE, OS_IE_VBLANK); } } diff --git a/arm9/src/save_data_write_error.c b/arm9/src/save_data_write_error.c index 7345e99ca..6eec9035c 100644 --- a/arm9/src/save_data_write_error.c +++ b/arm9/src/save_data_write_error.c @@ -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, }; @@ -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); } } diff --git a/arm9/src/wfc_user_info_warning.c b/arm9/src/wfc_user_info_warning.c index 975c2e4a8..0c9e17471 100644 --- a/arm9/src/wfc_user_info_warning.c +++ b/arm9/src/wfc_user_info_warning.c @@ -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, }; @@ -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); diff --git a/include/GX_layers.h b/include/GX_layers.h index e988216b4..40bae267c 100644 --- a/include/GX_layers.h +++ b/include/GX_layers.h @@ -11,7 +11,7 @@ typedef enum { GX_LAYER_TOGGLE_ON, } GXLayerToggle; -struct GraphicsBanks +typedef struct GraphicsBanks { s32 bg; s32 bgextpltt; @@ -23,7 +23,7 @@ struct GraphicsBanks s32 subobjextpltt; s32 tex; s32 texpltt; -}; +} GraphicsBanks; typedef struct GraphicsModes { GXDispMode dispMode; diff --git a/include/bg_window.h b/include/bg_window.h index 8246f4c93..e2b5e4670 100644 --- a/include/bg_window.h +++ b/include/bg_window.h @@ -23,7 +23,7 @@ typedef struct BgTemplate { u8 bgExtPltt; u8 priority; u8 areaOver; - u8 unk17; // probably paddding + u8 dummy; // probably paddding u32 mosaic; } BgTemplate; diff --git a/include/communication_error.h b/include/communication_error.h index 098bbff2c..571c54ece 100644 --- a/include/communication_error.h +++ b/include/communication_error.h @@ -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