diff --git a/asm/credits.s b/asm/credits.s index 0a568a3ae..0b2da16b8 100644 --- a/asm/credits.s +++ b/asm/credits.s @@ -491,14 +491,14 @@ _08175906: ldr r1, =gReservedSpritePaletteCount movs r0, 0x8 strb r0, [r1] - ldr r0, =gUnknown_085B0E04 + ldr r0, =gBirchHelpGfx movs r1, 0xC0 lsls r1, 19 bl LZ77UnCompVram - ldr r0, =gUnknown_085B0C0C + ldr r0, =gBirchGrassTilemap ldr r1, =0x06003800 bl LZ77UnCompVram - ldr r0, =gUnknown_085B0A02 + ldr r0, =gBirchBagGrassPal + 0x2 movs r1, 0x1 movs r2, 0x3E bl LoadPalette diff --git a/asm/save_failed_screen.s b/asm/save_failed_screen.s deleted file mode 100644 index 182ff8954..000000000 --- a/asm/save_failed_screen.s +++ /dev/null @@ -1,707 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_8178F44 -sub_8178F44: @ 8178F44 - push {r4,r5,lr} - sub sp, 0x18 - adds r5, r0, 0 - adds r4, r1, 0 - adds r3, r2, 0 - lsls r3, 24 - add r0, sp, 0x14 - movs r2, 0 - strb r2, [r0] - adds r1, r0, 0 - movs r0, 0xF - strb r0, [r1, 0x1] - movs r0, 0x3 - strb r0, [r1, 0x2] - ldr r0, =gUnknown_0203BD0E - ldrb r0, [r0] - lsls r4, 27 - lsrs r4, 24 - lsrs r3, 21 - adds r3, 0x1 - lsls r3, 24 - lsrs r3, 24 - str r2, [sp] - str r2, [sp, 0x4] - str r1, [sp, 0x8] - str r2, [sp, 0xC] - str r5, [sp, 0x10] - movs r1, 0x1 - adds r2, r4, 0 - bl AddTextPrinterParametrized2 - add sp, 0x18 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8178F44 - - thumb_func_start DoSaveFailedScreen -DoSaveFailedScreen: @ 8178F90 - push {r4,lr} - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - ldr r0, =sub_8178FDC - bl SetMainCallback2 - ldr r0, =gUnknown_0203BCFC - strh r4, [r0] - ldr r1, =gUnknown_0203BCFE - movs r2, 0 - movs r0, 0 - strh r0, [r1] - strh r0, [r1, 0x2] - ldr r0, =gUnknown_0203BD0E - strb r2, [r0] - strb r2, [r0, 0x1] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end DoSaveFailedScreen - - thumb_func_start sub_8178FC8 -sub_8178FC8: @ 8178FC8 - push {lr} - bl LoadOam - bl ProcessSpriteCopyRequests - bl TransferPlttBuffer - pop {r0} - bx r0 - thumb_func_end sub_8178FC8 - - thumb_func_start sub_8178FDC -sub_8178FDC: @ 8178FDC - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0xC - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r7, r0, r1 - ldrb r0, [r7] - cmp r0, 0 - beq _08178FF8 - cmp r0, 0x1 - bne _08178FF8 - b _0817925C -_08178FF8: - movs r0, 0 - bl SetVBlankCallback - movs r0, 0 - movs r1, 0 - bl SetGpuReg - movs r0, 0xE - movs r1, 0 - bl SetGpuReg - movs r0, 0xC - movs r1, 0 - bl SetGpuReg - movs r0, 0xA - movs r1, 0 - bl SetGpuReg - movs r0, 0x8 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1C - movs r1, 0 - bl SetGpuReg - movs r0, 0x1E - movs r1, 0 - bl SetGpuReg - movs r0, 0x18 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1A - movs r1, 0 - bl SetGpuReg - movs r0, 0x14 - movs r1, 0 - bl SetGpuReg - movs r0, 0x16 - movs r1, 0 - bl SetGpuReg - movs r0, 0x10 - movs r1, 0 - bl SetGpuReg - movs r0, 0x12 - movs r1, 0 - bl SetGpuReg - add r1, sp, 0x4 - movs r0, 0 - strh r0, [r1] - ldr r2, =0x040000d4 - str r1, [r2] - movs r1, 0xC0 - lsls r1, 19 - str r1, [r2, 0x4] - ldr r0, =0x8100c000 - str r0, [r2, 0x8] - ldr r0, [r2, 0x8] - movs r3, 0 - mov r8, r3 - str r3, [sp, 0x8] - add r4, sp, 0x8 - str r4, [r2] - movs r0, 0xE0 - lsls r0, 19 - str r0, [r2, 0x4] - ldr r0, =0x85000100 - str r0, [r2, 0x8] - ldr r0, [r2, 0x8] - add r0, sp, 0x4 - mov r3, r8 - strh r3, [r0] - str r0, [r2] - movs r0, 0xA0 - lsls r0, 19 - str r0, [r2, 0x4] - ldr r0, =0x81000200 - str r0, [r2, 0x8] - ldr r0, [r2, 0x8] - ldr r0, =gUnknown_085B0E04 - bl LZ77UnCompVram - ldr r0, =gUnknown_085B0A80 - ldr r1, =0x06007000 - bl LZ77UnCompVram - ldr r0, =gUnknown_085B0C0C - ldr r1, =0x06007800 - bl LZ77UnCompVram - ldr r0, =gUnknown_085EFDE4 - ldr r1, =0x06010020 - bl LZ77UnCompVram - movs r0, 0 - bl ResetBgsAndClearDma3BusyFlags - ldr r1, =gUnknown_085EFD88 - movs r0, 0 - movs r2, 0x3 - bl InitBgsFromTemplates - ldr r5, =0x0201e000 - movs r0, 0 - adds r1, r5, 0 - bl SetBgTilemapBuffer - mov r0, r8 - str r0, [sp, 0x8] - ldr r2, =0x05000200 - adds r0, r4, 0 - adds r1, r5, 0 - bl CpuSet - ldr r1, =gUnknown_0850E87C - movs r2, 0x90 - lsls r2, 1 - movs r6, 0x85 - lsls r6, 2 - movs r0, 0 - adds r3, r6, 0 - bl LoadBgTiles - ldr r0, =gUnknown_085EFD94 - bl InitWindows - ldr r0, =gUnknown_085EFD9C - bl AddWindowWithoutTileMap - ldr r4, =gUnknown_0203BD0E - strb r0, [r4] - ldrb r0, [r4] - movs r1, 0x80 - lsls r1, 4 - adds r2, r5, r1 - movs r1, 0x7 - bl SetWindowAttribute - ldr r0, =gUnknown_085EFDA4 - bl AddWindowWithoutTileMap - strb r0, [r4, 0x1] - ldrb r0, [r4, 0x1] - movs r3, 0xE8 - lsls r3, 5 - adds r5, r3 - movs r1, 0x7 - adds r2, r5, 0 - bl SetWindowAttribute - bl DeactivateAllTextPrinters - bl ResetSpriteData - bl ResetTasks - bl ResetPaletteFade - ldr r0, =gUnknown_085B0A00 - movs r1, 0 - movs r2, 0x40 - bl LoadPalette - ldr r0, =gUnknown_085EFDC4 - movs r1, 0x80 - lsls r1, 1 - movs r2, 0x20 - bl LoadPalette - ldr r0, =gUnknown_0850FEFC - movs r1, 0xE0 - movs r2, 0x20 - bl LoadPalette - ldr r0, =gUnknown_0860F074 - movs r1, 0xF0 - movs r2, 0x20 - bl LoadPalette - ldrb r0, [r4] - movs r1, 0 - adds r2, r6, 0 - movs r3, 0xE - bl SetWindowBorderStyle - ldrb r0, [r4, 0x1] - movs r1, 0 - adds r2, r6, 0 - movs r3, 0xE - bl SetWindowBorderStyle - ldrb r0, [r4, 0x1] - movs r1, 0x11 - bl FillWindowPixelBuffer - ldrb r0, [r4] - movs r1, 0x11 - bl FillWindowPixelBuffer - ldrb r0, [r4, 0x1] - movs r1, 0x2 - bl CopyWindowToVram - ldrb r0, [r4] - movs r1, 0x1 - bl CopyWindowToVram - ldr r0, =gText_SaveFailedCheckingBackup - movs r1, 0x1 - movs r2, 0 - bl sub_8178F44 - movs r0, 0x1 - negs r0, r0 - mov r1, r8 - str r1, [sp] - movs r1, 0 - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade - movs r0, 0x1 - bl EnableInterrupts - ldr r0, =sub_8178FC8 - bl SetVBlankCallback - movs r1, 0x82 - lsls r1, 5 - movs r0, 0 - bl SetGpuReg - movs r0, 0 - bl ShowBg - movs r0, 0x2 - bl ShowBg - movs r0, 0x3 - bl ShowBg - ldrb r0, [r7] - adds r0, 0x1 - strb r0, [r7] - b _08179272 - .pool -_0817925C: - bl UpdatePaletteFade - lsls r0, 24 - cmp r0, 0 - bne _08179272 - ldr r0, =sub_8179288 - bl SetMainCallback2 - ldr r0, =sub_8179454 - bl SetVBlankCallback -_08179272: - add sp, 0xC - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8178FDC - - thumb_func_start sub_8179288 -sub_8179288: @ 8179288 - push {r4-r6,lr} - movs r5, 0 - ldr r0, =gUnknown_0203BCFE - movs r1, 0x1 - strh r1, [r0] - ldr r1, =gDamagedSaveSectors - ldr r0, [r1] - cmp r0, 0 - beq _081792EC - adds r6, r1, 0 -_0817929C: - ldr r0, [r6] - bl sub_81795AC - lsls r0, 24 - cmp r0, 0 - bne _08179348 - ldr r4, =gUnknown_0203BD0E - ldrb r0, [r4] - movs r1, 0x11 - bl FillWindowPixelBuffer - ldr r0, =gText_CheckCompleted - movs r1, 0x1 - movs r2, 0 - bl sub_8178F44 - ldr r0, =gUnknown_0203BCFC - ldrb r0, [r0] - bl HandleSavingData - ldr r0, [r6] - cmp r0, 0 - beq _081792DC - ldrb r0, [r4] - movs r1, 0x11 - bl FillWindowPixelBuffer - ldr r0, =gText_SaveFailedCheckingBackup - movs r1, 0x1 - movs r2, 0 - bl sub_8178F44 -_081792DC: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - ldr r0, [r6] - cmp r0, 0 - beq _081792EC - cmp r5, 0x2 - bls _0817929C -_081792EC: - cmp r5, 0x3 - bne _0817931C - ldr r0, =gUnknown_0203BD0E - ldrb r0, [r0] - movs r1, 0x11 - bl FillWindowPixelBuffer - ldr r0, =gText_BackupMemoryDamaged - b _08179330 - .pool -_0817931C: - ldr r0, =gUnknown_0203BD0E - ldrb r0, [r0] - movs r1, 0x11 - bl FillWindowPixelBuffer - ldr r0, =gGameContinueCallback - ldr r0, [r0] - cmp r0, 0 - bne _08179370 - ldr r0, =gText_SaveCompleteGameCannotContinue -_08179330: - movs r1, 0x1 - movs r2, 0 - bl sub_8178F44 - b _0817937A - .pool -_08179348: - ldr r0, =gUnknown_0203BD0E - ldrb r0, [r0] - movs r1, 0x11 - bl FillWindowPixelBuffer - ldr r0, =gText_BackupMemoryDamaged - movs r1, 0x1 - movs r2, 0 - bl sub_8178F44 - ldr r0, =sub_8179390 - bl SetMainCallback2 - b _08179380 - .pool -_08179370: - ldr r0, =gText_SaveCompletePressA - movs r1, 0x1 - movs r2, 0 - bl sub_8178F44 -_0817937A: - ldr r0, =sub_81793E0 - bl SetMainCallback2 -_08179380: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8179288 - - thumb_func_start sub_8179390 -sub_8179390: @ 8179390 - push {lr} - ldr r1, =gUnknown_0203BCFE - movs r0, 0 - strh r0, [r1] - ldr r0, =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _081793C4 - ldr r0, =gUnknown_0203BD0E - ldrb r0, [r0] - movs r1, 0x11 - bl FillWindowPixelBuffer - ldr r0, =gText_GamePlayCannotBeContinued - movs r1, 0x1 - movs r2, 0 - bl sub_8178F44 - ldr r0, =sub_8178FC8 - bl SetVBlankCallback - ldr r0, =sub_81793E0 - bl SetMainCallback2 -_081793C4: - pop {r0} - bx r0 - .pool - thumb_func_end sub_8179390 - - thumb_func_start sub_81793E0 -sub_81793E0: @ 81793E0 - push {lr} - sub sp, 0x4 - ldr r0, =gUnknown_0203BCFE - movs r2, 0 - strh r2, [r0] - ldr r0, =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _08179410 - movs r0, 0x1 - negs r0, r0 - str r2, [sp] - movs r1, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - ldr r0, =sub_8178FC8 - bl SetVBlankCallback - ldr r0, =sub_8179428 - bl SetMainCallback2 -_08179410: - add sp, 0x4 - pop {r0} - bx r0 - .pool - thumb_func_end sub_81793E0 - - thumb_func_start sub_8179428 -sub_8179428: @ 8179428 - push {r4,r5,lr} - bl UpdatePaletteFade - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0 - bne _0817944E - ldr r5, =gGameContinueCallback - ldr r0, [r5] - cmp r0, 0 - bne _08179448 - bl DoSoftReset - b _0817944E - .pool -_08179448: - bl SetMainCallback2 - str r4, [r5] -_0817944E: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_8179428 - - thumb_func_start sub_8179454 -sub_8179454: @ 8179454 - push {r4,r5,lr} - ldr r5, =gMain - ldr r0, [r5, 0x24] - lsrs r4, r0, 3 - movs r0, 0x7 - ands r4, r0 - ldr r0, =gUnknown_085EFD80 - ldr r1, [r0, 0x4] - ldr r0, [r0] - str r0, [r5, 0x38] - str r1, [r5, 0x3C] - ldrh r1, [r5, 0x3A] - ldr r0, =0xfffffe00 - ands r0, r1 - movs r1, 0x70 - orrs r0, r1 - strh r0, [r5, 0x3A] - adds r1, r5, 0 - adds r1, 0x38 - movs r0, 0x48 - strb r0, [r1] - ldr r0, =gUnknown_0203BCFE - ldrh r0, [r0] - cmp r0, 0 - beq _081794DC - ldr r3, =gUnknown_085EFDAC - lsls r2, r4, 1 - adds r2, r4 - adds r0, r2, r3 - ldrb r4, [r0] - ldrh r1, [r5, 0x3C] - ldr r0, =0xfffffc00 - ands r0, r1 - orrs r0, r4 - strh r0, [r5, 0x3C] - adds r0, r3, 0x2 - adds r0, r2, r0 - ldrb r1, [r0] - lsls r1, 4 - adds r3, 0x1 - adds r2, r3 - ldrb r0, [r2] - lsls r0, 3 - orrs r1, r0 - adds r3, r5, 0 - adds r3, 0x3B - movs r0, 0x1F - ands r1, r0 - lsls r1, 1 - ldrb r2, [r3] - movs r0, 0x3F - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r3] - b _081794E8 - .pool -_081794DC: - ldrh r0, [r5, 0x3C] - ldr r1, =0xfffffc00 - ands r1, r0 - movs r0, 0x1 - orrs r1, r0 - strh r1, [r5, 0x3C] -_081794E8: - ldr r0, =gUnknown_030022F8 - movs r1, 0xE0 - lsls r1, 19 - movs r2, 0x1 - bl CpuFastSet - ldr r1, =gUnknown_0203BCFE - ldrh r0, [r1, 0x2] - cmp r0, 0 - beq _08179500 - subs r0, 0x1 - strh r0, [r1, 0x2] -_08179500: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8179454 - - thumb_func_start sub_8179514 -sub_8179514: @ 8179514 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r4, =gSaveDataBuffer - movs r3, 0x80 - lsls r3, 5 - movs r1, 0 - adds r2, r4, 0 - bl ReadFlash - movs r1, 0 - ldr r2, =0x000003ff -_0817952C: - ldr r0, [r4] - cmp r0, 0 - beq _08179540 - movs r0, 0x1 - b _0817954E - .pool -_08179540: - adds r0, r1, 0x1 - lsls r0, 16 - lsrs r1, r0, 16 - adds r4, 0x4 - cmp r1, r2 - bls _0817952C - movs r0, 0 -_0817954E: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8179514 - - thumb_func_start sub_8179554 -sub_8179554: @ 8179554 - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 16 - lsrs r6, r0, 16 - movs r0, 0 - ldr r1, =0x00000fff - mov r8, r1 - ldr r7, =ProgramFlashByte -_08179566: - movs r4, 0 - adds r5, r0, 0x1 -_0817956A: - ldr r3, [r7] - adds r0, r6, 0 - adds r1, r4, 0 - movs r2, 0 - bl _call_via_r3 - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, r8 - bls _0817956A - adds r0, r6, 0 - bl sub_8179514 - lsls r0, 24 - lsrs r1, r0, 24 - lsls r0, r5, 16 - lsrs r0, 16 - cmp r1, 0 - beq _08179596 - cmp r0, 0x81 - bls _08179566 -_08179596: - adds r0, r1, 0 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_8179554 - - thumb_func_start sub_81795AC -sub_81795AC: @ 81795AC - push {r4-r6,lr} - adds r5, r0, 0 - movs r6, 0 -_081795B2: - movs r4, 0x1 - lsls r4, r6 - adds r0, r5, 0 - ands r0, r4 - cmp r0, 0 - beq _081795CC - adds r0, r6, 0 - bl sub_8179554 - lsls r0, 24 - cmp r0, 0 - bne _081795CC - bics r5, r4 -_081795CC: - adds r0, r6, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 - cmp r6, 0x1F - bls _081795B2 - cmp r5, 0 - beq _081795DE - movs r0, 0x1 - b _081795E0 -_081795DE: - movs r0, 0 -_081795E0: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_81795AC - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/starter_choose.s b/asm/starter_choose.s index 7e998c45f..da42959ea 100644 --- a/asm/starter_choose.s +++ b/asm/starter_choose.s @@ -122,12 +122,12 @@ set_256color_bg_bg0: @ 8133F0C ldr r0, =0x81000200 str r0, [r2, 0x8] ldr r0, [r2, 0x8] - ldr r0, =gUnknown_085B0E04 + ldr r0, =gBirchHelpGfx bl LZ77UnCompVram - ldr r0, =gUnknown_085B0A80 + ldr r0, =gBirchBagTilemap ldr r1, =0x06003000 bl LZ77UnCompVram - ldr r0, =gUnknown_085B0C0C + ldr r0, =gBirchGrassTilemap ldr r1, =0x06003800 bl LZ77UnCompVram movs r0, 0 @@ -155,7 +155,7 @@ set_256color_bg_bg0: @ 8133F0C movs r1, 0xE0 movs r2, 0x20 bl LoadPalette - ldr r0, =gUnknown_085B0A00 + ldr r0, =gBirchBagGrassPal movs r1, 0 movs r2, 0x40 bl LoadPalette diff --git a/data/data4.s b/data/data4.s index 202b1ffe7..d99336e87 100644 --- a/data/data4.s +++ b/data/data4.s @@ -14,19 +14,16 @@ gUnknown_085B09F4:: @ 85B09F4 gUnknown_085B09F8:: @ 85B09F8 .incbin "baserom.gba", 0x5b09f8, 0x8 -gUnknown_085B0A00:: @ 85B0A00 - .incbin "baserom.gba", 0x5b0a00, 0x2 +gBirchBagGrassPal:: @ 85B0A00 + .incbin "baserom.gba", 0x5b0a00, 0x80 -gUnknown_085B0A02:: @ 85B0A02 - .incbin "baserom.gba", 0x5b0a02, 0x7e - -gUnknown_085B0A80:: @ 85B0A80 +gBirchBagTilemap:: @ 85B0A80 .incbin "baserom.gba", 0x5b0a80, 0x18c -gUnknown_085B0C0C:: @ 85B0C0C +gBirchGrassTilemap:: @ 85B0C0C .incbin "baserom.gba", 0x5b0c0c, 0x1f8 -gUnknown_085B0E04:: @ 85B0E04 +gBirchHelpGfx:: @ 85B0E04 .incbin "baserom.gba", 0x5b0e04, 0xfc8 gUnknown_085B1DCC:: @ 85B1DCC diff --git a/data/save_failed_screen.s b/data/save_failed_screen.s deleted file mode 100644 index 446eee2d2..000000000 --- a/data/save_failed_screen.s +++ /dev/null @@ -1,28 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - -gUnknown_085EFD80:: @ 85EFD80 - .incbin "baserom.gba", 0x5efd80, 0x8 - -gUnknown_085EFD88:: @ 85EFD88 - .incbin "baserom.gba", 0x5efd88, 0xc - -gUnknown_085EFD94:: @ 85EFD94 - .incbin "baserom.gba", 0x5efd94, 0x8 - -gUnknown_085EFD9C:: @ 85EFD9C - .incbin "baserom.gba", 0x5efd9c, 0x8 - -gUnknown_085EFDA4:: @ 85EFDA4 - .incbin "baserom.gba", 0x5efda4, 0x8 - -gUnknown_085EFDAC:: @ 85EFDAC - .incbin "baserom.gba", 0x5efdac, 0x18 - -gUnknown_085EFDC4:: @ 85EFDC4 - .incbin "baserom.gba", 0x5efdc4, 0x20 - -gUnknown_085EFDE4:: @ 85EFDE4 - .incbin "baserom.gba", 0x5efde4, 0x90 diff --git a/graphics/misc/clock_small.pal b/graphics/misc/clock_small.pal new file mode 100755 index 000000000..3398fcbe3 --- /dev/null +++ b/graphics/misc/clock_small.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +98 139 90 +0 0 0 +57 57 57 +123 123 123 +189 189 189 +255 255 255 +255 65 41 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 diff --git a/graphics/misc/clock_small.png b/graphics/misc/clock_small.png new file mode 100755 index 000000000..6b9f6c1f7 Binary files /dev/null and b/graphics/misc/clock_small.png differ diff --git a/include/gba/flash_internal.h b/include/gba/flash_internal.h index 6156b6c14..ba84546aa 100644 --- a/include/gba/flash_internal.h +++ b/include/gba/flash_internal.h @@ -65,6 +65,7 @@ u16 ReadFlashId(void); void StartFlashTimer(u8 phase); void SetReadFlash1(u16 *dest); void StopFlashTimer(void); +void ReadFlash(u16 sectorNum, u32 offset, u8 *dest, u32 size); u16 WaitForFlashWrite_Common(u8 phase, u8 *addr, u8 lastData); diff --git a/include/save.h b/include/save.h index e98233c67..6c1238cd2 100644 --- a/include/save.h +++ b/include/save.h @@ -76,7 +76,7 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location); //u8 sub_8125B88(u8 a1, u8 *data, u16 size); u8 DoReadFlashWholeSection(u8, struct SaveSection *); u16 CalculateChecksum(void *, u16); -//u8 HandleSavingData(u8 saveType); +u8 HandleSavingData(u8 saveType); //u8 TrySavingData(u8 saveType); //u8 sub_8125D80(void); //bool8 sub_8125DA8(void); diff --git a/include/window.h b/include/window.h index 4e814ebc6..b630cd316 100644 --- a/include/window.h +++ b/include/window.h @@ -43,7 +43,7 @@ struct Window bool16 InitWindows(const struct WindowTemplate *templates); u16 AddWindow(const struct WindowTemplate *template); -int AddWindowWithoutTileMap(struct WindowTemplate *template); +int AddWindowWithoutTileMap(const struct WindowTemplate *template); void RemoveWindow(u8 windowId); void FreeAllWindowBuffers(void); void CopyWindowToVram(u8 windowId, u8 mode); diff --git a/ld_script.txt b/ld_script.txt index cf8591194..de6ba62f1 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -221,7 +221,7 @@ SECTIONS { asm/diploma.o(.text); asm/berry_tag_screen.o(.text); asm/mystery_event_menu.o(.text); - asm/save_failed_screen.o(.text); + src/save_failed_screen.o(.text); src/braille_puzzles.o(.text); asm/pokeblock_feed.o(.text); asm/clear_save_data_screen.o(.text); @@ -434,7 +434,7 @@ SECTIONS { data/strings.o(.rodata); data/berry_tag_screen.o(.rodata); data/mystery_event_menu.o(.rodata); - data/save_failed_screen.o(.rodata); + src/save_failed_screen.o(.rodata); data/braille_puzzles.o(.rodata); data/pokeblock_feed.o(.rodata); data/clear_save_data_screen.o(.rodata); diff --git a/src/save.c b/src/save.c index aee20d451..2c1b26ca9 100644 --- a/src/save.c +++ b/src/save.c @@ -15,7 +15,6 @@ extern const struct SaveSectionOffsets gSaveSectionOffsets[0xE]; extern void DoSaveFailedScreen(u8); // save_failed_screen extern void LoadSerializedGame(void); // load_save extern bool32 ProgramFlashSectorAndVerify(u8 sector, u8 *data); -extern void ReadFlash(u8 sector, u32 arg1, void* data, u32 size); // iwram common u16 gLastWrittenSector; @@ -806,7 +805,7 @@ u32 sub_81535DC(u8 sector, u8* dst) if (sector != 30 && sector != 31) return 0xFF; - ReadFlash(sector, 0, &gSaveDataBuffer, sizeof(struct SaveSection)); + ReadFlash(sector, 0, (u8 *)&gSaveDataBuffer, sizeof(struct SaveSection)); if (*(u32*)(&gSaveDataBuffer.data[0]) != 0xB39D) return 0xFF; // copies whole save section except u32 counter diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c new file mode 100755 index 000000000..7a7c30388 --- /dev/null +++ b/src/save_failed_screen.c @@ -0,0 +1,426 @@ +#include "global.h" +#include "text.h" +#include "main.h" +#include "palette.h" +#include "gpu_regs.h" +#include "bg.h" +#include "task.h" +#include "window.h" +#include "menu.h" +#include "save.h" +#include "gba/flash_internal.h" + +#define MSG_WIN_TOP 12 +#define CLOCK_WIN_TOP (MSG_WIN_TOP - 4) + +extern void AddTextPrinterParametrized2(u8 windowId, u8 fontId, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, struct TextColor *color, u8 speed, u8 *str); + +extern void (*gGameContinueCallback)(void); + +extern u32 gDamagedSaveSectors; + +extern const u8 gBirchHelpGfx[]; +extern const u8 gBirchBagTilemap[]; +extern const u8 gBirchGrassTilemap[]; +extern const u16 gBirchBagGrassPal[]; +extern const u16 gUnknown_0850FEFC[]; +extern const u16 gUnknown_0860F074[]; +extern const u32 gUnknown_0850E87C[]; +extern struct SaveSection gSaveDataBuffer; + +extern u8 gText_SaveFailedCheckingBackup[]; +extern u8 gText_BackupMemoryDamaged[]; +extern u8 gText_CheckCompleted[]; +extern u8 gText_SaveCompleteGameCannotContinue[]; +extern u8 gText_SaveCompletePressA[]; +extern u8 gText_GamePlayCannotBeContinued[]; + +extern u8 gDecompressionBuffer[]; + +// gSaveFailedClockInfo enum +enum +{ + CLOCK_RUNNING, + DEBUG_TIMER +}; + +// gSaveFailedWindowIds enum +enum +{ + TEXT_WIN_ID, + CLOCK_WIN_ID +}; + +EWRAM_DATA u16 gSaveFailedType = {0}; +EWRAM_DATA u16 gSaveFailedClockInfo[2] = {0}; +EWRAM_DATA u8 gSaveFailedUnused1[12] = {0}; +EWRAM_DATA u8 gSaveFailedWindowIds[2] = {0}; +EWRAM_DATA u8 gSaveFailedUnused2[4] = {0}; + +static const struct OamData sClockOamData = +{ + 160, // Y + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0 +}; + +static const struct BgTemplate gUnknown_085EFD88[3] = +{ + { + .bg = 0, + .charBaseIndex = 2, + .mapBaseIndex = 31, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0, + }, + { + .bg = 2, + .charBaseIndex = 0, + .mapBaseIndex = 14, + .screenSize = 0, + .paletteMode = 0, + .priority = 2, + .baseTile = 0, + }, + { + .bg = 3, + .charBaseIndex = 0, + .mapBaseIndex = 15, + .screenSize = 0, + .paletteMode = 0, + .priority = 3, + .baseTile = 0, + }, +}; + +static const struct WindowTemplate gUnknown_085EFD94[] = +{ + { + .priority = 255, + .tilemapLeft = 0, + .tilemapTop = 0, + .width = 0, + .height = 0, + .paletteNum = 0, + .baseBlock = 0, + } +}; + +static const struct WindowTemplate gUnknown_085EFD9C[] = +{ + { + .priority = 0, + .tilemapLeft = 1, + .tilemapTop = 13, + .width = 28, + .height = 6, + .paletteNum = 15, + .baseBlock = 1, + } +}; + +static const struct WindowTemplate gUnknown_085EFDA4[] = +{ + { + .priority = 0, + .tilemapLeft = 14, + .tilemapTop = 9, + .width = 2, + .height = 2, + .paletteNum = 15, + .baseBlock = 169, + } +}; + +static const u8 sClockFrames[8][3] = +{ + { 1, 0, 0 }, + { 5, 0, 0 }, + { 9, 0, 0 }, + { 5, 0, 1 }, + { 1, 0, 1 }, + { 5, 1, 1 }, + { 9, 1, 0 }, + { 5, 1, 0 }, +}; + +static const u8 gSaveFailedClockPal[] = INCBIN_U8("graphics/misc/clock_small.gbapal"); +static const u8 gSaveFailedClockGfx[] = INCBIN_U8("graphics/misc/clock_small.4bpp.lz"); + +static void CB2_SaveFailedScreen(void); +static void CB2_WipeSave(void); +static void CB2_GameplayCannotBeContinued(void); +static void CB2_FadeAndReturnToTitleScreen(void); +static void CB2_ReturnToTitleScreen(void); +static void VBlankCB_UpdateClockGraphics(void); +static bool8 VerifySectorWipe(u16 sector); +static bool8 WipeSectors(u32); + +// although this is a general text printer, it's only used in this file. +static void SaveFailedScreenTextPrint(u8 *text, u8 var1, u8 var2) +{ + struct TextColor color; + + color.fgColor = 0; + color.bgColor = 15; + color.shadowColor = 3; + AddTextPrinterParametrized2(gSaveFailedWindowIds[TEXT_WIN_ID], 1, var1 * 8, var2 * 8 + 1, 0, 0, &color, 0, text); +} + +void DoSaveFailedScreen(u8 saveType) +{ + SetMainCallback2(CB2_SaveFailedScreen); + gSaveFailedType = saveType; + gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE; + gSaveFailedClockInfo[DEBUG_TIMER] = 0; + gSaveFailedWindowIds[TEXT_WIN_ID] = 0; + gSaveFailedWindowIds[CLOCK_WIN_ID] = 0; +} + +static void VBlankCB(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +static void CB2_SaveFailedScreen(void) +{ + switch (gMain.state) + { + case 0: + default: + SetVBlankCallback(NULL); + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_BG3CNT, 0); + SetGpuReg(REG_OFFSET_BG2CNT, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG0CNT, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + // how come this doesnt use the Dma manager? + DmaFill16(3, 0, VRAM, VRAM_SIZE); + DmaFill32(3, 0, OAM, OAM_SIZE); + DmaFill16(3, 0, PLTT, PLTT_SIZE); + LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM); + LZ77UnCompVram(gBirchBagTilemap, (void *)(VRAM + 0x7000)); + LZ77UnCompVram(gBirchGrassTilemap, (void *)(VRAM + 0x7800)); + LZ77UnCompVram(gSaveFailedClockGfx, (void *)(VRAM + 0x10020)); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, gUnknown_085EFD88, 3); + SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]); + CpuFill32(0, &gDecompressionBuffer[0x2000], 0x800); + LoadBgTiles(0, gUnknown_0850E87C, 0x120, 0x214); + InitWindows(gUnknown_085EFD94); + // AddWindowWithoutTileMap returns a u16/integer, but the info is clobbered into a u8 here resulting in lost info. Bug? + gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C); + SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]); + gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4); + SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]); + DeactivateAllTextPrinters(); + ResetSpriteData(); + ResetTasks(); + ResetPaletteFade(); + LoadPalette(gBirchBagGrassPal, 0, 0x40); + LoadPalette(gSaveFailedClockPal, 0x100, 0x20); + LoadPalette(gUnknown_0850FEFC, 0xE0, 0x20); + LoadPalette(gUnknown_0860F074, 0xF0, 0x20); + SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE); + SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE); + FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards? + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again? + CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1); + SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); + EnableInterrupts(1); + SetVBlankCallback(VBlankCB); + SetGpuReg(0, 0x1040); + ShowBg(0); + ShowBg(2); + ShowBg(3); + gMain.state++; + break; + case 1: + if (!UpdatePaletteFade()) + { + SetMainCallback2(CB2_WipeSave); + SetVBlankCallback(VBlankCB_UpdateClockGraphics); + } + break; + } +} + +static void CB2_WipeSave(void) +{ + u8 wipeTries = 0; + + gSaveFailedClockInfo[CLOCK_RUNNING] = TRUE; + + while (gDamagedSaveSectors != 0 && wipeTries < 3) + { + if (WipeSectors(gDamagedSaveSectors) != FALSE) + { + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0); + SetMainCallback2(CB2_GameplayCannotBeContinued); + return; + } + + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + SaveFailedScreenTextPrint(gText_CheckCompleted, 1, 0); + HandleSavingData(gSaveFailedType); + + if (gDamagedSaveSectors != 0) + { + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); + } + + wipeTries++; + } + + if (wipeTries == 3) + { + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0); + } + else + { + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + + if (gGameContinueCallback == NULL) + SaveFailedScreenTextPrint(gText_SaveCompleteGameCannotContinue, 1, 0); + else + SaveFailedScreenTextPrint(gText_SaveCompletePressA, 1, 0); + } + + SetMainCallback2(CB2_FadeAndReturnToTitleScreen); +} + +static void CB2_GameplayCannotBeContinued(void) +{ + gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE; + + if (gMain.newKeys & A_BUTTON) + { + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + SaveFailedScreenTextPrint(gText_GamePlayCannotBeContinued, 1, 0); + SetVBlankCallback(VBlankCB); + SetMainCallback2(CB2_FadeAndReturnToTitleScreen); + } +} + +static void CB2_FadeAndReturnToTitleScreen(void) +{ + gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE; + + if (gMain.newKeys & A_BUTTON) + { + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, 0); + SetVBlankCallback(VBlankCB); + SetMainCallback2(CB2_ReturnToTitleScreen); + } +} + +static void CB2_ReturnToTitleScreen(void) +{ + if (!UpdatePaletteFade()) + { + if (gGameContinueCallback == NULL) // no callback exists, so do a soft reset. + { + DoSoftReset(); + } + else + { + SetMainCallback2((MainCallback)gGameContinueCallback); + gGameContinueCallback = NULL; + } + } +} + +static void VBlankCB_UpdateClockGraphics(void) +{ + unsigned int n = (gMain.vblankCounter2 >> 3) & 7; + + gMain.oamBuffer[0] = sClockOamData; + gMain.oamBuffer[0].x = 112; + gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;; + + if (gSaveFailedClockInfo[CLOCK_RUNNING] != FALSE) + { + gMain.oamBuffer[0].tileNum = sClockFrames[n][0]; + gMain.oamBuffer[0].matrixNum = (sClockFrames[n][2] << 4) | (sClockFrames[n][1] << 3); + } + else + { + gMain.oamBuffer[0].tileNum = 1; + } + + CpuFastCopy(gMain.oamBuffer, (void *)OAM, 4); + + if (gSaveFailedClockInfo[DEBUG_TIMER]) + gSaveFailedClockInfo[DEBUG_TIMER]--; +} + +static bool8 VerifySectorWipe(u16 sector) +{ + u32 *ptr = (u32 *)&gSaveDataBuffer; + u16 i; + + ReadFlash(sector, 0, (u8 *)ptr, 4096); + + for (i = 0; i < 0x400; i++, ptr++) + if (*ptr) + return TRUE; + + return FALSE; +} + +static bool8 WipeSector(u16 sector) +{ + u16 i, j; + bool8 failed = TRUE; + + for (i = 0; failed && i < 130; i++) + { + for (j = 0; j < 0x1000; j++) + ProgramFlashByte(sector, j, 0); + + failed = VerifySectorWipe(sector); + } + + return failed; +} + +static bool8 WipeSectors(u32 sectorBits) +{ + u16 i; + + for (i = 0; i < 0x20; i++) + if ((sectorBits & (1 << i)) && !WipeSector(i)) + sectorBits &= ~(1 << i); + + if (sectorBits == 0) + return FALSE; + else + return TRUE; +} diff --git a/src/window.c b/src/window.c index 704060b9d..f4cb48ec0 100644 --- a/src/window.c +++ b/src/window.c @@ -190,7 +190,7 @@ u16 AddWindow(const struct WindowTemplate *template) return win; } -int AddWindowWithoutTileMap(struct WindowTemplate *template) +int AddWindowWithoutTileMap(const struct WindowTemplate *template) { u16 win; u8 bgLayer; diff --git a/sym_ewram.txt b/sym_ewram.txt index b7807e8a3..b1572bf25 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -1639,14 +1639,7 @@ gUnknown_0203BCF4: @ 203BCF4 gUnknown_0203BCF8: @ 203BCF8 .space 0x4 -gUnknown_0203BCFC: @ 203BCFC - .space 0x2 - -gUnknown_0203BCFE: @ 203BCFE - .space 0x10 - -gUnknown_0203BD0E: @ 203BD0E - .space 0x6 + .include "src/save_failed_screen.o" gBraillePuzzleCallbackFlag: @ 203BD14 .space 0x4