From 4223bb65f05704ade92ed99d9d5ea58becf1c8ec Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Tue, 19 Feb 2019 16:30:15 -0600 Subject: [PATCH] Decompile several contest_link_80F57C4.c functions --- asm/contest_link_80F57C4.s | 393 ------------------------------------- src/contest_link_80F57C4.c | 136 ++++++++++++- 2 files changed, 132 insertions(+), 397 deletions(-) diff --git a/asm/contest_link_80F57C4.s b/asm/contest_link_80F57C4.s index d73293648..44f92caca 100644 --- a/asm/contest_link_80F57C4.s +++ b/asm/contest_link_80F57C4.s @@ -5,399 +5,6 @@ .text - thumb_func_start sub_80F7364 -sub_80F7364: @ 80F7364 - push {r4-r7,lr} - lsls r0, 24 - lsrs r5, r0, 24 - lsls r1, 24 - lsrs r6, r1, 24 - ldr r1, =gUnknown_02039F18 - lsls r0, r5, 1 - adds r0, r1 - movs r2, 0 - ldrsh r0, [r0, r2] - adds r7, r1, 0 - cmp r0, 0 - bge _080F7380 - negs r0, r0 -_080F7380: - lsls r4, r0, 16 - adds r0, r4, 0 - movs r1, 0x50 - bl __udivsi3 - adds r2, r0, 0 - ldr r0, =0x0000ffff - ands r0, r2 - cmp r0, 0 - beq _080F739A - movs r0, 0x80 - lsls r0, 9 - adds r2, r0 -_080F739A: - lsrs r2, 16 - cmp r2, 0 - bne _080F73A6 - cmp r4, 0 - beq _080F73A6 - movs r2, 0x1 -_080F73A6: - cmp r6, 0 - beq _080F73B0 - cmp r2, 0xA - bls _080F73B0 - movs r2, 0xA -_080F73B0: - lsls r0, r5, 1 - adds r0, r7 - movs r1, 0 - ldrsh r0, [r0, r1] - cmp r0, 0 - bge _080F73CC - negs r0, r2 - lsls r0, 24 - b _080F73CE - .pool -_080F73CC: - lsls r0, r2, 24 -_080F73CE: - lsrs r0, 24 - lsls r0, 24 - asrs r0, 24 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_80F7364 - - thumb_func_start sub_80F73DC -sub_80F73DC: @ 80F73DC - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x10 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - ldr r1, =gTasks - lsls r0, 2 - add r0, r8 - lsls r0, 3 - adds r7, r0, r1 - ldrh r2, [r7, 0x1C] - movs r0, 0x1C - ldrsh r6, [r7, r0] - cmp r6, 0 - bne _080F741C - movs r1, 0x8 - ldrsh r0, [r7, r1] - movs r1, 0x3 - subs r1, r0 - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - strh r0, [r7, 0x1E] - adds r0, r2, 0x1 - strh r0, [r7, 0x1C] - b _080F74A4 - .pool -_080F741C: - cmp r6, 0x1 - bne _080F74A4 - ldrh r0, [r7, 0x1E] - subs r0, 0x1 - strh r0, [r7, 0x1E] - lsls r0, 16 - asrs r0, 16 - movs r1, 0x1 - negs r1, r1 - cmp r0, r1 - bne _080F74A4 - movs r2, 0x8 - ldrsh r4, [r7, r2] - lsls r4, 17 - ldr r0, =0x50430000 - adds r4, r0 - lsrs r4, 16 - movs r1, 0xA - ldrsh r0, [r7, r1] - lsls r3, r0, 1 - adds r3, r0 - adds r3, 0x5 - lsls r3, 24 - lsrs r3, 24 - movs r2, 0x2 - mov r9, r2 - str r2, [sp] - str r6, [sp, 0x4] - movs r5, 0x11 - str r5, [sp, 0x8] - str r6, [sp, 0xC] - movs r0, 0x2 - adds r1, r4, 0 - movs r2, 0x1 - bl WriteSequenceToBgTilemapBuffer - adds r4, 0x10 - lsls r4, 16 - lsrs r4, 16 - movs r1, 0xA - ldrsh r0, [r7, r1] - lsls r3, r0, 1 - adds r3, r0 - adds r3, 0x6 - lsls r3, 24 - lsrs r3, 24 - mov r2, r9 - str r2, [sp] - str r6, [sp, 0x4] - str r5, [sp, 0x8] - str r6, [sp, 0xC] - movs r0, 0x2 - adds r1, r4, 0 - movs r2, 0x1 - bl WriteSequenceToBgTilemapBuffer - ldr r0, =gUnknown_0203A034 - ldr r0, [r0] - ldr r1, [r0] - ldrb r0, [r1, 0x5] - adds r0, 0x1 - strb r0, [r1, 0x5] - mov r0, r8 - bl DestroyTask - movs r0, 0x18 - bl PlaySE -_080F74A4: - add sp, 0x10 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80F73DC - - thumb_func_start sub_80F74BC -sub_80F74BC: @ 80F74BC - push {r4-r6,lr} - sub sp, 0xC - lsls r0, 24 - lsrs r5, r0, 24 - movs r4, 0 - ldr r1, =gContestFinalStandings - ldrb r0, [r1] - ldr r6, =gUnknown_0203A034 - cmp r0, 0 - beq _080F74DE -_080F74D0: - adds r4, 0x1 - cmp r4, 0x3 - bgt _080F74DE - adds r0, r4, r1 - ldrb r0, [r0] - cmp r0, 0 - bne _080F74D0 -_080F74DE: - ldr r1, [r6] - lsls r3, r4, 1 - adds r3, r4 - lsls r0, r3, 6 - movs r2, 0x80 - lsls r2, 1 - adds r0, r2 - ldr r1, [r1, 0x14] - adds r1, r0 - adds r3, 0x4 - lsls r3, 24 - lsrs r3, 24 - movs r0, 0x20 - str r0, [sp] - movs r0, 0x3 - str r0, [sp, 0x4] - movs r0, 0x9 - str r0, [sp, 0x8] - movs r0, 0x2 - movs r2, 0 - bl CopyToBgTilemapBufferRect_ChangePalette - ldr r1, =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r0, r1 - strh r4, [r0, 0x1C] - movs r1, 0x1 - strh r1, [r0, 0x20] - ldr r1, =sub_80F753C - str r1, [r0] - ldr r0, [r6] - ldr r0, [r0] - strb r5, [r0, 0x3] - add sp, 0xC - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80F74BC - - thumb_func_start sub_80F753C -sub_80F753C: @ 80F753C - push {r4,r5,lr} - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r4, r1, r2 - ldrh r0, [r4, 0x1E] - adds r0, 0x1 - strh r0, [r4, 0x1E] - lsls r0, 16 - asrs r5, r0, 16 - cmp r5, 0x1 - bne _080F75A0 - movs r0, 0 - strh r0, [r4, 0x1E] - ldrh r2, [r4, 0x20] - lsls r2, 24 - lsrs r2, 24 - ldr r3, =0x00006f8d - movs r0, 0x91 - movs r1, 0x1 - bl BlendPalette - movs r1, 0x22 - ldrsh r0, [r4, r1] - cmp r0, 0 - bne _080F7590 - ldrh r0, [r4, 0x20] - adds r0, 0x1 - strh r0, [r4, 0x20] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x10 - bne _080F75A0 - strh r5, [r4, 0x22] - b _080F75A0 - .pool -_080F7590: - ldrh r0, [r4, 0x20] - subs r0, 0x1 - strh r0, [r4, 0x20] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0 - bne _080F75A0 - strh r0, [r4, 0x22] -_080F75A0: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_80F753C - - thumb_func_start sub_80F75A8 -sub_80F75A8: @ 80F75A8 - push {r4,lr} - adds r4, r0, 0 - ldrh r1, [r4, 0x2E] - movs r2, 0x2E - ldrsh r0, [r4, r2] - cmp r0, 0x9 - bgt _080F75D0 - adds r0, r1, 0x1 - strh r0, [r4, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0xA - bne _080F7610 - ldrh r0, [r4, 0x30] - movs r1, 0 - bl PlayCry1 - movs r0, 0 - strh r0, [r4, 0x30] - b _080F7610 -_080F75D0: - movs r0, 0xC0 - lsls r0, 3 - adds r2, r0, 0 - ldrh r1, [r4, 0x30] - adds r2, r1 - lsls r1, r2, 16 - asrs r1, 24 - ldrh r0, [r4, 0x20] - subs r0, r1 - strh r0, [r4, 0x20] - movs r1, 0xFF - ands r2, r1 - strh r2, [r4, 0x30] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x77 - bgt _080F75F6 - movs r0, 0x78 - strh r0, [r4, 0x20] -_080F75F6: - movs r2, 0x20 - ldrsh r0, [r4, r2] - cmp r0, 0x78 - bne _080F7610 - ldr r0, =SpriteCallbackDummy - str r0, [r4, 0x1C] - movs r0, 0 - strh r0, [r4, 0x30] - ldr r0, =gUnknown_0203A034 - ldr r0, [r0] - ldr r1, [r0] - movs r0, 0x1 - strb r0, [r1, 0x6] -_080F7610: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80F75A8 - - thumb_func_start sub_80F7620 -sub_80F7620: @ 80F7620 - push {lr} - adds r3, r0, 0 - movs r0, 0xC0 - lsls r0, 3 - adds r2, r0, 0 - ldrh r0, [r3, 0x30] - adds r2, r0 - lsls r1, r2, 16 - asrs r1, 24 - ldrh r0, [r3, 0x20] - subs r0, r1 - strh r0, [r3, 0x20] - movs r1, 0xFF - ands r2, r1 - strh r2, [r3, 0x30] - lsls r0, 16 - asrs r0, 16 - movs r1, 0x20 - negs r1, r1 - cmp r0, r1 - bge _080F7664 - ldr r0, =SpriteCallbackDummy - str r0, [r3, 0x1C] - adds r2, r3, 0 - adds r2, 0x3E - ldrb r0, [r2] - movs r1, 0x4 - orrs r0, r1 - strb r0, [r2] - ldr r0, =gUnknown_0203A034 - ldr r0, [r0] - ldr r1, [r0] - movs r0, 0x2 - strb r0, [r1, 0x6] -_080F7664: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80F7620 - thumb_func_start sub_80F7670 sub_80F7670: @ 80F7670 push {r4-r7,lr} diff --git a/src/contest_link_80F57C4.c b/src/contest_link_80F57C4.c index 381fb34fa..c72fc9ba3 100644 --- a/src/contest_link_80F57C4.c +++ b/src/contest_link_80F57C4.c @@ -110,13 +110,14 @@ static void sub_80F6EF4(u16); static void sub_80F60F0(u8); static void sub_80F616C(u8); static void sub_80F6204(u8); -void sub_80F73DC(u8); -void sub_80F74BC(u8); +static void sub_80F73DC(u8); +static void sub_80F74BC(u8); +static void sub_80F753C(u8); void sub_80F77E0(u8, u8); static void sub_80F6404(u8); -void sub_80F75A8(struct Sprite *); +static void sub_80F75A8(struct Sprite *); void sub_80F7670(u8); -void sub_80F7620(struct Sprite *); +static void sub_80F7620(struct Sprite *); static void sub_80F66B4(u8); static void sub_80F671C(u8); static void sub_80F677C(u8); @@ -1439,3 +1440,130 @@ u8 sub_80F7310(u8 monIndex, u8 arg1) return var1; } + +s8 sub_80F7364(u8 arg0, u8 arg1) +{ + u32 r4; + u32 r2; + s16 val; + s8 ret; + + val = gUnknown_02039F18[arg0]; + if (val < 0) + r4 = -val << 16; + else + r4 = val << 16; + + r2 = r4 / 80; + if (r2 & 0xFFFF) + r2 += 0x10000; + + r2 >>= 16; + if (r2 == 0 && r4 != 0) + r2 = 1; + + if (arg1 != 0 && r2 > 10) + r2 = 10; + + if (gUnknown_02039F18[arg0] < 0) + ret = -r2; + else + ret = r2; + + return ret; +} + +static void sub_80F73DC(u8 taskId) +{ + u16 firstTileNum; + + if (gTasks[taskId].data[10] == 0) + { + gTasks[taskId].data[11] = (3 - gTasks[taskId].data[0]) * 40; + gTasks[taskId].data[10]++; + } + else if (gTasks[taskId].data[10] == 1) + { + if (--gTasks[taskId].data[11] == -1) + { + firstTileNum = gTasks[taskId].data[0] * 2 + 0x5043; + WriteSequenceToBgTilemapBuffer(2, firstTileNum, 1, gTasks[taskId].data[1] * 3 + 5, 2, 1, 17, 1); + WriteSequenceToBgTilemapBuffer(2, firstTileNum + 0x10, 1, gTasks[taskId].data[1] * 3 + 6, 2, 1, 17, 1); + gUnknown_0203A034->unk0->unk5++; + DestroyTask(taskId); + PlaySE(SE_JYUNI); + } + } +} + +static void sub_80F74BC(u8 taskId) +{ + int i; + for (i = 0; i < 4 && gContestFinalStandings[i] != 0; i++) + ; + + CopyToBgTilemapBufferRect_ChangePalette(2, i * 0xC0 + 0x100 + gUnknown_0203A034->unkC[2], 0, i * 3 + 4, 32, 3, 9); + gTasks[taskId].data[10] = i; + gTasks[taskId].data[12] = 1; + gTasks[taskId].func = sub_80F753C; + gUnknown_0203A034->unk0->unk3 = taskId; +} + +static void sub_80F753C(u8 taskId) +{ + if (++gTasks[taskId].data[11] == 1) + { + gTasks[taskId].data[11] = 0; + BlendPalette(0x91, 1, gTasks[taskId].data[12], RGB(13, 28, 27)); + if (gTasks[taskId].data[13] == 0) + { + if (++gTasks[taskId].data[12] == 16) + gTasks[taskId].data[13] = 1; + } + else + { + if (--gTasks[taskId].data[12] == 0) + gTasks[taskId].data[13] = 0; + } + } +} + +static void sub_80F75A8(struct Sprite *sprite) +{ + if (sprite->data[0] < 10) + { + if (++sprite->data[0] == 10) + { + PlayCry1(sprite->data[1], 0); + sprite->data[1] = 0; + } + } + else + { + s16 delta = (u16)sprite->data[1] + 0x600; + sprite->pos1.x -= delta >> 8; + sprite->data[1] = (sprite->data[1] + 0x600) & 0xFF; + if (sprite->pos1.x < 120) + sprite->pos1.x = 120; + + if (sprite->pos1.x == 120) + { + sprite->callback = SpriteCallbackDummy; + sprite->data[1] = 0; + gUnknown_0203A034->unk0->unk6 = 1; + } + } +} + +static void sub_80F7620(struct Sprite *sprite) +{ + s16 delta = (u16)sprite->data[1] + 0x600; + sprite->pos1.x -= delta >> 8; + sprite->data[1] = (sprite->data[1] + 0x600) & 0xFF; + if (sprite->pos1.x < -32) + { + sprite->callback = SpriteCallbackDummy; + sprite->invisible = 1; + gUnknown_0203A034->unk0->unk6 = 2; + } +}