diff --git a/asm/roulette_util.s b/asm/roulette_util.s deleted file mode 100644 index 61f6f67b1..000000000 --- a/asm/roulette_util.s +++ /dev/null @@ -1,1431 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_8151678 -sub_8151678: @ 8151678 - push {lr} - movs r1, 0 - strb r1, [r0] - strh r1, [r0, 0x2] - adds r0, 0x4 - movs r2, 0xC0 - bl memset - pop {r0} - bx r0 - thumb_func_end sub_8151678 - - thumb_func_start sub_815168C -sub_815168C: @ 815168C - push {r4-r7,lr} - adds r3, r0, 0 - lsls r1, 24 - lsrs r6, r1, 24 - cmp r6, 0xF - bhi _081516A8 - lsls r0, r6, 1 - adds r0, r6 - lsls r0, 2 - adds r5, r3, r0 - ldrb r7, [r5, 0x4] - lsrs r0, r7, 7 - cmp r0, 0 - beq _081516AC -_081516A8: - movs r0, 0xFF - b _0815170A -_081516AC: - ldrh r0, [r2] - movs r4, 0 - strh r0, [r5, 0x8] - ldrh r0, [r2, 0x2] - strh r0, [r5, 0xA] - ldrb r0, [r2, 0x4] - strb r0, [r5, 0xC] - ldrb r0, [r2, 0x5] - strb r0, [r5, 0xD] - ldrb r0, [r2, 0x6] - strb r0, [r5, 0xE] - ldrb r3, [r2, 0x7] - lsls r0, r3, 27 - lsrs r0, 27 - ldrb r2, [r5, 0xF] - movs r1, 0x20 - negs r1, r1 - ands r1, r2 - orrs r1, r0 - movs r0, 0x60 - ands r0, r3 - movs r2, 0x61 - negs r2, r2 - ands r1, r2 - orrs r1, r0 - lsls r3, 24 - asrs r3, 31 - lsls r3, 7 - movs r0, 0x7F - ands r1, r0 - orrs r1, r3 - strb r1, [r5, 0xF] - subs r0, 0xFF - ands r0, r7 - movs r2, 0x80 - orrs r0, r2 - strb r0, [r5, 0x4] - strb r4, [r5, 0x6] - strb r4, [r5, 0x5] - lsls r1, 24 - cmp r1, 0 - bge _08151704 - movs r0, 0xFF - b _08151706 -_08151704: - movs r0, 0x1 -_08151706: - strb r0, [r5, 0x7] - adds r0, r6, 0 -_0815170A: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_815168C - - thumb_func_start sub_8151710 -sub_8151710: @ 8151710 - push {r4,lr} - adds r2, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r4, r1, 0 - cmp r4, 0xF - bhi _0815173C - lsls r0, r4, 1 - adds r0, r4 - lsls r0, 2 - adds r1, r2, r0 - ldrb r0, [r1, 0x4] - lsrs r0, 7 - cmp r0, 0 - beq _0815173C - adds r0, r1, 0x4 - movs r1, 0 - movs r2, 0xC - bl memset - adds r0, r4, 0 - b _0815173E -_0815173C: - movs r0, 0xFF -_0815173E: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8151710 - - thumb_func_start sub_8151744 -sub_8151744: @ 8151744 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - adds r5, r0, 0 - movs r0, 0 - mov r12, r0 - ldrb r1, [r5, 0x8] - cmp r12, r1 - bcc _0815175C - b _081518F4 -_0815175C: - movs r7, 0x1F - ldr r0, =0xfffffc1f - mov r10, r0 - movs r1, 0x7D - negs r1, r1 - mov r9, r1 - movs r0, 0x1F - mov r8, r0 -_0815176C: - ldrh r0, [r5, 0x6] - add r0, r12 - lsls r0, 1 - ldr r1, =gPlttBufferFaded - adds r3, r0, r1 - ldr r1, =gPlttBufferUnfaded - adds r6, r0, r1 - ldrb r0, [r5] - lsls r0, 25 - lsrs r0, 25 - cmp r0, 0x1 - beq _08151798 - cmp r0, 0x2 - beq _081517F6 - b _081518E2 - .pool -_08151798: - ldr r0, [r3] - lsls r2, r0, 27 - lsrs r0, r2, 27 - movs r1, 0x3 - ldrsb r1, [r5, r1] - adds r0, r1 - cmp r0, 0x1F - bhi _081517BA - lsrs r0, r2, 27 - adds r0, r1 - ands r0, r7 - ldrb r2, [r3] - movs r1, 0x20 - negs r1, r1 - ands r1, r2 - orrs r1, r0 - strb r1, [r3] -_081517BA: - ldr r0, [r3] - lsls r2, r0, 22 - lsrs r0, r2, 27 - movs r1, 0x3 - ldrsb r1, [r5, r1] - adds r0, r1 - cmp r0, 0x1F - bhi _081517DE - lsrs r0, r2, 27 - adds r0, r1 - mov r1, r8 - ands r0, r1 - lsls r0, 5 - ldrh r2, [r3] - mov r1, r10 - ands r1, r2 - orrs r1, r0 - strh r1, [r3] -_081517DE: - ldr r0, [r3] - lsls r2, r0, 17 - lsrs r0, r2, 27 - movs r1, 0x3 - ldrsb r1, [r5, r1] - adds r0, r1 - cmp r0, 0x1F - bls _081517F0 - b _081518E2 -_081517F0: - lsrs r0, r2, 27 - adds r0, r1 - b _081518D4 -_081517F6: - movs r0, 0x3 - ldrsb r0, [r5, r0] - cmp r0, 0 - bge _08151868 - ldr r0, [r3] - lsls r4, r0, 27 - lsrs r1, r4, 27 - movs r2, 0x3 - ldrsb r2, [r5, r2] - adds r1, r2 - ldr r0, [r6] - lsls r0, 27 - lsrs r0, 27 - cmp r1, r0 - blt _08151826 - lsrs r0, r4, 27 - adds r0, r2 - ands r0, r7 - ldrb r2, [r3] - movs r1, 0x20 - negs r1, r1 - ands r1, r2 - orrs r1, r0 - strb r1, [r3] -_08151826: - ldr r0, [r3] - lsls r4, r0, 22 - lsrs r1, r4, 27 - movs r2, 0x3 - ldrsb r2, [r5, r2] - adds r1, r2 - ldr r0, [r6] - lsls r0, 22 - lsrs r0, 27 - cmp r1, r0 - blt _08151850 - lsrs r0, r4, 27 - adds r0, r2 - mov r1, r8 - ands r0, r1 - lsls r0, 5 - ldrh r2, [r3] - mov r1, r10 - ands r1, r2 - orrs r1, r0 - strh r1, [r3] -_08151850: - ldr r0, [r3] - lsls r4, r0, 17 - lsrs r1, r4, 27 - movs r2, 0x3 - ldrsb r2, [r5, r2] - adds r1, r2 - ldr r0, [r6] - lsls r0, 17 - lsrs r0, 27 - cmp r1, r0 - blt _081518E2 - b _081518D0 -_08151868: - ldr r0, [r3] - lsls r4, r0, 27 - lsrs r1, r4, 27 - movs r2, 0x3 - ldrsb r2, [r5, r2] - adds r1, r2 - ldr r0, [r6] - lsls r0, 27 - lsrs r0, 27 - cmp r1, r0 - bgt _08151890 - lsrs r0, r4, 27 - adds r0, r2 - ands r0, r7 - ldrb r2, [r3] - movs r1, 0x20 - negs r1, r1 - ands r1, r2 - orrs r1, r0 - strb r1, [r3] -_08151890: - ldr r0, [r3] - lsls r4, r0, 22 - lsrs r1, r4, 27 - movs r2, 0x3 - ldrsb r2, [r5, r2] - adds r1, r2 - ldr r0, [r6] - lsls r0, 22 - lsrs r0, 27 - cmp r1, r0 - bgt _081518BA - lsrs r0, r4, 27 - adds r0, r2 - mov r1, r8 - ands r0, r1 - lsls r0, 5 - ldrh r2, [r3] - mov r1, r10 - ands r1, r2 - orrs r1, r0 - strh r1, [r3] -_081518BA: - ldr r0, [r3] - lsls r4, r0, 17 - lsrs r1, r4, 27 - movs r2, 0x3 - ldrsb r2, [r5, r2] - adds r1, r2 - ldr r0, [r6] - lsls r0, 17 - lsrs r0, 27 - cmp r1, r0 - bgt _081518E2 -_081518D0: - lsrs r0, r4, 27 - adds r0, r2 -_081518D4: - ands r0, r7 - lsls r0, 2 - ldrb r2, [r3, 0x1] - mov r1, r9 - ands r1, r2 - orrs r1, r0 - strb r1, [r3, 0x1] -_081518E2: - mov r0, r12 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r12, r0 - ldrb r0, [r5, 0x8] - cmp r12, r0 - bcs _081518F4 - b _0815176C -_081518F4: - ldrb r1, [r5, 0x2] - adds r0, r1, 0x1 - strb r0, [r5, 0x2] - ldrb r0, [r5, 0xB] - lsls r0, 27 - lsls r1, 24 - asrs r0, 3 - cmp r1, r0 - beq _0815190A - movs r0, 0 - b _0815193E -_0815190A: - movs r0, 0 - strb r0, [r5, 0x2] - movs r0, 0x3 - ldrsb r0, [r5, r0] - negs r0, r0 - strb r0, [r5, 0x3] - ldrb r2, [r5] - movs r1, 0x7F - movs r0, 0x7F - ands r0, r2 - cmp r0, 0x1 - bne _0815192A - lsls r0, r2, 25 - lsrs r0, 25 - adds r0, 0x1 - b _08151930 -_0815192A: - lsls r0, r2, 25 - lsrs r0, 25 - subs r0, 0x1 -_08151930: - ands r0, r1 - movs r1, 0x80 - negs r1, r1 - ands r1, r2 - orrs r1, r0 - strb r1, [r5] - movs r0, 0x1 -_0815193E: - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8151744 - - thumb_func_start sub_815194C -sub_815194C: @ 815194C - push {r4,r5,lr} - adds r3, r0, 0 - movs r2, 0 - ldrb r0, [r3] - lsls r0, 25 - lsrs r0, 25 - cmp r0, 0x1 - beq _08151962 - cmp r0, 0x2 - beq _08151990 - b _081519CA -_08151962: - ldrb r0, [r3, 0x8] - cmp r2, r0 - bcs _08151982 - ldr r4, =gPlttBufferFaded -_0815196A: - ldrh r0, [r3, 0x6] - adds r0, r2 - lsls r0, 1 - adds r0, r4 - ldrh r1, [r3, 0x4] - strh r1, [r0] - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 - ldrb r0, [r3, 0x8] - cmp r2, r0 - bcc _0815196A -_08151982: - ldrb r2, [r3] - lsls r1, r2, 25 - lsrs r1, 25 - adds r1, 0x1 - b _081519BC - .pool -_08151990: - ldrb r0, [r3, 0x8] - cmp r2, r0 - bcs _081519B4 - ldr r5, =gPlttBufferFaded - ldr r4, =gPlttBufferUnfaded -_0815199A: - ldrh r0, [r3, 0x6] - adds r0, r2 - lsls r0, 1 - adds r1, r0, r5 - adds r0, r4 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 - ldrb r0, [r3, 0x8] - cmp r2, r0 - bcc _0815199A -_081519B4: - ldrb r2, [r3] - lsls r1, r2, 25 - lsrs r1, 25 - subs r1, 0x1 -_081519BC: - movs r0, 0x7F - ands r1, r0 - movs r0, 0x80 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r3] -_081519CA: - movs r0, 0x1 - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end sub_815194C - - thumb_func_start task_tutorial_controls_fadein -task_tutorial_controls_fadein: @ 81519DC - push {r4-r6,lr} - adds r4, r0, 0 - movs r5, 0 - ldrb r0, [r4] - cmp r0, 0 - beq _08151A40 -_081519E8: - ldrh r0, [r4, 0x2] - asrs r0, r5 - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - beq _08151A36 - lsls r1, r5, 1 - adds r0, r1, r5 - lsls r3, r0, 2 - adds r2, r4, r3 - ldrb r0, [r2, 0x5] - subs r0, 0x1 - strb r0, [r2, 0x5] - lsls r0, 24 - lsrs r0, 24 - adds r6, r1, 0 - cmp r0, 0xFF - bne _08151A36 - ldrh r0, [r2, 0x8] - movs r2, 0x80 - lsls r2, 8 - adds r1, r2, 0 - ands r0, r1 - cmp r0, 0 - beq _08151A24 - adds r0, r3, 0x4 - adds r0, r4, r0 - bl sub_8151744 - b _08151A2C -_08151A24: - adds r0, r3, 0x4 - adds r0, r4, r0 - bl sub_815194C -_08151A2C: - adds r0, r6, r5 - lsls r0, 2 - adds r0, r4, r0 - ldrb r1, [r0, 0xD] - strb r1, [r0, 0x5] -_08151A36: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0xF - bls _081519E8 -_08151A40: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end task_tutorial_controls_fadein - - thumb_func_start sub_8151A48 -sub_8151A48: @ 8151A48 - push {r4-r7,lr} - adds r3, r0, 0 - lsls r1, 16 - lsrs r6, r1, 16 - movs r4, 0 - ldrb r0, [r3] - adds r0, 0x1 - strb r0, [r3] - movs r5, 0x1 - movs r7, 0x80 - negs r7, r7 -_08151A5E: - adds r0, r6, 0 - asrs r0, r4 - ands r0, r5 - cmp r0, 0 - beq _08151A8C - lsls r0, r4, 1 - adds r0, r4 - lsls r0, 2 - adds r2, r3, r0 - ldrb r0, [r2, 0x4] - lsrs r0, 7 - cmp r0, 0 - beq _08151A8C - adds r0, r5, 0 - lsls r0, r4 - ldrh r1, [r3, 0x2] - orrs r0, r1 - strh r0, [r3, 0x2] - ldrb r1, [r2, 0x4] - adds r0, r7, 0 - ands r0, r1 - orrs r0, r5 - strb r0, [r2, 0x4] -_08151A8C: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0xF - bls _08151A5E - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8151A48 - - thumb_func_start sub_8151A9C -sub_8151A9C: @ 8151A9C - push {r4-r7,lr} - sub sp, 0x4 - adds r6, r0, 0 - lsls r1, 16 - lsrs r7, r1, 16 - movs r5, 0 - movs r3, 0x1 -_08151AAA: - ldrh r0, [r6, 0x2] - asrs r0, r5 - ands r0, r3 - cmp r0, 0 - beq _08151B12 - lsls r0, r5, 1 - adds r0, r5 - lsls r0, 2 - adds r4, r6, r0 - ldrb r0, [r4, 0x4] - lsrs r0, 7 - cmp r0, 0 - beq _08151B12 - adds r0, r7, 0 - asrs r0, r5 - ands r0, r3 - cmp r0, 0 - beq _08151B12 - ldrh r1, [r4, 0xA] - lsls r1, 1 - ldr r0, =gPlttBufferFaded - adds r0, r1, r0 - ldr r2, =gPlttBufferUnfaded - adds r1, r2 - ldrb r2, [r4, 0xC] - lsls r2, 1 - str r3, [sp] - bl memcpy - ldrb r0, [r4, 0x4] - movs r2, 0x80 - negs r2, r2 - adds r1, r2, 0 - ands r0, r1 - strb r0, [r4, 0x4] - movs r0, 0 - strb r0, [r4, 0x6] - strb r0, [r4, 0x5] - ldrb r0, [r4, 0xF] - lsls r0, 24 - ldr r3, [sp] - cmp r0, 0 - bge _08151B10 - movs r0, 0xFF - strb r0, [r4, 0x7] - b _08151B12 - .pool -_08151B10: - strb r3, [r4, 0x7] -_08151B12: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0xF - bls _08151AAA - ldr r0, =0x0000ffff - cmp r7, r0 - bne _08151B2C - movs r0, 0 - strb r0, [r6] - b _08151B30 - .pool -_08151B2C: - ldrh r0, [r6, 0x2] - bics r0, r7 -_08151B30: - strh r0, [r6, 0x2] - add sp, 0x4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8151A9C - - thumb_func_start sub_8151B3C -sub_8151B3C: @ 8151B3C - push {r4,r5,lr} - adds r5, r0, 0 - movs r4, 0 - strh r4, [r5] - adds r0, r5, 0x4 - movs r1, 0 - movs r2, 0xC0 - bl memset -_08151B4E: - lsls r0, r4, 1 - adds r0, r4 - lsls r0, 2 - adds r0, r5, r0 - strb r4, [r0, 0x4] - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0xF - bls _08151B4E - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_8151B3C - - thumb_func_start sub_8151B68 -sub_8151B68: @ 8151B68 - push {r4,r5,lr} - adds r2, r0, 0 - adds r5, r1, 0 - movs r3, 0 - movs r4, 0 - ldrb r0, [r2, 0x5] - lsrs r0, 7 - cmp r0, 0 - bne _08151B7E - adds r4, r2, 0x4 - b _08151B9C -_08151B7E: - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, 0xF - bhi _08151B9C - lsls r0, r3, 1 - adds r0, r3 - lsls r1, r0, 2 - adds r0, r2, r1 - ldrb r0, [r0, 0x5] - lsrs r0, 7 - cmp r0, 0 - bne _08151B7E - adds r0, r1, 0x4 - adds r4, r2, r0 -_08151B9C: - cmp r4, 0 - beq _08151BCA - ldrb r1, [r4, 0x1] - movs r0, 0x10 - negs r0, r0 - ands r0, r1 - movs r1, 0x11 - negs r1, r1 - ands r0, r1 - movs r1, 0x40 - orrs r0, r1 - movs r1, 0x80 - orrs r0, r1 - strb r0, [r4, 0x1] - movs r0, 0 - strb r0, [r4, 0x2] - strb r0, [r4, 0x3] - adds r1, r4, 0x4 - adds r0, r5, 0 - ldm r0!, {r2,r4} - stm r1!, {r2,r4} - adds r0, r3, 0 - b _08151BCC -_08151BCA: - movs r0, 0xFF -_08151BCC: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_8151B68 - - thumb_func_start sub_8151BD4 -sub_8151BD4: @ 8151BD4 - push {r4,r5,lr} - adds r4, r0, 0 - ldrb r1, [r4, 0x1] - movs r2, 0x40 - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - bne _08151C16 - ldrb r1, [r4, 0xB] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - beq _08151C16 - ldrh r2, [r4, 0x6] - ldrb r0, [r4, 0x8] - adds r0, r2, r0 - cmp r2, r0 - bge _08151C16 - ldr r5, =gPlttBufferFaded - ldr r3, =gPlttBufferUnfaded -_08151BFC: - lsls r0, r2, 1 - adds r1, r0, r5 - adds r0, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - ldrh r0, [r4, 0x6] - ldrb r1, [r4, 0x8] - adds r0, r1 - cmp r2, r0 - blt _08151BFC -_08151C16: - adds r0, r4, 0x4 - movs r1, 0 - movs r2, 0x8 - bl memset - ldrb r1, [r4, 0x1] - movs r0, 0x10 - negs r0, r0 - ands r0, r1 - movs r1, 0x11 - negs r1, r1 - ands r0, r1 - subs r1, 0x10 - ands r0, r1 - movs r1, 0x40 - orrs r0, r1 - movs r1, 0x7F - ands r0, r1 - strb r0, [r4, 0x1] - movs r0, 0 - strb r0, [r4, 0x3] - strb r0, [r4, 0x2] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8151BD4 - - thumb_func_start sub_8151C50 -sub_8151C50: @ 8151C50 - push {r4-r6,lr} - adds r6, r0, 0 - lsls r1, 16 - lsrs r4, r1, 16 - lsls r2, 24 - movs r5, 0 - cmp r2, 0 - bne _08151C74 - movs r1, 0xF - ands r1, r4 - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, 0x4 - adds r0, r6, r0 - bl sub_8151BD4 - b _08151CA0 -_08151C74: - movs r0, 0x1 - ands r0, r4 - cmp r0, 0 - beq _08151C94 - lsls r0, r5, 1 - adds r0, r5 - lsls r1, r0, 2 - adds r0, r6, r1 - ldrb r0, [r0, 0x5] - lsrs r0, 7 - cmp r0, 0 - beq _08151C94 - adds r0, r1, 0x4 - adds r0, r6, r0 - bl sub_8151BD4 -_08151C94: - lsrs r4, 1 - adds r0, r5, 0x1 - lsls r0, 16 - lsrs r5, r0, 16 - cmp r5, 0xF - bls _08151C74 -_08151CA0: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_8151C50 - - thumb_func_start sub_8151CA8 -sub_8151CA8: @ 8151CA8 - push {r4-r7,lr} - adds r5, r0, 0 - lsls r1, 16 - lsrs r4, r1, 16 - lsls r2, 24 - movs r3, 0 - cmp r2, 0 - bne _08151CDC - movs r0, 0xF - adds r3, r0, 0 - ands r3, r4 - lsls r1, r3, 1 - adds r1, r3 - lsls r1, 2 - adds r1, r5, r1 - ldrb r2, [r1, 0x5] - movs r0, 0x41 - negs r0, r0 - ands r0, r2 - strb r0, [r1, 0x5] - movs r0, 0x1 - lsls r0, r3 - ldrh r1, [r5] - orrs r0, r1 - strh r0, [r5] - b _08151D20 -_08151CDC: - movs r6, 0x1 - movs r7, 0x41 - negs r7, r7 -_08151CE2: - adds r0, r4, 0 - ands r0, r6 - cmp r0, 0 - beq _08151D00 - lsls r0, r3, 1 - adds r0, r3 - lsls r0, 2 - adds r2, r5, r0 - ldrb r1, [r2, 0x5] - lsrs r0, r1, 7 - cmp r0, 0 - beq _08151D00 - lsls r0, r1, 25 - cmp r0, 0 - blt _08151D06 -_08151D00: - lsls r0, r4, 17 - lsrs r4, r0, 16 - b _08151D16 -_08151D06: - adds r0, r7, 0 - ands r0, r1 - strb r0, [r2, 0x5] - adds r0, r6, 0 - lsls r0, r3 - ldrh r1, [r5] - orrs r0, r1 - strh r0, [r5] -_08151D16: - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, 0xF - bls _08151CE2 -_08151D20: - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8151CA8 - - thumb_func_start sub_8151D28 -sub_8151D28: @ 8151D28 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - mov r8, r0 - lsls r1, 16 - lsrs r7, r1, 16 - lsls r2, 24 - movs r0, 0 - mov r12, r0 - cmp r2, 0 - bne _08151DB0 - movs r1, 0xF - ands r1, r7 - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, 0x4 - mov r1, r8 - adds r3, r1, r0 - ldrb r1, [r3, 0x1] - movs r0, 0xC0 - ands r0, r1 - cmp r0, 0x80 - bne _08151E3A - ldrb r1, [r3, 0xB] - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - beq _08151D8E - ldrh r2, [r3, 0x6] - ldrb r0, [r3, 0x8] - adds r0, r2, r0 - cmp r2, r0 - bge _08151D8E - ldr r5, =gPlttBufferFaded - ldr r4, =gPlttBufferUnfaded -_08151D74: - lsls r0, r2, 1 - adds r1, r0, r5 - adds r0, r4 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - ldrh r0, [r3, 0x6] - ldrb r1, [r3, 0x8] - adds r0, r1 - cmp r2, r0 - blt _08151D74 -_08151D8E: - ldrb r0, [r3, 0x1] - movs r1, 0x40 - orrs r0, r1 - strb r0, [r3, 0x1] - movs r1, 0x1 - mov r2, r12 - lsls r1, r2 - mov r2, r8 - ldrh r0, [r2] - bics r0, r1 - strh r0, [r2] - b _08151E3A - .pool -_08151DB0: - movs r0, 0x1 - mov r9, r0 - movs r1, 0x40 - mov r10, r1 -_08151DB8: - mov r2, r12 - lsls r0, r2, 1 - add r0, r12 - lsls r0, 2 - adds r0, 0x4 - mov r1, r8 - adds r3, r1, r0 - adds r0, r7, 0 - mov r2, r9 - ands r0, r2 - cmp r0, 0 - beq _08151DDA - ldrb r1, [r3, 0x1] - movs r0, 0xC0 - ands r0, r1 - cmp r0, 0x80 - beq _08151DE4 -_08151DDA: - lsls r0, r7, 17 - lsrs r7, r0, 16 - mov r5, r12 - adds r5, 0x1 - b _08151E30 -_08151DE4: - ldrb r1, [r3, 0xB] - mov r0, r10 - ands r0, r1 - mov r5, r12 - adds r5, 0x1 - cmp r0, 0 - beq _08151E1A - ldrh r2, [r3, 0x6] - ldrb r0, [r3, 0x8] - adds r0, r2, r0 - cmp r2, r0 - bge _08151E1A - ldr r6, =gPlttBufferFaded - ldr r4, =gPlttBufferUnfaded -_08151E00: - lsls r0, r2, 1 - adds r1, r0, r6 - adds r0, r4 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - ldrh r0, [r3, 0x6] - ldrb r1, [r3, 0x8] - adds r0, r1 - cmp r2, r0 - blt _08151E00 -_08151E1A: - ldrb r1, [r3, 0x1] - mov r0, r10 - orrs r0, r1 - strb r0, [r3, 0x1] - mov r1, r9 - mov r0, r12 - lsls r1, r0 - mov r2, r8 - ldrh r0, [r2] - bics r0, r1 - strh r0, [r2] -_08151E30: - lsls r0, r5, 24 - lsrs r0, 24 - mov r12, r0 - cmp r0, 0xF - bls _08151DB8 -_08151E3A: - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8151D28 - - thumb_func_start sub_8151E50 -sub_8151E50: @ 8151E50 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - str r0, [sp] - movs r0, 0 - mov r10, r0 - ldr r1, [sp] - ldrh r0, [r1] - cmp r0, 0 - bne _08151E6C - b _08151FF6 -_08151E6C: - movs r2, 0xF - mov r9, r2 - movs r3, 0x10 - negs r3, r3 - mov r8, r3 - movs r7, 0x1 -_08151E78: - mov r5, r10 - lsls r0, r5, 1 - add r0, r10 - lsls r0, 2 - adds r0, 0x4 - ldr r1, [sp] - adds r4, r1, r0 - ldrb r2, [r4, 0x1] - movs r3, 0xC0 - ands r3, r2 - cmp r3, 0x80 - beq _08151E92 - b _08151FE6 -_08151E92: - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - adds r0, r3, 0 - ands r0, r1 - cmp r0, 0 - beq _08151EA8 - ldrb r0, [r4, 0xB] - ands r3, r0 - cmp r3, 0 - beq _08151EA8 - b _08151FE6 -_08151EA8: - ldrb r0, [r4, 0x2] - subs r0, 0x1 - strb r0, [r4, 0x2] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - beq _08151EB8 - b _08151FE6 -_08151EB8: - ldrb r0, [r4, 0x9] - strb r0, [r4, 0x2] - ldrh r0, [r4, 0x6] - ldrb r1, [r4, 0x8] - lsls r2, 28 - lsrs r2, 28 - ldrh r3, [r4, 0x4] - bl BlendPalette - ldrb r5, [r4, 0xB] - lsls r0, r5, 26 - asrs r0, 30 - cmp r0, 0x1 - beq _08151F16 - cmp r0, 0x1 - bgt _08151EE4 - cmp r0, 0 - beq _08151EEA - b _08151FD0 - .pool -_08151EE4: - cmp r0, 0x2 - beq _08151F92 - b _08151FD0 -_08151EEA: - ldrb r2, [r4, 0x1] - lsls r1, r2, 28 - lsrs r0, r1, 28 - adds r0, 0x1 - mov r3, r9 - ands r0, r3 - mov r6, r8 - adds r3, r6, 0 - ands r3, r2 - orrs r3, r0 - strb r3, [r4, 0x1] - lsrs r1, 28 - lsls r0, r5, 28 - asrs r0, 28 - cmp r1, r0 - bne _08151FD0 - ldrb r0, [r4, 0x3] - adds r0, 0x1 - strb r0, [r4, 0x3] - ands r3, r6 - strb r3, [r4, 0x1] - b _08151FD0 -_08151F16: - ldrb r3, [r4, 0x1] - movs r0, 0x10 - ands r0, r3 - cmp r0, 0 - beq _08151F54 - lsls r0, r3, 28 - lsrs r0, 28 - subs r0, 0x1 - mov r5, r9 - ands r0, r5 - mov r2, r8 - ands r2, r3 - orrs r2, r0 - strb r2, [r4, 0x1] - cmp r0, 0 - bne _08151FD0 - ldrb r0, [r4, 0x3] - adds r0, 0x1 - strb r0, [r4, 0x3] - lsls r0, r2, 27 - lsrs r0, 31 - eors r0, r7 - ands r0, r7 - lsls r0, 4 - movs r3, 0x11 - negs r3, r3 - adds r1, r3, 0 - ands r2, r1 - orrs r2, r0 - strb r2, [r4, 0x1] - b _08151FD0 -_08151F54: - lsls r0, r5, 28 - asrs r0, 28 - subs r0, 0x1 - mov r5, r9 - ands r0, r5 - lsls r2, r3, 28 - lsrs r1, r2, 28 - adds r1, 0x1 - ands r1, r5 - mov r5, r8 - ands r3, r5 - orrs r3, r1 - strb r3, [r4, 0x1] - lsrs r2, 28 - cmp r2, r0 - bne _08151FD0 - ldrb r0, [r4, 0x3] - adds r0, 0x1 - strb r0, [r4, 0x3] - lsls r0, r3, 27 - lsrs r0, 31 - eors r0, r7 - ands r0, r7 - lsls r0, 4 - movs r2, 0x11 - negs r2, r2 - adds r1, r2, 0 - ands r3, r1 - orrs r3, r0 - strb r3, [r4, 0x1] - b _08151FD0 -_08151F92: - ldrb r2, [r4, 0x1] - movs r0, 0x10 - ands r0, r2 - cmp r0, 0 - beq _08151FA2 - mov r0, r8 - ands r0, r2 - b _08151FB0 -_08151FA2: - lsls r1, r5, 28 - asrs r1, 28 - mov r3, r9 - ands r1, r3 - mov r0, r8 - ands r0, r2 - orrs r0, r1 -_08151FB0: - strb r0, [r4, 0x1] - ldrb r2, [r4, 0x1] - lsls r0, r2, 27 - lsrs r0, 31 - eors r0, r7 - ands r0, r7 - lsls r0, 4 - movs r5, 0x11 - negs r5, r5 - adds r1, r5, 0 - ands r2, r1 - orrs r2, r0 - strb r2, [r4, 0x1] - ldrb r0, [r4, 0x3] - adds r0, 0x1 - strb r0, [r4, 0x3] -_08151FD0: - ldrb r1, [r4, 0xA] - cmp r1, 0xFF - beq _08151FE6 - ldrb r0, [r4, 0x3] - cmp r0, r1 - bne _08151FE6 - ldrb r1, [r4] - ldr r0, [sp] - movs r2, 0 - bl sub_8151D28 -_08151FE6: - mov r0, r10 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r10, r0 - cmp r0, 0xF - bhi _08151FF6 - b _08151E78 -_08151FF6: - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8151E50 - - thumb_func_start sub_8152008 -sub_8152008: @ 8152008 - push {r4-r7,lr} - adds r6, r0, 0 - ldr r0, [sp, 0x14] - ldr r4, [sp, 0x18] - lsls r1, 16 - lsrs r7, r1, 16 - lsls r2, 24 - lsrs r2, 24 - lsls r3, 24 - lsls r0, 24 - lsrs r5, r0, 24 - lsls r4, 24 - lsrs r4, 24 - movs r1, 0 - lsrs r3, 19 - adds r3, r2 - lsls r3, 1 - adds r6, r3 - cmp r1, r4 - bcs _08152052 -_08152030: - lsls r0, r1, 6 - adds r2, r6, r0 - movs r0, 0 - adds r3, r1, 0x1 - cmp r0, r5 - bcs _0815204A -_0815203C: - strh r7, [r2] - adds r2, 0x2 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - cmp r0, r5 - bcc _0815203C -_0815204A: - lsls r0, r3, 24 - lsrs r1, r0, 24 - cmp r1, r4 - bcc _08152030 -_08152052: - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8152008 - - thumb_func_start sub_8152058 -sub_8152058: @ 8152058 - push {r4-r7,lr} - adds r7, r0, 0 - ldr r0, [sp, 0x14] - ldr r4, [sp, 0x18] - lsls r2, 24 - lsrs r2, 24 - lsls r3, 24 - lsls r0, 24 - lsrs r5, r0, 24 - lsls r4, 24 - lsrs r6, r4, 24 - movs r4, 0 - lsrs r3, 19 - adds r3, r2 - lsls r3, 1 - adds r7, r3 - cmp r4, r6 - bcs _081520A2 -_0815207C: - lsls r0, r4, 6 - adds r2, r7, r0 - movs r3, 0 - adds r4, 0x1 - cmp r3, r5 - bcs _0815209A -_08152088: - ldrh r0, [r1] - strh r0, [r2] - adds r1, 0x2 - adds r2, 0x2 - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, r5 - bcc _08152088 -_0815209A: - lsls r0, r4, 24 - lsrs r4, r0, 24 - cmp r4, r6 - bcc _0815207C -_081520A2: - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8152058 - - .align 2, 0 @ Don't pad with nop. diff --git a/include/roulette.h b/include/roulette.h new file mode 100755 index 000000000..71100d0d3 --- /dev/null +++ b/include/roulette.h @@ -0,0 +1,34 @@ +#ifndef GUARD_ROULETTE_H +#define GUARD_ROULETTE_H + +struct UnkStruct1 +{ + u16 var00; + u16 var02; + u8 var04; + u8 var05; + u8 var06; + s8 var07_0:5; + s8 var07_5:2; + s8 var07_7:1; +}; + +struct UnkStruct3 +{ + u8 var00_0:7; + u8 var00_7:1; + u8 var01; + s8 var02; + s8 var03; + struct UnkStruct1 var04; +}; + +struct UnkStruct0 +{ + u8 var00; + u8 var01; + u16 var02; //flag for each UnkStruct3 + struct UnkStruct3 var04[0x10]; +}; + +#endif // GUARD_ROULETTE_H diff --git a/include/roulette_util.h b/include/roulette_util.h index f59c4e44c..964f551fe 100644 --- a/include/roulette_util.h +++ b/include/roulette_util.h @@ -1,17 +1,46 @@ #ifndef GUARD_ROULETTE_UTIL_H #define GUARD_ROULETTE_UTIL_H +struct InnerStruct203CF18_3 +{ + u16 unk0; + u16 unk2; + u8 unk4; + u8 unk5; + u8 unk6; + s8 unk7_0:4; + s8 unk7_4:2; + s8 unk7_6:1; + s8 unk7_7:1; +}; + +struct InnerStruct203CF18_2 +{ + u8 unk0; + u8 unk1_0:4; + u8 unk1_4:1; + s8 unk1_5:1; + s8 unk1_6:1; + u32 unk1_7:1; + u8 unk2; + u8 unk3; + struct InnerStruct203CF18_3 unk4; +}; + // structures struct InnerStruct203CF18 { - u8 filler[0xC4]; + u16 unk0; + struct InnerStruct203CF18_2 unk4[16]; }; -void sub_8151B68(struct InnerStruct203CF18 *, const u8*); +int sub_8151B68(struct InnerStruct203CF18 *, const struct InnerStruct203CF18_3 *); void sub_8151B3C(struct InnerStruct203CF18 *); -void sub_8151CA8(struct InnerStruct203CF18 *, u8, u8); -void sub_8151C50(struct InnerStruct203CF18 *, u8, u8); -void sub_8151D28(struct InnerStruct203CF18 *, u8, u8); +void sub_8151CA8(struct InnerStruct203CF18 *, u16, u8); +void sub_8151C50(struct InnerStruct203CF18 *, u16, u8); +void sub_8151D28(struct InnerStruct203CF18 *, u16, u8); void sub_8151E50(struct InnerStruct203CF18 *); +void sub_8152008(u16 *dest, u16 src, u8 left, u8 top, u8 width, u8 height); +void sub_8152058(u16 *dest, u16 *src, u8 left, u8 top, u8 width, u8 height); #endif // GUARD_ROULETTE_UTIL_H diff --git a/ld_script.txt b/ld_script.txt index ddafe6ecf..1e0fc6a0d 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -214,7 +214,7 @@ SECTIONS { src/battle_message.o(.text); asm/cable_car.o(.text); src/math_util.o(.text); - asm/roulette_util.o(.text); + src/roulette_util.o(.text); src/rom_81520A8.o(.text); src/save.o(.text); src/mystery_event_script.o(.text); diff --git a/src/fldeff_groundshake.c b/src/fldeff_groundshake.c index e9a46bb86..73d72c8b6 100644 --- a/src/fldeff_groundshake.c +++ b/src/fldeff_groundshake.c @@ -32,7 +32,17 @@ static void sub_81BEA20(void); static void sub_81BEAD8(struct Sprite* sprite); // rodata -static const u8 gUnknown_08617E18[] = {0x3b, 0x43, 0x61, 0x00, 0x0f, 0x05, 0xff, 0x9b}; +const struct InnerStruct203CF18_3 gUnknown_08617E18 = { + .unk0 = 0x433b, + .unk2 = 0x61, + .unk4 = 0x0F, + .unk5 = 0x05, + .unk6 = 0xFF, + .unk7_0 = 0xB, + .unk7_4 = 0x1, + .unk7_6 = 0, + .unk7_7 = 1, +}; static const union AnimCmd gSpriteAnim_8617E20[] = { @@ -131,7 +141,7 @@ void sub_81BE6B8(void) gUnknown_0203CF18 = (struct Struct203CF18 *)AllocZeroed(sizeof(struct Struct203CF18)); sub_8151B3C(&(gUnknown_0203CF18->unk4)); - sub_8151B68(&(gUnknown_0203CF18->unk4), gUnknown_08617E18); + sub_8151B68(&(gUnknown_0203CF18->unk4), &gUnknown_08617E18); sub_8151CA8(&(gUnknown_0203CF18->unk4), 1, 1); gUnknown_0203CF18->taskId = CreateTask(sub_81BE698, 0xFF); } diff --git a/src/roulette_util.c b/src/roulette_util.c new file mode 100755 index 000000000..a197cfa09 --- /dev/null +++ b/src/roulette_util.c @@ -0,0 +1,700 @@ +#include "global.h" +#include "palette.h" +#include "roulette.h" +#include "roulette_util.h" +#include "util.h" + +void sub_8151678(struct UnkStruct0 *r0) +{ + r0->var00 = 0; + r0->var02 = 0; + memset(&r0->var04, 0, sizeof(r0->var04)); +} + +u8 sub_815168C(struct UnkStruct0 *r0, u8 r1, struct UnkStruct1 *r2) +{ + if (!(r1 < 16) || (r0->var04[r1].var00_7)) + return 0xFF; + + r0->var04[r1].var04.var00 = r2->var00; + r0->var04[r1].var04.var02 = r2->var02; + r0->var04[r1].var04.var04 = r2->var04; + r0->var04[r1].var04.var05 = r2->var05; + r0->var04[r1].var04.var06 = r2->var06; + r0->var04[r1].var04.var07_0 = r2->var07_0; + r0->var04[r1].var04.var07_5 = r2->var07_5; + r0->var04[r1].var04.var07_7 = r2->var07_7; + r0->var04[r1].var00_0 = 0; + r0->var04[r1].var00_7 = 1; + r0->var04[r1].var02 = 0; + r0->var04[r1].var01 = 0; + if (r0->var04[r1].var04.var07_7 < 0) + r0->var04[r1].var03 = 0xFF; + else + r0->var04[r1].var03 = 1; + + return r1; +} + +u8 sub_8151710(struct UnkStruct0 *r0, u8 r1) +{ + if (r1 >= 16) + return 0xFF; + if (!r0->var04[r1].var00_7) + return 0xFF; + + memset(&r0->var04[r1], 0, sizeof(r0->var04[r1])); + return r1; +} + +u8 sub_8151744(struct UnkStruct3 *r0) +{ + u8 i; + u8 returnval; + + for (i = 0; i < r0->var04.var04; i++) + { + struct PlttData *faded = (struct PlttData *)&gPlttBufferFaded[r0->var04.var02 + i]; + struct PlttData *unfaded = (struct PlttData *)&gPlttBufferUnfaded[r0->var04.var02 + i]; + + switch (r0->var00_0) + { + case 1: + if (faded->r + r0->var03 >= 0 && faded->r + r0->var03 < 32) + faded->r += r0->var03; + if (faded->g + r0->var03 >= 0 && faded->g + r0->var03 < 32) + faded->g += r0->var03; + if (faded->b + r0->var03 >= 0 && faded->b + r0->var03 < 32) + faded->b += r0->var03; + break; + case 2: + if (r0->var03 < 0) + { + if (faded->r + r0->var03 >= unfaded->r) + faded->r += r0->var03; + if (faded->g + r0->var03 >= unfaded->g) + faded->g += r0->var03; + if (faded->b + r0->var03 >= unfaded->b) + faded->b += r0->var03; + } + else + { + if (faded->r + r0->var03 <= unfaded->r) + faded->r += r0->var03; + if (faded->g + r0->var03 <= unfaded->g) + faded->g += r0->var03; + if (faded->b + r0->var03 <= unfaded->b) + faded->b += r0->var03; + } + break; + } + } + if ((u32)r0->var02++ != r0->var04.var07_0) + { + returnval = 0; + } + else + { + r0->var02 = 0; + r0->var03 *= -1; + if (r0->var00_0 == 1) + r0->var00_0++; + else + r0->var00_0--; + returnval = 1; + } + return returnval; +} + +u8 sub_815194C(struct UnkStruct3 *r0) +{ + u8 rg2 = 0; + + switch (r0->var00_0) + { + case 1: + for (rg2 = 0; rg2 < r0->var04.var04; rg2++) + gPlttBufferFaded[r0->var04.var02 + rg2] = r0->var04.var00; + r0->var00_0++; + break; + case 2: + for (rg2 = 0; rg2 < r0->var04.var04; rg2++) + gPlttBufferFaded[r0->var04.var02 + rg2] = gPlttBufferUnfaded[r0->var04.var02 + rg2]; + r0->var00_0--; + break; + } + return 1; +} + +void task_tutorial_controls_fadein(struct UnkStruct0 *r0) +{ + u8 i = 0; + + if (r0->var00) + { + for (i = 0; i < 16; i++) + { + if ((r0->var02 >> i) & 1) + { + if (--r0->var04[i].var01 == 0xFF) // if underflow ? + { + if (r0->var04[i].var04.var00 & 0x8000) // PlttData->unused_15 ? + sub_8151744(&r0->var04[i]); + else + sub_815194C(&r0->var04[i]); + + r0->var04[i].var01 = r0->var04[i].var04.var05; + } + } + } + } +} + +void sub_8151A48(struct UnkStruct0 *r0, u16 r1) +{ + u8 i = 0; + + r0->var00++; + for (i = 0; i < 16; i++) + { + if ((r1 >> i) & 1) + { + if (r0->var04[i].var00_7) + { + r0->var02 |= 1 << i; + r0->var04[i].var00_0 = 1; + } + } + } +} + +void sub_8151A9C(struct UnkStruct0 *r0, u16 r1) +{ + u8 i; + + for (i = 0; i < 16; i++) + { + if ((r0->var02 >> i) & 1) + { + if (r0->var04[i].var00_7) + { + if ((r1 >> i) & 1) + { + u32 offset = r0->var04[i].var04.var02; + u16 *faded = &gPlttBufferFaded[offset]; + u16 *unfaded = &gPlttBufferUnfaded[offset]; + memcpy(faded, unfaded, r0->var04[i].var04.var04 * 2); + r0->var04[i].var00_0 = 0; + r0->var04[i].var02 = 0; + r0->var04[i].var01 = 0; + if (r0->var04[i].var04.var07_7 < 0) + r0->var04[i].var03 = 0xFF; + else + r0->var04[i].var03 = 0x1; + } + } + } + } + if (r1 == 0xFFFF) + { + r0->var00 = 0; + r0->var02 = 0; + } + else + { + r0->var02 = r0->var02 & ~r1; + } +} + +void sub_8151B3C(struct InnerStruct203CF18 *arg0) +{ + u8 i = 0; + arg0->unk0 = 0; + memset(&arg0->unk4, 0, sizeof(arg0->unk4)); + for (; i < 16; i++) + { + arg0->unk4[i].unk0 = i; + } +} + +int sub_8151B68(struct InnerStruct203CF18 *arg0, const struct InnerStruct203CF18_3 *arg1) +{ + u8 i = 0; + struct InnerStruct203CF18_2 *r4 = NULL; + + if (!arg0->unk4[0].unk1_7) + { + r4 = &arg0->unk4[0]; + } + else + { + while (++i < 16) + { + if (!arg0->unk4[i].unk1_7) + { + r4 = &arg0->unk4[i]; + break; + } + } + } + + if (r4 == 0) + return 0xFF; + + r4->unk1_0 = 0; + r4->unk1_4 = 0; + r4->unk1_6 = 1; + r4->unk1_7 = 1; + r4->unk2 = 0; + r4->unk3 = 0; + memcpy(&r4->unk4, arg1, sizeof(*arg1)); + return i; +} + +void sub_8151BD4(struct InnerStruct203CF18_2 *arg0) +{ + u16 i; + + if (!arg0->unk1_6 && arg0->unk4.unk7_6) + { + for (i = arg0->unk4.unk2; i < arg0->unk4.unk2 + arg0->unk4.unk4; i++) + gPlttBufferFaded[i] = gPlttBufferUnfaded[i]; + } + + memset(&arg0->unk4, 0, sizeof(arg0->unk4)); + arg0->unk1_0 = 0; + arg0->unk1_4 = 0; + arg0->unk1_5 = 0; + arg0->unk1_6 = 1; + arg0->unk1_7 = 0; + arg0->unk3 = 0; + arg0->unk2 = 0; +} + +void sub_8151C50(struct InnerStruct203CF18 *arg0, u16 arg1, u8 arg2) +{ + u16 i = 0; + + if (!arg2) + { + sub_8151BD4(&arg0->unk4[arg1 & 0xF]); + } + else + { + for (i = 0; i < 16; i++) + { + if ((arg1 & 1) && arg0->unk4[i].unk1_7) + sub_8151BD4(&arg0->unk4[i]); + + arg1 >>= 1; + } + } +} + +// there seems to be a temp var involved inside the first if block +void sub_8151CA8(struct InnerStruct203CF18 *arg0, u16 arg1, u8 arg2) +{ + u8 i = 0; + + if (!arg2) + { + i = arg1 & 0xF; + arg0->unk4[i].unk1_6 = 0; + arg0->unk0 |= 1 << i; + } + else + { + for (i = 0; i < 16; i++) + { + if (!(arg1 & 1) || !arg0->unk4[i].unk1_7 || !arg0->unk4[i].unk1_6) + { + arg1 <<= 1; + } + else + { + arg0->unk4[i].unk1_6 = 0; + arg0->unk0 |= 1 << i; + } + } + } +} + +void sub_8151D28(struct InnerStruct203CF18 *arg0, u16 arg1, u8 arg2) +{ + u16 i; + struct InnerStruct203CF18_2 *var0; + u8 j = 0; + + if (!arg2) + { + var0 = &arg0->unk4[arg1 & 0xF]; + if (!var0->unk1_6 && var0->unk1_7) + { + if (var0->unk4.unk7_6) + { + for (i = var0->unk4.unk2; i < var0->unk4.unk2 + var0->unk4.unk4; i++) + gPlttBufferFaded[i] = gPlttBufferUnfaded[i]; + } + + var0->unk1_6 = 1; + arg0->unk0 &= ~(1 << j); + } + } + else + { + for (j = 0; j < 16; j++) + { + var0 = &arg0->unk4[j]; + if (!(arg1 & 1) || var0->unk1_6 || !var0->unk1_7) + { + arg1 <<= 1; + } + else + { + if (var0->unk4.unk7_6) + { + for (i = var0->unk4.unk2; i < var0->unk4.unk2 + var0->unk4.unk4; i++) + gPlttBufferFaded[i] = gPlttBufferUnfaded[i]; + } + + var0->unk1_6 = 1; + arg0->unk0 &= ~(1 << j); + } + } + } +} + +#ifdef NONMATCHING +void sub_8151E50(struct InnerStruct203CF18 *arg0) +{ + struct InnerStruct203CF18_2 *var0; + u8 i = 0; + + if (arg0->unk0) + { + for (i = 0; i < 16; i++) + { + var0 = &arg0->unk4[i]; + if ((!var0->unk1_6 && var0->unk1_7) && (!gPaletteFade.active || !var0->unk4.unk7_7)) + { + if (--var0->unk2 == 0xFF) + { + var0->unk2 = var0->unk4.unk5; + BlendPalette(var0->unk4.unk2, var0->unk4.unk4, var0->unk1_0, var0->unk4.unk0); + switch (var0->unk4.unk7_4) + { + case 0: + if (var0->unk1_0++ == var0->unk4.unk7_0) + { + var0->unk3++; + var0->unk1_0 = 0; + } + break; + case 1: + if (var0->unk1_4) + { + if (--var0->unk1_0 == 0) + { + var0->unk3++; + var0->unk1_4 ^= 1; + } + } + else + { + if (var0->unk1_0++ == var0->unk4.unk7_0 - 1) + { + var0->unk3++; + var0->unk1_4 ^= 1; + } + } + break; + case 2: + if (var0->unk1_4) + var0->unk1_0 = 0; + else + var0->unk1_0 = var0->unk4.unk7_0; + + var0->unk1_4 ^= 1; + var0->unk3++; + break; + } + + if (var0->unk4.unk6 != 0xFF && var0->unk3 == 0xFF) + sub_8151D28(arg0, var0->unk0, 0); + } + } + } + } +} +#else +NAKED +void sub_8151E50(struct InnerStruct203CF18 *arg0) +{ + asm_unified("\n\ + push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x4\n\ + str r0, [sp]\n\ + movs r0, 0\n\ + mov r10, r0\n\ + ldr r1, [sp]\n\ + ldrh r0, [r1]\n\ + cmp r0, 0\n\ + bne _08151E6C\n\ + b _08151FF6\n\ +_08151E6C:\n\ + movs r2, 0xF\n\ + mov r9, r2\n\ + movs r3, 0x10\n\ + negs r3, r3\n\ + mov r8, r3\n\ + movs r7, 0x1\n\ +_08151E78:\n\ + mov r5, r10\n\ + lsls r0, r5, 1\n\ + add r0, r10\n\ + lsls r0, 2\n\ + adds r0, 0x4\n\ + ldr r1, [sp]\n\ + adds r4, r1, r0\n\ + ldrb r2, [r4, 0x1]\n\ + movs r3, 0xC0\n\ + ands r3, r2\n\ + cmp r3, 0x80\n\ + beq _08151E92\n\ + b _08151FE6\n\ +_08151E92:\n\ + ldr r0, =gPaletteFade\n\ + ldrb r1, [r0, 0x7]\n\ + adds r0, r3, 0\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _08151EA8\n\ + ldrb r0, [r4, 0xB]\n\ + ands r3, r0\n\ + cmp r3, 0\n\ + beq _08151EA8\n\ + b _08151FE6\n\ +_08151EA8:\n\ + ldrb r0, [r4, 0x2]\n\ + subs r0, 0x1\n\ + strb r0, [r4, 0x2]\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + cmp r0, 0xFF\n\ + beq _08151EB8\n\ + b _08151FE6\n\ +_08151EB8:\n\ + ldrb r0, [r4, 0x9]\n\ + strb r0, [r4, 0x2]\n\ + ldrh r0, [r4, 0x6]\n\ + ldrb r1, [r4, 0x8]\n\ + lsls r2, 28\n\ + lsrs r2, 28\n\ + ldrh r3, [r4, 0x4]\n\ + bl BlendPalette\n\ + ldrb r5, [r4, 0xB]\n\ + lsls r0, r5, 26\n\ + asrs r0, 30\n\ + cmp r0, 0x1\n\ + beq _08151F16\n\ + cmp r0, 0x1\n\ + bgt _08151EE4\n\ + cmp r0, 0\n\ + beq _08151EEA\n\ + b _08151FD0\n\ + .pool\n\ +_08151EE4:\n\ + cmp r0, 0x2\n\ + beq _08151F92\n\ + b _08151FD0\n\ +_08151EEA:\n\ + ldrb r2, [r4, 0x1]\n\ + lsls r1, r2, 28\n\ + lsrs r0, r1, 28\n\ + adds r0, 0x1\n\ + mov r3, r9\n\ + ands r0, r3\n\ + mov r6, r8\n\ + adds r3, r6, 0\n\ + ands r3, r2\n\ + orrs r3, r0\n\ + strb r3, [r4, 0x1]\n\ + lsrs r1, 28\n\ + lsls r0, r5, 28\n\ + asrs r0, 28\n\ + cmp r1, r0\n\ + bne _08151FD0\n\ + ldrb r0, [r4, 0x3]\n\ + adds r0, 0x1\n\ + strb r0, [r4, 0x3]\n\ + ands r3, r6\n\ + strb r3, [r4, 0x1]\n\ + b _08151FD0\n\ +_08151F16:\n\ + ldrb r3, [r4, 0x1]\n\ + movs r0, 0x10\n\ + ands r0, r3\n\ + cmp r0, 0\n\ + beq _08151F54\n\ + lsls r0, r3, 28\n\ + lsrs r0, 28\n\ + subs r0, 0x1\n\ + mov r5, r9\n\ + ands r0, r5\n\ + mov r2, r8\n\ + ands r2, r3\n\ + orrs r2, r0\n\ + strb r2, [r4, 0x1]\n\ + cmp r0, 0\n\ + bne _08151FD0\n\ + ldrb r0, [r4, 0x3]\n\ + adds r0, 0x1\n\ + strb r0, [r4, 0x3]\n\ + lsls r0, r2, 27\n\ + lsrs r0, 31\n\ + eors r0, r7\n\ + ands r0, r7\n\ + lsls r0, 4\n\ + movs r3, 0x11\n\ + negs r3, r3\n\ + adds r1, r3, 0\n\ + ands r2, r1\n\ + orrs r2, r0\n\ + strb r2, [r4, 0x1]\n\ + b _08151FD0\n\ +_08151F54:\n\ + lsls r0, r5, 28\n\ + asrs r0, 28\n\ + subs r0, 0x1\n\ + mov r5, r9\n\ + ands r0, r5\n\ + lsls r2, r3, 28\n\ + lsrs r1, r2, 28\n\ + adds r1, 0x1\n\ + ands r1, r5\n\ + mov r5, r8\n\ + ands r3, r5\n\ + orrs r3, r1\n\ + strb r3, [r4, 0x1]\n\ + lsrs r2, 28\n\ + cmp r2, r0\n\ + bne _08151FD0\n\ + ldrb r0, [r4, 0x3]\n\ + adds r0, 0x1\n\ + strb r0, [r4, 0x3]\n\ + lsls r0, r3, 27\n\ + lsrs r0, 31\n\ + eors r0, r7\n\ + ands r0, r7\n\ + lsls r0, 4\n\ + movs r2, 0x11\n\ + negs r2, r2\n\ + adds r1, r2, 0\n\ + ands r3, r1\n\ + orrs r3, r0\n\ + strb r3, [r4, 0x1]\n\ + b _08151FD0\n\ +_08151F92:\n\ + ldrb r2, [r4, 0x1]\n\ + movs r0, 0x10\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _08151FA2\n\ + mov r0, r8\n\ + ands r0, r2\n\ + b _08151FB0\n\ +_08151FA2:\n\ + lsls r1, r5, 28\n\ + asrs r1, 28\n\ + mov r3, r9\n\ + ands r1, r3\n\ + mov r0, r8\n\ + ands r0, r2\n\ + orrs r0, r1\n\ +_08151FB0:\n\ + strb r0, [r4, 0x1]\n\ + ldrb r2, [r4, 0x1]\n\ + lsls r0, r2, 27\n\ + lsrs r0, 31\n\ + eors r0, r7\n\ + ands r0, r7\n\ + lsls r0, 4\n\ + movs r5, 0x11\n\ + negs r5, r5\n\ + adds r1, r5, 0\n\ + ands r2, r1\n\ + orrs r2, r0\n\ + strb r2, [r4, 0x1]\n\ + ldrb r0, [r4, 0x3]\n\ + adds r0, 0x1\n\ + strb r0, [r4, 0x3]\n\ +_08151FD0:\n\ + ldrb r1, [r4, 0xA]\n\ + cmp r1, 0xFF\n\ + beq _08151FE6\n\ + ldrb r0, [r4, 0x3]\n\ + cmp r0, r1\n\ + bne _08151FE6\n\ + ldrb r1, [r4]\n\ + ldr r0, [sp]\n\ + movs r2, 0\n\ + bl sub_8151D28\n\ +_08151FE6:\n\ + mov r0, r10\n\ + adds r0, 0x1\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + mov r10, r0\n\ + cmp r0, 0xF\n\ + bhi _08151FF6\n\ + b _08151E78\n\ +_08151FF6:\n\ + add sp, 0x4\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0"); +} +#endif // NONMATCHING + +void sub_8152008(u16 *dest, u16 src, u8 left, u8 top, u8 width, u8 height) +{ + u16 *_dest; + u8 i; + u8 j; + i = 0; + dest = &dest[top * 32 + left]; + for (; i < height; i++) + { + _dest = dest + i * 32; + for (j = 0; j < width; j++) + { + *_dest++ = src; + } + } +} + +void sub_8152058(u16 *dest, u16 *src, u8 left, u8 top, u8 width, u8 height) +{ + u16 *_dest; + u16 *_src = src; + u8 i; + u8 j; + i = 0; + dest = &dest[top * 32 + left]; + for (; i < height; i++) + { + _dest = dest + i * 32; + for (j = 0; j < width; j++) + { + *_dest++ = *_src++; + } + } +}