From e3aacde32429d493c6b759b4b608d4c7c1097b33 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 20 Dec 2024 14:50:42 +0100 Subject: [PATCH] match InitShadowSprites --- asm/pokemon_2.s | 147 ------------------------------------ data/data_81076E4.s | 41 ---------- ld_script.txt | 1 - src/pokemon.c | 180 ++++++++++++++++++++++++++++++++++++-------- src/pokemon_3.c | 28 ------- 5 files changed, 149 insertions(+), 248 deletions(-) delete mode 100644 asm/pokemon_2.s diff --git a/asm/pokemon_2.s b/asm/pokemon_2.s deleted file mode 100644 index bba28883..00000000 --- a/asm/pokemon_2.s +++ /dev/null @@ -1,147 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - -@ https://decomp.me/scratch/aIvCa - SpriteOAM memes - thumb_func_start InitShadowSprites -InitShadowSprites: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - mov r8, r0 - str r1, [sp] - ldr r0, _0808E628 - ldr r1, _0808E62C - bl OpenFileAndGetFileDataPtr - adds r7, r0, 0 - ldr r4, [r7, 0x4] - movs r6, 0x7 - adds r4, 0x4 - mov r1, r8 - lsls r0, r1, 5 - ldr r2, _0808E630 - adds r5, r0, r2 -_0808E564: - adds r0, r5, 0 - adds r1, r4, 0 - movs r2, 0x20 - bl CpuCopy - adds r5, 0x20 - adds r4, 0x20 - subs r6, 0x1 - cmp r6, 0 - bne _0808E564 - adds r0, r7, 0 - bl CloseFile - movs r6, 0 - movs r0, 0x3 - mov r12, r0 - ldr r1, _0808E634 - mov r10, r1 - ldr r2, _0808E638 - mov r9, r2 - ldr r5, _0808E63C - movs r7, 0 - mov r4, r12 - ldr r0, [sp] - ands r4, r0 - lsls r4, 10 -_0808E598: - lsls r3, r6, 3 - ldr r0, _0808E640 - adds r3, r0 - ldrh r1, [r3] - ldr r0, _0808E644 - ands r0, r1 - ldr r1, _0808E648 - ands r0, r1 - mov r2, r10 - ands r0, r2 - ldr r1, _0808E64C - ands r0, r1 - ldr r1, _0808E650 - ands r0, r1 - strh r0, [r3] - ldr r1, [r5] - mov r2, r12 - ands r1, r2 - lsls r1, 14 - mov r2, r9 - ands r0, r2 - orrs r0, r1 - strh r0, [r3] - ldrh r0, [r3, 0x2] - ldr r1, _0808E654 - ands r1, r0 - strh r1, [r3, 0x2] - ldr r0, _0808E63C - adds r0, 0x4 - adds r0, r7, r0 - ldr r0, [r0] - mov r2, r12 - ands r0, r2 - lsls r0, 14 - mov r2, r9 - ands r1, r2 - orrs r1, r0 - strh r1, [r3, 0x2] - ldr r1, [r5, 0x8] - add r1, r8 - ldr r0, _0808E658 - ands r1, r0 - ldrh r2, [r3, 0x4] - movs r0, 0xFC - lsls r0, 8 - ands r0, r2 - orrs r0, r1 - mov r1, r10 - ands r0, r1 - orrs r0, r4 - ldr r1, _0808E65C - ands r0, r1 - strh r0, [r3, 0x4] - ldrh r1, [r3, 0x6] - ldr r0, _0808E660 - ands r0, r1 - ldr r1, _0808E664 - ands r0, r1 - strh r0, [r3, 0x6] - adds r5, 0xC - adds r7, 0xC - adds r6, 0x1 - cmp r6, 0x2 - ble _0808E598 - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0808E628: .4byte gUnknown_81076BC -_0808E62C: .4byte gDungeonFileArchive -_0808E630: .4byte 0x06010000 -_0808E634: .4byte 0x0000f3ff -_0808E638: .4byte 0x00003fff -_0808E63C: .4byte gShadowSpriteSizeFlags_8107698 -_0808E640: .4byte gShadowSprites -_0808E644: .4byte 0x0000feff -_0808E648: .4byte 0x0000fdff -_0808E64C: .4byte 0x0000efff -_0808E650: .4byte 0x0000dfff -_0808E654: .4byte 0x0000c1ff -_0808E658: .4byte 0x000003ff -_0808E65C: .4byte 0x00000fff -_0808E660: .4byte 0x0000fffe -_0808E664: .4byte 0x0000fffd - thumb_func_end InitShadowSprites - - .align 2, 0 @ Don't pad with nop. diff --git a/data/data_81076E4.s b/data/data_81076E4.s index 9adb67e8..6d2ff917 100644 --- a/data/data_81076E4.s +++ b/data/data_81076E4.s @@ -1,46 +1,5 @@ .section .rodata -.global gUnknown_810763C -gUnknown_810763C: @ 810763C -.string "{color}%c%s{reset}\0" - -.global gUnknown_8107645 -gUnknown_8107645: @ 8107645 -.byte 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - -.global gUnknown_8107654 -gUnknown_8107654: @ 8107654 -.byte 0x9d, 0x01, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x0c, 0x01, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00 -.byte 0x33, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - -.global gUnknown_8107684 -gUnknown_8107684: @ 8107684 -.string "kao%03d\0" -.align 2,0 - -.global gUnknown_810768C -gUnknown_810768C: @ 810768C -.string "lvmp%03d\0" -.align 2,0 - -.global gShadowSpriteSizeFlags_8107698 -gShadowSpriteSizeFlags_8107698: @ 8107698 -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 -.byte 0x03, 0x00, 0x00, 0x00 - -.global gUnknown_81076BC -gUnknown_81076BC: @ 81076BC -.string "etcfont\0" -.align 2,0 - -.global gUnknown_81076C4 -gUnknown_81076C4: @ 81076C4 -.4byte -4 -.4byte -8 -.4byte -16 -.4byte -4 -.4byte -8 -.4byte -16 .align 2,0 @ pokemon_3 #1 diff --git a/ld_script.txt b/ld_script.txt index d7a5f4d8..b887605f 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -290,7 +290,6 @@ SECTIONS { src/code_80869E4.o(.text); src/dungeon_cutscenes.o(.text); src/pokemon.o(.text); - asm/pokemon_2.o(.text); src/pokemon_3.o(.text); src/dungeon.o(.text); asm/dungeon_2.o(.text); diff --git a/src/pokemon.c b/src/pokemon.c index 2c75a21a..55476cd0 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4,6 +4,7 @@ #include "code_800D090.h" #include "code_8097DD0.h" #include "constants/colors.h" +#include "constants/monster.h" #include "decompress.h" #include "file_system.h" #include "pokemon_3.h" @@ -11,6 +12,7 @@ #include "moves.h" #include "friend_area.h" #include "exclusive_pokemon.h" +#include "cpu.h" extern struct FileArchive gSystemFileArchive; extern struct FileArchive gMonsterFileArchive; @@ -26,34 +28,18 @@ static EWRAM_DATA LevelData gLevelCurrentData[0x64] = {0}; EWRAM_INIT unkStruct_203B45C *gRecruitedPokemonRef = {NULL}; struct unkStruct_8107654 { - s16 unk0; - s16 fill2; - s32 unk4; + s16 species; + s32 unk4; }; -//const char gUnknown_810763C[] = "{color}%c%s{reset}" ; -//const u8 gUnknown_8107645[12] = {0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -//struct unkStruct_8107654 gUnknown_8107654[6]; -//ALIGNED(4) const char gUnknown_8107684[] = "kao%03d"; -//ALIGNED(4) const char gUnknown_810768C[] = "lvmp%03d"; // lvmp%03d\0 -//const u8 gShadowSpriteSizeFlags_8107698[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 }; -//ALIGNED(4) const char gUnknown_81076BC[] = "etcfont"; -//const s32 gUnknown_81076C4[6] = {-4, -8, -16, -4, -8, -16}; // x-coord positioning for shadow sprites - ALIGNED(4) static const char sMonsterParameterFileName[] = "monspara"; ALIGNED(4) static const char gUnknown_8107600[] = _("{color YELLOW_RAW}%s{reset}"); ALIGNED(4) static const char gUnknown_8107608[] = _("{color CYAN_RAW}%s{reset}"); ALIGNED(4) static const char gUnownLetters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?"; ALIGNED(4) static const char gUnknown_8107630[] = "%s%c"; ALIGNED(4) static const char gUnknown_8107638[] = "%s"; -extern const char gUnknown_810763C[]; -extern const u8 gUnknown_8107645[12]; -extern struct unkStruct_8107654 gUnknown_8107654[6]; -extern const char gUnknown_8107684[]; -extern const char gUnknown_810768C[]; // lvmp%03d -extern const u8 gShadowSpriteSizeFlags_8107698[]; -extern const char gUnknown_81076BC[]; -extern const s32 gUnknown_81076C4[6]; +ALIGNED(4) static const char gUnknown_810763C[] = _("{color}%c%s{reset}"); +static const u8 gUnknown_8107645[12] = {0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; extern s16 gFrenzyPlantIQReq; // 0x14d extern s16 gHydroCannonIQReq; // 0x14d @@ -835,19 +821,25 @@ void PrintPokeNameToBuffer(u8 *buffer, PokemonStruct1 *pokemon) sub_80922B4(buffer, pokemon->name, POKEMON_NAME_LENGTH); } -bool8 sub_808DA44(s32 a1_, u32 a2_) +bool8 sub_808DA44(s32 _species, u32 a2_) { // this is the dumbest thing ever, but just making a1 a s16 and // a2 a u8 did weird stuff with shifting... - s32 a1 = (s16)a1_; + s32 species = (s16) _species; u32 a2 = (u8)a2_; if (a2 > 0xc) { s32 i; - struct unkStruct_8107654 data[6]; - memcpy(data, gUnknown_8107654, 6 * sizeof(struct unkStruct_8107654)); - - for (i = 0; i < 10 && data[i].unk0; i++) { - if (data[i].unk0 == a1 && data[i].unk4 == a2) { + struct unkStruct_8107654 data[6] = { + {MONSTER_JIRACHI, 0xD}, + {MONSTER_RAIKOU, 0xD}, + {MONSTER_ALAKAZAM, 0xE}, + {MONSTER_DUGTRIO, 0xD}, + {MONSTER_DUGTRIO, 0xE}, + {MONSTER_NONE, 0}, + }; + + for (i = 0; i < 10 && data[i].species != MONSTER_NONE; i++) { + if (data[i].species == species && data[i].unk4 == a2) { return 1; } } @@ -1022,7 +1014,7 @@ OpenedFile *OpenPokemonDialogueSpriteFile(s16 index) { return NULL; } - sprintf(buffer, gUnknown_8107684, index); // "kao%03d" + sprintf(buffer, "kao%03d", index); return OpenFile(buffer, &gMonsterFileArchive); } @@ -1036,7 +1028,7 @@ OpenedFile *GetDialogueSpriteDataPtr(s32 index) { return NULL; } - sprintf(buffer, gUnknown_8107684, id); // "kao%03d" + sprintf(buffer, "kao%03d", id); return OpenFileAndGetFileDataPtr(buffer, &gMonsterFileArchive); } @@ -1160,8 +1152,7 @@ void GetPokemonLevelData(LevelData* a1, s32 _id, s32 level) OpenedFile *file; gLevelCurrentPokeId = id; - // lvmp%03d\0 - sprintf(buffer, gUnknown_810768C, id); + sprintf(buffer, "lvmp%03d", id); file = OpenFileAndGetFileDataPtr(buffer, &gSystemFileArchive); DecompressATFile((char*)gLevelCurrentData, 0, file); CloseFile(file); @@ -1459,3 +1450,130 @@ char* sub_808E51C(s32 a1) return result[0]->unk4; } +extern const struct FileArchive gDungeonFileArchive; + +struct ShadowSpriteFlags { + u32 shape; + u32 size; + u32 tileNum; +}; + +static const struct ShadowSpriteFlags gShadowSpriteSizeFlags_8107698[] = { + [0] = { + .shape = 0, + .size = 0, + .tileNum = 0, + }, + [1] = { + .shape = 1, + .size = 0, + .tileNum = 1, + }, + [2] = { + .shape = 1, + .size = 1, + .tileNum = 3, + }, +}; + +void InitShadowSprites(s32 param_1, s32 param_2) +{ + u8 *vram; + s32 i, spriteIndex; + + OpenedFile *file = OpenFileAndGetFileDataPtr("etcfont", &gDungeonFileArchive); + const u8 *src = file->data; + i = 7; + src += 4; + vram = OBJ_VRAM0 + param_1 * 0x20; + + // This loop could be a fakematch, but I couldn't get it work with a regular 'for(i = 0; i < 7; i)' loop. + while (i != 0) + { + CpuCopy(vram, src, 0x20); + vram += 0x20; + src += 0x20; + i--; + } + + CloseFile(file); + + for (spriteIndex = 0; spriteIndex < 3; spriteIndex++) { + u32 objMode, shape, size, tileNum, priority; + + SpriteOAM *sprite = &gShadowSprites[spriteIndex]; + + sprite->attrib1 &= ~SPRITEOAM_MASK_AFFINEMODE1; + sprite->attrib1 &= ~SPRITEOAM_MASK_AFFINEMODE2; + + objMode = 0; + objMode &= SPRITEOAM_MAX_OBJMODE; + objMode <<= SPRITEOAM_SHIFT_OBJMODE; + sprite->attrib1 &= ~SPRITEOAM_MASK_OBJMODE; + sprite->attrib1 |= objMode; + + sprite->attrib1 &= ~SPRITEOAM_MASK_MOSAIC; + sprite->attrib1 &= ~SPRITEOAM_MASK_BPP; + + shape = gShadowSpriteSizeFlags_8107698[spriteIndex].shape; + shape &= SPRITEOAM_MAX_SHAPE; + shape <<= SPRITEOAM_SHIFT_SHAPE; + sprite->attrib1 &= ~SPRITEOAM_MASK_SHAPE; + sprite->attrib1 |= shape; + + sprite->attrib2 &= ~SPRITEOAM_MASK_MATRIXNUM; + + size = gShadowSpriteSizeFlags_8107698[spriteIndex].size; + size &= SPRITEOAM_MAX_SIZE; + size <<= SPRITEOAM_SHIFT_SIZE; + sprite->attrib2 &= ~SPRITEOAM_MASK_SIZE; + sprite->attrib2 |= size; + + tileNum = gShadowSpriteSizeFlags_8107698[spriteIndex].tileNum + param_1; + tileNum &= SPRITEOAM_MAX_TILENUM; + tileNum <<= SPRITEOAM_SHIFT_TILENUM; + sprite->attrib3 &= ~SPRITEOAM_MASK_TILENUM; + sprite->attrib3 |= tileNum; + + priority = param_2; + priority &= SPRITEOAM_MAX_PRIORITY; + priority <<= SPRITEOAM_SHIFT_PRIORITY; + sprite->attrib3 &= ~SPRITEOAM_MASK_PRIORITY; + sprite->attrib3 |= priority; + + sprite->attrib3 &= ~SPRITEOAM_MASK_PALETTENUM; + + sprite->unk6 &= ~SPRITEOAM_MASK_UNK6_0; + sprite->unk6 &= ~SPRITEOAM_MASK_UNK6_1; + } +} + +static const s32 gUnknown_81076C4[6] = {-4, -8, -16, -4, -8, -16}; // x-coord positioning for shadow sprites + +bool8 AddShadowSprite(s16 species, s16* a2, s16* a3) +{ + if (species != MONSTER_DIGLETT && species != MONSTER_DUGTRIO) { + s32 shadowSize = GetShadowSize(species); + s32 x, y; + SpriteOAM* spr; + + x = a2[0] + a3[8]; + y = a2[1] + a3[9]; + x += gUnknown_81076C4[shadowSize]; + y -= 4; + + x &= SPRITEOAM_MAX_X; + x <<= SPRITEOAM_SHIFT_X; + spr = &gShadowSprites[shadowSize]; + spr->attrib2 &= ~SPRITEOAM_MASK_X; + spr->attrib2 |= x; + + y &= SPRITEOAM_MAX_UNK6_4; + y <<= SPRITEOAM_SHIFT_UNK6_4; + spr->unk6 &= ~SPRITEOAM_MASK_UNK6_4; + spr->unk6 |= y; + AddSprite(spr, 0, NULL, NULL); + } + + return TRUE; +} diff --git a/src/pokemon_3.c b/src/pokemon_3.c index cb82351f..a726eef0 100644 --- a/src/pokemon_3.c +++ b/src/pokemon_3.c @@ -34,7 +34,6 @@ struct unkStruct_808E9EC u8 unk12; u8 unk13; }; -extern s32 gUnknown_81076C4[6]; // x-coord positioning for shadow sprites extern SpriteOAM gShadowSprites[3]; // Shadow sprites of some kind extern s16 gUnknown_810AC60; // 0xC @@ -101,33 +100,6 @@ extern void ReadBellyBits(DataSerializer*, FixedPoint *dst); extern void ReadHiddenPowerBits(DataSerializer*, HiddenPower*); s16 GetPokemonEvolveConditions(s16 index, unkEvolve *r1); -bool8 AddShadowSprite(s16 species, s16* a2, s16* a3) -{ - if (species != MONSTER_DIGLETT && species != MONSTER_DUGTRIO) { - u8 shadowSize = GetShadowSize(species); - u32 x, unk6; - SpriteOAM* spr; - - x = a2[0] + a3[8]; - unk6 = a2[1] + a3[9]; - x += gUnknown_81076C4[shadowSize]; - unk6 -= 4; - x &= SPRITEOAM_MAX_X; - - spr = &gShadowSprites[shadowSize]; - spr->attrib2 &= ~SPRITEOAM_MASK_X; - spr->attrib2 |= x; - unk6 &= SPRITEOAM_MAX_UNK6_4; - unk6 <<= SPRITEOAM_SHIFT_UNK6_4; - spr->unk6 &= ~SPRITEOAM_MASK_UNK6_4; - spr->unk6 |= unk6; - AddSprite(spr, 0, NULL, NULL); - } - - return TRUE; -} - - void GenerateHiddenPower(HiddenPower* a1) { s32 i;