diff --git a/asm/bg.s b/asm/bg.s deleted file mode 100644 index 4526f8116..000000000 --- a/asm/bg.s +++ /dev/null @@ -1,3365 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start ResetBgs -@ void ResetBgs() -ResetBgs: @ 80012F0 - push {lr} - bl ResetBgControlStructs - ldr r1, =gUnknown_030008E0 - movs r0, 0 - strh r0, [r1, 0x10] - bl SetTextModeAndHideBgs - pop {r0} - bx r0 - .pool - thumb_func_end ResetBgs - - thumb_func_start SetBgModeInternal -@ void SetBgModeInternal(u8 bgMode) -SetBgModeInternal: @ 8001308 - lsls r0, 24 - lsrs r0, 24 - ldr r3, =gUnknown_030008E0 - ldrh r2, [r3, 0x10] - ldr r1, =0x0000fff8 - ands r1, r2 - orrs r1, r0 - strh r1, [r3, 0x10] - bx lr - .pool - thumb_func_end SetBgModeInternal - - thumb_func_start GetBgMode -@ u8 GetBgMode() -GetBgMode: @ 8001324 - ldr r0, =gUnknown_030008E0 - ldrb r1, [r0, 0x10] - movs r0, 0x7 - ands r0, r1 - bx lr - .pool - thumb_func_end GetBgMode - - thumb_func_start ResetBgControlStructs -@ void ResetBgControlStructs() -ResetBgControlStructs: @ 8001334 - push {lr} - ldr r2, =gUnknown_030008E0 - ldr r0, =gZeroedBgControlStruct - ldr r0, [r0] - adds r1, r2, 0 - adds r1, 0xC -_08001340: - str r0, [r1] - subs r1, 0x4 - cmp r1, r2 - bge _08001340 - pop {r0} - bx r0 - .pool - thumb_func_end ResetBgControlStructs - - thumb_func_start Unused_ResetBgControlStruct -@ void Unused_ResetBgControlStruct(u8 bg) -Unused_ResetBgControlStruct: @ 8001354 - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl IsInvalidBg - lsls r0, 24 - cmp r0, 0 - bne _08001372 - ldr r1, =gUnknown_030008E0 - lsls r0, r4, 2 - adds r0, r1 - ldr r1, =gZeroedBgControlStruct - ldr r1, [r1] - str r1, [r0] -_08001372: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end Unused_ResetBgControlStruct - - thumb_func_start SetBgControlAttributes -@ void SetBgControlAttributes(u8 bg, u8 tilesBaseBlock, u8 tileMapBaseBlock, u8 screenSize, u8 paletteMode, u8 priority, u8 mosaic, u8 wraparound) -SetBgControlAttributes: @ 8001380 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - ldr r4, [sp, 0x30] - ldr r5, [sp, 0x34] - ldr r6, [sp, 0x38] - mov r12, r6 - ldr r6, [sp, 0x3C] - mov r8, r6 - lsls r0, 24 - lsrs r7, r0, 24 - str r7, [sp] - lsls r1, 24 - lsrs r1, 24 - mov r10, r1 - lsls r2, 24 - lsrs r6, r2, 24 - lsls r3, 24 - lsrs r3, 24 - mov r9, r3 - lsls r4, 24 - lsrs r4, 24 - str r4, [sp, 0x4] - lsls r5, 24 - lsrs r5, 24 - mov r0, r12 - lsls r0, 24 - lsrs r4, r0, 24 - mov r1, r8 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0xC] - adds r0, r7, 0 - bl IsInvalidBg - lsls r0, 24 - lsrs r0, 24 - mov r12, r0 - cmp r0, 0 - bne _08001498 - ldr r2, =gUnknown_030008E0 - mov r8, r2 - mov r0, r10 - cmp r0, 0xFF - beq _080013F4 - lsls r2, r7, 2 - add r2, r8 - movs r1, 0x3 - ands r1, r0 - ldrb r3, [r2, 0x1] - movs r0, 0x4 - negs r0, r0 - ands r0, r3 - orrs r0, r1 - strb r0, [r2, 0x1] -_080013F4: - cmp r6, 0xFF - beq _0800140C - lsls r1, r7, 2 - add r1, r8 - movs r0, 0x1F - ands r6, r0 - lsls r3, r6, 2 - ldrb r2, [r1, 0x1] - subs r0, 0x9C - ands r0, r2 - orrs r0, r3 - strb r0, [r1, 0x1] -_0800140C: - mov r1, r9 - cmp r1, 0xFF - beq _08001428 - lsls r1, r7, 2 - add r1, r8 - movs r0, 0x3 - mov r2, r9 - ands r2, r0 - lsls r3, r2, 2 - ldrb r2, [r1] - subs r0, 0x10 - ands r0, r2 - orrs r0, r3 - strb r0, [r1] -_08001428: - ldr r6, [sp, 0x4] - cmp r6, 0xFF - beq _0800143E - lsls r1, r7, 2 - add r1, r8 - lsls r3, r6, 7 - ldrb r2, [r1, 0x1] - movs r0, 0x7F - ands r0, r2 - orrs r0, r3 - strb r0, [r1, 0x1] -_0800143E: - cmp r5, 0xFF - beq _08001456 - lsls r1, r7, 2 - add r1, r8 - movs r0, 0x3 - ands r5, r0 - lsls r3, r5, 4 - ldrb r2, [r1] - subs r0, 0x34 - ands r0, r2 - orrs r0, r3 - strb r0, [r1] -_08001456: - cmp r4, 0xFF - beq _0800146E - lsls r1, r7, 2 - add r1, r8 - movs r0, 0x1 - ands r4, r0 - lsls r3, r4, 6 - ldrb r2, [r1] - subs r0, 0x42 - ands r0, r2 - orrs r0, r3 - strb r0, [r1] -_0800146E: - ldr r0, [sp, 0xC] - cmp r0, 0xFF - beq _08001484 - lsls r1, r7, 2 - add r1, r8 - lsls r3, r0, 7 - ldrb r2, [r1] - movs r0, 0x7F - ands r0, r2 - orrs r0, r3 - strb r0, [r1] -_08001484: - ldr r1, [sp] - lsls r0, r1, 2 - add r0, r8 - mov r2, r12 - strb r2, [r0, 0x2] - strb r2, [r0, 0x3] - ldrb r1, [r0] - movs r2, 0x1 - orrs r1, r2 - strb r1, [r0] -_08001498: - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end SetBgControlAttributes - - thumb_func_start GetBgControlAttribute -@ u8 GetBgControlAttribute(u8 bg, u8 attributeId) -GetBgControlAttribute: @ 80014AC - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, 24 - lsrs r5, r1, 24 - adds r0, r4, 0 - bl IsInvalidBg - lsls r0, 24 - cmp r0, 0 - bne _08001558 - ldr r1, =gUnknown_030008E0 - lsls r2, r4, 2 - adds r0, r2, r1 - ldrb r0, [r0] - lsls r0, 31 - adds r3, r1, 0 - cmp r0, 0 - beq _08001558 - subs r0, r5, 0x1 - cmp r0, 0x7 - bhi _08001558 - lsls r0, 2 - ldr r1, =_080014EC - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_080014EC: - .4byte _0800150C - .4byte _08001516 - .4byte _08001520 - .4byte _0800152A - .4byte _08001534 - .4byte _0800153C - .4byte _08001546 - .4byte _08001550 -_0800150C: - adds r0, r2, r3 - ldrb r0, [r0] - lsls r0, 31 - lsrs r0, 31 - b _0800155A -_08001516: - adds r0, r2, r3 - ldrb r0, [r0, 0x1] - lsls r0, 30 - lsrs r0, 30 - b _0800155A -_08001520: - adds r0, r2, r3 - ldrb r0, [r0, 0x1] - lsls r0, 25 - lsrs r0, 27 - b _0800155A -_0800152A: - adds r0, r2, r3 - ldrb r0, [r0] - lsls r0, 28 - lsrs r0, 30 - b _0800155A -_08001534: - adds r0, r2, r3 - ldrb r0, [r0, 0x1] - lsrs r0, 7 - b _0800155A -_0800153C: - adds r0, r2, r3 - ldrb r0, [r0] - lsls r0, 26 - lsrs r0, 30 - b _0800155A -_08001546: - adds r0, r2, r3 - ldrb r0, [r0] - lsls r0, 25 - lsrs r0, 31 - b _0800155A -_08001550: - adds r0, r2, r3 - ldrb r0, [r0] - lsrs r0, 7 - b _0800155A -_08001558: - movs r0, 0xFF -_0800155A: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end GetBgControlAttribute - - thumb_func_start LoadBgVram -@ u8 LoadBgVram(u8, void *src, u16 size, u16 destOffset, u8 mode) -LoadBgVram: @ 8001560 - push {r4-r7,lr} - mov r7, r8 - push {r7} - mov r8, r1 - ldr r1, [sp, 0x18] - lsls r0, 24 - lsrs r4, r0, 24 - lsls r2, 16 - lsrs r7, r2, 16 - lsls r3, 16 - lsrs r6, r3, 16 - lsls r1, 24 - lsrs r5, r1, 24 - adds r0, r4, 0 - bl IsInvalidBg - lsls r0, 24 - cmp r0, 0 - bne _080015D8 - ldr r1, =gUnknown_030008E0 - lsls r0, r4, 2 - adds r1, r0, r1 - ldrb r0, [r1] - lsls r0, 31 - cmp r0, 0 - beq _080015D8 - cmp r5, 0x1 - beq _080015A4 - cmp r5, 0x2 - beq _080015AC - movs r2, 0xFF - b _080015DC - .pool -_080015A4: - ldrb r0, [r1, 0x1] - lsls r0, 30 - lsrs r0, 16 - b _080015B4 -_080015AC: - ldrb r0, [r1, 0x1] - lsls r0, 25 - lsrs r0, 27 - lsls r0, 11 -_080015B4: - adds r0, r6, r0 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0xC0 - lsls r1, 19 - adds r1, r0, r1 - mov r0, r8 - adds r2, r7, 0 - movs r3, 0 - bl RequestDma3Copy - lsls r0, 24 - lsrs r2, r0, 24 - asrs r0, 24 - movs r1, 0x1 - negs r1, r1 - cmp r0, r1 - bne _080015DC -_080015D8: - movs r0, 0xFF - b _080015DE -_080015DC: - adds r0, r2, 0 -_080015DE: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end LoadBgVram - - thumb_func_start ShowBgInternal -@ void ShowBgInternal(u8 bg) -ShowBgInternal: @ 80015E8 - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl IsInvalidBg - lsls r0, 24 - cmp r0, 0 - bne _08001656 - ldr r5, =gUnknown_030008E0 - lsls r0, r4, 2 - adds r2, r0, r5 - ldrb r3, [r2] - lsls r0, r3, 31 - cmp r0, 0 - beq _08001656 - lsls r1, r3, 26 - lsrs r1, 30 - ldrb r2, [r2, 0x1] - lsls r0, r2, 30 - lsrs r0, 28 - orrs r1, r0 - movs r0, 0x40 - ands r0, r3 - orrs r1, r0 - lsrs r0, r2, 7 - lsls r0, 7 - orrs r1, r0 - lsls r2, 25 - lsrs r2, 27 - lsls r2, 8 - orrs r1, r2 - lsrs r0, r3, 7 - lsls r0, 13 - orrs r1, r0 - lsls r0, r3, 28 - lsrs r0, 30 - lsls r0, 14 - orrs r1, r0 - lsls r0, r4, 25 - movs r2, 0x80 - lsls r2, 20 - adds r0, r2 - lsrs r0, 24 - bl SetGpuReg - adds r1, r4, 0 - adds r1, 0x8 - movs r0, 0x1 - lsls r0, r1 - ldrh r1, [r5, 0x10] - orrs r0, r1 - ldr r1, =0x00000f07 - ands r0, r1 - strh r0, [r5, 0x10] -_08001656: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end ShowBgInternal - - thumb_func_start HideBgInternal -@ void HideBgInternal(u8 bg) -HideBgInternal: @ 8001664 - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl IsInvalidBg - lsls r0, 24 - cmp r0, 0 - bne _0800168A - ldr r2, =gUnknown_030008E0 - adds r0, r4, 0 - adds r0, 0x8 - movs r1, 0x1 - lsls r1, r0 - ldrh r0, [r2, 0x10] - bics r0, r1 - ldr r1, =0x00000f07 - ands r0, r1 - strh r0, [r2, 0x10] -_0800168A: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end HideBgInternal - - thumb_func_start SyncBgVisibilityAndMode -@ void SyncBgVisibilityAndMode() -SyncBgVisibilityAndMode: @ 8001698 - push {lr} - movs r0, 0 - bl GetGpuReg - ldr r1, =0x0000f0f8 - ands r1, r0 - ldr r0, =gUnknown_030008E0 - ldrh r0, [r0, 0x10] - orrs r1, r0 - movs r0, 0 - bl SetGpuReg - pop {r0} - bx r0 - .pool - thumb_func_end SyncBgVisibilityAndMode - - thumb_func_start SetTextModeAndHideBgs -@ void SetTextModeAndHideBgs() -SetTextModeAndHideBgs: @ 80016BC - push {lr} - movs r0, 0 - bl GetGpuReg - ldr r1, =0x0000f0f8 - ands r1, r0 - movs r0, 0 - bl SetGpuReg - pop {r0} - bx r0 - .pool - thumb_func_end SetTextModeAndHideBgs - - thumb_func_start SetBgAffineInternal -@ void SetBgAffineInternal(u8 bg, u16 srcCenterX, u16 srcCenterY, u16 dispCenterX, u16 dispCenterY, u16 scaleX, u16 scaleY, u16 rotationAngle) -SetBgAffineInternal: @ 80016D8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x24 - mov r12, r1 - mov r8, r2 - ldr r1, [sp, 0x3C] - ldr r2, [sp, 0x40] - ldr r4, [sp, 0x44] - ldr r5, [sp, 0x48] - lsls r0, 24 - lsrs r6, r0, 24 - lsls r3, 16 - lsrs r3, 16 - lsls r1, 16 - lsrs r7, r1, 16 - lsls r2, 16 - lsrs r2, 16 - lsls r4, 16 - lsrs r4, 16 - lsls r5, 16 - lsrs r5, 16 - ldr r0, =gUnknown_030008E0 - ldrh r0, [r0, 0x10] - movs r1, 0x7 - ands r1, r0 - cmp r1, 0x1 - beq _08001720 - cmp r1, 0x1 - ble _08001796 - cmp r1, 0x2 - beq _08001726 - b _08001796 - .pool -_08001720: - cmp r6, 0x2 - bne _08001796 - b _08001730 -_08001726: - subs r0, r6, 0x2 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bhi _08001796 -_08001730: - mov r0, r12 - str r0, [sp] - mov r0, r8 - str r0, [sp, 0x4] - mov r0, sp - strh r3, [r0, 0x8] - strh r7, [r0, 0xA] - strh r2, [r0, 0xC] - strh r4, [r0, 0xE] - strh r5, [r0, 0x10] - add r4, sp, 0x14 - adds r1, r4, 0 - movs r2, 0x1 - bl BgAffineSet - ldrh r1, [r4] - movs r0, 0x20 - bl SetGpuReg - ldrh r1, [r4, 0x2] - movs r0, 0x22 - bl SetGpuReg - ldrh r1, [r4, 0x4] - movs r0, 0x24 - bl SetGpuReg - ldrh r1, [r4, 0x6] - movs r0, 0x26 - bl SetGpuReg - ldrh r1, [r4] - movs r0, 0x20 - bl SetGpuReg - ldrh r1, [r4, 0x8] - movs r0, 0x28 - bl SetGpuReg - ldrh r1, [r4, 0xA] - movs r0, 0x2A - bl SetGpuReg - ldrh r1, [r4, 0xC] - movs r0, 0x2C - bl SetGpuReg - ldrh r1, [r4, 0xE] - movs r0, 0x2E - bl SetGpuReg -_08001796: - add sp, 0x24 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end SetBgAffineInternal - - thumb_func_start IsInvalidBg -@ bool8 IsInvalidBg(u8 bg) -IsInvalidBg: @ 80017A4 - push {lr} - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - bhi _080017B2 - movs r0, 0 - b _080017B4 -_080017B2: - movs r0, 0x1 -_080017B4: - pop {r1} - bx r1 - thumb_func_end IsInvalidBg - - thumb_func_start DummiedOutFireRedLeafGreenTileAllocFunc -@ int DummiedOutFireRedLeafGreenTileAllocFunc() -DummiedOutFireRedLeafGreenTileAllocFunc: @ 80017B8 - movs r0, 0 - bx lr - thumb_func_end DummiedOutFireRedLeafGreenTileAllocFunc - - thumb_func_start ResetBgsAndClearDma3BusyFlags -@ void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable) -ResetBgsAndClearDma3BusyFlags: @ 80017BC - push {r4,lr} - adds r4, r0, 0 - bl ResetBgs - ldr r1, =gUnknown_03000938 - movs r2, 0 - adds r0, r1, 0 - adds r0, 0xC -_080017CC: - str r2, [r0] - subs r0, 0x4 - cmp r0, r1 - bge _080017CC - ldr r0, =gUnneededFireRedVariable - str r4, [r0] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end ResetBgsAndClearDma3BusyFlags - - thumb_func_start InitBgsFromTemplates -@ void InitBgsFromTemplates(u8 bgMode, struct BgTemplate *templates, u8 numTemplates) -InitBgsFromTemplates: @ 80017E8 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - adds r5, r1, 0 - lsls r0, 24 - lsrs r0, 24 - lsls r2, 24 - lsrs r4, r2, 24 - bl SetBgModeInternal - bl ResetBgControlStructs - cmp r4, 0 - beq _08001894 - movs r7, 0 - ldr r0, =gUnknown_030008F8 - mov r9, r0 - movs r2, 0xC - add r2, r9 - mov r10, r2 - adds r6, r5, 0 - mov r8, r4 -_0800181A: - ldr r4, [r6] - lsls r0, r4, 30 - lsrs r5, r0, 30 - cmp r5, 0x3 - bhi _08001886 - lsls r1, r4, 28 - lsrs r1, 30 - lsls r2, r4, 23 - lsrs r2, 27 - lsls r3, r4, 21 - lsrs r3, 30 - lsls r0, r4, 20 - lsrs r0, 31 - str r0, [sp] - lsls r0, r4, 18 - lsrs r0, 30 - str r0, [sp, 0x4] - str r7, [sp, 0x8] - str r7, [sp, 0xC] - adds r0, r5, 0 - bl SetBgControlAttributes - lsls r4, r5, 4 - mov r5, r9 - adds r3, r4, r5 - ldr r2, [r6] - lsls r2, 8 - lsrs r2, 22 - ldrh r0, [r3] - ldr r5, =0xfffffc00 - adds r1, r5, 0 - ands r0, r1 - orrs r0, r2 - strh r0, [r3] - ldrb r0, [r3, 0x1] - movs r2, 0x3D - negs r2, r2 - adds r1, r2, 0 - ands r0, r1 - strb r0, [r3, 0x1] - ldr r0, [r3] - ldr r1, =0x00003fff - ands r0, r1 - str r0, [r3] - mov r0, r9 - adds r0, 0x4 - adds r0, r4, r0 - str r7, [r0] - mov r0, r9 - adds r0, 0x8 - adds r0, r4, r0 - str r7, [r0] - add r4, r10 - str r7, [r4] -_08001886: - adds r6, 0x4 - movs r5, 0x1 - negs r5, r5 - add r8, r5 - mov r0, r8 - cmp r0, 0 - bne _0800181A -_08001894: - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end InitBgsFromTemplates - - thumb_func_start InitBgFromTemplate -@ void InitBgFromTemplate(struct BgTemplate *templates) -InitBgFromTemplate: @ 80018B0 - push {r4-r7,lr} - sub sp, 0x10 - adds r7, r0, 0 - ldr r4, [r7] - lsls r0, r4, 30 - lsrs r5, r0, 30 - cmp r5, 0x3 - bhi _08001920 - lsls r1, r4, 28 - lsrs r1, 30 - lsls r2, r4, 23 - lsrs r2, 27 - lsls r3, r4, 21 - lsrs r3, 30 - lsls r0, r4, 20 - lsrs r0, 31 - str r0, [sp] - lsls r0, r4, 18 - lsrs r0, 30 - str r0, [sp, 0x4] - movs r6, 0 - str r6, [sp, 0x8] - str r6, [sp, 0xC] - adds r0, r5, 0 - bl SetBgControlAttributes - ldr r4, =gUnknown_030008F8 - lsls r5, 4 - adds r3, r5, r4 - ldr r1, [r7] - lsls r1, 8 - lsrs r1, 22 - ldrh r2, [r3] - ldr r0, =0xfffffc00 - ands r0, r2 - orrs r0, r1 - strh r0, [r3] - ldrb r1, [r3, 0x1] - movs r0, 0x3D - negs r0, r0 - ands r0, r1 - strb r0, [r3, 0x1] - ldr r0, [r3] - ldr r1, =0x00003fff - ands r0, r1 - str r0, [r3] - adds r0, r4, 0x4 - adds r0, r5, r0 - str r6, [r0] - adds r0, r4, 0 - adds r0, 0x8 - adds r0, r5, r0 - str r6, [r0] - adds r4, 0xC - adds r5, r4 - str r6, [r5] -_08001920: - add sp, 0x10 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end InitBgFromTemplate - - thumb_func_start SetBgMode -@ void SetBgMode(u8 bgMode) -SetBgMode: @ 8001934 - push {lr} - lsls r0, 24 - lsrs r0, 24 - bl SetBgModeInternal - pop {r0} - bx r0 - thumb_func_end SetBgMode - - thumb_func_start LoadBgTiles -@ u8 LoadBgTiles(u8 bg, void *src, u16 size, u16 destOffset) -LoadBgTiles: @ 8001944 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x4 - adds r7, r1, 0 - lsls r0, 24 - lsrs r5, r0, 24 - lsls r2, 16 - lsrs r2, 16 - mov r8, r2 - lsls r3, 16 - lsrs r4, r3, 16 - adds r0, r5, 0 - movs r1, 0x5 - bl GetBgControlAttribute - lsls r0, 16 - cmp r0, 0 - bne _08001980 - ldr r1, =gUnknown_030008F8 - lsls r0, r5, 4 - adds r0, r1 - ldrh r0, [r0] - lsls r0, 22 - lsrs r0, 22 - adds r0, r4 - lsls r0, 21 - b _08001990 - .pool -_08001980: - ldr r1, =gUnknown_030008F8 - lsls r0, r5, 4 - adds r0, r1 - ldrh r0, [r0] - lsls r0, 22 - lsrs r0, 22 - adds r0, r4 - lsls r0, 22 -_08001990: - lsrs r4, r0, 16 - movs r6, 0x1 - str r6, [sp] - adds r0, r5, 0 - adds r1, r7, 0 - mov r2, r8 - adds r3, r4, 0 - bl LoadBgVram - lsls r2, r0, 24 - lsrs r1, r2, 24 - adds r7, r1, 0 - cmp r1, 0xFF - bne _080019B8 - ldr r0, =0x0000ffff - b _080019E6 - .pool -_080019B8: - ldr r0, =gUnknown_03000938 - lsrs r2, 29 - lsls r2, 2 - adds r2, r0 - movs r0, 0x1F - ands r0, r1 - adds r1, r6, 0 - lsls r1, r0 - ldr r0, [r2] - orrs r0, r1 - str r0, [r2] - ldr r0, =gUnneededFireRedVariable - ldr r0, [r0] - cmp r0, 0x1 - bne _080019E4 - lsrs r1, r4, 5 - mov r0, r8 - lsrs r2, r0, 5 - adds r0, r5, 0 - movs r3, 0x1 - bl DummiedOutFireRedLeafGreenTileAllocFunc -_080019E4: - adds r0, r7, 0 -_080019E6: - add sp, 0x4 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end LoadBgTiles - - thumb_func_start LoadBgTilemap -@ u8 LoadBgTilemap(u8 bg, void *src, u16 size, u16 destOffset) -LoadBgTilemap: @ 80019FC - push {r4,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r0, 24 - lsls r2, 16 - lsrs r2, 16 - lsls r3, 17 - lsrs r3, 16 - movs r4, 0x2 - str r4, [sp] - bl LoadBgVram - lsls r2, r0, 24 - lsrs r3, r2, 24 - cmp r3, 0xFF - beq _08001A3C - ldr r0, =gUnknown_03000938 - lsrs r2, 29 - lsls r2, 2 - adds r2, r0 - movs r0, 0x1F - ands r0, r3 - movs r1, 0x1 - lsls r1, r0 - ldr r0, [r2] - orrs r0, r1 - str r0, [r2] - adds r0, r3, 0 - b _08001A3E - .pool -_08001A3C: - ldr r0, =0x0000ffff -_08001A3E: - add sp, 0x4 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end LoadBgTilemap - - thumb_func_start Unused_LoadBgPalette -@ u8 Unused_LoadBgPalette(u8 bg, void *src, u16 size, u16 destOffset) -Unused_LoadBgPalette: @ 8001A4C - push {r4-r7,lr} - adds r7, r1, 0 - lsls r0, 24 - lsrs r4, r0, 24 - lsls r2, 16 - lsrs r6, r2, 16 - lsls r3, 16 - lsrs r5, r3, 16 - adds r0, r4, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _08001A98 - ldr r1, =gUnknown_030008F8 - lsls r0, r4, 4 - adds r0, r1 - ldrb r1, [r0, 0x1] - lsls r1, 26 - lsrs r1, 28 - lsls r1, 5 - lsls r0, r5, 1 - adds r1, r0 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0xA0 - lsls r0, 19 - adds r1, r0 - adds r0, r7, 0 - adds r2, r6, 0 - movs r3, 0 - bl RequestDma3Copy - lsls r3, r0, 24 - asrs r1, r3, 24 - movs r0, 0x1 - negs r0, r0 - cmp r1, r0 - bne _08001AA4 -_08001A98: - ldr r0, =0x0000ffff - b _08001AC8 - .pool -_08001AA4: - ldr r4, =gUnknown_03000938 - adds r0, r1, 0 - cmp r1, 0 - bge _08001AAE - adds r0, 0x1F -_08001AAE: - asrs r0, 5 - lsls r2, r0, 2 - adds r2, r4 - lsls r0, 5 - subs r0, r1, r0 - lsls r0, 24 - asrs r0, 24 - movs r1, 0x1 - lsls r1, r0 - ldr r0, [r2] - orrs r0, r1 - str r0, [r2] - lsrs r0, r3, 24 -_08001AC8: - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end Unused_LoadBgPalette - - thumb_func_start IsDma3ManagerBusyWithBgCopy -@ bool8 IsDma3ManagerBusyWithBgCopy() -IsDma3ManagerBusyWithBgCopy: @ 8001AD4 - push {r4-r7,lr} - movs r5, 0 - movs r7, 0x1 - negs r7, r7 -_08001ADC: - adds r0, r5, 0 - cmp r5, 0 - bge _08001AE4 - adds r0, 0x1F -_08001AE4: - asrs r0, 5 - lsls r2, r0, 24 - lsls r0, 5 - subs r0, r5, r0 - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gUnknown_03000938 - lsrs r2, 22 - adds r4, r2, r1 - movs r6, 0x1 - lsls r6, r0 - ldr r0, [r4] - ands r0, r6 - cmp r0, 0 - beq _08001B22 - lsls r0, r5, 16 - asrs r0, 16 - bl CheckForSpaceForDma3Request - lsls r0, 24 - asrs r0, 24 - cmp r0, r7 - bne _08001B1C - movs r0, 0x1 - b _08001B2A - .pool -_08001B1C: - ldr r0, [r4] - bics r0, r6 - str r0, [r4] -_08001B22: - adds r5, 0x1 - cmp r5, 0x7F - ble _08001ADC - movs r0, 0 -_08001B2A: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end IsDma3ManagerBusyWithBgCopy - - thumb_func_start ShowBg -@ void ShowBg(u8 bg) -ShowBg: @ 8001B30 - push {lr} - lsls r0, 24 - lsrs r0, 24 - bl ShowBgInternal - bl SyncBgVisibilityAndMode - pop {r0} - bx r0 - thumb_func_end ShowBg - - thumb_func_start HideBg -@ void HideBg(u8 bg) -HideBg: @ 8001B44 - push {lr} - lsls r0, 24 - lsrs r0, 24 - bl HideBgInternal - bl SyncBgVisibilityAndMode - pop {r0} - bx r0 - thumb_func_end HideBg - - thumb_func_start SetBgAttribute -@ void SetBgAttribute(u8 bg, u8 attributeId, u8 value) -SetBgAttribute: @ 8001B58 - push {r4,lr} - sub sp, 0x10 - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, 24 - lsrs r1, 24 - lsls r2, 24 - lsrs r3, r2, 24 - subs r0, r1, 0x1 - cmp r0, 0x6 - bhi _08001C12 - lsls r0, 2 - ldr r1, =_08001B7C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08001B7C: - .4byte _08001B98 - .4byte _08001BA8 - .4byte _08001BBA - .4byte _08001BD0 - .4byte _08001BE4 - .4byte _08001BFC - .4byte _08001BDA -_08001B98: - movs r0, 0xFF - str r0, [sp] - str r0, [sp, 0x4] - str r0, [sp, 0x8] - str r0, [sp, 0xC] - adds r0, r4, 0 - adds r1, r3, 0 - b _08001BF2 -_08001BA8: - movs r0, 0xFF - str r0, [sp] - str r0, [sp, 0x4] - str r0, [sp, 0x8] - str r0, [sp, 0xC] - adds r0, r4, 0 - movs r1, 0xFF - adds r2, r3, 0 - b _08001BF4 -_08001BBA: - movs r0, 0xFF - str r0, [sp] - str r0, [sp, 0x4] - str r0, [sp, 0x8] - str r0, [sp, 0xC] - adds r0, r4, 0 - movs r1, 0xFF - movs r2, 0xFF - bl SetBgControlAttributes - b _08001C12 -_08001BD0: - str r3, [sp] - movs r0, 0xFF - str r0, [sp, 0x4] - str r0, [sp, 0x8] - b _08001BEC -_08001BDA: - movs r0, 0xFF - str r0, [sp] - str r3, [sp, 0x4] - str r0, [sp, 0x8] - b _08001BEC -_08001BE4: - movs r0, 0xFF - str r0, [sp] - str r0, [sp, 0x4] - str r3, [sp, 0x8] -_08001BEC: - str r0, [sp, 0xC] - adds r0, r4, 0 - movs r1, 0xFF -_08001BF2: - movs r2, 0xFF -_08001BF4: - movs r3, 0xFF - bl SetBgControlAttributes - b _08001C12 -_08001BFC: - movs r0, 0xFF - str r0, [sp] - str r0, [sp, 0x4] - str r0, [sp, 0x8] - str r3, [sp, 0xC] - adds r0, r4, 0 - movs r1, 0xFF - movs r2, 0xFF - movs r3, 0xFF - bl SetBgControlAttributes -_08001C12: - add sp, 0x10 - pop {r4} - pop {r0} - bx r0 - thumb_func_end SetBgAttribute - - thumb_func_start GetBgAttribute -@ u8 GetBgAttribute(u8 bg, u8 attributeId) -GetBgAttribute: @ 8001C1C - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, 24 - lsrs r1, 24 - subs r0, r1, 0x1 - cmp r0, 0x9 - bhi _08001CF8 - lsls r0, 2 - ldr r1, =_08001C3C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08001C3C: - .4byte _08001C64 - .4byte _08001C6E - .4byte _08001C78 - .4byte _08001C82 - .4byte _08001C96 - .4byte _08001CA0 - .4byte _08001C8C - .4byte _08001CAA - .4byte _08001CD8 - .4byte _08001CE4 -_08001C64: - adds r0, r4, 0 - movs r1, 0x2 - bl GetBgControlAttribute - b _08001CDE -_08001C6E: - adds r0, r4, 0 - movs r1, 0x3 - bl GetBgControlAttribute - b _08001CDE -_08001C78: - adds r0, r4, 0 - movs r1, 0x4 - bl GetBgControlAttribute - b _08001CDE -_08001C82: - adds r0, r4, 0 - movs r1, 0x5 - bl GetBgControlAttribute - b _08001CDE -_08001C8C: - adds r0, r4, 0 - movs r1, 0x6 - bl GetBgControlAttribute - b _08001CDE -_08001C96: - adds r0, r4, 0 - movs r1, 0x7 - bl GetBgControlAttribute - b _08001CDE -_08001CA0: - adds r0, r4, 0 - movs r1, 0x8 - bl GetBgControlAttribute - b _08001CDE -_08001CAA: - adds r0, r4, 0 - bl GetBgType - cmp r0, 0 - beq _08001CBC - cmp r0, 0x1 - beq _08001CCA - movs r0, 0 - b _08001CFA -_08001CBC: - adds r0, r4, 0 - movs r1, 0 - bl GetBgMetricTextMode - lsls r0, 27 - lsrs r0, 16 - b _08001CFA -_08001CCA: - adds r0, r4, 0 - movs r1, 0 - bl GetBgMetricAffineMode - lsls r0, 24 - lsrs r0, 16 - b _08001CFA -_08001CD8: - adds r0, r4, 0 - bl GetBgType -_08001CDE: - lsls r0, 16 - lsrs r0, 16 - b _08001CFA -_08001CE4: - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r1, r0 - ldrh r0, [r1] - lsls r0, 22 - lsrs r0, 22 - b _08001CFA - .pool -_08001CF8: - ldr r0, =0x0000ffff -_08001CFA: - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end GetBgAttribute - - thumb_func_start ChangeBgX -@ u32 ChangeBgX(u8 bg, u32 value, u8 op) -ChangeBgX: @ 8001D04 - push {r4-r6,lr} - adds r6, r1, 0 - lsls r0, 24 - lsrs r4, r0, 24 - lsls r2, 24 - lsrs r5, r2, 24 - adds r0, r4, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _08001D28 - adds r0, r4, 0 - movs r1, 0x1 - bl GetBgControlAttribute - lsls r0, 16 - cmp r0, 0 - bne _08001D2E -_08001D28: - movs r0, 0x1 - negs r0, r0 - b _08001E34 -_08001D2E: - cmp r5, 0x1 - beq _08001D4C - cmp r5, 0x1 - ble _08001D3A - cmp r5, 0x2 - beq _08001D60 -_08001D3A: - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r0, 0x8 - adds r0, r1, r0 - str r6, [r0] - adds r5, r1, 0 - b _08001D70 - .pool -_08001D4C: - ldr r0, =gUnknown_030008F8 - lsls r2, r4, 4 - adds r0, 0x8 - adds r0, r2, r0 - ldr r1, [r0] - adds r1, r6 - b _08001D6C - .pool -_08001D60: - ldr r0, =gUnknown_030008F8 - lsls r2, r4, 4 - adds r0, 0x8 - adds r0, r2, r0 - ldr r1, [r0] - subs r1, r6 -_08001D6C: - str r1, [r0] - adds r5, r2, 0 -_08001D70: - bl GetBgMode - lsls r0, 24 - lsrs r0, 24 - cmp r4, 0x1 - beq _08001DAC - cmp r4, 0x1 - bgt _08001D8C - cmp r4, 0 - beq _08001D96 - b _08001E2C - .pool -_08001D8C: - cmp r4, 0x2 - beq _08001DC0 - cmp r4, 0x3 - beq _08001DF8 - b _08001E2C -_08001D96: - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x8] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x10 - bl SetGpuReg - b _08001E2C - .pool -_08001DAC: - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x18] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x14 - bl SetGpuReg - b _08001E2C - .pool -_08001DC0: - cmp r0, 0 - bne _08001DD8 - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x28] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x18 - bl SetGpuReg - b _08001E2C - .pool -_08001DD8: - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x28] - lsrs r1, r0, 16 - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x2A - bl SetGpuReg - movs r0, 0x28 - adds r1, r4, 0 - bl SetGpuReg - b _08001E2C - .pool -_08001DF8: - cmp r0, 0 - bne _08001E10 - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x38] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x1C - bl SetGpuReg - b _08001E2C - .pool -_08001E10: - cmp r0, 0x2 - bne _08001E2C - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x38] - lsrs r1, r0, 16 - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x3A - bl SetGpuReg - movs r0, 0x38 - adds r1, r4, 0 - bl SetGpuReg -_08001E2C: - ldr r0, =gUnknown_030008F8 - adds r0, 0x8 - adds r0, r5, r0 - ldr r0, [r0] -_08001E34: - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end ChangeBgX - - thumb_func_start GetBgX -@ u32 GetBgX(u8 bg) -GetBgX: @ 8001E40 - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - adds r4, r0, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _08001E70 - adds r0, r4, 0 - movs r1, 0x1 - bl GetBgControlAttribute - lsls r0, 16 - cmp r0, 0 - beq _08001E70 - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r0, 0x8 - adds r1, r0 - ldr r0, [r1] - b _08001E74 - .pool -_08001E70: - movs r0, 0x1 - negs r0, r0 -_08001E74: - pop {r4} - pop {r1} - bx r1 - thumb_func_end GetBgX - - thumb_func_start ChangeBgY -@ u32 ChangeBgY(u8 bg, u32 value, u8 op) -ChangeBgY: @ 8001E7C - push {r4-r6,lr} - adds r6, r1, 0 - lsls r0, 24 - lsrs r4, r0, 24 - lsls r2, 24 - lsrs r5, r2, 24 - adds r0, r4, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _08001EA0 - adds r0, r4, 0 - movs r1, 0x1 - bl GetBgControlAttribute - lsls r0, 16 - cmp r0, 0 - bne _08001EA6 -_08001EA0: - movs r0, 0x1 - negs r0, r0 - b _08001FAC -_08001EA6: - cmp r5, 0x1 - beq _08001EC4 - cmp r5, 0x1 - ble _08001EB2 - cmp r5, 0x2 - beq _08001ED8 -_08001EB2: - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r0, 0xC - adds r0, r1, r0 - str r6, [r0] - adds r5, r1, 0 - b _08001EE8 - .pool -_08001EC4: - ldr r0, =gUnknown_030008F8 - lsls r2, r4, 4 - adds r0, 0xC - adds r0, r2, r0 - ldr r1, [r0] - adds r1, r6 - b _08001EE4 - .pool -_08001ED8: - ldr r0, =gUnknown_030008F8 - lsls r2, r4, 4 - adds r0, 0xC - adds r0, r2, r0 - ldr r1, [r0] - subs r1, r6 -_08001EE4: - str r1, [r0] - adds r5, r2, 0 -_08001EE8: - bl GetBgMode - lsls r0, 24 - lsrs r0, 24 - cmp r4, 0x1 - beq _08001F24 - cmp r4, 0x1 - bgt _08001F04 - cmp r4, 0 - beq _08001F0E - b _08001FA4 - .pool -_08001F04: - cmp r4, 0x2 - beq _08001F38 - cmp r4, 0x3 - beq _08001F70 - b _08001FA4 -_08001F0E: - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0xC] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x12 - bl SetGpuReg - b _08001FA4 - .pool -_08001F24: - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x1C] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x16 - bl SetGpuReg - b _08001FA4 - .pool -_08001F38: - cmp r0, 0 - bne _08001F50 - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x2C] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x1A - bl SetGpuReg - b _08001FA4 - .pool -_08001F50: - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x2C] - lsrs r1, r0, 16 - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x2E - bl SetGpuReg - movs r0, 0x2C - adds r1, r4, 0 - bl SetGpuReg - b _08001FA4 - .pool -_08001F70: - cmp r0, 0 - bne _08001F88 - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x3C] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x1E - bl SetGpuReg - b _08001FA4 - .pool -_08001F88: - cmp r0, 0x2 - bne _08001FA4 - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x3C] - lsrs r1, r0, 16 - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x3E - bl SetGpuReg - movs r0, 0x3C - adds r1, r4, 0 - bl SetGpuReg -_08001FA4: - ldr r0, =gUnknown_030008F8 - adds r0, 0xC - adds r0, r5, r0 - ldr r0, [r0] -_08001FAC: - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end ChangeBgY - - thumb_func_start ChangeBgY_ScreenOff -@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op) -ChangeBgY_ScreenOff: @ 8001FB8 - push {r4-r6,lr} - adds r6, r1, 0 - lsls r0, 24 - lsrs r4, r0, 24 - lsls r2, 24 - lsrs r5, r2, 24 - adds r0, r4, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _08001FDC - adds r0, r4, 0 - movs r1, 0x1 - bl GetBgControlAttribute - lsls r0, 16 - cmp r0, 0 - bne _08001FE2 -_08001FDC: - movs r0, 0x1 - negs r0, r0 - b _080020E8 -_08001FE2: - cmp r5, 0x1 - beq _08002000 - cmp r5, 0x1 - ble _08001FEE - cmp r5, 0x2 - beq _08002014 -_08001FEE: - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r0, 0xC - adds r0, r1, r0 - str r6, [r0] - adds r5, r1, 0 - b _08002024 - .pool -_08002000: - ldr r0, =gUnknown_030008F8 - lsls r2, r4, 4 - adds r0, 0xC - adds r0, r2, r0 - ldr r1, [r0] - adds r1, r6 - b _08002020 - .pool -_08002014: - ldr r0, =gUnknown_030008F8 - lsls r2, r4, 4 - adds r0, 0xC - adds r0, r2, r0 - ldr r1, [r0] - subs r1, r6 -_08002020: - str r1, [r0] - adds r5, r2, 0 -_08002024: - bl GetBgMode - lsls r0, 24 - lsrs r0, 24 - cmp r4, 0x1 - beq _08002060 - cmp r4, 0x1 - bgt _08002040 - cmp r4, 0 - beq _0800204A - b _080020E0 - .pool -_08002040: - cmp r4, 0x2 - beq _08002074 - cmp r4, 0x3 - beq _080020AC - b _080020E0 -_0800204A: - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0xC] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x12 - bl SetGpuReg_ForcedBlank - b _080020E0 - .pool -_08002060: - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x1C] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x16 - bl SetGpuReg_ForcedBlank - b _080020E0 - .pool -_08002074: - cmp r0, 0 - bne _0800208C - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x2C] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x1A - bl SetGpuReg_ForcedBlank - b _080020E0 - .pool -_0800208C: - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x2C] - lsrs r1, r0, 16 - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x2E - bl SetGpuReg_ForcedBlank - movs r0, 0x2C - adds r1, r4, 0 - bl SetGpuReg_ForcedBlank - b _080020E0 - .pool -_080020AC: - cmp r0, 0 - bne _080020C4 - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x3C] - lsls r0, 8 - lsrs r1, r0, 16 - movs r0, 0x1E - bl SetGpuReg_ForcedBlank - b _080020E0 - .pool -_080020C4: - cmp r0, 0x2 - bne _080020E0 - ldr r0, =gUnknown_030008F8 - ldr r0, [r0, 0x3C] - lsrs r1, r0, 16 - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x3E - bl SetGpuReg_ForcedBlank - movs r0, 0x3C - adds r1, r4, 0 - bl SetGpuReg_ForcedBlank -_080020E0: - ldr r0, =gUnknown_030008F8 - adds r0, 0xC - adds r0, r5, r0 - ldr r0, [r0] -_080020E8: - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end ChangeBgY_ScreenOff - - thumb_func_start GetBgY -@ u32 GetBgY(u8 bg) -GetBgY: @ 80020F4 - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - adds r4, r0, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _08002124 - adds r0, r4, 0 - movs r1, 0x1 - bl GetBgControlAttribute - lsls r0, 16 - cmp r0, 0 - beq _08002124 - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r0, 0xC - adds r1, r0 - ldr r0, [r1] - b _08002128 - .pool -_08002124: - movs r0, 0x1 - negs r0, r0 -_08002128: - pop {r4} - pop {r1} - bx r1 - thumb_func_end GetBgY - - thumb_func_start SetBgAffine -@ void SetBgAffine(u8 bg, u16 srcCenterX, u16 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle) -SetBgAffine: @ 8002130 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x10 - ldr r4, [sp, 0x28] - ldr r5, [sp, 0x2C] - ldr r6, [sp, 0x30] - ldr r7, [sp, 0x34] - lsls r0, 24 - lsrs r0, 24 - lsls r7, 16 - lsrs r7, 16 - lsls r3, 16 - asrs r3, 16 - lsls r4, 16 - asrs r4, 16 - str r4, [sp] - lsls r5, 16 - asrs r5, 16 - str r5, [sp, 0x4] - lsls r6, 16 - asrs r6, 16 - str r6, [sp, 0x8] - str r7, [sp, 0xC] - bl SetBgAffineInternal - add sp, 0x10 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end SetBgAffine - - thumb_func_start Unused_AdjustBgMosaic -@ u8 Unused_AdjustBgMosaic(u8 a1, u8 a2) -Unused_AdjustBgMosaic: @ 8002170 - push {r4-r6,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, 24 - lsrs r6, r1, 24 - movs r0, 0x4C - bl GetGpuReg - lsls r0, 16 - lsrs r5, r0, 16 - movs r1, 0xF - movs r3, 0xF - ands r3, r5 - lsrs r2, r0, 20 - ands r2, r1 - movs r0, 0xFF - lsls r0, 8 - ands r5, r0 - cmp r6, 0x6 - bhi _080021C4 - lsls r0, r6, 2 - ldr r1, =_080021A8 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_080021A8: - .4byte _080021C4 - .4byte _080021CC - .4byte _080021D2 - .4byte _080021E4 - .4byte _080021FA - .4byte _08002200 - .4byte _08002212 -_080021C4: - movs r3, 0xF - ands r3, r4 - lsrs r2, r4, 4 - b _08002226 -_080021CC: - movs r3, 0xF - ands r3, r4 - b _08002226 -_080021D2: - lsls r0, r3, 16 - asrs r0, 16 - adds r0, r4 - cmp r0, 0xF - ble _080021E0 - movs r3, 0xF - b _08002226 -_080021E0: - adds r0, r3, r4 - b _080021F4 -_080021E4: - lsls r0, r3, 16 - asrs r0, 16 - subs r0, r4 - cmp r0, 0 - bge _080021F2 - movs r3, 0 - b _08002226 -_080021F2: - subs r0, r3, r4 -_080021F4: - lsls r0, 16 - lsrs r3, r0, 16 - b _08002226 -_080021FA: - movs r2, 0xF - ands r2, r4 - b _08002226 -_08002200: - lsls r0, r2, 16 - asrs r0, 16 - adds r0, r4 - cmp r0, 0xF - ble _0800220E - movs r2, 0xF - b _08002226 -_0800220E: - adds r0, r2, r4 - b _08002222 -_08002212: - lsls r0, r2, 16 - asrs r0, 16 - subs r0, r4 - cmp r0, 0 - bge _08002220 - movs r2, 0 - b _08002226 -_08002220: - subs r0, r2, r4 -_08002222: - lsls r0, 16 - lsrs r2, r0, 16 -_08002226: - lsls r0, r2, 16 - asrs r0, 12 - movs r1, 0xF0 - ands r0, r1 - orrs r5, r0 - lsls r0, r3, 16 - asrs r0, 16 - movs r1, 0xF - ands r0, r1 - orrs r5, r0 - lsls r0, r5, 16 - lsrs r5, r0, 16 - movs r0, 0x4C - adds r1, r5, 0 - bl SetGpuReg - lsls r0, r5, 24 - lsrs r0, 24 - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end Unused_AdjustBgMosaic - - thumb_func_start SetBgTilemapBuffer -@ void SetBgTilemapBuffer(u8 bg, void *tilemap) -SetBgTilemapBuffer: @ 8002250 - push {r4,r5,lr} - adds r5, r1, 0 - lsls r0, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _0800227A - adds r0, r4, 0 - movs r1, 0x1 - bl GetBgControlAttribute - lsls r0, 16 - cmp r0, 0 - beq _0800227A - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r0, 0x4 - adds r1, r0 - str r5, [r1] -_0800227A: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end SetBgTilemapBuffer - - thumb_func_start UnsetBgTilemapBuffer -@ void UnsetBgTilemapBuffer(u8 bg) -UnsetBgTilemapBuffer: @ 8002284 - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl IsInvalidBg_ - adds r5, r0, 0 - cmp r5, 0 - bne _080022AE - adds r0, r4, 0 - movs r1, 0x1 - bl GetBgControlAttribute - lsls r0, 16 - cmp r0, 0 - beq _080022AE - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r0, 0x4 - adds r1, r0 - str r5, [r1] -_080022AE: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end UnsetBgTilemapBuffer - - thumb_func_start GetBgTilemapBuffer -@ void *GetBgTilemapBuffer(u8 bg) -GetBgTilemapBuffer: @ 80022B8 - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - adds r4, r0, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _080022E8 - adds r0, r4, 0 - movs r1, 0x1 - bl GetBgControlAttribute - lsls r0, 16 - cmp r0, 0 - beq _080022E8 - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r0, 0x4 - adds r1, r0 - ldr r0, [r1] - b _080022EA - .pool -_080022E8: - movs r0, 0 -_080022EA: - pop {r4} - pop {r1} - bx r1 - thumb_func_end GetBgTilemapBuffer - - thumb_func_start CopyToBgTilemapBuffer -@ void CopyToBgTilemapBuffer(u8 bg, void *src, u16 mode, u16 destOffset) -CopyToBgTilemapBuffer: @ 80022F0 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - mov r10, r1 - lsls r0, 24 - lsrs r4, r0, 24 - mov r9, r4 - lsls r7, r2, 16 - lsrs r6, r7, 16 - lsls r3, 16 - lsrs r5, r3, 16 - mov r8, r5 - adds r0, r4, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _08002358 - adds r0, r4, 0 - bl IsTileMapOutsideWram - cmp r0, 0 - bne _08002358 - cmp r6, 0 - beq _08002340 - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r0, 0x4 - adds r1, r0 - lsls r0, r5, 1 - ldr r1, [r1] - adds r1, r0 - lsrs r2, r7, 17 - mov r0, r10 - bl CpuSet - b _08002358 - .pool -_08002340: - ldr r0, =gUnknown_030008F8 - mov r2, r9 - lsls r1, r2, 4 - adds r0, 0x4 - adds r1, r0 - mov r2, r8 - lsls r0, r2, 1 - ldr r1, [r1] - adds r1, r0 - mov r0, r10 - bl LZ77UnCompWram -_08002358: - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end CopyToBgTilemapBuffer - - thumb_func_start CopyBgTilemapBufferToVram -@ void CopyBgTilemapBufferToVram(u8 bg) -CopyBgTilemapBufferToVram: @ 800236C - push {r4,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _080023C8 - adds r0, r4, 0 - bl IsTileMapOutsideWram - cmp r0, 0 - bne _080023C8 - adds r0, r4, 0 - bl GetBgType - cmp r0, 0 - beq _0800239A - cmp r0, 0x1 - beq _080023A6 - movs r2, 0 - b _080023B2 -_0800239A: - adds r0, r4, 0 - movs r1, 0 - bl GetBgMetricTextMode - lsls r0, 27 - b _080023B0 -_080023A6: - adds r0, r4, 0 - movs r1, 0 - bl GetBgMetricAffineMode - lsls r0, 24 -_080023B0: - lsrs r2, r0, 16 -_080023B2: - ldr r0, =gUnknown_030008F8 - lsls r1, r4, 4 - adds r0, 0x4 - adds r1, r0 - ldr r1, [r1] - movs r0, 0x2 - str r0, [sp] - adds r0, r4, 0 - movs r3, 0 - bl LoadBgVram -_080023C8: - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end CopyBgTilemapBufferToVram - - thumb_func_start CopyToBgTilemapBufferRect -@ void CopyToBgTilemapBufferRect(u8 bg, void *src, u8 destX, u8 destY, u8 width, u8 height) -CopyToBgTilemapBufferRect: @ 80023D4 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - mov r8, r1 - ldr r1, [sp, 0x24] - ldr r4, [sp, 0x28] - lsls r0, 24 - lsrs r5, r0, 24 - lsls r2, 24 - lsrs r2, 24 - mov r10, r2 - lsls r3, 24 - lsrs r7, r3, 24 - lsls r1, 24 - lsrs r1, 24 - mov r9, r1 - lsls r4, 24 - lsrs r6, r4, 24 - adds r0, r5, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _080024C4 - adds r0, r5, 0 - bl IsTileMapOutsideWram - cmp r0, 0 - bne _080024C4 - adds r0, r5, 0 - bl GetBgType - cmp r0, 0 - beq _08002422 - cmp r0, 0x1 - beq _08002470 - b _080024C4 -_08002422: - mov r4, r8 - adds r3, r7, 0 - adds r0, r3, r6 - cmp r3, r0 - bge _080024C4 - mov r12, r0 - lsls r1, r5, 4 - ldr r0, =gUnknown_030008FC - adds r1, r0 - mov r8, r1 -_08002436: - mov r2, r10 - mov r1, r9 - adds r0, r2, r1 - adds r7, r3, 0x1 - cmp r2, r0 - bge _08002460 - mov r1, r8 - ldr r6, [r1] - lsls r5, r3, 5 - adds r3, r0, 0 -_0800244A: - adds r0, r5, r2 - lsls r0, 1 - adds r0, r6 - ldrh r1, [r4] - strh r1, [r0] - adds r4, 0x2 - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, r3 - blt _0800244A -_08002460: - lsls r0, r7, 16 - lsrs r3, r0, 16 - cmp r3, r12 - blt _08002436 - b _080024C4 - .pool -_08002470: - mov r4, r8 - adds r0, r5, 0 - movs r1, 0x1 - bl GetBgMetricAffineMode - lsls r0, 16 - lsrs r0, 16 - str r0, [sp] - adds r3, r7, 0 - adds r0, r3, r6 - cmp r3, r0 - bge _080024C4 - mov r12, r0 - lsls r5, 4 - mov r8, r5 -_0800248E: - mov r2, r10 - mov r1, r9 - adds r0, r2, r1 - adds r7, r3, 0x1 - cmp r2, r0 - bge _080024BC - ldr r6, =gUnknown_030008FC - add r6, r8 - ldr r1, [sp] - adds r5, r3, 0 - muls r5, r1 - adds r3, r0, 0 -_080024A6: - ldr r1, [r6] - adds r0, r5, r2 - adds r1, r0 - ldrb r0, [r4] - strb r0, [r1] - adds r4, 0x1 - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, r3 - blt _080024A6 -_080024BC: - lsls r0, r7, 16 - lsrs r3, r0, 16 - cmp r3, r12 - blt _0800248E -_080024C4: - 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 CopyToBgTilemapBufferRect - - thumb_func_start CopyToBgTilemapBufferRect_ChangePalette -@ void CopyToBgTilemapBufferRect_ChangePalette(u8 bg, void *src, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette) -CopyToBgTilemapBufferRect_ChangePalette: @ 80024D8 - push {r4-r6,lr} - sub sp, 0x24 - ldr r4, [sp, 0x34] - ldr r5, [sp, 0x38] - ldr r6, [sp, 0x3C] - lsls r0, 24 - lsrs r0, 24 - lsls r2, 24 - lsrs r2, 24 - lsls r3, 24 - lsrs r3, 24 - lsls r4, 24 - lsrs r4, 24 - lsls r5, 24 - lsrs r5, 24 - lsls r6, 24 - lsrs r6, 24 - str r4, [sp] - str r5, [sp, 0x4] - str r2, [sp, 0x8] - str r3, [sp, 0xC] - str r4, [sp, 0x10] - str r5, [sp, 0x14] - str r6, [sp, 0x18] - movs r2, 0 - str r2, [sp, 0x1C] - str r2, [sp, 0x20] - movs r3, 0 - bl CopyRectToBgTilemapBufferRect - add sp, 0x24 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end CopyToBgTilemapBufferRect_ChangePalette - - thumb_func_start CopyRectToBgTilemapBufferRect -@ void CopyRectToBgTilemapBufferRect(u8 bg, void *src, u8 srcX, u8 srcY, u8 srcWidth, u8 srcHeight, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette1, u16 tileOffset, u16 palette2) -CopyRectToBgTilemapBufferRect: @ 800251C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x40 - str r1, [sp, 0x8] - ldr r1, [sp, 0x60] - ldr r4, [sp, 0x68] - ldr r5, [sp, 0x6C] - ldr r6, [sp, 0x70] - ldr r7, [sp, 0x74] - mov r8, r7 - ldr r7, [sp, 0x78] - mov r9, r7 - ldr r7, [sp, 0x7C] - mov r10, r7 - ldr r7, [sp, 0x80] - mov r12, r7 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x4] - lsls r2, 24 - lsrs r2, 24 - str r2, [sp, 0xC] - lsls r3, 24 - lsrs r3, 24 - str r3, [sp, 0x10] - lsls r1, 24 - lsrs r7, r1, 24 - lsls r4, 24 - lsrs r4, 24 - str r4, [sp, 0x14] - lsls r5, 24 - lsrs r5, 24 - lsls r6, 24 - lsrs r6, 24 - str r6, [sp, 0x18] - mov r0, r8 - lsls r0, 24 - lsrs r4, r0, 24 - mov r1, r9 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x1C] - mov r2, r10 - lsls r2, 16 - lsrs r2, 16 - str r2, [sp, 0x20] - mov r0, r12 - lsls r0, 16 - lsrs r0, 16 - str r0, [sp, 0x24] - ldr r0, [sp, 0x4] - bl IsInvalidBg_ - cmp r0, 0 - beq _08002592 - b _080026EE -_08002592: - ldr r0, [sp, 0x4] - bl IsTileMapOutsideWram - cmp r0, 0 - beq _0800259E - b _080026EE -_0800259E: - ldr r0, [sp, 0x4] - movs r1, 0x4 - bl GetBgControlAttribute - lsls r0, 16 - lsrs r0, 16 - str r0, [sp, 0x30] - ldr r0, [sp, 0x4] - movs r1, 0x1 - bl GetBgMetricTextMode - lsls r0, 21 - lsrs r0, 16 - str r0, [sp, 0x28] - ldr r0, [sp, 0x4] - movs r1, 0x2 - bl GetBgMetricTextMode - lsls r0, 21 - lsrs r0, 16 - str r0, [sp, 0x2C] - ldr r0, [sp, 0x4] - bl GetBgType - cmp r0, 0 - beq _080025D8 - cmp r0, 0x1 - beq _08002674 - b _080026EE -_080025D8: - ldr r1, [sp, 0x10] - adds r0, r1, 0 - muls r0, r7 - ldr r2, [sp, 0xC] - adds r0, r2 - lsls r0, 1 - ldr r1, [sp, 0x8] - adds r6, r1, r0 - adds r0, r5, r4 - cmp r5, r0 - blt _080025F0 - b _080026EE -_080025F0: - ldr r2, [sp, 0x18] - subs r2, r7, r2 - str r2, [sp, 0x34] - str r0, [sp, 0x38] -_080025F8: - ldr r4, [sp, 0x14] - ldr r7, [sp, 0x18] - adds r0, r4, r7 - adds r1, r5, 0x1 - str r1, [sp, 0x3C] - cmp r4, r0 - bge _0800265A - ldr r2, [sp, 0x4] - lsls r0, r2, 4 - ldr r1, =gUnknown_030008FC - adds r0, r1 - mov r10, r0 - ldr r7, [sp, 0x20] - lsls r7, 16 - mov r9, r7 - ldr r1, [sp, 0x24] - lsls r0, r1, 16 - asrs r0, 16 - mov r8, r0 -_0800261E: - ldr r2, [sp, 0x2C] - str r2, [sp] - adds r0, r4, 0 - adds r1, r5, 0 - ldr r2, [sp, 0x30] - ldr r3, [sp, 0x28] - bl GetTileMapIndexFromCoords - lsls r0, 16 - lsrs r0, 15 - mov r7, r10 - ldr r1, [r7] - adds r1, r0 - mov r0, r8 - str r0, [sp] - adds r0, r6, 0 - ldr r2, [sp, 0x1C] - mov r7, r9 - asrs r3, r7, 16 - bl CopyTileMapEntry - adds r6, 0x2 - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - ldr r1, [sp, 0x14] - ldr r2, [sp, 0x18] - adds r0, r1, r2 - cmp r4, r0 - blt _0800261E -_0800265A: - ldr r5, [sp, 0x34] - lsls r0, r5, 1 - adds r6, r0 - ldr r7, [sp, 0x3C] - lsls r0, r7, 16 - lsrs r5, r0, 16 - ldr r0, [sp, 0x38] - cmp r5, r0 - blt _080025F8 - b _080026EE - .pool -_08002674: - ldr r1, [sp, 0x10] - adds r0, r1, 0 - muls r0, r7 - ldr r2, [sp, 0xC] - adds r0, r2 - ldr r1, [sp, 0x8] - adds r6, r1, r0 - ldr r0, [sp, 0x4] - movs r1, 0x1 - bl GetBgMetricAffineMode - lsls r0, 16 - lsrs r0, 16 - mov r9, r0 - adds r0, r5, r4 - cmp r5, r0 - bge _080026EE - ldr r2, [sp, 0x18] - subs r2, r7, r2 - str r2, [sp, 0x34] - str r0, [sp, 0x38] - ldr r7, =gUnknown_030008FC - mov r10, r7 - ldr r0, [sp, 0x4] - lsls r0, 4 - mov r8, r0 -_080026A8: - ldr r4, [sp, 0x14] - ldr r1, [sp, 0x18] - adds r0, r4, r1 - adds r2, r5, 0x1 - str r2, [sp, 0x3C] - cmp r4, r0 - bge _080026DE - mov r3, r8 - add r3, r10 - mov r7, r9 - muls r7, r5 - mov r12, r7 - adds r2, r0, 0 -_080026C2: - ldr r1, [r3] - mov r5, r12 - adds r0, r5, r4 - adds r1, r0 - ldrb r0, [r6] - ldr r7, [sp, 0x20] - adds r0, r7 - strb r0, [r1] - adds r6, 0x1 - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, r2 - blt _080026C2 -_080026DE: - ldr r0, [sp, 0x34] - adds r6, r0 - ldr r1, [sp, 0x3C] - lsls r0, r1, 16 - lsrs r5, r0, 16 - ldr r2, [sp, 0x38] - cmp r5, r2 - blt _080026A8 -_080026EE: - add sp, 0x40 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end CopyRectToBgTilemapBufferRect - - thumb_func_start FillBgTilemapBufferRect_Palette0 -@ void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height) -FillBgTilemapBufferRect_Palette0: @ 8002704 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - ldr r4, [sp, 0x24] - ldr r5, [sp, 0x28] - lsls r0, 24 - lsrs r6, r0, 24 - lsls r1, 16 - lsrs r1, 16 - mov r8, r1 - lsls r2, 24 - lsrs r2, 24 - mov r10, r2 - lsls r3, 24 - lsrs r7, r3, 24 - lsls r4, 24 - lsrs r4, 24 - mov r9, r4 - lsls r5, 24 - lsrs r5, 24 - adds r0, r6, 0 - bl IsInvalidBg_ - cmp r0, 0 - bne _080027F0 - adds r0, r6, 0 - bl IsTileMapOutsideWram - cmp r0, 0 - bne _080027F0 - adds r0, r6, 0 - bl GetBgType - cmp r0, 0 - beq _08002756 - cmp r0, 0x1 - beq _080027A0 - b _080027F0 -_08002756: - adds r3, r7, 0 - adds r5, r3, r5 - cmp r3, r5 - bge _080027F0 - adds r7, r5, 0 - lsls r1, r6, 4 - ldr r0, =gUnknown_030008FC - adds r1, r0 - mov r12, r1 -_08002768: - mov r2, r10 - mov r1, r9 - adds r0, r2, r1 - adds r6, r3, 0x1 - cmp r2, r0 - bge _08002790 - mov r5, r12 - ldr r4, [r5] - lsls r3, 5 - adds r1, r0, 0 -_0800277C: - adds r0, r3, r2 - lsls r0, 1 - adds r0, r4 - mov r5, r8 - strh r5, [r0] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, r1 - blt _0800277C -_08002790: - lsls r0, r6, 16 - lsrs r3, r0, 16 - cmp r3, r7 - blt _08002768 - b _080027F0 - .pool -_080027A0: - adds r0, r6, 0 - movs r1, 0x1 - bl GetBgMetricAffineMode - lsls r0, 16 - lsrs r0, 16 - str r0, [sp] - adds r3, r7, 0 - adds r5, r3, r5 - cmp r3, r5 - bge _080027F0 - adds r7, r5, 0 - lsls r6, 4 - mov r12, r6 -_080027BC: - mov r2, r10 - mov r1, r9 - adds r0, r2, r1 - adds r6, r3, 0x1 - cmp r2, r0 - bge _080027E8 - ldr r5, =gUnknown_030008FC - add r5, r12 - ldr r1, [sp] - adds r4, r3, 0 - muls r4, r1 - adds r3, r0, 0 -_080027D4: - ldr r0, [r5] - adds r1, r4, r2 - adds r0, r1 - mov r1, r8 - strb r1, [r0] - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, r3 - blt _080027D4 -_080027E8: - lsls r0, r6, 16 - lsrs r3, r0, 16 - cmp r3, r7 - blt _080027BC -_080027F0: - 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 FillBgTilemapBufferRect_Palette0 - - thumb_func_start FillBgTilemapBufferRect -@ void FillBgTilemapBufferRect(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height, u8 palette) -FillBgTilemapBufferRect: @ 8002804 - push {r4-r6,lr} - sub sp, 0x10 - ldr r4, [sp, 0x20] - ldr r5, [sp, 0x24] - ldr r6, [sp, 0x28] - lsls r0, 24 - lsrs r0, 24 - lsls r1, 16 - lsrs r1, 16 - lsls r2, 24 - lsrs r2, 24 - lsls r3, 24 - lsrs r3, 24 - lsls r4, 24 - lsrs r4, 24 - lsls r5, 24 - lsrs r5, 24 - lsls r6, 24 - lsrs r6, 24 - str r4, [sp] - str r5, [sp, 0x4] - str r6, [sp, 0x8] - movs r4, 0 - str r4, [sp, 0xC] - bl WriteSequenceToBgTilemapBuffer - add sp, 0x10 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end FillBgTilemapBufferRect - - thumb_func_start WriteSequenceToBgTilemapBuffer -@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 width, u8 height, u8 paletteSlot, u16 tileNumDelta) -WriteSequenceToBgTilemapBuffer: @ 8002840 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x2C - ldr r4, [sp, 0x4C] - ldr r5, [sp, 0x50] - ldr r6, [sp, 0x54] - ldr r7, [sp, 0x58] - mov r8, r7 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - add r0, sp, 0x4 - strh r1, [r0] - lsls r2, 24 - lsrs r2, 24 - str r2, [sp, 0x8] - lsls r3, 24 - lsrs r7, r3, 24 - lsls r4, 24 - lsrs r4, 24 - mov r10, r4 - lsls r5, 24 - lsrs r4, r5, 24 - lsls r6, 24 - lsrs r6, 24 - str r6, [sp, 0xC] - mov r0, r8 - lsls r0, 16 - lsrs r0, 16 - str r0, [sp, 0x10] - mov r0, r9 - bl IsInvalidBg_ - cmp r0, 0 - beq _0800288E - b _080029D4 -_0800288E: - mov r0, r9 - bl IsTileMapOutsideWram - cmp r0, 0 - beq _0800289A - b _080029D4 -_0800289A: - mov r0, r9 - movs r1, 0x4 - bl GetBgControlAttribute - lsls r0, 16 - lsrs r0, 16 - str r0, [sp, 0x1C] - mov r0, r9 - movs r1, 0x1 - bl GetBgMetricTextMode - lsls r0, 21 - lsrs r0, 16 - str r0, [sp, 0x14] - mov r0, r9 - movs r1, 0x2 - bl GetBgMetricTextMode - lsls r0, 21 - lsrs r0, 16 - str r0, [sp, 0x18] - mov r0, r9 - bl GetBgType - cmp r0, 0 - beq _080028D4 - cmp r0, 0x1 - beq _0800295C - b _080029D4 -_080028D4: - adds r5, r7, 0 - adds r0, r5, r4 - cmp r5, r0 - bge _080029D4 - str r0, [sp, 0x24] - add r7, sp, 0x4 -_080028E0: - ldr r4, [sp, 0x8] - mov r1, r10 - adds r0, r4, r1 - adds r2, r5, 0x1 - mov r8, r2 - cmp r4, r0 - bge _08002944 - mov r3, r9 - lsls r1, r3, 4 - ldr r0, =gUnknown_030008FC - adds r6, r1, r0 -_080028F6: - ldr r0, [sp, 0x18] - str r0, [sp] - adds r0, r4, 0 - adds r1, r5, 0 - ldr r2, [sp, 0x1C] - ldr r3, [sp, 0x14] - bl GetTileMapIndexFromCoords - lsls r0, 16 - lsrs r0, 15 - ldr r1, [r6] - adds r1, r0 - movs r0, 0 - str r0, [sp] - add r0, sp, 0x4 - ldr r2, [sp, 0xC] - movs r3, 0 - bl CopyTileMapEntry - ldrh r0, [r7] - movs r2, 0xFC - lsls r2, 8 - adds r1, r2, 0 - adds r2, r0, 0 - ands r2, r1 - ldr r3, [sp, 0x10] - adds r0, r3 - ldr r3, =0x000003ff - adds r1, r3, 0 - ands r0, r1 - adds r2, r0 - strh r2, [r7] - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - ldr r0, [sp, 0x8] - add r0, r10 - cmp r4, r0 - blt _080028F6 -_08002944: - mov r1, r8 - lsls r0, r1, 16 - lsrs r5, r0, 16 - ldr r2, [sp, 0x24] - cmp r5, r2 - blt _080028E0 - b _080029D4 - .pool -_0800295C: - mov r0, r9 - movs r1, 0x1 - bl GetBgMetricAffineMode - lsls r0, 16 - lsrs r0, 16 - str r0, [sp, 0x20] - adds r5, r7, 0 - adds r0, r5, r4 - cmp r5, r0 - bge _080029D4 - str r0, [sp, 0x24] - mov r3, r9 - lsls r3, 4 - mov r12, r3 -_0800297A: - ldr r4, [sp, 0x8] - mov r7, r10 - adds r0, r4, r7 - adds r1, r5, 0x1 - mov r8, r1 - cmp r4, r0 - bge _080029C8 - ldr r2, =gUnknown_030008FC - add r2, r12 - str r2, [sp, 0x28] - ldr r7, [sp, 0x20] - adds r3, r5, 0 - muls r3, r7 - add r2, sp, 0x4 - movs r1, 0xFC - lsls r1, 8 - mov r9, r1 - ldr r7, =0x000003ff - adds r5, r7, 0 - adds r6, r0, 0 -_080029A2: - ldr r0, [sp, 0x28] - ldr r1, [r0] - adds r0, r3, r4 - adds r1, r0 - ldrh r0, [r2] - strb r0, [r1] - ldrh r0, [r2] - mov r1, r9 - ands r1, r0 - ldr r7, [sp, 0x10] - adds r0, r7 - ands r0, r5 - adds r1, r0 - strh r1, [r2] - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, r6 - blt _080029A2 -_080029C8: - mov r1, r8 - lsls r0, r1, 16 - lsrs r5, r0, 16 - ldr r2, [sp, 0x24] - cmp r5, r2 - blt _0800297A -_080029D4: - add sp, 0x2C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end WriteSequenceToBgTilemapBuffer - - thumb_func_start GetBgMetricTextMode -@ u16 GetBgMetricTextMode(u8 bg, u8 whichMetric) -GetBgMetricTextMode: @ 80029EC - push {r4,r5,lr} - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r4, r1, 24 - adds r5, r4, 0 - movs r1, 0x4 - bl GetBgControlAttribute - lsls r0, 24 - lsrs r0, 24 - cmp r4, 0x1 - beq _08002A2C - cmp r4, 0x1 - bgt _08002A10 - cmp r4, 0 - beq _08002A16 - b _08002A52 -_08002A10: - cmp r5, 0x2 - beq _08002A3E - b _08002A52 -_08002A16: - cmp r0, 0x2 - bgt _08002A24 - cmp r0, 0x1 - bge _08002A4E -_08002A1E: - cmp r0, 0 - beq _08002A46 - b _08002A52 -_08002A24: - cmp r0, 0x3 - bne _08002A52 - movs r0, 0x4 - b _08002A54 -_08002A2C: - cmp r0, 0x1 - beq _08002A4E - cmp r0, 0x1 - ble _08002A1E - cmp r0, 0x2 - beq _08002A46 - cmp r0, 0x3 - bne _08002A52 - b _08002A4E -_08002A3E: - cmp r0, 0 - blt _08002A52 - cmp r0, 0x1 - bgt _08002A4A -_08002A46: - movs r0, 0x1 - b _08002A54 -_08002A4A: - cmp r0, 0x3 - bgt _08002A52 -_08002A4E: - movs r0, 0x2 - b _08002A54 -_08002A52: - movs r0, 0 -_08002A54: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end GetBgMetricTextMode - - thumb_func_start GetBgMetricAffineMode -@ u16 GetBgMetricAffineMode(u8 bg, u8 whichMetric) -GetBgMetricAffineMode: @ 8002A5C - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r4, r1, 24 - movs r1, 0x4 - bl GetBgControlAttribute - lsls r0, 24 - lsrs r1, r0, 24 - adds r0, r1, 0 - cmp r4, 0 - beq _08002A84 - cmp r4, 0 - blt _08002AAC - cmp r4, 0x2 - bgt _08002AAC - movs r0, 0x10 - lsls r0, r1 - b _08002AAE -_08002A84: - cmp r1, 0x1 - beq _08002AA0 - cmp r1, 0x1 - bgt _08002A92 - cmp r1, 0 - beq _08002A9C - b _08002AAC -_08002A92: - cmp r0, 0x2 - beq _08002AA4 - cmp r0, 0x3 - beq _08002AA8 - b _08002AAC -_08002A9C: - movs r0, 0x1 - b _08002AAE -_08002AA0: - movs r0, 0x4 - b _08002AAE -_08002AA4: - movs r0, 0x10 - b _08002AAE -_08002AA8: - movs r0, 0x40 - b _08002AAE -_08002AAC: - movs r0, 0 -_08002AAE: - pop {r4} - pop {r1} - bx r1 - thumb_func_end GetBgMetricAffineMode - - thumb_func_start GetTileMapIndexFromCoords -@ u32 GetTileMapIndexFromCoords(u32 x, u32 y, u32 screenSize, u32 screenWidth, u32 screenHeight) -GetTileMapIndexFromCoords: @ 8002AB4 - push {r4,lr} - adds r4, r0, 0 - ldr r0, [sp, 0x8] - subs r3, 0x1 - ands r4, r3 - subs r0, 0x1 - ands r1, r0 - cmp r2, 0x1 - beq _08002AD8 - cmp r2, 0x1 - ble _08002AE0 - cmp r2, 0x2 - beq _08002AE0 - cmp r2, 0x3 - bne _08002AE0 - cmp r1, 0x1F - ble _08002AD8 - adds r1, 0x20 -_08002AD8: - cmp r4, 0x1F - ble _08002AE0 - subs r4, 0x20 - adds r1, 0x20 -_08002AE0: - lsls r0, r1, 5 - adds r0, r4 - pop {r4} - pop {r1} - bx r1 - thumb_func_end GetTileMapIndexFromCoords - - thumb_func_start CopyTileMapEntry -@ void CopyTileMapEntry(u16 *src, u16 *dest, s32 palette1, u16 tileOffset, u32 palette2) -CopyTileMapEntry: @ 8002AEC - push {r4-r6,lr} - adds r4, r0, 0 - adds r6, r1, 0 - ldr r5, [sp, 0x10] - cmp r2, 0x10 - beq _08002B14 - cmp r2, 0x10 - bgt _08002B34 - cmp r2, 0 - blt _08002B34 - ldrh r0, [r4] - adds r0, r3 - ldr r3, =0x00000fff - adds r1, r3, 0 - ands r0, r1 - adds r1, r2, r5 - lsls r1, 12 - b _08002B3A - .pool -_08002B14: - ldrh r1, [r6] - movs r0, 0xFC - lsls r0, 8 - ands r1, r0 - lsls r2, r5, 12 - adds r2, r1, r2 - ldrh r0, [r4] - adds r0, r3 - ldr r3, =0x000003ff - adds r1, r3, 0 - ands r0, r1 - orrs r0, r2 - b _08002B3C - .pool -_08002B34: - ldrh r0, [r4] - adds r0, r3 - lsls r1, r5, 12 -_08002B3A: - adds r0, r1 -_08002B3C: - lsls r0, 16 - lsrs r1, r0, 16 - strh r1, [r6] - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end CopyTileMapEntry - - thumb_func_start GetBgType -@ u16 GetBgType(u8 bg) -GetBgType: @ 8002B48 - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - adds r5, r4, 0 - bl GetBgMode - lsls r0, 24 - lsrs r0, 24 - cmp r4, 0x2 - beq _08002B76 - cmp r4, 0x2 - ble _08002B66 - cmp r4, 0x3 - beq _08002B86 - b _08002B8E -_08002B66: - cmp r5, 0 - blt _08002B8E - cmp r0, 0x1 - bgt _08002B8E - cmp r0, 0 - blt _08002B8E -_08002B72: - movs r0, 0 - b _08002B90 -_08002B76: - cmp r0, 0 - beq _08002B72 - cmp r0, 0 - blt _08002B8E - cmp r0, 0x2 - bgt _08002B8E -_08002B82: - movs r0, 0x1 - b _08002B90 -_08002B86: - cmp r0, 0 - beq _08002B72 - cmp r0, 0x2 - beq _08002B82 -_08002B8E: - ldr r0, =0x0000ffff -_08002B90: - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end GetBgType - - thumb_func_start IsInvalidBg_ -@ bool8 IsInvalidBg_(u8 bg) -IsInvalidBg_: @ 8002B9C - push {lr} - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - bhi _08002BAA - movs r0, 0 - b _08002BAC -_08002BAA: - movs r0, 0x1 -_08002BAC: - pop {r1} - bx r1 - thumb_func_end IsInvalidBg_ - - thumb_func_start IsTileMapOutsideWram -@ bool8 IsTileMapOutsideWram(u8 bg) -IsTileMapOutsideWram: @ 8002BB0 - push {lr} - lsls r0, 24 - ldr r1, =gUnknown_030008F8 - lsrs r0, 20 - adds r1, 0x4 - adds r0, r1 - ldr r1, [r0] - ldr r0, =0x03008000 - cmp r1, r0 - bhi _08002BD4 - cmp r1, 0 - beq _08002BD4 - movs r0, 0 - b _08002BD6 - .pool -_08002BD4: - movs r0, 0x1 -_08002BD6: - pop {r1} - bx r1 - thumb_func_end IsTileMapOutsideWram - - .align 2, 0 @ Don't pad with nop. diff --git a/common_syms/bg.txt b/common_syms/bg.txt new file mode 100644 index 000000000..2495d1646 --- /dev/null +++ b/common_syms/bg.txt @@ -0,0 +1 @@ +gUnneededFireRedVariable diff --git a/data/bg.s b/data/bg.s deleted file mode 100644 index 2881d4347..000000000 --- a/data/bg.s +++ /dev/null @@ -1,7 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - -gZeroedBgControlStruct:: @ 82E9580 - .4byte 0 diff --git a/include/gba/defines.h b/include/gba/defines.h index 0f7f06755..e67d64777 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -15,6 +15,11 @@ #define INTR_CHECK (*(u16 *)0x3007FF8) #define INTR_VECTOR (*(void **)0x3007FFC) +#define EWRAM_START 0x02000000 +#define EWRAM_END (EWRAM_START + 0x40000) +#define IWRAM_START 0x03000000 +#define IWRAM_END (IWRAM_START + 0x8000) + #define PLTT 0x5000000 #define PLTT_SIZE 0x400 @@ -29,8 +34,10 @@ #define BG_VRAM VRAM #define BG_VRAM_SIZE 0x10000 -#define BG_CHAR_ADDR(n) (BG_VRAM + (0x4000 * (n))) -#define BG_SCREEN_ADDR(n) (BG_VRAM + (0x800 * (n))) +#define BG_CHAR_SIZE 0x4000 +#define BG_SCREEN_SIZE 0x800 +#define BG_CHAR_ADDR(n) (BG_VRAM + (BG_CHAR_SIZE * (n))) +#define BG_SCREEN_ADDR(n) (BG_VRAM + (BG_SCREEN_SIZE * (n))) // text-mode BG #define OBJ_VRAM0 (VRAM + 0x10000) diff --git a/ld_script.txt b/ld_script.txt index 584a57c6f..d558dddff 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -45,7 +45,7 @@ SECTIONS { src/malloc.o(.text); src/dma3_manager.o(.text); src/gpu_regs.o(.text); - asm/bg.o(.text); + src/bg.o(.text); asm/blit.o(.text); src/window.o(.text); src/text.o(.text); @@ -286,7 +286,7 @@ SECTIONS { ALIGN(4) { src/main.o(.rodata); - data/bg.o(.rodata); + src/bg.o(.rodata); src/window.o(.rodata); src/text.o(.rodata); src/sprite.o(.rodata); diff --git a/src/bg.c b/src/bg.c new file mode 100644 index 000000000..8979eaecd --- /dev/null +++ b/src/bg.c @@ -0,0 +1,1642 @@ +#include "global.h" +#include "dma3.h" + +#define DISPCNT_ALL_BG_AND_MODE_BITS 0x0F07 + +enum { + BG_CTRL_ATTR_VISIBLE = 1, + BG_CTRL_ATTR_CHARBASEINDEX = 2, + BG_CTRL_ATTR_MAPBASEINDEX = 3, + BG_CTRL_ATTR_SCREENSIZE = 4, + BG_CTRL_ATTR_PALETTEMODE = 5, + BG_CTRL_ATTR_PRIORITY = 6, + BG_CTRL_ATTR_MOSAIC = 7, + BG_CTRL_ATTR_WRAPAROUND = 8, +}; + +struct BgControl { + struct BgConfig { + u16 visible:1; + u16 unknown_1:1; + u16 screenSize:2; + u16 priority:2; + u16 mosaic:1; + u16 wraparound:1; + + u16 charBaseIndex:2; + u16 mapBaseIndex:5; + u16 paletteMode:1; + + u8 unknown_2; + u8 unknown_3; + } configs[4]; + + u16 bgVisibilityAndMode; +}; + +struct BgTemplate { + u32 bg:2; + u32 charBaseIndex:2; + u32 mapBaseIndex:5; + u32 screenSize:2; + u32 paletteMode:1; + u32 priority:2; + u32 baseTile:10; +}; + +struct BgConfig2 { + u32 baseTile:10; + u32 basePalette:4; + u32 unk_3:18; + + void* tilemap; + u32 bg_x; + u32 bg_y; +}; + +static struct BgControl gGpuBgConfigs; +static struct BgConfig2 gGpuBgConfigs2[4]; +static u32 gDmaBusyBitfield[4]; + +u32 gUnneededFireRedVariable; + +static const struct BgConfig gZeroedBgControlStruct = { 0 }; + +extern void SetGpuReg(u8 regOffset, u16 value); +extern void SetGpuReg_ForcedBlank(u8 regOffset, u16 value); +extern u16 GetGpuReg(u8 regOffset); +extern int CheckForSpaceForDma3Request(s16 index); + +bool32 IsInvalidBg32(u8); +void ResetBgControlStructs(); +u16 GetBgMetricTextMode(u8, u8); +u32 GetBgMetricAffineMode(u8, u8); +u32 GetBgType(u8); +void SetTextModeAndHideBgs(); +bool8 IsInvalidBg(u8); +bool32 IsTileMapOutsideWram(u8); +void CopyRectToBgTilemapBufferRect(u8, void*, u8, u8, u8, u8, u8, u8, u8, u8, u8, u16, u16); +void CopyTileMapEntry(u16*, u16*, s32, u32, u32); +u32 GetTileMapIndexFromCoords(s32, s32, s32, u32, u32); +void WriteSequenceToBgTilemapBuffer(u8, u16, u8, u8, u8, u8, u8, s16); + +void ResetBgs(void) +{ + ResetBgControlStructs(); + gGpuBgConfigs.bgVisibilityAndMode = 0; + SetTextModeAndHideBgs(); +} + +void SetBgModeInternal(u8 bgMode) +{ + gGpuBgConfigs.bgVisibilityAndMode &= 0xFFF8; + gGpuBgConfigs.bgVisibilityAndMode |= bgMode; +} + +u8 GetBgMode(void) +{ + return gGpuBgConfigs.bgVisibilityAndMode & 0x7; +} + +void ResetBgControlStructs(void) +{ + struct BgConfig* bgConfigs = &gGpuBgConfigs.configs[0]; + struct BgConfig zeroedConfig = gZeroedBgControlStruct; + int i; + + for (i = 0; i < 4; i++) + { + bgConfigs[i] = zeroedConfig; + } +} + +void Unused_ResetBgControlStruct(u8 bg) +{ + if (IsInvalidBg(bg) == FALSE) + { + gGpuBgConfigs.configs[bg] = gZeroedBgControlStruct; + } +} + +void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenSize, u8 paletteMode, u8 priority, u8 mosaic, u8 wraparound) +{ + if (IsInvalidBg(bg) == FALSE) + { + if (charBaseIndex != 0xFF) + { + gGpuBgConfigs.configs[bg].charBaseIndex = charBaseIndex & 0x3; + } + + if (mapBaseIndex != 0xFF) + { + gGpuBgConfigs.configs[bg].mapBaseIndex = mapBaseIndex & 0x1F; + } + + if (screenSize != 0xFF) + { + gGpuBgConfigs.configs[bg].screenSize = screenSize & 0x3; + } + + if (paletteMode != 0xFF) + { + gGpuBgConfigs.configs[bg].paletteMode = paletteMode; + } + + if (priority != 0xFF) + { + gGpuBgConfigs.configs[bg].priority = priority & 0x3; + } + + if (mosaic != 0xFF) + { + gGpuBgConfigs.configs[bg].mosaic = mosaic & 0x1; + } + + if (wraparound != 0xFF) + { + gGpuBgConfigs.configs[bg].wraparound = wraparound; + } + + gGpuBgConfigs.configs[bg].unknown_2 = 0; + gGpuBgConfigs.configs[bg].unknown_3 = 0; + + gGpuBgConfigs.configs[bg].visible = 1; + } +} + +u16 GetBgControlAttribute(u8 bg, u8 attributeId) +{ + if (IsInvalidBg(bg) == FALSE && gGpuBgConfigs.configs[bg].visible != FALSE) + { + switch (attributeId) + { + case BG_CTRL_ATTR_VISIBLE: + return gGpuBgConfigs.configs[bg].visible; + case BG_CTRL_ATTR_CHARBASEINDEX: + return gGpuBgConfigs.configs[bg].charBaseIndex; + case BG_CTRL_ATTR_MAPBASEINDEX: + return gGpuBgConfigs.configs[bg].mapBaseIndex; + case BG_CTRL_ATTR_SCREENSIZE: + return gGpuBgConfigs.configs[bg].screenSize; + case BG_CTRL_ATTR_PALETTEMODE: + return gGpuBgConfigs.configs[bg].paletteMode; + case BG_CTRL_ATTR_PRIORITY: + return gGpuBgConfigs.configs[bg].priority; + case BG_CTRL_ATTR_MOSAIC: + return gGpuBgConfigs.configs[bg].mosaic; + case BG_CTRL_ATTR_WRAPAROUND: + return gGpuBgConfigs.configs[bg].wraparound; + } + } + + return 0xFF; +} + +u8 LoadBgVram(u8 bg, void *src, u16 size, u16 destOffset, u8 mode) +{ + u16 offset; + s8 cursor; + + if (IsInvalidBg(bg) == FALSE && gGpuBgConfigs.configs[bg].visible != FALSE) + { + switch (mode) + { + case 0x1: + offset = gGpuBgConfigs.configs[bg].charBaseIndex * BG_CHAR_SIZE; + break; + case 0x2: + offset = gGpuBgConfigs.configs[bg].mapBaseIndex * BG_SCREEN_SIZE; + break; + default: + cursor = -1; + goto end; + } + + offset = destOffset + offset; + + cursor = RequestDma3Copy(src, (void*)(offset + BG_VRAM), size, 0); + + if (cursor == -1) + { + return -1; + } + } + else + { + return -1; + } + +end: + return cursor; +} + +void ShowBgInternal(u8 bg) +{ + u16 value; + if (IsInvalidBg(bg) == FALSE && gGpuBgConfigs.configs[bg].visible != FALSE) + { + value = gGpuBgConfigs.configs[bg].priority | + (gGpuBgConfigs.configs[bg].charBaseIndex << 2) | + (gGpuBgConfigs.configs[bg].mosaic << 6) | + (gGpuBgConfigs.configs[bg].paletteMode << 7) | + (gGpuBgConfigs.configs[bg].mapBaseIndex << 8) | + (gGpuBgConfigs.configs[bg].wraparound << 13) | + (gGpuBgConfigs.configs[bg].screenSize << 14); + + SetGpuReg((bg << 1) + 0x8, value); + + gGpuBgConfigs.bgVisibilityAndMode |= 1 << (bg + 8); + gGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS; + } +} + +void HideBgInternal(u8 bg) +{ + if (IsInvalidBg(bg) == FALSE) + { + gGpuBgConfigs.bgVisibilityAndMode &= ~(1 << (bg + 8)); + gGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS; + } +} + +void SyncBgVisibilityAndMode() +{ + SetGpuReg(0, (GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS) | gGpuBgConfigs.bgVisibilityAndMode); +} + +void SetTextModeAndHideBgs() +{ + SetGpuReg(0, GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS); +} + +void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle) +{ + struct BgAffineSrcData src; + struct BgAffineDstData dest; + + switch (gGpuBgConfigs.bgVisibilityAndMode & 0x7) + { + case 1: + if (bg != 2) + return; + break; + case 2: + if (bg < 2 || bg > 3) + return; + break; + case 0: + default: + return; + } + + src.texX = srcCenterX; + src.texY = srcCenterY; + src.scrX = dispCenterX; + src.scrY = dispCenterY; + src.sx = scaleX; + src.sy = scaleY; + src.alpha = rotationAngle; + + BgAffineSet(&src, &dest, 1); + + SetGpuReg(REG_OFFSET_BG2PA, dest.pa); + SetGpuReg(REG_OFFSET_BG2PB, dest.pb); + SetGpuReg(REG_OFFSET_BG2PC, dest.pc); + SetGpuReg(REG_OFFSET_BG2PD, dest.pd); + SetGpuReg(REG_OFFSET_BG2PA, dest.pa); + SetGpuReg(REG_OFFSET_BG2X_L, (s16)(dest.dx)); + SetGpuReg(REG_OFFSET_BG2X_H, (s16)(dest.dx >> 16)); + SetGpuReg(REG_OFFSET_BG2Y_L, (s16)(dest.dy)); + SetGpuReg(REG_OFFSET_BG2Y_H, (s16)(dest.dy >> 16)); +} + +bool8 IsInvalidBg(u8 bg) +{ + if (bg > 3) + return TRUE; + return FALSE; +} + +int DummiedOutFireRedLeafGreenTileAllocFunc(int a1, int a2, int a3, int a4) +{ + return 0; +} + +void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable) +{ + int i; + ResetBgs(); + + for (i = 0; i < 4; i++) + { + gDmaBusyBitfield[i] = 0; + } + + gUnneededFireRedVariable = leftoverFireRedLeafGreenVariable; +} + +void InitBgsFromTemplates(u8 bgMode, struct BgTemplate *templates, u8 numTemplates) +{ + int i; + u8 bg; + + SetBgModeInternal(bgMode); + ResetBgControlStructs(); + + for (i = 0; i < numTemplates; i++) + { + bg = templates[i].bg; + if (bg < 4) { + SetBgControlAttributes(bg, + templates[i].charBaseIndex, + templates[i].mapBaseIndex, + templates[i].screenSize, + templates[i].paletteMode, + templates[i].priority, + 0, + 0); + + gGpuBgConfigs2[bg].baseTile = templates[i].baseTile; + gGpuBgConfigs2[bg].basePalette = 0; + gGpuBgConfigs2[bg].unk_3 = 0; + + gGpuBgConfigs2[bg].tilemap = NULL; + gGpuBgConfigs2[bg].bg_x = 0; + gGpuBgConfigs2[bg].bg_y = 0; + } + } +} + +void InitBgFromTemplate(struct BgTemplate *template) +{ + u8 bg = template->bg; + + if (bg < 4) + { + SetBgControlAttributes(bg, + template->charBaseIndex, + template->mapBaseIndex, + template->screenSize, + template->paletteMode, + template->priority, + 0, + 0); + + gGpuBgConfigs2[bg].baseTile = template->baseTile; + gGpuBgConfigs2[bg].basePalette = 0; + gGpuBgConfigs2[bg].unk_3 = 0; + + gGpuBgConfigs2[bg].tilemap = NULL; + gGpuBgConfigs2[bg].bg_x = 0; + gGpuBgConfigs2[bg].bg_y = 0; + } +} + +void SetBgMode(u8 bgMode) +{ + SetBgModeInternal(bgMode); +} + +u16 LoadBgTiles(u8 bg, void* src, u16 size, u16 destOffset) +{ + u16 tileOffset; + u8 cursor; + + if (GetBgControlAttribute(bg, BG_CTRL_ATTR_PALETTEMODE) == 0) + { + tileOffset = (gGpuBgConfigs2[bg].baseTile + destOffset) * 0x20; + } + else + { + tileOffset = (gGpuBgConfigs2[bg].baseTile + destOffset) * 0x40; + } + + cursor = LoadBgVram(bg, src, size, tileOffset, DISPCNT_MODE_1); + + if (cursor == 0xFF) + { + return -1; + } + + gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20)); + + if (gUnneededFireRedVariable == 1) + { + DummiedOutFireRedLeafGreenTileAllocFunc(bg, tileOffset / 0x20, size / 0x20, 1); + } + + return cursor; +} + +u16 LoadBgTilemap(u8 bg, void *src, u16 size, u16 destOffset) +{ + u8 cursor; + + cursor = LoadBgVram(bg, src, size, destOffset * 2, DISPCNT_MODE_2); + + if (cursor == 0xFF) + { + return -1; + } + + gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20)); + + return cursor; +} + +u16 Unused_LoadBgPalette(u8 bg, void *src, u16 size, u16 destOffset) +{ + u16 paletteOffset; + s8 cursor; + + if (IsInvalidBg32(bg) == FALSE) + { + paletteOffset = (gGpuBgConfigs2[bg].basePalette * 0x20) + (destOffset * 2); + cursor = RequestDma3Copy(src, (void*)(paletteOffset + BG_PLTT), size, 0); + + if (cursor == -1) + { + return -1; + } + } + else + { + return -1; + } + + gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20)); + + return (u8)cursor; +} + +#ifdef NONMATCHING // Matches everything but r5 and r6 are flipped, rrr +bool8 IsDma3ManagerBusyWithBgCopy(void) +{ + u8 mod; + u8 div; + s8 reqSpace; + + int i; + + for (i = 0; i < 0x80; i++) + { + div = i / 0x20; + mod = i % 0x20; + + if ((gDmaBusyBitfield[div] & (1 << mod)) != FALSE) + { + reqSpace = CheckForSpaceForDma3Request(i); + if (reqSpace == -1) + { + return TRUE; + } + + gDmaBusyBitfield[div] &= ~(1 << mod); + } + } + + return FALSE; +} +#else +__attribute__((naked)) +bool8 IsDma3ManagerBusyWithBgCopy(void) +{ + asm("push {r4-r7,lr}\n\ + mov r5, #0\n\ + mov r7, #0x1\n\ + neg r7, r7\n\ +_08001ADC:\n\ + add r0, r5, #0\n\ + cmp r5, #0\n\ + bge _08001AE4\n\ + add r0, #0x1F\n\ +_08001AE4:\n\ + asr r0, #5\n\ + lsl r2, r0, #24\n\ + lsl r0, #5\n\ + sub r0, r5, r0\n\ + lsl r0, #24\n\ + lsr r0, #24\n\ + ldr r1, =gDmaBusyBitfield\n\ + lsr r2, #22\n\ + add r4, r2, r1\n\ + mov r6, #0x1\n\ + lsl r6, r0\n\ + ldr r0, [r4]\n\ + and r0, r6\n\ + cmp r0, #0\n\ + beq _08001B22\n\ + lsl r0, r5, #16\n\ + asr r0, #16\n\ + bl CheckForSpaceForDma3Request\n\ + lsl r0, #24\n\ + asr r0, #24\n\ + cmp r0, r7\n\ + bne _08001B1C\n\ + mov r0, #0x1\n\ + b _08001B2A\n\ + .pool\n\ +_08001B1C:\n\ + ldr r0, [r4]\n\ + bic r0, r6\n\ + str r0, [r4]\n\ +_08001B22:\n\ + add r5, #0x1\n\ + cmp r5, #0x7F\n\ + ble _08001ADC\n\ + mov r0, #0\n\ +_08001B2A:\n\ + pop {r4-r7}\n\ + pop {r1}\n\ + bx r1\n"); +} +#endif // NONMATCHING + +void ShowBg(u8 bg) +{ + ShowBgInternal(bg); + SyncBgVisibilityAndMode(); +} + +void HideBg(u8 bg) +{ + HideBgInternal(bg); + SyncBgVisibilityAndMode(); +} + +void SetBgAttribute(u8 bg, u8 attributeId, u8 value) +{ + switch (attributeId) + { + case 1: + SetBgControlAttributes(bg, value, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); + break; + case 2: + SetBgControlAttributes(bg, 0xFF, value, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); + break; + case 3: + SetBgControlAttributes(bg, 0xFF, 0xFF, value, 0xFF, 0xFF, 0xFF, 0xFF); + break; + case 4: + SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, value, 0xFF, 0xFF, 0xFF); + break; + case 7: + SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, 0xFF, value, 0xFF, 0xFF); + break; + case 5: + SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, value, 0xFF); + break; + case 6: + SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, value); + break; + } +} + +u16 GetBgAttribute(u8 bg, u8 attributeId) +{ + switch (attributeId) + { + case 1: + return GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX); + case 2: + return GetBgControlAttribute(bg, BG_CTRL_ATTR_MAPBASEINDEX); + case 3: + return GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); + case 4: + return GetBgControlAttribute(bg, BG_CTRL_ATTR_PALETTEMODE); + case 7: + return GetBgControlAttribute(bg, BG_CTRL_ATTR_PRIORITY); + case 5: + return GetBgControlAttribute(bg, BG_CTRL_ATTR_MOSAIC); + case 6: + return GetBgControlAttribute(bg, BG_CTRL_ATTR_WRAPAROUND); + case 8: + switch (GetBgType(bg)) + { + case 0: + return GetBgMetricTextMode(bg, 0) * 0x800; + case 1: + return GetBgMetricAffineMode(bg, 0) * 0x100; + default: + return 0; + } + case 9: + return GetBgType(bg); + case 10: + return gGpuBgConfigs2[bg].baseTile; + default: + return -1; + } +} + +u32 ChangeBgX(u8 bg, u32 value, u8 op) +{ + u8 mode; + u16 temp1; + u16 temp2; + + if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + { + return -1; + } + + switch (op) + { + case 0: + default: + gGpuBgConfigs2[bg].bg_x = value; + break; + case 1: + gGpuBgConfigs2[bg].bg_x += value; + break; + case 2: + gGpuBgConfigs2[bg].bg_x -= value; + break; + } + + mode = GetBgMode(); + + switch (bg) + { + case 0: + temp1 = gGpuBgConfigs2[0].bg_x >> 0x8; + SetGpuReg(REG_OFFSET_BG0HOFS, temp1); + break; + case 1: + temp1 = gGpuBgConfigs2[1].bg_x >> 0x8; + SetGpuReg(REG_OFFSET_BG1HOFS, temp1); + break; + case 2: + if (mode == 0) + { + temp1 = gGpuBgConfigs2[2].bg_x >> 0x8; + SetGpuReg(REG_OFFSET_BG2HOFS, temp1); + } + else + { + temp1 = gGpuBgConfigs2[2].bg_x >> 0x10; + temp2 = gGpuBgConfigs2[2].bg_x & 0xFFFF; + SetGpuReg(REG_OFFSET_BG2X_H, temp1); + SetGpuReg(REG_OFFSET_BG2X_L, temp2); + } + break; + case 3: + if (mode == 0) + { + temp1 = gGpuBgConfigs2[3].bg_x >> 0x8; + SetGpuReg(REG_OFFSET_BG3HOFS, temp1); + } + else if (mode == 2) + { + temp1 = gGpuBgConfigs2[3].bg_x >> 0x10; + temp2 = gGpuBgConfigs2[3].bg_x & 0xFFFF; + SetGpuReg(REG_OFFSET_BG3X_H, temp1); + SetGpuReg(REG_OFFSET_BG3X_L, temp2); + } + break; + } + + return gGpuBgConfigs2[bg].bg_x; +} + +u32 GetBgX(u8 bg) +{ + if (IsInvalidBg32(bg) != FALSE) + return -1; + if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + return -1; + return gGpuBgConfigs2[bg].bg_x; +} + +u32 ChangeBgY(u8 bg, u32 value, u8 op) +{ + u8 mode; + u16 temp1; + u16 temp2; + + if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + { + return -1; + } + + switch (op) + { + case 0: + default: + gGpuBgConfigs2[bg].bg_y = value; + break; + case 1: + gGpuBgConfigs2[bg].bg_y += value; + break; + case 2: + gGpuBgConfigs2[bg].bg_y -= value; + break; + } + + mode = GetBgMode(); + + switch (bg) + { + case 0: + temp1 = gGpuBgConfigs2[0].bg_y >> 0x8; + SetGpuReg(REG_OFFSET_BG0VOFS, temp1); + break; + case 1: + temp1 = gGpuBgConfigs2[1].bg_y >> 0x8; + SetGpuReg(REG_OFFSET_BG1VOFS, temp1); + break; + case 2: + if (mode == 0) + { + temp1 = gGpuBgConfigs2[2].bg_y >> 0x8; + SetGpuReg(REG_OFFSET_BG2VOFS, temp1); + } + else + { + temp1 = gGpuBgConfigs2[2].bg_y >> 0x10; + temp2 = gGpuBgConfigs2[2].bg_y & 0xFFFF; + SetGpuReg(REG_OFFSET_BG2Y_H, temp1); + SetGpuReg(REG_OFFSET_BG2Y_L, temp2); + } + break; + case 3: + if (mode == 0) + { + temp1 = gGpuBgConfigs2[3].bg_y >> 0x8; + SetGpuReg(REG_OFFSET_BG3VOFS, temp1); + } + else if (mode == 2) + { + temp1 = gGpuBgConfigs2[3].bg_y >> 0x10; + temp2 = gGpuBgConfigs2[3].bg_y & 0xFFFF; + SetGpuReg(REG_OFFSET_BG3Y_H, temp1); + SetGpuReg(REG_OFFSET_BG3Y_L, temp2); + } + break; + } + + return gGpuBgConfigs2[bg].bg_y; +} + +u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op) +{ + u8 mode; + u16 temp1; + u16 temp2; + + if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + { + return -1; + } + + switch (op) + { + case 0: + default: + gGpuBgConfigs2[bg].bg_y = value; + break; + case 1: + gGpuBgConfigs2[bg].bg_y += value; + break; + case 2: + gGpuBgConfigs2[bg].bg_y -= value; + break; + } + + mode = GetBgMode(); + + switch (bg) + { + case 0: + temp1 = gGpuBgConfigs2[0].bg_y >> 0x8; + SetGpuReg_ForcedBlank(REG_OFFSET_BG0VOFS, temp1); + break; + case 1: + temp1 = gGpuBgConfigs2[1].bg_y >> 0x8; + SetGpuReg_ForcedBlank(REG_OFFSET_BG1VOFS, temp1); + break; + case 2: + if (mode == 0) + { + temp1 = gGpuBgConfigs2[2].bg_y >> 0x8; + SetGpuReg_ForcedBlank(REG_OFFSET_BG2VOFS, temp1); + + } + else + { + temp1 = gGpuBgConfigs2[2].bg_y >> 0x10; + temp2 = gGpuBgConfigs2[2].bg_y & 0xFFFF; + SetGpuReg_ForcedBlank(REG_OFFSET_BG2Y_H, temp1); + SetGpuReg_ForcedBlank(REG_OFFSET_BG2Y_L, temp2); + } + break; + case 3: + if (mode == 0) + { + temp1 = gGpuBgConfigs2[3].bg_y >> 0x8; + SetGpuReg_ForcedBlank(REG_OFFSET_BG3VOFS, temp1); + } + else if (mode == 2) + { + temp1 = gGpuBgConfigs2[3].bg_y >> 0x10; + temp2 = gGpuBgConfigs2[3].bg_y & 0xFFFF; + SetGpuReg_ForcedBlank(REG_OFFSET_BG3Y_H, temp1); + SetGpuReg_ForcedBlank(REG_OFFSET_BG3Y_L, temp2); + } + break; + } + + return gGpuBgConfigs2[bg].bg_y; +} + +u32 GetBgY(u8 bg) +{ + if (IsInvalidBg32(bg) != FALSE) + return -1; + if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + return -1; + return gGpuBgConfigs2[bg].bg_y; +} + +void SetBgAffine(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle) +{ + SetBgAffineInternal(bg, srcCenterX, srcCenterY, dispCenterX, dispCenterY, scaleX, scaleY, rotationAngle); +} + +u8 Unused_AdjustBgMosaic(u8 a1, u8 a2) +{ + u16 result; + s16 test1; + s16 test2; + + result = GetGpuReg(REG_OFFSET_MOSAIC); + + test1 = result & 0xF; + test2 = (result >> 4) & 0xF; + result &= 0xFF00; + + switch (a2) + { + case 0: + default: + test1 = a1 & 0xF; + test2 = a1 >> 0x4; + break; + case 1: + test1 = a1 & 0xF; + break; + case 2: + if ((test1 + a1) > 0xF) + { + test1 = 0xF; + } + else + { + test1 += a1; + } + break; + case 3: + if ((test1 - a1) < 0) + { + test1 = 0x0; + } + else + { + test1 -= a1; + } + break; + case 4: + test2 = a1 & 0xF; + break; + case 5: + if ((test2 + a1) > 0xF) + { + test2 = 0xF; + } + else + { + test2 += a1; + } + break; + case 6: + if ((test2 - a1) < 0) + { + test2 = 0x0; + } + else + { + test2 -= a1; + } + break; + } + + result |= ((test2 << 0x4) & 0xF0); + result |= (test1 & 0xF); + + SetGpuReg(REG_OFFSET_MOSAIC, result); + + return result; +} + +void SetBgTilemapBuffer(u8 bg, void *tilemap) +{ + if (IsInvalidBg32(bg) == FALSE && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) != 0x0) + { + gGpuBgConfigs2[bg].tilemap = tilemap; + } +} + +void UnsetBgTilemapBuffer(u8 bg) +{ + if (IsInvalidBg32(bg) == FALSE && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) != 0x0) + { + gGpuBgConfigs2[bg].tilemap = NULL; + } +} + +void* GetBgTilemapBuffer(u8 bg) +{ + if (IsInvalidBg32(bg) != FALSE) + return NULL; + if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + return NULL; + return gGpuBgConfigs2[bg].tilemap; +} + +void CopyToBgTilemapBuffer(u8 bg, void *src, u16 mode, u16 destOffset) +{ + if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + { + if (mode != 0) + { + CpuCopy16(src, (void *)(gGpuBgConfigs2[bg].tilemap + (destOffset * 2)), mode); + } + else + { + LZ77UnCompWram(src, (void *)(gGpuBgConfigs2[bg].tilemap + (destOffset * 2))); + } + } +} + +void CopyBgTilemapBufferToVram(u8 bg) +{ + u16 sizeToLoad; + + if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + { + switch (GetBgType(bg)) + { + case 0: + sizeToLoad = GetBgMetricTextMode(bg, 0) * 0x800; + break; + case 1: + sizeToLoad = GetBgMetricAffineMode(bg, 0) * 0x100; + break; + default: + sizeToLoad = 0; + break; + } + LoadBgVram(bg, gGpuBgConfigs2[bg].tilemap, sizeToLoad, 0, 2); + } +} + +void CopyToBgTilemapBufferRect(u8 bg, void* src, u8 destX, u8 destY, u8 width, u8 height) +{ + void* srcCopy; + u16 destX16; + u16 destY16; + u16 mode; + + if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + { + switch (GetBgType(bg)) + { + case 0: + srcCopy = src; + for (destY16 = destY; destY16 < (destY + height); destY16++) + { + for (destX16 = destX; destX16 < (destX + width); destX16++) + { + ((u16*)gGpuBgConfigs2[bg].tilemap)[((destY16 * 0x20) + destX16)] = *((u16*)srcCopy)++; + } + } + break; + case 1: + srcCopy = src; + mode = GetBgMetricAffineMode(bg, 0x1); + for (destY16 = destY; destY16 < (destY + height); destY16++) + { + for (destX16 = destX; destX16 < (destX + width); destX16++) + { + ((u8*)gGpuBgConfigs2[bg].tilemap)[((destY16 * mode) + destX16)] = *((u8*)srcCopy)++; + } + } + break; + } + } +} + +void CopyToBgTilemapBufferRect_ChangePalette(u8 bg, void *src, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette) +{ + CopyRectToBgTilemapBufferRect(bg, src, 0, 0, rectWidth, rectHeight, destX, destY, rectWidth, rectHeight, palette, 0, 0); +} +// Skipping for now, it probably uses structs passed by value +/* +void CopyRectToBgTilemapBufferRect(u8 bg, void* src, u8 srcX, u8 srcY, u8 srcWidth, u8 srcHeight, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette1, u16 tileOffset, u16 palette2) +{ + u16 attribute; + u16 mode; + u16 mode2; + + void* srcCopy; + u16 destX16; + u16 destY16; + + if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + { + attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); + mode = GetBgMetricTextMode(bg, 0x1) * 0x20; + mode2 = GetBgMetricTextMode(bg, 0x2) * 0x20; + switch (GetBgType(bg)) + { + case 0: + srcCopy = src; + for (destY16 = destY; destY16 < (destY + rectHeight); destY16++) + { + for (destX16 = destX; destX16 < (destX + rectWidth); destX16++) + { + CopyTileMapEntry(&((u16*)srcCopy)[(srcY * rectWidth) + srcX], &((u16*)gGpuBgConfigs2[bg].tilemap)[GetTileMapIndexFromCoords(destX16, destY16, attribute, mode, mode2)], palette1, tileOffset, palette2); + } + } + break; + case 1: + srcCopy = src; + mode = GetBgMetricAffineMode(bg, 0x1); + for (destY16 = destY; destY16 < (destY + rectHeight); destY16++) + { + for (destX16 = destX; destX16 < (destX + rectWidth); destX16++) + { + CopyTileMapEntry(&((u16*)srcCopy)[(srcY * rectWidth) + srcX], &((u16*)gGpuBgConfigs2[bg].tilemap)[GetTileMapIndexFromCoords(destX16, destY16, attribute, mode, mode2)], palette1, tileOffset, palette2); + } + } + break; + } + } +}*/ +__attribute__((naked)) +void CopyRectToBgTilemapBufferRect(u8 bg, void* src, u8 srcX, u8 srcY, u8 srcWidth, u8 srcHeight, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette1, u16 tileOffset, u16 palette2) +{ + asm("push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, #0x40\n\ + str r1, [sp, #0x8]\n\ + ldr r1, [sp, #0x60]\n\ + ldr r4, [sp, #0x68]\n\ + ldr r5, [sp, #0x6C]\n\ + ldr r6, [sp, #0x70]\n\ + ldr r7, [sp, #0x74]\n\ + mov r8, r7\n\ + ldr r7, [sp, #0x78]\n\ + mov r9, r7\n\ + ldr r7, [sp, #0x7C]\n\ + mov r10, r7\n\ + ldr r7, [sp, #0x80]\n\ + mov r12, r7\n\ + lsl r0, #24\n\ + lsr r0, #24\n\ + str r0, [sp, #0x4]\n\ + lsl r2, #24\n\ + lsr r2, #24\n\ + str r2, [sp, #0xC]\n\ + lsl r3, #24\n\ + lsr r3, #24\n\ + str r3, [sp, #0x10]\n\ + lsl r1, #24\n\ + lsr r7, r1, #24\n\ + lsl r4, #24\n\ + lsr r4, #24\n\ + str r4, [sp, #0x14]\n\ + lsl r5, #24\n\ + lsr r5, #24\n\ + lsl r6, #24\n\ + lsr r6, #24\n\ + str r6, [sp, #0x18]\n\ + mov r0, r8\n\ + lsl r0, #24\n\ + lsr r4, r0, #24\n\ + mov r1, r9\n\ + lsl r1, #24\n\ + lsr r1, #24\n\ + str r1, [sp, #0x1C]\n\ + mov r2, r10\n\ + lsl r2, #16\n\ + lsr r2, #16\n\ + str r2, [sp, #0x20]\n\ + mov r0, r12\n\ + lsl r0, #16\n\ + lsr r0, #16\n\ + str r0, [sp, #0x24]\n\ + ldr r0, [sp, #0x4]\n\ + bl IsInvalidBg32\n\ + cmp r0, #0\n\ + beq _08002592\n\ + b _080026EE\n\ +_08002592:\n\ + ldr r0, [sp, #0x4]\n\ + bl IsTileMapOutsideWram\n\ + cmp r0, #0\n\ + beq _0800259E\n\ + b _080026EE\n\ +_0800259E:\n\ + ldr r0, [sp, #0x4]\n\ + mov r1, #0x4\n\ + bl GetBgControlAttribute\n\ + lsl r0, #16\n\ + lsr r0, #16\n\ + str r0, [sp, #0x30]\n\ + ldr r0, [sp, #0x4]\n\ + mov r1, #0x1\n\ + bl GetBgMetricTextMode\n\ + lsl r0, #21\n\ + lsr r0, #16\n\ + str r0, [sp, #0x28]\n\ + ldr r0, [sp, #0x4]\n\ + mov r1, #0x2\n\ + bl GetBgMetricTextMode\n\ + lsl r0, #21\n\ + lsr r0, #16\n\ + str r0, [sp, #0x2C]\n\ + ldr r0, [sp, #0x4]\n\ + bl GetBgType\n\ + cmp r0, #0\n\ + beq _080025D8\n\ + cmp r0, #0x1\n\ + beq _08002674\n\ + b _080026EE\n\ +_080025D8:\n\ + ldr r1, [sp, #0x10]\n\ + add r0, r1, #0\n\ + mul r0, r7\n\ + ldr r2, [sp, #0xC]\n\ + add r0, r2\n\ + lsl r0, #1\n\ + ldr r1, [sp, #0x8]\n\ + add r6, r1, r0\n\ + add r0, r5, r4\n\ + cmp r5, r0\n\ + blt _080025F0\n\ + b _080026EE\n\ +_080025F0:\n\ + ldr r2, [sp, #0x18]\n\ + sub r2, r7, r2\n\ + str r2, [sp, #0x34]\n\ + str r0, [sp, #0x38]\n\ +_080025F8:\n\ + ldr r4, [sp, #0x14]\n\ + ldr r7, [sp, #0x18]\n\ + add r0, r4, r7\n\ + add r1, r5, #0x1\n\ + str r1, [sp, #0x3C]\n\ + cmp r4, r0\n\ + bge _0800265A\n\ + ldr r2, [sp, #0x4]\n\ + lsl r0, r2, #4\n\ + ldr r1, =gGpuBgConfigs2+4\n\ + add r0, r1\n\ + mov r10, r0\n\ + ldr r7, [sp, #0x20]\n\ + lsl r7, #16\n\ + mov r9, r7\n\ + ldr r1, [sp, #0x24]\n\ + lsl r0, r1, #16\n\ + asr r0, #16\n\ + mov r8, r0\n\ +_0800261E:\n\ + ldr r2, [sp, #0x2C]\n\ + str r2, [sp]\n\ + add r0, r4, #0\n\ + add r1, r5, #0\n\ + ldr r2, [sp, #0x30]\n\ + ldr r3, [sp, #0x28]\n\ + bl GetTileMapIndexFromCoords\n\ + lsl r0, #16\n\ + lsr r0, #15\n\ + mov r7, r10\n\ + ldr r1, [r7]\n\ + add r1, r0\n\ + mov r0, r8\n\ + str r0, [sp]\n\ + add r0, r6, #0\n\ + ldr r2, [sp, #0x1C]\n\ + mov r7, r9\n\ + asr r3, r7, #16\n\ + bl CopyTileMapEntry\n\ + add r6, #0x2\n\ + add r0, r4, #0x1\n\ + lsl r0, #16\n\ + lsr r4, r0, #16\n\ + ldr r1, [sp, #0x14]\n\ + ldr r2, [sp, #0x18]\n\ + add r0, r1, r2\n\ + cmp r4, r0\n\ + blt _0800261E\n\ +_0800265A:\n\ + ldr r5, [sp, #0x34]\n\ + lsl r0, r5, #1\n\ + add r6, r0\n\ + ldr r7, [sp, #0x3C]\n\ + lsl r0, r7, #16\n\ + lsr r5, r0, #16\n\ + ldr r0, [sp, #0x38]\n\ + cmp r5, r0\n\ + blt _080025F8\n\ + b _080026EE\n\ + .pool\n\ +_08002674:\n\ + ldr r1, [sp, #0x10]\n\ + add r0, r1, #0\n\ + mul r0, r7\n\ + ldr r2, [sp, #0xC]\n\ + add r0, r2\n\ + ldr r1, [sp, #0x8]\n\ + add r6, r1, r0\n\ + ldr r0, [sp, #0x4]\n\ + mov r1, #0x1\n\ + bl GetBgMetricAffineMode\n\ + lsl r0, #16\n\ + lsr r0, #16\n\ + mov r9, r0\n\ + add r0, r5, r4\n\ + cmp r5, r0\n\ + bge _080026EE\n\ + ldr r2, [sp, #0x18]\n\ + sub r2, r7, r2\n\ + str r2, [sp, #0x34]\n\ + str r0, [sp, #0x38]\n\ + ldr r7, =gGpuBgConfigs2+4\n\ + mov r10, r7\n\ + ldr r0, [sp, #0x4]\n\ + lsl r0, #4\n\ + mov r8, r0\n\ +_080026A8:\n\ + ldr r4, [sp, #0x14]\n\ + ldr r1, [sp, #0x18]\n\ + add r0, r4, r1\n\ + add r2, r5, #0x1\n\ + str r2, [sp, #0x3C]\n\ + cmp r4, r0\n\ + bge _080026DE\n\ + mov r3, r8\n\ + add r3, r10\n\ + mov r7, r9\n\ + mul r7, r5\n\ + mov r12, r7\n\ + add r2, r0, #0\n\ +_080026C2:\n\ + ldr r1, [r3]\n\ + mov r5, r12\n\ + add r0, r5, r4\n\ + add r1, r0\n\ + ldrb r0, [r6]\n\ + ldr r7, [sp, #0x20]\n\ + add r0, r7\n\ + strb r0, [r1]\n\ + add r6, #0x1\n\ + add r0, r4, #0x1\n\ + lsl r0, #16\n\ + lsr r4, r0, #16\n\ + cmp r4, r2\n\ + blt _080026C2\n\ +_080026DE:\n\ + ldr r0, [sp, #0x34]\n\ + add r6, r0\n\ + ldr r1, [sp, #0x3C]\n\ + lsl r0, r1, #16\n\ + lsr r5, r0, #16\n\ + ldr r2, [sp, #0x38]\n\ + cmp r5, r2\n\ + blt _080026A8\n\ +_080026EE:\n\ + add sp, #0x40\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n"); +} + +void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height) +{ + u16 x16; + u16 y16; + u16 mode; + + if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + { + switch (GetBgType(bg)) + { + case 0: + for (y16 = y; y16 < (y + height); y16++) + { + for (x16 = x; x16 < (x + width); x16++) + { + ((u16*)gGpuBgConfigs2[bg].tilemap)[((y16 * 0x20) + x16)] = tileNum; + } + } + break; + case 1: + mode = GetBgMetricAffineMode(bg, 0x1); + for (y16 = y; y16 < (y + height); y16++) + { + for (x16 = x; x16 < (x + width); x16++) + { + ((u8*)gGpuBgConfigs2[bg].tilemap)[((y16 * mode) + x16)] = tileNum; + } + } + break; + } + } +} + +void FillBgTilemapBufferRect(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height, u8 palette) +{ + WriteSequenceToBgTilemapBuffer(bg, tileNum, x, y, width, height, palette, 0); +} + +void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 width, u8 height, u8 paletteSlot, s16 tileNumDelta) +{ + u16 mode; + u16 mode2; + u16 attribute; + u16 mode3; + + u16 x16; + u16 y16; + + if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + { + attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); + mode = GetBgMetricTextMode(bg, 0x1) * 0x20; + mode2 = GetBgMetricTextMode(bg, 0x2) * 0x20; + switch (GetBgType(bg)) + { + case 0: + for (y16 = y; y16 < (y + height); y16++) + { + for (x16 = x; x16 < (x + width); x16++) + { + CopyTileMapEntry(&firstTileNum, &((u16*)gGpuBgConfigs2[bg].tilemap)[(u16)GetTileMapIndexFromCoords(x16, y16, attribute, mode, mode2)], paletteSlot, 0, 0); + firstTileNum = (firstTileNum & 0xFC00) + ((firstTileNum + tileNumDelta) & 0x3FF); + } + } + break; + case 1: + mode3 = GetBgMetricAffineMode(bg, 0x1); + for (y16 = y; y16 < (y + height); y16++) + { + for (x16 = x; x16 < (x + width); x16++) + { + ((u8*)gGpuBgConfigs2[bg].tilemap)[(y16 * mode3) + x16] = firstTileNum; + firstTileNum = (firstTileNum & 0xFC00) + ((firstTileNum + tileNumDelta) & 0x3FF); + } + } + break; + } + } +} + +u16 GetBgMetricTextMode(u8 bg, u8 whichMetric) +{ + u8 attribute; + + attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); + + switch (whichMetric) + { + case 0: + switch (attribute) + { + case 0: + return 1; + case 1: + case 2: + return 2; + case 3: + return 4; + } + break; + case 1: + switch (attribute) + { + case 0: + return 1; + case 1: + return 2; + case 2: + return 1; + case 3: + return 2; + } + break; + case 2: + switch (attribute) + { + case 0: + case 1: + return 1; + case 2: + case 3: + return 2; + } + break; + } + return 0; +} + +u32 GetBgMetricAffineMode(u8 bg, u8 whichMetric) +{ + u8 attribute; + + attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); + + switch (whichMetric) + { + case 0: + switch (attribute) + { + case 0: + return 0x1; + case 1: + return 0x4; + case 2: + return 0x10; + case 3: + return 0x40; + } + break; + case 1: + case 2: + return 0x10 << attribute; + } + return 0; +} + +u32 GetTileMapIndexFromCoords(s32 x, s32 y, s32 screenSize, u32 screenWidth, u32 screenHeight) +{ + x = x & (screenWidth - 1); + y = y & (screenHeight - 1); + + switch (screenSize) + { + case 0: + case 2: + break; + case 3: + if (y >= 0x20) + y += 0x20; + case 1: + if (x >= 0x20) + { + x -= 0x20; + y += 0x20; + } + } + return (y * 0x20) + x; +} + +#ifdef NONMATCHING // This one has some weird switch statement cases that refuse to cooperate +void CopyTileMapEntry(u16 *src, u16 *dest, s32 palette1, u32 tileOffset, u32 palette2) +{ + u16 test; + switch (palette1) + { + default: + if (palette1 > 0x10 || palette1 < 0) + test = *src + tileOffset + (palette2 << 12); + else + test = ((*src + tileOffset) & 0xFFF) + ((palette1 + palette2) << 12); + break; + case 0x10: + test = ((*dest & 0xFC00) + (palette2 << 12)) | ((*src + tileOffset) & 0x3FF); + break; + } + + *dest = test; +} +#else +__attribute__((naked)) +void CopyTileMapEntry(u16 *src, u16 *dest, s32 palette1, u32 tileOffset, u32 palette2) +{ + asm("push {r4-r6,lr}\n\ + add r4, r0, #0\n\ + add r6, r1, #0\n\ + ldr r5, [sp, #0x10]\n\ + cmp r2, #0x10\n\ + beq _08002B14\n\ + cmp r2, #0x10\n\ + bgt _08002B34\n\ + cmp r2, #0\n\ + blt _08002B34\n\ + ldrh r0, [r4]\n\ + add r0, r3\n\ + ldr r3, =0x00000fff\n\ + add r1, r3, #0\n\ + and r0, r1\n\ + add r1, r2, r5\n\ + lsl r1, #12\n\ + b _08002B3A\n\ + .pool\n\ +_08002B14:\n\ + ldrh r1, [r6]\n\ + mov r0, #0xFC\n\ + lsl r0, #8\n\ + and r1, r0\n\ + lsl r2, r5, #12\n\ + add r2, r1, r2\n\ + ldrh r0, [r4]\n\ + add r0, r3\n\ + ldr r3, =0x000003ff\n\ + add r1, r3, #0\n\ + and r0, r1\n\ + orr r0, r2\n\ + b _08002B3C\n\ + .pool\n\ +_08002B34:\n\ + ldrh r0, [r4]\n\ + add r0, r3\n\ + lsl r1, r5, #12\n\ +_08002B3A:\n\ + add r0, r1\n\ +_08002B3C:\n\ + lsl r0, #16\n\ + lsr r1, r0, #16\n\ + strh r1, [r6]\n\ + pop {r4-r6}\n\ + pop {r0}\n\ + bx r0\n"); +} +#endif // NONMATCHING + +u32 GetBgType(u8 bg) +{ + u8 mode; + + mode = GetBgMode(); + + + switch (bg) + { + case 0: + case 1: + switch (mode) + { + case 0: + case 1: + return 0; + } + break; + case 2: + switch (mode) + { + case 0: + return 0; + case 1: + case 2: + return 1; + } + break; + case 3: + switch (mode) + { + case 0: + return 0; + case 2: + return 1; + } + break; + } + + return 0xFFFF; +} + +bool32 IsInvalidBg32(u8 bg) +{ + if (bg > 3) + return TRUE; + return FALSE; +} + +bool32 IsTileMapOutsideWram(u8 bg) +{ + if (gGpuBgConfigs2[bg].tilemap > (void*)IWRAM_END) + return TRUE; + if (gGpuBgConfigs2[bg].tilemap == 0x0) + return TRUE; + return FALSE; +} diff --git a/sym_bss.txt b/sym_bss.txt index 4a61c2ff1..070e7e5f9 100644 --- a/sym_bss.txt +++ b/sym_bss.txt @@ -23,20 +23,7 @@ gDma3RequestCursor: @ 3000811 .space 0x7 .include "src/gpu_regs.o" - - .align 4 -gUnknown_030008E0: @ 30008E0 - .space 0x18 - -gUnknown_030008F8: @ 30008F8 - .space 0x4 - -gUnknown_030008FC: @ 30008FC - .space 0x3C - -gUnknown_03000938: @ 3000938 - .space 0x10 - + .include "src/bg.o" .include "src/text.o" .include "src/sprite.o" diff --git a/sym_common.txt b/sym_common.txt index 0bca24003..c2a966f53 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -39,9 +39,9 @@ IntrMain_Buffer: @ 3002750 gPcmDmaCounter: @ 3002F50 .space 0x4 -gUnneededFireRedVariable: @ 3002F54 - .space 0xC + .include "bg.o" + .align 4 gUnknown_03002F60: @ 3002F60 .space 0x10