From f600aff71140b34e4b3c210ef27ec1b9704a6f45 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 17 Jun 2020 03:42:10 -0400 Subject: Rename rom_81520A8 --- include/oam_util.h | 33 ++++++++ include/rom_81520A8.h | 33 -------- ld_script.txt | 2 +- src/hall_of_fame.c | 2 +- src/oam_util.c | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/rom_81520A8.c | 218 -------------------------------------------------- sym_ewram.txt | 2 +- 7 files changed, 254 insertions(+), 254 deletions(-) create mode 100644 include/oam_util.h delete mode 100644 include/rom_81520A8.h create mode 100644 src/oam_util.c delete mode 100644 src/rom_81520A8.c diff --git a/include/oam_util.h b/include/oam_util.h new file mode 100644 index 000000000..24e166c93 --- /dev/null +++ b/include/oam_util.h @@ -0,0 +1,33 @@ +#ifndef GUARD_OAM_UTIL_H +#define GUARD_OAM_UTIL_H + +struct OamUtil +{ + struct OamData oam; + s16 x; + s16 y; + s16 xDelta; + s16 yDelta; + u16 tileTag; + u16 palTag; + u16 tileNum; + u8 id; + u8 filler; + u8 animNum; + u8 active:1; + u8 allowUpdates:1; + u8 dummied:1; + u8 priority:2; + s16 data[8]; + void (*callback)(struct OamUtil *); +}; + +bool32 OamUtil_Init(u8 count); +bool32 OamUtil_Free(void); +bool32 OamUtil_Update(void); +u8 OamUtil_SetCallback(u8 id, void (*func)(struct OamUtil *)); +u8 OamUtil_SetData(u8 id, u8 dataArrayId, s16 dataValue); +u8 OamUtil_AddNew(const struct OamData *oam, u16 tileTag, u16 palTag, s16 x, s16 y, u8 animNum, u8 priority); +u8 OamUtil_Remove(u8 id); + +#endif // GUARD_OAM_UTIL_H diff --git a/include/rom_81520A8.h b/include/rom_81520A8.h deleted file mode 100644 index 9ad299197..000000000 --- a/include/rom_81520A8.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef GUARD_ROM_81520A8_H -#define GUARD_ROM_81520A8_H - -struct OamUtil -{ - struct OamData oam; - s16 x; - s16 y; - s16 xDelta; - s16 yDelta; - u16 tileTag; - u16 palTag; - u16 tileNum; - u8 id; - u8 filler; - u8 animNum; - u8 active:1; - u8 allowUpdates:1; - u8 dummied:1; - u8 priority:2; - s16 data[8]; - void (*callback)(struct OamUtil *); -}; - -bool32 OamUtil_Init(u8 count); -bool32 OamUtil_Free(void); -bool32 OamUtil_Update(void); -u8 OamUtil_SetCallback(u8 id, void (*func)(struct OamUtil *)); -u8 OamUtil_SetData(u8 id, u8 dataArrayId, s16 dataValue); -u8 OamUtil_AddNew(const struct OamData *oam, u16 tileTag, u16 palTag, s16 x, s16 y, u8 animNum, u8 priority); -u8 OamUtil_Remove(u8 id); - -#endif // GUARD_ROM_81520A8_H diff --git a/ld_script.txt b/ld_script.txt index 74d9f6ae6..d22c4a0ce 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -237,7 +237,7 @@ SECTIONS { src/cable_car.o(.text); src/math_util.o(.text); src/roulette_util.o(.text); - src/rom_81520A8.o(.text); + src/oam_util.o(.text); src/save.o(.text); src/mystery_event_script.o(.text); src/field_effect_helpers.o(.text); diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index fa70ae478..30b170d8e 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -33,7 +33,7 @@ #include "fldeff_misc.h" #include "trainer_pokemon_sprites.h" #include "data.h" -#include "rom_81520A8.h" +#include "oam_util.h" #include "constants/rgb.h" #define HALL_OF_FAME_MAX_TEAMS 50 diff --git a/src/oam_util.c b/src/oam_util.c new file mode 100644 index 000000000..bd1801a7d --- /dev/null +++ b/src/oam_util.c @@ -0,0 +1,218 @@ +#include "global.h" +#include "oam_util.h" +#include "malloc.h" +#include "main.h" +#include "digit_obj_util.h" + +static EWRAM_DATA struct +{ + u8 count; + struct OamUtil *array; +} *sWork = NULL; + +static void sub_81520A8(void *dest, u16 value, u8 left, u8 top, u8 width, u8 height) // Unused. +{ + u8 i; + u8 j; + u8 x; + u8 y; + + for (i = 0, y = top; i < height; i++) + { + for (x = left, j = 0; j < width; j++) + { + *(u16 *)((dest) + (y * 64 + x * 2)) = value; + x = (x + 1) % 32; + } + y = (y + 1) % 32; + } +} + +static void sub_8152134(void *dest, const u16 *src, u8 left, u8 top, u8 width, u8 height) // Unused. +{ + u8 i; + u8 j; + u8 x; + u8 y; + const u16 *_src; + + for (i = 0, _src = src, y = top; i < height; i++) + { + for (x = left, j = 0; j < width; j++) + { + *(u16 *)((dest) + (y * 64 + x * 2)) = *(_src++); + x = (x + 1) % 32; + } + y = (y + 1) % 32; + } +} + +bool32 OamUtil_Init(u8 count) +{ + u8 i = 0; + + if (count == 0) + return FALSE; + if (count > 64) + count = 64; + + sWork = AllocZeroed(sizeof(*sWork)); + if (sWork == NULL) + return FALSE; + sWork->array = AllocZeroed(count * sizeof(struct OamUtil)); + if (sWork->array == NULL) + { + FREE_AND_SET_NULL(sWork); + return FALSE; + } + + sWork->count = count; + for (i = 0; i < count; i++) + { + memcpy(&sWork->array[i].oam, &gDummyOamData, sizeof(struct OamData)); + sWork->array[i].dummied = TRUE; + } + + return TRUE; +} + +bool32 OamUtil_Free(void) +{ + u8 i = 0; + + if (sWork == NULL) + return FALSE; + + for (i = 0; i < sWork->count; i++) + memcpy(&gMain.oamBuffer[i + 64], &gDummyOamData, sizeof(struct OamData)); + + memset(sWork->array, 0, sWork->count * sizeof(struct OamUtil)); + FREE_AND_SET_NULL(sWork->array); + memset(sWork, 0, sizeof(*sWork)); + FREE_AND_SET_NULL(sWork); + + return TRUE; +} + +bool32 OamUtil_Update(void) +{ + u8 i = 0; + + if (sWork == NULL || sWork->array == NULL) + return FALSE; + + for (i = 0; i < sWork->count; i++) + { + if (sWork->array[i].active && sWork->array[i].allowUpdates) + { + if (sWork->array[i].callback != NULL) + sWork->array[i].callback(&sWork->array[i]); + + if (sWork->array[i].dummied) + { + memcpy(&gMain.oamBuffer[i + 64], &gDummyOamData, sizeof(struct OamData)); + } + else + { + sWork->array[i].oam.y = sWork->array[i].y + sWork->array[i].yDelta; + sWork->array[i].oam.x = sWork->array[i].x + sWork->array[i].xDelta; + sWork->array[i].oam.priority = sWork->array[i].priority; + sWork->array[i].oam.tileNum = sWork->array[i].tileNum; + memcpy(&gMain.oamBuffer[i + 64], &sWork->array[i], sizeof(struct OamData)); + } + } + } + + return TRUE; +} + +static bool32 SetAnimAndTileNum(struct OamUtil *structPtr, u8 animNum) +{ + u16 tileStart; + + if (structPtr == NULL) + return FALSE; + + tileStart = GetSpriteTileStartByTag(structPtr->tileTag); + if (tileStart == 0xFFFF) + return FALSE; + + structPtr->animNum = animNum; + structPtr->tileNum = (GetTilesPerImage(structPtr->oam.shape, structPtr->oam.size) * animNum) + tileStart; + return TRUE; +} + +u8 OamUtil_SetCallback(u8 id, void (*func)(struct OamUtil *)) +{ + if (sWork == NULL || id >= sWork->count) + return 0xFF; + else if (!sWork->array[id].active) + return 0xFF; + + sWork->array[id].callback = func; + return id; +} + +u8 OamUtil_SetData(u8 id, u8 dataArrayId, s16 dataValue) +{ + if (sWork == NULL || id >= sWork->count) + return 0xFF; + else if (!sWork->array[id].active || dataArrayId > ARRAY_COUNT(sWork->array[id].data) - 1) // - 1 b/c last slot is reserved for taskId + return 0xFF; + + sWork->array[id].data[dataArrayId] = dataValue; + return id; +} + +u8 OamUtil_AddNew(const struct OamData *oam, u16 tileTag, u16 palTag, s16 x, s16 y, u8 animNum, u8 priority) +{ + struct OamUtil *structPtr = NULL; + u8 i; + + if (sWork == NULL || oam == NULL) + return 0xFF; + + for (i = 0; i < sWork->count; i++) + { + if (!sWork->array[i].active) + { + structPtr = &sWork->array[i]; + memset(structPtr, 0, sizeof(*structPtr)); + structPtr->id = i; + structPtr->active = TRUE; + structPtr->allowUpdates = TRUE; + break; + } + } + + if (structPtr == NULL) + return 0xFF; + + memcpy(&structPtr->oam, oam, sizeof(*oam)); + structPtr->tileTag = tileTag; + structPtr->palTag = palTag; + structPtr->x = x; + structPtr->y = y; + structPtr->oam.paletteNum = IndexOfSpritePaletteTag(palTag); + if (priority < 4) + { + structPtr->priority = priority; + structPtr->oam.priority = priority; + } + SetAnimAndTileNum(structPtr, animNum); + + return structPtr->id; +} + +u8 OamUtil_Remove(u8 id) +{ + if (sWork == NULL || !sWork->array[id].active) + return 0xFF; + + memset(&sWork->array[id], 0, sizeof(struct OamUtil)); + sWork->array[id].oam.y = 160; + sWork->array[id].oam.x = 240; + sWork->array[id].dummied = TRUE; + memcpy(&gMain.oamBuffer[id + 64], &gDummyOamData, sizeof(struct OamData)); + return id; +} diff --git a/src/rom_81520A8.c b/src/rom_81520A8.c deleted file mode 100644 index 2c37d7d48..000000000 --- a/src/rom_81520A8.c +++ /dev/null @@ -1,218 +0,0 @@ -#include "global.h" -#include "rom_81520A8.h" -#include "malloc.h" -#include "main.h" -#include "digit_obj_util.h" - -static EWRAM_DATA struct -{ - u8 count; - struct OamUtil *array; -} *sWork = NULL; - -static void sub_81520A8(void *dest, u16 value, u8 left, u8 top, u8 width, u8 height) // Unused. -{ - u8 i; - u8 j; - u8 x; - u8 y; - - for (i = 0, y = top; i < height; i++) - { - for (x = left, j = 0; j < width; j++) - { - *(u16 *)((dest) + (y * 64 + x * 2)) = value; - x = (x + 1) % 32; - } - y = (y + 1) % 32; - } -} - -static void sub_8152134(void *dest, const u16 *src, u8 left, u8 top, u8 width, u8 height) // Unused. -{ - u8 i; - u8 j; - u8 x; - u8 y; - const u16 *_src; - - for (i = 0, _src = src, y = top; i < height; i++) - { - for (x = left, j = 0; j < width; j++) - { - *(u16 *)((dest) + (y * 64 + x * 2)) = *(_src++); - x = (x + 1) % 32; - } - y = (y + 1) % 32; - } -} - -bool32 OamUtil_Init(u8 count) -{ - u8 i = 0; - - if (count == 0) - return FALSE; - if (count > 64) - count = 64; - - sWork = AllocZeroed(sizeof(*sWork)); - if (sWork == NULL) - return FALSE; - sWork->array = AllocZeroed(count * sizeof(struct OamUtil)); - if (sWork->array == NULL) - { - FREE_AND_SET_NULL(sWork); - return FALSE; - } - - sWork->count = count; - for (i = 0; i < count; i++) - { - memcpy(&sWork->array[i].oam, &gDummyOamData, sizeof(struct OamData)); - sWork->array[i].dummied = TRUE; - } - - return TRUE; -} - -bool32 OamUtil_Free(void) -{ - u8 i = 0; - - if (sWork == NULL) - return FALSE; - - for (i = 0; i < sWork->count; i++) - memcpy(&gMain.oamBuffer[i + 64], &gDummyOamData, sizeof(struct OamData)); - - memset(sWork->array, 0, sWork->count * sizeof(struct OamUtil)); - FREE_AND_SET_NULL(sWork->array); - memset(sWork, 0, sizeof(*sWork)); - FREE_AND_SET_NULL(sWork); - - return TRUE; -} - -bool32 OamUtil_Update(void) -{ - u8 i = 0; - - if (sWork == NULL || sWork->array == NULL) - return FALSE; - - for (i = 0; i < sWork->count; i++) - { - if (sWork->array[i].active && sWork->array[i].allowUpdates) - { - if (sWork->array[i].callback != NULL) - sWork->array[i].callback(&sWork->array[i]); - - if (sWork->array[i].dummied) - { - memcpy(&gMain.oamBuffer[i + 64], &gDummyOamData, sizeof(struct OamData)); - } - else - { - sWork->array[i].oam.y = sWork->array[i].y + sWork->array[i].yDelta; - sWork->array[i].oam.x = sWork->array[i].x + sWork->array[i].xDelta; - sWork->array[i].oam.priority = sWork->array[i].priority; - sWork->array[i].oam.tileNum = sWork->array[i].tileNum; - memcpy(&gMain.oamBuffer[i + 64], &sWork->array[i], sizeof(struct OamData)); - } - } - } - - return TRUE; -} - -static bool32 SetAnimAndTileNum(struct OamUtil *structPtr, u8 animNum) -{ - u16 tileStart; - - if (structPtr == NULL) - return FALSE; - - tileStart = GetSpriteTileStartByTag(structPtr->tileTag); - if (tileStart == 0xFFFF) - return FALSE; - - structPtr->animNum = animNum; - structPtr->tileNum = (GetTilesPerImage(structPtr->oam.shape, structPtr->oam.size) * animNum) + tileStart; - return TRUE; -} - -u8 OamUtil_SetCallback(u8 id, void (*func)(struct OamUtil *)) -{ - if (sWork == NULL || id >= sWork->count) - return 0xFF; - else if (!sWork->array[id].active) - return 0xFF; - - sWork->array[id].callback = func; - return id; -} - -u8 OamUtil_SetData(u8 id, u8 dataArrayId, s16 dataValue) -{ - if (sWork == NULL || id >= sWork->count) - return 0xFF; - else if (!sWork->array[id].active || dataArrayId > ARRAY_COUNT(sWork->array[id].data) - 1) // - 1 b/c last slot is reserved for taskId - return 0xFF; - - sWork->array[id].data[dataArrayId] = dataValue; - return id; -} - -u8 OamUtil_AddNew(const struct OamData *oam, u16 tileTag, u16 palTag, s16 x, s16 y, u8 animNum, u8 priority) -{ - struct OamUtil *structPtr = NULL; - u8 i; - - if (sWork == NULL || oam == NULL) - return 0xFF; - - for (i = 0; i < sWork->count; i++) - { - if (!sWork->array[i].active) - { - structPtr = &sWork->array[i]; - memset(structPtr, 0, sizeof(*structPtr)); - structPtr->id = i; - structPtr->active = TRUE; - structPtr->allowUpdates = TRUE; - break; - } - } - - if (structPtr == NULL) - return 0xFF; - - memcpy(&structPtr->oam, oam, sizeof(*oam)); - structPtr->tileTag = tileTag; - structPtr->palTag = palTag; - structPtr->x = x; - structPtr->y = y; - structPtr->oam.paletteNum = IndexOfSpritePaletteTag(palTag); - if (priority < 4) - { - structPtr->priority = priority; - structPtr->oam.priority = priority; - } - SetAnimAndTileNum(structPtr, animNum); - - return structPtr->id; -} - -u8 OamUtil_Remove(u8 id) -{ - if (sWork == NULL || !sWork->array[id].active) - return 0xFF; - - memset(&sWork->array[id], 0, sizeof(struct OamUtil)); - sWork->array[id].oam.y = 160; - sWork->array[id].oam.x = 240; - sWork->array[id].dummied = TRUE; - memcpy(&gMain.oamBuffer[id + 64], &gDummyOamData, sizeof(struct OamData)); - return id; -} diff --git a/sym_ewram.txt b/sym_ewram.txt index d00f7953c..58fb0648e 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -103,7 +103,7 @@ .include "src/battle_transition.o" .include "src/battle_message.o" .include "src/cable_car.o" - .include "src/rom_81520A8.o" + .include "src/oam_util.o" .include "src/save.o" .include "src/mystery_event_script.o" .include "src/move_relearner.o" -- cgit v1.2.3