diff --git a/asm/bg.s b/asm/bg.s index efa94ea796..4c61745433 100644 --- a/asm/bg.s +++ b/asm/bg.s @@ -5,1273 +5,6 @@ .text - 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 IsInvalidBgDuplicate - 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 IsInvalidBgDuplicate - 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 IsInvalidBgDuplicate - 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 IsInvalidBgDuplicate - 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 IsInvalidBgDuplicate - 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 IsInvalidBgDuplicate - 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 IsInvalidBgDuplicate - 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 IsInvalidBgDuplicate - 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 IsInvalidBgDuplicate - 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 IsInvalidBgDuplicate - 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 IsInvalidBgDuplicate - 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 diff --git a/src/bg.c b/src/bg.c index 37336c7f10..902579b57f 100644 --- a/src/bg.c +++ b/src/bg.c @@ -40,9 +40,9 @@ struct BgConfig2 { u32 unk_2:4; u32 unk_3:18; - u32 unk_4; - u32 unk_5; - u32 unk_6; + void* tilemap; + u32 bg_x; + u32 bg_y; }; extern struct BgControl gUnknown_030008E0; // gGpuBgConfigs @@ -53,12 +53,17 @@ extern struct BgConfig gZeroedBgControlStruct; extern bool32 IsInvalidBgDuplicate(u8 bg); void ResetBgControlStructs(); +u16 GetBgMetricTextMode(u8 bg, u8 whichMetric); +u16 GetBgMetricAffineMode(u8 bg, u8 whichMetric); +u32 GetBgType(u8 bg); +void SetTextModeAndHideBgs(); +bool8 IsInvalidBg(u8 bg); +bool32 IsTileMapOutsideWram(u8 bg); -extern void SetTextModeAndHideBgs(); -extern bool8 IsInvalidBg(u8 bg); extern void SetGpuReg(u8 regOffset, u16 value); +extern void SetGpuReg_ForcedBlank(u8 regOffset, u16 value); extern u16 GetGpuReg(u8 regOffset); -extern s8 CheckForSpaceForDma3Request(s16 index); +extern int CheckForSpaceForDma3Request(s16 index); void ResetBgs(void) { @@ -249,7 +254,7 @@ void SetTextModeAndHideBgs() SetGpuReg(0, GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS); } -void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, u16 dispCenterX, u16 dispCenterY, u16 scaleX, u16 scaleY, u16 rotationAngle) +void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle) { struct BgAffineSrcData src; struct BgAffineDstData dest; @@ -340,9 +345,9 @@ void InitBgsFromTemplates(u8 bgMode, struct BgTemplate *templates, u8 numTemplat gUnknown_030008F8[bg].unk_2 = 0; gUnknown_030008F8[bg].unk_3 = 0; - gUnknown_030008F8[bg].unk_4 = 0; - gUnknown_030008F8[bg].unk_5 = 0; - gUnknown_030008F8[bg].unk_6 = 0; + gUnknown_030008F8[bg].tilemap = NULL; + gUnknown_030008F8[bg].bg_x = 0; + gUnknown_030008F8[bg].bg_y = 0; } } } @@ -366,9 +371,9 @@ void InitBgFromTemplate(struct BgTemplate *template) gUnknown_030008F8[bg].unk_2 = 0; gUnknown_030008F8[bg].unk_3 = 0; - gUnknown_030008F8[bg].unk_4 = 0; - gUnknown_030008F8[bg].unk_5 = 0; - gUnknown_030008F8[bg].unk_6 = 0; + gUnknown_030008F8[bg].tilemap = NULL; + gUnknown_030008F8[bg].bg_x = 0; + gUnknown_030008F8[bg].bg_y = 0; } } @@ -449,11 +454,14 @@ u16 Unused_LoadBgPalette(u8 bg, void *src, u16 size, u16 destOffset) return (u8)cursor; } +#ifdef NONMATCHING // Matches everything but r5 and r6 are flipped, rrr bool8 IsDma3ManagerBusyWithBgCopy(void) { - int i; - u8 div; u8 mod; + u8 div; + s8 reqSpace; + + int i; for (i = 0; i < 0x80; i++) { @@ -462,7 +470,8 @@ bool8 IsDma3ManagerBusyWithBgCopy(void) if ((gUnknown_03000938[div] & (1 << mod)) != FALSE) { - if (CheckForSpaceForDma3Request(i) == -1) + reqSpace = CheckForSpaceForDma3Request(i); + if (reqSpace == -1) { return TRUE; } @@ -473,3 +482,1099 @@ bool8 IsDma3ManagerBusyWithBgCopy(void) 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, =gUnknown_03000938\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, 2); + case 2: + return GetBgControlAttribute(bg, 3); + case 3: + return GetBgControlAttribute(bg, 4); + case 4: + return GetBgControlAttribute(bg, 5); + case 7: + return GetBgControlAttribute(bg, 6); + case 5: + return GetBgControlAttribute(bg, 7); + case 6: + return GetBgControlAttribute(bg, 8); + 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 gUnknown_030008F8[bg].unk_1; + default: + return -1; + } +} + +#ifdef NONMATCHING // Everything that uses temp1 doesn't match +u32 ChangeBgX(u8 bg, u32 value, u8 op) +{ + u8 mode; + u32 temp1; + + if (IsInvalidBgDuplicate(bg) != FALSE || GetBgControlAttribute(bg, 1) == 0) + { + return -1; + } + + switch (op) + { + case 0: + default: + gUnknown_030008F8[bg].bg_x = value; + break; + case 1: + gUnknown_030008F8[bg].bg_x += value; + break; + case 2: + gUnknown_030008F8[bg].bg_x -= value; + break; + } + + mode = GetBgMode(); + + switch (bg) + { + case 0: + SetGpuReg(REG_OFFSET_BG0HOFS, gUnknown_030008F8[0].bg_x >> 0x8); + break; + case 1: + SetGpuReg(REG_OFFSET_BG1HOFS, gUnknown_030008F8[1].bg_x >> 0x8); + break; + case 2: + if (mode == 0) + { + SetGpuReg(REG_OFFSET_BG2HOFS, gUnknown_030008F8[2].bg_x >> 0x8); + } + else + { + temp1 = gUnknown_030008F8[2].bg_x; + SetGpuReg(REG_OFFSET_BG2X_H, (u16)(temp1 >> 0x10)); + SetGpuReg(REG_OFFSET_BG2X_L, (u16)(temp1)); + } + break; + case 3: + if (mode == 0) + { + SetGpuReg(REG_OFFSET_BG3HOFS, gUnknown_030008F8[3].bg_x >> 0x8); + } + else if (mode == 2) + { + temp1 = gUnknown_030008F8[3].bg_x; + SetGpuReg(REG_OFFSET_BG2X_H, (u16)(temp1 >> 0x10)); + SetGpuReg(REG_OFFSET_BG2X_L, (u16)(temp1)); + } + break; + } + + return gUnknown_030008F8[bg].bg_x; +} +#else +__attribute__((naked)) +u32 ChangeBgX(u8 bg, u32 value, u8 op) +{ + asm("push {r4-r6,lr}\n\ + add r6, r1, #0\n\ + lsl r0, #24\n\ + lsr r4, r0, #24\n\ + lsl r2, #24\n\ + lsr r5, r2, #24\n\ + add r0, r4, #0\n\ + bl IsInvalidBgDuplicate\n\ + cmp r0, #0\n\ + bne _08001D28\n\ + add r0, r4, #0\n\ + mov r1, #0x1\n\ + bl GetBgControlAttribute\n\ + lsl r0, #16\n\ + cmp r0, #0\n\ + bne _08001D2E\n\ +_08001D28:\n\ + mov r0, #0x1\n\ + neg r0, r0\n\ + b _08001E34\n\ +_08001D2E:\n\ + cmp r5, #0x1\n\ + beq _08001D4C\n\ + cmp r5, #0x1\n\ + ble _08001D3A\n\ + cmp r5, #0x2\n\ + beq _08001D60\n\ +_08001D3A:\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r1, r4, #4\n\ + add r0, #0x8\n\ + add r0, r1, r0\n\ + str r6, [r0]\n\ + add r5, r1, #0\n\ + b _08001D70\n\ + .pool\n\ +_08001D4C:\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r2, r4, #4\n\ + add r0, #0x8\n\ + add r0, r2, r0\n\ + ldr r1, [r0]\n\ + add r1, r6\n\ + b _08001D6C\n\ + .pool\n\ +_08001D60:\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r2, r4, #4\n\ + add r0, #0x8\n\ + add r0, r2, r0\n\ + ldr r1, [r0]\n\ + sub r1, r6\n\ +_08001D6C:\n\ + str r1, [r0]\n\ + add r5, r2, #0\n\ +_08001D70:\n\ + bl GetBgMode\n\ + lsl r0, #24\n\ + lsr r0, #24\n\ + cmp r4, #0x1\n\ + beq _08001DAC\n\ + cmp r4, #0x1\n\ + bgt _08001D8C\n\ + cmp r4, #0\n\ + beq _08001D96\n\ + b _08001E2C\n\ + .pool\n\ +_08001D8C:\n\ + cmp r4, #0x2\n\ + beq _08001DC0\n\ + cmp r4, #0x3\n\ + beq _08001DF8\n\ + b _08001E2C\n\ +_08001D96:\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x8]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x10\n\ + bl SetGpuReg\n\ + b _08001E2C\n\ + .pool\n\ +_08001DAC:\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x18]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x14\n\ + bl SetGpuReg\n\ + b _08001E2C\n\ + .pool\n\ +_08001DC0:\n\ + cmp r0, #0\n\ + bne _08001DD8\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x28]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x18\n\ + bl SetGpuReg\n\ + b _08001E2C\n\ + .pool\n\ +_08001DD8:\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x28]\n\ + lsr r1, r0, #16\n\ + lsl r0, #16\n\ + lsr r4, r0, #16\n\ + mov r0, #0x2A\n\ + bl SetGpuReg\n\ + mov r0, #0x28\n\ + add r1, r4, #0\n\ + bl SetGpuReg\n\ + b _08001E2C\n\ + .pool\n\ +_08001DF8:\n\ + cmp r0, #0\n\ + bne _08001E10\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x38]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x1C\n\ + bl SetGpuReg\n\ + b _08001E2C\n\ + .pool\n\ +_08001E10:\n\ + cmp r0, #0x2\n\ + bne _08001E2C\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x38]\n\ + lsr r1, r0, #16\n\ + lsl r0, #16\n\ + lsr r4, r0, #16\n\ + mov r0, #0x3A\n\ + bl SetGpuReg\n\ + mov r0, #0x38\n\ + add r1, r4, #0\n\ + bl SetGpuReg\n\ +_08001E2C:\n\ + ldr r0, =gUnknown_030008F8\n\ + add r0, #0x8\n\ + add r0, r5, r0\n\ + ldr r0, [r0]\n\ +_08001E34:\n\ + pop {r4-r6}\n\ + pop {r1}\n\ + bx r1\n\ + .pool\n"); +} +#endif // NONMATCHING + +#ifdef NONMATCHING // Probably the stupidest nonmatching ever +u32 GetBgX(u8 bg) +{ + if (IsInvalidBgDuplicate(bg) == FALSE && GetBgControlAttribute(bg, 0x1) != 0) + { + return gUnknown_030008F8[bg].bg_x; + } + else + { + return -1; + } +} +#else +__attribute__((naked)) +u32 GetBgX(u8 bg) +{ + asm("push {r4,lr}\n\ + lsl r0, #24\n\ + lsr r0, #24\n\ + add r4, r0, #0\n\ + bl IsInvalidBgDuplicate\n\ + cmp r0, #0\n\ + bne _08001E70\n\ + add r0, r4, #0\n\ + mov r1, #0x1\n\ + bl GetBgControlAttribute\n\ + lsl r0, #16\n\ + cmp r0, #0\n\ + beq _08001E70\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r1, r4, #4\n\ + add r0, #0x8\n\ + add r1, r0\n\ + ldr r0, [r1]\n\ + b _08001E74\n\ + .pool\n\ +_08001E70:\n\ + mov r0, #0x1\n\ + neg r0, r0\n\ +_08001E74:\n\ + pop {r4}\n\ + pop {r1}\n\ + bx r1\n"); +} +#endif // NONMATCHING + +#ifdef NONMATCHING // Everything that uses temp1 doesn't match +u32 ChangeBgY(u8 bg, u32 value, u8 op) +{ + u8 mode; + u32 temp1; + + if (IsInvalidBgDuplicate(bg) != FALSE || GetBgControlAttribute(bg, 1) == 0) + { + return -1; + } + + switch (op) + { + case 0: + default: + gUnknown_030008F8[bg].bg_y = value; + break; + case 1: + gUnknown_030008F8[bg].bg_y += value; + break; + case 2: + gUnknown_030008F8[bg].bg_y -= value; + break; + } + + mode = GetBgMode(); + + switch (bg) + { + case 0: + SetGpuReg(REG_OFFSET_BG0VOFS, gUnknown_030008F8[0].bg_y >> 0x8); + break; + case 1: + SetGpuReg(REG_OFFSET_BG1VOFS, gUnknown_030008F8[1].bg_y >> 0x8); + break; + case 2: + if (mode == 0) + { + SetGpuReg(REG_OFFSET_BG2VOFS, gUnknown_030008F8[2].bg_y >> 0x8); + } + else + { + temp1 = gUnknown_030008F8[2].bg_y; + + SetGpuReg(REG_OFFSET_BG2Y_H, (u16)(temp1 >> 0x10)); + SetGpuReg(REG_OFFSET_BG2Y_L, (u16)(temp1)); + } + break; + case 3: + if (mode == 0) + { + SetGpuReg(REG_OFFSET_BG3VOFS, gUnknown_030008F8[3].bg_y >> 0x8); + } + else if (mode == 2) + { + temp1 = gUnknown_030008F8[3].bg_y; + + SetGpuReg(REG_OFFSET_BG3Y_H, (u16)(temp1 >> 0x10)); + SetGpuReg(REG_OFFSET_BG3Y_L, (u16)(temp1)); + } + break; + } + + return gUnknown_030008F8[bg].bg_y; +} +#else +__attribute__((naked)) +u32 ChangeBgY(u8 bg, u32 value, u8 op) +{ + asm("push {r4-r6,lr}\n\ + add r6, r1, #0\n\ + lsl r0, #24\n\ + lsr r4, r0, #24\n\ + lsl r2, #24\n\ + lsr r5, r2, #24\n\ + add r0, r4, #0\n\ + bl IsInvalidBgDuplicate\n\ + cmp r0, #0\n\ + bne _08001EA0\n\ + add r0, r4, #0\n\ + mov r1, #0x1\n\ + bl GetBgControlAttribute\n\ + lsl r0, #16\n\ + cmp r0, #0\n\ + bne _08001EA6\n\ +_08001EA0:\n\ + mov r0, #0x1\n\ + neg r0, r0\n\ + b _08001FAC\n\ +_08001EA6:\n\ + cmp r5, #0x1\n\ + beq _08001EC4\n\ + cmp r5, #0x1\n\ + ble _08001EB2\n\ + cmp r5, #0x2\n\ + beq _08001ED8\n\ +_08001EB2:\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r1, r4, #4\n\ + add r0, #0xC\n\ + add r0, r1, r0\n\ + str r6, [r0]\n\ + add r5, r1, #0\n\ + b _08001EE8\n\ + .pool\n\ +_08001EC4:\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r2, r4, #4\n\ + add r0, #0xC\n\ + add r0, r2, r0\n\ + ldr r1, [r0]\n\ + add r1, r6\n\ + b _08001EE4\n\ + .pool\n\ +_08001ED8:\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r2, r4, #4\n\ + add r0, #0xC\n\ + add r0, r2, r0\n\ + ldr r1, [r0]\n\ + sub r1, r6\n\ +_08001EE4:\n\ + str r1, [r0]\n\ + add r5, r2, #0\n\ +_08001EE8:\n\ + bl GetBgMode\n\ + lsl r0, #24\n\ + lsr r0, #24\n\ + cmp r4, #0x1\n\ + beq _08001F24\n\ + cmp r4, #0x1\n\ + bgt _08001F04\n\ + cmp r4, #0\n\ + beq _08001F0E\n\ + b _08001FA4\n\ + .pool\n\ +_08001F04:\n\ + cmp r4, #0x2\n\ + beq _08001F38\n\ + cmp r4, #0x3\n\ + beq _08001F70\n\ + b _08001FA4\n\ +_08001F0E:\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0xC]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x12\n\ + bl SetGpuReg\n\ + b _08001FA4\n\ + .pool\n\ +_08001F24:\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x1C]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x16\n\ + bl SetGpuReg\n\ + b _08001FA4\n\ + .pool\n\ +_08001F38:\n\ + cmp r0, #0\n\ + bne _08001F50\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x2C]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x1A\n\ + bl SetGpuReg\n\ + b _08001FA4\n\ + .pool\n\ +_08001F50:\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x2C]\n\ + lsr r1, r0, #16\n\ + lsl r0, #16\n\ + lsr r4, r0, #16\n\ + mov r0, #0x2E\n\ + bl SetGpuReg\n\ + mov r0, #0x2C\n\ + add r1, r4, #0\n\ + bl SetGpuReg\n\ + b _08001FA4\n\ + .pool\n\ +_08001F70:\n\ + cmp r0, #0\n\ + bne _08001F88\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x3C]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x1E\n\ + bl SetGpuReg\n\ + b _08001FA4\n\ + .pool\n\ +_08001F88:\n\ + cmp r0, #0x2\n\ + bne _08001FA4\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x3C]\n\ + lsr r1, r0, #16\n\ + lsl r0, #16\n\ + lsr r4, r0, #16\n\ + mov r0, #0x3E\n\ + bl SetGpuReg\n\ + mov r0, #0x3C\n\ + add r1, r4, #0\n\ + bl SetGpuReg\n\ +_08001FA4:\n\ + ldr r0, =gUnknown_030008F8\n\ + add r0, #0xC\n\ + add r0, r5, r0\n\ + ldr r0, [r0]\n\ +_08001FAC:\n\ + pop {r4-r6}\n\ + pop {r1}\n\ + bx r1\n\ + .pool\n"); +} +#endif // NONMATCHING + +#ifdef NONMATCHING // Same issue as ChangeBgX and ChangeBgY +u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op) +{ + u8 mode; + u16 temp1; + + if (IsInvalidBgDuplicate(bg) != FALSE || GetBgControlAttribute(bg, 1) == 0) + { + return -1; + } + + switch (op) + { + case 0: + default: + gUnknown_030008F8[bg].bg_y = value; + break; + case 1: + gUnknown_030008F8[bg].bg_y += value; + break; + case 2: + gUnknown_030008F8[bg].bg_y -= value; + break; + } + + mode = GetBgMode(); + + switch (bg) + { + case 0: + SetGpuReg_ForcedBlank(REG_OFFSET_BG0VOFS, gUnknown_030008F8[0].bg_y >> 0x8); + break; + case 1: + SetGpuReg_ForcedBlank(REG_OFFSET_BG1VOFS, gUnknown_030008F8[1].bg_y >> 0x8); + break; + case 2: + if (mode == 0) + { + SetGpuReg_ForcedBlank(REG_OFFSET_BG2VOFS, gUnknown_030008F8[2].bg_y >> 0x8); + + } + else + { + temp1 = gUnknown_030008F8[2].bg_y; + + SetGpuReg_ForcedBlank(REG_OFFSET_BG2Y_H, (gUnknown_030008F8[2].bg_y >> 0x10)); + SetGpuReg_ForcedBlank(REG_OFFSET_BG2Y_L, (temp1)); + } + break; + case 3: + if (mode == 0) + { + SetGpuReg_ForcedBlank(REG_OFFSET_BG3VOFS, gUnknown_030008F8[3].bg_y >> 0x8); + } + else if (mode == 2) + { + temp1 = gUnknown_030008F8[3].bg_y; + + SetGpuReg_ForcedBlank(REG_OFFSET_BG3Y_H, (gUnknown_030008F8[3].bg_y >> 0x10)); + SetGpuReg_ForcedBlank(REG_OFFSET_BG3Y_L, (temp1)); + } + break; + } + + return gUnknown_030008F8[bg].bg_y; +} +#else +__attribute__((naked)) +u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op) +{ + asm("push {r4-r6,lr}\n\ + add r6, r1, #0\n\ + lsl r0, #24\n\ + lsr r4, r0, #24\n\ + lsl r2, #24\n\ + lsr r5, r2, #24\n\ + add r0, r4, #0\n\ + bl IsInvalidBgDuplicate\n\ + cmp r0, #0\n\ + bne _08001FDC\n\ + add r0, r4, #0\n\ + mov r1, #0x1\n\ + bl GetBgControlAttribute\n\ + lsl r0, #16\n\ + cmp r0, #0\n\ + bne _08001FE2\n\ +_08001FDC:\n\ + mov r0, #0x1\n\ + neg r0, r0\n\ + b _080020E8\n\ +_08001FE2:\n\ + cmp r5, #0x1\n\ + beq _08002000\n\ + cmp r5, #0x1\n\ + ble _08001FEE\n\ + cmp r5, #0x2\n\ + beq _08002014\n\ +_08001FEE:\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r1, r4, #4\n\ + add r0, #0xC\n\ + add r0, r1, r0\n\ + str r6, [r0]\n\ + add r5, r1, #0\n\ + b _08002024\n\ + .pool\n\ +_08002000:\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r2, r4, #4\n\ + add r0, #0xC\n\ + add r0, r2, r0\n\ + ldr r1, [r0]\n\ + add r1, r6\n\ + b _08002020\n\ + .pool\n\ +_08002014:\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r2, r4, #4\n\ + add r0, #0xC\n\ + add r0, r2, r0\n\ + ldr r1, [r0]\n\ + sub r1, r6\n\ +_08002020:\n\ + str r1, [r0]\n\ + add r5, r2, #0\n\ +_08002024:\n\ + bl GetBgMode\n\ + lsl r0, #24\n\ + lsr r0, #24\n\ + cmp r4, #0x1\n\ + beq _08002060\n\ + cmp r4, #0x1\n\ + bgt _08002040\n\ + cmp r4, #0\n\ + beq _0800204A\n\ + b _080020E0\n\ + .pool\n\ +_08002040:\n\ + cmp r4, #0x2\n\ + beq _08002074\n\ + cmp r4, #0x3\n\ + beq _080020AC\n\ + b _080020E0\n\ +_0800204A:\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0xC]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x12\n\ + bl SetGpuReg_ForcedBlank\n\ + b _080020E0\n\ + .pool\n\ +_08002060:\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x1C]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x16\n\ + bl SetGpuReg_ForcedBlank\n\ + b _080020E0\n\ + .pool\n\ +_08002074:\n\ + cmp r0, #0\n\ + bne _0800208C\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x2C]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x1A\n\ + bl SetGpuReg_ForcedBlank\n\ + b _080020E0\n\ + .pool\n\ +_0800208C:\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x2C]\n\ + lsr r1, r0, #16\n\ + lsl r0, #16\n\ + lsr r4, r0, #16\n\ + mov r0, #0x2E\n\ + bl SetGpuReg_ForcedBlank\n\ + mov r0, #0x2C\n\ + add r1, r4, #0\n\ + bl SetGpuReg_ForcedBlank\n\ + b _080020E0\n\ + .pool\n\ +_080020AC:\n\ + cmp r0, #0\n\ + bne _080020C4\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x3C]\n\ + lsl r0, #8\n\ + lsr r1, r0, #16\n\ + mov r0, #0x1E\n\ + bl SetGpuReg_ForcedBlank\n\ + b _080020E0\n\ + .pool\n\ +_080020C4:\n\ + cmp r0, #0x2\n\ + bne _080020E0\n\ + ldr r0, =gUnknown_030008F8\n\ + ldr r0, [r0, #0x3C]\n\ + lsr r1, r0, #16\n\ + lsl r0, #16\n\ + lsr r4, r0, #16\n\ + mov r0, #0x3E\n\ + bl SetGpuReg_ForcedBlank\n\ + mov r0, #0x3C\n\ + add r1, r4, #0\n\ + bl SetGpuReg_ForcedBlank\n\ +_080020E0:\n\ + ldr r0, =gUnknown_030008F8\n\ + add r0, #0xC\n\ + add r0, r5, r0\n\ + ldr r0, [r0]\n\ +_080020E8:\n\ + pop {r4-r6}\n\ + pop {r1}\n\ + bx r1\n\ + .pool\n"); +} +#endif // NONMATCHING + +#ifdef NONMATCHING // Probably the stupidest nonmatching ever, electric boogaloo +u32 GetBgY(u8 bg) +{ + if (IsInvalidBgDuplicate(bg) != FALSE || GetBgControlAttribute(bg, 0x1) == 0) + { + return gUnknown_030008F8[bg].bg_y; + } + else + { + return -1; + } +} +#else +__attribute__((naked)) +u32 GetBgY(u8 bg) +{ + asm("push {r4,lr}\n\ + lsl r0, #24\n\ + lsr r0, #24\n\ + add r4, r0, #0\n\ + bl IsInvalidBgDuplicate\n\ + cmp r0, #0\n\ + bne _08002124\n\ + add r0, r4, #0\n\ + mov r1, #0x1\n\ + bl GetBgControlAttribute\n\ + lsl r0, #16\n\ + cmp r0, #0\n\ + beq _08002124\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r1, r4, #4\n\ + add r0, #0xC\n\ + add r1, r0\n\ + ldr r0, [r1]\n\ + b _08002128\n\ + .pool\n\ +_08002124:\n\ + mov r0, #0x1\n\ + neg r0, r0\n\ +_08002128:\n\ + pop {r4}\n\ + pop {r1}\n\ + bx r1\n"); +} +#endif // NONMATCHING + +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 (IsInvalidBgDuplicate(bg) == FALSE && GetBgControlAttribute(bg, 0x1) != 0x0) + { + gUnknown_030008F8[bg].tilemap = tilemap; + } +} + +void UnsetBgTilemapBuffer(u8 bg) +{ + if (IsInvalidBgDuplicate(bg) == FALSE && GetBgControlAttribute(bg, 0x1) != 0x0) + { + gUnknown_030008F8[bg].tilemap = NULL; + } +} + +#ifdef NONMATCHING // Probably the stupidest nonmatching ever pt 3 +void* GetBgTilemapBuffer(u8 bg) +{ + if (IsInvalidBgDuplicate(bg) == FALSE && GetBgControlAttribute(bg, 0x1) != 0) + { + return gUnknown_030008F8[bg].tilemap; + } + else + { + return NULL; + } +} +#else +__attribute__((naked)) +void* GetBgTilemapBuffer(u8 bg) +{ + asm("push {r4,lr}\n\ + lsl r0, #24\n\ + lsr r0, #24\n\ + add r4, r0, #0\n\ + bl IsInvalidBgDuplicate\n\ + cmp r0, #0\n\ + bne _080022E8\n\ + add r0, r4, #0\n\ + mov r1, #0x1\n\ + bl GetBgControlAttribute\n\ + lsl r0, #16\n\ + cmp r0, #0\n\ + beq _080022E8\n\ + ldr r0, =gUnknown_030008F8\n\ + lsl r1, r4, #4\n\ + add r0, #0x4\n\ + add r1, r0\n\ + ldr r0, [r1]\n\ + b _080022EA\n\ + .pool\n\ +_080022E8:\n\ + mov r0, #0\n\ +_080022EA:\n\ + pop {r4}\n\ + pop {r1}\n\ + bx r1\n"); +} +#endif // NONMATCHING + +void CopyToBgTilemapBuffer(u8 bg, void *src, u16 mode, u16 destOffset) +{ + if (IsInvalidBgDuplicate(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + { + if (mode != 0) + { + CpuCopy16(src, (void *)(gUnknown_030008F8[bg].tilemap + (destOffset * 2)), mode); + } + else + { + LZ77UnCompWram(src, (void *)(gUnknown_030008F8[bg].tilemap + (destOffset * 2))); + } + } +} + +void CopyBgTilemapBufferToVram(u8 bg) +{ + u16 sizeToLoad; + + if (IsInvalidBgDuplicate(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, gUnknown_030008F8[bg].tilemap, sizeToLoad, 0, 2); + } +} + +void CopyToBgTilemapBufferRect(u8 bg, void* src, u8 destX, u8 destY, u8 width, u8 height) +{ + s16 finalX; + s16 finalY; + u16 test; + + if (IsInvalidBgDuplicate(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + { + switch (GetBgType(bg)) + { + case 0: + for (finalY = destY + height; destY < finalY; destY++) + { + for (finalX = destX + width; destX < finalX; destX++) + { + ((u16*)gUnknown_030008F8[bg].tilemap)[((destY * 0x20) + destX)] = *((u16*)src)++; + } + } + break; + case 1: + test = GetBgMetricAffineMode(bg, 0x1); + for (finalY = destY + height; destY < finalY; destY++) + { + for (finalX = destX + width; destX < finalX; destX++) + { + ((u8*)gUnknown_030008F8[bg].tilemap)[((destY * test) + destX)] = *((u8*)src)++; + } + } + break; + } + } +}