diff --git a/asm/field_player_avatar.s b/asm/field_player_avatar.s index cd4f83681..f5acc1e3e 100644 --- a/asm/field_player_avatar.s +++ b/asm/field_player_avatar.s @@ -1071,7 +1071,7 @@ sub_808B164: @ 808B164 adds r0, r6, 0 adds r1, r5, 0 adds r2, r4, 0 - bl sub_80FBFD4 + bl CheckForRotatingGatePuzzleCollisionWithoutAnimation cmp r0, 0 beq _0808B1A2 movs r0, 0x8 diff --git a/asm/rotating_gate.s b/asm/rotating_gate.s deleted file mode 100644 index 9b57dc1b0..000000000 --- a/asm/rotating_gate.s +++ /dev/null @@ -1,1152 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start GetCurrentMapRotatingGatePuzzleType -GetCurrentMapRotatingGatePuzzleType: @ 80FB7E8 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldrh r1, [r0, 0x4] - movs r0, 0x86 - lsls r0, 1 - cmp r1, r0 - bne _080FB800 - movs r0, 0x1 - b _080FB812 - .pool -_080FB800: - ldr r0, =0x0000081d - cmp r1, r0 - beq _080FB810 - movs r0, 0 - b _080FB812 - .pool -_080FB810: - movs r0, 0x2 -_080FB812: - pop {r1} - bx r1 - thumb_func_end GetCurrentMapRotatingGatePuzzleType - - thumb_func_start sub_80FB818 -sub_80FB818: @ 80FB818 - push {r4-r6,lr} - movs r0, 0x80 - lsls r0, 7 - bl GetVarPointer - adds r5, r0, 0 - movs r3, 0 - ldr r4, =gUnknown_0203A048 - ldrb r0, [r4] - cmp r3, r0 - bge _080FB844 - ldr r6, =gUnknown_0203A044 -_080FB830: - adds r2, r5, r3 - ldr r1, [r6] - lsls r0, r3, 3 - adds r0, r1 - ldrb r0, [r0, 0x5] - strb r0, [r2] - adds r3, 0x1 - ldrb r0, [r4] - cmp r3, r0 - blt _080FB830 -_080FB844: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80FB818 - - thumb_func_start sub_80FB854 -sub_80FB854: @ 80FB854 - push {r4,lr} - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - movs r0, 0x80 - lsls r0, 7 - bl GetVarPointer - adds r0, r4 - ldrb r0, [r0] - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_80FB854 - - thumb_func_start sub_80FB870 -sub_80FB870: @ 80FB870 - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - lsls r4, 24 - lsrs r4, 24 - lsls r5, 24 - lsrs r5, 24 - movs r0, 0x80 - lsls r0, 7 - bl GetVarPointer - adds r0, r4 - strb r5, [r0] - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_80FB870 - - thumb_func_start sub_80FB890 -sub_80FB890: @ 80FB890 - push {r4,r5,lr} - adds r4, r1, 0 - lsls r0, 24 - lsrs r5, r0, 24 - adds r0, r5, 0 - bl sub_80FB854 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r4, 0x1 - bne _080FB8B4 - cmp r1, 0 - beq _080FB8B0 - subs r0, r1, 0x1 - lsls r0, 24 - b _080FB8BE -_080FB8B0: - movs r1, 0x3 - b _080FB8C0 -_080FB8B4: - adds r1, 0x1 - lsls r1, 24 - movs r0, 0xC0 - lsls r0, 18 - ands r0, r1 -_080FB8BE: - lsrs r1, r0, 24 -_080FB8C0: - adds r0, r5, 0 - bl sub_80FB870 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_80FB890 - - thumb_func_start sub_80FB8CC -sub_80FB8CC: @ 80FB8CC - push {lr} - bl GetCurrentMapRotatingGatePuzzleType - cmp r0, 0x1 - beq _080FB8E0 - cmp r0, 0x1 - ble _080FB914 - cmp r0, 0x2 - beq _080FB8F8 - b _080FB914 -_080FB8E0: - ldr r1, =gUnknown_0203A044 - ldr r0, =gUnknown_0858E8B0 - str r0, [r1] - ldr r1, =gUnknown_0203A048 - movs r0, 0x8 - b _080FB902 - .pool -_080FB8F8: - ldr r1, =gUnknown_0203A044 - ldr r0, =gUnknown_0858E8F0 - str r0, [r1] - ldr r1, =gUnknown_0203A048 - movs r0, 0xB -_080FB902: - strb r0, [r1] - movs r1, 0 - ldr r3, =gUnknown_0203A038 - movs r2, 0x40 -_080FB90A: - adds r0, r1, r3 - strb r2, [r0] - adds r1, 0x1 - cmp r1, 0xA - bls _080FB90A -_080FB914: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80FB8CC - - thumb_func_start sub_80FB928 -sub_80FB928: @ 80FB928 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - lsls r0, 16 - lsrs r0, 16 - str r0, [sp] - lsls r1, 16 - lsrs r1, 16 - mov r10, r1 - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - ldrh r1, [r2] - subs r0, r1, 0x2 - lsls r0, 16 - lsrs r3, r0, 16 - adds r1, 0x11 - lsls r1, 16 - lsrs r1, 16 - mov r9, r1 - ldrh r1, [r2, 0x2] - subs r0, r1, 0x2 - lsls r0, 16 - lsrs r2, r0, 16 - adds r1, 0xE - lsls r1, 16 - lsrs r1, 16 - mov r8, r1 - movs r5, 0 - ldr r0, =gUnknown_0203A048 - ldrb r0, [r0] - cmp r5, r0 - bcs _080FB9DA - lsls r0, r2, 16 - asrs r7, r0, 16 - lsls r0, r3, 16 - asrs r6, r0, 16 -_080FB976: - ldr r0, =gUnknown_0203A044 - ldr r0, [r0] - lsls r1, r5, 3 - adds r1, r0 - ldrh r0, [r1] - adds r0, 0x7 - lsls r0, 16 - lsrs r2, r0, 16 - ldrh r0, [r1, 0x2] - adds r0, 0x7 - lsls r0, 16 - asrs r1, r0, 16 - cmp r7, r1 - bgt _080FB9CC - mov r3, r8 - lsls r0, r3, 16 - asrs r0, 16 - cmp r0, r1 - blt _080FB9CC - lsls r0, r2, 16 - asrs r1, r0, 16 - cmp r6, r1 - bgt _080FB9CC - mov r2, r9 - lsls r0, r2, 16 - asrs r0, 16 - cmp r0, r1 - blt _080FB9CC - ldr r0, =gUnknown_0203A038 - adds r4, r5, r0 - ldrb r0, [r4] - cmp r0, 0x40 - bne _080FB9CC - ldr r3, [sp] - lsls r1, r3, 16 - mov r0, r10 - lsls r2, r0, 16 - adds r0, r5, 0 - asrs r1, 16 - asrs r2, 16 - bl sub_80FB9FC - strb r0, [r4] -_080FB9CC: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - ldr r0, =gUnknown_0203A048 - ldrb r0, [r0] - cmp r5, r0 - bcc _080FB976 -_080FB9DA: - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80FB928 - - thumb_func_start sub_80FB9FC -sub_80FB9FC: @ 80FB9FC - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x18 - lsls r0, 24 - lsrs r6, r0, 24 - lsls r1, 16 - lsrs r7, r1, 16 - lsls r2, 16 - lsrs r2, 16 - mov r8, r2 - ldr r0, =gUnknown_0203A044 - lsls r1, r6, 3 - ldr r0, [r0] - adds r4, r0, r1 - ldrb r0, [r4, 0x4] - cmp r0, 0 - beq _080FBA24 - cmp r0, 0x4 - bne _080FBA34 -_080FBA24: - mov r1, sp - ldr r0, =gUnknown_08591FE0 - b _080FBA38 - .pool -_080FBA34: - mov r1, sp - ldr r0, =gUnknown_08591FC8 -_080FBA38: - ldm r0!, {r2,r3,r5} - stm r1!, {r2,r3,r5} - ldm r0!, {r2,r3,r5} - stm r1!, {r2,r3,r5} - mov r2, sp - ldrb r0, [r4, 0x4] - movs r3, 0x98 - lsls r3, 5 - adds r1, r3, 0 - adds r0, r1 - strh r0, [r2] - mov r0, sp - movs r1, 0 - movs r2, 0 - movs r3, 0x94 - bl CreateSprite - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x40 - beq _080FBAD4 - ldrh r0, [r4] - adds r0, 0x7 - ldrh r1, [r4, 0x2] - adds r1, 0x7 - lsls r4, r5, 4 - adds r4, r5 - lsls r4, 2 - ldr r2, =gSprites - adds r4, r2 - strh r6, [r4, 0x2E] - movs r2, 0x3E - adds r2, r4 - mov r12, r2 - ldrb r2, [r2] - movs r3, 0x2 - orrs r2, r3 - mov r3, r12 - strb r2, [r3] - lsls r0, 16 - asrs r0, 16 - lsls r2, r7, 16 - asrs r2, 16 - adds r0, r2 - lsls r0, 16 - asrs r0, 16 - lsls r1, 16 - asrs r1, 16 - mov r3, r8 - lsls r2, r3, 16 - asrs r2, 16 - adds r1, r2 - lsls r1, 16 - asrs r1, 16 - adds r2, r4, 0 - adds r2, 0x20 - adds r3, r4, 0 - adds r3, 0x22 - bl sub_8092FF0 - adds r0, r4, 0 - bl sub_80FBB64 - adds r0, r6, 0 - bl sub_80FB854 - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - bl StartSpriteAffineAnim - adds r0, r5, 0 - b _080FBAD6 - .pool -_080FBAD4: - movs r0, 0x40 -_080FBAD6: - add sp, 0x18 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_80FB9FC - - thumb_func_start sub_80FBAE4 -sub_80FBAE4: @ 80FBAE4 - push {r4-r7,lr} - adds r6, r0, 0 - ldrh r0, [r6, 0x30] - lsls r0, 24 - lsrs r5, r0, 24 - ldrh r0, [r6, 0x32] - lsls r0, 24 - lsrs r4, r0, 24 - adds r7, r4, 0 - adds r0, r6, 0 - bl sub_80FBB64 - cmp r5, 0x1 - bne _080FBB2A - adds r0, r4, 0x4 - lsls r0, 24 - lsrs r4, r0, 24 - bl GetPlayerSpeed - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x1 - beq _080FBB1A - adds r0, r4, 0 - adds r0, 0x8 - lsls r0, 24 - lsrs r4, r0, 24 -_080FBB1A: - movs r0, 0x30 - bl PlaySE - adds r0, r6, 0 - adds r1, r4, 0 - bl StartSpriteAffineAnim - b _080FBB58 -_080FBB2A: - cmp r5, 0x2 - bne _080FBB58 - adds r0, r7, 0 - adds r0, 0x8 - lsls r0, 24 - lsrs r4, r0, 24 - bl GetPlayerSpeed - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x1 - beq _080FBB4A - adds r0, r4, 0 - adds r0, 0x8 - lsls r0, 24 - lsrs r4, r0, 24 -_080FBB4A: - movs r0, 0x30 - bl PlaySE - adds r0, r6, 0 - adds r1, r4, 0 - bl StartSpriteAffineAnim -_080FBB58: - movs r0, 0 - strh r0, [r6, 0x30] - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80FBAE4 - - thumb_func_start sub_80FBB64 -sub_80FBB64: @ 80FBB64 - push {r4-r6,lr} - mov r12, r0 - mov r4, r12 - adds r4, 0x3E - ldrb r0, [r4] - movs r5, 0x5 - negs r5, r5 - ands r5, r0 - strb r5, [r4] - mov r0, r12 - ldrh r1, [r0, 0x24] - ldrh r2, [r0, 0x20] - adds r1, r2 - adds r0, 0x28 - movs r2, 0 - ldrsb r2, [r0, r2] - ldr r0, =gSpriteCoordOffsetX - adds r2, r1 - ldrh r0, [r0] - adds r2, r0 - lsls r2, 16 - mov r3, r12 - ldrh r1, [r3, 0x26] - ldrh r0, [r3, 0x22] - adds r1, r0 - mov r0, r12 - adds r0, 0x29 - ldrb r0, [r0] - lsls r0, 24 - asrs r0, 24 - ldr r3, =gSpriteCoordOffsetY - adds r0, r1 - ldrh r3, [r3] - adds r0, r3 - lsls r0, 16 - movs r3, 0x80 - lsls r3, 15 - adds r1, r2, r3 - lsrs r1, 16 - lsrs r6, r0, 16 - adds r0, r3 - lsrs r3, r0, 16 - asrs r2, 16 - cmp r2, 0xFF - bgt _080FBBCA - lsls r0, r1, 16 - asrs r0, 16 - movs r1, 0x10 - negs r1, r1 - cmp r0, r1 - bge _080FBBD2 -_080FBBCA: - movs r1, 0x4 - adds r0, r5, 0 - orrs r0, r1 - strb r0, [r4] -_080FBBD2: - lsls r0, r6, 16 - asrs r0, 16 - cmp r0, 0xAF - bgt _080FBBE6 - lsls r0, r3, 16 - asrs r0, 16 - movs r1, 0x10 - negs r1, r1 - cmp r0, r1 - bge _080FBBF2 -_080FBBE6: - mov r0, r12 - adds r0, 0x3E - ldrb r1, [r0] - movs r2, 0x4 - orrs r1, r2 - strb r1, [r0] -_080FBBF2: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80FBB64 - - thumb_func_start LoadRotatingGatePics -@ void LoadRotatingGatePics() -LoadRotatingGatePics: @ 80FBC00 - push {lr} - ldr r0, =gUnknown_08591D58 - bl LoadSpriteSheets - pop {r0} - bx r0 - .pool - thumb_func_end LoadRotatingGatePics - - thumb_func_start sub_80FBC10 -sub_80FBC10: @ 80FBC10 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - ldrh r1, [r2] - subs r0, r1, 0x2 - lsls r0, 16 - lsrs r0, 16 - mov r10, r0 - adds r1, 0x11 - lsls r1, 16 - lsrs r1, 16 - mov r9, r1 - ldrh r1, [r2, 0x2] - subs r0, r1, 0x2 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - adds r1, 0xE - lsls r1, 16 - lsrs r7, r1, 16 - movs r6, 0 - b _080FBCB6 - .pool -_080FBC48: - ldr r0, =gUnknown_0203A044 - ldr r0, [r0] - lsls r1, r6, 3 - adds r1, r0 - ldrh r0, [r1] - adds r0, 0x7 - lsls r0, 16 - lsrs r2, r0, 16 - ldrh r0, [r1, 0x2] - adds r0, 0x7 - lsls r0, 16 - lsrs r3, r0, 16 - ldr r0, =gUnknown_0203A038 - adds r0, r6, r0 - ldrb r0, [r0] - cmp r0, 0x40 - beq _080FBCB4 - lsls r0, r2, 16 - mov r2, r10 - lsls r1, r2, 16 - asrs r2, r0, 16 - cmp r0, r1 - blt _080FBC94 - mov r1, r9 - lsls r0, r1, 16 - asrs r0, 16 - cmp r2, r0 - bgt _080FBC94 - lsls r0, r3, 16 - mov r2, r8 - lsls r1, r2, 16 - asrs r2, r0, 16 - cmp r0, r1 - blt _080FBC94 - lsls r0, r7, 16 - asrs r0, 16 - cmp r2, r0 - ble _080FBCB4 -_080FBC94: - ldr r0, =gUnknown_0203A038 - adds r5, r6, r0 - ldrb r0, [r5] - lsls r4, r0, 4 - adds r4, r0 - lsls r4, 2 - ldr r0, =gSprites - adds r4, r0 - adds r0, r4, 0 - bl FreeSpriteOamMatrix - adds r0, r4, 0 - bl DestroySprite - movs r0, 0x40 - strb r0, [r5] -_080FBCB4: - adds r6, 0x1 -_080FBCB6: - ldr r0, =gUnknown_0203A048 - ldrb r0, [r0] - cmp r6, r0 - blt _080FBC48 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80FBC10 - - thumb_func_start sub_80FBCDC -sub_80FBCDC: @ 80FBCDC - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - lsls r0, 24 - lsrs r4, r0, 24 - cmp r1, 0x1 - bne _080FBCFC - ldr r0, =gUnknown_08592058 - mov r10, r0 - b _080FBD08 - .pool -_080FBCFC: - cmp r1, 0x2 - beq _080FBD04 -_080FBD00: - movs r0, 0 - b _080FBD98 -_080FBD04: - ldr r1, =gUnknown_08592038 - mov r10, r1 -_080FBD08: - adds r0, r4, 0 - bl sub_80FB854 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - ldr r0, =gUnknown_0203A044 - ldr r1, [r0] - lsls r0, r4, 3 - adds r0, r1 - ldrb r2, [r0, 0x4] - ldrh r1, [r0] - adds r1, 0x7 - ldrh r0, [r0, 0x2] - adds r0, 0x7 - movs r3, 0 - lsls r2, 3 - str r2, [sp, 0x4] - lsls r1, 16 - asrs r1, 16 - mov r9, r1 - lsls r0, 16 - asrs r0, 16 - mov r8, r0 -_080FBD38: - movs r6, 0 - ldr r2, [sp] - adds r7, r2, r3 - lsls r0, r3, 1 - adds r5, r7, 0 - ldr r1, [sp, 0x4] - adds r0, r1 - ldr r2, =gUnknown_08592078 - adds r4, r0, r2 -_080FBD4A: - adds r0, r5, 0 - cmp r5, 0 - bge _080FBD52 - adds r0, r7, 0x3 -_080FBD52: - asrs r0, 2 - lsls r0, 2 - subs r0, r5, r0 - lsls r0, 1 - adds r0, r6 - lsls r0, 24 - lsrs r1, r0, 24 - ldrb r0, [r4] - cmp r0, 0 - beq _080FBD88 - lsls r1, 2 - add r1, r10 - movs r0, 0 - ldrsb r0, [r1, r0] - add r0, r9 - ldrb r1, [r1, 0x1] - lsls r1, 24 - asrs r1, 24 - add r1, r8 - str r3, [sp, 0x8] - bl MapGridIsImpassableAt - lsls r0, 24 - lsrs r0, 24 - ldr r3, [sp, 0x8] - cmp r0, 0x1 - beq _080FBD00 -_080FBD88: - adds r4, 0x1 - adds r6, 0x1 - cmp r6, 0x1 - ble _080FBD4A - adds r3, 0x1 - cmp r3, 0x3 - ble _080FBD38 - movs r0, 0x1 -_080FBD98: - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_80FBCDC - - thumb_func_start sub_80FBDB4 -sub_80FBDB4: @ 80FBDB4 - push {r4-r6,lr} - adds r4, r1, 0 - lsls r0, 24 - lsrs r0, 24 - adds r6, r0, 0 - lsls r4, 24 - lsrs r5, r4, 24 - lsrs r4, 25 - movs r0, 0x1 - ands r5, r0 - adds r0, r6, 0 - bl sub_80FB854 - subs r4, r0 - adds r1, r4, 0x4 - adds r0, r1, 0 - cmp r1, 0 - bge _080FBDDA - adds r0, r4, 0x7 -_080FBDDA: - asrs r0, 2 - lsls r0, 2 - subs r0, r1, r0 - ldr r1, =gUnknown_0203A044 - ldr r2, [r1] - lsls r1, r6, 3 - adds r1, r2 - ldrb r1, [r1, 0x4] - ldr r2, =gUnknown_08592078 - lsls r0, 24 - asrs r0, 23 - adds r0, r5 - lsls r1, 3 - adds r0, r1 - adds r0, r2 - ldrb r0, [r0] - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end sub_80FBDB4 - - thumb_func_start sub_80FBE08 -sub_80FBE08: @ 80FBE08 - push {r4,lr} - lsls r0, 24 - lsrs r3, r0, 24 - ldr r0, =gUnknown_0203A038 - adds r2, r3, r0 - ldrb r0, [r2] - cmp r0, 0x40 - beq _080FBE2C - lsls r4, r0, 4 - adds r4, r0 - lsls r4, 2 - ldr r0, =gSprites - adds r4, r0 - strh r1, [r4, 0x30] - adds r0, r3, 0 - bl sub_80FB854 - strh r0, [r4, 0x32] -_080FBE2C: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80FBE08 - - thumb_func_start sub_80FBE3C -sub_80FBE3C: @ 80FBE3C - push {lr} - lsls r0, 24 - lsrs r0, 24 - adds r3, r0, 0 - lsls r1, 16 - lsrs r1, 16 - lsls r2, 16 - lsrs r2, 16 - cmp r0, 0x2 - bne _080FBE58 - ldr r3, =gUnknown_08591FF8 - b _080FBE7A - .pool -_080FBE58: - cmp r0, 0x1 - bne _080FBE64 - ldr r3, =gUnknown_08592008 - b _080FBE7A - .pool -_080FBE64: - cmp r0, 0x3 - bne _080FBE70 - ldr r3, =gUnknown_08592018 - b _080FBE7A - .pool -_080FBE70: - cmp r3, 0x4 - beq _080FBE78 - movs r0, 0xFF - b _080FBE88 -_080FBE78: - ldr r3, =gUnknown_08592028 -_080FBE7A: - lsls r0, r2, 16 - lsls r1, 16 - asrs r1, 16 - asrs r0, 14 - adds r0, r1 - adds r0, r3, r0 - ldrb r0, [r0] -_080FBE88: - pop {r1} - bx r1 - .pool - thumb_func_end sub_80FBE3C - - thumb_func_start sub_80FBE90 -sub_80FBE90: @ 80FBE90 - push {lr} - bl GetCurrentMapRotatingGatePuzzleType - cmp r0, 0 - beq _080FBEA2 - bl sub_80FB8CC - bl sub_80FB818 -_080FBEA2: - pop {r0} - bx r0 - thumb_func_end sub_80FBE90 - - thumb_func_start RotatingGatePuzzleCameraUpdate -@ void RotatingGatePuzzleCameraUpdate(s32 deltaX, s32 deltaY) -RotatingGatePuzzleCameraUpdate: @ 80FBEA8 - push {r4,r5,lr} - lsls r0, 16 - lsrs r4, r0, 16 - lsls r1, 16 - lsrs r5, r1, 16 - bl GetCurrentMapRotatingGatePuzzleType - cmp r0, 0 - beq _080FBECA - lsls r0, r4, 16 - asrs r0, 16 - lsls r1, r5, 16 - asrs r1, 16 - bl sub_80FB928 - bl sub_80FBC10 -_080FBECA: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end RotatingGatePuzzleCameraUpdate - - thumb_func_start RotatingGate_InitPuzzleAndGraphics -RotatingGate_InitPuzzleAndGraphics: @ 80FBED0 - push {lr} - bl GetCurrentMapRotatingGatePuzzleType - cmp r0, 0 - beq _080FBEEA - bl LoadRotatingGatePics - bl sub_80FB8CC - movs r0, 0 - movs r1, 0 - bl sub_80FB928 -_080FBEEA: - pop {r0} - bx r0 - thumb_func_end RotatingGate_InitPuzzleAndGraphics - - thumb_func_start CheckForRotatingGatePuzzleCollision -CheckForRotatingGatePuzzleCollision: @ 80FBEF0 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - lsls r1, 16 - lsrs r4, r1, 16 - lsls r2, 16 - lsrs r2, 16 - mov r8, r2 - bl GetCurrentMapRotatingGatePuzzleType - cmp r0, 0 - bne _080FBF24 - b _080FBFC2 -_080FBF12: - adds r0, r4, 0 - adds r1, r5, 0 - bl sub_80FBE08 - adds r0, r4, 0 - adds r1, r5, 0 - bl sub_80FB890 - b _080FBFC2 -_080FBF24: - movs r6, 0 - ldr r0, =gUnknown_0203A048 - ldrb r0, [r0] - cmp r6, r0 - bge _080FBFC2 - lsls r0, r4, 16 - asrs r7, r0, 16 -_080FBF32: - ldr r0, =gUnknown_0203A044 - ldr r1, [r0] - lsls r0, r6, 3 - adds r0, r1 - ldrh r1, [r0] - adds r1, 0x7 - ldrh r0, [r0, 0x2] - adds r0, 0x7 - lsls r0, 16 - lsrs r2, r0, 16 - lsls r1, 16 - asrs r4, r1, 16 - subs r0, r4, 0x2 - cmp r0, r7 - bgt _080FBFB8 - adds r0, r4, 0x1 - cmp r7, r0 - bgt _080FBFB8 - lsls r0, r2, 16 - asrs r3, r0, 16 - subs r1, r3, 0x2 - mov r2, r8 - lsls r0, r2, 16 - asrs r2, r0, 16 - cmp r1, r2 - bgt _080FBFB8 - adds r0, r3, 0x1 - cmp r2, r0 - bgt _080FBFB8 - subs r1, r7, r4 - adds r1, 0x2 - subs r2, r3 - adds r2, 0x2 - lsls r1, 16 - asrs r1, 16 - lsls r2, 16 - asrs r2, 16 - mov r0, r9 - bl sub_80FBE3C - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - beq _080FBFB8 - lsrs r5, r0, 4 - movs r1, 0xF - ands r1, r0 - lsls r0, r6, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl sub_80FBDB4 - cmp r0, 0 - beq _080FBFB8 - adds r0, r4, 0 - adds r1, r5, 0 - bl sub_80FBCDC - cmp r0, 0 - bne _080FBF12 - movs r0, 0x1 - b _080FBFC4 - .pool -_080FBFB8: - adds r6, 0x1 - ldr r0, =gUnknown_0203A048 - ldrb r0, [r0] - cmp r6, r0 - blt _080FBF32 -_080FBFC2: - movs r0, 0 -_080FBFC4: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end CheckForRotatingGatePuzzleCollision - - thumb_func_start sub_80FBFD4 -sub_80FBFD4: @ 80FBFD4 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - lsls r1, 16 - lsrs r4, r1, 16 - lsls r2, 16 - lsrs r2, 16 - mov r8, r2 - bl GetCurrentMapRotatingGatePuzzleType - cmp r0, 0 - bne _080FBFFA - b _080FC08A -_080FBFF6: - movs r0, 0x1 - b _080FC08C -_080FBFFA: - movs r6, 0 - ldr r0, =gUnknown_0203A048 - ldrb r0, [r0] - cmp r6, r0 - bge _080FC08A - lsls r0, r4, 16 - asrs r7, r0, 16 -_080FC008: - ldr r0, =gUnknown_0203A044 - ldr r1, [r0] - lsls r0, r6, 3 - adds r0, r1 - ldrh r1, [r0] - adds r1, 0x7 - ldrh r0, [r0, 0x2] - adds r0, 0x7 - lsls r0, 16 - lsrs r2, r0, 16 - lsls r1, 16 - asrs r4, r1, 16 - subs r0, r4, 0x2 - cmp r0, r7 - bgt _080FC080 - adds r0, r4, 0x1 - cmp r7, r0 - bgt _080FC080 - lsls r0, r2, 16 - asrs r3, r0, 16 - subs r1, r3, 0x2 - mov r2, r8 - lsls r0, r2, 16 - asrs r2, r0, 16 - cmp r1, r2 - bgt _080FC080 - adds r0, r3, 0x1 - cmp r2, r0 - bgt _080FC080 - subs r1, r7, r4 - adds r1, 0x2 - subs r2, r3 - adds r2, 0x2 - lsls r1, 16 - asrs r1, 16 - lsls r2, 16 - asrs r2, 16 - mov r0, r9 - bl sub_80FBE3C - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - beq _080FC080 - lsrs r5, r0, 4 - movs r1, 0xF - ands r1, r0 - lsls r0, r6, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl sub_80FBDB4 - cmp r0, 0 - beq _080FC080 - adds r0, r4, 0 - adds r1, r5, 0 - bl sub_80FBCDC - cmp r0, 0 - beq _080FBFF6 -_080FC080: - adds r6, 0x1 - ldr r0, =gUnknown_0203A048 - ldrb r0, [r0] - cmp r6, r0 - blt _080FC008 -_080FC08A: - movs r0, 0 -_080FC08C: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_80FBFD4 - - .align 2, 0 @ Don't pad with nop. diff --git a/data/rotating_gate.s b/data/rotating_gate.s deleted file mode 100644 index 595cc9917..000000000 --- a/data/rotating_gate.s +++ /dev/null @@ -1,285 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - - .align 2 -gUnknown_0858E8B0:: @ 858E8B0 - .2byte 0x0006, 0x0007 - .byte 0x05, 0x01 - - .align 2 - .2byte 0x0009, 0x000f - .byte 0x05, 0x02 - - .align 2 - .2byte 0x0003, 0x0013 - .byte 0x05, 0x01 - - .align 2 - .2byte 0x0002, 0x0006 - .byte 0x04, 0x01 - - .align 2 - .2byte 0x0009, 0x000c - .byte 0x04, 0x00 - - .align 2 - .2byte 0x0006, 0x0017 - .byte 0x04, 0x00 - - .align 2 - .2byte 0x000c, 0x0016 - .byte 0x04, 0x00 - - .align 2 - .2byte 0x0006, 0x0003 - .byte 0x03, 0x02 - - .align 2 -gUnknown_0858E8F0:: @ 858E8F0 - .2byte 0x000e, 0x0005 - .byte 0x04, 0x01 - - .align 2 - .2byte 0x000a, 0x0006 - .byte 0x01, 0x02 - - .align 2 - .2byte 0x0006, 0x0006 - .byte 0x03, 0x01 - - .align 2 - .2byte 0x000e, 0x0008 - .byte 0x04, 0x01 - - .align 2 - .2byte 0x0003, 0x000a - .byte 0x02, 0x03 - - .align 2 - .2byte 0x0009, 0x000e - .byte 0x00, 0x01 - - .align 2 - .2byte 0x0003, 0x000f - .byte 0x06, 0x00 - - .align 2 - .2byte 0x0002, 0x0011 - .byte 0x01, 0x02 - - .align 2 - .2byte 0x000c, 0x0012 - .byte 0x06, 0x03 - - .align 2 - .2byte 0x0005, 0x0012 - .byte 0x03, 0x01 - - .align 2 - .2byte 0x000a, 0x0013 - .byte 0x02, 0x02 - - .align 2 -gUnknown_0858E948:: @ 858E948 - .incbin "graphics/misc/rotating_gate_1.4bpp" - - .align 2 -gUnknown_0858EB48:: @ 858EB48 - .incbin "graphics/misc/rotating_gate_2.4bpp" - - .align 2 -gUnknown_0858F348:: @ 858F348 - .incbin "graphics/misc/rotating_gate_3.4bpp" - - .align 2 -gUnknown_0858FB48:: @ 858FB48 - .incbin "graphics/misc/rotating_gate_4.4bpp" - - .align 2 -gUnknown_08590348:: @ 8590348 - .incbin "graphics/misc/rotating_gate_5.4bpp" - - .align 2 -gUnknown_08590548:: @ 8590548 - .incbin "graphics/misc/rotating_gate_6.4bpp" - - .align 2 -gUnknown_08590D48:: @ 8590D48 - .incbin "graphics/misc/rotating_gate_7.4bpp" - - .align 2 -gUnknown_08591548:: @ 8591548 - .incbin "graphics/misc/rotating_gate_8.4bpp" - - .align 2 -gOamData_8591D48:: @ 8591D48 - .2byte 0x0100, 0xc000, 0x2800 - - .align 2 -gOamData_8591D50:: @ 8591D50 - .2byte 0x0100, 0x8000, 0x2800 - - .align 2 -gUnknown_08591D58:: @ 8591D58 - obj_tiles gUnknown_0858E948, 0x0200, 0x1300 - obj_tiles gUnknown_0858EB48, 0x0800, 0x1301 - obj_tiles gUnknown_0858F348, 0x0800, 0x1302 - obj_tiles gUnknown_0858FB48, 0x0800, 0x1303 - obj_tiles gUnknown_08590348, 0x0200, 0x1304 - obj_tiles gUnknown_08590548, 0x0800, 0x1305 - obj_tiles gUnknown_08590D48, 0x0800, 0x1306 - obj_tiles gUnknown_08591548, 0x0800, 0x1307 - null_obj_tiles - - .align 2 -gSpriteAnim_8591DA0:: @ 8591DA0 - .2byte 0x0000, 0x0000, 0xffff, 0x0000 - - .align 2 -gSpriteAnim_8591DA8:: @ 8591DA8 - .2byte 0x0000, 0x0000, 0xffff, 0x0000 - - .align 2 -gSpriteAnimTable_8591DB0:: @ 8591DB0 - .4byte gSpriteAnim_8591DA0 - - .align 2 -gSpriteAnimTable_8591DB4:: @ 8591DB4 - .4byte gSpriteAnim_8591DA8 - - .align 2 -gSpriteAffineAnim_8591DB8:: @ 8591DB8 - .2byte 0x0100, 0x0100, 0x0000, 0x0000, 0x7ffe, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591DC8:: @ 8591DC8 - .2byte 0x0100, 0x0100, 0x00c0, 0x0000, 0x7ffe, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591DD8:: @ 8591DD8 - .2byte 0x0100, 0x0100, 0x0080, 0x0000, 0x7ffe, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591DE8:: @ 8591DE8 - .2byte 0x0100, 0x0100, 0x0040, 0x0000, 0x7ffe, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591DF8:: @ 8591DF8 - .2byte 0x0100, 0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x10fc, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591E10:: @ 8591E10 - .2byte 0x0100, 0x0100, 0x00c0, 0x0000, 0x0000, 0x0000, 0x10fc, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591E28:: @ 8591E28 - .2byte 0x0100, 0x0100, 0x0080, 0x0000, 0x0000, 0x0000, 0x10fc, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591E40:: @ 8591E40 - .2byte 0x0100, 0x0100, 0x0040, 0x0000, 0x0000, 0x0000, 0x10fc, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591E58:: @ 8591E58 - .2byte 0x0100, 0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x1004, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591E70:: @ 8591E70 - .2byte 0x0100, 0x0100, 0x0040, 0x0000, 0x0000, 0x0000, 0x1004, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591E88:: @ 8591E88 - .2byte 0x0100, 0x0100, 0x0080, 0x0000, 0x0000, 0x0000, 0x1004, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591EA0:: @ 8591EA0 - .2byte 0x0100, 0x0100, 0x00c0, 0x0000, 0x0000, 0x0000, 0x1004, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591EB8:: @ 8591EB8 - .2byte 0x0100, 0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x08f8, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591ED0:: @ 8591ED0 - .2byte 0x0100, 0x0100, 0x00c0, 0x0000, 0x0000, 0x0000, 0x08f8, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591EE8:: @ 8591EE8 - .2byte 0x0100, 0x0100, 0x0080, 0x0000, 0x0000, 0x0000, 0x08f8, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591F00:: @ 8591F00 - .2byte 0x0100, 0x0100, 0x0040, 0x0000, 0x0000, 0x0000, 0x08f8, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591F18:: @ 8591F18 - .2byte 0x0100, 0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0808, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591F30:: @ 8591F30 - .2byte 0x0100, 0x0100, 0x0040, 0x0000, 0x0000, 0x0000, 0x0808, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591F48:: @ 8591F48 - .2byte 0x0100, 0x0100, 0x0080, 0x0000, 0x0000, 0x0000, 0x0808, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnim_8591F60:: @ 8591F60 - .2byte 0x0100, 0x0100, 0x00c0, 0x0000, 0x0000, 0x0000, 0x0808, 0x0000, 0x7fff, 0x0000, 0x0000, 0x0000 - - .align 2 -gSpriteAffineAnimTable_8591F78:: @ 8591F78 - .4byte gSpriteAffineAnim_8591DB8 - .4byte gSpriteAffineAnim_8591DC8 - .4byte gSpriteAffineAnim_8591DD8 - .4byte gSpriteAffineAnim_8591DE8 - .4byte gSpriteAffineAnim_8591E58 - .4byte gSpriteAffineAnim_8591EA0 - .4byte gSpriteAffineAnim_8591E88 - .4byte gSpriteAffineAnim_8591E70 - .4byte gSpriteAffineAnim_8591DF8 - .4byte gSpriteAffineAnim_8591E10 - .4byte gSpriteAffineAnim_8591E28 - .4byte gSpriteAffineAnim_8591E40 - .4byte gSpriteAffineAnim_8591F18 - .4byte gSpriteAffineAnim_8591F60 - .4byte gSpriteAffineAnim_8591F48 - .4byte gSpriteAffineAnim_8591F30 - .4byte gSpriteAffineAnim_8591EB8 - .4byte gSpriteAffineAnim_8591ED0 - .4byte gSpriteAffineAnim_8591EE8 - .4byte gSpriteAffineAnim_8591F00 - - .align 2 -gUnknown_08591FC8:: @ 8591FC8 - spr_template 0x1300, 0xffff, gOamData_8591D48, gSpriteAnimTable_8591DB0, NULL, gSpriteAffineAnimTable_8591F78, sub_80FBAE4 - - .align 2 -gUnknown_08591FE0:: @ 8591FE0 - spr_template 0x1300, 0xffff, gOamData_8591D50, gSpriteAnimTable_8591DB4, NULL, gSpriteAffineAnimTable_8591F78, sub_80FBAE4 - -gUnknown_08591FF8:: @ 8591FF8 - .byte 0xff, 0xff, 0xff, 0xff, 0x27, 0x26, 0x12, 0x13, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff - -gUnknown_08592008:: @ 8592008 - .byte 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x17, 0x16, 0x22, 0x23, 0xff, 0xff, 0xff, 0xff - -gUnknown_08592018:: @ 8592018 - .byte 0xff, 0x11, 0xff, 0xff, 0xff, 0x10, 0xff, 0xff, 0xff, 0x24, 0xff, 0xff, 0xff, 0x25, 0xff, 0xff - -gUnknown_08592028:: @ 8592028 - .byte 0xff, 0xff, 0x21, 0xff, 0xff, 0xff, 0x20, 0xff, 0xff, 0xff, 0x14, 0xff, 0xff, 0xff, 0x15, 0xff - -gUnknown_08592038:: @ 8592038 - .byte 0x00, 0xff, 0x00, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0x00, 0x00 - -gUnknown_08592058:: @ 8592058 - .byte 0xff, 0xff, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00 - -gUnknown_08592078:: @ 8592078 - .byte 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00 - .byte 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00 - diff --git a/data/scripts/maps/FortreeCity_Gym.inc b/data/scripts/maps/FortreeCity_Gym.inc index 01ce60717..b8b800286 100644 --- a/data/scripts/maps/FortreeCity_Gym.inc +++ b/data/scripts/maps/FortreeCity_Gym.inc @@ -4,7 +4,7 @@ FortreeCity_Gym_MapScripts:: @ 82165AB .byte 0 FortreeCity_Gym_MapScript1_2165B6: @ 82165B6 - special sub_80FBE90 + special RotatingGate_InitPuzzle end FortreeCity_Gym_MapScript2_2165BA: @ 82165BA diff --git a/data/scripts/maps/Route110_TrickHousePuzzle6.inc b/data/scripts/maps/Route110_TrickHousePuzzle6.inc index 6b13cf8cb..0a0e025af 100644 --- a/data/scripts/maps/Route110_TrickHousePuzzle6.inc +++ b/data/scripts/maps/Route110_TrickHousePuzzle6.inc @@ -4,7 +4,7 @@ Route110_TrickHousePuzzle6_MapScripts:: @ 826DDA7 .byte 0 Route110_TrickHousePuzzle6_MapScript1_26DDB2: @ 826DDB2 - special sub_80FBE90 + special RotatingGate_InitPuzzle end Route110_TrickHousePuzzle6_MapScript2_26DDB6: @ 826DDB6 diff --git a/data/specials.inc b/data/specials.inc index 394e4a10e..2290c9d21 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -212,7 +212,7 @@ gSpecials:: @ 81DBA64 def_special SubtractMoneyFromVar0x8005 def_special sub_80F972C def_special sp0C8_whiteout_maybe - def_special sub_80FBE90 + def_special RotatingGate_InitPuzzle def_special RotatingGate_InitPuzzleAndGraphics def_special SetSSTidalFlag def_special ResetSSTidalFlag diff --git a/ld_script.txt b/ld_script.txt index 056e83828..66ba4e6c8 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -154,7 +154,7 @@ SECTIONS { src/pokemon_size_record.o(.text); asm/fldeff_80F9BCC.o(.text); src/field_special_scene.o(.text); - asm/rotating_gate.o(.text); + src/rotating_gate.o(.text); src/safari_zone.o(.text); asm/contest_link_80FC4F4.o(.text); src/item_use.o(.text); @@ -450,7 +450,7 @@ SECTIONS { src/pokemon_size_record.o(.rodata) data/field_effect_misc.o(.rodata); data/field_special_scene.o(.rodata); - data/rotating_gate.o(.rodata); + src/rotating_gate.o(.rodata); data/item_use.o(.rodata); data/battle_anim_80FE840.o(.rodata); src/bike.o(.rodata); diff --git a/src/mon_markings.c b/src/mon_markings.c index 37be1b764..147872ab6 100644 --- a/src/mon_markings.c +++ b/src/mon_markings.c @@ -9,12 +9,7 @@ #include "sprite.h" #include "text_window.h" - -#ifdef GERMAN -#define MENU_TEXT_SPRITE_X_OFFSET 24 -#else #define MENU_TEXT_SPRITE_X_OFFSET 32 -#endif // static functions static void sub_811FC80(s16, s16, u16, u16); diff --git a/src/rotating_gate.c b/src/rotating_gate.c new file mode 100644 index 000000000..f68fe60ba --- /dev/null +++ b/src/rotating_gate.c @@ -0,0 +1,1189 @@ +#include "global.h" +#include "bike.h" +#include "event_data.h" +#include "field_map_obj.h" +#include "constants/maps.h" +#include "constants/songs.h" +#include "sound.h" +#include "sprite.h" + +#define ROTATING_GATE_TILE_TAG 0x1300 +#define ROTATING_GATE_PUZZLE_MAX 12 +#define GATE_ARM_MAX_LENGTH 2 + +#define GATE_ROT(rotationDirection, arm, longArm) \ + ((rotationDirection & 15) << 4) | ((arm & 7) << 1) | (longArm & 1) +#define GATE_ROT_CW(arm, longArm) GATE_ROT(ROTATE_CLOCKWISE, arm, longArm) +#define GATE_ROT_ACW(arm, longArm) GATE_ROT(ROTATE_ANTICLOCKWISE, arm, longArm) +#define GATE_ROT_NONE 255 + +static void SpriteCallback_RotatingGate(struct Sprite *sprite); +static u8 RotatingGate_CreateGate(u8 gateId, s16 deltaX, s16 deltaY); +static void RotatingGate_HideGatesOutsideViewport(struct Sprite *sprite); + +enum +{ + /* + * | + * +-- + */ + GATE_SHAPE_L1, + + /* + * | + * | + * +-- + */ + GATE_SHAPE_L2, + + /* + * | + * +---- + */ + GATE_SHAPE_L3, + + /* + * | + * | + * +---- + */ + GATE_SHAPE_L4, + + /* + * | + * +-- + * | + */ + GATE_SHAPE_T1, + + /* + * | + * | + * +-- + * | + */ + GATE_SHAPE_T2, + + /* + * | + * +---- + * | + */ + GATE_SHAPE_T3, + + /* + * An unused T-shape gate + * | + * +-- + * | + * | + */ + GATE_SHAPE_T4, + + /* + * An unused T-shape gate + * | + * | + * +---- + * | + */ + GATE_SHAPE_UNUSED_T1, + + /* + * An unused T-shape gate + * | + * | + * +-- + * | + * | + */ + GATE_SHAPE_UNUSED_T2, + + /* + * An unused T-shape gate + * | + * +---- + * | + * | + */ + GATE_SHAPE_UNUSED_T3, + + /* + * An unused T-shape gate + * | + * | + * +---- + * | + * | + */ + GATE_SHAPE_UNUSED_T4, +}; + +enum +{ + /* + * 0 degrees (clockwise) + * | + * +-- + * | + */ + GATE_ORIENTATION_0, + + /* + * 90 degress (clockwise) + * --+-- + * | + */ + GATE_ORIENTATION_90, + + /* + * 180 degrees (clockwise) + * | + * --+ + * | + */ + GATE_ORIENTATION_180, + + /* + * 270 degrees (clockwise) + * | + * --+-- + */ + GATE_ORIENTATION_270, + + GATE_ORIENTATION_MAX, +}; + +// Describes the location of the gates "arms" when the gate has not +// been rotated (i.e. rotated 0 degrees) +enum +{ + GATE_ARM_NORTH, + GATE_ARM_EAST, + GATE_ARM_SOUTH, + GATE_ARM_WEST, +}; + +enum +{ + ROTATE_NONE, + ROTATE_ANTICLOCKWISE, + ROTATE_CLOCKWISE, +}; + +enum +{ + PUZZLE_NONE, + PUZZLE_FORTREE_CITY_GYM, + PUZZLE_ROUTE110_TRICK_HOUSE_PUZZLE6, +}; + +struct RotatingGatePuzzle +{ + s16 x; + s16 y; + u8 shape; + u8 orientation; +}; + +struct Coords8 +{ + s8 deltaX; + s8 deltaY; +}; + +// Fortree +static const struct RotatingGatePuzzle sRotatingGate_FortreePuzzleConfig[] = +{ + { 6, 7, GATE_SHAPE_T2, GATE_ORIENTATION_90}, + { 9, 15, GATE_SHAPE_T2, GATE_ORIENTATION_180}, + { 3, 19, GATE_SHAPE_T2, GATE_ORIENTATION_90}, + { 2, 6, GATE_SHAPE_T1, GATE_ORIENTATION_90}, + { 9, 12, GATE_SHAPE_T1, GATE_ORIENTATION_0}, + { 6, 23, GATE_SHAPE_T1, GATE_ORIENTATION_0}, + {12, 22, GATE_SHAPE_T1, GATE_ORIENTATION_0}, + { 6, 3, GATE_SHAPE_L4, GATE_ORIENTATION_180}, +}; + +// Trickhouse +static const struct RotatingGatePuzzle sRotatingGate_TrickHousePuzzleConfig[] = +{ + {14, 5, GATE_SHAPE_T1, GATE_ORIENTATION_90}, + {10, 6, GATE_SHAPE_L2, GATE_ORIENTATION_180}, + { 6, 6, GATE_SHAPE_L4, GATE_ORIENTATION_90}, + {14, 8, GATE_SHAPE_T1, GATE_ORIENTATION_90}, + { 3, 10, GATE_SHAPE_L3, GATE_ORIENTATION_270}, + { 9, 14, GATE_SHAPE_L1, GATE_ORIENTATION_90}, + { 3, 15, GATE_SHAPE_T3, GATE_ORIENTATION_0}, + { 2, 17, GATE_SHAPE_L2, GATE_ORIENTATION_180}, + {12, 18, GATE_SHAPE_T3, GATE_ORIENTATION_270}, + { 5, 18, GATE_SHAPE_L4, GATE_ORIENTATION_90}, + {10, 19, GATE_SHAPE_L3, GATE_ORIENTATION_180}, +}; + +static const u8 sRotatingGateTiles_1[] = INCBIN_U8("graphics/misc/rotating_gate_1.4bpp"); +static const u8 sRotatingGateTiles_2[] = INCBIN_U8("graphics/misc/rotating_gate_2.4bpp"); +static const u8 sRotatingGateTiles_3[] = INCBIN_U8("graphics/misc/rotating_gate_3.4bpp"); +static const u8 sRotatingGateTiles_4[] = INCBIN_U8("graphics/misc/rotating_gate_4.4bpp"); +static const u8 sRotatingGateTiles_5[] = INCBIN_U8("graphics/misc/rotating_gate_5.4bpp"); +static const u8 sRotatingGateTiles_6[] = INCBIN_U8("graphics/misc/rotating_gate_6.4bpp"); +static const u8 sRotatingGateTiles_7[] = INCBIN_U8("graphics/misc/rotating_gate_7.4bpp"); +static const u8 sRotatingGateTiles_8[] = INCBIN_U8("graphics/misc/rotating_gate_8.4bpp"); + +static const struct OamData sOamData_RotatingGateLarge = +{ + .y = 0, + .affineMode = ST_OAM_AFFINE_NORMAL, + .objMode = 0, + .mosaic = 0, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .x = 0, + .matrixNum = 0, + .size = 3, + .tileNum = 0, + .priority = 2, + .paletteNum = 2, + .affineParam = 0, +}; + +static const struct OamData sOamData_RotatingGateRegular = +{ + .y = 0, + .affineMode = ST_OAM_AFFINE_NORMAL, + .objMode = 0, + .mosaic = 0, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .x = 0, + .matrixNum = 0, + .size = 2, + .tileNum = 0, + .priority = 2, + .paletteNum = 2, + .affineParam = 0, +}; + +static const struct SpriteSheet sRotatingGatesGraphicsTable[] = +{ + {sRotatingGateTiles_1, 0x200, ROTATING_GATE_TILE_TAG + GATE_SHAPE_L1}, + {sRotatingGateTiles_2, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_L2}, + {sRotatingGateTiles_3, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_L3}, + {sRotatingGateTiles_4, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_L4}, + {sRotatingGateTiles_5, 0x200, ROTATING_GATE_TILE_TAG + GATE_SHAPE_T1}, + {sRotatingGateTiles_6, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_T2}, + {sRotatingGateTiles_7, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_T3}, + {sRotatingGateTiles_8, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_T4}, + {NULL}, +}; + +static const union AnimCmd sSpriteAnim_RotatingGateLarge[] = +{ + ANIMCMD_FRAME(0, 0), + ANIMCMD_END, +}; + +static const union AnimCmd sSpriteAnim_RotatingGateRegular[] = +{ + ANIMCMD_FRAME(0, 0), ANIMCMD_END, +}; + +static const union AnimCmd *const sSpriteAnimTable_RotatingGateLarge[] = +{ + sSpriteAnim_RotatingGateLarge, +}; + +static const union AnimCmd *const sSpriteAnimTable_RotatingGateRegular[] = +{ + sSpriteAnim_RotatingGateRegular, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_Rotated0[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0), + AFFINEANIMCMD_JUMP(0), +}; + +static const union AffineAnimCmd sSpriteAffineAnim_Rotated90[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, -64, 0), + AFFINEANIMCMD_JUMP(0), +}; + +static const union AffineAnimCmd sSpriteAffineAnim_Rotated180[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, -128, 0), + AFFINEANIMCMD_JUMP(0), +}; + +static const union AffineAnimCmd sSpriteAffineAnim_Rotated270[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, 64, 0), + AFFINEANIMCMD_JUMP(0), +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingClockwise0to90[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, -4, 16), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingClockwise90to180[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, -64, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, -4, 16), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingClockwise180to270[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, -128, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, -4, 16), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingClockwise270to360[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, 64, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, -4, 16), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingAnticlockwise360to270[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, 4, 16), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingAnticlockwise270to180[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, 64, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, 4, 16), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingAnticlockwise180to90[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, -128, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, 4, 16), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingAnticlockwise90to0[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, -64, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, 4, 16), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingClockwise0to90Faster[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 8), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingClockwise90to180Faster[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, -64, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 8), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingClockwise180to270Faster[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, -128, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 8), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingClockwise270to360Faster[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, 64, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 8), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingAnticlockwise360to270Faster[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 8), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingAnticlockwise270to180Faster[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, 64, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 8), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingAnticlockwise180to90Faster[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, -128, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 8), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd sSpriteAffineAnim_RotatingAnticlockwise90to0Faster[] = +{ + AFFINEANIMCMD_FRAME(0x100, 0x100, -64, 0), + AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 8), + AFFINEANIMCMD_END, +}; + +static const union AffineAnimCmd *const sSpriteAffineAnimTable_RotatingGate[] = +{ + sSpriteAffineAnim_Rotated0, + sSpriteAffineAnim_Rotated90, + sSpriteAffineAnim_Rotated180, + sSpriteAffineAnim_Rotated270, + sSpriteAffineAnim_RotatingAnticlockwise360to270, + sSpriteAffineAnim_RotatingAnticlockwise90to0, + sSpriteAffineAnim_RotatingAnticlockwise180to90, + sSpriteAffineAnim_RotatingAnticlockwise270to180, + sSpriteAffineAnim_RotatingClockwise0to90, + sSpriteAffineAnim_RotatingClockwise90to180, + sSpriteAffineAnim_RotatingClockwise180to270, + sSpriteAffineAnim_RotatingClockwise270to360, + sSpriteAffineAnim_RotatingAnticlockwise360to270Faster, + sSpriteAffineAnim_RotatingAnticlockwise90to0Faster, + sSpriteAffineAnim_RotatingAnticlockwise180to90Faster, + sSpriteAffineAnim_RotatingAnticlockwise270to180Faster, + sSpriteAffineAnim_RotatingClockwise0to90Faster, + sSpriteAffineAnim_RotatingClockwise90to180Faster, + sSpriteAffineAnim_RotatingClockwise180to270Faster, + sSpriteAffineAnim_RotatingClockwise270to360Faster, +}; + + +static const struct SpriteTemplate sSpriteTemplate_RotatingGateLarge = +{ + .tileTag = ROTATING_GATE_TILE_TAG, + .paletteTag = 0xFFFF, + .oam = &sOamData_RotatingGateLarge, + .anims = sSpriteAnimTable_RotatingGateLarge, + .images = NULL, + .affineAnims = sSpriteAffineAnimTable_RotatingGate, + .callback = SpriteCallback_RotatingGate, +}; + +static const struct SpriteTemplate sSpriteTemplate_RotatingGateRegular = +{ + .tileTag = ROTATING_GATE_TILE_TAG, + .paletteTag = 0xFFFF, + .oam = &sOamData_RotatingGateRegular, + .anims = sSpriteAnimTable_RotatingGateRegular, + .images = NULL, + .affineAnims = sSpriteAffineAnimTable_RotatingGate, + .callback = SpriteCallback_RotatingGate, +}; + +// These structures describe what happens to the gate if you hit it at +// a given coordinate in a 4x4 grid when walking in the specified +// direction. Either the gate does not rotate, or it rotates in the +// given direction. This information is compared against the gate +// "arm" layout to see if there is an arm at the position in order to +// produce the final rotation. +static const u8 sRotatingGate_RotationInfoNorth[4 * 4] = +{ + GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, + GATE_ROT_CW(GATE_ARM_WEST, 1), GATE_ROT_CW(GATE_ARM_WEST, 0), GATE_ROT_ACW(GATE_ARM_EAST, 0), GATE_ROT_ACW(GATE_ARM_EAST, 1), + GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, + GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, +}; + +static const u8 sRotatingGate_RotationInfoSouth[4 * 4] = +{ + GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, + GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, + GATE_ROT_ACW(GATE_ARM_WEST, 1), GATE_ROT_ACW(GATE_ARM_WEST, 0), GATE_ROT_CW(GATE_ARM_EAST, 0), GATE_ROT_CW(GATE_ARM_EAST, 1), + GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_NONE, +}; + +static const u8 sRotatingGate_RotationInfoWest[4 * 4] = +{ + GATE_ROT_NONE, GATE_ROT_ACW(GATE_ARM_NORTH, 1), GATE_ROT_NONE, GATE_ROT_NONE, + GATE_ROT_NONE, GATE_ROT_ACW(GATE_ARM_NORTH, 0), GATE_ROT_NONE, GATE_ROT_NONE, + GATE_ROT_NONE, GATE_ROT_CW(GATE_ARM_SOUTH, 0), GATE_ROT_NONE, GATE_ROT_NONE, + GATE_ROT_NONE, GATE_ROT_CW(GATE_ARM_SOUTH, 1), GATE_ROT_NONE, GATE_ROT_NONE, +}; + +static const u8 sRotatingGate_RotationInfoEast[4 * 4] = +{ + GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_CW(GATE_ARM_NORTH, 1), GATE_ROT_NONE, + GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_CW(GATE_ARM_NORTH, 0), GATE_ROT_NONE, + GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_ACW(GATE_ARM_SOUTH, 0), GATE_ROT_NONE, + GATE_ROT_NONE, GATE_ROT_NONE, GATE_ROT_ACW(GATE_ARM_SOUTH, 1), GATE_ROT_NONE, +}; + +// These tables describe the relative coordinate positions the arms +// must move through in order to be rotated. +static const struct Coords8 sRotatingGate_ArmPositionsClockwiseRotation[] = { + { 0, -1 }, { 1, -2 }, { 0, 0 }, { 1, 0 }, { -1, 0 }, { -1, 1 }, { -1, -1 }, { -2, -1 }, +}; + +static const struct Coords8 sRotatingGate_ArmPositionsAntiClockwiseRotation[] = { + { -1, -1 }, { -1, -2 }, { 0, -1 }, { 1, -1 }, { 0, 0 }, { 0, 1 }, { -1, 0 }, { -2, 0 }, +}; + +// Describes where the gates "arms" are in the order north, east, south, west. +// These are adjusted using the current orientation to perform collision checking +static const u8 sRotatingGate_ArmLayout[][4 * 2] = +{ + // L-shape gates + { + 1, 0, + 1, 0, + 0, 0, + 0, 0, + }, + { + 1, 1, + 1, 0, + 0, 0, + 0, 0, + }, + { + 1, 0, + 1, 1, + 0, 0, + 0, 0, + }, + { + 1, 1, + 1, 1, + 0, 0, + 0, 0, + }, + + // T-shape gates + { + 1, 0, + 1, 0, + 1, 0, + 0, 0, + }, + { + 1, 1, + 1, 0, + 1, 0, + 0, 0, + }, + { + 1, 0, + 1, 1, + 1, 0, + 0, 0, + }, + { + 1, 0, + 1, 0, + 1, 1, + 0, 0, + }, + + // Unused T-shape gates + // These have 2-3 long arms and cannot actually be used anywhere + // since configuration for them is missing from the other tables. + { + 1, 1, + 1, 1, + 1, 0, + 0, 0, + }, + { + 1, 1, + 1, 0, + 1, 1, + 0, 0, + }, + { + 1, 0, + 1, 1, + 1, 1, + 0, 0, + }, + { + 1, 1, + 1, 1, + 1, 1, + 0, 0, + }, +}; + +static EWRAM_DATA u8 gRotatingGate_GateSpriteIds[ROTATING_GATE_PUZZLE_MAX] = {0}; +static EWRAM_DATA const struct RotatingGatePuzzle *gRotatingGate_PuzzleConfig = NULL; +static EWRAM_DATA u8 gRotatingGate_PuzzleCount = 0; + +static s32 GetCurrentMapRotatingGatePuzzleType(void) +{ + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(FORTREE_CITY_GYM) && + gSaveBlock1Ptr->location.mapNum == MAP_NUM(FORTREE_CITY_GYM)) + { + return PUZZLE_FORTREE_CITY_GYM; + } + + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE110_TRICK_HOUSE_PUZZLE6) && + gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE110_TRICK_HOUSE_PUZZLE6)) + { + return PUZZLE_ROUTE110_TRICK_HOUSE_PUZZLE6; + } + + return PUZZLE_NONE; +} + +static void RotatingGate_ResetAllGateOrientations(void) +{ + s32 i; + u8 *ptr; + + ptr = (u8 *)GetVarPointer(0x4000); + + for (i = 0; i < gRotatingGate_PuzzleCount; i++) + { + ptr[i] = gRotatingGate_PuzzleConfig[i].orientation; + } +} + +static s32 RotatingGate_GetGateOrientation(u8 gateId) +{ + return ((u8 *)GetVarPointer(0x4000))[gateId]; +} + +static void RotatingGate_SetGateOrientation(u8 gateId, u8 orientation) +{ + ((u8 *)GetVarPointer(0x4000))[gateId] = orientation; +} + +static void RotatingGate_RotateInDirection(u8 gateId, u32 rotationDirection) +{ + u8 orientation = RotatingGate_GetGateOrientation(gateId); + + if (rotationDirection == ROTATE_ANTICLOCKWISE) + { + if (orientation) + { + orientation--; + } + else + { + orientation = GATE_ORIENTATION_270; + } + } + else + { + orientation = ++orientation % GATE_ORIENTATION_MAX; + } + + RotatingGate_SetGateOrientation(gateId, orientation); +} + +static void RotatingGate_LoadPuzzleConfig(void) +{ + s32 puzzleType = GetCurrentMapRotatingGatePuzzleType(); + u32 i; + + switch (puzzleType) + { + case PUZZLE_FORTREE_CITY_GYM: + gRotatingGate_PuzzleConfig = sRotatingGate_FortreePuzzleConfig; + gRotatingGate_PuzzleCount = + sizeof(sRotatingGate_FortreePuzzleConfig) / sizeof(struct RotatingGatePuzzle); + break; + case PUZZLE_ROUTE110_TRICK_HOUSE_PUZZLE6: + gRotatingGate_PuzzleConfig = sRotatingGate_TrickHousePuzzleConfig; + gRotatingGate_PuzzleCount = + sizeof(sRotatingGate_TrickHousePuzzleConfig) / sizeof(struct RotatingGatePuzzle); + break; + case PUZZLE_NONE: + default: + return; + } + + for (i = 0; i < ROTATING_GATE_PUZZLE_MAX - 1; i++) + { + gRotatingGate_GateSpriteIds[i] = MAX_SPRITES; + } +} + +static void RotatingGate_CreateGatesWithinViewport(s16 deltaX, s16 deltaY) +{ + u8 i; + + // Calculate the bounding box of the camera + // Same as RotatingGate_DestroyGatesOutsideViewport + s16 x = gSaveBlock1Ptr->pos.x - 2; + s16 x2 = gSaveBlock1Ptr->pos.x + 0x11; + s16 y = gSaveBlock1Ptr->pos.y - 2; + s16 y2 = gSaveBlock1Ptr->pos.y + 0xe; + + s16 x3, y3; + + for (i = 0; i < gRotatingGate_PuzzleCount; i++) + { + x3 = gRotatingGate_PuzzleConfig[i].x + 7; + y3 = gRotatingGate_PuzzleConfig[i].y + 7; + + if (y <= y3 && y2 >= y3 && x <= x3 && x2 >= x3 && + gRotatingGate_GateSpriteIds[i] == MAX_SPRITES) + { + gRotatingGate_GateSpriteIds[i] = RotatingGate_CreateGate(i, deltaX, deltaY); + } + } +} + +static u8 RotatingGate_CreateGate(u8 gateId, s16 deltaX, s16 deltaY) +{ + struct Sprite *sprite; + struct SpriteTemplate template; + const struct RotatingGatePuzzle *gate; + u8 spriteId; + s16 x, y; + + gate = &gRotatingGate_PuzzleConfig[gateId]; + + if (gate->shape == GATE_SHAPE_L1 || gate->shape == GATE_SHAPE_T1) + template = sSpriteTemplate_RotatingGateRegular; + else + template = sSpriteTemplate_RotatingGateLarge; + + template.tileTag = gate->shape + ROTATING_GATE_TILE_TAG; + + spriteId = CreateSprite(&template, 0, 0, 0x94); + if (spriteId == MAX_SPRITES) + return MAX_SPRITES; + + x = gate->x + 7; + y = gate->y + 7; + + sprite = &gSprites[spriteId]; + sprite->data[0] = gateId; + sprite->coordOffsetEnabled = 1; + + sub_8092FF0(x + deltaX, y + deltaY, &sprite->pos1.x, &sprite->pos1.y); + RotatingGate_HideGatesOutsideViewport(sprite); + StartSpriteAffineAnim(sprite, RotatingGate_GetGateOrientation(gateId)); + + return spriteId; +} + +/* +static*/ void SpriteCallback_RotatingGate(struct Sprite *sprite) +{ + u8 rotationDirection; + u8 orientation; + u8 affineAnimation; + + rotationDirection = sprite->data[1]; + orientation = sprite->data[2]; + + RotatingGate_HideGatesOutsideViewport(sprite); + + if (rotationDirection == ROTATE_ANTICLOCKWISE) + { + affineAnimation = orientation + 4; + + if (GetPlayerSpeed() != 1) + affineAnimation += 8; + + PlaySE(SE_HI_TURUN); + StartSpriteAffineAnim(sprite, affineAnimation); + } + else if (rotationDirection == ROTATE_CLOCKWISE) + { + affineAnimation = orientation + 8; + + if (GetPlayerSpeed() != 1) + affineAnimation += 8; + + PlaySE(SE_HI_TURUN); + StartSpriteAffineAnim(sprite, affineAnimation); + } + + sprite->data[1] = ROTATE_NONE; +} + +/* +static*/ void RotatingGate_HideGatesOutsideViewport(struct Sprite *sprite) +{ + u16 x; + s16 x2; + u16 y; + s16 y2; + + sprite->invisible = FALSE; + x = sprite->pos1.x + sprite->pos2.x + sprite->centerToCornerVecX + gSpriteCoordOffsetX; + y = sprite->pos1.y + sprite->pos2.y + sprite->centerToCornerVecY + gSpriteCoordOffsetY; + + x2 = x + 0x40; // Dimensions of the rotating gate + y2 = y + 0x40; + + if ((s16)x > DISPLAY_WIDTH + 0x10 - 1 || x2 < -0x10) + { + sprite->invisible = TRUE; + } + + if ((s16)y > DISPLAY_HEIGHT + 0x10 - 1 || y2 < -0x10) + { + sprite->invisible = TRUE; + } +} + +static void LoadRotatingGatePics(void) +{ + LoadSpriteSheets(sRotatingGatesGraphicsTable); +} + +/* +static*/ void RotatingGate_DestroyGatesOutsideViewport(void) +{ + s16 x; + s16 x2; + s16 y; + s16 y2; + s16 xGate; + s16 yGate; + s32 i; + struct Sprite *sprite; + + // Same as RotatingGate_CreateGatesWithinViewport + x = gSaveBlock1Ptr->pos.x - 2; + x2 = gSaveBlock1Ptr->pos.x + 0x11; + y = gSaveBlock1Ptr->pos.y - 2; + y2 = gSaveBlock1Ptr->pos.y + 0xe; + + for (i = 0; i < gRotatingGate_PuzzleCount; i++) + { + xGate = gRotatingGate_PuzzleConfig[i].x + 7; + yGate = gRotatingGate_PuzzleConfig[i].y + 7; + + if (gRotatingGate_GateSpriteIds[i] == MAX_SPRITES) + continue; + + if (xGate < x || xGate > x2 || yGate < y || yGate > y2) + { + sprite = &gSprites[gRotatingGate_GateSpriteIds[i]]; + FreeSpriteOamMatrix(sprite); + DestroySprite(sprite); + gRotatingGate_GateSpriteIds[i] = MAX_SPRITES; + } + } +} + + +#ifdef NONMATCHING +bool8 MapGridIsImpassableAt(s32, s32); //fool the compiler + +static s32 RotatingGate_CanRotate(u8 gateId, s16 rotationDirection) +{ + const struct Coords8 *armPos; + u8 orientation; + s16 x; + s16 y; + u8 shape; + u32 shape8; + s32 i; + s32 j; + s32 armOrientation; + const u8 *gateArmCollisionData; + u8 armIndex; + + if (rotationDirection == ROTATE_ANTICLOCKWISE) + armPos = sRotatingGate_ArmPositionsAntiClockwiseRotation; + else if (rotationDirection == ROTATE_CLOCKWISE) + armPos = sRotatingGate_ArmPositionsClockwiseRotation; + else + return FALSE; + + orientation = RotatingGate_GetGateOrientation(gateId); + + shape = gRotatingGate_PuzzleConfig[gateId].shape; + x = gRotatingGate_PuzzleConfig[gateId].x + 7; + y = gRotatingGate_PuzzleConfig[gateId].y + 7; + + + // Loop through the gate's "arms" clockwise (north, south, east, west) + for (i = GATE_ARM_NORTH, shape8 = shape* 4*2 ; i <= GATE_ARM_WEST; i++) + { + // Ensure that no part of the arm collides with the map + for (j = 0, armOrientation = orientation + i, gateArmCollisionData = (u8 *)((u32)sRotatingGate_ArmLayout + shape8 + 2*i); j < GATE_ARM_MAX_LENGTH; j++) + { + armIndex = 2 * (armOrientation % 4) + j; + + if (*gateArmCollisionData) + { + if (MapGridIsImpassableAt(x + armPos[armIndex].deltaX, y + armPos[armIndex].deltaY) == TRUE) + return FALSE; + } + gateArmCollisionData++; + } + } + + return TRUE; +} + +#else +ASM_DIRECT +static s32 RotatingGate_CanRotate(u8 a, s16 rotationDirection) +{ + asm(".syntax 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, 0xC\n\ + lsls r0, 24\n\ + lsrs r4, r0, 24\n\ + cmp r1, 0x1\n\ + bne _080FBCFC\n\ + ldr r0, =sRotatingGate_ArmPositionsAntiClockwiseRotation\n\ + mov r10, r0\n\ + b _080FBD08\n\ + .pool\n\ +_080FBCFC:\n\ + cmp r1, 0x2\n\ + beq _080FBD04\n\ +_080FBD00:\n\ + movs r0, 0\n\ + b _080FBD98\n\ +_080FBD04:\n\ + ldr r1, =sRotatingGate_ArmPositionsClockwiseRotation\n\ + mov r10, r1\n\ +_080FBD08:\n\ + adds r0, r4, 0\n\ + bl RotatingGate_GetGateOrientation\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + str r0, [sp]\n\ + ldr r0, =gRotatingGate_PuzzleConfig\n\ + ldr r1, [r0]\n\ + lsls r0, r4, 3\n\ + adds r0, r1\n\ + ldrb r2, [r0, 0x4]\n\ + ldrh r1, [r0]\n\ + adds r1, 0x7\n\ + ldrh r0, [r0, 0x2]\n\ + adds r0, 0x7\n\ + movs r3, 0\n\ + lsls r2, 3\n\ + str r2, [sp, 0x4]\n\ + lsls r1, 16\n\ + asrs r1, 16\n\ + mov r9, r1\n\ + lsls r0, 16\n\ + asrs r0, 16\n\ + mov r8, r0\n\ +_080FBD38:\n\ + movs r6, 0\n\ + ldr r2, [sp]\n\ + adds r7, r2, r3\n\ + lsls r0, r3, 1\n\ + adds r5, r7, 0\n\ + ldr r1, [sp, 0x4]\n\ + adds r0, r1\n\ + ldr r2, =sRotatingGate_ArmLayout\n\ + adds r4, r0, r2\n\ +_080FBD4A:\n\ + adds r0, r5, 0\n\ + cmp r5, 0\n\ + bge _080FBD52\n\ + adds r0, r7, 0x3\n\ +_080FBD52:\n\ + asrs r0, 2\n\ + lsls r0, 2\n\ + subs r0, r5, r0\n\ + lsls r0, 1\n\ + adds r0, r6\n\ + lsls r0, 24\n\ + lsrs r1, r0, 24\n\ + ldrb r0, [r4]\n\ + cmp r0, 0\n\ + beq _080FBD88\n\ + lsls r1, 2\n\ + add r1, r10\n\ + movs r0, 0\n\ + ldrsb r0, [r1, r0]\n\ + add r0, r9\n\ + ldrb r1, [r1, 0x1]\n\ + lsls r1, 24\n\ + asrs r1, 24\n\ + add r1, r8\n\ + str r3, [sp, 0x8]\n\ + bl MapGridIsImpassableAt\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + ldr r3, [sp, 0x8]\n\ + cmp r0, 0x1\n\ + beq _080FBD00\n\ +_080FBD88:\n\ + adds r4, 0x1\n\ + adds r6, 0x1\n\ + cmp r6, 0x1\n\ + ble _080FBD4A\n\ + adds r3, 0x1\n\ + cmp r3, 0x3\n\ + ble _080FBD38\n\ + movs r0, 0x1\n\ +_080FBD98:\n\ + add sp, 0xC\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r1}\n\ + bx r1\n\ + .pool\n\ +.syntax divided\n"); +} +#endif + +static s32 RotatingGate_HasArm(u8 gateId, u8 armInfo) +{ + s32 isLongArm; + s8 armOrientation; + s32 arm; + s32 shape; + + arm = armInfo >> 1; + isLongArm = armInfo & 1; + + armOrientation = (arm - RotatingGate_GetGateOrientation(gateId) + 4) % 4; + shape = gRotatingGate_PuzzleConfig[gateId].shape; + return sRotatingGate_ArmLayout[shape][armOrientation * 2 + isLongArm]; +} + +static void RotatingGate_TriggerRotationAnimation(u8 gateId, s32 rotationDirection) +{ + struct Sprite *sprite; + + if (gRotatingGate_GateSpriteIds[gateId] != MAX_SPRITES) + { + sprite = &gSprites[gRotatingGate_GateSpriteIds[gateId]]; + sprite->data[1] = rotationDirection; + sprite->data[2] = RotatingGate_GetGateOrientation(gateId); + } +} + +static u8 RotatingGate_GetRotationInfo(u8 direction, s16 x, s16 y) +{ + register const u8 *ptr; + + if (direction == DIR_NORTH) + ptr = sRotatingGate_RotationInfoNorth; + else if (direction == DIR_SOUTH) + ptr = sRotatingGate_RotationInfoSouth; + else if (direction == DIR_WEST) + ptr = sRotatingGate_RotationInfoWest; + else if (direction == DIR_EAST) + ptr = sRotatingGate_RotationInfoEast; + else + return GATE_ROT_NONE; + + return ptr[y * 4 + x]; +} + +void RotatingGate_InitPuzzle(void) +{ + if (GetCurrentMapRotatingGatePuzzleType()) + { + RotatingGate_LoadPuzzleConfig(); + RotatingGate_ResetAllGateOrientations(); + } +} + +void RotatingGatePuzzleCameraUpdate(u16 deltaX, u16 deltaY) +{ + if (GetCurrentMapRotatingGatePuzzleType()) + { + RotatingGate_CreateGatesWithinViewport(deltaX, deltaY); + RotatingGate_DestroyGatesOutsideViewport(); + } +} + +void RotatingGate_InitPuzzleAndGraphics(void) +{ + if (GetCurrentMapRotatingGatePuzzleType()) + { + LoadRotatingGatePics(); + RotatingGate_LoadPuzzleConfig(); + RotatingGate_CreateGatesWithinViewport(0, 0); + } +} + +bool8 CheckForRotatingGatePuzzleCollision(u8 direction, s16 x, s16 y) +{ + s32 i; + + if (!GetCurrentMapRotatingGatePuzzleType()) + return FALSE; + for (i = 0; i < gRotatingGate_PuzzleCount; i++) + { + s16 gateX = gRotatingGate_PuzzleConfig[i].x + 7; + s16 gateY = gRotatingGate_PuzzleConfig[i].y + 7; + + if (gateX - 2 <= x && x <= gateX + 1 && gateY - 2 <= y && y <= gateY + 1) + { + s16 centerX = x - gateX + 2; + s16 centerY = y - gateY + 2; + u8 rotationInfo = RotatingGate_GetRotationInfo(direction, centerX, centerY); + + if (rotationInfo != GATE_ROT_NONE) + { + u8 rotationDirection = ((rotationInfo & 0xF0) >> 4); + u8 armInfo = rotationInfo & 0xF; + + if (RotatingGate_HasArm(i, armInfo)) + { + if (RotatingGate_CanRotate(i, rotationDirection)) + { + RotatingGate_TriggerRotationAnimation(i, rotationDirection); + RotatingGate_RotateInDirection(i, rotationDirection); + return FALSE; + } + return TRUE; + } + } + } + } + return FALSE; +} + +bool8 CheckForRotatingGatePuzzleCollisionWithoutAnimation(u8 direction, s16 x, s16 y) +{ + s32 i; + + if (!GetCurrentMapRotatingGatePuzzleType()) + return FALSE; + for (i = 0; i < gRotatingGate_PuzzleCount; i++) + { + s16 gateX = gRotatingGate_PuzzleConfig[i].x + 7; + s16 gateY = gRotatingGate_PuzzleConfig[i].y + 7; + + if (gateX - 2 <= x && x <= gateX + 1 && gateY - 2 <= y && y <= gateY + 1) + { + s16 centerX = x - gateX + 2; + s16 centerY = y - gateY + 2; + u8 rotationInfo = RotatingGate_GetRotationInfo(direction, centerX, centerY); + + if (rotationInfo != GATE_ROT_NONE) + { + u8 rotationDirection = ((rotationInfo & 0xF0) >> 4); + u8 armInfo = rotationInfo & 0xF; + + if (RotatingGate_HasArm(i, armInfo)) + { + if (!RotatingGate_CanRotate(i, rotationDirection)) + { + return TRUE; + } + } + } + } + } + return FALSE; +} diff --git a/sym_ewram.txt b/sym_ewram.txt index f84c5c1be..52bf32709 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -522,15 +522,7 @@ gUnknown_0203A018: @ 203A018 gUnknown_0203A034: @ 203A034 .space 0x4 -gUnknown_0203A038: @ 203A038 - .space 0xC - -gUnknown_0203A044: @ 203A044 - .space 0x4 - -gUnknown_0203A048: @ 203A048 - .space 0x4 - + .include "src/rotating_gate.o" .include "src/safari_zone.o" gUnknown_0203A0F4: @ 203A0F4