From 7f6f6c33ab9a9a5ab97aff8976ea2cb153106624 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 26 Dec 2018 13:05:02 +0100 Subject: [PATCH 1/4] Fix BgAttributes --- include/bg.h | 20 ++-- src/battle_bg.c | 6 +- src/battle_intro.c | 20 ++-- src/battle_script_commands.c | 12 +- src/bg.c | 166 ++++++++++++++------------- src/contest.c | 2 +- src/egg_hatch.c | 2 +- src/evolution_scene.c | 8 +- src/menu.c | 4 +- src/mirage_tower.c | 4 +- src/overworld.c | 6 +- src/pokedex_area_screen.c | 6 +- src/pokemon_storage_system.c | 20 ++-- src/pokemon_summary_screen.c | 16 +-- src/region_map.c | 152 ++++++++++++------------ src/reshow_battle_screen.c | 4 +- src/unk_pokedex_area_screen_helper.c | 8 +- src/window.c | 12 +- 18 files changed, 237 insertions(+), 231 deletions(-) diff --git a/include/bg.h b/include/bg.h index ffcaf43edf..1366923f1f 100644 --- a/include/bg.h +++ b/include/bg.h @@ -13,14 +13,16 @@ struct BGCntrlBitfield // for the I/O registers enum { - BG_CTRL_ATTR_VISIBLE = 1, - BG_CTRL_ATTR_CHARBASEINDEX = 2, - BG_CTRL_ATTR_MAPBASEINDEX = 3, - BG_CTRL_ATTR_SCREENSIZE = 4, - BG_CTRL_ATTR_PALETTEMODE = 5, - BG_CTRL_ATTR_PRIORITY = 6, - BG_CTRL_ATTR_MOSAIC = 7, - BG_CTRL_ATTR_WRAPAROUND = 8, + BG_ATTR_CHARBASEINDEX = 1, + BG_ATTR_MAPBASEINDEX, + BG_ATTR_SCREENSIZE, + BG_ATTR_PALETTEMODE, + BG_ATTR_MOSAIC, + BG_ATTR_WRAPAROUND, + BG_ATTR_PRIORITY, + BG_ATTR_METRIC, + BG_ATTR_TYPE, + BG_ATTR_BASETILE, }; struct BgTemplate @@ -38,8 +40,6 @@ void ResetBgs(void); u8 GetBgMode(void); void ResetBgControlStructs(void); void Unused_ResetBgControlStruct(u8 bg); -void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenSize, u8 paletteMode, u8 priority, u8 mosaic, u8 wraparound); -u16 GetBgControlAttribute(u8 bg, u8 attributeId); u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode); void SetTextModeAndHideBgs(void); bool8 IsInvalidBg(u8 bg); diff --git a/src/battle_bg.c b/src/battle_bg.c index a6919be1db..a072a2cda0 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -1092,7 +1092,7 @@ void DrawBattleEntryBackground(void) LZDecompressVram(gUnknown_08D778F0, (void*)(VRAM + 0x4000)); LZDecompressVram(gUnknown_08D77B0C, (void*)(VRAM + 0x10000)); LoadCompressedPalette(gUnknown_08D77AE4, 0x60, 0x20); - SetBgAttribute(1, BG_CTRL_ATTR_MAPBASEINDEX, 1); + SetBgAttribute(1, BG_ATTR_SCREENSIZE, 1); SetGpuReg(REG_OFFSET_BG1CNT, 0x5C04); CopyToBgTilemapBuffer(1, gUnknown_08D779D8, 0, 0); CopyToBgTilemapBuffer(2, gUnknown_08D779D8, 0, 0); @@ -1113,8 +1113,8 @@ void DrawBattleEntryBackground(void) } else { - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 2); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 2); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 2); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 2); CopyToBgTilemapBuffer(1, gUnknown_08D857A8, 0, 0); CopyToBgTilemapBuffer(2, gUnknown_08D85A1C, 0, 0); CopyBgTilemapBufferToVram(1); diff --git a/src/battle_intro.c b/src/battle_intro.c index 736e35a87f..21e83ed29e 100644 --- a/src/battle_intro.c +++ b/src/battle_intro.c @@ -221,8 +221,8 @@ static void BattleIntroSlide1(u8 taskId) gScanlineEffect.state = 3; gTasks[taskId].data[0]++; CpuFill32(0, (void *)BG_SCREEN_ADDR(28), BG_SCREEN_SIZE); - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(28) | BGCNT_TXT256x512); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(30) | BGCNT_TXT512x256); } @@ -330,8 +330,8 @@ static void BattleIntroSlide2(u8 taskId) gScanlineEffect.state = 3; gTasks[taskId].data[0]++; CpuFill32(0, (void *)BG_SCREEN_ADDR(28), BG_SCREEN_SIZE); - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(28) | BGCNT_TXT256x512); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(30) | BGCNT_TXT512x256); } @@ -418,8 +418,8 @@ static void BattleIntroSlide3(u8 taskId) gScanlineEffect.state = 3; gTasks[taskId].data[0]++; CpuFill32(0, (void *)BG_SCREEN_ADDR(28), BG_SCREEN_SIZE); - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(28) | BGCNT_TXT256x512); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(30) | BGCNT_TXT512x256); } @@ -499,8 +499,8 @@ static void BattleIntroSlideLink(u8 taskId) { gScanlineEffect.state = 3; gTasks[taskId].data[0]++; - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(28) | BGCNT_TXT256x512); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(30) | BGCNT_TXT512x256); } @@ -567,8 +567,8 @@ static void BattleIntroSlidePartner(u8 taskId) { CpuFill32(0, (void *)BG_SCREEN_ADDR(28), BG_SCREEN_SIZE * 4); SetGpuReg(REG_OFFSET_DISPCNT, GetGpuReg(REG_OFFSET_DISPCNT) & ~DISPCNT_WIN1_ON); - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(28) | BGCNT_TXT256x512); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(30) | BGCNT_TXT512x256); gScanlineEffect.state = 3; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9e1aa6be7b..67e9a0b1a1 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6237,7 +6237,7 @@ static void atk6C_drawlvlupbox(void) { case 1: gBattle_BG2_Y = 0x60; - SetBgAttribute(2, BG_CTRL_ATTR_MOSAIC, 0); + SetBgAttribute(2, BG_ATTR_PRIORITY, 0); ShowBg(2); sub_804F17C(); gBattleScripting.atk6C_state = 2; @@ -6249,8 +6249,8 @@ static void atk6C_drawlvlupbox(void) case 3: gBattle_BG1_X = 0; gBattle_BG1_Y = 0x100; - SetBgAttribute(0, BG_CTRL_ATTR_MOSAIC, 1); - SetBgAttribute(1, BG_CTRL_ATTR_MOSAIC, 0); + SetBgAttribute(0, BG_ATTR_PRIORITY, 1); + SetBgAttribute(1, BG_ATTR_PRIORITY, 0); ShowBg(0); ShowBg(1); HandleBattleWindow(0x12, 7, 0x1D, 0x13, WINDOW_x80); @@ -6296,7 +6296,7 @@ static void atk6C_drawlvlupbox(void) ClearWindowTilemap(13); CopyWindowToVram(13, 1); - SetBgAttribute(2, BG_CTRL_ATTR_MOSAIC, 2); + SetBgAttribute(2, BG_ATTR_PRIORITY, 2); ShowBg(2); gBattleScripting.atk6C_state = 10; @@ -6305,8 +6305,8 @@ static void atk6C_drawlvlupbox(void) case 10: if (!IsDma3ManagerBusyWithBgCopy()) { - SetBgAttribute(0, BG_CTRL_ATTR_MOSAIC, 0); - SetBgAttribute(1, BG_CTRL_ATTR_MOSAIC, 1); + SetBgAttribute(0, BG_ATTR_PRIORITY, 0); + SetBgAttribute(1, BG_ATTR_PRIORITY, 1); ShowBg(0); ShowBg(1); gBattlescriptCurrInstr++; diff --git a/src/bg.c b/src/bg.c index 21624e4a02..54ec3b347b 100644 --- a/src/bg.c +++ b/src/bg.c @@ -77,15 +77,27 @@ void ResetBgControlStructs(void) void Unused_ResetBgControlStruct(u8 bg) { - if (IsInvalidBg(bg) == FALSE) + if (!IsInvalidBg(bg)) { sGpuBgConfigs.configs[bg] = sZeroedBgControlStruct; } } -void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenSize, u8 paletteMode, u8 priority, u8 mosaic, u8 wraparound) +enum { - if (IsInvalidBg(bg) == FALSE) + BG_CTRL_ATTR_VISIBLE = 1, + BG_CTRL_ATTR_CHARBASEINDEX = 2, + BG_CTRL_ATTR_MAPBASEINDEX = 3, + BG_CTRL_ATTR_SCREENSIZE = 4, + BG_CTRL_ATTR_PALETTEMODE = 5, + BG_CTRL_ATTR_PRIORITY = 6, + BG_CTRL_ATTR_MOSAIC = 7, + BG_CTRL_ATTR_WRAPAROUND = 8, +}; + +static void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenSize, u8 paletteMode, u8 priority, u8 mosaic, u8 wraparound) +{ + if (!IsInvalidBg(bg)) { if (charBaseIndex != 0xFF) { @@ -129,9 +141,9 @@ void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenS } } -u16 GetBgControlAttribute(u8 bg, u8 attributeId) +static u16 GetBgControlAttribute(u8 bg, u8 attributeId) { - if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE) + if (!IsInvalidBg(bg) && sGpuBgConfigs.configs[bg].visible) { switch (attributeId) { @@ -162,7 +174,7 @@ u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode) u16 offset; s8 cursor; - if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE) + if (!IsInvalidBg(bg) && sGpuBgConfigs.configs[bg].visible) { switch (mode) { @@ -198,7 +210,7 @@ end: static void ShowBgInternal(u8 bg) { u16 value; - if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE) + if (!IsInvalidBg(bg) && sGpuBgConfigs.configs[bg].visible) { value = sGpuBgConfigs.configs[bg].priority | (sGpuBgConfigs.configs[bg].charBaseIndex << 2) | @@ -217,7 +229,7 @@ static void ShowBgInternal(u8 bg) static void HideBgInternal(u8 bg) { - if (IsInvalidBg(bg) == FALSE) + if (!IsInvalidBg(bg)) { sGpuBgConfigs.bgVisibilityAndMode &= ~(1 << (bg + 8)); sGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS; @@ -226,12 +238,12 @@ static void HideBgInternal(u8 bg) static void SyncBgVisibilityAndMode(void) { - SetGpuReg(0, (GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS) | sGpuBgConfigs.bgVisibilityAndMode); + SetGpuReg(REG_OFFSET_DISPCNT, (GetGpuReg(REG_OFFSET_DISPCNT) & ~DISPCNT_ALL_BG_AND_MODE_BITS) | sGpuBgConfigs.bgVisibilityAndMode); } void SetTextModeAndHideBgs(void) { - SetGpuReg(0, GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS); + SetGpuReg(REG_OFFSET_DISPCNT, GetGpuReg(REG_OFFSET_DISPCNT) & ~DISPCNT_ALL_BG_AND_MODE_BITS); } static void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle) @@ -312,7 +324,8 @@ void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numT for (i = 0; i < numTemplates; i++) { bg = templates[i].bg; - if (bg < 4) { + if (bg < 4) + { SetBgControlAttributes(bg, templates[i].charBaseIndex, templates[i].mapBaseIndex, @@ -396,9 +409,7 @@ u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset) u16 LoadBgTilemap(u8 bg, const void *src, u16 size, u16 destOffset) { - u8 cursor; - - cursor = LoadBgVram(bg, src, size, destOffset * 2, DISPCNT_MODE_2); + u8 cursor = LoadBgVram(bg, src, size, destOffset * 2, DISPCNT_MODE_2); if (cursor == 0xFF) { @@ -412,12 +423,11 @@ u16 LoadBgTilemap(u8 bg, const void *src, u16 size, u16 destOffset) u16 Unused_LoadBgPalette(u8 bg, const void *src, u16 size, u16 destOffset) { - u16 paletteOffset; s8 cursor; - if (IsInvalidBg32(bg) == FALSE) + if (!IsInvalidBg32(bg)) { - paletteOffset = (sGpuBgConfigs2[bg].basePalette * 0x20) + (destOffset * 2); + u16 paletteOffset = (sGpuBgConfigs2[bg].basePalette * 0x20) + (destOffset * 2); cursor = RequestDma3Copy(src, (void*)(paletteOffset + BG_PLTT), size, 0); if (cursor == -1) @@ -437,20 +447,16 @@ u16 Unused_LoadBgPalette(u8 bg, const void *src, u16 size, u16 destOffset) bool8 IsDma3ManagerBusyWithBgCopy(void) { - u8 mod; - u8 div; - s8 reqSpace; - int i; for (i = 0; i < 0x80; i++) { - div = i / 0x20; - mod = i % 0x20; + u8 div = i / 0x20; + u8 mod = i % 0x20; - if ((sDmaBusyBitfield[div] & (1 << mod)) != FALSE) + if ((sDmaBusyBitfield[div] & (1 << mod))) { - reqSpace = CheckForSpaceForDma3Request(i); + s8 reqSpace = CheckForSpaceForDma3Request(i); if (reqSpace == -1) { return TRUE; @@ -479,25 +485,25 @@ void SetBgAttribute(u8 bg, u8 attributeId, u8 value) { switch (attributeId) { - case 1: + case BG_ATTR_CHARBASEINDEX: SetBgControlAttributes(bg, value, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); break; - case 2: + case BG_ATTR_MAPBASEINDEX: SetBgControlAttributes(bg, 0xFF, value, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); break; - case 3: + case BG_ATTR_SCREENSIZE: SetBgControlAttributes(bg, 0xFF, 0xFF, value, 0xFF, 0xFF, 0xFF, 0xFF); break; - case 4: + case BG_ATTR_PALETTEMODE: SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, value, 0xFF, 0xFF, 0xFF); break; - case 7: + case BG_ATTR_PRIORITY: SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, 0xFF, value, 0xFF, 0xFF); break; - case 5: + case BG_ATTR_MOSAIC: SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, value, 0xFF); break; - case 6: + case BG_ATTR_WRAPAROUND: SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, value); break; } @@ -507,21 +513,21 @@ u16 GetBgAttribute(u8 bg, u8 attributeId) { switch (attributeId) { - case 1: + case BG_ATTR_CHARBASEINDEX: return GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX); - case 2: + case BG_ATTR_MAPBASEINDEX: return GetBgControlAttribute(bg, BG_CTRL_ATTR_MAPBASEINDEX); - case 3: + case BG_ATTR_SCREENSIZE: return GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); - case 4: + case BG_ATTR_PALETTEMODE: return GetBgControlAttribute(bg, BG_CTRL_ATTR_PALETTEMODE); - case 7: + case BG_ATTR_PRIORITY: return GetBgControlAttribute(bg, BG_CTRL_ATTR_PRIORITY); - case 5: + case BG_ATTR_MOSAIC: return GetBgControlAttribute(bg, BG_CTRL_ATTR_MOSAIC); - case 6: + case BG_ATTR_WRAPAROUND: return GetBgControlAttribute(bg, BG_CTRL_ATTR_WRAPAROUND); - case 8: + case BG_ATTR_METRIC: switch (GetBgType(bg)) { case 0: @@ -531,9 +537,9 @@ u16 GetBgAttribute(u8 bg, u8 attributeId) default: return 0; } - case 9: + case BG_ATTR_TYPE: return GetBgType(bg); - case 10: + case BG_ATTR_BASETILE: return sGpuBgConfigs2[bg].baseTile; default: return -1; @@ -546,7 +552,7 @@ s32 ChangeBgX(u8 bg, s32 value, u8 op) u16 temp1; u16 temp2; - if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + if (IsInvalidBg32(bg) || !GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { return -1; } @@ -612,9 +618,9 @@ s32 ChangeBgX(u8 bg, s32 value, u8 op) s32 GetBgX(u8 bg) { - if (IsInvalidBg32(bg) != FALSE) + if (IsInvalidBg32(bg)) return -1; - else if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + else if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) return -1; else return sGpuBgConfigs2[bg].bg_x; @@ -626,7 +632,7 @@ s32 ChangeBgY(u8 bg, s32 value, u8 op) u16 temp1; u16 temp2; - if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + if (IsInvalidBg32(bg) || !GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { return -1; } @@ -696,7 +702,7 @@ s32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op) u16 temp1; u16 temp2; - if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + if (IsInvalidBg32(bg) || !GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { return -1; } @@ -763,9 +769,9 @@ s32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op) s32 GetBgY(u8 bg) { - if (IsInvalidBg32(bg) != FALSE) + if (IsInvalidBg32(bg)) return -1; - else if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + else if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) return -1; else return sGpuBgConfigs2[bg].bg_y; @@ -849,7 +855,7 @@ u8 Unused_AdjustBgMosaic(u8 a1, u8 a2) void SetBgTilemapBuffer(u8 bg, void *tilemap) { - if (IsInvalidBg32(bg) == FALSE && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) != 0x0) + if (!IsInvalidBg32(bg) && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { sGpuBgConfigs2[bg].tilemap = tilemap; } @@ -857,7 +863,7 @@ void SetBgTilemapBuffer(u8 bg, void *tilemap) void UnsetBgTilemapBuffer(u8 bg) { - if (IsInvalidBg32(bg) == FALSE && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) != 0x0) + if (!IsInvalidBg32(bg) && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { sGpuBgConfigs2[bg].tilemap = NULL; } @@ -865,9 +871,9 @@ void UnsetBgTilemapBuffer(u8 bg) void* GetBgTilemapBuffer(u8 bg) { - if (IsInvalidBg32(bg) != FALSE) + if (IsInvalidBg32(bg)) return NULL; - else if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + else if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) return NULL; else return sGpuBgConfigs2[bg].tilemap; @@ -875,7 +881,7 @@ void* GetBgTilemapBuffer(u8 bg) void CopyToBgTilemapBuffer(u8 bg, const void *src, u16 mode, u16 destOffset) { - if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) { if (mode != 0) CpuCopy16(src, (void *)(sGpuBgConfigs2[bg].tilemap + (destOffset * 2)), mode); @@ -888,7 +894,7 @@ void CopyBgTilemapBufferToVram(u8 bg) { u16 sizeToLoad; - if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) { switch (GetBgType(bg)) { @@ -908,12 +914,12 @@ void CopyBgTilemapBufferToVram(u8 bg) void CopyToBgTilemapBufferRect(u8 bg, const void* src, u8 destX, u8 destY, u8 width, u8 height) { - const void* srcCopy; + const void *srcCopy; u16 destX16; u16 destY16; u16 mode; - if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) { switch (GetBgType(bg)) { @@ -997,29 +1003,29 @@ void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u16 y16; u16 mode; - if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) { switch (GetBgType(bg)) { - case 0: - for (y16 = y; y16 < (y + height); y16++) + case 0: + for (y16 = y; y16 < (y + height); y16++) + { + for (x16 = x; x16 < (x + width); x16++) { - for (x16 = x; x16 < (x + width); x16++) - { - ((u16*)sGpuBgConfigs2[bg].tilemap)[((y16 * 0x20) + x16)] = tileNum; - } + ((u16*)sGpuBgConfigs2[bg].tilemap)[((y16 * 0x20) + x16)] = tileNum; } - break; - case 1: - mode = GetBgMetricAffineMode(bg, 0x1); - for (y16 = y; y16 < (y + height); y16++) + } + break; + case 1: + mode = GetBgMetricAffineMode(bg, 0x1); + for (y16 = y; y16 < (y + height); y16++) + { + for (x16 = x; x16 < (x + width); x16++) { - for (x16 = x; x16 < (x + width); x16++) - { - ((u8*)sGpuBgConfigs2[bg].tilemap)[((y16 * mode) + x16)] = tileNum; - } + ((u8*)sGpuBgConfigs2[bg].tilemap)[((y16 * mode) + x16)] = tileNum; } - break; + } + break; } } } @@ -1071,12 +1077,12 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt u16 GetBgMetricTextMode(u8 bg, u8 whichMetric) { - u8 attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); + u8 screenSize = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); switch (whichMetric) { case 0: - switch (attribute) + switch (screenSize) { case 0: return 1; @@ -1088,7 +1094,7 @@ u16 GetBgMetricTextMode(u8 bg, u8 whichMetric) } break; case 1: - switch (attribute) + switch (screenSize) { case 0: return 1; @@ -1101,7 +1107,7 @@ u16 GetBgMetricTextMode(u8 bg, u8 whichMetric) } break; case 2: - switch (attribute) + switch (screenSize) { case 0: case 1: @@ -1117,12 +1123,12 @@ u16 GetBgMetricTextMode(u8 bg, u8 whichMetric) u32 GetBgMetricAffineMode(u8 bg, u8 whichMetric) { - u8 attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); + u8 screenSize = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); switch (whichMetric) { case 0: - switch (attribute) + switch (screenSize) { case 0: return 0x1; @@ -1136,7 +1142,7 @@ u32 GetBgMetricAffineMode(u8 bg, u8 whichMetric) break; case 1: case 2: - return 0x10 << attribute; + return 0x10 << screenSize; } return 0; } diff --git a/src/contest.c b/src/contest.c index c3ce9c9aae..0f29f4ad96 100644 --- a/src/contest.c +++ b/src/contest.c @@ -285,7 +285,7 @@ void sub_80D779C(void) ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, gUnknown_08587F34, ARRAY_COUNT(gUnknown_08587F34)); - SetBgAttribute(3, BG_CTRL_ATTR_PRIORITY, 1); + SetBgAttribute(3, BG_ATTR_WRAPAROUND, 1); for (i = 0; i < 4; i++) { SetBgTilemapBuffer(i, gContestResources->field_24[i]); diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 360dd24664..a7b3e30b04 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -502,7 +502,7 @@ static void CB2_EggHatch_0(void) ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); - SetBgAttribute(1, BG_CTRL_ATTR_MOSAIC, 2); + SetBgAttribute(1, BG_ATTR_PRIORITY, 2); SetBgTilemapBuffer(1, Alloc(0x1000)); SetBgTilemapBuffer(0, Alloc(0x2000)); diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 1070c69e90..ea2302130b 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -1483,8 +1483,8 @@ static void InitMovingBackgroundTask(bool8 isLink) SetGpuReg(REG_OFFSET_BLDALPHA, 0x808); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG2_ON | DISPCNT_BG1_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP); - SetBgAttribute(innerBgId, BG_CTRL_ATTR_MOSAIC, 2); - SetBgAttribute(outerBgId, BG_CTRL_ATTR_MOSAIC, 2); + SetBgAttribute(innerBgId, BG_ATTR_PRIORITY, 2); + SetBgAttribute(outerBgId, BG_ATTR_PRIORITY, 2); ShowBg(1); ShowBg(2); @@ -1529,8 +1529,8 @@ static void sub_8140174(void) gBattle_BG1_X = 0; gBattle_BG1_Y = 0; gBattle_BG2_X = 0; - SetBgAttribute(1, BG_CTRL_ATTR_MOSAIC, sub_80391E0(1, 5)); - SetBgAttribute(2, BG_CTRL_ATTR_MOSAIC, sub_80391E0(2, 5)); + SetBgAttribute(1, BG_ATTR_PRIORITY, sub_80391E0(1, 5)); + SetBgAttribute(2, BG_ATTR_PRIORITY, sub_80391E0(2, 5)); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG3_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP); Free(sEvoMovingBgPtr); } diff --git a/src/menu.c b/src/menu.c index e0e5eb4eb9..8c3c61ea76 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1934,8 +1934,8 @@ void sub_8199D98(void) void sub_8199DF0(u32 bg, u8 a1, int a2, int a3) { - int temp = (!GetBgAttribute(bg, 4)) ? 0x20 : 0x40; - void *addr = (void *)((GetBgAttribute(bg, 1) * 0x4000) + (GetBgAttribute(bg, 10) + a2) * temp); + int temp = (!GetBgAttribute(bg, BG_ATTR_PALETTEMODE)) ? 0x20 : 0x40; + void *addr = (void *)((GetBgAttribute(bg, BG_ATTR_CHARBASEINDEX) * 0x4000) + (GetBgAttribute(bg, BG_ATTR_BASETILE) + a2) * temp); RequestDma3Fill(a1 << 24 | a1 << 16 | a1 << 8 | a1, addr + VRAM, a3 * temp, 1); } diff --git a/src/mirage_tower.c b/src/mirage_tower.c index d002e1de4d..bfaea4c5e7 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -509,7 +509,7 @@ static void InitMirageTowerShake(u8 taskId) { case 0: FreeAllWindowBuffers(); - SetBgAttribute(0, BG_CTRL_ATTR_MOSAIC, 2); + SetBgAttribute(0, BG_ATTR_PRIORITY, 2); gTasks[taskId].data[0]++; break; case 1: @@ -624,7 +624,7 @@ static void DoMirageTowerDisintegration(u8 taskId) case 6: SetGpuRegBits(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2)); SetGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(0)); - SetBgAttribute(0, BG_CTRL_ATTR_MOSAIC, 0); + SetBgAttribute(0, BG_ATTR_PRIORITY, 0); sub_81971D0(); break; case 7: diff --git a/src/overworld.c b/src/overworld.c index ea4b44cbf9..2aad688615 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1448,9 +1448,9 @@ u8 GetCurrentMapBattleScene(void) static void overworld_bg_setup(void) { InitBgsFromTemplates(0, gUnknown_08339DAC, ARRAY_COUNT(gUnknown_08339DAC)); - SetBgAttribute(1, BG_CTRL_ATTR_PALETTEMODE, 1); - SetBgAttribute(2, BG_CTRL_ATTR_PALETTEMODE, 1); - SetBgAttribute(3, BG_CTRL_ATTR_PALETTEMODE, 1); + SetBgAttribute(1, BG_ATTR_MOSAIC, 1); + SetBgAttribute(2, BG_ATTR_MOSAIC, 1); + SetBgAttribute(3, BG_ATTR_MOSAIC, 1); gBGTilemapBuffers2 = AllocZeroed(0x800); gBGTilemapBuffers1 = AllocZeroed(0x800); gBGTilemapBuffers3 = AllocZeroed(0x800); diff --git a/src/pokedex_area_screen.c b/src/pokedex_area_screen.c index 30a127c713..a268b53822 100755 --- a/src/pokedex_area_screen.c +++ b/src/pokedex_area_screen.c @@ -533,7 +533,7 @@ static void Task_PokedexAreaScreen_0(u8 taskId) HideBg(0); break; case 1: - SetBgAttribute(3, BG_CTRL_ATTR_VISIBLE, 3); + SetBgAttribute(3, BG_ATTR_CHARBASEINDEX, 3); sub_81C4D70(&sUnknown_085B4018); StringFill(sPokedexAreaScreen->charBuffer, CHAR_SPACE, 16); break; @@ -628,8 +628,8 @@ static void Task_PokedexAreaScreen_1(u8 taskId) static void sub_813D6B4(void) { - SetBgAttribute(3, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(3, BG_CTRL_ATTR_SCREENSIZE, 0); + SetBgAttribute(3, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(3, BG_ATTR_PALETTEMODE, 0); } static void CreateAreaMarkerSprites(void) diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 7b1d8da7c9..91a1a5fd03 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -8826,7 +8826,7 @@ static bool8 sub_80D024C(void) FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x20, 0x20); FillWindowPixelBuffer8Bit(sPSSData->field_2200, 0); sub_80D07B0(sMoveMonsPtr->fromRow, sMoveMonsPtr->fromColumn); - SetBgAttribute(0, 4, 1); + SetBgAttribute(0, BG_ATTR_PALETTEMODE, 1); PutWindowTilemap(sPSSData->field_2200); CopyWindowToVram8Bit(sPSSData->field_2200, 3); BlendPalettes(0x3F00, 8, RGB_WHITE); @@ -9246,7 +9246,7 @@ static void sub_80D0B5C(void) { ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); - SetBgAttribute(0, 4, 0); + SetBgAttribute(0, BG_ATTR_PALETTEMODE, 0); ClearGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR); FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32); CopyBgTilemapBufferToVram(0); @@ -9865,7 +9865,7 @@ static bool8 sub_80D184C(void) var = 0x15 - sPSSData->field_2236; for (i = 0; i < var; i++) { - WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, 10) + 0x14 + sPSSData->field_2236 + i, i, 13, 1, 7, 15, 21); + WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->field_2236 + i, i, 13, 1, 7, 15, 21); } sub_80D19B4(var); @@ -9886,7 +9886,7 @@ static bool8 sub_80D18E4(void) var = 0x15 - sPSSData->field_2236; for (i = 0; i < var; i++) { - WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, 10) + 0x14 + sPSSData->field_2236 + i, i, 13, 1, 7, 15, 21); + WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->field_2236 + i, i, 13, 1, 7, 15, 21); } if (var >= 0) @@ -10423,7 +10423,7 @@ static const sUnkVars[][4] = static void sub_80D2644(u8 id, u8 bg, const void *arg2, u16 arg3, u16 arg4) { - u16 attribute1, attribute2; + u16 bgScreenSize, bgType; if (id >= gUnknown_02039D88) return; @@ -10434,11 +10434,11 @@ static void sub_80D2644(u8 id, u8 bg, const void *arg2, u16 arg3, u16 arg4) gUnknown_02039D84[id].field_24 = arg3; gUnknown_02039D84[id].field_26 = arg4; - attribute1 = GetBgAttribute(bg, 3); - attribute2 = GetBgAttribute(bg, 9); - gUnknown_02039D84[id].field_20 = sUnkVars[attribute2][attribute1].a; - gUnknown_02039D84[id].field_22 = sUnkVars[attribute2][attribute1].b; - if (attribute2 != 0) + bgScreenSize = GetBgAttribute(bg, BG_ATTR_SCREENSIZE); + bgType = GetBgAttribute(bg, BG_ATTR_TYPE); + gUnknown_02039D84[id].field_20 = sUnkVars[bgType][bgScreenSize].a; + gUnknown_02039D84[id].field_22 = sUnkVars[bgType][bgScreenSize].b; + if (bgType != 0) gUnknown_02039D84[id].field_2A = 1; else gUnknown_02039D84[id].field_2A = 2; diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index eedb9417bd..7feeb79e76 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -1688,15 +1688,15 @@ static void sub_81C0B8C(u8 taskId) if (pssData->unk40C9 == 0) { data[1] = 1; - SetBgAttribute(1, 7, 1); - SetBgAttribute(2, 7, 2); + SetBgAttribute(1, BG_ATTR_PRIORITY, 1); + SetBgAttribute(2, BG_ATTR_PRIORITY, 2); schedule_bg_copy_tilemap_to_vram(1); } else { data[1] = 2; - SetBgAttribute(2, 7, 1); - SetBgAttribute(1, 7, 2); + SetBgAttribute(2, BG_ATTR_PRIORITY, 1); + SetBgAttribute(1, BG_ATTR_PRIORITY, 2); schedule_bg_copy_tilemap_to_vram(2); } ChangeBgX(data[1], 0, 0); @@ -1745,14 +1745,14 @@ static void sub_81C0D44(u8 taskId) s16 *data = gTasks[taskId].data; if (pssData->unk40C9 == 0) { - SetBgAttribute(1, 7, 1); - SetBgAttribute(2, 7, 2); + SetBgAttribute(1, BG_ATTR_PRIORITY, 1); + SetBgAttribute(2, BG_ATTR_PRIORITY, 2); schedule_bg_copy_tilemap_to_vram(2); } else { - SetBgAttribute(2, 7, 1); - SetBgAttribute(1, 7, 2); + SetBgAttribute(2, BG_ATTR_PRIORITY, 1); + SetBgAttribute(1, BG_ATTR_PRIORITY, 2); schedule_bg_copy_tilemap_to_vram(1); } if (pssData->currPageIndex > 1) diff --git a/src/region_map.c b/src/region_map.c index 4caf3147a2..fa5ed21592 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -427,82 +427,82 @@ bool8 sub_8122DB0(void) { switch (gRegionMap->initStep) { - case 0: - if (gRegionMap->bgManaged) - { - decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_GfxLZ, 0, 0, 0); - } - else - { - LZ77UnCompVram(sRegionMapBkgnd_GfxLZ, (u16 *)BG_CHAR_ADDR(2)); - } - break; - case 1: - if (gRegionMap->bgManaged) - { - if (!free_temp_tile_data_buffers_if_possible()) - { - decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_TilemapLZ, 0, 0, 1); - } - } - else - { - LZ77UnCompVram(sRegionMapBkgnd_TilemapLZ, (u16 *)BG_SCREEN_ADDR(28)); - } - break; - case 2: - if (!free_temp_tile_data_buffers_if_possible()) - { - LoadPalette(sRegionMapBkgnd_Pal, 0x70, 0x60); - } - break; - case 3: - LZ77UnCompWram(sRegionMapCursorSmallGfxLZ, gRegionMap->cursorSmallImage); - break; - case 4: - LZ77UnCompWram(sRegionMapCursorLargeGfxLZ, gRegionMap->cursorLargeImage); - break; - case 5: - RegionMap_InitializeStateBasedOnPlayerLocation(); - gRegionMap->playerIconSpritePosX = gRegionMap->cursorPosX; - gRegionMap->playerIconSpritePosY = gRegionMap->cursorPosY; - gRegionMap->mapSecId = CorrectSpecialMapSecId_Internal(gRegionMap->mapSecId); - gRegionMap->iconDrawType = get_flagnr_blue_points(gRegionMap->mapSecId); - GetMapName(gRegionMap->mapSecName, gRegionMap->mapSecId, 16); - break; - case 6: - if (gRegionMap->zoomed == FALSE) - { - CalcZoomScrollParams(0, 0, 0, 0, 0x100, 0x100, 0); - } - else - { - gRegionMap->scrollX = gRegionMap->cursorPosX * 8 - 0x34; - gRegionMap->scrollY = gRegionMap->cursorPosY * 8 - 0x44; - gRegionMap->zoomedCursorPosX = gRegionMap->cursorPosX; - gRegionMap->zoomedCursorPosY = gRegionMap->cursorPosY; - CalcZoomScrollParams(gRegionMap->scrollX, gRegionMap->scrollY, 0x38, 0x48, 0x80, 0x80, 0); - } - break; - case 7: - RegionMap_GetPositionOfCursorWithinMapSection(); - UpdateRegionMapVideoRegs(); - gRegionMap->cursorSprite = NULL; - gRegionMap->playerIconSprite = NULL; - gRegionMap->cursorMovementFrameCounter = 0; - gRegionMap->blinkPlayerIcon = FALSE; - if (gRegionMap->bgManaged) - { - SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_MAPBASEINDEX, 2); - SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_VISIBLE, gRegionMap->charBaseIdx); - SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_CHARBASEINDEX, gRegionMap->mapBaseIdx); - SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_PRIORITY, 1); - SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_SCREENSIZE, 1); - } - gRegionMap->initStep++; - return FALSE; - default: - return FALSE; + case 0: + if (gRegionMap->bgManaged) + { + decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_GfxLZ, 0, 0, 0); + } + else + { + LZ77UnCompVram(sRegionMapBkgnd_GfxLZ, (u16 *)BG_CHAR_ADDR(2)); + } + break; + case 1: + if (gRegionMap->bgManaged) + { + if (!free_temp_tile_data_buffers_if_possible()) + { + decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_TilemapLZ, 0, 0, 1); + } + } + else + { + LZ77UnCompVram(sRegionMapBkgnd_TilemapLZ, (u16 *)BG_SCREEN_ADDR(28)); + } + break; + case 2: + if (!free_temp_tile_data_buffers_if_possible()) + { + LoadPalette(sRegionMapBkgnd_Pal, 0x70, 0x60); + } + break; + case 3: + LZ77UnCompWram(sRegionMapCursorSmallGfxLZ, gRegionMap->cursorSmallImage); + break; + case 4: + LZ77UnCompWram(sRegionMapCursorLargeGfxLZ, gRegionMap->cursorLargeImage); + break; + case 5: + RegionMap_InitializeStateBasedOnPlayerLocation(); + gRegionMap->playerIconSpritePosX = gRegionMap->cursorPosX; + gRegionMap->playerIconSpritePosY = gRegionMap->cursorPosY; + gRegionMap->mapSecId = CorrectSpecialMapSecId_Internal(gRegionMap->mapSecId); + gRegionMap->iconDrawType = get_flagnr_blue_points(gRegionMap->mapSecId); + GetMapName(gRegionMap->mapSecName, gRegionMap->mapSecId, 16); + break; + case 6: + if (gRegionMap->zoomed == FALSE) + { + CalcZoomScrollParams(0, 0, 0, 0, 0x100, 0x100, 0); + } + else + { + gRegionMap->scrollX = gRegionMap->cursorPosX * 8 - 0x34; + gRegionMap->scrollY = gRegionMap->cursorPosY * 8 - 0x44; + gRegionMap->zoomedCursorPosX = gRegionMap->cursorPosX; + gRegionMap->zoomedCursorPosY = gRegionMap->cursorPosY; + CalcZoomScrollParams(gRegionMap->scrollX, gRegionMap->scrollY, 0x38, 0x48, 0x80, 0x80, 0); + } + break; + case 7: + RegionMap_GetPositionOfCursorWithinMapSection(); + UpdateRegionMapVideoRegs(); + gRegionMap->cursorSprite = NULL; + gRegionMap->playerIconSprite = NULL; + gRegionMap->cursorMovementFrameCounter = 0; + gRegionMap->blinkPlayerIcon = FALSE; + if (gRegionMap->bgManaged) + { + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_SCREENSIZE, 2); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_CHARBASEINDEX, gRegionMap->charBaseIdx); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_MAPBASEINDEX, gRegionMap->mapBaseIdx); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_WRAPAROUND, 1); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_PALETTEMODE, 1); + } + gRegionMap->initStep++; + return FALSE; + default: + return FALSE; } gRegionMap->initStep++; return TRUE; diff --git a/src/reshow_battle_screen.c b/src/reshow_battle_screen.c index 06d2af5b74..1b17c372c6 100644 --- a/src/reshow_battle_screen.c +++ b/src/reshow_battle_screen.c @@ -50,8 +50,8 @@ static void CB2_ReshowBattleScreenAfterMenu(void) case 0: ScanlineEffect_Clear(); BattleInitBgsAndWindows(); - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); ShowBg(0); ShowBg(1); ShowBg(2); diff --git a/src/unk_pokedex_area_screen_helper.c b/src/unk_pokedex_area_screen_helper.c index 67fd52cb50..0041d628c5 100644 --- a/src/unk_pokedex_area_screen_helper.c +++ b/src/unk_pokedex_area_screen_helper.c @@ -22,21 +22,21 @@ void sub_81C4D70(const struct UnkStruct_1C4D70 *template) if (unk == 0) { - SetBgAttribute(template->bg, BG_CTRL_ATTR_WRAPAROUND, 0); + SetBgAttribute(template->bg, BG_ATTR_METRIC, 0); decompress_and_copy_tile_data_to_vram(template->bg, gUnknown_0861D1A0, 0, template->unk2, unk); sub_8199D3C(decompress_and_copy_tile_data_to_vram(template->bg, gUnknown_0861DEF4, 0, 0, 1), template->unk2, 32, 32, unk); } else { - SetBgAttribute(template->bg, BG_CTRL_ATTR_WRAPAROUND, 2); - SetBgAttribute(template->bg, 9, 1); + SetBgAttribute(template->bg, BG_ATTR_METRIC, 2); + SetBgAttribute(template->bg, BG_ATTR_TYPE, 1); decompress_and_copy_tile_data_to_vram(template->bg, gUnknown_0861E208, 0, template->unk2, 0); sub_8199D3C(decompress_and_copy_tile_data_to_vram(template->bg, gUnknown_0861EF64, 0, 0, 1), template->unk2, 64, 64, 1); } ChangeBgX(template->bg, 0, 0); ChangeBgY(template->bg, 0, 0); - SetBgAttribute(template->bg, BG_CTRL_ATTR_SCREENSIZE, 1); + SetBgAttribute(template->bg, BG_ATTR_PALETTEMODE, 1); CpuCopy32(gUnknown_0861D140, &gPlttBufferUnfaded[0x70], 0x60); *gUnknown_0203CF28 = template->bg; } diff --git a/src/window.c b/src/window.c index aa1df3a123..3da5291789 100644 --- a/src/window.c +++ b/src/window.c @@ -63,7 +63,7 @@ bool16 InitWindows(const struct WindowTemplate *templates) if (gUnknown_03002F70[bgLayer] == NULL) { - attrib = GetBgAttribute(bgLayer, 0x8); + attrib = GetBgAttribute(bgLayer, BG_ATTR_METRIC); if (attrib != 0xFFFF) { @@ -141,7 +141,7 @@ u16 AddWindow(const struct WindowTemplate *template) if (gUnknown_03002F70[bgLayer] == NULL) { - attrib = GetBgAttribute(bgLayer, 0x8); + attrib = GetBgAttribute(bgLayer, BG_ATTR_METRIC); if (attrib != 0xFFFF) { @@ -328,7 +328,7 @@ void PutWindowTilemap(u8 windowId) WriteSequenceToBgTilemapBuffer( windowLocal.window.bg, - GetBgAttribute(windowLocal.window.bg, 0xA) + windowLocal.window.baseBlock, + GetBgAttribute(windowLocal.window.bg, BG_ATTR_BASETILE) + windowLocal.window.baseBlock, windowLocal.window.tilemapLeft, windowLocal.window.tilemapTop, windowLocal.window.width, @@ -340,7 +340,7 @@ void PutWindowTilemap(u8 windowId) void PutWindowRectTilemapOverridePalette(u8 windowId, u8 x, u8 y, u8 width, u8 height, u8 palette) { struct Window windowLocal = gWindows[windowId]; - u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.bg, 0xA); + u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.bg, BG_ATTR_BASETILE); int i; for (i = 0; i < height; ++i) @@ -376,7 +376,7 @@ void ClearWindowTilemap(u8 windowId) void PutWindowRectTilemap(u8 windowId, u8 x, u8 y, u8 width, u8 height) { struct Window windowLocal = gWindows[windowId]; - u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.bg, 0xA); + u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.bg, BG_ATTR_BASETILE); int i; for (i = 0; i < height; ++i) @@ -617,7 +617,7 @@ u16 AddWindow8Bit(const struct WindowTemplate *template) bgLayer = template->bg; if (gUnknown_03002F70[bgLayer] == 0) { - u16 attribute = GetBgAttribute(bgLayer, 8); + u16 attribute = GetBgAttribute(bgLayer, BG_ATTR_METRIC); if (attribute != 0xFFFF) { s32 i; From 7e4db39da531320f0f2ff180ddbd2f2c21f84fce Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 26 Dec 2018 13:43:07 +0100 Subject: [PATCH 2/4] Fix bldcnt gpu reg args --- src/battle_anim.c | 2 +- src/battle_anim_effects_2.c | 2 +- src/battle_anim_effects_3.c | 2 +- src/berry_fix_program.c | 18 +++++++++--------- src/credits.c | 2 +- src/evolution_scene.c | 4 ++-- src/fldeff_misc.c | 4 ++-- src/hall_of_fame.c | 4 ++-- src/starter_choose.c | 2 +- src/title_screen.c | 6 +++--- src/unk_transition.c | 2 +- src/wallclock.c | 16 ++++++++-------- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/battle_anim.c b/src/battle_anim.c index d1550f31e6..7dd1526dd2 100644 --- a/src/battle_anim.c +++ b/src/battle_anim.c @@ -2283,7 +2283,7 @@ static void ScriptCmd_setalpha(void) sBattleAnimScriptPtr++; half1 = *(sBattleAnimScriptPtr++); half2 = *(sBattleAnimScriptPtr++) << 8; - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F40); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); SetGpuReg(REG_OFFSET_BLDALPHA, half1 | half2); } diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c index 8acbf62d4a..0ec8b63d7a 100755 --- a/src/battle_anim_effects_2.c +++ b/src/battle_anim_effects_2.c @@ -3134,7 +3134,7 @@ void sub_8105EB0(u8 taskId) SetGpuReg(REG_OFFSET_WIN0V, gBattle_WIN0V); SetGpuReg(REG_OFFSET_WININ, 0x3F1F); SetGpuReg(REG_OFFSET_WINOUT, 0x3F3F); - SetGpuReg(REG_OFFSET_BLDCNT, 0xC8); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG3 | BLDCNT_EFFECT_DARKEN); SetGpuReg(REG_OFFSET_BLDY, 0x10); gTasks[taskId].data[0] = win0v; gTasks[taskId].data[1] = win0h; diff --git a/src/battle_anim_effects_3.c b/src/battle_anim_effects_3.c index f6858c0935..5f135691b9 100755 --- a/src/battle_anim_effects_3.c +++ b/src/battle_anim_effects_3.c @@ -3220,7 +3220,7 @@ void sub_815CED8(u8 taskId) gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND; FillPalette(RGB(31, 31, 31), (gSprites[spriteId].oam.paletteNum << 4) + 0x100, 32); gSprites[spriteId].oam.priority = priority; - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F40); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[1], 16 - gTasks[taskId].data[1])); gTasks[taskId].data[0] = spriteId; diff --git a/src/berry_fix_program.c b/src/berry_fix_program.c index d87509e101..3631c083ad 100644 --- a/src/berry_fix_program.c +++ b/src/berry_fix_program.c @@ -67,7 +67,7 @@ static const u16 sUnknown_08618138[] = { 0x7fff, 0x7fff, 0x318c, 0x675a, 0x043c, 0x3aff, 0x0664, 0x4bd2, 0x6546, 0x7b14, 0x7fff, 0x318c, - 0x675a, 0x0000, 0x0000, 0x0000 + 0x675a, 0, 0, 0 }; static const u8 sUnknown_08618158[] = {10, 11, 12}; @@ -124,7 +124,7 @@ void CB2_InitBerryFixProgram(void) ResetSpriteData(); ResetTasks(); ScanlineEffect_Stop(); - SetGpuReg(REG_OFFSET_DISPCNT, 0x0000); + SetGpuReg(REG_OFFSET_DISPCNT, 0); berry_fix_mb_manager = AllocZeroed(0x50); berry_fix_mb_manager->state = 0; berry_fix_mb_manager->unk1 = 6; @@ -203,13 +203,13 @@ static void berry_fix_gpu_set(void) { s32 width, left; - SetGpuReg(REG_OFFSET_BG0CNT, 0x0000); - SetGpuReg(REG_OFFSET_BG1CNT, 0x0000); - SetGpuReg(REG_OFFSET_BG0HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG0VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG1HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG1VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BLDCNT, 0x0000); + SetGpuReg(REG_OFFSET_BG0CNT, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); DmaFill32(3, 0, VRAM, VRAM_SIZE); DmaFill32(3, 0, OAM, OAM_SIZE); diff --git a/src/credits.c b/src/credits.c index 5e52e5fb71..c27004a283 100644 --- a/src/credits.c +++ b/src/credits.c @@ -2219,7 +2219,7 @@ static void sub_8177050(struct Sprite *sprite) } else { - SetGpuReg(REG_OFFSET_BLDCNT, 0xF40); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_BG3); SetGpuReg(REG_OFFSET_BLDALPHA, 0x10); sprite->oam.objMode = 1; sprite->data[3] = 16; diff --git a/src/evolution_scene.c b/src/evolution_scene.c index ea2302130b..1b3133e9ec 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -1479,7 +1479,7 @@ static void InitMovingBackgroundTask(bool8 isLink) if (!isLink) { - SetGpuReg(REG_OFFSET_BLDCNT, 0x442); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG2); SetGpuReg(REG_OFFSET_BLDALPHA, 0x808); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG2_ON | DISPCNT_BG1_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP); @@ -1491,7 +1491,7 @@ static void InitMovingBackgroundTask(bool8 isLink) } else { - SetGpuReg(REG_OFFSET_BLDCNT, 0x842); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG3); SetGpuReg(REG_OFFSET_BLDALPHA, 0x808); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG3_ON | DISPCNT_BG1_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP); } diff --git a/src/fldeff_misc.c b/src/fldeff_misc.c index 9d77383ae4..1f4c6f9fbd 100644 --- a/src/fldeff_misc.c +++ b/src/fldeff_misc.c @@ -376,7 +376,7 @@ static void sub_80F9C90(u8 taskId) task->data[7] = GetGpuReg(REG_OFFSET_BLDCNT); task->data[8] = GetGpuReg(REG_OFFSET_BLDY); - SetGpuReg(REG_OFFSET_BLDCNT, 0xBF); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_ALL | BLDCNT_EFFECT_LIGHTEN); SetGpuReg(REG_OFFSET_BLDY, 0x10); break; @@ -452,7 +452,7 @@ static void sub_80F9DFC(u8 taskId) { task->data[5] = 0x50; task->data[6] = 0x51; - SetGpuReg(REG_OFFSET_BLDCNT, 0xBF); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_ALL | BLDCNT_EFFECT_LIGHTEN); SetGpuReg(REG_OFFSET_BLDY, 0x10); } SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[6])); diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index b973798f6e..63818dd49b 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -355,7 +355,7 @@ static bool8 InitHallOfFameScreen(void) gMain.state++; break; case 2: - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F42); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); SetGpuReg(REG_OFFSET_BLDALPHA, 0x710); SetGpuReg(REG_OFFSET_BLDY, 0); sub_8174FAC(); @@ -817,7 +817,7 @@ void CB2_DoHallOfFamePC(void) { u8 taskId, i; - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F42); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); SetGpuReg(REG_OFFSET_BLDALPHA, 0x710); SetGpuReg(REG_OFFSET_BLDY, 0); taskId = CreateTask(Task_HofPC_CopySaveData, 0); diff --git a/src/starter_choose.c b/src/starter_choose.c index afa3fabbf6..2d4a1b1e1c 100644 --- a/src/starter_choose.c +++ b/src/starter_choose.c @@ -425,7 +425,7 @@ void CB2_ChooseStarter(void) SetGpuReg(REG_OFFSET_WINOUT, 0x1F); SetGpuReg(REG_OFFSET_WIN0H, 0); SetGpuReg(REG_OFFSET_WIN0V, 0); - SetGpuReg(REG_OFFSET_BLDCNT, 0xFE); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_TGT1_BG2 | BLDCNT_TGT1_BG3 | BLDCNT_TGT1_OBJ | BLDCNT_TGT1_BD | BLDCNT_EFFECT_DARKEN); SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDY, 7); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); diff --git a/src/title_screen.c b/src/title_screen.c index c6e9aa26fa..76704987f4 100644 --- a/src/title_screen.c +++ b/src/title_screen.c @@ -553,7 +553,7 @@ void CB2_InitTitleScreen(void) SetGpuReg(REG_OFFSET_WIN1V, 0); SetGpuReg(REG_OFFSET_WININ, 0x1F1F); SetGpuReg(REG_OFFSET_WINOUT, 0x3F1F); - SetGpuReg(REG_OFFSET_BLDCNT, 0x84); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG2 | BLDCNT_EFFECT_LIGHTEN); SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDY, 0xC); SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(3) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(26) | BGCNT_16COLOR | BGCNT_TXT256x256); @@ -615,7 +615,7 @@ static void Task_TitleScreenPhase1(u8 taskId) SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG2_ON | DISPCNT_OBJ_ON); SetGpuReg(REG_OFFSET_WININ, 0); SetGpuReg(REG_OFFSET_WINOUT, 0); - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F50); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_OBJ | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); SetGpuReg(REG_OFFSET_BLDALPHA, 0x10); SetGpuReg(REG_OFFSET_BLDY, 0); @@ -652,7 +652,7 @@ static void Task_TitleScreenPhase2(u8 taskId) else { gTasks[taskId].tSkipToNext = TRUE; - SetGpuReg(REG_OFFSET_BLDCNT, 0x2142); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG0 | BLDCNT_TGT2_BD); SetGpuReg(REG_OFFSET_BLDALPHA, 0xF06); SetGpuReg(REG_OFFSET_BLDY, 0); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 diff --git a/src/unk_transition.c b/src/unk_transition.c index 7346e06abe..0faf454026 100644 --- a/src/unk_transition.c +++ b/src/unk_transition.c @@ -337,7 +337,7 @@ static bool8 sub_81DAACC(struct Task *task) else { sub_81DA700(); - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F41); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG0 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); SetGpuReg(REG_OFFSET_BLDALPHA, 0x1000); ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); diff --git a/src/wallclock.c b/src/wallclock.c index 58704c8a39..546750ba66 100644 --- a/src/wallclock.c +++ b/src/wallclock.c @@ -585,11 +585,11 @@ static void WallClockVblankCallback(void) static void LoadWallClockGraphics(void) { SetVBlankCallback(NULL); - SetGpuReg(REG_OFFSET_DISPCNT, 0x0000); - SetGpuReg(REG_OFFSET_BG3CNT, 0x0000); - SetGpuReg(REG_OFFSET_BG2CNT, 0x0000); - SetGpuReg(REG_OFFSET_BG1CNT, 0x0000); - SetGpuReg(REG_OFFSET_BG0CNT, 0x0000); + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_BG3CNT, 0); + SetGpuReg(REG_OFFSET_BG2CNT, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG0CNT, 0); ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); ChangeBgX(1, 0, 0); @@ -633,9 +633,9 @@ static void WallClockInit(void) EnableInterrupts(INTR_FLAG_VBLANK); SetVBlankCallback(WallClockVblankCallback); SetMainCallback2(WallClockMainCallback); - SetGpuReg(REG_OFFSET_BLDCNT, 0x0000); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x0000); - SetGpuReg(REG_OFFSET_BLDY, 0x0000); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 0); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON); ShowBg(0); ShowBg(2); From 6761a049daa44bce169638356dd1760c55e786c5 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 26 Dec 2018 14:03:48 +0100 Subject: [PATCH 3/4] Fix Bldalpha args --- src/battle_interface.c | 4 ++-- src/credits.c | 2 +- src/evolution_scene.c | 4 ++-- src/hall_of_fame.c | 4 ++-- src/mail.c | 48 +++++++++++++++++++++--------------------- src/rayquaza_scene.c | 8 +++---- src/title_screen.c | 4 ++-- src/unk_transition.c | 8 +++---- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/battle_interface.c b/src/battle_interface.c index 4a84220912..0eb494db4b 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1753,7 +1753,7 @@ static void sub_8073E08(u8 taskId) if (--gTasks[taskId].tData15 < 0) return; - SetGpuReg(REG_OFFSET_BLDALPHA, (gTasks[taskId].data[15]) | ((16 - gTasks[taskId].data[15]) << 8)); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[15], 16 - gTasks[taskId].data[15])); } if (gTasks[taskId].tData15 == 0) gTasks[taskId].func = sub_8073E64; @@ -1806,7 +1806,7 @@ static void sub_8073F98(u8 taskId) if (--gTasks[taskId].tData15 >= 0) { - SetGpuReg(REG_OFFSET_BLDALPHA, (gTasks[taskId].tData15) | ((16 - gTasks[taskId].tData15) << 8)); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[15], 16 - gTasks[taskId].data[15])); } else if (gTasks[taskId].tData15 == -1) { diff --git a/src/credits.c b/src/credits.c index c27004a283..3639d36e4c 100644 --- a/src/credits.c +++ b/src/credits.c @@ -2220,7 +2220,7 @@ static void sub_8177050(struct Sprite *sprite) else { SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_BG3); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x10); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 0)); sprite->oam.objMode = 1; sprite->data[3] = 16; sprite->data[0] += 1; diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 1b3133e9ec..2c1df814b4 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -1480,7 +1480,7 @@ static void InitMovingBackgroundTask(bool8 isLink) if (!isLink) { SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG2); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x808); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(8, 8)); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG2_ON | DISPCNT_BG1_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP); SetBgAttribute(innerBgId, BG_ATTR_PRIORITY, 2); @@ -1492,7 +1492,7 @@ static void InitMovingBackgroundTask(bool8 isLink) else { SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG3); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x808); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(8, 8)); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG3_ON | DISPCNT_BG1_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP); } diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 63818dd49b..34d62149a1 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -356,7 +356,7 @@ static bool8 InitHallOfFameScreen(void) break; case 2: SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x710); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 7)); SetGpuReg(REG_OFFSET_BLDY, 0); sub_8174FAC(); sHofGfxPtr->state = 0; @@ -818,7 +818,7 @@ void CB2_DoHallOfFamePC(void) u8 taskId, i; SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x710); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 7)); SetGpuReg(REG_OFFSET_BLDY, 0); taskId = CreateTask(Task_HofPC_CopySaveData, 0); diff --git a/src/mail.c b/src/mail.c index 7b096ed00c..287a91e656 100644 --- a/src/mail.c +++ b/src/mail.c @@ -89,7 +89,7 @@ struct MailGraphics struct MailRead { - /*0x0000*/ u8 strbuf[8][64]; + /*0*/ u8 strbuf[8][64]; /*0x0200*/ u8 playerName[12]; /*0x020C*/ MainCallback callback; /*0x0210*/ MainCallback callback2; @@ -170,29 +170,29 @@ static const u16 sUnknown_0859F2B0[][2] = { static const struct MailGraphics sUnknown_0859F2B8[] = { { - gMailPalette_Orange, gMailTiles_Orange, gMailTilemap_Orange, 0x02c0, 0x0000, 0x294a, 0x6739 + gMailPalette_Orange, gMailTiles_Orange, gMailTilemap_Orange, 0x02c0, 0, 0x294a, 0x6739 }, { - gMailPalette_Harbor, gMailTiles_Harbor, gMailTilemap_Harbor, 0x02e0, 0x0000, 0x7fff, 0x4631 + gMailPalette_Harbor, gMailTiles_Harbor, gMailTilemap_Harbor, 0x02e0, 0, 0x7fff, 0x4631 }, { - gMailPalette_Glitter, gMailTiles_Glitter, gMailTilemap_Glitter, 0x0400, 0x0000, 0x294a, 0x6739 + gMailPalette_Glitter, gMailTiles_Glitter, gMailTilemap_Glitter, 0x0400, 0, 0x294a, 0x6739 }, { - gMailPalette_Mech, gMailTiles_Mech, gMailTilemap_Mech, 0x01e0, 0x0000, 0x7fff, 0x4631 + gMailPalette_Mech, gMailTiles_Mech, gMailTilemap_Mech, 0x01e0, 0, 0x7fff, 0x4631 }, { - gMailPalette_Wood, gMailTiles_Wood, gMailTilemap_Wood, 0x02e0, 0x0000, 0x7fff, 0x4631 + gMailPalette_Wood, gMailTiles_Wood, gMailTilemap_Wood, 0x02e0, 0, 0x7fff, 0x4631 }, { - gMailPalette_Wave, gMailTiles_Wave, gMailTilemap_Wave, 0x0300, 0x0000, 0x294a, 0x6739 + gMailPalette_Wave, gMailTiles_Wave, gMailTilemap_Wave, 0x0300, 0, 0x294a, 0x6739 }, { - gMailPalette_Bead, gMailTiles_Bead, gMailTilemap_Bead, 0x0140, 0x0000, 0x7fff, 0x4631 + gMailPalette_Bead, gMailTiles_Bead, gMailTilemap_Bead, 0x0140, 0, 0x7fff, 0x4631 }, { - gMailPalette_Shadow, gMailTiles_Shadow, gMailTilemap_Shadow, 0x0300, 0x0000, 0x7fff, 0x4631 + gMailPalette_Shadow, gMailTiles_Shadow, gMailTilemap_Shadow, 0x0300, 0, 0x7fff, 0x4631 }, { - gMailPalette_Tropic, gMailTiles_Tropic, gMailTilemap_Tropic, 0x0220, 0x0000, 0x294a, 0x6739 + gMailPalette_Tropic, gMailTiles_Tropic, gMailTilemap_Tropic, 0x0220, 0, 0x294a, 0x6739 }, { - gMailPalette_Dream, gMailTiles_Dream, gMailTilemap_Dream, 0x0340, 0x0000, 0x294a, 0x6739 + gMailPalette_Dream, gMailTiles_Dream, gMailTilemap_Dream, 0x0340, 0, 0x294a, 0x6739 }, { - gMailPalette_Fab, gMailTiles_Fab, gMailTilemap_Fab, 0x02a0, 0x0000, 0x294a, 0x6739 + gMailPalette_Fab, gMailTiles_Fab, gMailTilemap_Fab, 0x02a0, 0, 0x294a, 0x6739 }, { - gMailPalette_Retro, gMailTiles_Retro, gMailTilemap_Retro, 0x0520, 0x0000, 0x294a, 0x6739 + gMailPalette_Retro, gMailTiles_Retro, gMailTilemap_Retro, 0x0520, 0, 0x294a, 0x6739 } }; @@ -306,7 +306,7 @@ static bool8 MailReadBuildGraphics(void) case 0: SetVBlankCallback(NULL); ScanlineEffect_Stop(); - SetGpuReg(REG_OFFSET_DISPCNT, 0x0000); + SetGpuReg(REG_OFFSET_DISPCNT, 0); break; case 1: CpuFill16(0, (void *)OAM, OAM_SIZE); @@ -323,16 +323,16 @@ static bool8 MailReadBuildGraphics(void) case 5: FreeAllSpritePalettes(); reset_temp_tile_data_buffers(); - SetGpuReg(REG_OFFSET_BG0HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG0VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG1HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG1VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG2VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG2HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG3HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG3VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BLDCNT, 0x0000); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x0000); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); break; case 6: ResetBgsAndClearDma3BusyFlags(0); diff --git a/src/rayquaza_scene.c b/src/rayquaza_scene.c index 94d81e30f6..00a73a0a20 100644 --- a/src/rayquaza_scene.c +++ b/src/rayquaza_scene.c @@ -1708,7 +1708,7 @@ static void sub_81D752C(u8 taskId) if (data[0] != 16) { data[0]++; - SetGpuReg(REG_OFFSET_BLDALPHA, (data[0] << 8) | (16 - data[0])); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16 - data[0], data[0])); } } @@ -1954,7 +1954,7 @@ static void Task_RayTakesFlightAnim(u8 taskId) sub_81D7E10(); sub_81D7E9C(); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_OBJ | BLDCNT_TGT2_BG1 | BLDCNT_EFFECT_BLEND); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x808); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(8, 8)); BlendPalettes(-1, 0x10, 0); SetVBlankCallback(VBlankCB_RayquazaScene); CreateTask(sub_81D81A4, 0); @@ -2153,7 +2153,7 @@ static void Task_RayDescendsAnim(u8 taskId) sub_81D82B0(); sub_81D8358(); SetGpuRegBits(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_BG3 | BLDCNT_TGT2_OBJ | BLDCNT_EFFECT_BLEND); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x1000); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 16)); BlendPalettes(-1, 0x10, 0); SetVBlankCallback(VBlankCB_RayquazaScene); sRayScene->field_2008 = 0; @@ -2509,7 +2509,7 @@ static void Task_RayChasesAwayAnim(u8 taskId) sub_81D68C8(); ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_BG2_ON); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_EFFECT_BLEND); - SetGpuReg(REG_OFFSET_BLDALPHA, 0xE09); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(9, 14)); BlendPalettes(-1, 0x10, 0); SetVBlankCallback(VBlankCB_RayquazaScene); data[0] = 0; diff --git a/src/title_screen.c b/src/title_screen.c index 76704987f4..48571ff96c 100644 --- a/src/title_screen.c +++ b/src/title_screen.c @@ -616,7 +616,7 @@ static void Task_TitleScreenPhase1(u8 taskId) SetGpuReg(REG_OFFSET_WININ, 0); SetGpuReg(REG_OFFSET_WINOUT, 0); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_OBJ | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x10); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 0)); SetGpuReg(REG_OFFSET_BLDY, 0); // Create left side of version banner @@ -653,7 +653,7 @@ static void Task_TitleScreenPhase2(u8 taskId) { gTasks[taskId].tSkipToNext = TRUE; SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG0 | BLDCNT_TGT2_BD); - SetGpuReg(REG_OFFSET_BLDALPHA, 0xF06); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(6, 15)); SetGpuReg(REG_OFFSET_BLDY, 0); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 | DISPCNT_OBJ_1D_MAP diff --git a/src/unk_transition.c b/src/unk_transition.c index 0faf454026..d56998b5bb 100644 --- a/src/unk_transition.c +++ b/src/unk_transition.c @@ -338,7 +338,7 @@ static bool8 sub_81DAACC(struct Task *task) { sub_81DA700(); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG0 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x1000); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 16)); ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); ChangeBgY(0, 0x500, 2); @@ -368,11 +368,11 @@ static bool8 sub_81DAB4C(struct Task *task) } else { - u16 var; + u16 blnd; task->data[2]++; - var = task->data[2]; - SetGpuReg(REG_OFFSET_BLDALPHA, (var) | ((16 - var) << 8)); + blnd = task->data[2]; + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(blnd, 16 - blnd)); } return FALSE; From b9ad5de8a044623b9d4d76307a76c00e2fcf0da6 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 26 Dec 2018 14:50:47 +0100 Subject: [PATCH 4/4] fortmatting --- src/mail.c | 2 +- src/region_map.c | 152 +++++++++++++++++++++++------------------------ 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/mail.c b/src/mail.c index 287a91e656..45e96e85e5 100644 --- a/src/mail.c +++ b/src/mail.c @@ -89,7 +89,7 @@ struct MailGraphics struct MailRead { - /*0*/ u8 strbuf[8][64]; + /*0x0000*/ u8 strbuf[8][64]; /*0x0200*/ u8 playerName[12]; /*0x020C*/ MainCallback callback; /*0x0210*/ MainCallback callback2; diff --git a/src/region_map.c b/src/region_map.c index fa5ed21592..4752d96f05 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -427,82 +427,82 @@ bool8 sub_8122DB0(void) { switch (gRegionMap->initStep) { - case 0: - if (gRegionMap->bgManaged) - { - decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_GfxLZ, 0, 0, 0); - } - else - { - LZ77UnCompVram(sRegionMapBkgnd_GfxLZ, (u16 *)BG_CHAR_ADDR(2)); - } - break; - case 1: - if (gRegionMap->bgManaged) - { - if (!free_temp_tile_data_buffers_if_possible()) - { - decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_TilemapLZ, 0, 0, 1); - } - } - else - { - LZ77UnCompVram(sRegionMapBkgnd_TilemapLZ, (u16 *)BG_SCREEN_ADDR(28)); - } - break; - case 2: - if (!free_temp_tile_data_buffers_if_possible()) - { - LoadPalette(sRegionMapBkgnd_Pal, 0x70, 0x60); - } - break; - case 3: - LZ77UnCompWram(sRegionMapCursorSmallGfxLZ, gRegionMap->cursorSmallImage); - break; - case 4: - LZ77UnCompWram(sRegionMapCursorLargeGfxLZ, gRegionMap->cursorLargeImage); - break; - case 5: - RegionMap_InitializeStateBasedOnPlayerLocation(); - gRegionMap->playerIconSpritePosX = gRegionMap->cursorPosX; - gRegionMap->playerIconSpritePosY = gRegionMap->cursorPosY; - gRegionMap->mapSecId = CorrectSpecialMapSecId_Internal(gRegionMap->mapSecId); - gRegionMap->iconDrawType = get_flagnr_blue_points(gRegionMap->mapSecId); - GetMapName(gRegionMap->mapSecName, gRegionMap->mapSecId, 16); - break; - case 6: - if (gRegionMap->zoomed == FALSE) - { - CalcZoomScrollParams(0, 0, 0, 0, 0x100, 0x100, 0); - } - else - { - gRegionMap->scrollX = gRegionMap->cursorPosX * 8 - 0x34; - gRegionMap->scrollY = gRegionMap->cursorPosY * 8 - 0x44; - gRegionMap->zoomedCursorPosX = gRegionMap->cursorPosX; - gRegionMap->zoomedCursorPosY = gRegionMap->cursorPosY; - CalcZoomScrollParams(gRegionMap->scrollX, gRegionMap->scrollY, 0x38, 0x48, 0x80, 0x80, 0); - } - break; - case 7: - RegionMap_GetPositionOfCursorWithinMapSection(); - UpdateRegionMapVideoRegs(); - gRegionMap->cursorSprite = NULL; - gRegionMap->playerIconSprite = NULL; - gRegionMap->cursorMovementFrameCounter = 0; - gRegionMap->blinkPlayerIcon = FALSE; - if (gRegionMap->bgManaged) - { - SetBgAttribute(gRegionMap->bgNum, BG_ATTR_SCREENSIZE, 2); - SetBgAttribute(gRegionMap->bgNum, BG_ATTR_CHARBASEINDEX, gRegionMap->charBaseIdx); - SetBgAttribute(gRegionMap->bgNum, BG_ATTR_MAPBASEINDEX, gRegionMap->mapBaseIdx); - SetBgAttribute(gRegionMap->bgNum, BG_ATTR_WRAPAROUND, 1); - SetBgAttribute(gRegionMap->bgNum, BG_ATTR_PALETTEMODE, 1); - } - gRegionMap->initStep++; - return FALSE; - default: - return FALSE; + case 0: + if (gRegionMap->bgManaged) + { + decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_GfxLZ, 0, 0, 0); + } + else + { + LZ77UnCompVram(sRegionMapBkgnd_GfxLZ, (u16 *)BG_CHAR_ADDR(2)); + } + break; + case 1: + if (gRegionMap->bgManaged) + { + if (!free_temp_tile_data_buffers_if_possible()) + { + decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_TilemapLZ, 0, 0, 1); + } + } + else + { + LZ77UnCompVram(sRegionMapBkgnd_TilemapLZ, (u16 *)BG_SCREEN_ADDR(28)); + } + break; + case 2: + if (!free_temp_tile_data_buffers_if_possible()) + { + LoadPalette(sRegionMapBkgnd_Pal, 0x70, 0x60); + } + break; + case 3: + LZ77UnCompWram(sRegionMapCursorSmallGfxLZ, gRegionMap->cursorSmallImage); + break; + case 4: + LZ77UnCompWram(sRegionMapCursorLargeGfxLZ, gRegionMap->cursorLargeImage); + break; + case 5: + RegionMap_InitializeStateBasedOnPlayerLocation(); + gRegionMap->playerIconSpritePosX = gRegionMap->cursorPosX; + gRegionMap->playerIconSpritePosY = gRegionMap->cursorPosY; + gRegionMap->mapSecId = CorrectSpecialMapSecId_Internal(gRegionMap->mapSecId); + gRegionMap->iconDrawType = get_flagnr_blue_points(gRegionMap->mapSecId); + GetMapName(gRegionMap->mapSecName, gRegionMap->mapSecId, 16); + break; + case 6: + if (gRegionMap->zoomed == FALSE) + { + CalcZoomScrollParams(0, 0, 0, 0, 0x100, 0x100, 0); + } + else + { + gRegionMap->scrollX = gRegionMap->cursorPosX * 8 - 0x34; + gRegionMap->scrollY = gRegionMap->cursorPosY * 8 - 0x44; + gRegionMap->zoomedCursorPosX = gRegionMap->cursorPosX; + gRegionMap->zoomedCursorPosY = gRegionMap->cursorPosY; + CalcZoomScrollParams(gRegionMap->scrollX, gRegionMap->scrollY, 0x38, 0x48, 0x80, 0x80, 0); + } + break; + case 7: + RegionMap_GetPositionOfCursorWithinMapSection(); + UpdateRegionMapVideoRegs(); + gRegionMap->cursorSprite = NULL; + gRegionMap->playerIconSprite = NULL; + gRegionMap->cursorMovementFrameCounter = 0; + gRegionMap->blinkPlayerIcon = FALSE; + if (gRegionMap->bgManaged) + { + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_SCREENSIZE, 2); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_CHARBASEINDEX, gRegionMap->charBaseIdx); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_MAPBASEINDEX, gRegionMap->mapBaseIdx); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_WRAPAROUND, 1); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_PALETTEMODE, 1); + } + gRegionMap->initStep++; + return FALSE; + default: + return FALSE; } gRegionMap->initStep++; return TRUE;