From 5bc640da9b754e3eae70bb82288c7e86dd5b29de Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 10 Apr 2019 20:49:10 +0200 Subject: [PATCH] nonmatchings --- src/battle_anim_effects_2.c | 81 +------ src/berry_crush.c | 2 +- src/contest_link_80F57C4.c | 458 +++++++----------------------------- 3 files changed, 99 insertions(+), 442 deletions(-) diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c index 580b138643..65cc556048 100755 --- a/src/battle_anim_effects_2.c +++ b/src/battle_anim_effects_2.c @@ -1734,90 +1734,25 @@ void sub_8103FE8(struct Sprite *sprite) sprite->callback = sub_8104018; } -#ifdef NONMATCHING static void sub_8104018(struct Sprite *sprite) { - u16 r7; - u16 r5; + u16 id, val; int i; + if (++sprite->data[1] == 2) { sprite->data[1] = 0; - r5 = sprite->data[0]; - r7 = gPlttBufferFaded[8 + r5]; - for (i = 0; i < 8; i++) - { - gPlttBufferFaded[i + r5 + 8] = gPlttBufferFaded[i + r5 + 9]; - } - gPlttBufferFaded[r5 + 15] = r7; + id = sprite->data[0]; + val = gPlttBufferFaded[8 + id]; + for (i = 8; i < 16; i++) + gPlttBufferFaded[i + id] = gPlttBufferFaded[i + id + 1]; + + gPlttBufferFaded[id + 15] = val; if (++sprite->data[2] == 24) DestroyAnimSprite(sprite); } } -#else -NAKED -static void sub_8104018(struct Sprite *sprite) -{ - asm(".syntax unified\n\ - push {r4-r7,lr}\n\ - adds r4, r0, 0\n\ - ldrh r0, [r4, 0x30]\n\ - adds r0, 0x1\n\ - strh r0, [r4, 0x30]\n\ - lsls r0, 16\n\ - asrs r0, 16\n\ - cmp r0, 0x2\n\ - bne _0810407C\n\ - movs r0, 0\n\ - strh r0, [r4, 0x30]\n\ - ldrh r5, [r4, 0x2E]\n\ - ldr r1, =gPlttBufferFaded\n\ - adds r0, r5, 0\n\ - adds r0, 0x8\n\ - lsls r0, 1\n\ - adds r0, r1 \n\ - ldrh r7, [r0]\n\ - adds r6, r1, 0\n\ - adds r1, r5, 0\n\ - adds r1, 0x9\n\ - lsls r0, r5, 1\n\ - adds r0, r6\n\ - adds r2, r0, 0\n\ - adds r2, 0x10\n\ - movs r3, 0x7\n\ - lsls r1, 1\n\ - adds r1, r6\n\ -_08104050:\n\ - ldrh r0, [r1]\n\ - strh r0, [r2]\n\ - adds r1, 0x2\n\ - adds r2, 0x2\n\ - subs r3, 0x1\n\ - cmp r3, 0\n\ - bge _08104050\n\ - adds r0, r5, 0\n\ - adds r0, 0xF\n\ - lsls r0, 1\n\ - adds r0, r6\n\ - strh r7, [r0]\n\ - ldrh r0, [r4, 0x32]\n\ - adds r0, 0x1\n\ - strh r0, [r4, 0x32]\n\ - lsls r0, 16\n\ - asrs r0, 16\n\ - cmp r0, 0x18\n\ - bne _0810407C\n\ - adds r0, r4, 0\n\ - bl DestroyAnimSprite\n\ -_0810407C:\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .pool\n\ -.syntax divided\n"); -} -#endif void sub_8104088(struct Sprite *sprite) { diff --git a/src/berry_crush.c b/src/berry_crush.c index 8efb5906b4..a5d964cc9e 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -337,7 +337,7 @@ void sub_8020FC4(struct BerryCrushGame *arg0) for (i = 0; i < arg0->unk9; i++) StringCopy(arg0->unk84.players[i].unk14, gLinkPlayers[i].name); - + for (; i < 5; i++) { memset(arg0->unk84.players[i].unk14, 1, PLAYER_NAME_LENGTH); diff --git a/src/contest_link_80F57C4.c b/src/contest_link_80F57C4.c index aa3c670508..bae7859b54 100644 --- a/src/contest_link_80F57C4.c +++ b/src/contest_link_80F57C4.c @@ -121,7 +121,7 @@ static void sub_80F5F30(u8); static void sub_80F5F74(u8); static void sub_80F7144(void); static void sub_80F68F0(u8); -s16 sub_80F6B78(const u8 *, u8); +s32 sub_80F6B78(const u8 *, u8); static void sub_80F6E9C(s16, u16, u16, u16); static void sub_80F6058(u8); static void sub_80F7A80(u8, u8); @@ -919,39 +919,76 @@ static void sub_80F6AE8(void) } } -// s16 sub_80F6B78(const u8 *text, u8 spriteId) -// { -// int i; -// int origWidth, strWidth; -// const u8 *r8; -// u8 sp10[0x10]; -// struct WindowTemplate windowTemplate; -// int spC; -// u8 *windowTileData; -// u8 windowId; +// Functionally equivalent, the same except compiler generated variables from +// src are placed on different stack positions. -// memset(windowTemplate, 0, sizeof(*windowTemplate)); -// windowTemplate.width = 30; -// windowTemplate.height = 2; -// windowId = AddWindow(&windowTemplate); -// FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); -// origWidth = GetStringWidth(1, text, 0) + 9; -// strWidth = origWidth; -// if (strWidth < 0) -// strWidth += 7; +#ifdef NONMATCHING +s32 sub_80F6B78(const u8 *text, u8 spriteId) +{ + u8 *windowTilesPtr; + u16 windowId; + int origWidth; + struct WindowTemplate windowTemplate; + int strWidth; + u8 *spriteTilePtrs[4]; + u8 *dst; + int i; + struct Sprite *sprite; + const u8 *src; // The culprit. -// strWidth >>= 3; -// if (strWidth > 30) -// strWidth = 30; + memset(&windowTemplate, 0, sizeof(windowTemplate)); + windowTemplate.width = 30; + windowTemplate.height = 2; + windowId = AddWindow(&windowTemplate); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); -// AddTextPrinterParameterized3(windowId, 1, (strWidth * 8 - origWidth) / 2, 1, gUnknown_0858D8E8, -1, text); -// windowTileData = (u8 *)GetWindowAttribute(windowId, WINDOW_TILE_DATA); -// r8 = gUnknown_0858D6D0; -// // .... -// } + origWidth = GetStringWidth(1, text, 0); + strWidth = (origWidth + 9) / 8; + if (strWidth > 30) + strWidth = 30; + AddTextPrinterParameterized3(windowId, 1, (strWidth * 8 - origWidth) / 2, 1, gUnknown_0858D8E8, -1, text); + windowTilesPtr = (u8 *)(GetWindowAttribute(windowId, WINDOW_TILE_DATA)); + src = (u8 *)(gUnknown_0858D6D0); + + sprite = &gSprites[spriteId]; + spriteTilePtrs[0] = (u8 *)(sprite->oam.tileNum * 32 + VRAM + 0x10000); + + for (i = 1; i < 4; i++) + spriteTilePtrs[i] = (void*)(gSprites[sprite->data[i - 1]].oam.tileNum * 32 + VRAM + 0x10000); + + for (i = 0; i < 4; i++) + CpuFill32(0, spriteTilePtrs[i], 0x400); + + dst = spriteTilePtrs[0]; + CpuCopy32(src, dst, 0x20); + CpuCopy32(src + 128, dst + 0x100, 0x20); + CpuCopy32(src + 128, dst + 0x200, 0x20); + CpuCopy32(src + 64, dst + 0x300, 0x20); + + for (i = 0; i < strWidth; i++) + { + dst = &spriteTilePtrs[(i + 1) / 8][((i + 1) % 8) * 32]; + CpuCopy32(src + 192, dst, 0x20); + CpuCopy32(windowTilesPtr, dst + 0x100, 0x20); + CpuCopy32(windowTilesPtr + 960, dst + 0x200, 0x20); + CpuCopy32(src + 224, dst + 0x300, 0x20); + windowTilesPtr += 0x20; + } + + dst = &spriteTilePtrs[(i + 1) / 8][((i + 1) % 8) * 32]; + CpuCopy32(src + 32, dst, 0x20); + CpuCopy32(src + 160, dst + 0x100, 0x20); + CpuCopy32(src + 160, dst + 0x200, 0x20); + CpuCopy32(src + 96, dst + 0x300, 0x20); + RemoveWindow(windowId); + + return (240 - (strWidth + 2) * 8) / 2; +} + +#else NAKED -s16 sub_80F6B78(const u8 *text, u8 spriteId) +s32 sub_80F6B78(const u8 *text, u8 spriteId) { asm_unified("\n\ push {r4-r7,lr}\n\ @@ -1224,6 +1261,7 @@ _080F6D3E:\n\ bx r1\n\ .pool"); } +#endif // NONMATCHING static void sub_80F6DC0(void) { @@ -1630,7 +1668,7 @@ void sub_80F7768(struct Sprite *sprite) sprite->pos1.y++; if (gUnknown_0203A034->unk0->unk9) sprite->invisible = 1; - + if (sprite->pos1.x > 248 || sprite->pos1.y > 116) { DestroySprite(sprite); @@ -2091,7 +2129,7 @@ _080F7A70:\n\ // if (spC) // PlaySE(SE_PIN); - + // if (sp8) // PlaySE(SE_BAN); // } @@ -2358,38 +2396,32 @@ _080F7C96:\n\ bx r0"); } -#ifdef NONMATCHING void sub_80F7CA8(u8 taskId) { - register int r4 asm("r4"); - int r9; - u8 r6; - s16 r7; - s16 r12; int i; u8 var0; u16 tileNum; + bool32 r4 = FALSE; + bool32 endTask = FALSE; + u8 r6 = gTasks[taskId].data[0]; + s16 r7 = gTasks[taskId].data[1]; + s16 r12 = gTasks[taskId].data[2]; - r4 = 0; - r9 = 0; - r6 = gTasks[taskId].data[0]; - r7 = gTasks[taskId].data[1]; - r12 = gTasks[taskId].data[2]; if (r12) { if (gUnknown_0203A034->unk0->unkC[r6] <= 0) - r4 = 1; + r4 = TRUE; } else { if (gUnknown_0203A034->unk0->unkC[r6] > 87) - r4 = 1; + r4 = TRUE; } if (gUnknown_0203A034->unk0->unkC[r6] == r7) - r9 = 1; + endTask = TRUE; - if (!r9) + if (!endTask) { if (r4) gUnknown_0203A034->unk0->unkC[r6] = r7; @@ -2399,220 +2431,32 @@ void sub_80F7CA8(u8 taskId) gUnknown_0203A034->unk0->unkC[r6] = gUnknown_0203A034->unk0->unkC[r6] + 1; } - if (!r4 && !r9) + if (!r4 && !endTask) { for (i = 0; i < 11; i++) { if (gUnknown_0203A034->unk0->unkC[r6] >= (i + 1) * 8) - { var0 = 8; - } else if (gUnknown_0203A034->unk0->unkC[r6] >= i * 8) - { - int var2 = gUnknown_0203A034->unk0->unkC[r6]; - int var1 = var2; - if (var1 < 0) - var1 += 7; - - var0 = var2 - ((var1 >> 3) << 3); - } + var0 = gUnknown_0203A034->unk0->unkC[r6] % 8; else - { var0 = 0; - } if (var0 < 4) - tileNum = 0x504C; + tileNum = 0x504C + var0; else - tileNum = 0x5057; + tileNum = 0x5057 + var0; - FillBgTilemapBufferRect_Palette0(2, tileNum + var0, i + 7, r6 * 3 + 6, 1, 1); + FillBgTilemapBufferRect_Palette0(2, tileNum, i + 7, r6 * 3 + 6, 1, 1); } } - - if (r9) + + if (endTask) { gUnknown_0203A034->unk0->unk14--; DestroyTask(taskId); } } -#else -NAKED -void sub_80F7CA8(u8 taskId) -{ - asm_unified("\n\ - push {r4-r7,lr}\n\ - mov r7, r9\n\ - mov r6, r8\n\ - push {r6,r7}\n\ - sub sp, 0x8\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - mov r8, r0\n\ - movs r4, 0\n\ - mov r9, r4\n\ - ldr r1, =gTasks\n\ - lsls r0, 2\n\ - add r0, r8\n\ - lsls r0, 3\n\ - adds r0, r1\n\ - ldrb r6, [r0, 0x8]\n\ - ldrh r7, [r0, 0xA]\n\ - ldrh r1, [r0, 0xC]\n\ - mov r12, r1\n\ - movs r2, 0xC\n\ - ldrsh r0, [r0, r2]\n\ - cmp r0, 0\n\ - beq _080F7CF8\n\ - ldr r2, =gUnknown_0203A034\n\ - ldr r0, [r2]\n\ - ldr r0, [r0]\n\ - lsls r1, r6, 1\n\ - adds r0, 0xC\n\ - adds r0, r1\n\ - movs r3, 0\n\ - ldrsh r0, [r0, r3]\n\ - adds r5, r1, 0\n\ - cmp r0, 0\n\ - bgt _080F7D10\n\ - b _080F7D0E\n\ - .pool\n\ -_080F7CF8:\n\ - ldr r2, =gUnknown_0203A034\n\ - ldr r0, [r2]\n\ - ldr r0, [r0]\n\ - lsls r1, r6, 1\n\ - adds r0, 0xC\n\ - adds r0, r1\n\ - movs r3, 0\n\ - ldrsh r0, [r0, r3]\n\ - adds r5, r1, 0\n\ - cmp r0, 0x57\n\ - ble _080F7D10\n\ -_080F7D0E:\n\ - movs r4, 0x1\n\ -_080F7D10:\n\ - ldr r0, [r2]\n\ - ldr r0, [r0]\n\ - adds r0, 0xC\n\ - adds r2, r0, r5\n\ - ldrh r3, [r2]\n\ - movs r0, 0\n\ - ldrsh r1, [r2, r0]\n\ - lsls r0, r7, 16\n\ - asrs r0, 16\n\ - cmp r1, r0\n\ - bne _080F7D2A\n\ - movs r1, 0x1\n\ - mov r9, r1\n\ -_080F7D2A:\n\ - mov r0, r9\n\ - cmp r0, 0\n\ - bne _080F7D4A\n\ - cmp r4, 0\n\ - beq _080F7D3C\n\ - strh r7, [r2]\n\ - b _080F7D4A\n\ - .pool\n\ -_080F7D3C:\n\ - mov r1, r12\n\ - cmp r1, 0\n\ - beq _080F7D46\n\ - subs r0, r3, 0x1\n\ - b _080F7D48\n\ -_080F7D46:\n\ - adds r0, r3, 0x1\n\ -_080F7D48:\n\ - strh r0, [r2]\n\ -_080F7D4A:\n\ - cmp r4, 0\n\ - bne _080F7DC4\n\ - mov r2, r9\n\ - cmp r2, 0\n\ - bne _080F7DCA\n\ - movs r2, 0\n\ -_080F7D56:\n\ - ldr r0, =gUnknown_0203A034\n\ - ldr r0, [r0]\n\ - ldr r0, [r0]\n\ - adds r0, 0xC\n\ - adds r0, r5\n\ - movs r1, 0\n\ - ldrsh r3, [r0, r1]\n\ - adds r0, r2, 0x1\n\ - lsls r1, r0, 3\n\ - adds r4, r0, 0\n\ - cmp r3, r1\n\ - blt _080F7D78\n\ - movs r0, 0x8\n\ - b _080F7D94\n\ - .pool\n\ -_080F7D78:\n\ - lsls r0, r2, 3\n\ - cmp r3, r0\n\ - blt _080F7D92\n\ - adds r0, r3, 0\n\ - cmp r3, 0\n\ - bge _080F7D86\n\ - adds r0, r3, 0x7\n\ -_080F7D86:\n\ - asrs r0, 3\n\ - lsls r0, 3\n\ - subs r0, r3, r0\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - b _080F7D94\n\ -_080F7D92:\n\ - movs r0, 0\n\ -_080F7D94:\n\ - cmp r0, 0x3\n\ - bhi _080F7DA0\n\ - ldr r3, =0x0000504c\n\ - b _080F7DA2\n\ - .pool\n\ -_080F7DA0:\n\ - ldr r3, =0x00005057\n\ -_080F7DA2:\n\ - adds r1, r0, r3\n\ - adds r2, 0x7\n\ - lsls r2, 24\n\ - lsrs r2, 24\n\ - adds r3, r5, r6\n\ - adds r3, 0x6\n\ - lsls r3, 24\n\ - movs r0, 0x1\n\ - str r0, [sp]\n\ - str r0, [sp, 0x4]\n\ - movs r0, 0x2\n\ - lsrs r3, 24\n\ - bl FillBgTilemapBufferRect_Palette0\n\ - adds r2, r4, 0\n\ - cmp r2, 0xA\n\ - ble _080F7D56\n\ -_080F7DC4:\n\ - mov r0, r9\n\ - cmp r0, 0\n\ - beq _080F7DDC\n\ -_080F7DCA:\n\ - ldr r0, =gUnknown_0203A034\n\ - ldr r0, [r0]\n\ - ldr r1, [r0]\n\ - ldrb r0, [r1, 0x14]\n\ - subs r0, 0x1\n\ - strb r0, [r1, 0x14]\n\ - mov r0, r8\n\ - bl DestroyTask\n\ -_080F7DDC:\n\ - add sp, 0x8\n\ - pop {r3,r4}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .pool"); -} -#endif // NONMATCHING static void sub_80F7DF4(void) { @@ -2913,10 +2757,9 @@ static void sub_80F85A0(u8 taskId) SetTaskFuncWithFollowupFunc(taskId, sub_80FC894, sub_80F85BC); } -#ifdef NONMATCHING static void sub_80F85BC(u8 taskId) { - u32 i; + u8 i; u8 sp0[4]; u8 sp4[4]; @@ -2926,9 +2769,10 @@ static void sub_80F85BC(u8 taskId) for (i = 0; i < gNumLinkContestPlayers; i++) sp0[i] = gTasks[taskId].data[i + 1]; - for (i = 0; i < gNumLinkContestPlayers; i++) + for (i = 0; i < gNumLinkContestPlayers;) { - if (sp0[0] != sp0[i + 1]) + i++; + if (i >= gNumLinkContestPlayers || sp0[0] != sp0[i]) break; } @@ -2939,133 +2783,11 @@ static void sub_80F85BC(u8 taskId) for (i = 0; i < gNumLinkContestPlayers; i++) sp4[i] = gTasks[taskId].data[i + 5]; - + gUnknown_02039F2B = sub_80F86E0(sp4); sub_80DB09C(gSpecialVar_ContestCategory); SetTaskFuncWithFollowupFunc(taskId, sub_80FCF40, sub_80F86B8); } -#else -NAKED -static void sub_80F85BC(u8 taskId) -{ - asm_unified("\n\ - push {r4-r7,lr}\n\ - mov r7, r9\n\ - mov r6, r8\n\ - push {r6,r7}\n\ - sub sp, 0x8\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - movs r0, 0\n\ - str r0, [sp]\n\ - str r0, [sp, 0x4]\n\ - movs r3, 0\n\ - ldr r5, =gNumLinkContestPlayers\n\ - mov r12, r5\n\ - ldr r0, =gSpecialVar_0x8004\n\ - mov r9, r0\n\ - add r1, sp, 0x4\n\ - mov r8, r1\n\ - ldrb r0, [r5]\n\ - cmp r3, r0\n\ - bcs _080F8606\n\ - lsls r0, r6, 2\n\ - adds r0, r6\n\ - lsls r4, r0, 3\n\ - ldr r7, =gTasks + 0x8\n\ -_080F85EC:\n\ - mov r1, sp\n\ - adds r2, r1, r3\n\ - adds r1, r3, 0x1\n\ - lsls r0, r1, 1\n\ - adds r0, r4\n\ - adds r0, r7\n\ - ldrh r0, [r0]\n\ - strb r0, [r2]\n\ - lsls r1, 24\n\ - lsrs r3, r1, 24\n\ - ldrb r0, [r5]\n\ - cmp r3, r0\n\ - bcc _080F85EC\n\ -_080F8606:\n\ - movs r3, 0\n\ - mov r1, r12\n\ - ldrb r0, [r1]\n\ - cmp r3, r0\n\ - bcs _080F862A\n\ - adds r4, r0, 0\n\ - mov r2, sp\n\ -_080F8614:\n\ - adds r0, r3, 0x1\n\ - lsls r0, 24\n\ - lsrs r3, r0, 24\n\ - cmp r3, r4\n\ - bcs _080F862A\n\ - mov r0, sp\n\ - adds r1, r0, r3\n\ - ldrb r0, [r2]\n\ - ldrb r1, [r1]\n\ - cmp r0, r1\n\ - beq _080F8614\n\ -_080F862A:\n\ - mov r1, r12\n\ - ldrb r1, [r1]\n\ - cmp r3, r1\n\ - bne _080F8644\n\ - movs r0, 0\n\ - b _080F8646\n\ - .pool\n\ -_080F8644:\n\ - movs r0, 0x1\n\ -_080F8646:\n\ - mov r1, r9\n\ - strh r0, [r1]\n\ - movs r3, 0\n\ - mov r4, r12\n\ - ldrb r0, [r4]\n\ - cmp r3, r0\n\ - bcs _080F8678\n\ - mov r5, r8\n\ - lsls r0, r6, 2\n\ - adds r0, r6\n\ - lsls r2, r0, 3\n\ - ldr r7, =gTasks + 0x8\n\ -_080F865E:\n\ - adds r1, r5, r3\n\ - adds r0, r3, 0x5\n\ - lsls r0, 1\n\ - adds r0, r2\n\ - adds r0, r7\n\ - ldrh r0, [r0]\n\ - strb r0, [r1]\n\ - adds r0, r3, 0x1\n\ - lsls r0, 24\n\ - lsrs r3, r0, 24\n\ - ldrb r1, [r4]\n\ - cmp r3, r1\n\ - bcc _080F865E\n\ -_080F8678:\n\ - mov r0, r8\n\ - bl sub_80F86E0\n\ - ldr r1, =gUnknown_02039F2B\n\ - strb r0, [r1]\n\ - ldr r0, =gSpecialVar_ContestCategory\n\ - ldrb r0, [r0]\n\ - bl sub_80DB09C\n\ - ldr r1, =sub_80FCF40\n\ - ldr r2, =sub_80F86B8\n\ - adds r0, r6, 0\n\ - bl SetTaskFuncWithFollowupFunc\n\ - add sp, 0x8\n\ - pop {r3,r4}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .pool"); -} -#endif // NONMATCHING static void sub_80F86B8(u8 taskId) {