From 7700fe61fed39ecda329db5087ca30e3eb3335ee Mon Sep 17 00:00:00 2001 From: KDSKardabox Date: Wed, 18 Apr 2018 17:42:41 +0530 Subject: [PATCH] Decompile field camera --- asm/field_camera.s | 1153 --------------------------------------- include/bike.h | 4 + include/field_camera.h | 7 +- include/field_map_obj.h | 2 + include/fieldmap.h | 2 + include/overworld.h | 6 + include/rotating_gate.h | 8 + ld_script.txt | 2 +- src/bike.c | 3 +- src/decoration.c | 20 +- src/field_camera.c | 491 ++++++++++++++++- src/overworld.c | 27 +- src/rotating_gate.c | 6 + sym_common.txt | 6 +- sym_ewram.txt | 2 +- 15 files changed, 537 insertions(+), 1202 deletions(-) delete mode 100644 asm/field_camera.s create mode 100644 include/rotating_gate.h diff --git a/asm/field_camera.s b/asm/field_camera.s deleted file mode 100644 index 35359f444..000000000 --- a/asm/field_camera.s +++ /dev/null @@ -1,1153 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start move_tilemap_camera_to_upper_left_corner_ -@ void move_tilemap_camera_to_upper_left_corner_(struc_28 *a1) -move_tilemap_camera_to_upper_left_corner_: @ 8089B58 - movs r1, 0 - strb r1, [r0, 0x2] - strb r1, [r0, 0x3] - strb r1, [r0] - strb r1, [r0, 0x1] - movs r1, 0x1 - strb r1, [r0, 0x4] - bx lr - thumb_func_end move_tilemap_camera_to_upper_left_corner_ - - thumb_func_start tilemap_move_something -@ void tilemap_move_something(struct struc_28 *, u8 deltaX, u8 deltaY) -tilemap_move_something: @ 8089B68 - ldrb r3, [r0, 0x2] - adds r3, r1 - strb r3, [r0, 0x2] - ldrb r1, [r0, 0x2] - movs r3, 0x1F - ands r1, r3 - strb r1, [r0, 0x2] - ldrb r1, [r0, 0x3] - adds r1, r2 - strb r1, [r0, 0x3] - ldrb r1, [r0, 0x3] - ands r1, r3 - strb r1, [r0, 0x3] - bx lr - thumb_func_end tilemap_move_something - - thumb_func_start coords8_add -@ void coords8_add(struct coords8 *coords, u8 x, u8 y) -coords8_add: @ 8089B84 - ldrb r3, [r0] - adds r3, r1 - strb r3, [r0] - ldrb r1, [r0, 0x1] - adds r1, r2 - strb r1, [r0, 0x1] - bx lr - thumb_func_end coords8_add - - thumb_func_start move_tilemap_camera_to_upper_left_corner -@ void move_tilemap_camera_to_upper_left_corner() -move_tilemap_camera_to_upper_left_corner: @ 8089B94 - push {lr} - ldr r0, =gUnknown_03000E20 - bl move_tilemap_camera_to_upper_left_corner_ - pop {r0} - bx r0 - .pool - thumb_func_end move_tilemap_camera_to_upper_left_corner - - thumb_func_start FieldUpdateBgTilemapScroll -@ void FieldUpdateBgTilemapScroll() -FieldUpdateBgTilemapScroll: @ 8089BA4 - push {r4,r5,lr} - ldr r1, =gUnknown_03000E20 - ldr r0, =gUnknown_03000E28 - movs r2, 0 - ldrsh r5, [r0, r2] - ldrb r0, [r1] - adds r5, r0 - ldr r0, =gUnknown_03000E2A - movs r2, 0 - ldrsh r4, [r0, r2] - ldrb r1, [r1, 0x1] - adds r4, r1 - adds r4, 0x8 - lsls r5, 16 - lsrs r5, 16 - movs r0, 0x14 - adds r1, r5, 0 - bl SetGpuReg - lsls r4, 16 - lsrs r4, 16 - movs r0, 0x16 - adds r1, r4, 0 - bl SetGpuReg - movs r0, 0x18 - adds r1, r5, 0 - bl SetGpuReg - movs r0, 0x1A - adds r1, r4, 0 - bl SetGpuReg - movs r0, 0x1C - adds r1, r5, 0 - bl SetGpuReg - movs r0, 0x1E - adds r1, r4, 0 - bl SetGpuReg - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end FieldUpdateBgTilemapScroll - - thumb_func_start sub_8089C08 -sub_8089C08: @ 8089C08 - push {r4,lr} - ldr r3, =gUnknown_03000E20 - ldr r2, =gUnknown_03000E28 - ldrh r2, [r2] - ldrb r4, [r3] - adds r2, r4 - strh r2, [r0] - ldr r0, =gUnknown_03000E2A - ldrh r0, [r0] - ldrb r3, [r3, 0x1] - adds r0, r3 - adds r0, 0x8 - strh r0, [r1] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8089C08 - - thumb_func_start DrawWholeMapView -@ void DrawWholeMapView() -DrawWholeMapView: @ 8089C34 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - movs r2, 0 - ldrsh r0, [r1, r2] - movs r2, 0x2 - ldrsh r1, [r1, r2] - ldr r2, =gMapHeader - ldr r2, [r2] - bl DrawWholeMapViewInternal - ldr r1, =gUnknown_03000E20 - movs r0, 0x1 - strb r0, [r1, 0x4] - pop {r0} - bx r0 - .pool - thumb_func_end DrawWholeMapView - - thumb_func_start DrawWholeMapViewInternal -@ void DrawWholeMapViewInternal(s32 x, s32 y, struct mapdata_header *mapGrid) -DrawWholeMapViewInternal: @ 8089C60 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - mov r10, r0 - mov r9, r1 - mov r8, r2 - movs r1, 0 -_08089C74: - ldr r2, =gUnknown_03000E20 - ldrb r0, [r2, 0x3] - adds r0, r1, r0 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1F - bls _08089C88 - subs r0, 0x20 - lsls r0, 24 - lsrs r0, 24 -_08089C88: - lsls r6, r0, 5 - movs r4, 0 - adds r7, r1, 0x2 - str r7, [sp] - lsrs r5, r1, 1 -_08089C92: - ldr r1, =gUnknown_03000E20 - ldrb r0, [r1, 0x2] - adds r0, r4, r0 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1F - bls _08089CA6 - subs r0, 0x20 - lsls r0, 24 - lsrs r0, 24 -_08089CA6: - adds r1, r6, r0 - lsls r1, 16 - lsrs r1, 16 - lsrs r2, r4, 1 - add r2, r10 - mov r0, r8 - mov r7, r9 - adds r3, r7, r5 - bl DrawMetatileAt - adds r0, r4, 0x2 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x1F - bls _08089C92 - ldr r1, [sp] - lsls r0, r1, 24 - lsrs r1, r0, 24 - cmp r1, 0x1F - bls _08089C74 - 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 DrawWholeMapViewInternal - - thumb_func_start RedrawMapSlicesForCameraUpdate -@ void RedrawMapSlicesForCameraUpdate(struct struc_28 *, u8 deltaX, u8 deltaY) -RedrawMapSlicesForCameraUpdate: @ 8089CE4 - push {r4-r7,lr} - adds r5, r0, 0 - adds r6, r1, 0 - adds r7, r2, 0 - ldr r0, =gMapHeader - ldr r4, [r0] - cmp r6, 0 - ble _08089CFC - adds r0, r5, 0 - adds r1, r4, 0 - bl RedrawMapSliceWest -_08089CFC: - cmp r6, 0 - bge _08089D08 - adds r0, r5, 0 - adds r1, r4, 0 - bl RedrawMapSliceEast -_08089D08: - cmp r7, 0 - ble _08089D14 - adds r0, r5, 0 - adds r1, r4, 0 - bl RedrawMapSliceNorth -_08089D14: - cmp r7, 0 - bge _08089D20 - adds r0, r5, 0 - adds r1, r4, 0 - bl RedrawMapSliceSouth -_08089D20: - movs r0, 0x1 - strb r0, [r5, 0x4] - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end RedrawMapSlicesForCameraUpdate - - thumb_func_start RedrawMapSliceNorth -@ void RedrawMapSliceNorth(struct struc_28 *, struct mapdata_header *mapGrid) -RedrawMapSliceNorth: @ 8089D30 - push {r4-r7,lr} - adds r5, r0, 0 - adds r7, r1, 0 - ldrb r0, [r5, 0x3] - adds r0, 0x1C - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1F - bls _08089D48 - subs r0, 0x20 - lsls r0, 24 - lsrs r0, 24 -_08089D48: - lsls r6, r0, 5 - movs r4, 0 -_08089D4C: - ldrb r0, [r5, 0x2] - adds r0, r4, r0 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1F - bls _08089D5E - subs r0, 0x20 - lsls r0, 24 - lsrs r0, 24 -_08089D5E: - adds r1, r6, r0 - lsls r1, 16 - lsrs r1, 16 - ldr r0, =gSaveBlock1Ptr - ldr r3, [r0] - movs r0, 0 - ldrsh r2, [r3, r0] - lsrs r0, r4, 1 - adds r2, r0 - movs r0, 0x2 - ldrsh r3, [r3, r0] - adds r3, 0xE - adds r0, r7, 0 - bl DrawMetatileAt - adds r0, r4, 0x2 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x1F - bls _08089D4C - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end RedrawMapSliceNorth - - thumb_func_start RedrawMapSliceSouth -@ void RedrawMapSliceSouth(struct struc_28 *, struct mapdata_header *mapGrid) -RedrawMapSliceSouth: @ 8089D90 - push {r4-r7,lr} - adds r5, r0, 0 - adds r7, r1, 0 - ldrb r0, [r5, 0x3] - lsls r6, r0, 5 - movs r4, 0 -_08089D9C: - ldrb r0, [r5, 0x2] - adds r0, r4, r0 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1F - bls _08089DAE - subs r0, 0x20 - lsls r0, 24 - lsrs r0, 24 -_08089DAE: - adds r1, r6, r0 - ldr r0, =gSaveBlock1Ptr - ldr r3, [r0] - movs r0, 0 - ldrsh r2, [r3, r0] - lsrs r0, r4, 1 - adds r2, r0 - movs r0, 0x2 - ldrsh r3, [r3, r0] - adds r0, r7, 0 - bl DrawMetatileAt - adds r0, r4, 0x2 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x1F - bls _08089D9C - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end RedrawMapSliceSouth - - thumb_func_start RedrawMapSliceEast -@ void RedrawMapSliceEast(struct struc_28 *, struct mapdata_header *mapGrid) -RedrawMapSliceEast: @ 8089DDC - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r5, r0, 0 - mov r8, r1 - ldrb r6, [r5, 0x2] - movs r4, 0 -_08089DEA: - ldrb r0, [r5, 0x3] - adds r0, r4, r0 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1F - bls _08089DFC - subs r0, 0x20 - lsls r0, 24 - lsrs r0, 24 -_08089DFC: - lsls r1, r0, 5 - adds r1, r6 - lsls r1, 16 - lsrs r1, 16 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r3, 0 - ldrsh r2, [r0, r3] - movs r7, 0x2 - ldrsh r3, [r0, r7] - lsrs r0, r4, 1 - adds r3, r0 - mov r0, r8 - bl DrawMetatileAt - adds r0, r4, 0x2 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x1F - bls _08089DEA - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end RedrawMapSliceEast - - thumb_func_start RedrawMapSliceWest -@ void RedrawMapSliceWest(struct struc_28 *, struct mapdata_header *mapGrid) -RedrawMapSliceWest: @ 8089E34 - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r6, r0, 0 - mov r8, r1 - ldrb r0, [r6, 0x2] - adds r0, 0x1C - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x1F - bls _08089E52 - adds r0, r5, 0 - subs r0, 0x20 - lsls r0, 24 - lsrs r5, r0, 24 -_08089E52: - movs r4, 0 -_08089E54: - ldrb r0, [r6, 0x3] - adds r0, r4, r0 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1F - bls _08089E66 - subs r0, 0x20 - lsls r0, 24 - lsrs r0, 24 -_08089E66: - lsls r1, r0, 5 - adds r1, r5 - lsls r1, 16 - lsrs r1, 16 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r3, 0 - ldrsh r2, [r0, r3] - adds r2, 0xE - movs r7, 0x2 - ldrsh r3, [r0, r7] - lsrs r0, r4, 1 - adds r3, r0 - mov r0, r8 - bl DrawMetatileAt - adds r0, r4, 0x2 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x1F - bls _08089E54 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end RedrawMapSliceWest - - thumb_func_start CurrentMapDrawMetatileAt -@ void CurrentMapDrawMetatileAt(u32 x, u32 y) -CurrentMapDrawMetatileAt: @ 8089EA0 - push {r4-r6,lr} - adds r4, r0, 0 - adds r5, r1, 0 - ldr r6, =gUnknown_03000E20 - adds r0, r6, 0 - adds r1, r4, 0 - adds r2, r5, 0 - bl MapPosToBgTilemapOffset - adds r1, r0, 0 - cmp r1, 0 - blt _08089ECC - ldr r0, =gMapHeader - ldr r0, [r0] - lsls r1, 16 - lsrs r1, 16 - adds r2, r4, 0 - adds r3, r5, 0 - bl DrawMetatileAt - movs r0, 0x1 - strb r0, [r6, 0x4] -_08089ECC: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end CurrentMapDrawMetatileAt - - thumb_func_start DrawDoorMetatileAt -@ void DrawDoorMetatileAt(u32 x, u32 y, u16 *metatile) -DrawDoorMetatileAt: @ 8089EDC - push {r4-r6,lr} - adds r3, r0, 0 - adds r4, r1, 0 - adds r5, r2, 0 - ldr r6, =gUnknown_03000E20 - adds r0, r6, 0 - adds r1, r3, 0 - adds r2, r4, 0 - bl MapPosToBgTilemapOffset - cmp r0, 0 - blt _08089F04 - lsls r2, r0, 16 - lsrs r2, 16 - movs r0, 0x1 - adds r1, r5, 0 - bl DrawMetatile - movs r0, 0x1 - strb r0, [r6, 0x4] -_08089F04: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end DrawDoorMetatileAt - - thumb_func_start DrawMetatileAt -@ void DrawMetatileAt(struct mapdata_header *mapGrid, u16 offset, s32 x, s32 y) -DrawMetatileAt: @ 8089F10 - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r5, r0, 0 - adds r6, r2, 0 - adds r7, r3, 0 - lsls r1, 16 - lsrs r1, 16 - mov r8, r1 - adds r0, r6, 0 - adds r1, r7, 0 - bl MapGridGetMetatileIdAt - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x80 - lsls r0, 3 - cmp r4, r0 - bls _08089F38 - movs r4, 0 -_08089F38: - ldr r0, =0x000001ff - cmp r4, r0 - bhi _08089F48 - ldr r0, [r5, 0x10] - ldr r5, [r0, 0xC] - b _08089F54 - .pool -_08089F48: - ldr r0, [r5, 0x14] - ldr r5, [r0, 0xC] - ldr r1, =0xfffffe00 - adds r0, r4, r1 - lsls r0, 16 - lsrs r4, r0, 16 -_08089F54: - adds r0, r6, 0 - adds r1, r7, 0 - bl MapGridGetMetatileLayerTypeAt - lsls r0, 24 - lsrs r0, 24 - lsls r1, r4, 4 - adds r1, r5, r1 - mov r2, r8 - bl DrawMetatile - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end DrawMetatileAt - - thumb_func_start DrawMetatile -@ void DrawMetatile(u32 layerType, u16 *metatile, u16 offset) -DrawMetatile: @ 8089F78 - push {r4,lr} - adds r4, r1, 0 - lsls r2, 16 - lsrs r2, 16 - cmp r0, 0x1 - beq _08089FD0 - cmp r0, 0x1 - bgt _08089F8E - cmp r0, 0 - beq _0808A030 - b _0808A082 -_08089F8E: - cmp r0, 0x2 - bne _0808A082 - ldr r0, =gUnknown_03005DA4 - ldr r0, [r0] - lsls r3, r2, 1 - adds r0, r3, r0 - ldrh r1, [r4] - strh r1, [r0] - ldrh r1, [r4, 0x2] - strh r1, [r0, 0x2] - adds r2, r0, 0 - adds r2, 0x40 - ldrh r1, [r4, 0x4] - strh r1, [r2] - adds r0, 0x42 - ldrh r1, [r4, 0x6] - strh r1, [r0] - ldr r0, =gUnknown_03005D9C - ldr r0, [r0] - adds r0, r3, r0 - movs r2, 0 - strh r2, [r0] - strh r2, [r0, 0x2] - adds r1, r0, 0 - adds r1, 0x40 - strh r2, [r1] - adds r0, 0x42 - strh r2, [r0] - b _0808A066 - .pool -_08089FD0: - ldr r0, =gUnknown_03005DA4 - ldr r0, [r0] - lsls r3, r2, 1 - adds r0, r3, r0 - ldrh r1, [r4] - strh r1, [r0] - ldrh r1, [r4, 0x2] - strh r1, [r0, 0x2] - adds r2, r0, 0 - adds r2, 0x40 - ldrh r1, [r4, 0x4] - strh r1, [r2] - adds r0, 0x42 - ldrh r1, [r4, 0x6] - strh r1, [r0] - ldr r0, =gUnknown_03005D9C - ldr r0, [r0] - adds r0, r3, r0 - ldrh r1, [r4, 0x8] - strh r1, [r0] - ldrh r1, [r4, 0xA] - strh r1, [r0, 0x2] - adds r2, r0, 0 - adds r2, 0x40 - ldrh r1, [r4, 0xC] - strh r1, [r2] - adds r0, 0x42 - ldrh r1, [r4, 0xE] - strh r1, [r0] - ldr r0, =gUnknown_03005DA0 - ldr r0, [r0] - adds r3, r0 - movs r1, 0 - strh r1, [r3] - strh r1, [r3, 0x2] - adds r0, r3, 0 - adds r0, 0x40 - strh r1, [r0] - adds r3, 0x42 - strh r1, [r3] - b _0808A082 - .pool -_0808A030: - ldr r0, =gUnknown_03005DA4 - ldr r0, [r0] - lsls r3, r2, 1 - adds r0, r3, r0 - ldr r1, =0x00003014 - adds r2, r1, 0 - strh r2, [r0] - strh r2, [r0, 0x2] - adds r1, r0, 0 - adds r1, 0x40 - strh r2, [r1] - adds r0, 0x42 - strh r2, [r0] - ldr r0, =gUnknown_03005D9C - ldr r0, [r0] - adds r0, r3, r0 - ldrh r1, [r4] - strh r1, [r0] - ldrh r1, [r4, 0x2] - strh r1, [r0, 0x2] - adds r2, r0, 0 - adds r2, 0x40 - ldrh r1, [r4, 0x4] - strh r1, [r2] - adds r0, 0x42 - ldrh r1, [r4, 0x6] - strh r1, [r0] -_0808A066: - ldr r0, =gUnknown_03005DA0 - ldr r0, [r0] - adds r3, r0 - ldrh r0, [r4, 0x8] - strh r0, [r3] - ldrh r0, [r4, 0xA] - strh r0, [r3, 0x2] - adds r1, r3, 0 - adds r1, 0x40 - ldrh r0, [r4, 0xC] - strh r0, [r1] - adds r3, 0x42 - ldrh r0, [r4, 0xE] - strh r0, [r3] -_0808A082: - movs r0, 0x1 - bl schedule_bg_copy_tilemap_to_vram - movs r0, 0x2 - bl schedule_bg_copy_tilemap_to_vram - movs r0, 0x3 - bl schedule_bg_copy_tilemap_to_vram - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end DrawMetatile - - thumb_func_start MapPosToBgTilemapOffset -@ u32 MapPosToBgTilemapOffset(struct struc_28 *, u32 x, u32 y) -MapPosToBgTilemapOffset: @ 808A0AC - push {r4,r5,lr} - adds r4, r0, 0 - ldr r0, =gSaveBlock1Ptr - ldr r3, [r0] - movs r5, 0 - ldrsh r0, [r3, r5] - subs r1, r0 - lsls r1, 1 - cmp r1, 0x1F - bhi _0808A0D6 - ldrb r0, [r4, 0x2] - adds r1, r0 - cmp r1, 0x1F - ble _0808A0CA - subs r1, 0x20 -_0808A0CA: - movs r5, 0x2 - ldrsh r0, [r3, r5] - subs r0, r2, r0 - lsls r2, r0, 1 - cmp r2, 0x1F - bls _0808A0E0 -_0808A0D6: - movs r0, 0x1 - negs r0, r0 - b _0808A0EE - .pool -_0808A0E0: - ldrb r0, [r4, 0x3] - adds r2, r0 - cmp r2, 0x1F - ble _0808A0EA - subs r2, 0x20 -_0808A0EA: - lsls r0, r2, 5 - adds r0, r1 -_0808A0EE: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end MapPosToBgTilemapOffset - - thumb_func_start CameraUpdateCallback -@ void CameraUpdateCallback(struct CameraUpdateInfo *info) -CameraUpdateCallback: @ 808A0F4 - push {lr} - adds r3, r0, 0 - ldr r2, [r3, 0x4] - cmp r2, 0 - beq _0808A114 - ldr r1, =gSprites - lsls r0, r2, 4 - adds r0, r2 - lsls r0, 2 - adds r0, r1 - movs r2, 0x32 - ldrsh r1, [r0, r2] - str r1, [r3, 0x8] - movs r1, 0x34 - ldrsh r0, [r0, r1] - str r0, [r3, 0xC] -_0808A114: - pop {r0} - bx r0 - .pool - thumb_func_end CameraUpdateCallback - - thumb_func_start ResetCameraUpdateInfo -@ void ResetCameraUpdateInfo() -ResetCameraUpdateInfo: @ 808A11C - ldr r1, =gUnknown_03005DD0 - movs r0, 0 - str r0, [r1, 0x8] - str r0, [r1, 0xC] - str r0, [r1, 0x10] - str r0, [r1, 0x14] - str r0, [r1, 0x4] - str r0, [r1] - bx lr - .pool - thumb_func_end ResetCameraUpdateInfo - - thumb_func_start InitCameraUpdateCallback -@ u8 InitCameraUpdateCallback(u8 followedObjectId) -InitCameraUpdateCallback: @ 808A134 - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - ldr r4, =gUnknown_03005DD0 - ldr r1, [r4, 0x4] - cmp r1, 0 - beq _0808A150 - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - ldr r1, =gSprites - adds r0, r1 - bl DestroySprite -_0808A150: - adds r0, r5, 0 - bl AddCameraObject - lsls r0, 24 - lsrs r0, 24 - str r0, [r4, 0x4] - ldr r0, =CameraUpdateCallback - str r0, [r4] - movs r0, 0 - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end InitCameraUpdateCallback - - thumb_func_start CameraUpdate -@ void CameraUpdate() -CameraUpdate: @ 808A174 - push {r4-r7,lr} - mov r7, r8 - push {r7} - ldr r6, =gUnknown_03005DD0 - ldr r1, [r6] - cmp r1, 0 - beq _0808A188 - adds r0, r6, 0 - bl _call_via_r1 -_0808A188: - ldr r7, [r6, 0x8] - ldr r0, [r6, 0xC] - mov r8, r0 - movs r4, 0 - movs r5, 0 - ldr r1, [r6, 0x10] - ldr r0, [r6, 0x14] - cmp r1, 0 - bne _0808A1A6 - cmp r7, 0 - beq _0808A1A6 - subs r4, 0x1 - cmp r7, 0 - ble _0808A1A6 - movs r4, 0x1 -_0808A1A6: - cmp r0, 0 - bne _0808A1BA - mov r2, r8 - cmp r2, 0 - beq _0808A1BA - movs r5, 0x1 - negs r5, r5 - cmp r2, 0 - ble _0808A1BA - movs r5, 0x1 -_0808A1BA: - cmp r1, 0 - beq _0808A1CC - cmn r1, r7 - bne _0808A1CC - movs r4, 0x1 - negs r4, r4 - cmp r7, 0 - ble _0808A1CC - movs r4, 0x1 -_0808A1CC: - cmp r0, 0 - beq _0808A1E0 - mov r3, r8 - cmn r0, r3 - bne _0808A1E0 - movs r4, 0x1 - negs r4, r4 - cmp r3, 0 - ble _0808A1E0 - movs r4, 0x1 -_0808A1E0: - ldr r2, =gUnknown_03005DD0 - ldr r0, [r2, 0x10] - adds r1, r0, r7 - str r1, [r2, 0x10] - adds r0, r1, 0 - cmp r1, 0 - bge _0808A1F0 - adds r0, 0xF -_0808A1F0: - asrs r0, 4 - lsls r0, 4 - subs r0, r1, r0 - str r0, [r2, 0x10] - ldr r0, [r2, 0x14] - mov r3, r8 - adds r1, r0, r3 - str r1, [r2, 0x14] - adds r0, r1, 0 - cmp r1, 0 - bge _0808A208 - adds r0, 0xF -_0808A208: - asrs r0, 4 - lsls r0, 4 - subs r0, r1, r0 - str r0, [r2, 0x14] - cmp r4, 0 - bne _0808A218 - cmp r5, 0 - beq _0808A24E -_0808A218: - adds r0, r4, 0 - adds r1, r5, 0 - bl CameraMove - adds r0, r4, 0 - adds r1, r5, 0 - bl UpdateFieldObjectsForCameraUpdate - adds r0, r4, 0 - adds r1, r5, 0 - bl RotatingGatePuzzleCameraUpdate - bl ResetBerryTreeSparkleFlags - ldr r6, =gUnknown_03000E20 - lsls r4, 1 - lsls r5, 1 - adds r0, r6, 0 - adds r1, r4, 0 - adds r2, r5, 0 - bl tilemap_move_something - adds r0, r6, 0 - adds r1, r4, 0 - adds r2, r5, 0 - bl RedrawMapSlicesForCameraUpdate -_0808A24E: - ldr r0, =gUnknown_03000E20 - adds r1, r7, 0 - mov r2, r8 - bl coords8_add - ldr r1, =gUnknown_03005DEC - ldrh r0, [r1] - subs r0, r7 - strh r0, [r1] - ldr r1, =gUnknown_03005DE8 - ldrh r0, [r1] - mov r2, r8 - subs r0, r2 - strh r0, [r1] - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end CameraUpdate - - thumb_func_start sub_808A284 -sub_808A284: @ 808A284 - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - bl CameraMove - lsls r0, r4, 16 - asrs r0, 16 - lsls r1, r5, 16 - asrs r1, 16 - bl UpdateFieldObjectsForCameraUpdate - bl DrawWholeMapView - ldr r1, =gUnknown_03005DEC - lsls r4, 4 - ldrh r0, [r1] - subs r0, r4 - strh r0, [r1] - ldr r1, =gUnknown_03005DE8 - lsls r5, 4 - ldrh r0, [r1] - subs r0, r5 - strh r0, [r1] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_808A284 - - thumb_func_start SetCameraPanningCallback -@ void SetCameraPanningCallback(void ( *callback)()) -SetCameraPanningCallback: @ 808A2C0 - ldr r1, =gUnknown_03000E30 - str r0, [r1] - bx lr - .pool - thumb_func_end SetCameraPanningCallback - - thumb_func_start SetCameraPanning -@ void SetCameraPanning(s16 x, s16 y) -SetCameraPanning: @ 808A2CC - ldr r2, =gUnknown_03000E28 - strh r0, [r2] - ldr r0, =gUnknown_03000E2A - lsls r1, 16 - asrs r1, 16 - adds r1, 0x20 - strh r1, [r0] - bx lr - .pool - thumb_func_end SetCameraPanning - - thumb_func_start InstallCameraPanAheadCallback -@ void InstallCameraPanAheadCallback() -InstallCameraPanAheadCallback: @ 808A2E4 - ldr r1, =gUnknown_03000E30 - ldr r0, =CameraPanningCB_PanAhead - str r0, [r1] - ldr r1, =gUnknown_03000E2C - movs r0, 0 - strb r0, [r1] - ldr r1, =gUnknown_03000E28 - movs r0, 0 - strh r0, [r1] - ldr r1, =gUnknown_03000E2A - movs r0, 0x20 - strh r0, [r1] - bx lr - .pool - thumb_func_end InstallCameraPanAheadCallback - - thumb_func_start UpdateCameraPanning -@ void UpdateCameraPanning() -UpdateCameraPanning: @ 808A314 - push {lr} - ldr r0, =gUnknown_03000E30 - ldr r0, [r0] - cmp r0, 0 - beq _0808A322 - bl _call_via_r0 -_0808A322: - ldr r2, =gSpriteCoordOffsetX - ldr r0, =gUnknown_03005DEC - ldr r1, =gUnknown_03000E28 - ldrh r0, [r0] - ldrh r1, [r1] - subs r0, r1 - strh r0, [r2] - ldr r2, =gSpriteCoordOffsetY - ldr r0, =gUnknown_03005DE8 - ldr r1, =gUnknown_03000E2A - ldrh r0, [r0] - ldrh r1, [r1] - subs r0, r1 - subs r0, 0x8 - strh r0, [r2] - pop {r0} - bx r0 - .pool - thumb_func_end UpdateCameraPanning - - thumb_func_start CameraPanningCB_PanAhead -@ void CameraPanningCB_PanAhead() -CameraPanningCB_PanAhead: @ 808A360 - push {lr} - ldr r0, =gUnknown_02037348 - ldrb r0, [r0] - cmp r0, 0 - bne _0808A374 - bl InstallCameraPanAheadCallback - b _0808A3FC - .pool -_0808A374: - ldr r0, =gPlayerAvatar - ldrb r0, [r0, 0x3] - cmp r0, 0x1 - bne _0808A394 - ldr r0, =gUnknown_03000E2C - ldrb r1, [r0] - movs r2, 0x1 - eors r1, r2 - strb r1, [r0] - cmp r1, 0 - beq _0808A3FC - b _0808A39A - .pool -_0808A394: - ldr r1, =gUnknown_03000E2C - movs r0, 0 - strb r0, [r1] -_0808A39A: - bl player_get_direction_upper_nybble - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - bne _0808A3C4 - ldr r2, =gUnknown_03000E2A - ldrh r3, [r2] - movs r0, 0 - ldrsh r1, [r2, r0] - movs r0, 0x8 - negs r0, r0 - cmp r1, r0 - ble _0808A3FC - subs r0, r3, 0x2 - b _0808A3FA - .pool -_0808A3C4: - cmp r0, 0x1 - bne _0808A3E0 - ldr r1, =gUnknown_03000E2A - ldrh r2, [r1] - movs r3, 0 - ldrsh r0, [r1, r3] - cmp r0, 0x47 - bgt _0808A3FC - adds r0, r2, 0x2 - strh r0, [r1] - b _0808A3FC - .pool -_0808A3E0: - ldr r2, =gUnknown_03000E2A - ldrh r0, [r2] - movs r3, 0 - ldrsh r1, [r2, r3] - cmp r1, 0x1F - bgt _0808A3F4 - adds r0, 0x2 - b _0808A3FA - .pool -_0808A3F4: - cmp r1, 0x20 - ble _0808A3FC - subs r0, 0x2 -_0808A3FA: - strh r0, [r2] -_0808A3FC: - pop {r0} - bx r0 - thumb_func_end CameraPanningCB_PanAhead - - .align 2, 0 @ Don't pad with nop. diff --git a/include/bike.h b/include/bike.h index e625ad438..46b668169 100644 --- a/include/bike.h +++ b/include/bike.h @@ -63,6 +63,10 @@ enum ACRO_TRANS_WHEELIE_LOWERING_MOVING, }; +// Exported RAM declarations +extern bool8 gUnusedBikeCameraAheadPanback; + +// Exported ROM declarations void MovePlayerOnBike(u8 direction, u16 newKeys, u16 heldKeys); void Bike_TryAcroBikeHistoryUpdate(u16 newKeys, u16 heldKeys); bool8 RS_IsRunningDisallowed(u8 tile); diff --git a/include/field_camera.h b/include/field_camera.h index 6ff8ce006..fcc19ce9a 100644 --- a/include/field_camera.h +++ b/include/field_camera.h @@ -6,22 +6,19 @@ struct CameraObject { void (*callback)(struct CameraObject *); - u32 unk4; + u32 spriteId; s32 unk8; s32 unkC; s32 x; s32 y; }; -extern struct CameraObject gUnknown_03005DD0; - // Exported RAM declarations - +extern struct CameraObject gUnknown_03005DD0; extern u16 gUnknown_03005DEC; extern u16 gUnknown_03005DE8; // Exported ROM declarations - void DrawWholeMapView(void); void CurrentMapDrawMetatileAt(int x, int y); void sub_8089C08(s16 *a0, s16 *a1); diff --git a/include/field_map_obj.h b/include/field_map_obj.h index 8b7e296dd..8f34d4b93 100644 --- a/include/field_map_obj.h +++ b/include/field_map_obj.h @@ -91,6 +91,8 @@ void sub_808F23C(const struct MapObject *mapObject, u8 movementType); void sub_808F208(const struct MapObject *mapObject); void npc_coords_shift_still(struct MapObject *pObject); void FieldObjectMoveDestCoords(struct MapObject *pObject, u32 unk_19, s16 *pInt, s16 *pInt1); +u8 AddCameraObject(u8 linkedSpriteId); +void UpdateFieldObjectsForCameraUpdate(s16 x, s16 y); // Exported data declarations diff --git a/include/fieldmap.h b/include/fieldmap.h index 23654f536..3128e95ce 100644 --- a/include/fieldmap.h +++ b/include/fieldmap.h @@ -16,5 +16,7 @@ s32 GetMapBorderIdAt(s16, s16); bool32 CanCameraMoveInDirection(u8); u16 GetBehaviorByMetatileId(u16 metatileId); void sav1_camera_get_focus_coords(u16 *x, u16 *y); +u8 MapGridGetMetatileLayerTypeAt(s32 x, s32 y); +u8 CameraMove(s32 deltaX, s32 deltaY); #endif //GUARD_FIELDMAP_H diff --git a/include/overworld.h b/include/overworld.h index 7f0a1795f..cd0f4e60f 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -15,9 +15,15 @@ struct LinkPlayerMapObject u8 mode; }; +// Exported RAM declarations extern struct WarpData gUnknown_020322DC; extern struct LinkPlayerMapObject gLinkPlayerMapObjects[4]; +extern u16 *gBGTilemapBuffers1; +extern u16 *gBGTilemapBuffers2; +extern u16 *gBGTilemapBuffers3; + +// Exported ROM declarations extern const struct UCoords32 gUnknown_08339D64[]; void DoWhiteOut(void); diff --git a/include/rotating_gate.h b/include/rotating_gate.h new file mode 100644 index 000000000..50a838953 --- /dev/null +++ b/include/rotating_gate.h @@ -0,0 +1,8 @@ +#ifndef GUARD_ROTATING_GATE_H +#define GUARD_ROTATING_GATE_H + +void RotatingGatePuzzleCameraUpdate(s16, s16); +void RotatingGate_InitPuzzleAndGraphics(); +u32 CheckForRotatingGatePuzzleCollision(u8, s16, s16); + +#endif // GUARD_ROTATING_GATE_H diff --git a/ld_script.txt b/ld_script.txt index 66ba4e6c8..5591472e8 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -89,7 +89,7 @@ SECTIONS { src/overworld.o(.text); asm/fieldmap.o(.text); src/metatile_behavior.o(.text); - asm/field_camera.o(.text); + src/field_camera.o(.text); src/field_door.o(.text); asm/field_player_avatar.o(.text); src/field_map_obj.o(.text); diff --git a/src/bike.c b/src/bike.c index 64af7c711..782eceb8e 100644 --- a/src/bike.c +++ b/src/bike.c @@ -12,7 +12,6 @@ extern bool8 gBikeCyclingChallenge; extern u8 gBikeCollisions; -extern bool8 gUnknown_02037348; extern u8 sub_8093514(u8 direction); extern u8 sub_808B980(u8 direction); @@ -989,7 +988,7 @@ bool8 player_should_look_direction_be_enforced_upon_movement(void) void GetOnOffBike(u8 transitionFlags) { - gUnknown_02037348 = FALSE; + gUnusedBikeCameraAheadPanback = FALSE; if (gPlayerAvatar.flags & (PLAYER_AVATAR_FLAG_MACH_BIKE | PLAYER_AVATAR_FLAG_ACRO_BIKE)) { diff --git a/src/decoration.c b/src/decoration.c index a0855db69..f376c2115 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -1305,12 +1305,12 @@ void sub_8128060(u8 taskId) void ConfigureCameraObjectForPlacingDecoration(struct PlaceDecorationGraphicsDataBuffer *data, u8 decor) { - sDecor_CameraSpriteObjectIdx1 = gSprites[gUnknown_03005DD0.unk4].data[0]; - gUnknown_03005DD0.unk4 = gpu_pal_decompress_alloc_tag_and_upload(data, decor); - gSprites[gUnknown_03005DD0.unk4].oam.priority = 1; - gSprites[gUnknown_03005DD0.unk4].callback = sub_81292D0; - gSprites[gUnknown_03005DD0.unk4].pos1.x = gUnknown_085A7250[data->decoration->shape].x; - gSprites[gUnknown_03005DD0.unk4].pos1.y = gUnknown_085A7250[data->decoration->shape].y; + sDecor_CameraSpriteObjectIdx1 = gSprites[gUnknown_03005DD0.spriteId].data[0]; + gUnknown_03005DD0.spriteId = gpu_pal_decompress_alloc_tag_and_upload(data, decor); + gSprites[gUnknown_03005DD0.spriteId].oam.priority = 1; + gSprites[gUnknown_03005DD0.spriteId].callback = sub_81292D0; + gSprites[gUnknown_03005DD0.spriteId].pos1.x = gUnknown_085A7250[data->decoration->shape].x; + gSprites[gUnknown_03005DD0.spriteId].pos1.y = gUnknown_085A7250[data->decoration->shape].y; } void SetUpPlacingDecorationPlayerAvatar(u8 taskId, struct PlaceDecorationGraphicsDataBuffer *data) @@ -1332,7 +1332,7 @@ void SetUpPlacingDecorationPlayerAvatar(u8 taskId, struct PlaceDecorationGraphic } gSprites[sDecor_CameraSpriteObjectIdx2].oam.priority = 1; DestroySprite(&gSprites[sDecor_CameraSpriteObjectIdx1]); - sDecor_CameraSpriteObjectIdx1 = gUnknown_03005DD0.unk4; + sDecor_CameraSpriteObjectIdx1 = gUnknown_03005DD0.spriteId; } void sub_812826C(u8 taskId) @@ -2251,9 +2251,9 @@ bool8 sub_81299AC(u8 taskId) void SetUpPuttingAwayDecorationPlayerAvatar(void) { player_get_direction_lower_nybble(); - sDecor_CameraSpriteObjectIdx1 = gSprites[gUnknown_03005DD0.unk4].data[0]; + sDecor_CameraSpriteObjectIdx1 = gSprites[gUnknown_03005DD0.spriteId].data[0]; sub_812A39C(); - gUnknown_03005DD0.unk4 = CreateSprite(&gUnknown_085A7404, 0x78, 0x50, 0); + gUnknown_03005DD0.spriteId = CreateSprite(&gUnknown_085A7404, 0x78, 0x50, 0); if (gSaveBlock2Ptr->playerGender == MALE) { sDecor_CameraSpriteObjectIdx2 = AddPseudoFieldObject(0xC1, SpriteCallbackDummy, 0x88, 0x48, 0); @@ -2264,7 +2264,7 @@ void SetUpPuttingAwayDecorationPlayerAvatar(void) } gSprites[sDecor_CameraSpriteObjectIdx2].oam.priority = 1; DestroySprite(&gSprites[sDecor_CameraSpriteObjectIdx1]); - sDecor_CameraSpriteObjectIdx1 = gUnknown_03005DD0.unk4; + sDecor_CameraSpriteObjectIdx1 = gUnknown_03005DD0.spriteId; gSprites[sDecor_CameraSpriteObjectIdx1].oam.priority = 1; } diff --git a/src/field_camera.c b/src/field_camera.c index 17ced6aa5..f653e0bf1 100644 --- a/src/field_camera.c +++ b/src/field_camera.c @@ -1,9 +1,18 @@ - -// Includes #include "global.h" +#include "berry.h" +#include "bike.h" +#include "field_camera.h" +#include "field_player_avatar.h" +#include "fieldmap.h" +#include "field_map_obj.h" +#include "gpu_regs.h" +#include "menu.h" +#include "overworld.h" +#include "rotating_gate.h" +#include "sprite.h" +#include "text.h" // Static type declarations - struct FieldCameraUnknownStruct { u8 unk0; @@ -13,16 +22,474 @@ struct FieldCameraUnknownStruct bool8 unk4; }; -// Static RAM declarations +// static functions +static void RedrawMapSliceNorth(struct FieldCameraUnknownStruct *a, const struct MapData *mapData); +static void RedrawMapSliceSouth(struct FieldCameraUnknownStruct *a, const struct MapData *mapData); +static void RedrawMapSliceEast(struct FieldCameraUnknownStruct *a, const struct MapData *mapData); +static void RedrawMapSliceWest(struct FieldCameraUnknownStruct *a, const struct MapData *mapData); +static s32 MapPosToBgTilemapOffset(struct FieldCameraUnknownStruct *a, s32 x, s32 y); +static void DrawWholeMapViewInternal(int x, int y, const struct MapData *mapData); +static void DrawMetatileAt(const struct MapData *mapData, u16, int, int); +static void DrawMetatile(s32 a, u16 *b, u16 c); +static void CameraPanningCB_PanAhead(void); -IWRAM_DATA struct FieldCameraUnknownStruct gUnknown_03000E20; -IWRAM_DATA s16 gUnknown_03000E28; -IWRAM_DATA s16 gUnknown_03000E2A; -IWRAM_DATA u8 gUnknown_03000E2C; -IWRAM_DATA void (*gUnknown_03000E30)(void); +// IWRAM bss vars +static IWRAM_DATA struct FieldCameraUnknownStruct gUnknown_03000E20; +static IWRAM_DATA s16 gUnknown_03000E28; +static IWRAM_DATA s16 gUnknown_03000E2A; +static IWRAM_DATA u8 gUnknown_03000E2C; +static IWRAM_DATA void (*gUnknown_03000E30)(void); -// Static ROM declarations +// text +static void move_tilemap_camera_to_upper_left_corner_(struct FieldCameraUnknownStruct *a) +{ + a->unk2 = 0; + a->unk3 = 0; + a->unk0 = 0; + a->unk1 = 0; + a->unk4 = TRUE; +} -// .rodata +static void tilemap_move_something(struct FieldCameraUnknownStruct *a, u32 b, u32 c) +{ + a->unk2 += b; + a->unk2 %= 32; + a->unk3 += c; + a->unk3 %= 32; +} + +static void coords8_add(struct FieldCameraUnknownStruct *a, u32 b, u32 c) +{ + a->unk0 += b; + a->unk1 += c; +} + +void move_tilemap_camera_to_upper_left_corner(void) +{ + move_tilemap_camera_to_upper_left_corner_(&gUnknown_03000E20); +} + +void FieldUpdateBgTilemapScroll(void) +{ + u32 r4, r5; + r5 = gUnknown_03000E20.unk0 + gUnknown_03000E28; + r4 = gUnknown_03000E2A + gUnknown_03000E20.unk1 + 8; + + SetGpuReg(REG_OFFSET_BG1HOFS, r5); + SetGpuReg(REG_OFFSET_BG1VOFS, r4); + SetGpuReg(REG_OFFSET_BG2HOFS, r5); + SetGpuReg(REG_OFFSET_BG2VOFS, r4); + SetGpuReg(REG_OFFSET_BG3HOFS, r5); + SetGpuReg(REG_OFFSET_BG3VOFS, r4); +} + +void sub_8089C08(s16 *a, s16 *b) +{ + *a = gUnknown_03000E20.unk0 + gUnknown_03000E28; + *b = gUnknown_03000E20.unk1 + gUnknown_03000E2A + 8; +} + +void DrawWholeMapView(void) +{ + DrawWholeMapViewInternal(gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y, gMapHeader.mapData); + gUnknown_03000E20.unk4 = TRUE; +} + +static void DrawWholeMapViewInternal(int x, int y, const struct MapData *mapData) +{ + u8 i; + u8 j; + u32 r6; + u8 temp; + + for (i = 0; i < 32; i += 2) + { + temp = gUnknown_03000E20.unk3 + i; + if (temp >= 32) + temp -= 32; + r6 = temp * 32; + for (j = 0; j < 32; j += 2) + { + temp = gUnknown_03000E20.unk2 + j; + if (temp >= 32) + temp -= 32; + DrawMetatileAt(mapData, r6 + temp, x + j / 2, y + i / 2); + } + } +} + +static void RedrawMapSlicesForCameraUpdate(struct FieldCameraUnknownStruct *a, int x, int y) +{ + const struct MapData *mapData = gMapHeader.mapData; + + if (x > 0) + RedrawMapSliceWest(a, mapData); + if (x < 0) + RedrawMapSliceEast(a, mapData); + if (y > 0) + RedrawMapSliceNorth(a, mapData); + if (y < 0) + RedrawMapSliceSouth(a, mapData); + a->unk4 = TRUE; +} + +static void RedrawMapSliceNorth(struct FieldCameraUnknownStruct *a, const struct MapData *mapData) +{ + u8 i; + u8 temp; + u32 r7; + + temp = a->unk3 + 28; + if (temp >= 32) + temp -= 32; + r7 = temp * 32; + for (i = 0; i < 32; i += 2) + { + temp = a->unk2 + i; + if (temp >= 32) + temp -= 32; + DrawMetatileAt(mapData, r7 + temp, gSaveBlock1Ptr->pos.x + i / 2, gSaveBlock1Ptr->pos.y + 14); + } +} + +static void RedrawMapSliceSouth(struct FieldCameraUnknownStruct *a, const struct MapData *mapData) +{ + u8 i; + u8 temp; + u32 r7 = a->unk3 * 32; + + for (i = 0; i < 32; i += 2) + { + temp = a->unk2 + i; + if (temp >= 32) + temp -= 32; + DrawMetatileAt(mapData, r7 + temp, gSaveBlock1Ptr->pos.x + i / 2, gSaveBlock1Ptr->pos.y); + } +} + +static void RedrawMapSliceEast(struct FieldCameraUnknownStruct *a, const struct MapData *mapData) +{ + u8 i; + u8 temp; + u32 r6 = a->unk2; + + for (i = 0; i < 32; i += 2) + { + temp = a->unk3 + i; + if (temp >= 32) + temp -= 32; + DrawMetatileAt(mapData, temp * 32 + r6, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y + i / 2); + } +} + +static void RedrawMapSliceWest(struct FieldCameraUnknownStruct *a, const struct MapData *mapData) +{ + u8 i; + u8 temp; + u8 r5 = a->unk2 + 28; + + if (r5 >= 32) + r5 -= 32; + for (i = 0; i < 32; i += 2) + { + temp = a->unk3 + i; + if (temp >= 32) + temp -= 32; + DrawMetatileAt(mapData, temp * 32 + r5, gSaveBlock1Ptr->pos.x + 14, gSaveBlock1Ptr->pos.y + i / 2); + } +} + +void CurrentMapDrawMetatileAt(int a, int b) +{ + int offset = MapPosToBgTilemapOffset(&gUnknown_03000E20, a, b); + + if (offset >= 0) + { + DrawMetatileAt(gMapHeader.mapData, offset, a, b); + gUnknown_03000E20.unk4 = TRUE; + } +} + +void DrawDoorMetatileAt(int x, int y, u16 *arr) +{ + int offset = MapPosToBgTilemapOffset(&gUnknown_03000E20, x, y); + + if (offset >= 0) + { + DrawMetatile(1, arr, offset); + gUnknown_03000E20.unk4 = TRUE; + } +} + +static void DrawMetatileAt(const struct MapData *mapData, u16 b, int c, int d) +{ + u16 metatileId = MapGridGetMetatileIdAt(c, d); + u16 *metatiles; + + if (metatileId > 1024) + metatileId = 0; + if (metatileId < 512) + metatiles = mapData->primaryTileset->metatiles; + else + { + metatiles = mapData->secondaryTileset->metatiles; + metatileId -= 512; + } + DrawMetatile(MapGridGetMetatileLayerTypeAt(c, d), metatiles + metatileId * 8, b); +} + +static void DrawMetatile(s32 a, u16 *b, u16 c) +{ + switch (a) + { + case 2: + gBGTilemapBuffers3[c] = b[0]; + gBGTilemapBuffers3[c + 1] = b[1]; + gBGTilemapBuffers3[c + 0x20] = b[2]; + gBGTilemapBuffers3[c + 0x21] = b[3]; + + gBGTilemapBuffers1[c] = 0; + gBGTilemapBuffers1[c + 1] = 0; + gBGTilemapBuffers1[c + 0x20] = 0; + gBGTilemapBuffers1[c + 0x21] = 0; + + gBGTilemapBuffers2[c] = b[4]; + gBGTilemapBuffers2[c + 1] = b[5]; + gBGTilemapBuffers2[c + 0x20] = b[6]; + gBGTilemapBuffers2[c + 0x21] = b[7]; + break; + case 1: + gBGTilemapBuffers3[c] = b[0]; + gBGTilemapBuffers3[c + 1] = b[1]; + gBGTilemapBuffers3[c + 0x20] = b[2]; + gBGTilemapBuffers3[c + 0x21] = b[3]; + + gBGTilemapBuffers1[c] = b[4]; + gBGTilemapBuffers1[c + 1] = b[5]; + gBGTilemapBuffers1[c + 0x20] = b[6]; + gBGTilemapBuffers1[c + 0x21] = b[7]; + + gBGTilemapBuffers2[c] = 0; + gBGTilemapBuffers2[c + 1] = 0; + gBGTilemapBuffers2[c + 0x20] = 0; + gBGTilemapBuffers2[c + 0x21] = 0; + break; + case 0: + gBGTilemapBuffers3[c] = 0x3014; + gBGTilemapBuffers3[c + 1] = 0x3014; + gBGTilemapBuffers3[c + 0x20] = 0x3014; + gBGTilemapBuffers3[c + 0x21] = 0x3014; + + gBGTilemapBuffers1[c] = b[0]; + gBGTilemapBuffers1[c + 1] = b[1]; + gBGTilemapBuffers1[c + 0x20] = b[2]; + gBGTilemapBuffers1[c + 0x21] = b[3]; + + gBGTilemapBuffers2[c] = b[4]; + gBGTilemapBuffers2[c + 1] = b[5]; + gBGTilemapBuffers2[c + 0x20] = b[6]; + gBGTilemapBuffers2[c + 0x21] = b[7]; + break; + } + schedule_bg_copy_tilemap_to_vram(1); + schedule_bg_copy_tilemap_to_vram(2); + schedule_bg_copy_tilemap_to_vram(3); +} + +static s32 MapPosToBgTilemapOffset(struct FieldCameraUnknownStruct *a, s32 x, s32 y) +{ + x -= gSaveBlock1Ptr->pos.x; + x *= 2; + if (x >= 32 || x < 0) + return -1; + x = x + a->unk2; + if (x >= 32) + x -= 32; + + y = (y - gSaveBlock1Ptr->pos.y) * 2; + if (y >= 32 || y < 0) + return -1; + y = y + a->unk3; + if (y >= 32) + y -= 32; + + return y * 32 + x; +} + +static void CameraUpdateCallback(struct CameraObject *a) +{ + if (a->spriteId != 0) + { + a->unk8 = gSprites[a->spriteId].data[2]; + a->unkC = gSprites[a->spriteId].data[3]; + } +} + +void ResetCameraUpdateInfo(void) +{ + gUnknown_03005DD0.unk8 = 0; + gUnknown_03005DD0.unkC = 0; + gUnknown_03005DD0.x = 0; + gUnknown_03005DD0.y = 0; + gUnknown_03005DD0.spriteId = 0; + gUnknown_03005DD0.callback = NULL; +} + +u32 InitCameraUpdateCallback(u8 a) +{ + if (gUnknown_03005DD0.spriteId != 0) + DestroySprite(&gSprites[gUnknown_03005DD0.spriteId]); + gUnknown_03005DD0.spriteId = AddCameraObject(a); + gUnknown_03005DD0.callback = CameraUpdateCallback; + return 0; +} + +void CameraUpdate(void) +{ + int deltaX; + int deltaY; + int r0; + int r1; + int r7; + int r8; + + if (gUnknown_03005DD0.callback != NULL) + gUnknown_03005DD0.callback(&gUnknown_03005DD0); + r7 = gUnknown_03005DD0.unk8; + r8 = gUnknown_03005DD0.unkC; + deltaX = 0; + deltaY = 0; + r1 = gUnknown_03005DD0.x; + r0 = gUnknown_03005DD0.y; + + + if (r1 == 0 && r7 != 0) + { + if (r7 > 0) + deltaX = 1; + else + deltaX = -1; + } + if (r0 == 0 && r8 != 0) + { + if (r8 > 0) + deltaY = 1; + else + deltaY = -1; + } + if (r1 != 0 && r1 == -r7) + { + if (r7 > 0) + deltaX = 1; + else + deltaX = -1; + } + if (r0 != 0 && r0 == -r8) + { + if (r8 > 0) + deltaX = 1; + else + deltaX = -1; + } + + gUnknown_03005DD0.x += r7; + gUnknown_03005DD0.x = gUnknown_03005DD0.x - 16 * (gUnknown_03005DD0.x / 16); + gUnknown_03005DD0.y += r8; + gUnknown_03005DD0.y = gUnknown_03005DD0.y - 16 * (gUnknown_03005DD0.y / 16); + + if (deltaX != 0 || deltaY != 0) + { + CameraMove(deltaX, deltaY); + UpdateFieldObjectsForCameraUpdate(deltaX, deltaY); + RotatingGatePuzzleCameraUpdate(deltaX, deltaY); + ResetBerryTreeSparkleFlags(); + tilemap_move_something(&gUnknown_03000E20, deltaX * 2, deltaY * 2); + RedrawMapSlicesForCameraUpdate(&gUnknown_03000E20, deltaX * 2, deltaY * 2); + } + + coords8_add(&gUnknown_03000E20, r7, r8); + gUnknown_03005DEC -= r7; + gUnknown_03005DE8 -= r8; +} + +void camera_move_and_redraw(int a, int b) //unused +{ + CameraMove(a, b); + UpdateFieldObjectsForCameraUpdate(a, b); + DrawWholeMapView(); + gUnknown_03005DEC -= a * 16; + gUnknown_03005DE8 -= b * 16; +} + +void SetCameraPanningCallback(void (*a)(void)) +{ + gUnknown_03000E30 = a; +} + +void SetCameraPanning(s16 a, s16 b) +{ + gUnknown_03000E28 = a; + gUnknown_03000E2A = b + 32; +} + +void InstallCameraPanAheadCallback(void) +{ + gUnknown_03000E30 = CameraPanningCB_PanAhead; + gUnknown_03000E2C = 0; + gUnknown_03000E28 = 0; + gUnknown_03000E2A = 32; +} + +void UpdateCameraPanning(void) +{ + if (gUnknown_03000E30 != NULL) + gUnknown_03000E30(); + //Update sprite offset of overworld objects + gSpriteCoordOffsetX = gUnknown_03005DEC - gUnknown_03000E28; + gSpriteCoordOffsetY = gUnknown_03005DE8 - gUnknown_03000E2A - 8; +} + +static void CameraPanningCB_PanAhead(void) +{ + u8 var; + + if (gUnusedBikeCameraAheadPanback == FALSE) + { + InstallCameraPanAheadCallback(); + } + else + { + // this code is never reached. + if (gPlayerAvatar.tileTransitionState == T_TILE_TRANSITION) + { + gUnknown_03000E2C ^= 1; + if (gUnknown_03000E2C == 0) + return; + } + else + { + gUnknown_03000E2C = 0; + } + + var = player_get_direction_upper_nybble(); + if (var == 2) + { + if (gUnknown_03000E2A > -8) + gUnknown_03000E2A -= 2; + } + else if (var == 1) + { + if (gUnknown_03000E2A < 72) + gUnknown_03000E2A += 2; + } + else if (gUnknown_03000E2A < 32) + { + gUnknown_03000E2A += 2; + } + else if (gUnknown_03000E2A > 32) + { + gUnknown_03000E2A -= 2; + } + } +} -// .text diff --git a/src/overworld.c b/src/overworld.c index 920f6f8f1..532615f27 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -89,9 +89,6 @@ extern const u16 gUnknown_82EC7C4[]; extern u16 gSaveFileStatus; extern u16 gUnknown_03005DA8; -extern u8 *gUnknown_03005DA0; -extern u8 *gUnknown_03005D9C; -extern u8 *gUnknown_03005DA4; extern bool8 (*gUnknown_03005DB0)(void); extern u8 gUnknown_03005DB4; extern u8 gFieldLinkPlayerCount; @@ -1422,12 +1419,12 @@ static void overworld_bg_setup(void) SetBgAttribute(1, BG_CTRL_ATTR_PALETTEMODE, 1); SetBgAttribute(2, BG_CTRL_ATTR_PALETTEMODE, 1); SetBgAttribute(3, BG_CTRL_ATTR_PALETTEMODE, 1); - gUnknown_03005DA0 = AllocZeroed(0x800); - gUnknown_03005D9C = AllocZeroed(0x800); - gUnknown_03005DA4 = AllocZeroed(0x800); - SetBgTilemapBuffer(1, gUnknown_03005DA0); - SetBgTilemapBuffer(2, gUnknown_03005D9C); - SetBgTilemapBuffer(3, gUnknown_03005DA4); + gBGTilemapBuffers2 = AllocZeroed(0x800); + gBGTilemapBuffers1 = AllocZeroed(0x800); + gBGTilemapBuffers3 = AllocZeroed(0x800); + SetBgTilemapBuffer(1, gBGTilemapBuffers2); + SetBgTilemapBuffer(2, gBGTilemapBuffers1); + SetBgTilemapBuffer(3, gBGTilemapBuffers3); sub_81971D0(); } @@ -1435,12 +1432,12 @@ void overworld_free_bg_tilemaps(void) { sub_81BE72C(); sub_81971F4(); - if (gUnknown_03005DA4 != NULL) - FREE_AND_SET_NULL(gUnknown_03005DA4); - if (gUnknown_03005D9C != NULL) - FREE_AND_SET_NULL(gUnknown_03005D9C); - if (gUnknown_03005DA0 != NULL) - FREE_AND_SET_NULL(gUnknown_03005DA0); + if (gBGTilemapBuffers3 != NULL) + FREE_AND_SET_NULL(gBGTilemapBuffers3); + if (gBGTilemapBuffers1 != NULL) + FREE_AND_SET_NULL(gBGTilemapBuffers1); + if (gBGTilemapBuffers2 != NULL) + FREE_AND_SET_NULL(gBGTilemapBuffers2); } static void ResetSafariZoneFlag_(void) diff --git a/src/rotating_gate.c b/src/rotating_gate.c index f68fe60ba..ac03508bf 100644 --- a/src/rotating_gate.c +++ b/src/rotating_gate.c @@ -17,10 +17,12 @@ #define GATE_ROT_ACW(arm, longArm) GATE_ROT(ROTATE_ANTICLOCKWISE, arm, longArm) #define GATE_ROT_NONE 255 +// static functions static void SpriteCallback_RotatingGate(struct Sprite *sprite); static u8 RotatingGate_CreateGate(u8 gateId, s16 deltaX, s16 deltaY); static void RotatingGate_HideGatesOutsideViewport(struct Sprite *sprite); +// enums enum { /* @@ -178,6 +180,7 @@ enum PUZZLE_ROUTE110_TRICK_HOUSE_PUZZLE6, }; +// structure struct RotatingGatePuzzle { s16 x; @@ -192,6 +195,7 @@ struct Coords8 s8 deltaY; }; +// .rodata // Fortree static const struct RotatingGatePuzzle sRotatingGate_FortreePuzzleConfig[] = { @@ -614,10 +618,12 @@ static const u8 sRotatingGate_ArmLayout[][4 * 2] = }, }; +// ewram 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; +// text static s32 GetCurrentMapRotatingGatePuzzleType(void) { if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(FORTREE_CITY_GYM) && diff --git a/sym_common.txt b/sym_common.txt index 6f6a8da32..b0548a84c 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -30,13 +30,13 @@ gPokemonStoragePtr: @ 3005D94 gInGameOpponentsNo: @ 3005D98 .space 0x4 -gUnknown_03005D9C: @ 3005D9C +gBGTilemapBuffers1: @ 3005D9C .space 0x4 -gUnknown_03005DA0: @ 3005DA0 +gBGTilemapBuffers2: @ 3005DA0 .space 0x4 -gUnknown_03005DA4: @ 3005DA4 +gBGTilemapBuffers3: @ 3005DA4 .space 0x4 gUnknown_03005DA8: @ 3005DA8 diff --git a/sym_ewram.txt b/sym_ewram.txt index 52bf32709..9bf04d201 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -222,7 +222,7 @@ gCamera: @ 2037334 gUnknown_02037340: @ 2037340 .space 0x8 -gUnknown_02037348: @ 2037348 +gUnusedBikeCameraAheadPanback: @ 2037348 .space 0x4 gUnknown_0203734C: @ 203734C