From 8853588af07169ac61a5fe22ab928d94c92a05ea Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 8 Apr 2020 16:24:30 -0400 Subject: [PATCH] Sync digit_obj_util --- include/digit_obj_util.h | 26 +++ include/rom_8034C54.h | 26 --- ld_script.txt | 4 +- src/battle_bg.c | 19 ++ src/berry_crush.c | 44 ++-- src/digit_obj_util.c | 450 ++++++++++++++++++++++++++++++++++++++ src/pokemon_jump.c | 28 +-- src/rom_8034C54.c | 453 --------------------------------------- src/rom_81520A8.c | 4 +- sym_bss.txt | 2 +- sym_ewram.txt | 2 +- 11 files changed, 537 insertions(+), 521 deletions(-) create mode 100644 include/digit_obj_util.h delete mode 100644 include/rom_8034C54.h create mode 100644 src/digit_obj_util.c delete mode 100644 src/rom_8034C54.c diff --git a/include/digit_obj_util.h b/include/digit_obj_util.h new file mode 100644 index 000000000..aca97e2c7 --- /dev/null +++ b/include/digit_obj_util.h @@ -0,0 +1,26 @@ +#ifndef GUARD_DIGIT_OBJ_UTIL_H +#define GUARD_DIGIT_OBJ_UTIL_H + +struct DigitObjUtilTemplate +{ + u8 strConvMode:2; + u8 shape:2; + u8 size:2; + u8 priority:2; + u8 oamCount; + u8 xDelta; + s16 x; + s16 y; + const struct SpriteSheet *spriteSheet; + const struct SpritePalette *spritePal; +}; + +bool32 DigitObjUtil_Init(u32 count); +void DigitObjUtil_Free(void); +bool32 DigitObjUtil_CreatePrinter(u32 id, s32 num, const struct DigitObjUtilTemplate *template); +void DigitObjUtil_PrintNumOn(u32 id, s32 arg1); +void DigitObjUtil_DeletePrinter(u32 id); +void DigitObjUtil_HideOrShow(u32 id, bool32 arg1); +u8 GetTilesPerImage(u32 shape, u32 size); + +#endif // GUARD_DIGIT_OBJ_UTIL_H diff --git a/include/rom_8034C54.h b/include/rom_8034C54.h deleted file mode 100644 index 4da324dd1..000000000 --- a/include/rom_8034C54.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef GUARD_ROM_8034C54_H -#define GUARD_ROM_8034C54_H - -struct UnkStruct3 -{ - u8 field_0_0:2; - u8 shape:2; - u8 size:2; - u8 priority:2; - u8 field_1; - u8 xDelta; - s16 x; - s16 y; - const struct SpriteSheet *spriteSheet; - const struct SpritePalette *spritePal; -}; - -bool32 sub_8034C54(u32 count); -void sub_8034CC8(void); -bool32 sub_8034D14(u32 id, s32 arg1, const struct UnkStruct3 *arg2); -void sub_8035044(u32 id, s32 arg1); -void sub_80353DC(u32 id); -void sub_803547C(u32 id, bool32 arg1); -u8 sub_80355F8(u32 shape, u32 size); - -#endif // GUARD_ROM_8034C54_H diff --git a/ld_script.txt b/ld_script.txt index 1c4db64cc..c98eb6442 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -81,7 +81,7 @@ SECTIONS { src/main_menu.o(.text); src/battle_controllers.o(.text); src/decompress.o(.text); - src/rom_8034C54.o(.text); + src/digit_obj_util.o(.text); src/battle_bg.o(.text); src/battle_main.o(.text); src/battle_util.o(.text); @@ -463,7 +463,7 @@ SECTIONS { src/rtc.o(.rodata); src/main_menu.o(.rodata); src/battle_controllers.o(.rodata); - src/rom_8034C54.o(.rodata); + src/digit_obj_util.o(.rodata); src/data.o(.rodata); src/battle_bg.o(.rodata); src/battle_main.o(.rodata); diff --git a/src/battle_bg.c b/src/battle_bg.c index 01d05e68d..00c504bfd 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -691,6 +691,25 @@ static const struct BattleBackground gBattleTerrainTable[] = }, }; +static void sub_8035648(void); + +// Unused +static void sub_8035608(void) +{ + u8 spriteId; + + ResetSpriteData(); + spriteId = CreateSprite(&gUnknown_0831AC88, 0, 0, 0); + gSprites[spriteId].invisible = TRUE; + SetMainCallback2(sub_8035648); +} + +static void sub_8035648(void) +{ + AnimateSprites(); + BuildOamBuffer(); +} + void BattleInitBgsAndWindows(void) { ResetBgsAndClearDma3BusyFlags(0); diff --git a/src/berry_crush.c b/src/berry_crush.c index 542888631..0985fce9a 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -21,7 +21,7 @@ #include "palette.h" #include "pokemon_jump.h" #include "random.h" -#include "rom_8034C54.h" +#include "digit_obj_util.h" #include "save.h" #include "scanline_effect.h" #include "script.h" @@ -714,14 +714,14 @@ static const struct SpriteTemplate gUnknown_082F436C = .callback = SpriteCallbackDummy }; -static const struct UnkStruct3 gUnknown_082F4384[] = +static const struct DigitObjUtilTemplate gUnknown_082F4384[] = { { - .field_0_0 = 1, + .strConvMode = 1, .shape = 2, .size = 0, .priority = 0, - .field_1 = 2, + .oamCount = 2, .xDelta = 8, .x = 156, .y = 0, @@ -729,11 +729,11 @@ static const struct UnkStruct3 gUnknown_082F4384[] = .spritePal = gUnknown_082F422C, }, { - .field_0_0 = 0, + .strConvMode = 0, .shape = 2, .size = 0, .priority = 0, - .field_1 = 2, + .oamCount = 2, .xDelta = 8, .x = 180, .y = 0, @@ -741,11 +741,11 @@ static const struct UnkStruct3 gUnknown_082F4384[] = .spritePal = gUnknown_082F422C, }, { - .field_0_0 = 0, + .strConvMode = 0, .shape = 2, .size = 0, .priority = 0, - .field_1 = 2, + .oamCount = 2, .xDelta = 8, .x = 204, .y = 0, @@ -1036,7 +1036,7 @@ int sub_802104C(void) case 1: CpuFill16(0, (void *)OAM, OAM_SIZE); gReservedSpritePaletteCount = 0; - sub_8034C54(3); + DigitObjUtil_Init(3); break; case 2: ResetPaletteFade(); @@ -1165,7 +1165,7 @@ int sub_802130C(void) case 6: DestroyWirelessStatusIndicatorSprite(); sub_8022960(var0); - sub_8034CC8(); + DigitObjUtil_Free(); break; case 7: var0->unkC = 0; @@ -1701,18 +1701,18 @@ void ShowBerryCrushRankings(void) void sub_8022524(struct BerryCrushGame_138 *r4, u16 r1) { sub_8021944(r4, r1); - sub_8035044(0, r4->unk4); - sub_8035044(1, r4->unk6); - sub_8035044(2, r4->unk8); + DigitObjUtil_PrintNumOn(0, r4->unk4); + DigitObjUtil_PrintNumOn(1, r4->unk6); + DigitObjUtil_PrintNumOn(2, r4->unk8); } void sub_8022554(struct BerryCrushGame_138 *r0) { r0->unk78[0]->invisible = TRUE; r0->unk78[1]->invisible = TRUE; - sub_803547C(2, 1); - sub_803547C(1, 1); - sub_803547C(0, 1); + DigitObjUtil_HideOrShow(2, 1); + DigitObjUtil_HideOrShow(1, 1); + DigitObjUtil_HideOrShow(0, 1); } void sub_8022588(struct BerryCrushGame *r5) @@ -1855,9 +1855,9 @@ void sub_8022730(struct BerryCrushGame *r6) r6->unk138.unk78[r5]->invisible = FALSE; r6->unk138.unk78[r5]->animPaused = FALSE; } - sub_8034D14(0, 0, &gUnknown_082F4384[0]); - sub_8034D14(1, 0, &gUnknown_082F4384[1]); - sub_8034D14(2, 0, &gUnknown_082F4384[2]); + DigitObjUtil_CreatePrinter(0, 0, &gUnknown_082F4384[0]); + DigitObjUtil_CreatePrinter(1, 0, &gUnknown_082F4384[1]); + DigitObjUtil_CreatePrinter(2, 0, &gUnknown_082F4384[2]); if (r6->unk12 == 1) sub_8022554(&r6->unk138); } @@ -1875,9 +1875,9 @@ void sub_8022960(struct BerryCrushGame *r5) FreeSpritePaletteByTag(1); for (; r4 < ARRAY_COUNT(r5->unk138.unk78); ++r4) DestroySprite(r5->unk138.unk78[r4]); - sub_80353DC(2); - sub_80353DC(1); - sub_80353DC(0); + DigitObjUtil_DeletePrinter(2); + DigitObjUtil_DeletePrinter(1); + DigitObjUtil_DeletePrinter(0); for (r4 = 0; r4 < ARRAY_COUNT(r5->unk138.unk4C); ++r4) DestroySprite(r5->unk138.unk4C[r4]); for (r4 = 0; r4 < r5->unk9; ++r4) diff --git a/src/digit_obj_util.c b/src/digit_obj_util.c new file mode 100644 index 000000000..fe5d49e69 --- /dev/null +++ b/src/digit_obj_util.c @@ -0,0 +1,450 @@ +#include "global.h" +#include "digit_obj_util.h" +#include "malloc.h" +#include "decompress.h" +#include "main.h" +#include "battle_main.h" + +struct DigitPrinter +{ + bool8 isActive; + u8 firstOamId; + u8 strConvMode; + u8 oamCount; + u8 palTagIndex; + u8 size; + u8 shape; + u8 priority; + u8 xDelta; + u8 tilesPerImage; + u16 tileStart; + s16 x; + s16 y; + u16 tileTag; + u16 palTag; + u32 pow10; + s32 lastPrinted; +}; + +struct DigitPrinterAlloc +{ + u32 count; + struct DigitPrinter *array; +}; + +// this file's functions +static u8 GetFirstOamId(u8 oamCount);; +static void CopyWorkToOam(struct DigitPrinter *objWork); +static void DrawNumObjsLeadingZeros(struct DigitPrinter *objWork, s32 num, bool32 sign); +static void DrawNumObjsMinusInFront(struct DigitPrinter *objWork, s32 num, bool32 sign); +static void DrawNumObjsMinusInBack(struct DigitPrinter *objWork, s32 num, bool32 sign); +static bool32 SharesTileWithAnyActive(u32 id); +static bool32 SharesPalWithAnyActive(u32 id); + +// ewram +static EWRAM_DATA struct DigitPrinterAlloc *sOamWork = {0}; + +// const rom data +static const u8 sTilesPerImage[4][4] = +{ + [ST_OAM_SQUARE] = { + [ST_OAM_SIZE_0] = 0x01, // SPRITE_SIZE_8x8 + [ST_OAM_SIZE_1] = 0x04, // SPRITE_SIZE_16x16 + [ST_OAM_SIZE_2] = 0x10, // SPRITE_SIZE_32x32 + [ST_OAM_SIZE_3] = 0x40 // SPRITE_SIZE_64x64 + }, + [ST_OAM_H_RECTANGLE] = { + [ST_OAM_SIZE_0] = 0x02, // SPRITE_SIZE_16x8 + [ST_OAM_SIZE_1] = 0x04, // SPRITE_SIZE_32x8 + [ST_OAM_SIZE_2] = 0x08, // SPRITE_SIZE_32x16 + [ST_OAM_SIZE_3] = 0x20 // SPRITE_SIZE_64x32 + }, + [ST_OAM_V_RECTANGLE] = { + [ST_OAM_SIZE_0] = 0x02, // SPRITE_SIZE_8x16 + [ST_OAM_SIZE_1] = 0x04, // SPRITE_SIZE_8x32 + [ST_OAM_SIZE_2] = 0x08, // SPRITE_SIZE_16x32 + [ST_OAM_SIZE_3] = 0x20 // SPRITE_SIZE_32x64 + } +}; + +// code +bool32 DigitObjUtil_Init(u32 count) +{ + u32 i; + + if (sOamWork != NULL) + DigitObjUtil_Free(); + + sOamWork = Alloc(sizeof(*sOamWork)); + if (sOamWork == NULL) + return FALSE; + + sOamWork->array = Alloc(sizeof(struct DigitPrinter) * count); + if (sOamWork->array == NULL) + { + Free(sOamWork); + return FALSE; + } + + sOamWork->count = count; + for (i = 0; i < count; i++) + { + sOamWork->array[i].isActive = FALSE; + sOamWork->array[i].firstOamId = 0xFF; + } + + return TRUE; +} + +void DigitObjUtil_Free(void) +{ + if (sOamWork != NULL) + { + if (sOamWork->array != NULL) + { + u32 i; + + for (i = 0; i < sOamWork->count; i++) + DigitObjUtil_DeletePrinter(i); + + Free(sOamWork->array); + } + + FREE_AND_SET_NULL(sOamWork); + } +} + +bool32 DigitObjUtil_CreatePrinter(u32 id, s32 num, const struct DigitObjUtilTemplate *template) +{ + u32 i; + + if (sOamWork == NULL) + return FALSE; + if (sOamWork->array[id].isActive) + return FALSE; + + sOamWork->array[id].firstOamId = GetFirstOamId(template->oamCount); + if (sOamWork->array[id].firstOamId == 0xFF) + return FALSE; + + sOamWork->array[id].tileStart = GetSpriteTileStartByTag(template->spriteSheet->tag); + if (sOamWork->array[id].tileStart == 0xFFFF) + { + if (template->spriteSheet->size != 0) + { + sOamWork->array[id].tileStart = LoadSpriteSheet(template->spriteSheet); + } + else + { + struct CompressedSpriteSheet compSpriteSheet; + + compSpriteSheet = *(struct CompressedSpriteSheet*)(template->spriteSheet); + compSpriteSheet.size = GetDecompressedDataSize(template->spriteSheet->data); + sOamWork->array[id].tileStart = LoadCompressedSpriteSheet(&compSpriteSheet); + } + + if (sOamWork->array[id].tileStart == 0xFFFF) + return FALSE; + } + + sOamWork->array[id].palTagIndex = IndexOfSpritePaletteTag(template->spritePal->tag); + if (sOamWork->array[id].palTagIndex == 0xFF) + sOamWork->array[id].palTagIndex = LoadSpritePalette(template->spritePal); + + sOamWork->array[id].strConvMode = template->strConvMode; + sOamWork->array[id].oamCount = template->oamCount; + sOamWork->array[id].x = template->x; + sOamWork->array[id].y = template->y; + sOamWork->array[id].shape = template->shape; + sOamWork->array[id].size = template->size; + sOamWork->array[id].priority = template->priority; + sOamWork->array[id].xDelta = template->xDelta; + sOamWork->array[id].tilesPerImage = GetTilesPerImage(template->shape, template->size); + sOamWork->array[id].tileTag = template->spriteSheet->tag; + sOamWork->array[id].palTag = template->spritePal->tag; + sOamWork->array[id].isActive = TRUE; + + // Decimal left shift + sOamWork->array[id].pow10 = 1; + for (i = 1; i < template->oamCount; i++) + sOamWork->array[id].pow10 *= 10; + + CopyWorkToOam(&sOamWork->array[id]); + DigitObjUtil_PrintNumOn(id, num); + + return TRUE; +} + +static void CopyWorkToOam(struct DigitPrinter *objWork) +{ + u32 i; + u32 oamId = objWork->firstOamId; + u32 x = objWork->x; + u32 oamCount = objWork->oamCount + 1; + + CpuFill16(0, &gMain.oamBuffer[oamId], sizeof(struct OamData) * oamCount); + for (i = 0, oamId = objWork->firstOamId; i < oamCount; i++, oamId++) + { + gMain.oamBuffer[oamId].y = objWork->y; + gMain.oamBuffer[oamId].x = x; + gMain.oamBuffer[oamId].shape = objWork->shape; + gMain.oamBuffer[oamId].size = objWork->size; + gMain.oamBuffer[oamId].tileNum = objWork->tileStart; + gMain.oamBuffer[oamId].priority = objWork->priority; + gMain.oamBuffer[oamId].paletteNum = objWork->palTagIndex; + + x += objWork->xDelta; + } + + oamId--; + gMain.oamBuffer[oamId].x = objWork->x - objWork->xDelta; + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; + gMain.oamBuffer[oamId].tileNum = objWork->tileStart + (objWork->tilesPerImage * 10); +} + +void DigitObjUtil_PrintNumOn(u32 id, s32 num) +{ + bool32 sign; + + if (sOamWork == NULL) + return; + if (!sOamWork->array[id].isActive) + return; + + sOamWork->array[id].lastPrinted = num; + if (num < 0) + { + sign = TRUE; + num *= -1; + } + else + { + sign = FALSE; + } + + switch (sOamWork->array[id].strConvMode) + { + case 0: + default: + DrawNumObjsLeadingZeros(&sOamWork->array[id], num, sign); + break; + case 1: + DrawNumObjsMinusInFront(&sOamWork->array[id], num, sign); + break; + case 2: + DrawNumObjsMinusInBack(&sOamWork->array[id], num, sign); + break; + } +} + +static void DrawNumObjsLeadingZeros(struct DigitPrinter *objWork, s32 num, bool32 sign) +{ + u32 pow10 = objWork->pow10; + u32 oamId = objWork->firstOamId; + + while (pow10 != 0) + { + u32 digit = num / pow10; + num -= (digit * pow10); + pow10 /= 10; + + gMain.oamBuffer[oamId].tileNum = (digit * objWork->tilesPerImage) + objWork->tileStart; + oamId++; + } + + if (sign) + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_OFF; + else + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; +} + +static void DrawNumObjsMinusInFront(struct DigitPrinter *objWork, s32 num, bool32 sign) +{ + u32 pow10 = objWork->pow10; + static int oamId; + static int curDigit; + static int firstDigit; + + oamId = objWork->firstOamId; + curDigit = 0; + firstDigit = -1; + + while (pow10 != 0) + { + u32 digit = num / pow10; + num -= (digit * pow10); + pow10 /= 10; + + if (digit != 0 || firstDigit != -1 || pow10 == 0) + { + gMain.oamBuffer[oamId].tileNum = (digit * objWork->tilesPerImage) + objWork->tileStart; + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_OFF; + + if (firstDigit == -1) + firstDigit = curDigit; + } + else + { + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; + } + + oamId++; + curDigit++; + } + + if (sign) + { + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_OFF; + gMain.oamBuffer[oamId].x = objWork->x + ((firstDigit - 1) * objWork->xDelta); + } + else + { + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; + } +} + +static void DrawNumObjsMinusInBack(struct DigitPrinter *objWork, s32 num, bool32 sign) +{ + u32 pow10 = objWork->pow10; + u32 oamId = objWork->firstOamId; + bool32 printingDigits = FALSE; + s32 nsprites = 0; + + while (pow10 != 0) + { + u32 digit = num / pow10; + num -= (digit * pow10); + pow10 /= 10; + + if (digit != 0 || printingDigits || pow10 == 0) + { + printingDigits = TRUE; + gMain.oamBuffer[oamId].tileNum = (digit * objWork->tilesPerImage) + objWork->tileStart; + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_OFF; + + oamId++; + nsprites++; + } + } + + while (nsprites < objWork->oamCount) + { + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; + oamId++; + nsprites++; + } + + if (sign) + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_OFF; + else + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; +} + +void DigitObjUtil_DeletePrinter(u32 id) +{ + s32 oamId, oamCount, i; + + if (sOamWork == NULL) + return; + if (!sOamWork->array[id].isActive) + return; + + oamCount = sOamWork->array[id].oamCount + 1; + oamId = sOamWork->array[id].firstOamId; + + for (i = 0; i < oamCount; i++, oamId++) + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; + + if (!SharesTileWithAnyActive(id)) + FreeSpriteTilesByTag(sOamWork->array[id].tileTag); + if (!SharesPalWithAnyActive(id)) + FreeSpritePaletteByTag(sOamWork->array[id].palTag); + + sOamWork->array[id].isActive = FALSE; +} + +void DigitObjUtil_HideOrShow(u32 id, bool32 hide) +{ + s32 oamId, oamCount, i; + + if (sOamWork == NULL) + return; + if (!sOamWork->array[id].isActive) + return; + + oamCount = sOamWork->array[id].oamCount + 1; + oamId = sOamWork->array[id].firstOamId; + if (hide) + { + for (i = 0; i < oamCount; i++, oamId++) + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; + } + else + { + for (i = 0; i < oamCount; i++, oamId++) + gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_OFF; + + DigitObjUtil_PrintNumOn(id, sOamWork->array[id].lastPrinted); + } +} + +static u8 GetFirstOamId(u8 oamCount) +{ + u32 i; + u16 firstOamId = 64; + + for (i = 0; i < sOamWork->count; i++) + { + if (!sOamWork->array[i].isActive) + { + if (sOamWork->array[i].firstOamId != 0xFF && sOamWork->array[i].oamCount <= oamCount) + return sOamWork->array[i].firstOamId; + } + else + { + firstOamId += 1 + sOamWork->array[i].oamCount; + } + } + + if (firstOamId + oamCount + 1 > 128) + return 0xFF; + else + return firstOamId; +} + +static bool32 SharesTileWithAnyActive(u32 id) +{ + u32 i; + + for (i = 0; i < sOamWork->count; i++) + { + if (sOamWork->array[i].isActive && i != id + && sOamWork->array[i].tileTag == sOamWork->array[id].tileTag) + { + return TRUE; + } + } + + return FALSE; +} + +static bool32 SharesPalWithAnyActive(u32 id) +{ + u32 i; + + for (i = 0; i < sOamWork->count; i++) + { + if (sOamWork->array[i].isActive && i != id + && sOamWork->array[i].palTag == sOamWork->array[id].palTag) + { + return TRUE; + } + } + + return FALSE; +} + +u8 GetTilesPerImage(u32 shape, u32 size) +{ + return sTilesPerImage[shape][size]; +} diff --git a/src/pokemon_jump.c b/src/pokemon_jump.c index 6c76b15a6..51520cae8 100755 --- a/src/pokemon_jump.c +++ b/src/pokemon_jump.c @@ -14,7 +14,7 @@ #include "menu.h" #include "palette.h" #include "random.h" -#include "rom_8034C54.h" +#include "digit_obj_util.h" #include "save.h" #include "script.h" #include "sound.h" @@ -2831,7 +2831,7 @@ static void sub_802D074(struct PokemonJump2 *arg0) static void sub_802D0AC(void) { FreeAllWindowBuffers(); - sub_8034CC8(); + DigitObjUtil_Free(); } static void sub_802D0BC(struct PokemonJump2 *arg0) @@ -3515,37 +3515,37 @@ static int sub_802DCCC(u8 flags) static void sub_802DD08(void) { - struct UnkStruct3 unkStruct; - struct UnkStruct3 *ptr = &unkStruct; // This temp variable is needed to match, don't ask me why. + struct DigitObjUtilTemplate template; + struct DigitObjUtilTemplate *ptr = &template; // This temp variable is needed to match, don't ask me why. ptr->shape = SPRITE_SHAPE(8x8); ptr->size = SPRITE_SIZE(8x8); - ptr->field_0_0 = 0; + ptr->strConvMode = 0; ptr->priority = 1; - ptr->field_1 = 5; + ptr->oamCount = 5; ptr->xDelta = 8; ptr->x = 108; ptr->y = 6; ptr->spriteSheet = (void*) &gUnknown_082FE1EC; ptr->spritePal = &gUnknown_082FE1F4; - sub_8034C54(2); - sub_8034D14(0, 0, ptr); + DigitObjUtil_Init(2); + DigitObjUtil_CreatePrinter(0, 0, ptr); - unkStruct.field_1 = 4; - unkStruct.x = 30; - unkStruct.y = 6; - sub_8034D14(1, 0, &unkStruct); + template.oamCount = 4; + template.x = 30; + template.y = 6; + DigitObjUtil_CreatePrinter(1, 0, &template); } static void sub_802DD64(int arg0) { - sub_8035044(0, arg0); + DigitObjUtil_PrintNumOn(0, arg0); } static void sub_802DD74(u16 arg0) { - sub_8035044(1, arg0); + DigitObjUtil_PrintNumOn(1, arg0); } static void sub_802DD88(u8 multiplayerId) diff --git a/src/rom_8034C54.c b/src/rom_8034C54.c deleted file mode 100644 index 029696526..000000000 --- a/src/rom_8034C54.c +++ /dev/null @@ -1,453 +0,0 @@ -#include "global.h" -#include "rom_8034C54.h" -#include "malloc.h" -#include "decompress.h" -#include "main.h" -#include "battle_main.h" - -struct UnkStruct2 -{ - bool8 isActive; - u8 firstOamId; - u8 field_2; - u8 oamCount; - u8 palTagIndex; - u8 size; - u8 shape; - u8 priority; - u8 xDelta; - u8 field_9; - u16 tileStart; - s16 x; - s16 y; - u16 tileTag; - u16 palTag; - u32 field_14; - s32 field_18; -}; - -struct UnkStruct1 -{ - u32 count; - struct UnkStruct2 *array; -}; - -// this file's functions -static u8 sub_8035518(u8 arg0);; -static void sub_8034EFC(struct UnkStruct2 *arg0); -static void sub_80350B0(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2); -static void sub_8035164(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2); -static void sub_80352C0(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2); -static bool32 SharesTileWithAnyActive(u32 id); -static bool32 SharesPalWithAnyActive(u32 id); -static void sub_8035648(void); - -// iwram -static s32 gUnknown_03000DD4; -static s32 gUnknown_03000DD8; -static s32 gUnknown_03000DDC; - -// ewram -static EWRAM_DATA struct UnkStruct1 *gUnknown_02022E10 = {0}; - -// const rom data -static const u8 gUnknown_082FF1C8[][4] = -{ - {0x01, 0x04, 0x10, 0x40}, - {0x02, 0x04, 0x08, 0x20}, - {0x02, 0x04, 0x08, 0x20}, - {0x00, 0x00, 0x00, 0x00} -}; - -// code -bool32 sub_8034C54(u32 count) -{ - u32 i; - - if (gUnknown_02022E10 != NULL) - sub_8034CC8(); - - gUnknown_02022E10 = Alloc(sizeof(*gUnknown_02022E10)); - if (gUnknown_02022E10 == NULL) - return FALSE; - - gUnknown_02022E10->array = Alloc(sizeof(struct UnkStruct2) * count); - if (gUnknown_02022E10->array == NULL) - { - Free(gUnknown_02022E10); - return FALSE; - } - - gUnknown_02022E10->count = count; - for (i = 0; i < count; i++) - { - gUnknown_02022E10->array[i].isActive = FALSE; - gUnknown_02022E10->array[i].firstOamId = 0xFF; - } - - return TRUE; -} - -void sub_8034CC8(void) -{ - if (gUnknown_02022E10 != NULL) - { - if (gUnknown_02022E10->array != NULL) - { - u32 i; - - for (i = 0; i < gUnknown_02022E10->count; i++) - sub_80353DC(i); - - Free(gUnknown_02022E10->array); - } - - FREE_AND_SET_NULL(gUnknown_02022E10); - } -} - -bool32 sub_8034D14(u32 id, s32 arg1, const struct UnkStruct3 *arg2) -{ - u32 i; - - if (gUnknown_02022E10 == NULL) - return FALSE; - if (gUnknown_02022E10->array[id].isActive) - return FALSE; - - gUnknown_02022E10->array[id].firstOamId = sub_8035518(arg2->field_1); - if (gUnknown_02022E10->array[id].firstOamId == 0xFF) - return FALSE; - - gUnknown_02022E10->array[id].tileStart = GetSpriteTileStartByTag(arg2->spriteSheet->tag); - if (gUnknown_02022E10->array[id].tileStart == 0xFFFF) - { - if (arg2->spriteSheet->size != 0) - { - gUnknown_02022E10->array[id].tileStart = LoadSpriteSheet(arg2->spriteSheet); - } - else - { - struct CompressedSpriteSheet compSpriteSheet; - - compSpriteSheet = *(struct CompressedSpriteSheet*)(arg2->spriteSheet); - compSpriteSheet.size = GetDecompressedDataSize(arg2->spriteSheet->data); - gUnknown_02022E10->array[id].tileStart = LoadCompressedSpriteSheet(&compSpriteSheet); - } - - if (gUnknown_02022E10->array[id].tileStart == 0xFFFF) - return FALSE; - } - - gUnknown_02022E10->array[id].palTagIndex = IndexOfSpritePaletteTag(arg2->spritePal->tag); - if (gUnknown_02022E10->array[id].palTagIndex == 0xFF) - gUnknown_02022E10->array[id].palTagIndex = LoadSpritePalette(arg2->spritePal); - - gUnknown_02022E10->array[id].field_2 = arg2->field_0_0; - gUnknown_02022E10->array[id].oamCount = arg2->field_1; - gUnknown_02022E10->array[id].x = arg2->x; - gUnknown_02022E10->array[id].y = arg2->y; - gUnknown_02022E10->array[id].shape = arg2->shape; - gUnknown_02022E10->array[id].size = arg2->size; - gUnknown_02022E10->array[id].priority = arg2->priority; - gUnknown_02022E10->array[id].xDelta = arg2->xDelta; - gUnknown_02022E10->array[id].field_9 = sub_80355F8(arg2->shape, arg2->size); - gUnknown_02022E10->array[id].tileTag = arg2->spriteSheet->tag; - gUnknown_02022E10->array[id].palTag = arg2->spritePal->tag; - gUnknown_02022E10->array[id].isActive = TRUE; - gUnknown_02022E10->array[id].field_14 = 1; - - for (i = 1; i < arg2->field_1; i++) - gUnknown_02022E10->array[id].field_14 *= 10; - - sub_8034EFC(&gUnknown_02022E10->array[id]); - sub_8035044(id, arg1); - - return TRUE; -} - -static void sub_8034EFC(struct UnkStruct2 *arg0) -{ - u32 i; - u32 oamId = arg0->firstOamId; - u32 x = arg0->x; - u32 oamCount = arg0->oamCount + 1; - - CpuFill16(0, &gMain.oamBuffer[oamId], sizeof(struct OamData) * oamCount); - for (i = 0, oamId = arg0->firstOamId; i < oamCount; i++, oamId++) - { - gMain.oamBuffer[oamId].y = arg0->y; - gMain.oamBuffer[oamId].x = x; - gMain.oamBuffer[oamId].shape = arg0->shape; - gMain.oamBuffer[oamId].size = arg0->size; - gMain.oamBuffer[oamId].tileNum = arg0->tileStart; - gMain.oamBuffer[oamId].priority = arg0->priority; - gMain.oamBuffer[oamId].paletteNum = arg0->palTagIndex; - - x += arg0->xDelta; - } - - oamId--; - gMain.oamBuffer[oamId].x = arg0->x - arg0->xDelta; - gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; - gMain.oamBuffer[oamId].tileNum = arg0->tileStart + (arg0->field_9 * 10); -} - -void sub_8035044(u32 id, s32 arg1) -{ - bool32 r2; - - if (gUnknown_02022E10 == NULL) - return; - if (!gUnknown_02022E10->array[id].isActive) - return; - - gUnknown_02022E10->array[id].field_18 = arg1; - if (arg1 < 0) - { - r2 = TRUE; - arg1 *= -1; - } - else - { - r2 = FALSE; - } - - switch (gUnknown_02022E10->array[id].field_2) - { - case 0: - default: - sub_80350B0(&gUnknown_02022E10->array[id], arg1, r2); - break; - case 1: - sub_8035164(&gUnknown_02022E10->array[id], arg1, r2); - break; - case 2: - sub_80352C0(&gUnknown_02022E10->array[id], arg1, r2); - break; - } -} - -static void sub_80350B0(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2) -{ - u32 r5 = arg0->field_14; - u32 oamId = arg0->firstOamId; - - while (r5 != 0) - { - u32 r4 = arg1 / r5; - arg1 -= (r4 * r5); - r5 /= 10; - - gMain.oamBuffer[oamId].tileNum = (r4 * arg0->field_9) + arg0->tileStart; - oamId++; - } - - if (arg2) - gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_OFF; - else - gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; -} - -static void sub_8035164(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2) -{ - u32 r5 = arg0->field_14; - gUnknown_03000DD4 = arg0->firstOamId; - gUnknown_03000DD8 = 0; - gUnknown_03000DDC = -1; - - while (r5 != 0) - { - u32 r4 = arg1 / r5; - arg1 -= (r4 * r5); - r5 /= 10; - - if (r4 != 0 || gUnknown_03000DDC != -1 || r5 == 0) - { - gMain.oamBuffer[gUnknown_03000DD4].tileNum = (r4 * arg0->field_9) + arg0->tileStart; - gMain.oamBuffer[gUnknown_03000DD4].affineMode = ST_OAM_AFFINE_OFF; - - if (gUnknown_03000DDC == -1) - gUnknown_03000DDC = gUnknown_03000DD8; - } - else - { - gMain.oamBuffer[gUnknown_03000DD4].affineMode = ST_OAM_AFFINE_ERASE; - } - - gUnknown_03000DD4++; - gUnknown_03000DD8++; - } - - if (arg2) - { - gMain.oamBuffer[gUnknown_03000DD4].affineMode = ST_OAM_AFFINE_OFF; - gMain.oamBuffer[gUnknown_03000DD4].x = arg0->x + ((gUnknown_03000DDC - 1) * arg0->xDelta); - } - else - { - gMain.oamBuffer[gUnknown_03000DD4].affineMode = ST_OAM_AFFINE_ERASE; - } -} - -static void sub_80352C0(struct UnkStruct2 *arg0, s32 arg1, bool32 arg2) -{ - u32 r5 = arg0->field_14; - u32 oamId = arg0->firstOamId; - u32 var_28 = 0; - s32 r9 = 0; - - while (r5 != 0) - { - u32 r4 = arg1 / r5; - arg1 -= (r4 * r5); - r5 /= 10; - - if (r4 != 0 || var_28 != 0 || r5 == 0) - { - var_28 = 1; - gMain.oamBuffer[oamId].tileNum = (r4 * arg0->field_9) + arg0->tileStart; - gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_OFF; - - oamId++; - r9++; - } - } - - while (r9 < arg0->oamCount) - { - gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; - oamId++; - r9++; - } - - if (arg2) - gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_OFF; - else - gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; -} - -void sub_80353DC(u32 id) -{ - s32 oamId, oamCount, i; - - if (gUnknown_02022E10 == NULL) - return; - if (!gUnknown_02022E10->array[id].isActive) - return; - - oamCount = gUnknown_02022E10->array[id].oamCount + 1; - oamId = gUnknown_02022E10->array[id].firstOamId; - - for (i = 0; i < oamCount; i++, oamId++) - gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; - - if (!SharesTileWithAnyActive(id)) - FreeSpriteTilesByTag(gUnknown_02022E10->array[id].tileTag); - if (!SharesPalWithAnyActive(id)) - FreeSpritePaletteByTag(gUnknown_02022E10->array[id].palTag); - - gUnknown_02022E10->array[id].isActive = FALSE; -} - -void sub_803547C(u32 id, bool32 arg1) -{ - s32 oamId, oamCount, i; - - if (gUnknown_02022E10 == NULL) - return; - if (!gUnknown_02022E10->array[id].isActive) - return; - - oamCount = gUnknown_02022E10->array[id].oamCount + 1; - oamId = gUnknown_02022E10->array[id].firstOamId; - if (arg1) - { - for (i = 0; i < oamCount; i++, oamId++) - gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_ERASE; - } - else - { - for (i = 0; i < oamCount; i++, oamId++) - gMain.oamBuffer[oamId].affineMode = ST_OAM_AFFINE_OFF; - - sub_8035044(id, gUnknown_02022E10->array[id].field_18); - } -} - -static u8 sub_8035518(u8 arg0) -{ - u32 i; - u16 oamCount = 64; - - for (i = 0; i < gUnknown_02022E10->count; i++) - { - if (!gUnknown_02022E10->array[i].isActive) - { - if (gUnknown_02022E10->array[i].firstOamId != 0xFF && gUnknown_02022E10->array[i].oamCount <= arg0) - return gUnknown_02022E10->array[i].firstOamId; - } - else - { - oamCount += 1 + gUnknown_02022E10->array[i].oamCount; - } - } - - if (oamCount + arg0 + 1 > 128) - return 0xFF; - else - return oamCount; -} - -static bool32 SharesTileWithAnyActive(u32 id) -{ - u32 i; - - for (i = 0; i < gUnknown_02022E10->count; i++) - { - if (gUnknown_02022E10->array[i].isActive && i != id - && gUnknown_02022E10->array[i].tileTag == gUnknown_02022E10->array[id].tileTag) - { - return TRUE; - } - } - - return FALSE; -} - -static bool32 SharesPalWithAnyActive(u32 id) -{ - u32 i; - - for (i = 0; i < gUnknown_02022E10->count; i++) - { - if (gUnknown_02022E10->array[i].isActive && i != id - && gUnknown_02022E10->array[i].palTag == gUnknown_02022E10->array[id].palTag) - { - return TRUE; - } - } - - return FALSE; -} - -u8 sub_80355F8(u32 shape, u32 size) -{ - return gUnknown_082FF1C8[shape][size]; -} - -static void sub_8035608(void) -{ - u8 spriteId; - - ResetSpriteData(); - spriteId = CreateSprite(&gUnknown_0831AC88, 0, 0, 0); - gSprites[spriteId].invisible = TRUE; - SetMainCallback2(sub_8035648); -} - -static void sub_8035648(void) -{ - AnimateSprites(); - BuildOamBuffer(); -} diff --git a/src/rom_81520A8.c b/src/rom_81520A8.c index f6d14d49c..8b10d44d0 100644 --- a/src/rom_81520A8.c +++ b/src/rom_81520A8.c @@ -2,7 +2,7 @@ #include "rom_81520A8.h" #include "malloc.h" #include "main.h" -#include "rom_8034C54.h" +#include "digit_obj_util.h" static EWRAM_DATA struct { @@ -138,7 +138,7 @@ static bool32 sub_81523F4(struct UnkStruct_81520A8 *structPtr, u8 arg1) return FALSE; structPtr->unk18 = arg1; - structPtr->tileNum = (sub_80355F8(structPtr->oam.shape, structPtr->oam.size) * arg1) + tileStart; + structPtr->tileNum = (GetTilesPerImage(structPtr->oam.shape, structPtr->oam.size) * arg1) + tileStart; return TRUE; } diff --git a/sym_bss.txt b/sym_bss.txt index 1c58146f6..aad8c8f14 100644 --- a/sym_bss.txt +++ b/sym_bss.txt @@ -14,7 +14,7 @@ .include "src/dodrio_berry_picking.o" .include "src/rtc.o" .include "src/main_menu.o" - .include "src/rom_8034C54.o" + .include "src/digit_obj_util.o" .include "src/egg_hatch.o" .include "src/berry_blender.o" .include "src/play_time.o" diff --git a/sym_ewram.txt b/sym_ewram.txt index c5cb123c5..d00f7953c 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -23,7 +23,7 @@ .include "src/pokemon_jump.o" .include "src/main_menu.o" .include "src/battle_controllers.o" - .include "src/rom_8034C54.o" + .include "src/digit_obj_util.o" .include "src/battle_main.o" .include "src/pokemon.o" .include "src/random.o"