From 4fbfeb3de834a3999c720e59897b9679bcd6e393 Mon Sep 17 00:00:00 2001 From: Rachel Date: Fri, 12 Sep 2025 14:04:25 -0700 Subject: [PATCH] Document `software_sprite.c` (#754) --- .../applications/pokedex/pokedex_graphics.h | 5 +- .../pokedex/struct_ov21_021E7F40.h | 22 - include/constants/colors.h | 1 + include/overlay022/ov22_02255094.h | 4 +- include/overlay022/struct_ov22_0225500C.h | 12 +- include/overlay022/struct_ov22_02255040.h | 4 +- include/overlay022/struct_ov22_022550D4.h | 11 - include/overlay022/struct_ov22_022557A0.h | 13 - include/overlay022/struct_ov22_02255800.h | 14 - include/overlay022/struct_ov22_02255CB8.h | 8 +- .../overlay022/struct_ov22_02257964_sub2.h | 10 +- .../overlay022/struct_ov22_02257F50_sub2.h | 11 +- include/overlay022/struct_ov22_02258470.h | 11 +- include/overlay022/struct_ov22_0225A0E4.h | 11 +- include/overlay022/struct_ov22_0225B388.h | 11 +- include/overlay083/ov83_0223D6A8.h | 5 +- include/overlay083/struct_ov83_0223B784.h | 5 +- include/overlay083/struct_ov83_0223E340.h | 12 +- include/software_sprite.h | 77 +++ include/struct_decls/struct_02015064_decl.h | 6 - include/struct_decls/struct_02015128_decl.h | 6 - include/struct_decls/struct_020151A4_decl.h | 6 - include/struct_decls/struct_02015214_decl.h | 6 - include/unk_02015064.h | 46 -- platinum.us/main.lsf | 2 +- src/applications/pokedex/ov21_021E737C.c | 81 ++- src/applications/pokedex/pokedex_graphics.c | 18 +- src/choose_starter/choose_starter_app.c | 89 ++-- src/meson.build | 2 +- src/overlay022/ov22_02254DE0.c | 47 +- src/overlay022/ov22_02255094.c | 81 ++- src/overlay022/ov22_022578F4.c | 6 +- src/overlay022/ov22_0225AF8C.c | 20 +- src/overlay083/ov83_0223C958.c | 17 +- src/overlay083/ov83_0223D6A8.c | 83 ++- src/software_sprite.c | 467 +++++++++++++++++ src/unk_02015064.c | 478 ------------------ src/unk_020298BC.c | 10 +- 38 files changed, 799 insertions(+), 919 deletions(-) delete mode 100644 include/applications/pokedex/struct_ov21_021E7F40.h delete mode 100644 include/overlay022/struct_ov22_022550D4.h delete mode 100644 include/overlay022/struct_ov22_022557A0.h delete mode 100644 include/overlay022/struct_ov22_02255800.h create mode 100644 include/software_sprite.h delete mode 100644 include/struct_decls/struct_02015064_decl.h delete mode 100644 include/struct_decls/struct_02015128_decl.h delete mode 100644 include/struct_decls/struct_020151A4_decl.h delete mode 100644 include/struct_decls/struct_02015214_decl.h delete mode 100644 include/unk_02015064.h create mode 100644 src/software_sprite.c delete mode 100644 src/unk_02015064.c diff --git a/include/applications/pokedex/pokedex_graphics.h b/include/applications/pokedex/pokedex_graphics.h index ea028c03e5..f063409f3c 100644 --- a/include/applications/pokedex/pokedex_graphics.h +++ b/include/applications/pokedex/pokedex_graphics.h @@ -5,8 +5,6 @@ #include "constants/species.h" -#include "struct_decls/struct_02015064_decl.h" - #include "applications/pokedex/pokedex_panel.h" #include "applications/pokedex/pokedex_text_manager.h" @@ -14,6 +12,7 @@ #include "heap.h" #include "narc.h" #include "pokemon_sprite.h" +#include "software_sprite.h" #include "sprite_resource.h" #include "sprite_util.h" #include "sys_task_manager.h" @@ -82,7 +81,7 @@ typedef struct PokedexGraphicData { PokedexTextManager *textMan; PokemonSpriteManager *spriteMan; PokemonSprite *pokemonSprite[MAX_SPRITE_RESOURCE_GEN4]; - UnkStruct_02015064 *unk_164; + SoftwareSpriteManager *unk_164; PokedexBlendTransition blendMain; PokedexBlendTransition blendSub; PokedexSpeciesLabel pokedexSpeciesLabel; diff --git a/include/applications/pokedex/struct_ov21_021E7F40.h b/include/applications/pokedex/struct_ov21_021E7F40.h deleted file mode 100644 index 0d35c0bef5..0000000000 --- a/include/applications/pokedex/struct_ov21_021E7F40.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV21_021E7F40_H -#define POKEPLATINUM_STRUCT_OV21_021E7F40_H - -#include "struct_decls/struct_02015064_decl.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" - -typedef struct { - UnkStruct_02015064 *unk_00; - UnkStruct_02015128 *unk_04; - UnkStruct_020151A4 *unk_08; - s16 unk_0C; - s16 unk_0E; - u16 unk_10; - u8 padding_12[2]; - fx32 unk_14; - int unk_18; - u16 unk_1C; - u8 padding_1E[2]; -} UnkStruct_ov21_021E7F40; - -#endif // POKEPLATINUM_STRUCT_OV21_021E7F40_H diff --git a/include/constants/colors.h b/include/constants/colors.h index 864fc88159..27881ff8d6 100644 --- a/include/constants/colors.h +++ b/include/constants/colors.h @@ -14,6 +14,7 @@ #define COLOR_BLACK RGB(0, 0, 0) #define COLOR_DARK_GRAY RGB(4, 4, 4) #define COLOR_WHITE RGB(31, 31, 31) +#define COLOR_GRAY RGB(16, 16, 16) #define COLOR_RED RGB(31, 0, 0) #define COLOR_TRANSPARENT RGB(31, 31, 16) #define COLOR_SAVED 0xFFFF diff --git a/include/overlay022/ov22_02255094.h b/include/overlay022/ov22_02255094.h index 232bda5157..f3380790b4 100644 --- a/include/overlay022/ov22_02255094.h +++ b/include/overlay022/ov22_02255094.h @@ -4,12 +4,12 @@ #include #include -#include "overlay022/struct_ov22_022550D4.h" #include "overlay022/struct_ov22_02255CB8.h" #include "overlay022/struct_ov22_0225A0E4.h" #include "bg_window.h" #include "narc.h" +#include "software_sprite.h" #include "sprite.h" void ov22_02255094(void); @@ -36,7 +36,7 @@ void ov22_02255390(void); void ov22_022553F8(UnkStruct_ov22_0225A0E4 *param0); void ov22_02255410(UnkStruct_ov22_02255CB8 *param0, int heapID); int ov22_02255420(NNSG2dCharacterData *param0, int param1, int param2, int param3); -void ov22_0225547C(UnkStruct_ov22_0225A0E4 *param0, const UnkStruct_ov22_022550D4 *param1, int heapID); +void ov22_0225547C(UnkStruct_ov22_0225A0E4 *param0, const SoftwareSpriteManagerTemplate *param1, int heapID); void ov22_022554A8(UnkStruct_ov22_0225A0E4 *param0, BgConfig *param1, int param2); void ov22_022554F8(UnkStruct_ov22_0225A0E4 *param0); void ov22_02255524(UnkStruct_ov22_0225A0E4 *param0); diff --git a/include/overlay022/struct_ov22_0225500C.h b/include/overlay022/struct_ov22_0225500C.h index 8e5a820945..f6057b7c97 100644 --- a/include/overlay022/struct_ov22_0225500C.h +++ b/include/overlay022/struct_ov22_0225500C.h @@ -1,17 +1,15 @@ #ifndef POKEPLATINUM_STRUCT_OV22_0225500C_H #define POKEPLATINUM_STRUCT_OV22_0225500C_H -#include "struct_decls/struct_02015064_decl.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" - #include "overlay022/struct_ov22_02254DE0.h" +#include "software_sprite.h" + typedef struct { UnkStruct_ov22_02254DE0 *unk_00; - UnkStruct_02015064 *unk_04; - UnkStruct_02015128 *unk_08; - UnkStruct_020151A4 *unk_0C; + SoftwareSpriteManager *unk_04; + SoftwareSpriteChars *unk_08; + SoftwareSpritePalette *unk_0C; int unk_10; int unk_14; u32 unk_18; diff --git a/include/overlay022/struct_ov22_02255040.h b/include/overlay022/struct_ov22_02255040.h index 039e2ab0a9..b1162e06f1 100644 --- a/include/overlay022/struct_ov22_02255040.h +++ b/include/overlay022/struct_ov22_02255040.h @@ -1,11 +1,11 @@ #ifndef POKEPLATINUM_STRUCT_OV22_02255040_H #define POKEPLATINUM_STRUCT_OV22_02255040_H -#include "struct_decls/struct_02015214_decl.h" +#include "software_sprite.h" typedef struct { int unk_00; - UnkStruct_02015214 *unk_04; + SoftwareSprite *unk_04; } UnkStruct_ov22_02255040; #endif // POKEPLATINUM_STRUCT_OV22_02255040_H diff --git a/include/overlay022/struct_ov22_022550D4.h b/include/overlay022/struct_ov22_022550D4.h deleted file mode 100644 index 391b035f17..0000000000 --- a/include/overlay022/struct_ov22_022550D4.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV22_022550D4_H -#define POKEPLATINUM_STRUCT_OV22_022550D4_H - -typedef struct { - int unk_00; - int unk_04; - int unk_08; - int heapID; -} UnkStruct_ov22_022550D4; - -#endif // POKEPLATINUM_STRUCT_OV22_022550D4_H diff --git a/include/overlay022/struct_ov22_022557A0.h b/include/overlay022/struct_ov22_022557A0.h deleted file mode 100644 index ec2a83c2e3..0000000000 --- a/include/overlay022/struct_ov22_022557A0.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV22_022557A0_H -#define POKEPLATINUM_STRUCT_OV22_022557A0_H - -#include - -#include "struct_decls/struct_02015064_decl.h" - -typedef struct { - UnkStruct_02015064 *unk_00; - NNSG2dCharacterData *unk_04; -} UnkStruct_ov22_022557A0; - -#endif // POKEPLATINUM_STRUCT_OV22_022557A0_H diff --git a/include/overlay022/struct_ov22_02255800.h b/include/overlay022/struct_ov22_02255800.h deleted file mode 100644 index a01cabd968..0000000000 --- a/include/overlay022/struct_ov22_02255800.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV22_02255800_H -#define POKEPLATINUM_STRUCT_OV22_02255800_H - -#include - -#include "struct_decls/struct_02015064_decl.h" - -typedef struct { - UnkStruct_02015064 *unk_00; - NNSG2dPaletteData *unk_04; - u32 unk_08; -} UnkStruct_ov22_02255800; - -#endif // POKEPLATINUM_STRUCT_OV22_02255800_H diff --git a/include/overlay022/struct_ov22_02255CB8.h b/include/overlay022/struct_ov22_02255CB8.h index 9975eb6634..9e438e06d3 100644 --- a/include/overlay022/struct_ov22_02255CB8.h +++ b/include/overlay022/struct_ov22_02255CB8.h @@ -1,15 +1,13 @@ #ifndef POKEPLATINUM_STRUCT_OV22_02255CB8_H #define POKEPLATINUM_STRUCT_OV22_02255CB8_H -#include "overlay022/struct_ov22_022557A0.h" -#include "overlay022/struct_ov22_02255800.h" - #include "resource_collection.h" +#include "software_sprite.h" typedef struct { - UnkStruct_ov22_022557A0 *unk_00; + SoftwareSpriteCharsTemplate *unk_00; int unk_04; - UnkStruct_ov22_02255800 *unk_08; + SoftwareSpritePaletteTemplate *unk_08; int unk_0C; ResourceCollection *unk_10; ResourceCollection *unk_14; diff --git a/include/overlay022/struct_ov22_02257964_sub2.h b/include/overlay022/struct_ov22_02257964_sub2.h index a4339be46c..ff2e10c4ba 100644 --- a/include/overlay022/struct_ov22_02257964_sub2.h +++ b/include/overlay022/struct_ov22_02257964_sub2.h @@ -1,20 +1,18 @@ #ifndef POKEPLATINUM_STRUCT_OV22_02257964_SUB2_H #define POKEPLATINUM_STRUCT_OV22_02257964_SUB2_H -#include "struct_decls/struct_02015064_decl.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" #include "struct_defs/struct_020298D8.h" #include "overlay022/struct_ov22_02254DE0.h" #include "overlay022/struct_ov22_022597BC.h" #include "bg_window.h" +#include "software_sprite.h" typedef struct { - UnkStruct_02015064 *unk_00; - UnkStruct_02015128 **unk_04; - UnkStruct_020151A4 **unk_08; + SoftwareSpriteManager *unk_00; + SoftwareSpriteChars **unk_04; + SoftwareSpritePalette **unk_08; u8 *unk_0C; PokemonSpriteManager *unk_10; BgConfig *unk_14; diff --git a/include/overlay022/struct_ov22_02257F50_sub2.h b/include/overlay022/struct_ov22_02257F50_sub2.h index 4620018dde..a27cb9c964 100644 --- a/include/overlay022/struct_ov22_02257F50_sub2.h +++ b/include/overlay022/struct_ov22_02257F50_sub2.h @@ -1,19 +1,16 @@ #ifndef POKEPLATINUM_STRUCT_OV22_02257F50_SUB2_H #define POKEPLATINUM_STRUCT_OV22_02257F50_SUB2_H -#include "struct_decls/struct_02015064_decl.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" - #include "overlay022/struct_ov22_02254DE0.h" #include "overlay022/struct_ov22_022597BC.h" #include "bg_window.h" +#include "software_sprite.h" typedef struct { - UnkStruct_02015064 *unk_00; - UnkStruct_02015128 **unk_04; - UnkStruct_020151A4 **unk_08; + SoftwareSpriteManager *unk_00; + SoftwareSpriteChars **unk_04; + SoftwareSpritePalette **unk_08; u8 *unk_0C; BgConfig *unk_10; UnkStruct_ov22_02254DE0 *unk_14; diff --git a/include/overlay022/struct_ov22_02258470.h b/include/overlay022/struct_ov22_02258470.h index 79f1d497b4..f735c1b6cc 100644 --- a/include/overlay022/struct_ov22_02258470.h +++ b/include/overlay022/struct_ov22_02258470.h @@ -1,20 +1,17 @@ #ifndef POKEPLATINUM_STRUCT_OV22_02258470_H #define POKEPLATINUM_STRUCT_OV22_02258470_H -#include "struct_decls/struct_02015064_decl.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" - #include "overlay022/struct_ov22_02254DE0.h" #include "overlay022/struct_ov22_0225899C.h" #include "overlay022/struct_ov22_02259484.h" #include "bg_window.h" +#include "software_sprite.h" typedef struct { - UnkStruct_02015064 *unk_00; - UnkStruct_02015128 **unk_04; - UnkStruct_020151A4 **unk_08; + SoftwareSpriteManager *unk_00; + SoftwareSpriteChars **unk_04; + SoftwareSpritePalette **unk_08; u8 *unk_0C; BgConfig *unk_10; UnkStruct_ov22_02254DE0 *unk_14; diff --git a/include/overlay022/struct_ov22_0225A0E4.h b/include/overlay022/struct_ov22_0225A0E4.h index b89eae0c16..d72d01bd59 100644 --- a/include/overlay022/struct_ov22_0225A0E4.h +++ b/include/overlay022/struct_ov22_0225A0E4.h @@ -3,24 +3,21 @@ #include -#include "struct_decls/struct_02015064_decl.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" - #include "bg_window.h" #include "narc.h" #include "pokemon_sprite.h" #include "resource_collection.h" +#include "software_sprite.h" #include "sprite.h" #include "sprite_resource.h" #include "sprite_util.h" typedef struct { - UnkStruct_02015064 *unk_00; - UnkStruct_02015128 **unk_04; + SoftwareSpriteManager *unk_00; + SoftwareSpriteChars **unk_04; int unk_08; int unk_0C; - UnkStruct_020151A4 **unk_10; + SoftwareSpritePalette **unk_10; int unk_14; int unk_18; BOOL unk_1C; diff --git a/include/overlay022/struct_ov22_0225B388.h b/include/overlay022/struct_ov22_0225B388.h index db1f71fc80..c618e09e1d 100644 --- a/include/overlay022/struct_ov22_0225B388.h +++ b/include/overlay022/struct_ov22_0225B388.h @@ -1,19 +1,16 @@ #ifndef POKEPLATINUM_STRUCT_OV22_0225B388_H #define POKEPLATINUM_STRUCT_OV22_0225B388_H -#include "struct_decls/struct_02015064_decl.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" - #include "overlay022/struct_ov22_02254DE0.h" #include "overlay022/struct_ov22_02259484.h" #include "bg_window.h" +#include "software_sprite.h" typedef struct { - UnkStruct_02015064 *unk_00; - UnkStruct_02015128 **unk_04; - UnkStruct_020151A4 **unk_08; + SoftwareSpriteManager *unk_00; + SoftwareSpriteChars **unk_04; + SoftwareSpritePalette **unk_08; u8 *unk_0C; PokemonSpriteManager *unk_10; BgConfig *unk_14; diff --git a/include/overlay083/ov83_0223D6A8.h b/include/overlay083/ov83_0223D6A8.h index 20118d9cc4..53e42fed1e 100644 --- a/include/overlay083/ov83_0223D6A8.h +++ b/include/overlay083/ov83_0223D6A8.h @@ -3,8 +3,6 @@ #include -#include "struct_decls/struct_02015064_decl.h" - #include "overlay083/struct_ov83_0223D4CC_decl.h" #include "overlay083/struct_ov83_0223D784.h" #include "overlay083/struct_ov83_0223D95C.h" @@ -27,6 +25,7 @@ #include "bg_window.h" #include "narc.h" +#include "software_sprite.h" #include "sprite.h" #include "sprite_resource.h" @@ -64,7 +63,7 @@ void ov83_0223E2FC(UnkStruct_ov83_0223E244 *param0); BOOL ov83_0223E32C(UnkStruct_ov83_0223E244 *param0); void ov83_0223E340(UnkStruct_ov83_0223E340 *param0); void ov83_0223E34C(UnkStruct_ov83_0223E340 *param0); -void ov83_0223E368(UnkStruct_ov83_0223E340 *param0, UnkStruct_02015064 *param1, u32 param2, NARC *param3); +void ov83_0223E368(UnkStruct_ov83_0223E340 *param0, SoftwareSpriteManager *param1, u32 param2, NARC *param3); void ov83_0223E438(UnkStruct_ov83_0223E340 *param0); void ov83_0223E484(UnkStruct_ov83_0223E340 *param0, u32 param1, BOOL param2); void ov83_0223E4A4(UnkStruct_ov83_0223E340 *param0, u16 param1); diff --git a/include/overlay083/struct_ov83_0223B784.h b/include/overlay083/struct_ov83_0223B784.h index 776772a320..05da517822 100644 --- a/include/overlay083/struct_ov83_0223B784.h +++ b/include/overlay083/struct_ov83_0223B784.h @@ -1,8 +1,6 @@ #ifndef POKEPLATINUM_STRUCT_OV83_0223B784_H #define POKEPLATINUM_STRUCT_OV83_0223B784_H -#include "struct_decls/struct_02015064_decl.h" - #include "overlay083/struct_ov83_0223D4CC_decl.h" #include "overlay083/struct_ov83_0223D784.h" #include "overlay083/struct_ov83_0223D95C.h" @@ -23,6 +21,7 @@ #include "overlay083/struct_ov83_0223FE50.h" #include "bg_window.h" +#include "software_sprite.h" typedef struct { int heapID; @@ -42,7 +41,7 @@ typedef struct { UnkStruct_ov83_0223D784 unk_2C; UnkStruct_ov83_0223D95C unk_1CC[6]; BOOL unk_31C; - UnkStruct_02015064 *unk_320; + SoftwareSpriteManager *unk_320; u32 unk_324; u32 unk_328; BOOL unk_32C; diff --git a/include/overlay083/struct_ov83_0223E340.h b/include/overlay083/struct_ov83_0223E340.h index 3543f74127..378e1720c5 100644 --- a/include/overlay083/struct_ov83_0223E340.h +++ b/include/overlay083/struct_ov83_0223E340.h @@ -1,16 +1,14 @@ #ifndef POKEPLATINUM_STRUCT_OV83_0223E340_H #define POKEPLATINUM_STRUCT_OV83_0223E340_H -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" -#include "struct_decls/struct_02015214_decl.h" - #include "overlay083/struct_ov83_0223D9EC.h" +#include "software_sprite.h" + typedef struct { - UnkStruct_02015128 *unk_00[6]; - UnkStruct_020151A4 *unk_18[8]; - UnkStruct_02015214 *unk_38[8]; + SoftwareSpriteChars *unk_00[6]; + SoftwareSpritePalette *unk_18[8]; + SoftwareSprite *unk_38[8]; UnkStruct_ov83_0223D9EC unk_58; int unk_6C; int unk_70; diff --git a/include/software_sprite.h b/include/software_sprite.h new file mode 100644 index 0000000000..bc7a111a3f --- /dev/null +++ b/include/software_sprite.h @@ -0,0 +1,77 @@ +#ifndef POKEPLATINUM_SOFTWARE_SPRITE_H +#define POKEPLATINUM_SOFTWARE_SPRITE_H + +#include +#include + +typedef struct SoftwareSpriteChars SoftwareSpriteChars; +typedef struct SoftwareSpritePalette SoftwareSpritePalette; +typedef struct SoftwareSprite SoftwareSprite; +typedef struct SoftwareSpriteManager SoftwareSpriteManager; + +typedef struct SoftwareSpriteManagerTemplate { + int numSprites; + int numChars; + int numPalettes; + int heapID; +} SoftwareSpriteManagerTemplate; + +typedef struct SoftwareSpriteCharsTemplate { + SoftwareSpriteManager *softSpriteMan; + NNSG2dCharacterData *charsData; +} SoftwareSpriteCharsTemplate; + +typedef struct SoftwareSpritePaletteTemplate { + SoftwareSpriteManager *softSpriteMan; + NNSG2dPaletteData *paletteData; + u32 paletteSlot; +} SoftwareSpritePaletteTemplate; + +typedef struct SoftwareSpriteTemplate { + SoftwareSpriteManager *softSpriteMan; + SoftwareSpriteChars *chars; + SoftwareSpritePalette *palette; + s16 xPos; + s16 yPos; + u16 rotation; + fx32 alpha; + int priority; + u16 paletteSlot; +} SoftwareSpriteTemplate; + +#define SPRITE_FLIP_H 0 +#define SPRITE_FLIP_V 1 + +SoftwareSpriteManager *SoftwareSpriteManager_New(const SoftwareSpriteManagerTemplate *template); +void SoftwareSpriteManager_Free(SoftwareSpriteManager *softSpriteMan); +SoftwareSpriteChars *SoftwareSprite_LoadChars(const SoftwareSpriteCharsTemplate *template); +void SoftwareSprite_FreeChars(SoftwareSpriteChars *chars); +void SoftwareSpriteManager_FreeAllChars(SoftwareSpriteManager *softSpriteMan); +SoftwareSpritePalette *SoftwareSprite_LoadPalette(const SoftwareSpritePaletteTemplate *template); +void SoftwareSprite_FreePalette(SoftwareSpritePalette *palette); +void SoftwareSpriteManager_FreeAllPalettes(SoftwareSpriteManager *softSpriteMan); + +void SoftwareSpriteManager_DrawVisible(SoftwareSpriteManager *softSpriteMan); +SoftwareSprite *SoftwareSprite_Load(const SoftwareSpriteTemplate *template); +void SoftwareSprite_Reset(SoftwareSprite *sprite); + +NNSG2dSVec2 SoftwareSprite_GetPosition(SoftwareSprite *sprite); +NNSG2dSVec2 SoftwareSprite_GetDimensions(SoftwareSprite *sprite); +int SoftwareSprite_GetPriority(SoftwareSprite *sprite); + +void SoftwareSprite_SetVisible(SoftwareSprite *sprite, BOOL visible); +void SoftwareSprite_SetPosition(SoftwareSprite *sprite, s16 x, s16 y); +void SoftwareSprite_SetCenter(SoftwareSprite *sprite, s16 x, s16 y); +void SoftwareSprite_SetScalingFactors(SoftwareSprite *sprite, fx32 scaleX, fx32 scaleY); +void SoftwareSprite_SetDimensions(SoftwareSprite *sprite, int x, int y); +void SoftwareSprite_SetPriority(SoftwareSprite *sprite, int priority); +void SoftwareSprite_SetAlpha(SoftwareSprite *sprite, u8 alpha); +void SoftwareSprite_SetDiffuse(SoftwareSprite *sprite, GXRgb diffuse); +void SoftwareSprite_SetAttributes(SoftwareSprite *sprite, NNSG2dImageAttr *attributes); +void SoftwareSprite_SetVRAMAddress_Chars(SoftwareSprite *sprite, u32 address); +void SoftwareSprite_SetVRAMAddress_Palette(SoftwareSprite *sprite, u32 address); +void SoftwareSprite_SetPaletteSlot(SoftwareSprite *sprite, u32 slot); +void SoftwareSprite_SetFlip(SoftwareSprite *sprite, int direction, BOOL flip); +void SoftwareSprite_SetRotation(SoftwareSprite *sprite, u16 rotation); + +#endif // POKEPLATINUM_SOFTWARE_SPRITE_H diff --git a/include/struct_decls/struct_02015064_decl.h b/include/struct_decls/struct_02015064_decl.h deleted file mode 100644 index 607c2bc58e..0000000000 --- a/include/struct_decls/struct_02015064_decl.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_02015064_DECL_H -#define POKEPLATINUM_STRUCT_02015064_DECL_H - -typedef struct UnkStruct_02015064_t UnkStruct_02015064; - -#endif // POKEPLATINUM_STRUCT_02015064_DECL_H diff --git a/include/struct_decls/struct_02015128_decl.h b/include/struct_decls/struct_02015128_decl.h deleted file mode 100644 index 55acc4753f..0000000000 --- a/include/struct_decls/struct_02015128_decl.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_02015128_DECL_H -#define POKEPLATINUM_STRUCT_02015128_DECL_H - -typedef struct UnkStruct_02015128_t UnkStruct_02015128; - -#endif // POKEPLATINUM_STRUCT_02015128_DECL_H diff --git a/include/struct_decls/struct_020151A4_decl.h b/include/struct_decls/struct_020151A4_decl.h deleted file mode 100644 index d3e5fe34fe..0000000000 --- a/include/struct_decls/struct_020151A4_decl.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_020151A4_DECL_H -#define POKEPLATINUM_STRUCT_020151A4_DECL_H - -typedef struct UnkStruct_020151A4_t UnkStruct_020151A4; - -#endif // POKEPLATINUM_STRUCT_020151A4_DECL_H diff --git a/include/struct_decls/struct_02015214_decl.h b/include/struct_decls/struct_02015214_decl.h deleted file mode 100644 index b79bc0b983..0000000000 --- a/include/struct_decls/struct_02015214_decl.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_02015214_DECL_H -#define POKEPLATINUM_STRUCT_02015214_DECL_H - -typedef struct UnkStruct_02015214_t UnkStruct_02015214; - -#endif // POKEPLATINUM_STRUCT_02015214_DECL_H diff --git a/include/unk_02015064.h b/include/unk_02015064.h deleted file mode 100644 index 30fc4d5109..0000000000 --- a/include/unk_02015064.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef POKEPLATINUM_UNK_02015064_H -#define POKEPLATINUM_UNK_02015064_H - -#include -#include - -#include "struct_decls/struct_02015064_decl.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" -#include "struct_decls/struct_02015214_decl.h" - -#include "applications/pokedex/struct_ov21_021E7F40.h" -#include "overlay022/struct_ov22_022550D4.h" -#include "overlay022/struct_ov22_022557A0.h" -#include "overlay022/struct_ov22_02255800.h" - -UnkStruct_02015064 *sub_02015064(const UnkStruct_ov22_022550D4 *param0); -void sub_020150A8(UnkStruct_02015064 *param0); -void sub_020150EC(UnkStruct_02015064 *param0); -UnkStruct_02015128 *sub_02015128(const UnkStruct_ov22_022557A0 *param0); -void sub_02015164(UnkStruct_02015128 *param0); -void sub_0201517C(UnkStruct_02015064 *param0); -UnkStruct_020151A4 *sub_020151A4(const UnkStruct_ov22_02255800 *param0); -void sub_020151D4(UnkStruct_020151A4 *param0); -void sub_020151EC(UnkStruct_02015064 *param0); -UnkStruct_02015214 *sub_02015214(const UnkStruct_ov21_021E7F40 *param0); -void sub_02015238(UnkStruct_02015214 *param0); -void sub_02015240(UnkStruct_02015214 *param0, BOOL param1); -void sub_02015254(UnkStruct_02015214 *param0, s16 param1, s16 param2); -NNSG2dSVec2 sub_0201525C(UnkStruct_02015214 *param0); -void sub_02015268(UnkStruct_02015214 *param0, s16 param1, s16 param2); -void sub_02015270(UnkStruct_02015214 *param0, fx32 param1, fx32 param2); -void sub_02015278(UnkStruct_02015214 *param0, int param1, int param2); -NNSG2dSVec2 sub_02015280(UnkStruct_02015214 *param0); -void sub_0201528C(UnkStruct_02015214 *param0, int param1); -int sub_02015290(UnkStruct_02015214 *param0); -void sub_02015294(UnkStruct_02015214 *param0, u8 param1); -void sub_0201529C(UnkStruct_02015214 *param0, GXRgb param1); -void sub_020152A0(UnkStruct_02015214 *param0, NNSG2dImageAttr *param1); -void sub_020152A4(UnkStruct_02015214 *param0, u32 param1); -void sub_020152A8(UnkStruct_02015214 *param0, u32 param1); -void sub_020152AC(UnkStruct_02015214 *param0, u32 param1); -void sub_020152B0(UnkStruct_02015214 *param0, int param1, BOOL param2); -void sub_020152BC(UnkStruct_02015214 *param0, u16 param1); - -#endif // POKEPLATINUM_UNK_02015064_H diff --git a/platinum.us/main.lsf b/platinum.us/main.lsf index 68003e52ca..8c82d65002 100644 --- a/platinum.us/main.lsf +++ b/platinum.us/main.lsf @@ -58,7 +58,7 @@ Static main Object main.nef.p/src_colored_arrow.c.o Object main.nef.p/src_unk_02014A84.c.o Object main.nef.p/src_unk_02014D38.c.o - Object main.nef.p/src_unk_02015064.c.o + Object main.nef.p/src_software_sprite.c.o Object main.nef.p/src_unk_0201567C.c.o Object main.nef.p/src_unk_020158A8.c.o Object main.nef.p/src_unk_02015920.c.o diff --git a/src/applications/pokedex/ov21_021E737C.c b/src/applications/pokedex/ov21_021E737C.c index a0650f0acf..bf1e982bb4 100644 --- a/src/applications/pokedex/ov21_021E737C.c +++ b/src/applications/pokedex/ov21_021E737C.c @@ -3,10 +3,6 @@ #include #include -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" -#include "struct_decls/struct_02015214_decl.h" - #include "applications/pokedex/ov21_021E29DC.h" #include "applications/pokedex/pokedex_app.h" #include "applications/pokedex/pokedex_data_manager.h" @@ -16,9 +12,6 @@ #include "applications/pokedex/pokedex_sort.h" #include "applications/pokedex/pokedex_sort_data.h" #include "applications/pokedex/struct_ov21_021E68F4.h" -#include "applications/pokedex/struct_ov21_021E7F40.h" -#include "overlay022/struct_ov22_022557A0.h" -#include "overlay022/struct_ov22_02255800.h" #include "bg_window.h" #include "font.h" @@ -30,6 +23,7 @@ #include "pokedex_data_index.h" #include "pokedex_heightweight.h" #include "pokemon_icon.h" +#include "software_sprite.h" #include "sprite.h" #include "sprite_resource.h" #include "sprite_transfer.h" @@ -38,7 +32,6 @@ #include "sys_task.h" #include "sys_task_manager.h" #include "text.h" -#include "unk_02015064.h" #include "vram_transfer.h" #include "res/text/bank/pokedex.h" @@ -59,9 +52,9 @@ typedef struct { typedef struct { PokedexGraphicData *unk_00; - UnkStruct_02015128 *unk_04; - UnkStruct_020151A4 *unk_08; - UnkStruct_02015214 *unk_0C; + SoftwareSpriteChars *unk_04; + SoftwareSpritePalette *unk_08; + SoftwareSprite *unk_0C; void *unk_10; void *unk_14; NNSG2dCharacterData *unk_18; @@ -74,7 +67,7 @@ typedef struct { } UnkStruct_ov21_021E74A0; typedef struct { - UnkStruct_02015214 *unk_00; + SoftwareSprite *unk_00; Sprite *unk_04; Sprite *unk_08; Sprite *unk_0C; @@ -90,7 +83,7 @@ typedef struct { } UnkStruct_ov21_021E8084; typedef struct { - UnkStruct_02015214 *unk_00; + SoftwareSprite *unk_00; Sprite *unk_04; Sprite *unk_08; Sprite *unk_0C; @@ -161,7 +154,7 @@ static void ov21_021E7F20(UnkStruct_ov21_021E747C *param0); static void ov21_021E7F40(UnkStruct_ov21_021E747C *param0, int param1); static void ov21_021E7F7C(UnkStruct_ov21_021E747C *param0); static const UnkStruct_ov21_021E9DB0 *ov21_021E83D8(const UnkStruct_ov21_021E9DB0 *param0, int param1, int param2); -static void ov21_021E80D4(UnkStruct_02015214 *param0, Sprite *param1, Sprite *param2, Sprite *param3, Sprite *param4, u16 param5); +static void ov21_021E80D4(SoftwareSprite *param0, Sprite *param1, Sprite *param2, Sprite *param3, Sprite *param4, u16 param5); static void ov21_021E7F88(UnkStruct_ov21_021E7714 *param0, UnkStruct_ov21_021E747C *param1, int param2); static void ov21_021E7FD0(SysTask *param0, void *param1); static void ov21_021E8084(UnkStruct_ov21_021E8084 *param0); @@ -240,7 +233,7 @@ UnkStruct_ov21_021E747C *ov21_021E7424(enum HeapID heapID, PokedexApp *param1) ov21_021E7EC0(v0, heapID); ov21_021E7F40(v0, heapID); - sub_02015240(v0->unk_0C, 0); + SoftwareSprite_SetVisible(v0->unk_0C, 0); return v0; } @@ -508,8 +501,8 @@ static void ov21_021E7800(UnkStruct_ov21_021E7714 *param0, UnkStruct_ov21_021E74 ov21_021E7B34(param0, param1, param2, heapID); ov21_021E7CF0(param0, param1, param2, heapID); - sub_020152BC(param1->unk_0C, 0); - sub_02015240(param1->unk_0C, 1); + SoftwareSprite_SetRotation(param1->unk_0C, 0); + SoftwareSprite_SetVisible(param1->unk_0C, 1); } static void ov21_021E785C(UnkStruct_ov21_021E7714 *param0, UnkStruct_ov21_021E747C *param1) @@ -521,8 +514,8 @@ static void ov21_021E785C(UnkStruct_ov21_021E7714 *param0, UnkStruct_ov21_021E74 Window_FillTilemap(¶m1->unk_00->window, 0); Bg_ClearTilemap(param1->unk_00->bgConfig, 1); - sub_02015240(param1->unk_0C, 0); - sub_020152BC(param1->unk_0C, 0); + SoftwareSprite_SetVisible(param1->unk_0C, 0); + SoftwareSprite_SetRotation(param1->unk_0C, 0); } static void ov21_021E789C(UnkStruct_ov21_021E747C *param0, const UnkStruct_ov21_021E7468 *param1, enum HeapID heapID) @@ -756,53 +749,53 @@ static void ov21_021E7DA8(UnkStruct_ov21_021E747C *param0, const UnkStruct_ov21_ static void ov21_021E7EC0(UnkStruct_ov21_021E747C *param0, int heapID) { - UnkStruct_ov22_022557A0 v0; - UnkStruct_ov22_02255800 v1; + SoftwareSpriteCharsTemplate v0; + SoftwareSpritePaletteTemplate v1; param0->unk_10 = PokedexGraphics_GetGraphicNarcCharacterData(param0->unk_00, 36, 1, ¶m0->unk_18, heapID); param0->unk_14 = PokedexGraphics_GetGraphicNarcPaletteData(param0->unk_00, 6, ¶m0->unk_1C, heapID); - v0.unk_00 = param0->unk_00->unk_164; - v0.unk_04 = param0->unk_18; + v0.softSpriteMan = param0->unk_00->unk_164; + v0.charsData = param0->unk_18; - param0->unk_04 = sub_02015128(&v0); + param0->unk_04 = SoftwareSprite_LoadChars(&v0); - v1.unk_00 = param0->unk_00->unk_164; - v1.unk_04 = param0->unk_1C; - v1.unk_08 = 16; + v1.softSpriteMan = param0->unk_00->unk_164; + v1.paletteData = param0->unk_1C; + v1.paletteSlot = 16; - param0->unk_08 = sub_020151A4(&v1); + param0->unk_08 = SoftwareSprite_LoadPalette(&v1); } static void ov21_021E7F20(UnkStruct_ov21_021E747C *param0) { - sub_02015164(param0->unk_04); - sub_020151D4(param0->unk_08); + SoftwareSprite_FreeChars(param0->unk_04); + SoftwareSprite_FreePalette(param0->unk_08); Heap_Free(param0->unk_10); Heap_Free(param0->unk_14); } static void ov21_021E7F40(UnkStruct_ov21_021E747C *param0, int param1) { - UnkStruct_ov21_021E7F40 v0; + SoftwareSpriteTemplate v0; - v0.unk_00 = param0->unk_00->unk_164; - v0.unk_04 = param0->unk_04; - v0.unk_08 = param0->unk_08; + v0.softSpriteMan = param0->unk_00->unk_164; + v0.chars = param0->unk_04; + v0.palette = param0->unk_08; - v0.unk_0C = 128 - (128 / 2); - v0.unk_0E = 96 - (16 / 2); - v0.unk_10 = 0; - v0.unk_14 = 31; - v0.unk_18 = 0; - v0.unk_1C = 0; + v0.xPos = 128 - (128 / 2); + v0.yPos = 96 - (16 / 2); + v0.rotation = 0; + v0.alpha = 31; + v0.priority = 0; + v0.paletteSlot = 0; - param0->unk_0C = sub_02015214(&v0); + param0->unk_0C = SoftwareSprite_Load(&v0); } static void ov21_021E7F7C(UnkStruct_ov21_021E747C *param0) { - sub_02015238(param0->unk_0C); + SoftwareSprite_Reset(param0->unk_0C); } static void ov21_021E7F88(UnkStruct_ov21_021E7714 *param0, UnkStruct_ov21_021E747C *param1, int param2) @@ -894,12 +887,12 @@ static void ov21_021E8084(UnkStruct_ov21_021E8084 *param0) ov21_021E80D4(param0->unk_00, param0->unk_04, param0->unk_08, param0->unk_0C, param0->unk_10, param0->unk_1C); } -static void ov21_021E80D4(UnkStruct_02015214 *param0, Sprite *param1, Sprite *param2, Sprite *param3, Sprite *param4, u16 param5) +static void ov21_021E80D4(SoftwareSprite *param0, Sprite *param1, Sprite *param2, Sprite *param3, Sprite *param4, u16 param5) { fx32 v0, v1; VecFx32 v2; - sub_020152BC(param0, param5); + SoftwareSprite_SetRotation(param0, param5); v0 = FX_Mul(FX_CosIdx(param5), 56 << FX32_SHIFT); v1 = FX_Mul(FX_SinIdx(param5), 56 << FX32_SHIFT); diff --git a/src/applications/pokedex/pokedex_graphics.c b/src/applications/pokedex/pokedex_graphics.c index a80622ae94..1fe6bbbc82 100644 --- a/src/applications/pokedex/pokedex_graphics.c +++ b/src/applications/pokedex/pokedex_graphics.c @@ -2,16 +2,14 @@ #include -#include "overlay022/struct_ov22_022550D4.h" - #include "bg_window.h" #include "font.h" #include "gx_layers.h" #include "pokemon.h" +#include "software_sprite.h" #include "sprite_transfer.h" #include "sys_task.h" #include "unk_02012744.h" -#include "unk_02015064.h" static void InitBackgrounds(BgConfig *bgConfig, enum HeapID heapID); static void FreeBackgrounds(BgConfig *bgConfig); @@ -110,7 +108,7 @@ void PokemonGraphics_UpdateSprites(PokedexGraphicData *pokedexGraphicData) NNS_G2dSetupSoftwareSpriteCamera(); PokemonSpriteManager_DrawSprites(pokedexGraphicData->spriteMan); - sub_020150EC(pokedexGraphicData->unk_164); + SoftwareSpriteManager_DrawVisible(pokedexGraphicData->unk_164); } void PokemonGraphics_UpdateCharAndPltt(PokedexGraphicData *pokedexGraphicData) @@ -697,15 +695,15 @@ static void NewPokemonSprite(PokedexGraphicData *pokedexGraphicData, enum HeapID } { - UnkStruct_ov22_022550D4 v3 = { - .unk_00 = 8, - .unk_04 = 8, - .unk_08 = 8, + SoftwareSpriteManagerTemplate v3 = { + .numSprites = 8, + .numChars = 8, + .numPalettes = 8, .heapID = HEAP_ID_SYSTEM }; v3.heapID = heapID; - pokedexGraphicData->unk_164 = sub_02015064(&v3); + pokedexGraphicData->unk_164 = SoftwareSpriteManager_New(&v3); } } @@ -718,7 +716,7 @@ static void FreePokemonSprite(PokedexGraphicData *pokedexGraphicData) } PokemonSpriteManager_Free(pokedexGraphicData->spriteMan); - sub_020150A8(pokedexGraphicData->unk_164); + SoftwareSpriteManager_Free(pokedexGraphicData->unk_164); } static void InitSpeciesLabelGraphics(PokedexGraphicData *pokedexGraphicData, enum HeapID heapID) diff --git a/src/choose_starter/choose_starter_app.c b/src/choose_starter/choose_starter_app.c index cc5c172f5b..90e2be5839 100644 --- a/src/choose_starter/choose_starter_app.c +++ b/src/choose_starter/choose_starter_app.c @@ -9,18 +9,9 @@ #include "constants/narc.h" #include "constants/species.h" -#include "struct_decls/struct_02015064_decl.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" -#include "struct_decls/struct_02015214_decl.h" #include "struct_defs/choose_starter_data.h" #include "struct_defs/struct_02099F80.h" -#include "applications/pokedex/struct_ov21_021E7F40.h" -#include "overlay022/struct_ov22_022550D4.h" -#include "overlay022/struct_ov22_022557A0.h" -#include "overlay022/struct_ov22_02255800.h" - #include "bg_window.h" #include "camera.h" #include "char_transfer.h" @@ -40,6 +31,7 @@ #include "render_text.h" #include "render_window.h" #include "screen_fade.h" +#include "software_sprite.h" #include "sound.h" #include "sound_playback.h" #include "sprite.h" @@ -52,7 +44,6 @@ #include "system.h" #include "text.h" #include "touch_pad.h" -#include "unk_02015064.h" #include "unk_0202419C.h" #include "vram_transfer.h" @@ -166,9 +157,9 @@ typedef struct StarterPreviewAnimation { } StarterPreviewAnimation; typedef struct StarterPreviewWindow { - UnkStruct_02015128 *unk_00; - UnkStruct_020151A4 *unk_04; - UnkStruct_02015214 *unk_08; + SoftwareSpriteChars *unk_00; + SoftwareSpritePalette *unk_04; + SoftwareSprite *unk_08; void *unk_0C; void *unk_10; NNSG2dCharacterData *unk_14; @@ -211,7 +202,7 @@ typedef struct ChooseStarterApp { VecFx32 unk_64C; ChooseStarterCursor unk_658; GXRgb edgeMarkings[8]; - UnkStruct_02015064 *spriteDisplay; + SoftwareSpriteManager *spriteDisplay; StarterPreviewWindow unk_6A8; int messageFrame; u32 unk_704; @@ -716,20 +707,20 @@ static void ov78_021D14BC(ChooseStarterApp *param0) static void MakeSpriteDisplay(ChooseStarterApp *param0, enum HeapID heapID) { - UnkStruct_ov22_022550D4 v0 = { - .unk_00 = 1, - .unk_04 = 1, - .unk_08 = 1, + SoftwareSpriteManagerTemplate v0 = { + .numSprites = 1, + .numChars = 1, + .numPalettes = 1, .heapID = HEAP_ID_SYSTEM }; v0.heapID = heapID; - param0->spriteDisplay = sub_02015064(&v0); + param0->spriteDisplay = SoftwareSpriteManager_New(&v0); } static void ov78_021D1518(ChooseStarterApp *param0) { - sub_020150A8(param0->spriteDisplay); + SoftwareSpriteManager_Free(param0->spriteDisplay); } static void MakeCellActors(ChooseStarterApp *param0, int heapID) @@ -1015,7 +1006,7 @@ static void DrawScene(ChooseStarterApp *param0) NNS_G2dSetupSoftwareSpriteCamera(); PokemonSpriteManager_DrawSprites(param0->spriteManager); - sub_020150EC(param0->spriteDisplay); + SoftwareSpriteManager_DrawVisible(param0->spriteDisplay); } NNS_G3dGePopMtx(1); @@ -1528,52 +1519,52 @@ static void ov78_021D243C(ChooseStarterCursor *param0, int param1, int param2) static void MakePreviewWindow(StarterPreviewWindow *param0, ChooseStarterApp *param1, int param2) { - UnkStruct_ov22_022557A0 v0; - UnkStruct_ov22_02255800 v1; - UnkStruct_ov21_021E7F40 v2; + SoftwareSpriteCharsTemplate v0; + SoftwareSpritePaletteTemplate v1; + SoftwareSpriteTemplate v2; param0->unk_0C = Graphics_GetCharData(NARC_INDEX_GRAPHIC__EV_POKESELECT, 14, 0, ¶m0->unk_14, param2); param0->unk_10 = Graphics_GetPlttData(NARC_INDEX_GRAPHIC__EV_POKESELECT, 15, ¶m0->unk_18, param2); - v0.unk_00 = param1->spriteDisplay; - v0.unk_04 = param0->unk_14; + v0.softSpriteMan = param1->spriteDisplay; + v0.charsData = param0->unk_14; - param0->unk_00 = sub_02015128(&v0); + param0->unk_00 = SoftwareSprite_LoadChars(&v0); - v1.unk_00 = param1->spriteDisplay; - v1.unk_04 = param0->unk_18; - v1.unk_08 = 1; + v1.softSpriteMan = param1->spriteDisplay; + v1.paletteData = param0->unk_18; + v1.paletteSlot = 1; - param0->unk_04 = sub_020151A4(&v1); + param0->unk_04 = SoftwareSprite_LoadPalette(&v1); - v2.unk_00 = param1->spriteDisplay; - v2.unk_04 = param0->unk_00; - v2.unk_08 = param0->unk_04; - v2.unk_0C = 0; - v2.unk_0E = 0; - v2.unk_10 = 0; - v2.unk_14 = 31; - v2.unk_18 = 1022; - v2.unk_1C = 0; + v2.softSpriteMan = param1->spriteDisplay; + v2.chars = param0->unk_00; + v2.palette = param0->unk_04; + v2.xPos = 0; + v2.yPos = 0; + v2.rotation = 0; + v2.alpha = 31; + v2.priority = 1022; + v2.paletteSlot = 0; - param0->unk_08 = sub_02015214(&v2); + param0->unk_08 = SoftwareSprite_Load(&v2); - sub_02015240(param0->unk_08, 0); - sub_02015268(param0->unk_08, 128 / 2, 128 / 2); + SoftwareSprite_SetVisible(param0->unk_08, 0); + SoftwareSprite_SetCenter(param0->unk_08, 128 / 2, 128 / 2); } static void ov78_021D24E4(StarterPreviewWindow *param0) { - sub_02015238(param0->unk_08); - sub_02015164(param0->unk_00); - sub_020151D4(param0->unk_04); + SoftwareSprite_Reset(param0->unk_08); + SoftwareSprite_FreeChars(param0->unk_00); + SoftwareSprite_FreePalette(param0->unk_04); Heap_Free(param0->unk_0C); Heap_Free(param0->unk_10); } static void ov78_021D2508(StarterPreviewWindow *param0, BOOL param1) { - sub_02015240(param0->unk_08, param1); + SoftwareSprite_SetVisible(param0->unk_08, param1); } static void ov78_021D2514(StarterPreviewWindow *param0, fx32 param1, fx32 param2, fx32 param3, fx32 param4, fx32 param5, fx32 param6, int param7) @@ -1616,8 +1607,8 @@ static void ov78_021D25A0(SysTask *param0, void *param1) v2 = v0->unk_1C.unk_00.unk_00 - ((128 / 2) * FX32_ONE); v3 = v0->unk_1C.unk_10.unk_00 - ((128 / 2) * FX32_ONE); - sub_02015254(v0->unk_08, v2 >> FX32_SHIFT, v3 >> FX32_SHIFT); - sub_02015270(v0->unk_08, v0->unk_1C.unk_20.unk_00, v0->unk_1C.unk_20.unk_00); + SoftwareSprite_SetPosition(v0->unk_08, v2 >> FX32_SHIFT, v3 >> FX32_SHIFT); + SoftwareSprite_SetScalingFactors(v0->unk_08, v0->unk_1C.unk_20.unk_00, v0->unk_1C.unk_20.unk_00); if ((v1 == 1) || (v0->unk_1C.unk_30 < 0)) { SysTask_Done(param0); diff --git a/src/meson.build b/src/meson.build index 1775b04648..f4e6b5c614 100644 --- a/src/meson.build +++ b/src/meson.build @@ -53,7 +53,7 @@ pokeplatinum_c = files( 'colored_arrow.c', 'unk_02014A84.c', 'unk_02014D38.c', - 'unk_02015064.c', + 'software_sprite.c', 'unk_0201567C.c', 'unk_020158A8.c', 'unk_02015920.c', diff --git a/src/overlay022/ov22_02254DE0.c b/src/overlay022/ov22_02254DE0.c index 6282431b81..a96e8d5090 100644 --- a/src/overlay022/ov22_02254DE0.c +++ b/src/overlay022/ov22_02254DE0.c @@ -3,21 +3,18 @@ #include #include -#include "struct_decls/struct_02015214_decl.h" - -#include "applications/pokedex/struct_ov21_021E7F40.h" #include "overlay022/ov22_02255094.h" #include "overlay022/struct_ov22_02254DE0.h" #include "overlay022/struct_ov22_0225500C.h" #include "overlay022/struct_ov22_02255040.h" #include "heap.h" +#include "software_sprite.h" #include "system.h" #include "touch_screen.h" -#include "unk_02015064.h" static UnkStruct_ov22_02255040 *ov22_02254FE0(UnkStruct_ov22_02254DE0 *param0); -static UnkStruct_02015214 *ov22_0225500C(UnkStruct_ov22_0225500C *param0); +static SoftwareSprite *ov22_0225500C(UnkStruct_ov22_0225500C *param0); static void ov22_02255040(UnkStruct_ov22_02255040 *param0, TouchScreenHitTable *hitTable); UnkStruct_ov22_02254DE0 *ov22_02254DE0(int param0, int heapID) @@ -100,14 +97,14 @@ BOOL ov22_02254EDC(UnkStruct_ov22_02255040 *param0, int param1, int param2) void ov22_02254EF4(UnkStruct_ov22_02255040 *param0, s16 param1, s16 param2) { - sub_02015254(param0->unk_04, param1, param2); + SoftwareSprite_SetPosition(param0->unk_04, param1, param2); } void ov22_02254F00(UnkStruct_ov22_02255040 *param0, int *param1, int *param2) { NNSG2dSVec2 v0; - v0 = sub_0201525C(param0->unk_04); + v0 = SoftwareSprite_GetPosition(param0->unk_04); *param1 = v0.x; *param2 = v0.y; } @@ -116,24 +113,24 @@ void ov22_02254F30(UnkStruct_ov22_02255040 *param0, int *param1, int *param2) { NNSG2dSVec2 v0; - v0 = sub_02015280(param0->unk_04); + v0 = SoftwareSprite_GetDimensions(param0->unk_04); *param1 = v0.x; *param2 = v0.y; } void ov22_02254F60(UnkStruct_ov22_02255040 *param0, BOOL param1) { - sub_02015240(param0->unk_04, param1); + SoftwareSprite_SetVisible(param0->unk_04, param1); } void ov22_02254F6C(UnkStruct_ov22_02255040 *param0, int param1) { - sub_0201528C(param0->unk_04, param1); + SoftwareSprite_SetPriority(param0->unk_04, param1); } int ov22_02254F78(UnkStruct_ov22_02255040 *param0) { - return sub_02015290(param0->unk_04); + return SoftwareSprite_GetPriority(param0->unk_04); } void ov22_02254F84(UnkStruct_ov22_02255040 *param0, int *param1, int *param2) @@ -180,27 +177,27 @@ static UnkStruct_ov22_02255040 *ov22_02254FE0(UnkStruct_ov22_02254DE0 *param0) return NULL; } -static UnkStruct_02015214 *ov22_0225500C(UnkStruct_ov22_0225500C *param0) +static SoftwareSprite *ov22_0225500C(UnkStruct_ov22_0225500C *param0) { - UnkStruct_ov21_021E7F40 v0; + SoftwareSpriteTemplate v0; - v0.unk_00 = param0->unk_04; - v0.unk_04 = param0->unk_08; - v0.unk_08 = param0->unk_0C; - v0.unk_0C = param0->unk_10; - v0.unk_0E = param0->unk_14; - v0.unk_10 = 0; - v0.unk_14 = 31; - v0.unk_18 = 0; - v0.unk_1C = param0->unk_1C; + v0.softSpriteMan = param0->unk_04; + v0.chars = param0->unk_08; + v0.palette = param0->unk_0C; + v0.xPos = param0->unk_10; + v0.yPos = param0->unk_14; + v0.rotation = 0; + v0.alpha = 31; + v0.priority = 0; + v0.paletteSlot = param0->unk_1C; - return sub_02015214(&v0); + return SoftwareSprite_Load(&v0); } static void ov22_02255040(UnkStruct_ov22_02255040 *param0, TouchScreenHitTable *hitTable) { - NNSG2dSVec2 v0 = sub_0201525C(param0->unk_04); - NNSG2dSVec2 v1 = sub_02015280(param0->unk_04); + NNSG2dSVec2 v0 = SoftwareSprite_GetPosition(param0->unk_04); + NNSG2dSVec2 v1 = SoftwareSprite_GetDimensions(param0->unk_04); hitTable->rect.top = v0.y; hitTable->rect.bottom = v0.y + v1.y; diff --git a/src/overlay022/ov22_02255094.c b/src/overlay022/ov22_02255094.c index 9b0268152b..d4114f6ab2 100644 --- a/src/overlay022/ov22_02255094.c +++ b/src/overlay022/ov22_02255094.c @@ -5,13 +5,8 @@ #include "constants/graphics.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" #include "struct_defs/struct_02099F80.h" -#include "overlay022/struct_ov22_022550D4.h" -#include "overlay022/struct_ov22_022557A0.h" -#include "overlay022/struct_ov22_02255800.h" #include "overlay022/struct_ov22_02255CB8.h" #include "overlay022/struct_ov22_0225A0E4.h" @@ -25,12 +20,12 @@ #include "pokemon_sprite.h" #include "render_oam.h" #include "resource_collection.h" +#include "software_sprite.h" #include "sprite.h" #include "sprite_resource.h" #include "sprite_transfer.h" #include "sprite_util.h" #include "system.h" -#include "unk_02015064.h" #include "unk_0202419C.h" static void ov22_02255634(void); @@ -38,7 +33,7 @@ static void ov22_02255654(void); static void ov22_022556DC(void); static void ov22_0225572C(void); static void ov22_02255738(void); -static void ov22_02255748(UnkStruct_ov22_0225A0E4 *param0, const UnkStruct_ov22_022550D4 *param1); +static void ov22_02255748(UnkStruct_ov22_0225A0E4 *param0, const SoftwareSpriteManagerTemplate *param1); static void ov22_02255784(UnkStruct_ov22_0225A0E4 *param0); static void ov22_02255794(UnkStruct_ov22_0225A0E4 *param0); static void ov22_02255C24(UnkStruct_ov22_0225A0E4 *param0, int heapID, int param2, int param3); @@ -50,8 +45,8 @@ static void ov22_02255A98(UnkStruct_ov22_0225A0E4 *param0); static void ov22_02255AC0(UnkStruct_ov22_0225A0E4 *param0); static void ov22_022559B4(UnkStruct_ov22_0225A0E4 *param0); static void ov22_022559E0(UnkStruct_ov22_0225A0E4 *param0); -static void ov22_022557A0(UnkStruct_ov22_0225A0E4 *param0, UnkStruct_ov22_022557A0 *param1, int param2); -static void ov22_02255800(UnkStruct_ov22_0225A0E4 *param0, UnkStruct_ov22_02255800 *param1, int param2); +static void ov22_022557A0(UnkStruct_ov22_0225A0E4 *param0, SoftwareSpriteCharsTemplate *param1, int param2); +static void ov22_02255800(UnkStruct_ov22_0225A0E4 *param0, SoftwareSpritePaletteTemplate *param1, int param2); static void ov22_02255860(UnkStruct_ov22_0225A0E4 *param0); static void ov22_02255984(UnkStruct_ov22_0225A0E4 *param0); static void ov22_02255CB8(UnkStruct_ov22_02255CB8 *param0, int param1, int param2, int heapID); @@ -83,10 +78,10 @@ void ov22_022550B4(void) void ov22_022550D4(UnkStruct_ov22_0225A0E4 *param0) { - UnkStruct_ov22_022550D4 v0 = { - .unk_00 = 718, - .unk_04 = 118, - .unk_08 = 19, + SoftwareSpriteManagerTemplate v0 = { + .numSprites = 718, + .numChars = 118, + .numPalettes = 19, .heapID = HEAP_ID_14 }; @@ -148,8 +143,8 @@ void ov22_022551B4(UnkStruct_ov22_0225A0E4 *param0, UnkStruct_ov22_02255CB8 *par void ov22_022551D0(UnkStruct_ov22_0225A0E4 *param0) { - sub_0201517C(param0->unk_00); - sub_020151EC(param0->unk_00); + SoftwareSpriteManager_FreeAllChars(param0->unk_00); + SoftwareSpriteManager_FreeAllPalettes(param0->unk_00); } Sprite *ov22_022551E4(UnkStruct_ov22_0225A0E4 *param0, int param1, int param2, int param3, int param4, int param5) @@ -294,7 +289,7 @@ int ov22_02255420(NNSG2dCharacterData *param0, int param1, int param2, int param return 0; } -void ov22_0225547C(UnkStruct_ov22_0225A0E4 *param0, const UnkStruct_ov22_022550D4 *param1, int heapID) +void ov22_0225547C(UnkStruct_ov22_0225A0E4 *param0, const SoftwareSpriteManagerTemplate *param1, int heapID) { ov22_02255748(param0, param1); ov22_02255C24(param0, heapID, 0x2800, 0x20); @@ -484,13 +479,13 @@ static void ov22_02255738(void) NNS_G2dInitOamManagerModule(); } -static void ov22_02255748(UnkStruct_ov22_0225A0E4 *param0, const UnkStruct_ov22_022550D4 *param1) +static void ov22_02255748(UnkStruct_ov22_0225A0E4 *param0, const SoftwareSpriteManagerTemplate *param1) { - param0->unk_00 = sub_02015064(param1); - param0->unk_04 = Heap_Alloc(param1->heapID, sizeof(UnkStruct_02015128 *) * (100 + 18)); + param0->unk_00 = SoftwareSpriteManager_New(param1); + param0->unk_04 = Heap_Alloc(param1->heapID, sizeof(SoftwareSpriteChars *) * (100 + 18)); param0->unk_08 = (100 + 18); param0->unk_0C = 0; - param0->unk_10 = Heap_Alloc(param1->heapID, sizeof(UnkStruct_020151A4 *) * (1 + 18)); + param0->unk_10 = Heap_Alloc(param1->heapID, sizeof(SoftwareSpritePalette *) * (1 + 18)); param0->unk_14 = (1 + 18); param0->unk_18 = 0; param0->unk_1C = 1; @@ -498,24 +493,24 @@ static void ov22_02255748(UnkStruct_ov22_0225A0E4 *param0, const UnkStruct_ov22_ static void ov22_02255784(UnkStruct_ov22_0225A0E4 *param0) { - sub_020150A8(param0->unk_00); + SoftwareSpriteManager_Free(param0->unk_00); param0->unk_00 = NULL; } static void ov22_02255794(UnkStruct_ov22_0225A0E4 *param0) { - sub_020150EC(param0->unk_00); + SoftwareSpriteManager_DrawVisible(param0->unk_00); } -static void ov22_022557A0(UnkStruct_ov22_0225A0E4 *param0, UnkStruct_ov22_022557A0 *param1, int param2) +static void ov22_022557A0(UnkStruct_ov22_0225A0E4 *param0, SoftwareSpriteCharsTemplate *param1, int param2) { int v0; for (v0 = 0; v0 < param2; v0++) { GF_ASSERT(param0->unk_0C < param0->unk_08); - if (param1[v0].unk_04 != NULL) { - param0->unk_04[param0->unk_0C] = sub_02015128(param1 + v0); + if (param1[v0].charsData != NULL) { + param0->unk_04[param0->unk_0C] = SoftwareSprite_LoadChars(param1 + v0); } else { param0->unk_04[param0->unk_0C] = NULL; } @@ -524,15 +519,15 @@ static void ov22_022557A0(UnkStruct_ov22_0225A0E4 *param0, UnkStruct_ov22_022557 } } -static void ov22_02255800(UnkStruct_ov22_0225A0E4 *param0, UnkStruct_ov22_02255800 *param1, int param2) +static void ov22_02255800(UnkStruct_ov22_0225A0E4 *param0, SoftwareSpritePaletteTemplate *param1, int param2) { int v0; for (v0 = 0; v0 < param2; v0++) { GF_ASSERT(param0->unk_18 < param0->unk_14); - if (param1[v0].unk_04 != NULL) { - param0->unk_10[param0->unk_18] = sub_020151A4(param1 + v0); + if (param1[v0].paletteData != NULL) { + param0->unk_10[param0->unk_18] = SoftwareSprite_LoadPalette(param1 + v0); } else { param0->unk_10[param0->unk_18] = NULL; } @@ -737,17 +732,17 @@ static void ov22_02255ACC(UnkStruct_ov22_0225A0E4 *param0, UnkStruct_ov22_02255C v1 = v0; - param1->unk_00[v1].unk_04 = ov22_02255340(param0, v2, v0); - param1->unk_00[v1].unk_00 = param0->unk_00; + param1->unk_00[v1].charsData = ov22_02255340(param0, v2, v0); + param1->unk_00[v1].softSpriteMan = param0->unk_00; } v2 = LoadMemberFromOpenNARC(param0->unk_5C, 0, 0, HEAP_ID_14, 1); ResourceCollection_Add(param1->unk_14, v2, 0); - NNS_G2dGetUnpackedPaletteData(v2, ¶m1->unk_08[0].unk_04); + NNS_G2dGetUnpackedPaletteData(v2, ¶m1->unk_08[0].paletteData); - param1->unk_08[0].unk_00 = param0->unk_00; - param1->unk_08[0].unk_08 = 3; + param1->unk_08[0].softSpriteMan = param0->unk_00; + param1->unk_08[0].paletteSlot = 3; } static void ov22_02255B50(UnkStruct_ov22_0225A0E4 *param0, UnkStruct_ov22_02255CB8 *param1) @@ -760,18 +755,18 @@ static void ov22_02255B50(UnkStruct_ov22_0225A0E4 *param0, UnkStruct_ov22_02255C v1 = LoadMemberFromOpenNARC(param0->unk_5C, v0 + 206, 0, HEAP_ID_14, 1); v2 = v0 + 100; - param1->unk_00[v2].unk_04 = ov22_02255340(param0, v1, v2); - param1->unk_00[v2].unk_00 = param0->unk_00; + param1->unk_00[v2].charsData = ov22_02255340(param0, v1, v2); + param1->unk_00[v2].softSpriteMan = param0->unk_00; v2 = v0 + 1; v1 = LoadMemberFromOpenNARC(param0->unk_5C, (v0) * 4 + 134 + 1, 0, HEAP_ID_14, 1); ResourceCollection_Add(param1->unk_14, v1, v2); - NNS_G2dGetUnpackedPaletteData(v1, ¶m1->unk_08[v2].unk_04); - GF_ASSERT(param1->unk_08[v2].unk_04); + NNS_G2dGetUnpackedPaletteData(v1, ¶m1->unk_08[v2].paletteData); + GF_ASSERT(param1->unk_08[v2].paletteData); - param1->unk_08[v2].unk_00 = param0->unk_00; - param1->unk_08[v2].unk_08 = 1; + param1->unk_08[v2].softSpriteMan = param0->unk_00; + param1->unk_08[v2].paletteSlot = 1; } } @@ -810,13 +805,13 @@ static void ov22_02255C90(UnkStruct_ov22_0225A0E4 *param0) static void ov22_02255CB8(UnkStruct_ov22_02255CB8 *param0, int param1, int param2, int heapID) { - param0->unk_00 = Heap_Alloc(heapID, sizeof(UnkStruct_ov22_022557A0) * param1); - memset(param0->unk_00, 0, sizeof(UnkStruct_ov22_022557A0) * param1); + param0->unk_00 = Heap_Alloc(heapID, sizeof(SoftwareSpriteCharsTemplate) * param1); + memset(param0->unk_00, 0, sizeof(SoftwareSpriteCharsTemplate) * param1); param0->unk_10 = ResourceCollection_New(param1, heapID); param0->unk_04 = param1; - param0->unk_08 = Heap_Alloc(heapID, sizeof(UnkStruct_ov22_02255800) * param2); - memset(param0->unk_08, 0, sizeof(UnkStruct_ov22_02255800) * param2); + param0->unk_08 = Heap_Alloc(heapID, sizeof(SoftwareSpritePaletteTemplate) * param2); + memset(param0->unk_08, 0, sizeof(SoftwareSpritePaletteTemplate) * param2); param0->unk_14 = ResourceCollection_New(param2, heapID); param0->unk_0C = param2; } diff --git a/src/overlay022/ov22_022578F4.c b/src/overlay022/ov22_022578F4.c index 944c52cb6b..3d3c668dee 100644 --- a/src/overlay022/ov22_022578F4.c +++ b/src/overlay022/ov22_022578F4.c @@ -20,8 +20,8 @@ #include "pokemon.h" #include "pokemon_sprite.h" +#include "software_sprite.h" #include "touch_screen.h" -#include "unk_02015064.h" static void ov22_02257DEC(UnkStruct_ov22_02257964 *param0, UnkStruct_ov22_02259560 *param1, BOOL param2, NNSG2dCharacterData **param3); static void ov22_02257EC8(UnkStruct_ov22_02259560 *param0, int *param1, int *param2); @@ -373,7 +373,7 @@ void ov22_02257D70(UnkStruct_ov22_02257964 *param0, GXRgb param1) if (v0->unk_04 == 0) { UnkStruct_ov22_02255040 *v1 = v0->unk_00; - sub_0201529C(v1->unk_04, param1); + SoftwareSprite_SetDiffuse(v1->unk_04, param1); } else { UnkStruct_020298D8 *v2 = v0->unk_00; @@ -390,7 +390,7 @@ void ov22_02257D70(UnkStruct_ov22_02257964 *param0, GXRgb param1) while (v0 != ¶m0->unk_00.unk_04) { UnkStruct_ov22_02255040 *v3 = v0->unk_00; - sub_0201529C(v3->unk_04, param1); + SoftwareSprite_SetDiffuse(v3->unk_04, param1); v0 = v0->unk_08; } } diff --git a/src/overlay022/ov22_0225AF8C.c b/src/overlay022/ov22_0225AF8C.c index f011b2ae33..f4e66b61a6 100644 --- a/src/overlay022/ov22_0225AF8C.c +++ b/src/overlay022/ov22_0225AF8C.c @@ -15,7 +15,6 @@ #include "overlay022/ov22_02259484.h" #include "overlay022/ov22_0225AF44.h" #include "overlay022/struct_ov22_02254DE0.h" -#include "overlay022/struct_ov22_022550D4.h" #include "overlay022/struct_ov22_02255CB8.h" #include "overlay022/struct_ov22_02257964.h" #include "overlay022/struct_ov22_02259484.h" @@ -30,6 +29,7 @@ #include "narc.h" #include "pokemon.h" #include "resource_collection.h" +#include "software_sprite.h" #include "unk_020298BC.h" typedef struct UnkStruct_ov22_0225B1BC_t { @@ -293,13 +293,13 @@ static UnkStruct_ov22_0225B1BC *ov22_0225B258(const UnkStruct_ov22_0225B4E4 *par static void ov22_0225B2D4(UnkStruct_ov22_0225B1BC *param0, const UnkStruct_ov22_0225B4E4 *param1) { UnkStruct_ov22_02255CB8 v0; - UnkStruct_ov22_022550D4 v1; + SoftwareSpriteManagerTemplate v1; param0->unk_00.unk_5C = NARC_ctor(NARC_INDEX_GRAPHIC__IMAGECLIP, param1->heapID); - v1.unk_00 = (700 + 18); - v1.unk_04 = (100 + 18); - v1.unk_08 = (1 + 18); + v1.numSprites = (700 + 18); + v1.numChars = (100 + 18); + v1.numPalettes = (1 + 18); v1.heapID = param1->heapID; ov22_0225547C(¶m0->unk_00, &v1, param1->heapID); @@ -466,17 +466,17 @@ static void ov22_0225B5A8(UnkStruct_ov22_0225A0E4 *param0, UnkStruct_ov22_02255C v2 = LoadMemberFromOpenNARC(param0->unk_5C, v3 + 1, 0, heapID, 1); ResourceCollection_Add(param1->unk_10, v2, v1); - NNS_G2dGetUnpackedCharacterData(v2, ¶m1->unk_00[v1].unk_04); + NNS_G2dGetUnpackedCharacterData(v2, ¶m1->unk_00[v1].charsData); - param1->unk_00[v1].unk_00 = param0->unk_00; + param1->unk_00[v1].softSpriteMan = param0->unk_00; } } v2 = LoadMemberFromOpenNARC(param0->unk_5C, 0, 0, heapID, 1); ResourceCollection_Add(param1->unk_14, v2, 0); - NNS_G2dGetUnpackedPaletteData(v2, ¶m1->unk_08[0].unk_04); + NNS_G2dGetUnpackedPaletteData(v2, ¶m1->unk_08[0].paletteData); - param1->unk_08[0].unk_00 = param0->unk_00; - param1->unk_08[0].unk_08 = 3; + param1->unk_08[0].softSpriteMan = param0->unk_00; + param1->unk_08[0].paletteSlot = 3; } diff --git a/src/overlay083/ov83_0223C958.c b/src/overlay083/ov83_0223C958.c index c49813dd5d..ef1ea637e6 100644 --- a/src/overlay083/ov83_0223C958.c +++ b/src/overlay083/ov83_0223C958.c @@ -7,7 +7,6 @@ #include "struct_defs/struct_02099F80.h" -#include "overlay022/struct_ov22_022550D4.h" #include "overlay083/ov83_0223D6A8.h" #include "overlay083/struct_ov83_0223B784.h" @@ -19,11 +18,11 @@ #include "narc.h" #include "pltt_transfer.h" #include "render_oam.h" +#include "software_sprite.h" #include "sprite.h" #include "strbuf.h" #include "string_template.h" #include "system.h" -#include "unk_02015064.h" #include "unk_0202419C.h" static void ov83_0223CC30(BgConfig **param0, int heapID); @@ -120,7 +119,7 @@ void ov83_0223CBA4(UnkStruct_ov83_0223B784 *param0) NNS_G2dSetupSoftwareSpriteCamera(); if (param0->unk_320) { - sub_020150EC(param0->unk_320); + SoftwareSpriteManager_DrawVisible(param0->unk_320); } } @@ -276,20 +275,20 @@ static void ov83_0223CD1C(UnkStruct_ov83_0223B784 *param0) static void ov83_0223CD28(UnkStruct_ov83_0223B784 *param0) { - UnkStruct_ov22_022550D4 v0 = { - .unk_00 = 48, - .unk_04 = 32, - .unk_08 = 32, + SoftwareSpriteManagerTemplate v0 = { + .numSprites = 48, + .numChars = 32, + .numPalettes = 32, .heapID = HEAP_ID_SYSTEM }; v0.heapID = param0->heapID; - param0->unk_320 = sub_02015064(&v0); + param0->unk_320 = SoftwareSpriteManager_New(&v0); } static void ov83_0223CD54(UnkStruct_ov83_0223B784 *param0) { - sub_020150A8(param0->unk_320); + SoftwareSpriteManager_Free(param0->unk_320); } static void ov83_0223CD64(UnkStruct_ov83_0223B784 *param0) diff --git a/src/overlay083/ov83_0223D6A8.c b/src/overlay083/ov83_0223D6A8.c index d842f3aaeb..88691a01db 100644 --- a/src/overlay083/ov83_0223D6A8.c +++ b/src/overlay083/ov83_0223D6A8.c @@ -3,15 +3,8 @@ #include #include -#include "struct_decls/struct_02015064_decl.h" -#include "struct_decls/struct_02015128_decl.h" -#include "struct_decls/struct_020151A4_decl.h" -#include "struct_decls/struct_02015214_decl.h" #include "struct_defs/struct_02015958.h" -#include "applications/pokedex/struct_ov21_021E7F40.h" -#include "overlay022/struct_ov22_022557A0.h" -#include "overlay022/struct_ov22_02255800.h" #include "overlay083/ov83_0223D4CC.h" #include "overlay083/struct_ov83_0223D4CC_decl.h" #include "overlay083/struct_ov83_0223D784.h" @@ -46,6 +39,7 @@ #include "math_util.h" #include "narc.h" #include "render_window.h" +#include "software_sprite.h" #include "sound_playback.h" #include "sprite.h" #include "sprite_resource.h" @@ -56,7 +50,6 @@ #include "sys_task.h" #include "sys_task_manager.h" #include "text.h" -#include "unk_02015064.h" #include "unk_02015920.h" #include "unk_02098FFC.h" @@ -122,58 +115,58 @@ static int ov83_0223D6A8(int param0, const Strbuf *param1, int param2) return param0; } -static UnkStruct_02015128 *ov83_0223D6BC(UnkStruct_02015064 *param0, u32 param1, u32 param2, NARC *param3) +static SoftwareSpriteChars *ov83_0223D6BC(SoftwareSpriteManager *param0, u32 param1, u32 param2, NARC *param3) { - UnkStruct_ov22_022557A0 v0; + SoftwareSpriteCharsTemplate v0; void *v1; NNSG2dCharacterData *v2; - UnkStruct_02015128 *v3; + SoftwareSpriteChars *v3; v1 = Graphics_GetCharDataFromOpenNARC(param3, param1, 0, &v2, param2); - v0.unk_00 = param0; - v0.unk_04 = v2; - v3 = sub_02015128(&v0); + v0.softSpriteMan = param0; + v0.charsData = v2; + v3 = SoftwareSprite_LoadChars(&v0); Heap_Free(v1); return v3; } -static UnkStruct_020151A4 *ov83_0223D6EC(UnkStruct_02015064 *param0, u32 param1, u32 param2, NARC *param3) +static SoftwareSpritePalette *ov83_0223D6EC(SoftwareSpriteManager *param0, u32 param1, u32 param2, NARC *param3) { - UnkStruct_ov22_02255800 v0; + SoftwareSpritePaletteTemplate v0; void *v1; NNSG2dPaletteData *v2; - UnkStruct_020151A4 *v3; + SoftwareSpritePalette *v3; v1 = Graphics_GetPlttDataFromOpenNARC(param3, param1, &v2, param2); - v0.unk_00 = param0; - v0.unk_04 = v2; - v0.unk_08 = 1; - v3 = sub_020151A4(&v0); + v0.softSpriteMan = param0; + v0.paletteData = v2; + v0.paletteSlot = 1; + v3 = SoftwareSprite_LoadPalette(&v0); Heap_Free(v1); return v3; } -static UnkStruct_02015214 *ov83_0223D720(UnkStruct_02015064 *param0, UnkStruct_02015128 *param1, UnkStruct_020151A4 *param2, int param3, int param4, int param5) +static SoftwareSprite *ov83_0223D720(SoftwareSpriteManager *param0, SoftwareSpriteChars *param1, SoftwareSpritePalette *param2, int param3, int param4, int param5) { - UnkStruct_ov21_021E7F40 v0; - UnkStruct_02015214 *v1; + SoftwareSpriteTemplate v0; + SoftwareSprite *v1; - v0.unk_00 = param0; - v0.unk_04 = param1; - v0.unk_08 = param2; - v0.unk_0C = param3; - v0.unk_0E = param4; - v0.unk_10 = 0; - v0.unk_14 = 31; - v0.unk_18 = param5; - v0.unk_1C = 0; + v0.softSpriteMan = param0; + v0.chars = param1; + v0.palette = param2; + v0.xPos = param3; + v0.yPos = param4; + v0.rotation = 0; + v0.alpha = 31; + v0.priority = param5; + v0.paletteSlot = 0; - v1 = sub_02015214(&v0); - sub_02015240(v1, 0); + v1 = SoftwareSprite_Load(&v0); + SoftwareSprite_SetVisible(v1, 0); return v1; } @@ -757,7 +750,7 @@ void ov83_0223E34C(UnkStruct_ov83_0223E340 *param0) memset(param0, 0, sizeof(UnkStruct_ov83_0223E340)); } -void ov83_0223E368(UnkStruct_ov83_0223E340 *param0, UnkStruct_02015064 *param1, u32 param2, NARC *param3) +void ov83_0223E368(UnkStruct_ov83_0223E340 *param0, SoftwareSpriteManager *param1, u32 param2, NARC *param3) { int v0; static const u8 v1[] = { @@ -831,7 +824,7 @@ void ov83_0223E368(UnkStruct_ov83_0223E340 *param0, UnkStruct_02015064 *param1, for (v0 = 0; v0 < 8; v0++) { param0->unk_38[v0] = ov83_0223D720(param1, param0->unk_00[v3[v0]], param0->unk_18[v0], v5[v0], v6[v0], v4[v0]); - sub_02015268(param0->unk_38[v0], 128 - v5[v0], 96 - v6[v0]); + SoftwareSprite_SetCenter(param0->unk_38[v0], 128 - v5[v0], 96 - v6[v0]); } param0->unk_74 = 1; @@ -844,15 +837,15 @@ void ov83_0223E438(UnkStruct_ov83_0223E340 *param0) GF_ASSERT(param0->unk_74 == 1); for (v0 = 0; v0 < 8; v0++) { - sub_02015238(param0->unk_38[v0]); + SoftwareSprite_Reset(param0->unk_38[v0]); } for (v0 = 0; v0 < 6; v0++) { - sub_02015164(param0->unk_00[v0]); + SoftwareSprite_FreeChars(param0->unk_00[v0]); } for (v0 = 0; v0 < 8; v0++) { - sub_020151D4(param0->unk_18[v0]); + SoftwareSprite_FreePalette(param0->unk_18[v0]); } param0->unk_74 = 0; @@ -861,7 +854,7 @@ void ov83_0223E438(UnkStruct_ov83_0223E340 *param0) void ov83_0223E484(UnkStruct_ov83_0223E340 *param0, u32 param1, BOOL param2) { GF_ASSERT(param1 < 8); - sub_02015240(param0->unk_38[param1], param2); + SoftwareSprite_SetVisible(param0->unk_38[param1], param2); } void ov83_0223E4A4(UnkStruct_ov83_0223E340 *param0, u16 param1) @@ -869,7 +862,7 @@ void ov83_0223E4A4(UnkStruct_ov83_0223E340 *param0, u16 param1) int v0; for (v0 = 5; v0 <= 7; v0++) { - sub_020152BC(param0->unk_38[v0], param1); + SoftwareSprite_SetRotation(param0->unk_38[v0], param1); } } @@ -878,14 +871,14 @@ void ov83_0223E4C0(UnkStruct_ov83_0223E340 *param0, fx32 param1) int v0; for (v0 = 5; v0 <= 7; v0++) { - sub_02015270(param0->unk_38[v0], param1, param1); + SoftwareSprite_SetScalingFactors(param0->unk_38[v0], param1, param1); } } void ov83_0223E4E0(UnkStruct_ov83_0223E340 *param0, u32 param1, u32 param2) { GF_ASSERT(param1 < 8); - sub_02015294(param0->unk_38[param1], param2); + SoftwareSprite_SetAlpha(param0->unk_38[param1], param2); } void ov83_0223E500(UnkStruct_ov83_0223E340 *param0) @@ -915,7 +908,7 @@ void ov83_0223E51C(UnkStruct_ov83_0223E340 *param0, int param1) v0 = ov83_0223D9EC(¶m0->unk_58); for (v1 = 0; v1 <= 2; v1++) { - sub_02015270(param0->unk_38[v1], param0->unk_58.unk_00, param0->unk_58.unk_00); + SoftwareSprite_SetScalingFactors(param0->unk_38[v1], param0->unk_58.unk_00, param0->unk_58.unk_00); } if (v0 == 1) { diff --git a/src/software_sprite.c b/src/software_sprite.c new file mode 100644 index 0000000000..82d7ce3525 --- /dev/null +++ b/src/software_sprite.c @@ -0,0 +1,467 @@ +#include "software_sprite.h" + +#include +#include +#include +#include +#include + +#include "constants/colors.h" +#include "constants/graphics.h" +#include "constants/heap.h" + +#include "heap.h" + +struct SoftwareSpriteChars { + NNSGfdTexKey vramKey; + NNSG2dImageProxy proxy; +}; + +struct SoftwareSpritePalette { + NNSGfdPlttKey vramKey; + NNSG2dImagePaletteProxy proxy; +}; + +struct SoftwareSprite { + NNSG2dSVec2 position; + NNSG2dSVec2 center; + NNSG2dSVec2 dimensions; + fx32 scaleX; + fx32 scaleY; + int priority; + int rotation; + BOOL inUse; + BOOL visible; + NNSG2dImageAttr *attributes; + u32 vramAddressChars; + u32 vramAddressPalette; + u32 paletteSlot; + BOOL flipH; + BOOL flipV; + GXRgb diffuse; + u8 alpha; +}; + +struct SoftwareSpriteManager { + SoftwareSprite *sprites; + int numSprites; + SoftwareSpriteChars *chars; + int numChars; + SoftwareSpritePalette *palettes; + int numPalettes; +}; + +static SoftwareSprite *NewSprites(int count, enum HeapID heapID); +static SoftwareSpriteChars *NewSpriteChars(int count, enum HeapID heapID); +static SoftwareSpritePalette *NewSpritePalettes(int count, enum HeapID heapID); + +static void ZeroSprite(SoftwareSprite *sprite); +static void ZeroChars(SoftwareSpriteChars *chars); +static void ZeroPalette(SoftwareSpritePalette *palette); + +static SoftwareSprite *FindAvailableSprite(SoftwareSpriteManager *softSpriteMan); +static SoftwareSpriteChars *FindAvailableChars(SoftwareSpriteManager *softSpriteMan); +static SoftwareSpritePalette *FindAvailablePalette(SoftwareSpriteManager *softSpriteMan); + +static NNSGfdTexKey AllocateVRAM_Chars(NNSG2dCharacterData *charsData); +static NNSGfdPlttKey AllocateVRAM_Palette(int paletteSlot); +static void LoadProxy_Chars(NNSG2dCharacterData *charsData, NNSGfdTexKey vramKey, NNSG2dImageProxy *proxy); +static void LoadProxy_Palette(NNSG2dPaletteData *paletteData, NNSGfdPlttKey vramKey, NNSG2dImagePaletteProxy *proxy); + +static void DrawSprite(SoftwareSprite *sprite); +static void LoadSprite(SoftwareSprite *sprite, const SoftwareSpriteTemplate *template); + +SoftwareSpriteManager *SoftwareSpriteManager_New(const SoftwareSpriteManagerTemplate *template) +{ + SoftwareSpriteManager *softSpriteMan = Heap_Alloc(template->heapID, sizeof(SoftwareSpriteManager)); + GF_ASSERT(softSpriteMan); + + softSpriteMan->sprites = NewSprites(template->numSprites, template->heapID); + softSpriteMan->numSprites = template->numSprites; + softSpriteMan->chars = NewSpriteChars(template->numChars, template->heapID); + softSpriteMan->numChars = template->numChars; + softSpriteMan->palettes = NewSpritePalettes(template->numPalettes, template->heapID); + softSpriteMan->numPalettes = template->numPalettes; + + return softSpriteMan; +} + +void SoftwareSpriteManager_Free(SoftwareSpriteManager *softSpriteMan) +{ + GF_ASSERT(softSpriteMan); + GF_ASSERT(softSpriteMan->sprites); + GF_ASSERT(softSpriteMan->chars); + GF_ASSERT(softSpriteMan->palettes); + + Heap_Free(softSpriteMan->sprites); + Heap_Free(softSpriteMan->chars); + Heap_Free(softSpriteMan->palettes); + Heap_Free(softSpriteMan); + + softSpriteMan = NULL; +} + +void SoftwareSpriteManager_DrawVisible(SoftwareSpriteManager *manager) +{ + G3_PushMtx(); + + for (int i = 0; i < manager->numSprites; i++) { + if (manager->sprites[i].visible) { + DrawSprite(manager->sprites + i); + } + } + + G3_PopMtx(1); +} + +SoftwareSpriteChars *SoftwareSprite_LoadChars(const SoftwareSpriteCharsTemplate *template) +{ + SoftwareSpriteChars *chars = FindAvailableChars(template->softSpriteMan); + GF_ASSERT(chars); + GF_ASSERT(template->charsData->mapingType == GX_OBJVRAMMODE_CHAR_2D); + + chars->vramKey = AllocateVRAM_Chars(template->charsData); + GF_ASSERT(chars->vramKey); + + LoadProxy_Chars(template->charsData, chars->vramKey, &chars->proxy); + return chars; +} + +void SoftwareSprite_FreeChars(SoftwareSpriteChars *chars) +{ + NNS_GfdFreeTexVram(chars->vramKey); + ZeroChars(chars); +} + +void SoftwareSpriteManager_FreeAllChars(SoftwareSpriteManager *softSpriteMan) +{ + for (int i = 0; i < softSpriteMan->numChars; i++) { + if (softSpriteMan->chars[i].vramKey) { + SoftwareSprite_FreeChars(softSpriteMan->chars + i); + } + } +} + +SoftwareSpritePalette *SoftwareSprite_LoadPalette(const SoftwareSpritePaletteTemplate *template) +{ + SoftwareSpritePalette *palette = FindAvailablePalette(template->softSpriteMan); + GF_ASSERT(palette); + + palette->vramKey = AllocateVRAM_Palette(template->paletteSlot); + GF_ASSERT(palette->vramKey); + + LoadProxy_Palette(template->paletteData, palette->vramKey, &palette->proxy); + return palette; +} + +void SoftwareSprite_FreePalette(SoftwareSpritePalette *palette) +{ + NNS_GfdFreePlttVram(palette->vramKey); + ZeroPalette(palette); +} + +void SoftwareSpriteManager_FreeAllPalettes(SoftwareSpriteManager *softSpriteMan) +{ + for (int i = 0; i < softSpriteMan->numPalettes; i++) { + if (softSpriteMan->palettes[i].vramKey) { + SoftwareSprite_FreePalette(softSpriteMan->palettes + i); + } + } +} + +SoftwareSprite *SoftwareSprite_Load(const SoftwareSpriteTemplate *template) +{ + SoftwareSprite *sprite = FindAvailableSprite(template->softSpriteMan); + GF_ASSERT(sprite); + + LoadSprite(sprite, template); + sprite->inUse = TRUE; + sprite->visible = TRUE; + return sprite; +} + +void SoftwareSprite_Reset(SoftwareSprite *sprite) +{ + ZeroSprite(sprite); +} + +void SoftwareSprite_SetVisible(SoftwareSprite *sprite, BOOL visible) +{ + GF_ASSERT(sprite); + sprite->visible = visible; +} + +void SoftwareSprite_SetPosition(SoftwareSprite *sprite, s16 x, s16 y) +{ + sprite->position.x = x; + sprite->position.y = y; +} + +NNSG2dSVec2 SoftwareSprite_GetPosition(SoftwareSprite *sprite) +{ + return sprite->position; +} + +void SoftwareSprite_SetCenter(SoftwareSprite *sprite, s16 x, s16 y) +{ + sprite->center.x = x; + sprite->center.y = y; +} + +void SoftwareSprite_SetScalingFactors(SoftwareSprite *sprite, fx32 scaleX, fx32 scaleY) +{ + sprite->scaleX = scaleX; + sprite->scaleY = scaleY; +} + +void SoftwareSprite_SetDimensions(SoftwareSprite *sprite, int x, int y) +{ + sprite->dimensions.x = x; + sprite->dimensions.y = y; +} + +NNSG2dSVec2 SoftwareSprite_GetDimensions(SoftwareSprite *sprite) +{ + return sprite->dimensions; +} + +void SoftwareSprite_SetPriority(SoftwareSprite *sprite, int priority) +{ + sprite->priority = priority; +} + +int SoftwareSprite_GetPriority(SoftwareSprite *sprite) +{ + return sprite->priority; +} + +void SoftwareSprite_SetAlpha(SoftwareSprite *sprite, u8 alpha) +{ + sprite->alpha = alpha; +} + +void SoftwareSprite_SetDiffuse(SoftwareSprite *sprite, GXRgb diffuse) +{ + sprite->diffuse = diffuse; +} + +void SoftwareSprite_SetAttributes(SoftwareSprite *sprite, NNSG2dImageAttr *attributes) +{ + sprite->attributes = attributes; +} + +void SoftwareSprite_SetVRAMAddress_Chars(SoftwareSprite *sprite, u32 address) +{ + sprite->vramAddressChars = address; +} + +void SoftwareSprite_SetVRAMAddress_Palette(SoftwareSprite *sprite, u32 address) +{ + sprite->vramAddressPalette = address; +} + +void SoftwareSprite_SetPaletteSlot(SoftwareSprite *sprite, u32 offset) +{ + sprite->paletteSlot = offset; +} + +void SoftwareSprite_SetFlip(SoftwareSprite *sprite, int direction, BOOL flip) +{ + if (direction == SPRITE_FLIP_H) { + sprite->flipH = flip; + } else { + sprite->flipV = flip; + } +} + +void SoftwareSprite_SetRotation(SoftwareSprite *sprite, u16 rotation) +{ + sprite->rotation = rotation; +} + +static void ZeroSprite(SoftwareSprite *sprite) +{ + memset(sprite, 0, sizeof(SoftwareSprite)); + sprite->alpha = 31; + sprite->diffuse = COLOR_WHITE; +} + +static void ZeroChars(SoftwareSpriteChars *chars) +{ + chars->vramKey = 0; + NNS_G2dInitImageProxy(&chars->proxy); +} + +static void ZeroPalette(SoftwareSpritePalette *palette) +{ + palette->vramKey = 0; + NNS_G2dInitImagePaletteProxy(&palette->proxy); +} + +static SoftwareSprite *NewSprites(int count, enum HeapID heapID) +{ + SoftwareSprite *sprites = Heap_Alloc(heapID, sizeof(SoftwareSprite) * count); + GF_ASSERT(sprites); + + for (int i = 0; i < count; i++) { + ZeroSprite(sprites + i); + } + + return sprites; +} + +static SoftwareSpriteChars *NewSpriteChars(int count, enum HeapID heapID) +{ + SoftwareSpriteChars *chars = Heap_Alloc(heapID, sizeof(SoftwareSpriteChars) * count); + GF_ASSERT(chars); + + for (int i = 0; i < count; i++) { + ZeroChars(chars + i); + } + + return chars; +} + +static SoftwareSpritePalette *NewSpritePalettes(int count, enum HeapID heapID) +{ + SoftwareSpritePalette *palettes = Heap_Alloc(heapID, sizeof(SoftwareSpritePalette) * count); + GF_ASSERT(palettes); + + for (int i = 0; i < count; i++) { + ZeroPalette(palettes + i); + } + + return palettes; +} + +static SoftwareSprite *FindAvailableSprite(SoftwareSpriteManager *softSpriteMan) +{ + for (int i = 0; i < softSpriteMan->numSprites; i++) { + if (softSpriteMan->sprites[i].inUse == FALSE) { + return softSpriteMan->sprites + i; + } + } + + return NULL; +} + +static SoftwareSpriteChars *FindAvailableChars(SoftwareSpriteManager *softSpriteMan) +{ + for (int i = 0; i < softSpriteMan->numSprites; i++) { + if (softSpriteMan->chars[i].vramKey == 0) { + return softSpriteMan->chars + i; + } + } + + return NULL; +} + +static SoftwareSpritePalette *FindAvailablePalette(SoftwareSpriteManager *softSpriteMan) +{ + for (int i = 0; i < softSpriteMan->numSprites; i++) { + if (softSpriteMan->palettes[i].vramKey == 0) { + return softSpriteMan->palettes + i; + } + } + + return NULL; +} + +static NNSGfdTexKey AllocateVRAM_Chars(NNSG2dCharacterData *charsData) +{ + return NNS_GfdAllocTexVram(charsData->szByte, FALSE, 0); +} + +static NNSGfdPlttKey AllocateVRAM_Palette(int paletteSlot) +{ + return NNS_GfdAllocPlttVram(PLTT_OFFSET(paletteSlot), FALSE, 0); +} + +static void LoadProxy_Chars(NNSG2dCharacterData *charsData, NNSGfdTexKey vramKey, NNSG2dImageProxy *proxy) +{ + NNS_G2dLoadImage2DMapping(charsData, NNS_GfdGetTexKeyAddr(vramKey), NNS_G2D_VRAM_TYPE_3DMAIN, proxy); +} + +static void LoadProxy_Palette(NNSG2dPaletteData *paletteData, NNSGfdPlttKey vramKey, NNSG2dImagePaletteProxy *proxy) +{ + int size = paletteData->szByte; + paletteData->szByte = NNS_GfdGetPlttKeySize(vramKey); + + NNS_G2dLoadPalette(paletteData, NNS_GfdGetPlttKeyAddr(vramKey), NNS_G2D_VRAM_TYPE_3DMAIN, proxy); + paletteData->szByte = size; +} + +static void DrawSprite(SoftwareSprite *sprite) +{ + G3_PushMtx(); + G3_MaterialColorDiffAmb(sprite->diffuse, COLOR_WHITE, TRUE); + G3_MaterialColorSpecEmi(COLOR_GRAY, COLOR_BLACK, FALSE); + G3_TexImageParam( + sprite->attributes->fmt, + GX_TEXGEN_TEXCOORD, + sprite->attributes->sizeS, + sprite->attributes->sizeT, + GX_TEXREPEAT_NONE, + GX_TEXFLIP_NONE, + sprite->attributes->plttUse, + sprite->vramAddressChars); + G3_TexPlttBase(sprite->vramAddressPalette + PLTT_OFFSET(sprite->paletteSlot), sprite->attributes->fmt); + G3_PolygonAttr(GX_LIGHTMASK_NONE, GX_POLYGONMODE_MODULATE, GX_CULL_NONE, 0, sprite->alpha, 0); + + NNSG2dSVec2 uv0, uv1; + if (sprite->flipH) { + uv0.x = sprite->dimensions.x; + uv1.x = 0; + } else { + uv1.x = sprite->dimensions.x; + uv0.x = 0; + } + + if (sprite->flipV) { + uv0.y = sprite->dimensions.y; + uv1.y = 0; + } else { + uv1.y = sprite->dimensions.y; + uv0.y = 0; + } + + G3_Translate( + (sprite->position.x + sprite->center.x) * FX32_ONE, + (sprite->position.y + sprite->center.y) * FX32_ONE, + sprite->priority * FX32_ONE); + G3_RotZ(FX_SinIdx(sprite->rotation), FX_CosIdx(sprite->rotation)); + G3_Scale(sprite->scaleX, sprite->scaleY, FX32_ONE); + G3_Translate(-sprite->center.x * FX32_ONE, -sprite->center.y * FX32_ONE, 0); + NNS_G2dDrawSpriteFast(0, 0, 0, sprite->dimensions.x, sprite->dimensions.y, uv0.x, uv0.y, uv1.x, uv1.y); + G3_PopMtx(1); +} + +static void LoadSprite(SoftwareSprite *sprite, const SoftwareSpriteTemplate *template) +{ + int dimenX = 8; + for (int i = 0; i < template->chars->proxy.attr.sizeS; i++) { + dimenX *= 2; + } + + int dimenY = 8; + for (int i = 0; i < template->chars->proxy.attr.sizeT; i++) { + dimenY *= 2; + } + + SoftwareSprite_SetPosition(sprite, template->xPos, template->yPos); + SoftwareSprite_SetCenter(sprite, dimenX / 2, dimenY / 2); + + sprite->scaleX = FX32_ONE; + sprite->scaleY = FX32_ONE; + + SoftwareSprite_SetDimensions(sprite, dimenX, dimenY); + SoftwareSprite_SetPriority(sprite, template->priority); + SoftwareSprite_SetAlpha(sprite, template->alpha); + SoftwareSprite_SetAttributes(sprite, &template->chars->proxy.attr); + SoftwareSprite_SetVRAMAddress_Chars(sprite, NNS_G2dGetImageLocation(&template->chars->proxy, NNS_G2D_VRAM_TYPE_3DMAIN)); + SoftwareSprite_SetVRAMAddress_Palette(sprite, NNS_G2dGetImagePaletteLocation(&template->palette->proxy, NNS_G2D_VRAM_TYPE_3DMAIN)); + SoftwareSprite_SetPaletteSlot(sprite, template->paletteSlot); + SoftwareSprite_SetFlip(sprite, SPRITE_FLIP_H, FALSE); + SoftwareSprite_SetFlip(sprite, SPRITE_FLIP_V, FALSE); + SoftwareSprite_SetRotation(sprite, template->rotation); +} diff --git a/src/unk_02015064.c b/src/unk_02015064.c deleted file mode 100644 index 310345bfd1..0000000000 --- a/src/unk_02015064.c +++ /dev/null @@ -1,478 +0,0 @@ -#include "unk_02015064.h" - -#include -#include - -#include "applications/pokedex/struct_ov21_021E7F40.h" -#include "overlay022/struct_ov22_022550D4.h" -#include "overlay022/struct_ov22_022557A0.h" -#include "overlay022/struct_ov22_02255800.h" - -#include "heap.h" - -typedef struct UnkStruct_02015128_t { - NNSGfdTexKey unk_00; - NNSG2dImageProxy unk_04; -} UnkStruct_02015128; - -typedef struct UnkStruct_020151A4_t { - NNSGfdPlttKey unk_00; - NNSG2dImagePaletteProxy unk_04; -} UnkStruct_020151A4; - -typedef struct UnkStruct_02015214_t { - NNSG2dSVec2 unk_00; - NNSG2dSVec2 unk_04; - NNSG2dSVec2 unk_08; - fx32 unk_0C; - fx32 unk_10; - int unk_14; - int unk_18; - BOOL unk_1C; - BOOL unk_20; - NNSG2dImageAttr *unk_24; - u32 unk_28; - u32 unk_2C; - u32 unk_30; - BOOL unk_34; - BOOL unk_38; - GXRgb unk_3C; - u8 unk_3E; -} UnkStruct_02015214; - -typedef struct UnkStruct_02015064_t { - UnkStruct_02015214 *unk_00; - int unk_04; - UnkStruct_02015128 *unk_08; - int unk_0C; - UnkStruct_020151A4 *unk_10; - int unk_14; -} UnkStruct_02015064; - -static void sub_020152C0(UnkStruct_02015214 *param0); -static void sub_020152E0(UnkStruct_02015128 *param0); -static void sub_020152EC(UnkStruct_020151A4 *param0); -static void sub_02015468(UnkStruct_02015214 *param0); -static UnkStruct_02015214 *sub_020152F8(int param0, int heapID); -static UnkStruct_02015128 *sub_02015328(int param0, int heapID); -static UnkStruct_020151A4 *sub_02015358(int param0, int heapID); -static UnkStruct_02015214 *sub_02015388(UnkStruct_02015064 *param0); -static UnkStruct_02015128 *sub_020153B4(UnkStruct_02015064 *param0); -static UnkStruct_020151A4 *sub_020153E0(UnkStruct_02015064 *param0); -static NNSGfdTexKey sub_0201540C(NNSG2dCharacterData *param0); -static NNSGfdPlttKey sub_02015420(int param0); -static void sub_02015434(NNSG2dCharacterData *param0, NNSGfdTexKey param1, NNSG2dImageProxy *param2); -static void sub_02015444(NNSG2dPaletteData *param0, NNSGfdPlttKey param1, NNSG2dImagePaletteProxy *param2); -static void sub_020155A8(UnkStruct_02015214 *param0, const UnkStruct_ov21_021E7F40 *param1); - -UnkStruct_02015064 *sub_02015064(const UnkStruct_ov22_022550D4 *param0) -{ - UnkStruct_02015064 *v0; - int v1; - - v0 = Heap_Alloc(param0->heapID, sizeof(UnkStruct_02015064)); - GF_ASSERT(v0); - - v0->unk_00 = sub_020152F8(param0->unk_00, param0->heapID); - v0->unk_04 = param0->unk_00; - v0->unk_08 = sub_02015328(param0->unk_04, param0->heapID); - v0->unk_0C = param0->unk_04; - v0->unk_10 = sub_02015358(param0->unk_08, param0->heapID); - v0->unk_14 = param0->unk_08; - - return v0; -} - -void sub_020150A8(UnkStruct_02015064 *param0) -{ - GF_ASSERT(param0); - GF_ASSERT(param0->unk_00); - GF_ASSERT(param0->unk_08); - GF_ASSERT(param0->unk_10); - - Heap_Free(param0->unk_00); - Heap_Free(param0->unk_08); - Heap_Free(param0->unk_10); - Heap_Free(param0); - - param0 = NULL; -} - -void sub_020150EC(UnkStruct_02015064 *param0) -{ - int v0; - - G3_PushMtx(); - - for (v0 = 0; v0 < param0->unk_04; v0++) { - if (param0->unk_00[v0].unk_20) { - sub_02015468(param0->unk_00 + v0); - } - } - - G3_PopMtx(1); -} - -UnkStruct_02015128 *sub_02015128(const UnkStruct_ov22_022557A0 *param0) -{ - UnkStruct_02015128 *v0 = sub_020153B4(param0->unk_00); - - GF_ASSERT(v0); - GF_ASSERT(param0->unk_04->mapingType == GX_OBJVRAMMODE_CHAR_2D); - - v0->unk_00 = sub_0201540C(param0->unk_04); - GF_ASSERT(v0->unk_00); - - sub_02015434(param0->unk_04, v0->unk_00, &v0->unk_04); - - return v0; -} - -void sub_02015164(UnkStruct_02015128 *param0) -{ - NNS_GfdFreeTexVram(param0->unk_00); - sub_020152E0(param0); -} - -void sub_0201517C(UnkStruct_02015064 *param0) -{ - int v0; - - for (v0 = 0; v0 < param0->unk_0C; v0++) { - if (param0->unk_08[v0].unk_00) { - sub_02015164(param0->unk_08 + v0); - } - } -} - -UnkStruct_020151A4 *sub_020151A4(const UnkStruct_ov22_02255800 *param0) -{ - UnkStruct_020151A4 *v0 = sub_020153E0(param0->unk_00); - GF_ASSERT(v0); - - v0->unk_00 = sub_02015420(param0->unk_08); - GF_ASSERT(v0->unk_00); - - sub_02015444(param0->unk_04, v0->unk_00, &v0->unk_04); - - return v0; -} - -void sub_020151D4(UnkStruct_020151A4 *param0) -{ - NNS_GfdFreePlttVram(param0->unk_00); - sub_020152EC(param0); -} - -void sub_020151EC(UnkStruct_02015064 *param0) -{ - int v0; - - for (v0 = 0; v0 < param0->unk_14; v0++) { - if (param0->unk_10[v0].unk_00) { - sub_020151D4(param0->unk_10 + v0); - } - } -} - -UnkStruct_02015214 *sub_02015214(const UnkStruct_ov21_021E7F40 *param0) -{ - UnkStruct_02015214 *v0 = sub_02015388(param0->unk_00); - GF_ASSERT(v0); - - sub_020155A8(v0, param0); - - v0->unk_1C = 1; - v0->unk_20 = 1; - - return v0; -} - -void sub_02015238(UnkStruct_02015214 *param0) -{ - sub_020152C0(param0); -} - -void sub_02015240(UnkStruct_02015214 *param0, BOOL param1) -{ - GF_ASSERT(param0); - param0->unk_20 = param1; -} - -void sub_02015254(UnkStruct_02015214 *param0, s16 param1, s16 param2) -{ - param0->unk_00.x = param1; - param0->unk_00.y = param2; -} - -NNSG2dSVec2 sub_0201525C(UnkStruct_02015214 *param0) -{ - return param0->unk_00; -} - -void sub_02015268(UnkStruct_02015214 *param0, s16 param1, s16 param2) -{ - param0->unk_04.x = param1; - param0->unk_04.y = param2; -} - -void sub_02015270(UnkStruct_02015214 *param0, fx32 param1, fx32 param2) -{ - param0->unk_0C = param1; - param0->unk_10 = param2; -} - -void sub_02015278(UnkStruct_02015214 *param0, int param1, int param2) -{ - param0->unk_08.x = param1; - param0->unk_08.y = param2; -} - -NNSG2dSVec2 sub_02015280(UnkStruct_02015214 *param0) -{ - return param0->unk_08; -} - -void sub_0201528C(UnkStruct_02015214 *param0, int param1) -{ - param0->unk_14 = param1; -} - -int sub_02015290(UnkStruct_02015214 *param0) -{ - return param0->unk_14; -} - -void sub_02015294(UnkStruct_02015214 *param0, u8 param1) -{ - param0->unk_3E = param1; -} - -void sub_0201529C(UnkStruct_02015214 *param0, GXRgb param1) -{ - param0->unk_3C = param1; -} - -void sub_020152A0(UnkStruct_02015214 *param0, NNSG2dImageAttr *param1) -{ - param0->unk_24 = param1; -} - -void sub_020152A4(UnkStruct_02015214 *param0, u32 param1) -{ - param0->unk_28 = param1; -} - -void sub_020152A8(UnkStruct_02015214 *param0, u32 param1) -{ - param0->unk_2C = param1; -} - -void sub_020152AC(UnkStruct_02015214 *param0, u32 param1) -{ - param0->unk_30 = param1; -} - -void sub_020152B0(UnkStruct_02015214 *param0, int param1, BOOL param2) -{ - if (param1 == 0) { - param0->unk_34 = param2; - } else { - param0->unk_38 = param2; - } -} - -void sub_020152BC(UnkStruct_02015214 *param0, u16 param1) -{ - param0->unk_18 = param1; -} - -static void sub_020152C0(UnkStruct_02015214 *param0) -{ - memset(param0, 0, sizeof(UnkStruct_02015214)); - - param0->unk_3E = 31; - param0->unk_3C = GX_RGB(31, 31, 31); -} - -static void sub_020152E0(UnkStruct_02015128 *param0) -{ - param0->unk_00 = 0; - NNS_G2dInitImageProxy(¶m0->unk_04); -} - -static void sub_020152EC(UnkStruct_020151A4 *param0) -{ - param0->unk_00 = 0; - NNS_G2dInitImagePaletteProxy(¶m0->unk_04); -} - -static UnkStruct_02015214 *sub_020152F8(int param0, int heapID) -{ - UnkStruct_02015214 *v0 = Heap_Alloc(heapID, sizeof(UnkStruct_02015214) * param0); - GF_ASSERT(v0); - - for (int i = 0; i < param0; i++) { - sub_020152C0(v0 + i); - } - - return v0; -} - -static UnkStruct_02015128 *sub_02015328(int param0, int heapID) -{ - UnkStruct_02015128 *v0 = Heap_Alloc(heapID, sizeof(UnkStruct_02015128) * param0); - GF_ASSERT(v0); - - for (int i = 0; i < param0; i++) { - sub_020152E0(v0 + i); - } - - return v0; -} - -static UnkStruct_020151A4 *sub_02015358(int param0, int heapID) -{ - UnkStruct_020151A4 *v0 = Heap_Alloc(heapID, sizeof(UnkStruct_020151A4) * param0); - GF_ASSERT(v0); - - for (int i = 0; i < param0; i++) { - sub_020152EC(v0 + i); - } - - return v0; -} - -static UnkStruct_02015214 *sub_02015388(UnkStruct_02015064 *param0) -{ - for (int i = 0; i < param0->unk_04; i++) { - if (param0->unk_00[i].unk_1C == 0) { - return param0->unk_00 + i; - } - } - - return NULL; -} - -static UnkStruct_02015128 *sub_020153B4(UnkStruct_02015064 *param0) -{ - for (int i = 0; i < param0->unk_04; i++) { - if (param0->unk_08[i].unk_00 == 0) { - return param0->unk_08 + i; - } - } - - return NULL; -} - -static UnkStruct_020151A4 *sub_020153E0(UnkStruct_02015064 *param0) -{ - for (int i = 0; i < param0->unk_04; i++) { - if (param0->unk_10[i].unk_00 == 0) { - return param0->unk_10 + i; - } - } - - return NULL; -} - -static NNSGfdTexKey sub_0201540C(NNSG2dCharacterData *param0) -{ - return NNS_GfdAllocTexVram(param0->szByte, 0, 0); -} - -static NNSGfdPlttKey sub_02015420(int param0) -{ - return NNS_GfdAllocPlttVram(param0 * 32, 0, 0); -} - -static void sub_02015434(NNSG2dCharacterData *param0, NNSGfdTexKey param1, NNSG2dImageProxy *param2) -{ - NNS_G2dLoadImage2DMapping(param0, NNS_GfdGetTexKeyAddr(param1), NNS_G2D_VRAM_TYPE_3DMAIN, param2); -} - -static void sub_02015444(NNSG2dPaletteData *param0, NNSGfdPlttKey param1, NNSG2dImagePaletteProxy *param2) -{ - int v0 = param0->szByte; - param0->szByte = NNS_GfdGetPlttKeySize(param1); - - NNS_G2dLoadPalette(param0, NNS_GfdGetPlttKeyAddr(param1), NNS_G2D_VRAM_TYPE_3DMAIN, param2); - param0->szByte = v0; -} - -static void sub_02015468(UnkStruct_02015214 *param0) -{ - NNSG2dSVec2 v0, v1; - - G3_PushMtx(); - G3_MaterialColorDiffAmb(param0->unk_3C, GX_RGB(31, 31, 31), 1); - G3_MaterialColorSpecEmi(GX_RGB(16, 16, 16), GX_RGB(0, 0, 0), 0); - G3_TexImageParam(param0->unk_24->fmt, GX_TEXGEN_TEXCOORD, param0->unk_24->sizeS, param0->unk_24->sizeT, GX_TEXREPEAT_NONE, GX_TEXFLIP_NONE, param0->unk_24->plttUse, param0->unk_28); - G3_TexPlttBase((u32)(param0->unk_2C + (32 * param0->unk_30)), param0->unk_24->fmt); - G3_PolygonAttr(GX_LIGHTMASK_NONE, GX_POLYGONMODE_MODULATE, GX_CULL_NONE, 0, param0->unk_3E, 0); - - if (param0->unk_34) { - v0.x = param0->unk_08.x; - v1.x = 0; - } else { - v1.x = param0->unk_08.x; - v0.x = 0; - } - - if (param0->unk_38) { - v0.y = param0->unk_08.y; - v1.y = 0; - } else { - v1.y = param0->unk_08.y; - v0.y = 0; - } - - G3_Translate((param0->unk_00.x + param0->unk_04.x) * FX32_ONE, (param0->unk_00.y + param0->unk_04.y) * FX32_ONE, param0->unk_14 * FX32_ONE); - G3_RotZ(FX_SinIdx(param0->unk_18), FX_CosIdx(param0->unk_18)); - G3_Scale(param0->unk_0C, param0->unk_10, FX32_ONE); - G3_Translate(-param0->unk_04.x * FX32_ONE, -param0->unk_04.y * FX32_ONE, 0); - NNS_G2dDrawSpriteFast(0, 0, 0, param0->unk_08.x, param0->unk_08.y, v0.x, v0.y, v1.x, v1.y); - G3_PopMtx(1); -} - -static void sub_020155A8(UnkStruct_02015214 *param0, const UnkStruct_ov21_021E7F40 *param1) -{ - int v0; - int v1, v2; - fx32 v3, v4; - fx32 v5, v6; - - v1 = 8; - - for (v0 = 0; v0 < param1->unk_04->unk_04.attr.sizeS; v0++) { - v1 *= 2; - } - - v2 = 8; - - for (v0 = 0; v0 < param1->unk_04->unk_04.attr.sizeT; v0++) { - v2 *= 2; - } - - v3 = 0; - v4 = 0; - v5 = v1 << FX32_SHIFT; - v6 = v2 << FX32_SHIFT; - - sub_02015254(param0, param1->unk_0C, param1->unk_0E); - sub_02015268(param0, v1 / 2, v2 / 2); - - param0->unk_0C = FX32_ONE; - param0->unk_10 = FX32_ONE; - - sub_02015278(param0, v1, v2); - sub_0201528C(param0, param1->unk_18); - sub_02015294(param0, param1->unk_14); - sub_020152A0(param0, ¶m1->unk_04->unk_04.attr); - sub_020152A4(param0, NNS_G2dGetImageLocation(¶m1->unk_04->unk_04, NNS_G2D_VRAM_TYPE_3DMAIN)); - sub_020152A8(param0, NNS_G2dGetImagePaletteLocation(¶m1->unk_08->unk_04, NNS_G2D_VRAM_TYPE_3DMAIN)); - sub_020152AC(param0, param1->unk_1C); - sub_020152B0(param0, 0, 0); - sub_020152B0(param0, 1, 0); - sub_020152BC(param0, param1->unk_10); -} diff --git a/src/unk_020298BC.c b/src/unk_020298BC.c index 7c9bf10586..7f267cd8f4 100644 --- a/src/unk_020298BC.c +++ b/src/unk_020298BC.c @@ -16,9 +16,9 @@ #include "inlines.h" #include "pokemon.h" #include "savedata.h" +#include "software_sprite.h" #include "strbuf.h" #include "unk_02014A84.h" -#include "unk_02015064.h" typedef struct UnkStruct_0202A138_t { u32 unk_00; @@ -570,8 +570,8 @@ void sub_02029FAC(UnkStruct_02029C68 *param0, Pokemon *param1, UnkStruct_020298D void sub_02029FD0(UnkStruct_02029C68 *param0, const UnkStruct_ov22_02255040 *param1, int param2) { - NNSG2dSVec2 v0 = sub_0201525C(param1->unk_04); - int v1 = sub_02015290(param1->unk_04); + NNSG2dSVec2 v0 = SoftwareSprite_GetPosition(param1->unk_04); + int v1 = SoftwareSprite_GetPriority(param1->unk_04); GF_ASSERT(param2 < (11 - 1)); GF_ASSERT(v0.x < 256); @@ -701,8 +701,8 @@ void sub_0202A284(UnkStruct_02029C88 *param0, Pokemon *param1, UnkStruct_020298D void sub_0202A2A8(UnkStruct_02029C88 *param0, const UnkStruct_ov22_02255040 *param1, int param2) { - NNSG2dSVec2 v0 = sub_0201525C(param1->unk_04); - int v1 = sub_02015290(param1->unk_04); + NNSG2dSVec2 v0 = SoftwareSprite_GetPosition(param1->unk_04); + int v1 = SoftwareSprite_GetPriority(param1->unk_04); GF_ASSERT(param2 < (21 - 1)); GF_ASSERT(v0.x < 256);