diff --git a/asm/bg.s b/asm/bg.s index 492e8b990..4526f8116 100644 --- a/asm/bg.s +++ b/asm/bg.s @@ -680,7 +680,7 @@ _080017CC: subs r0, 0x4 cmp r0, r1 bge _080017CC - ldr r0, =gUnknown_03002F54 + ldr r0, =gUnneededFireRedVariable str r4, [r0] pop {r4} pop {r0} @@ -934,7 +934,7 @@ _080019B8: ldr r0, [r2] orrs r0, r1 str r0, [r2] - ldr r0, =gUnknown_03002F54 + ldr r0, =gUnneededFireRedVariable ldr r0, [r0] cmp r0, 0x1 bne _080019E4 diff --git a/asm/window.s b/asm/window.s index 602f2a156..6bb76d594 100644 --- a/asm/window.s +++ b/asm/window.s @@ -5,1394 +5,6 @@ .text - thumb_func_start nullsub_8 -nullsub_8: @ 80031BC - bx lr - thumb_func_end nullsub_8 - - thumb_func_start InitWindows -@ bool16 InitWindows(struct WindowTemplate *templates) -InitWindows: @ 80031C0 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r5, r0, 0 - movs r0, 0 - mov r8, r0 - ldr r4, =gUnknown_03002F70 -_080031D4: - mov r1, r8 - lsls r0, r1, 24 - lsrs r0, 24 - bl GetBgTilemapBuffer - cmp r0, 0 - beq _080031E4 - ldr r0, =nullsub_8 -_080031E4: - str r0, [r4] - adds r4, 0x4 - movs r2, 0x1 - add r8, r2 - mov r0, r8 - cmp r0, 0x3 - ble _080031D4 - ldr r0, =gDummyWindowTemplate - ldr r2, [r0] - ldr r3, [r0, 0x4] - ldr r1, =gWindows - movs r0, 0 - movs r4, 0x1F - mov r8, r4 -_08003200: - str r2, [r1] - str r3, [r1, 0x4] - str r0, [r1, 0x8] - adds r1, 0xC - movs r4, 0x1 - negs r4, r4 - add r8, r4 - mov r4, r8 - cmp r4, 0 - bge _08003200 - movs r0, 0 - mov r8, r0 - movs r1, 0 - str r1, [sp] - ldrb r7, [r5] - cmp r7, 0xFF - bne _08003224 - b _0800335C -_08003224: - adds r6, r5, 0 - movs r2, 0 - str r2, [sp, 0x4] -_0800322A: - ldr r0, =gUnknown_03002F54 - ldr r0, [r0] - cmp r0, 0x1 - bne _08003268 - ldrb r1, [r6, 0x3] - ldrb r0, [r6, 0x4] - adds r2, r1, 0 - muls r2, r0 - adds r0, r7, 0 - movs r1, 0 - movs r3, 0 - bl DummiedOutFireRedLeafGreenTileAllocFunc - str r0, [sp] - movs r0, 0x1 - negs r0, r0 - ldr r4, [sp] - cmp r4, r0 - bne _08003268 -_08003250: - movs r0, 0 - b _08003364 - .pool -_08003268: - ldr r0, =gUnknown_03002F70 - mov r9, r0 - lsls r0, r7, 2 - mov r2, r9 - adds r1, r0, r2 - ldr r1, [r1] - mov r10, r0 - cmp r1, 0 - bne _080032CA - adds r0, r7, 0 - movs r1, 0x8 - bl GetBgAttribute - lsls r0, 16 - lsrs r5, r0, 16 - ldr r0, =0x0000ffff - cmp r5, r0 - beq _080032CA - adds r0, r5, 0 - bl AllocZeroed - adds r4, r0, 0 - cmp r4, 0 - bne _080032A8 - bl FreeAllWindowBuffers - b _08003250 - .pool -_080032A8: - movs r1, 0 - mov r3, r9 - cmp r1, r5 - bge _080032BC - movs r2, 0 -_080032B2: - adds r0, r4, r1 - strb r2, [r0] - adds r1, 0x1 - cmp r1, r5 - blt _080032B2 -_080032BC: - mov r1, r10 - adds r0, r1, r3 - str r4, [r0] - adds r0, r7, 0 - adds r1, r4, 0 - bl SetBgTilemapBuffer -_080032CA: - ldrb r1, [r6, 0x3] - ldrb r0, [r6, 0x4] - muls r0, r1 - lsls r0, 21 - lsrs r0, 16 - bl AllocZeroed - adds r4, r0, 0 - cmp r4, 0 - bne _0800330C - adds r0, r7, 0 - bl GetNumActiveWindowsOnBg - lsls r0, 24 - cmp r0, 0 - bne _08003250 - ldr r0, =gUnknown_03002F70 - mov r2, r10 - adds r5, r2, r0 - ldr r1, [r5] - ldr r0, =nullsub_8 - cmp r1, r0 - beq _08003250 - adds r0, r1, 0 - bl Free - str r4, [r5] - b _08003250 - .pool -_0800330C: - ldr r1, =gWindows - adds r0, r1, 0 - adds r0, 0x8 - ldr r2, [sp, 0x4] - adds r0, r2, r0 - str r4, [r0] - adds r2, r1 - ldr r0, [r6] - ldr r1, [r6, 0x4] - str r0, [r2] - str r1, [r2, 0x4] - ldr r0, =gUnknown_03002F54 - ldr r0, [r0] - cmp r0, 0x1 - bne _08003342 - mov r4, sp - ldrh r4, [r4] - strh r4, [r2, 0x6] - ldrb r0, [r6, 0x3] - ldrb r1, [r6, 0x4] - adds r2, r0, 0 - muls r2, r1 - adds r0, r7, 0 - ldr r1, [sp] - movs r3, 0x1 - bl DummiedOutFireRedLeafGreenTileAllocFunc -_08003342: - adds r6, 0x8 - ldr r0, [sp, 0x4] - adds r0, 0xC - str r0, [sp, 0x4] - movs r1, 0x1 - add r8, r1 - ldrb r7, [r6] - cmp r7, 0xFF - beq _0800335C - mov r2, r8 - cmp r2, 0x1F - bgt _0800335C - b _0800322A -_0800335C: - ldr r1, =gUnknown_03002F60 - movs r0, 0 - strb r0, [r1] - movs r0, 0x1 -_08003364: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end InitWindows - - thumb_func_start AddWindow -@ u8 AddWindow(struct WindowTemplate *template) -AddWindow: @ 8003380 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - mov r8, r0 - movs r6, 0 - ldr r1, =gWindows - ldrb r0, [r1] - cmp r0, 0xFF - beq _080033B0 -_08003398: - adds r0, r6, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 - cmp r6, 0x1F - bhi _080033B0 - lsls r0, r6, 1 - adds r0, r6 - lsls r0, 2 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0xFF - bne _08003398 -_080033B0: - cmp r6, 0x20 - beq _0800346A - mov r0, r8 - ldrb r7, [r0] - movs r1, 0 - mov r9, r1 - ldr r0, =gUnknown_03002F54 - ldr r0, [r0] - cmp r0, 0x1 - bne _080033E2 - mov r2, r8 - ldrb r1, [r2, 0x3] - ldrb r0, [r2, 0x4] - adds r2, r1, 0 - muls r2, r0 - adds r0, r7, 0 - movs r1, 0 - movs r3, 0 - bl DummiedOutFireRedLeafGreenTileAllocFunc - mov r9, r0 - movs r0, 0x1 - negs r0, r0 - cmp r9, r0 - beq _0800346A -_080033E2: - ldr r3, =gUnknown_03002F70 - mov r10, r3 - lsls r0, r7, 2 - adds r1, r0, r3 - ldr r1, [r1] - str r0, [sp] - cmp r1, 0 - bne _08003432 - adds r0, r7, 0 - movs r1, 0x8 - bl GetBgAttribute - lsls r0, 16 - lsrs r5, r0, 16 - ldr r0, =0x0000ffff - cmp r5, r0 - beq _08003432 - adds r0, r5, 0 - bl AllocZeroed - adds r4, r0, 0 - cmp r4, 0 - beq _0800346A - movs r1, 0 - mov r3, r10 - cmp r1, r5 - bge _08003424 - movs r2, 0 -_0800341A: - adds r0, r4, r1 - strb r2, [r0] - adds r1, 0x1 - cmp r1, r5 - blt _0800341A -_08003424: - ldr r1, [sp] - adds r0, r1, r3 - str r4, [r0] - adds r0, r7, 0 - adds r1, r4, 0 - bl SetBgTilemapBuffer -_08003432: - mov r2, r8 - ldrb r1, [r2, 0x3] - ldrb r0, [r2, 0x4] - muls r0, r1 - lsls r0, 21 - lsrs r0, 16 - bl AllocZeroed - adds r4, r0, 0 - cmp r4, 0 - bne _08003484 - adds r0, r7, 0 - bl GetNumActiveWindowsOnBg - lsls r0, 24 - cmp r0, 0 - bne _0800346A - ldr r0, =gUnknown_03002F70 - ldr r3, [sp] - adds r5, r3, r0 - ldr r1, [r5] - ldr r0, =nullsub_8 - cmp r1, r0 - beq _0800346A - adds r0, r1, 0 - bl Free - str r4, [r5] -_0800346A: - movs r0, 0xFF - b _080034C0 - .pool -_08003484: - ldr r2, =gWindows - lsls r1, r6, 1 - adds r1, r6 - lsls r1, 2 - adds r0, r2, 0 - adds r0, 0x8 - adds r0, r1, r0 - str r4, [r0] - adds r2, r1, r2 - mov r3, r8 - ldr r0, [r3] - ldr r1, [r3, 0x4] - str r0, [r2] - str r1, [r2, 0x4] - ldr r0, =gUnknown_03002F54 - ldr r0, [r0] - cmp r0, 0x1 - bne _080034BE - mov r0, r9 - strh r0, [r2, 0x6] - ldrb r0, [r2, 0x3] - ldrb r1, [r2, 0x4] - adds r2, r0, 0 - muls r2, r1 - adds r0, r7, 0 - mov r1, r9 - movs r3, 0x1 - bl DummiedOutFireRedLeafGreenTileAllocFunc -_080034BE: - adds r0, r6, 0 -_080034C0: - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end AddWindow - - thumb_func_start AddWindowWithoutTileMap -@ int AddWindowWithoutTileMap(struct WindowTemplate *template) -AddWindowWithoutTileMap: @ 80034D8 - push {r4-r6,lr} - adds r5, r0, 0 - movs r4, 0 - ldr r1, =gWindows - ldrb r0, [r1] - cmp r0, 0xFF - beq _080034FE -_080034E6: - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0x1F - bhi _080034FE - lsls r0, r4, 1 - adds r0, r4 - lsls r0, 2 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0xFF - bne _080034E6 -_080034FE: - cmp r4, 0x20 - beq _08003528 - ldrb r6, [r5] - movs r3, 0 - ldr r0, =gUnknown_03002F54 - ldr r0, [r0] - cmp r0, 0x1 - bne _08003534 - ldrb r1, [r5, 0x3] - ldrb r0, [r5, 0x4] - adds r2, r1, 0 - muls r2, r0 - adds r0, r6, 0 - movs r1, 0 - bl DummiedOutFireRedLeafGreenTileAllocFunc - adds r3, r0, 0 - movs r0, 0x1 - negs r0, r0 - cmp r3, r0 - bne _08003534 -_08003528: - movs r0, 0xFF - b _08003564 - .pool -_08003534: - ldr r1, =gWindows - lsls r0, r4, 1 - adds r0, r4 - lsls r0, 2 - adds r2, r0, r1 - ldr r0, [r5] - ldr r1, [r5, 0x4] - str r0, [r2] - str r1, [r2, 0x4] - ldr r0, =gUnknown_03002F54 - ldr r0, [r0] - cmp r0, 0x1 - bne _08003562 - strh r3, [r2, 0x6] - ldrb r0, [r2, 0x3] - ldrb r1, [r2, 0x4] - adds r2, r0, 0 - muls r2, r1 - adds r0, r6, 0 - adds r1, r3, 0 - movs r3, 0x1 - bl DummiedOutFireRedLeafGreenTileAllocFunc -_08003562: - adds r0, r4, 0 -_08003564: - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end AddWindowWithoutTileMap - - thumb_func_start RemoveWindow -@ void RemoveWindow(u8 windowId) -RemoveWindow: @ 8003574 - push {r4-r7,lr} - lsls r0, 24 - lsrs r6, r0, 24 - ldr r1, =gWindows - lsls r0, r6, 1 - adds r0, r6 - lsls r0, 2 - adds r4, r0, r1 - ldrb r3, [r4] - adds r7, r3, 0 - ldr r0, =gUnknown_03002F54 - ldr r0, [r0] - cmp r0, 0x1 - bne _080035A0 - ldrh r1, [r4, 0x6] - ldrb r2, [r4, 0x3] - ldrb r0, [r4, 0x4] - muls r2, r0 - adds r0, r3, 0 - movs r3, 0x2 - bl DummiedOutFireRedLeafGreenTileAllocFunc -_080035A0: - ldr r0, =gDummyWindowTemplate - ldr r1, [r0, 0x4] - ldr r0, [r0] - str r0, [r4] - str r1, [r4, 0x4] - adds r0, r7, 0 - bl GetNumActiveWindowsOnBg - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0 - bne _080035CE - ldr r0, =gUnknown_03002F70 - lsls r1, r7, 2 - adds r4, r1, r0 - ldr r1, [r4] - ldr r0, =nullsub_8 - cmp r1, r0 - beq _080035CE - adds r0, r1, 0 - bl Free - str r5, [r4] -_080035CE: - ldr r1, =gWindows - lsls r0, r6, 1 - adds r0, r6 - lsls r0, 2 - adds r1, 0x8 - adds r4, r0, r1 - ldr r0, [r4] - cmp r0, 0 - beq _080035E8 - bl Free - movs r0, 0 - str r0, [r4] -_080035E8: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end RemoveWindow - - thumb_func_start FreeAllWindowBuffers -@ void FreeAllWindowBuffers() -FreeAllWindowBuffers: @ 8003604 - push {r4-r6,lr} - ldr r4, =gUnknown_03002F70 - movs r5, 0x3 -_0800360A: - ldr r1, [r4] - cmp r1, 0 - beq _08003620 - ldr r0, =nullsub_8 - cmp r1, r0 - beq _08003620 - adds r0, r1, 0 - bl Free - movs r0, 0 - str r0, [r4] -_08003620: - adds r4, 0x4 - subs r5, 0x1 - cmp r5, 0 - bge _0800360A - ldr r0, =gWindows - adds r4, r0, 0 - adds r4, 0x8 - movs r6, 0 - movs r5, 0x1F -_08003632: - ldr r0, [r4] - cmp r0, 0 - beq _0800363E - bl Free - str r6, [r4] -_0800363E: - adds r4, 0xC - subs r5, 0x1 - cmp r5, 0 - bge _08003632 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end FreeAllWindowBuffers - - thumb_func_start CopyWindowToVram -@ void CopyWindowToVram(u8 windowId, u8 mode) -CopyWindowToVram: @ 8003658 - push {r4-r6,lr} - sub sp, 0xC - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r3, r1, 24 - adds r5, r3, 0 - ldr r2, =gWindows - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 2 - mov r0, sp - adds r1, r2 - ldm r1!, {r2,r4,r6} - stm r0!, {r2,r4,r6} - mov r0, sp - ldrb r1, [r0, 0x3] - ldrb r0, [r0, 0x4] - muls r0, r1 - lsls r0, 21 - lsrs r4, r0, 16 - cmp r3, 0x2 - beq _080036A4 - cmp r3, 0x2 - bgt _08003694 - cmp r3, 0x1 - beq _0800369A - b _080036CE - .pool -_08003694: - cmp r5, 0x3 - beq _080036B6 - b _080036CE -_0800369A: - mov r0, sp - ldrb r0, [r0] - bl CopyBgTilemapBufferToVram - b _080036CE -_080036A4: - mov r0, sp - ldrb r0, [r0] - ldr r1, [sp, 0x8] - mov r2, sp - ldrh r3, [r2, 0x6] - adds r2, r4, 0 - bl LoadBgTiles - b _080036CE -_080036B6: - mov r0, sp - ldrb r0, [r0] - ldr r1, [sp, 0x8] - mov r2, sp - ldrh r3, [r2, 0x6] - adds r2, r4, 0 - bl LoadBgTiles - mov r0, sp - ldrb r0, [r0] - bl CopyBgTilemapBufferToVram -_080036CE: - add sp, 0xC - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end CopyWindowToVram - - thumb_func_start CopyWindowRectToVram -@ void CopyWindowRectToVram(int rbox_id, int mode, int x, int y, int w, int h) -CopyWindowRectToVram: @ 80036D8 - push {r4-r7,lr} - sub sp, 0xC - adds r6, r0, 0 - adds r5, r1, 0 - adds r4, r2, 0 - mov r12, r3 - ldr r3, [sp, 0x24] - ldr r0, [sp, 0x20] - cmp r0, 0 - beq _08003782 - cmp r3, 0 - beq _08003782 - ldr r2, =gWindows - lsls r0, r6, 1 - adds r0, r6 - lsls r0, 2 - mov r1, sp - adds r0, r2 - ldm r0!, {r2,r6,r7} - stm r1!, {r2,r6,r7} - subs r2, r3, 0x1 - mov r0, sp - ldrb r1, [r0, 0x3] - adds r3, r2, 0 - muls r3, r1 - subs r0, r1, r4 - adds r3, r0 - ldr r2, [sp, 0x20] - adds r0, r4, r2 - subs r0, r1, r0 - subs r3, r0 - lsls r3, 5 - mov r0, r12 - muls r0, r1 - adds r4, r0, r4 - cmp r5, 0x2 - beq _08003740 - cmp r5, 0x2 - bhi _08003730 - cmp r5, 0x1 - beq _08003736 - b _08003782 - .pool -_08003730: - cmp r5, 0x3 - beq _0800375E - b _08003782 -_08003736: - mov r0, sp - ldrb r0, [r0] - bl CopyBgTilemapBufferToVram - b _08003782 -_08003740: - mov r0, sp - ldrb r0, [r0] - lsls r2, r4, 5 - ldr r1, [sp, 0x8] - adds r1, r2 - lsls r2, r3, 16 - lsrs r2, 16 - mov r3, sp - ldrh r3, [r3, 0x6] - adds r3, r4 - lsls r3, 16 - lsrs r3, 16 - bl LoadBgTiles - b _08003782 -_0800375E: - mov r0, sp - ldrb r0, [r0] - lsls r2, r4, 5 - ldr r1, [sp, 0x8] - adds r1, r2 - lsls r2, r3, 16 - lsrs r2, 16 - mov r3, sp - ldrh r3, [r3, 0x6] - adds r3, r4 - lsls r3, 16 - lsrs r3, 16 - bl LoadBgTiles - mov r0, sp - ldrb r0, [r0] - bl CopyBgTilemapBufferToVram -_08003782: - add sp, 0xC - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end CopyWindowRectToVram - - thumb_func_start PutWindowTilemap -@ void PutWindowTilemap(u8 windowId) -PutWindowTilemap: @ 800378C - push {r4,lr} - sub sp, 0x1C - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gWindows - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 2 - add r0, sp, 0x10 - adds r1, r2 - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - add r0, sp, 0x10 - ldrb r0, [r0] - movs r1, 0xA - bl GetBgAttribute - adds r1, r0, 0 - add r0, sp, 0x10 - ldrh r0, [r0, 0x6] - adds r1, r0 - lsls r1, 16 - lsrs r1, 16 - add r0, sp, 0x10 - ldrb r0, [r0] - add r2, sp, 0x10 - ldrb r2, [r2, 0x1] - add r3, sp, 0x10 - ldrb r3, [r3, 0x2] - add r4, sp, 0x10 - ldrb r4, [r4, 0x3] - str r4, [sp] - add r4, sp, 0x10 - ldrb r4, [r4, 0x4] - str r4, [sp, 0x4] - add r4, sp, 0x10 - ldrb r4, [r4, 0x5] - str r4, [sp, 0x8] - movs r4, 0x1 - str r4, [sp, 0xC] - bl WriteSequenceToBgTilemapBuffer - add sp, 0x1C - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end PutWindowTilemap - - thumb_func_start PutWindowRectTilemapOverridePalette -@ void PutWindowRectTilemapOverridePalette(u8 windowId, u8 x, u8 y, u8 width, u8 height, u8 palette) -PutWindowRectTilemapOverridePalette: @ 80037EC - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x24 - ldr r4, [sp, 0x44] - ldr r5, [sp, 0x48] - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r1, 24 - mov r10, r1 - lsls r2, 24 - lsrs r2, 24 - mov r9, r2 - lsls r3, 24 - lsrs r3, 24 - str r3, [sp, 0x1C] - lsls r4, 24 - lsrs r4, 24 - mov r8, r4 - lsls r5, 24 - lsrs r5, 24 - str r5, [sp, 0x20] - ldr r2, =gWindows - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 2 - add r0, sp, 0x10 - adds r1, r2 - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - add r0, sp, 0x10 - ldrb r0, [r0] - movs r1, 0xA - bl GetBgAttribute - add r2, sp, 0x10 - adds r1, r2, 0 - ldrb r1, [r1, 0x3] - mov r3, r9 - muls r3, r1 - adds r1, r3, 0 - ldrh r2, [r2, 0x6] - adds r1, r2 - add r1, r10 - adds r0, r1 - lsls r0, 16 - lsrs r6, r0, 16 - movs r5, 0 - cmp r5, r8 - bge _0800388E - add r4, sp, 0x10 - movs r7, 0x1 -_0800385A: - ldrb r0, [r4] - ldrb r2, [r4, 0x1] - add r2, r10 - lsls r2, 24 - lsrs r2, 24 - ldrb r3, [r4, 0x2] - add r3, r9 - adds r3, r5 - lsls r3, 24 - lsrs r3, 24 - ldr r1, [sp, 0x1C] - str r1, [sp] - str r7, [sp, 0x4] - ldr r1, [sp, 0x20] - str r1, [sp, 0x8] - str r7, [sp, 0xC] - adds r1, r6, 0 - bl WriteSequenceToBgTilemapBuffer - ldrb r0, [r4, 0x3] - adds r0, r6, r0 - lsls r0, 16 - lsrs r6, r0, 16 - adds r5, 0x1 - cmp r5, r8 - blt _0800385A -_0800388E: - add sp, 0x24 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end PutWindowRectTilemapOverridePalette - - thumb_func_start ClearWindowTilemap -@ void ClearWindowTilemap(u8 windowId) -ClearWindowTilemap: @ 80038A4 - push {r4,lr} - sub sp, 0x18 - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gWindows - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 2 - add r0, sp, 0xC - adds r1, r2 - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - add r0, sp, 0xC - ldrb r0, [r0] - ldr r1, =gUnknown_03002F60 - ldrb r1, [r1] - add r2, sp, 0xC - ldrb r2, [r2, 0x1] - add r3, sp, 0xC - ldrb r3, [r3, 0x2] - add r4, sp, 0xC - ldrb r4, [r4, 0x3] - str r4, [sp] - add r4, sp, 0xC - ldrb r4, [r4, 0x4] - str r4, [sp, 0x4] - add r4, sp, 0xC - ldrb r4, [r4, 0x5] - str r4, [sp, 0x8] - bl FillBgTilemapBufferRect - add sp, 0x18 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end ClearWindowTilemap - - thumb_func_start PutWindowRectTilemap -@ void PutWindowRectTilemap(u8 windowId, u8 x, u8 y, u8 width, u8 height) -PutWindowRectTilemap: @ 80038F4 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - ldr r4, [sp, 0x40] - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r1, 24 - mov r10, r1 - lsls r2, 24 - lsrs r2, 24 - mov r9, r2 - lsls r3, 24 - lsrs r3, 24 - str r3, [sp, 0x1C] - lsls r4, 24 - lsrs r4, 24 - mov r8, r4 - ldr r2, =gWindows - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 2 - add r0, sp, 0x10 - adds r1, r2 - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - add r0, sp, 0x10 - ldrb r0, [r0] - movs r1, 0xA - bl GetBgAttribute - add r2, sp, 0x10 - adds r1, r2, 0 - ldrb r1, [r1, 0x3] - mov r3, r9 - muls r3, r1 - adds r1, r3, 0 - ldrh r2, [r2, 0x6] - adds r1, r2 - add r1, r10 - adds r0, r1 - lsls r0, 16 - lsrs r6, r0, 16 - movs r5, 0 - cmp r5, r8 - bge _0800398E - add r4, sp, 0x10 - movs r7, 0x1 -_0800395A: - ldrb r0, [r4] - ldrb r2, [r4, 0x1] - add r2, r10 - lsls r2, 24 - lsrs r2, 24 - ldrb r3, [r4, 0x2] - add r3, r9 - adds r3, r5 - lsls r3, 24 - lsrs r3, 24 - ldr r1, [sp, 0x1C] - str r1, [sp] - str r7, [sp, 0x4] - ldrb r1, [r4, 0x5] - str r1, [sp, 0x8] - str r7, [sp, 0xC] - adds r1, r6, 0 - bl WriteSequenceToBgTilemapBuffer - ldrb r0, [r4, 0x3] - adds r0, r6, r0 - lsls r0, 16 - lsrs r6, r0, 16 - adds r5, 0x1 - cmp r5, r8 - blt _0800395A -_0800398E: - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end PutWindowRectTilemap - - thumb_func_start BlitBitmapToWindow -@ void BlitBitmapToWindow(u8 windowId, u8 *pixels, u16 x, u16 y, u16 width, u16 height) -BlitBitmapToWindow: @ 80039A4 - push {r4,r5,lr} - sub sp, 0x18 - ldr r4, [sp, 0x24] - ldr r5, [sp, 0x28] - lsls r0, 24 - lsrs r0, 24 - lsls r2, 16 - lsrs r2, 16 - lsls r3, 16 - lsrs r3, 16 - lsls r4, 16 - lsrs r4, 16 - lsls r5, 16 - lsrs r5, 16 - str r4, [sp] - str r5, [sp, 0x4] - str r2, [sp, 0x8] - str r3, [sp, 0xC] - str r4, [sp, 0x10] - str r5, [sp, 0x14] - movs r2, 0 - movs r3, 0 - bl BlitBitmapRectToWindow - add sp, 0x18 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end BlitBitmapToWindow - - thumb_func_start BlitBitmapRectToWindow -@ void BlitBitmapRectToWindow(u8 windowId, u8 *pixels, u16 srcX, u16 srcY, u16 srcWidth, int srcHeight, u16 destX, u16 destY, u16 rectWidth, u16 rectHeight) -BlitBitmapRectToWindow: @ 80039DC - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x24 - ldr r4, [sp, 0x44] - ldr r5, [sp, 0x48] - ldr r6, [sp, 0x4C] - mov r8, r6 - ldr r6, [sp, 0x50] - mov r9, r6 - ldr r6, [sp, 0x54] - mov r10, r6 - ldr r6, [sp, 0x58] - mov r12, r6 - lsls r0, 24 - lsrs r0, 24 - lsls r2, 16 - lsrs r2, 16 - lsls r3, 16 - lsrs r3, 16 - lsls r4, 16 - mov r6, r8 - lsls r6, 16 - lsrs r6, 16 - mov r8, r6 - mov r6, r9 - lsls r6, 16 - lsrs r6, 16 - mov r9, r6 - mov r6, r10 - lsls r6, 16 - lsrs r6, 16 - mov r10, r6 - mov r6, r12 - lsls r6, 16 - lsrs r6, 16 - mov r12, r6 - str r1, [sp, 0x14] - ldr r7, =0xffff0000 - lsls r5, 16 - ldr r6, =0x0000ffff - lsrs r4, 16 - orrs r4, r5 - str r4, [sp, 0x18] - ldr r1, =gWindows - lsls r5, r0, 1 - adds r5, r0 - lsls r5, 2 - adds r0, r1, 0 - adds r0, 0x8 - adds r0, r5, r0 - ldr r0, [r0] - str r0, [sp, 0x1C] - adds r5, r1 - ldrb r0, [r5, 0x3] - lsls r0, 3 - add r1, sp, 0x1C - ldr r4, [r1, 0x4] - ands r4, r7 - orrs r4, r0 - str r4, [r1, 0x4] - ldrb r0, [r5, 0x4] - lsls r0, 19 - ands r6, r4 - orrs r6, r0 - str r6, [r1, 0x4] - mov r0, r8 - str r0, [sp] - mov r6, r9 - str r6, [sp, 0x4] - mov r0, r10 - str r0, [sp, 0x8] - mov r6, r12 - str r6, [sp, 0xC] - movs r0, 0 - str r0, [sp, 0x10] - add r0, sp, 0x14 - bl BlitBitmapRect4Bit - add sp, 0x24 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end BlitBitmapRectToWindow - - thumb_func_start BlitBitmapRectToWindowWithColorKey -@ void BlitBitmapRectToWindowWithColorKey(u8 rbox_id, u8 *pixels, u16 srcX, u16 srcY, u16 srcWidth, int srcHeight, u16 destX, u16 destY, u16 rectWidth, u16 rectHeight, u8 colorKey) -BlitBitmapRectToWindowWithColorKey: @ 8003A9C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x28 - ldr r4, [sp, 0x48] - ldr r5, [sp, 0x4C] - ldr r6, [sp, 0x50] - mov r8, r6 - ldr r7, [sp, 0x54] - mov r9, r7 - ldr r6, [sp, 0x58] - mov r10, r6 - ldr r7, [sp, 0x5C] - mov r12, r7 - ldr r6, [sp, 0x60] - lsls r0, 24 - lsrs r0, 24 - lsls r2, 16 - lsrs r2, 16 - lsls r3, 16 - lsrs r3, 16 - lsls r4, 16 - mov r7, r8 - lsls r7, 16 - lsrs r7, 16 - mov r8, r7 - mov r7, r9 - lsls r7, 16 - lsrs r7, 16 - mov r9, r7 - mov r7, r10 - lsls r7, 16 - lsrs r7, 16 - mov r10, r7 - mov r7, r12 - lsls r7, 16 - lsrs r7, 16 - mov r12, r7 - lsls r6, 24 - lsrs r6, 24 - str r6, [sp, 0x24] - str r1, [sp, 0x14] - lsls r5, 16 - ldr r6, =0x0000ffff - lsrs r4, 16 - orrs r4, r5 - str r4, [sp, 0x18] - ldr r1, =gWindows - lsls r5, r0, 1 - adds r5, r0 - lsls r5, 2 - adds r0, r1, 0 - adds r0, 0x8 - adds r0, r5, r0 - ldr r0, [r0] - str r0, [sp, 0x1C] - adds r5, r1 - ldrb r0, [r5, 0x3] - lsls r0, 3 - add r1, sp, 0x1C - ldr r4, [r1, 0x4] - ldr r7, =0xffff0000 - ands r4, r7 - orrs r4, r0 - str r4, [r1, 0x4] - ldrb r0, [r5, 0x4] - lsls r0, 19 - ands r6, r4 - orrs r6, r0 - str r6, [r1, 0x4] - mov r0, r8 - str r0, [sp] - mov r6, r9 - str r6, [sp, 0x4] - mov r7, r10 - str r7, [sp, 0x8] - mov r0, r12 - str r0, [sp, 0xC] - ldr r6, [sp, 0x24] - str r6, [sp, 0x10] - add r0, sp, 0x14 - bl BlitBitmapRect4Bit - add sp, 0x28 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end BlitBitmapRectToWindowWithColorKey - - thumb_func_start FillWindowPixelRect -@ void FillWindowPixelRect(u8 windowId, u8 fillValue, u16 x, u16 y, u16 width, u16 height) -FillWindowPixelRect: @ 8003B64 - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - sub sp, 0x10 - mov r9, r3 - ldr r3, [sp, 0x28] - ldr r4, [sp, 0x2C] - mov r8, r4 - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r1, 24 - lsls r2, 16 - lsrs r2, 16 - mov r4, r9 - lsls r4, 16 - lsrs r4, 16 - mov r9, r4 - lsls r3, 16 - lsrs r3, 16 - mov r4, r8 - lsls r4, 16 - lsrs r4, 16 - mov r8, r4 - ldr r5, =gWindows - lsls r4, r0, 1 - adds r4, r0 - lsls r4, 2 - adds r0, r5, 0 - adds r0, 0x8 - adds r0, r4, r0 - ldr r0, [r0] - str r0, [sp, 0x8] - adds r4, r5 - ldrb r0, [r4, 0x3] - lsls r0, 3 - ldr r6, =0xffff0000 - ldr r5, [sp, 0xC] - ands r5, r6 - orrs r5, r0 - str r5, [sp, 0xC] - ldrb r4, [r4, 0x4] - lsls r4, 19 - ldr r0, =0x0000ffff - ands r0, r5 - orrs r0, r4 - str r0, [sp, 0xC] - mov r0, r8 - str r0, [sp] - str r1, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r2, 0 - mov r2, r9 - bl FillBitmapRect4Bit - add sp, 0x10 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end FillWindowPixelRect - - thumb_func_start CopyToWindowPixelBuffer -@ void CopyToWindowPixelBuffer(u8 windowId, u8 *src, u32 size, u16 tileOffset) -CopyToWindowPixelBuffer: @ 8003BF0 - push {r4-r6,lr} - adds r6, r1, 0 - lsls r0, 24 - lsrs r4, r0, 24 - lsls r5, r2, 16 - lsls r3, 16 - lsrs r2, r3, 16 - cmp r5, 0 - beq _08003C24 - ldr r1, =gWindows - lsls r0, r4, 1 - adds r0, r4 - lsls r0, 2 - adds r1, 0x8 - adds r0, r1 - lsls r2, 5 - ldr r1, [r0] - adds r1, r2 - lsrs r2, r5, 17 - adds r0, r6, 0 - bl CpuSet - b _08003C3C - .pool -_08003C24: - ldr r1, =gWindows - lsls r0, r4, 1 - adds r0, r4 - lsls r0, 2 - adds r1, 0x8 - adds r0, r1 - lsls r2, 5 - ldr r1, [r0] - adds r1, r2 - adds r0, r6, 0 - bl LZ77UnCompWram -_08003C3C: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end CopyToWindowPixelBuffer - - thumb_func_start FillWindowPixelBuffer -@ void FillWindowPixelBuffer(u8 windowId, u32 fillValue) -FillWindowPixelBuffer: @ 8003C48 - push {r4,r5,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r1, 24 - ldr r5, =gWindows - lsls r4, r0, 1 - adds r4, r0 - lsls r4, 2 - adds r0, r4, r5 - ldrb r2, [r0, 0x3] - ldrb r0, [r0, 0x4] - muls r2, r0 - lsls r0, r1, 24 - lsls r3, r1, 16 - orrs r0, r3 - lsls r3, r1, 8 - orrs r0, r3 - orrs r0, r1 - str r0, [sp] - adds r5, 0x8 - adds r4, r5 - ldr r1, [r4] - lsls r2, 3 - movs r0, 0x80 - lsls r0, 17 - orrs r2, r0 - mov r0, sp - bl CpuFastSet - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end FillWindowPixelBuffer - thumb_func_start ScrollWindow @ void ScrollWindow(u8 windowId, u8 direction, u8 distance, u8 fillValue) ScrollWindow: @ 8003C94 diff --git a/include/gba/macro.h b/include/gba/macro.h index 230fb4383..0217898e8 100644 --- a/include/gba/macro.h +++ b/include/gba/macro.h @@ -27,6 +27,8 @@ #define CpuFastFill16(value, dest, size) CpuFastFill(((value) << 16) | (value), (dest), (size)) +#define CpuFastFill8(value, dest, size) CpuFastFill(((value) << 24) | ((value) << 16) | ((value) << 8) | (value), (dest), (size)) + #define CpuFastCopy(src, dest, size) CpuFastSet(src, dest, ((size)/(32/8) & 0x1FFFFF)) #define DmaSet(dmaNum, src, dest, control) \ diff --git a/include/global.h b/include/global.h index b7038025b..08ccc670b 100644 --- a/include/global.h +++ b/include/global.h @@ -96,4 +96,11 @@ struct SaveBlock2 extern struct SaveBlock2 *gSaveBlock2Ptr; +struct Bitmap // TODO: Find a better spot for this +{ + u8* pixels; + u32 width:16; + u32 height:16; +}; + #endif // GUARD_GLOBAL_H diff --git a/include/text.h b/include/text.h index 9a3434583..d8fc6f89d 100644 --- a/include/text.h +++ b/include/text.h @@ -13,18 +13,6 @@ #define NUM_TEXT_PRINTERS 32 -struct Window -{ - u8 priority; - u8 tilemapLeft; - u8 tilemapTop; - u8 width; - u8 height; - u8 paletteNum; - u16 baseBlock; - u8 *tileData; -}; - struct TextPrinter { struct TextSubPrinter { // TODO: Better name diff --git a/include/window.h b/include/window.h new file mode 100644 index 000000000..ca0520d41 --- /dev/null +++ b/include/window.h @@ -0,0 +1,21 @@ +#ifndef GUARD_WINDOW_H +#define GUARD_WINDOW_H + +struct WindowTemplate +{ + u8 priority; + u8 tilemapLeft; + u8 tilemapTop; + u8 width; + u8 height; + u8 paletteNum; + u16 baseBlock; +}; + +struct Window +{ + struct WindowTemplate window; + u8 *tileData; +}; + +#endif // GUARD_WINDOW_H diff --git a/ld_script.txt b/ld_script.txt index 424963179..8d09ace42 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -47,6 +47,7 @@ SECTIONS { src/gpu_regs.o(.text); asm/bg.o(.text); asm/blit.o(.text); + src/window.o(.text); asm/window.o(.text); src/text.o(.text); asm/sprite.o(.text); diff --git a/src/text.c b/src/text.c index 82b624ad7..835e0f389 100644 --- a/src/text.c +++ b/src/text.c @@ -1,9 +1,9 @@ #include "global.h" #include "text.h" -#include "battle.h" #include "main.h" #include "palette.h" #include "string_util.h" +#include "window.h" extern void FillBitmapRect4Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue); extern void FillWindowPixelRect(u8 windowId, u8 fillValue, u16 x, u16 y, u16 width, u16 height); @@ -15,7 +15,7 @@ extern u32 GetGlyphWidthFont6(u16 glyphId, bool32 isJapanese); extern void audio_play(u16 songNum); extern u8* sub_81AFC74(u8 a1); -EWRAM_DATA struct Window gWindows[20] = {}; +extern struct Window gWindows[20]; EWRAM_DATA struct TextPrinter gTempTextPrinter = {}; EWRAM_DATA struct TextPrinter gTextPrinters[NUM_TEXT_PRINTERS] = {}; diff --git a/src/window.c b/src/window.c new file mode 100644 index 000000000..aeae9e1ed --- /dev/null +++ b/src/window.c @@ -0,0 +1,461 @@ +#include "global.h" +#include "window.h" + +extern u8 gUnknown_03002F60; +extern void* gUnknown_03002F70[]; +extern u32 gUnneededFireRedVariable; +EWRAM_DATA struct Window gWindows[20]; + +extern void* GetBgTilemapBuffer(u8 bg); +extern int DummiedOutFireRedLeafGreenTileAllocFunc(int, int, int, int); +extern u16 GetBgAttribute(u8 bg, u8 attributeId); +extern void *AllocZeroed(u16 size); +extern void FreeAllWindowBuffers(void); +extern void SetBgTilemapBuffer(u8 bg, void *tilemap); +extern u8 GetNumActiveWindowsOnBg(u8 bgId); +extern void Free(void *pointer); +extern void CopyBgTilemapBufferToVram(u8 bg); +extern u8 LoadBgTiles(u8 bg, void *src, u16 size, u16 destOffset); +extern void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 width, u8 height, u8 paletteSlot, u16 tileNumDelta); +extern void FillBgTilemapBufferRect(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height, u8 palette); +extern void BlitBitmapRect4Bit(struct Bitmap *src, struct Bitmap *dest, u16 srcX, u16 srcY, u16 destX, u16 destY, u16 width, u16 height, u8 colorKey); +extern void FillBitmapRect4Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue); + +void BlitBitmapRectToWindow(u8 windowId, const u8 *pixels, u16 srcX, u16 srcY, u16 srcWidth, int srcHeight, u16 destX, u16 destY, u16 rectWidth, u16 rectHeight); + +extern const struct WindowTemplate gDummyWindowTemplate; + +void nullsub_8(void) +{ + +} + +bool16 InitWindows(struct WindowTemplate *templates) +{ + int i; + void *bgTilemapBuffer; + int j; + u8 bgLayer; + u16 attrib; + u8* allocatedTilemapBuffer; + int allocatedBaseBlock; + + for (i = 0; i < 0x4; ++i) + { + bgTilemapBuffer = GetBgTilemapBuffer(i); + if (bgTilemapBuffer != NULL) + gUnknown_03002F70[i] = nullsub_8; + else + gUnknown_03002F70[i] = bgTilemapBuffer; + } + + for (i = 0; i < 0x20; ++i) + { + gWindows[i].window = gDummyWindowTemplate; + gWindows[i].tileData = NULL; + } + + for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].priority; bgLayer != 0xFF && i < 0x20; ++i, bgLayer = templates[i].priority) + { + if (gUnneededFireRedVariable == 1) + { + allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, templates[i].width * templates[i].height, 0); + if (allocatedBaseBlock == -1) + return FALSE; + } + + if (gUnknown_03002F70[bgLayer] == NULL) + { + attrib = GetBgAttribute(bgLayer, 0x8); + + if (attrib != 0xFFFF) + { + allocatedTilemapBuffer = AllocZeroed(attrib); + + if (allocatedTilemapBuffer == NULL) + { + FreeAllWindowBuffers(); + return FALSE; + } + + for (j = 0; j < attrib; ++j) + allocatedTilemapBuffer[j] = 0; + + gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + SetBgTilemapBuffer(bgLayer, allocatedTilemapBuffer); + } + } + + allocatedTilemapBuffer = AllocZeroed(0x20 * (templates[i].width * templates[i].height)); + + if (allocatedTilemapBuffer == NULL) + { + if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gUnknown_03002F70[bgLayer] != nullsub_8)) + { + Free(gUnknown_03002F70[bgLayer]); + gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + } + + return FALSE; + } + + gWindows[i].tileData = allocatedTilemapBuffer; + gWindows[i].window = templates[i]; + + if (gUnneededFireRedVariable == 1) + { + gWindows[i].window.baseBlock = allocatedBaseBlock; + DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, allocatedBaseBlock, templates[i].width * templates[i].height, 1); + } + } + + gUnknown_03002F60 = 0; + return TRUE; +} + +u16 AddWindow(struct WindowTemplate *template) +{ + u16 win; + u8 bgLayer; + int allocatedBaseBlock; + u16 attrib; + u8 *allocatedTilemapBuffer; + int i; + + for (win = 0; win < 0x20; ++win) + { + if ((bgLayer = gWindows[win].window.priority) == 0xFF) + break; + } + + if (win == 0x20) + return 0xFF; + + bgLayer = template->priority; + allocatedBaseBlock = 0; + + if (gUnneededFireRedVariable == 1) + { + allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0); + + if (allocatedBaseBlock == -1) + return 0xFF; + } + + if (gUnknown_03002F70[bgLayer] == NULL) + { + attrib = GetBgAttribute(bgLayer, 0x8); + + if (attrib != 0xFFFF) + { + allocatedTilemapBuffer = AllocZeroed(attrib); + + if (allocatedTilemapBuffer == NULL) + return 0xFF; + + for (i = 0; i < attrib; ++i) + allocatedTilemapBuffer[i] = 0; + + gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + SetBgTilemapBuffer(bgLayer, allocatedTilemapBuffer); + } + } + + allocatedTilemapBuffer = AllocZeroed(0x20 * (template->width * template->height)); + + if (allocatedTilemapBuffer == NULL) + { + if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gUnknown_03002F70[bgLayer] != nullsub_8)) + { + Free(gUnknown_03002F70[bgLayer]); + gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + } + return 0xFF; + } + + gWindows[win].tileData = allocatedTilemapBuffer; + gWindows[win].window = *template; + + if (gUnneededFireRedVariable == 1) + { + gWindows[win].window.baseBlock = allocatedBaseBlock; + DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, allocatedBaseBlock, gWindows[win].window.width * gWindows[win].window.height, 1); + } + + return win; +} + +int AddWindowWithoutTileMap(struct WindowTemplate *template) +{ + u16 win; + u8 bgLayer; + int allocatedBaseBlock; + + for (win = 0; win < 0x20; ++win) + { + if (gWindows[win].window.priority == 0xFF) + break; + } + + if (win == 0x20) + return 0xFF; + + bgLayer = template->priority; + allocatedBaseBlock = 0; + + if (gUnneededFireRedVariable == 1) + { + allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0); + + if (allocatedBaseBlock == -1) + return 0xFF; + } + + gWindows[win].window = *template; + + if (gUnneededFireRedVariable == 1) + { + gWindows[win].window.baseBlock = allocatedBaseBlock; + DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, allocatedBaseBlock, gWindows[win].window.width * gWindows[win].window.height, 1); + } + + return win; +} + +void RemoveWindow(u8 windowId) +{ + u8 bgLayer = gWindows[windowId].window.priority; + + if (gUnneededFireRedVariable == 1) + { + DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, gWindows[windowId].window.baseBlock, gWindows[windowId].window.width * gWindows[windowId].window.height, 2); + } + + gWindows[windowId].window = gDummyWindowTemplate; + + if (GetNumActiveWindowsOnBg(bgLayer) == 0) + { + if (gUnknown_03002F70[bgLayer] != nullsub_8) + { + Free(gUnknown_03002F70[bgLayer]); + gUnknown_03002F70[bgLayer] = 0; + } + } + + if (gWindows[windowId].tileData != NULL) + { + Free(gWindows[windowId].tileData); + gWindows[windowId].tileData = NULL; + } +} + +void FreeAllWindowBuffers(void) +{ + int i; + + for (i = 0; i < 4; ++i) + { + if (gUnknown_03002F70[i] != NULL && gUnknown_03002F70[i] != nullsub_8) + { + Free(gUnknown_03002F70[i]); + gUnknown_03002F70[i] = NULL; + } + } + + for (i = 0; i < 0x20; ++i) + { + if (gWindows[i].tileData != NULL) + { + Free(gWindows[i].tileData); + gWindows[i].tileData = NULL; + } + } +} + +void CopyWindowToVram(u8 windowId, u8 mode) +{ + struct Window windowLocal = gWindows[windowId]; + u16 windowSize = 32 * (windowLocal.window.width * windowLocal.window.height); + + switch (mode) + { + case 1: + CopyBgTilemapBufferToVram(windowLocal.window.priority); + break; + case 2: + LoadBgTiles(windowLocal.window.priority, windowLocal.tileData, windowSize, windowLocal.window.baseBlock); + break; + case 3: + LoadBgTiles(windowLocal.window.priority, windowLocal.tileData, windowSize, windowLocal.window.baseBlock); + CopyBgTilemapBufferToVram(windowLocal.window.priority); + break; + } +} + +void CopyWindowRectToVram(u32 windowId, u32 mode, u32 x, u32 y, u32 w, u32 h) +{ + struct Window windowLocal; + int rectSize; + int rectPos; + + if (w != 0 && h != 0) + { + windowLocal = gWindows[windowId]; + + rectSize = ((h - 1) * windowLocal.window.width); + rectSize += (windowLocal.window.width - x); + rectSize -= (windowLocal.window.width - (x + w)); + rectSize *= 32; + + rectPos = (y * windowLocal.window.width) + x; + + switch (mode) + { + case 1: + CopyBgTilemapBufferToVram(windowLocal.window.priority); + break; + case 2: + LoadBgTiles(windowLocal.window.priority, windowLocal.tileData + (rectPos * 32), rectSize, windowLocal.window.baseBlock + rectPos); + break; + case 3: + LoadBgTiles(windowLocal.window.priority, windowLocal.tileData + (rectPos * 32), rectSize, windowLocal.window.baseBlock + rectPos); + CopyBgTilemapBufferToVram(windowLocal.window.priority); + break; + } + } +} + +void PutWindowTilemap(u8 windowId) +{ + struct Window windowLocal = gWindows[windowId]; + + WriteSequenceToBgTilemapBuffer( + windowLocal.window.priority, + GetBgAttribute(windowLocal.window.priority, 0xA) + windowLocal.window.baseBlock, + windowLocal.window.tilemapLeft, + windowLocal.window.tilemapTop, + windowLocal.window.width, + windowLocal.window.height, + windowLocal.window.paletteNum, + 1); +} + +void PutWindowRectTilemapOverridePalette(u8 windowId, u8 x, u8 y, u8 width, u8 height, u8 palette) +{ + struct Window windowLocal = gWindows[windowId]; + u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.priority, 0xA); + int i; + + for (i = 0; i < height; ++i) + { + WriteSequenceToBgTilemapBuffer( + windowLocal.window.priority, + currentRow, + windowLocal.window.tilemapLeft + x, + windowLocal.window.tilemapTop + y + i, + width, + 1, + palette, + 1); + + currentRow += windowLocal.window.width; + } +} + +void ClearWindowTilemap(u8 windowId) +{ + struct Window windowLocal = gWindows[windowId]; + + FillBgTilemapBufferRect( + windowLocal.window.priority, + gUnknown_03002F60, + windowLocal.window.tilemapLeft, + windowLocal.window.tilemapTop, + windowLocal.window.width, + windowLocal.window.height, + windowLocal.window.paletteNum); +} + +void PutWindowRectTilemap(u8 windowId, u8 x, u8 y, u8 width, u8 height) +{ + struct Window windowLocal = gWindows[windowId]; + u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.priority, 0xA); + int i; + + for (i = 0; i < height; ++i) + { + WriteSequenceToBgTilemapBuffer( + windowLocal.window.priority, + currentRow, + windowLocal.window.tilemapLeft + x, + windowLocal.window.tilemapTop + y + i, + width, + 1, + windowLocal.window.paletteNum, + 1); + + currentRow += windowLocal.window.width; + } +} + +void BlitBitmapToWindow(u8 windowId, u8 *pixels, u16 x, u16 y, u16 width, u16 height) +{ + BlitBitmapRectToWindow(windowId, pixels, 0, 0, width, height, x, y, width, height); +} + +void BlitBitmapRectToWindow(u8 windowId, const u8 *pixels, u16 srcX, u16 srcY, u16 srcWidth, int srcHeight, u16 destX, u16 destY, u16 rectWidth, u16 rectHeight) +{ + struct Bitmap sourceRect; + struct Bitmap destRect; + + sourceRect.pixels = (u8*)pixels; + sourceRect.width = srcWidth; + sourceRect.height = srcHeight; + + destRect.pixels = gWindows[windowId].tileData; + destRect.width = 8 * gWindows[windowId].window.width; + destRect.height = 8 * gWindows[windowId].window.height; + + BlitBitmapRect4Bit(&sourceRect, &destRect, srcX, srcY, destX, destY, rectWidth, rectHeight, 0); +} + +void BlitBitmapRectToWindowWithColorKey(u8 windowId, const u8 *pixels, u16 srcX, u16 srcY, u16 srcWidth, int srcHeight, u16 destX, u16 destY, u16 rectWidth, u16 rectHeight, u8 colorKey) +{ + struct Bitmap sourceRect; + struct Bitmap destRect; + + sourceRect.pixels = (u8*)pixels; + sourceRect.width = srcWidth; + sourceRect.height = srcHeight; + + destRect.pixels = gWindows[windowId].tileData; + destRect.width = 8 * gWindows[windowId].window.width; + destRect.height = 8 * gWindows[windowId].window.height; + + BlitBitmapRect4Bit(&sourceRect, &destRect, srcX, srcY, destX, destY, rectWidth, rectHeight, colorKey); +} + +void FillWindowPixelRect(u8 windowId, u8 fillValue, u16 x, u16 y, u16 width, u16 height) +{ + struct Bitmap pixelRect; + + pixelRect.pixels = gWindows[windowId].tileData; + pixelRect.width = 8 * gWindows[windowId].window.width; + pixelRect.height = 8 * gWindows[windowId].window.height; + + FillBitmapRect4Bit(&pixelRect, x, y, width, height, fillValue); +} + +void CopyToWindowPixelBuffer(u8 windowId, u8 *src, u16 size, u16 tileOffset) +{ + if (size != 0) + CpuCopy16(src, gWindows[windowId].tileData + (0x20 * tileOffset), size); + else + LZ77UnCompWram(src, gWindows[windowId].tileData + (0x20 * tileOffset)); +} + +void FillWindowPixelBuffer(u8 windowId, u8 fillValue) +{ + int fillSize = gWindows[windowId].window.width * gWindows[windowId].window.height; + CpuFastFill8(fillValue, gWindows[windowId].tileData, 0x20 * fillSize); +} diff --git a/sym_common.txt b/sym_common.txt index e8c385a6c..d6f32ee4b 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -39,7 +39,7 @@ IntrMain_Buffer: @ 3002750 gPcmDmaCounter: @ 3002F50 .space 0x4 -gUnknown_03002F54: @ 3002F54 +gUnneededFireRedVariable: @ 3002F54 .space 0xC gUnknown_03002F60: @ 3002F60