From 11bead31e90aca72f85352b684670a76a5aa7a16 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 19 Oct 2017 15:28:41 +0200 Subject: [PATCH] battle interface is done --- asm/battle_7.s | 6 +- asm/battle_interface.s | 996 ------------------------------------- asm/party_menu.s | 4 +- asm/trade.s | 4 +- data/battle_interface.s | 139 ------ include/battle.h | 6 +- include/battle_interface.h | 16 +- ld_script.txt | 2 - src/battle_interface.c | 820 ++++++++++++++++++++++++++---- 9 files changed, 749 insertions(+), 1244 deletions(-) delete mode 100755 asm/battle_interface.s delete mode 100644 data/battle_interface.s diff --git a/asm/battle_7.s b/asm/battle_7.s index 3e4574658b..5925058d25 100644 --- a/asm/battle_7.s +++ b/asm/battle_7.s @@ -2857,7 +2857,7 @@ sub_805E990: @ 805E990 lsls r1, 16 asrs r1, 16 adds r0, r4, 0 - bl sub_8075060 + bl GetHPBarLevel lsls r0, 24 lsrs r0, 24 cmp r0, 0x1 @@ -2997,7 +2997,7 @@ sub_805EAB4: @ 805EAB4 lsls r1, 16 asrs r1, 16 adds r0, r4, 0 - bl sub_8075060 + bl GetHPBarLevel lsls r0, 24 lsrs r0, 24 pop {r4,r5} @@ -3796,7 +3796,7 @@ sub_805F110: @ 805F110 lsls r1, 16 asrs r1, 16 adds r0, r4, 0 - bl sub_8075060 + bl GetHPBarLevel lsls r0, 24 lsrs r0, 24 cmp r0, 0x2 diff --git a/asm/battle_interface.s b/asm/battle_interface.s deleted file mode 100755 index 5a4ca6bedf..0000000000 --- a/asm/battle_interface.s +++ /dev/null @@ -1,996 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start sub_8074AA0 -sub_8074AA0: @ 8074AA0 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - lsls r2, 24 - lsrs r2, 24 - mov r9, r2 - cmp r2, 0 - bne _08074AEC - ldr r0, =gBattleSpritesDataPtr - ldr r0, [r0] - ldr r0, [r0, 0xC] - mov r1, r8 - lsls r5, r1, 2 - adds r3, r5, r1 - lsls r3, 2 - adds r3, r0 - ldr r0, [r3, 0x4] - ldr r1, [r3, 0x8] - ldr r2, [r3, 0xC] - adds r3, 0x10 - movs r4, 0x6 - str r4, [sp] - movs r4, 0x1 - str r4, [sp, 0x4] - bl sub_8074DB8 - adds r4, r0, 0 - adds r7, r5, 0 - b _08074B48 - .pool -_08074AEC: - ldr r2, =gBattleSpritesDataPtr - mov r10, r2 - ldr r0, [r2] - ldr r2, [r0, 0xC] - mov r0, r8 - lsls r4, r0, 2 - adds r0, r4, r0 - lsls r6, r0, 2 - adds r2, r6, r2 - ldr r0, [r2, 0x8] - ldr r1, [r2, 0xC] - ldr r2, [r2, 0x4] - movs r3, 0x8 - bl sub_8074FE8 - lsls r0, 24 - lsrs r5, r0, 24 - adds r7, r4, 0 - cmp r5, 0 - bne _08074B16 - movs r5, 0x1 -_08074B16: - mov r1, r10 - ldr r0, [r1] - ldr r0, [r0, 0xC] - adds r4, r6, r0 - ldr r6, [r4, 0xC] - adds r0, r6, 0 - adds r1, r5, 0 - bl __divsi3 - cmp r0, 0 - bge _08074B2E - negs r0, r0 -_08074B2E: - lsls r0, 16 - lsrs r5, r0, 16 - ldr r0, [r4, 0x4] - ldr r1, [r4, 0x8] - adds r3, r4, 0 - adds r3, 0x10 - movs r2, 0x8 - str r2, [sp] - str r5, [sp, 0x4] - adds r2, r6, 0 - bl sub_8074DB8 - adds r4, r0, 0 -_08074B48: - mov r2, r9 - cmp r2, 0x1 - beq _08074B64 - cmp r2, 0 - bne _08074B6C - ldr r0, =gBattleSpritesDataPtr - ldr r0, [r0] - ldr r0, [r0] - adds r0, r7, r0 - ldrb r1, [r0] - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - bne _08074B6C -_08074B64: - mov r0, r8 - mov r1, r9 - bl sub_8074B9C -_08074B6C: - movs r0, 0x1 - negs r0, r0 - cmp r4, r0 - bne _08074B86 - ldr r0, =gBattleSpritesDataPtr - ldr r0, [r0] - ldr r1, [r0, 0xC] - mov r2, r8 - adds r0, r7, r2 - lsls r0, 2 - adds r0, r1 - movs r1, 0 - str r1, [r0, 0x10] -_08074B86: - adds r0, r4, 0 - 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 sub_8074AA0 - - thumb_func_start sub_8074B9C -sub_8074B9C: @ 8074B9C - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x10 - lsls r0, 24 - lsrs r6, r0, 24 - lsls r1, 24 - lsrs r1, 24 - cmp r1, 0 - beq _08074BB8 - cmp r1, 0x1 - beq _08074CA0 - b _08074D9E -_08074BB8: - ldr r0, =gBattleSpritesDataPtr - ldr r0, [r0] - ldr r0, [r0, 0xC] - lsls r5, r6, 2 - adds r3, r5, r6 - lsls r3, 2 - adds r3, r0 - ldr r0, [r3, 0x4] - ldr r1, [r3, 0x8] - ldr r2, [r3, 0xC] - adds r3, 0x10 - add r4, sp, 0x8 - str r4, [sp] - movs r4, 0x6 - str r4, [sp, 0x4] - bl sub_8074E8C - lsls r0, 24 - lsrs r0, 24 - movs r1, 0x3 - mov r9, r1 - adds r7, r5, 0 - cmp r0, 0x18 - bhi _08074BF4 - movs r2, 0x38 - mov r9, r2 - cmp r0, 0x9 - bls _08074BF4 - movs r4, 0x2F - mov r9, r4 -_08074BF4: - movs r5, 0 - ldr r0, =gSprites - mov r8, r0 -_08074BFA: - ldr r0, =gBattleSpritesDataPtr - ldr r0, [r0] - ldr r1, [r0, 0xC] - adds r0, r7, r6 - lsls r0, 2 - adds r0, r1 - ldrb r1, [r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - add r0, r8 - ldrh r0, [r0, 0x38] - lsls r0, 24 - lsrs r4, r0, 24 - cmp r5, 0x1 - bhi _08074C5C - mov r0, r9 - bl GetHealthboxElementGfxPtr - mov r1, sp - adds r1, r5 - adds r1, 0x8 - ldrb r1, [r1] - lsls r1, 5 - adds r0, r1 - lsls r1, r4, 4 - adds r1, r4 - lsls r1, 2 - add r1, r8 - ldrh r1, [r1, 0x4] - lsls r1, 22 - lsrs r1, 22 - adds r2, r5, 0x2 - adds r1, r2 - lsls r1, 5 - ldr r2, =0x06010000 - adds r1, r2 - ldr r2, =0x04000008 - bl CpuSet - b _08074C8A - .pool -_08074C5C: - mov r0, r9 - bl GetHealthboxElementGfxPtr - mov r1, sp - adds r1, r5 - adds r1, 0x8 - ldrb r1, [r1] - lsls r1, 5 - adds r0, r1 - lsls r1, r4, 4 - adds r1, r4 - lsls r1, 2 - add r1, r8 - ldrh r1, [r1, 0x4] - lsls r1, 22 - lsrs r1, 22 - adds r1, r5, r1 - lsls r1, 5 - ldr r4, =0x06010040 - adds r1, r4 - ldr r2, =0x04000008 - bl CpuSet -_08074C8A: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x5 - bls _08074BFA - b _08074D9E - .pool -_08074CA0: - ldr r0, =gBattleSpritesDataPtr - ldr r0, [r0] - ldr r0, [r0, 0xC] - lsls r5, r6, 2 - adds r3, r5, r6 - lsls r3, 2 - adds r3, r0 - ldr r0, [r3, 0x4] - ldr r1, [r3, 0x8] - ldr r2, [r3, 0xC] - adds r3, 0x10 - add r4, sp, 0x8 - str r4, [sp] - movs r4, 0x8 - str r4, [sp, 0x4] - bl sub_8074E8C - ldr r1, =gBattlePartyID - lsls r0, r6, 1 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - adds r0, r1 - movs r1, 0x38 - bl GetMonData - lsls r0, 24 - lsrs r0, 24 - adds r7, r5, 0 - cmp r0, 0x64 - bne _08074CF8 - movs r5, 0 - movs r1, 0 -_08074CE6: - mov r0, sp - adds r0, r5 - adds r0, 0x8 - strb r1, [r0] - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x7 - bls _08074CE6 -_08074CF8: - movs r5, 0 - ldr r0, =gSprites - mov r8, r0 - adds r0, r7, r6 - lsls r4, r0, 2 -_08074D02: - cmp r5, 0x3 - bhi _08074D5C - movs r0, 0xC - bl GetHealthboxElementGfxPtr - mov r1, sp - adds r1, r5 - adds r1, 0x8 - ldrb r1, [r1] - lsls r1, 5 - adds r0, r1 - ldr r1, =gBattleSpritesDataPtr - ldr r1, [r1] - ldr r1, [r1, 0xC] - adds r1, r4, r1 - ldrb r2, [r1] - lsls r1, r2, 4 - adds r1, r2 - lsls r1, 2 - add r1, r8 - ldrh r1, [r1, 0x4] - lsls r1, 22 - lsrs r1, 22 - adds r2, r5, 0 - adds r2, 0x24 - adds r1, r2 - lsls r1, 5 - ldr r2, =0x06010000 - adds r1, r2 - ldr r2, =0x04000008 - bl CpuSet - b _08074D94 - .pool -_08074D5C: - movs r0, 0xC - bl GetHealthboxElementGfxPtr - mov r1, sp - adds r1, r5 - adds r1, 0x8 - ldrb r1, [r1] - lsls r1, 5 - adds r0, r1 - ldr r1, =gBattleSpritesDataPtr - ldr r1, [r1] - ldr r1, [r1, 0xC] - adds r1, r4, r1 - ldrb r2, [r1] - lsls r1, r2, 4 - adds r1, r2 - lsls r1, 2 - add r1, r8 - ldrh r1, [r1, 0x4] - lsls r1, 22 - lsrs r1, 22 - adds r1, r5, r1 - lsls r1, 5 - ldr r2, =0x06010b80 - adds r1, r2 - ldr r2, =0x04000008 - bl CpuSet -_08074D94: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x7 - bls _08074D02 -_08074D9E: - add sp, 0x10 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8074B9C - - thumb_func_start sub_8074DB8 -sub_8074DB8: @ 8074DB8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r7, r0, 0 - adds r4, r1, 0 - mov r8, r2 - adds r5, r3, 0 - ldr r1, [sp, 0x18] - ldr r0, [sp, 0x1C] - lsls r0, 16 - lsrs r3, r0, 16 - lsls r1, 27 - lsrs r2, r1, 24 - ldr r1, [r5] - ldr r0, =0xffff8000 - cmp r1, r0 - bne _08074DEA - cmp r7, r2 - bge _08074DE8 - lsls r0, r4, 8 - str r0, [r5] - b _08074DEA - .pool -_08074DE8: - str r4, [r5] -_08074DEA: - mov r0, r8 - subs r4, r0 - cmp r4, 0 - bge _08074DF6 - movs r4, 0 - b _08074DFC -_08074DF6: - cmp r4, r7 - ble _08074DFC - adds r4, r7, 0 -_08074DFC: - cmp r7, r2 - bge _08074E18 - ldr r0, [r5] - asrs r1, r0, 8 - adds r6, r0, 0 - cmp r4, r1 - bne _08074E24 - movs r0, 0xFF - ands r0, r6 - cmp r0, 0 - bne _08074E24 - movs r0, 0x1 - negs r0, r0 - b _08074E80 -_08074E18: - ldr r6, [r5] - cmp r4, r6 - bne _08074E24 - movs r0, 0x1 - negs r0, r0 - b _08074E80 -_08074E24: - cmp r7, r2 - bge _08074E5E - lsls r0, r7, 8 - adds r1, r2, 0 - bl __divsi3 - mov r1, r8 - cmp r1, 0 - bge _08074E42 - adds r0, r6, r0 - str r0, [r5] - asrs r2, r0, 8 - cmp r2, r4 - blt _08074E7E - b _08074E56 -_08074E42: - subs r0, r6, r0 - str r0, [r5] - asrs r2, r0, 8 - movs r1, 0xFF - ands r0, r1 - cmp r0, 0 - ble _08074E52 - adds r2, 0x1 -_08074E52: - cmp r2, r4 - bgt _08074E7E -_08074E56: - lsls r0, r4, 8 - str r0, [r5] - adds r2, r4, 0 - b _08074E7E -_08074E5E: - mov r0, r8 - cmp r0, 0 - bge _08074E70 - ldr r0, [r5] - adds r0, r3 - str r0, [r5] - cmp r0, r4 - ble _08074E7C - b _08074E7A -_08074E70: - ldr r0, [r5] - subs r0, r3 - str r0, [r5] - cmp r0, r4 - bge _08074E7C -_08074E7A: - str r4, [r5] -_08074E7C: - ldr r2, [r5] -_08074E7E: - adds r0, r2, 0 -_08074E80: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8074DB8 - - thumb_func_start sub_8074E8C -sub_8074E8C: @ 8074E8C - push {r4-r7,lr} - adds r4, r0, 0 - mov r12, r3 - ldr r7, [sp, 0x14] - ldr r0, [sp, 0x18] - lsls r0, 24 - lsrs r6, r0, 24 - subs r5, r1, r2 - cmp r5, 0 - bge _08074EA4 - movs r5, 0 - b _08074EAA -_08074EA4: - cmp r5, r4 - ble _08074EAA - adds r5, r4, 0 -_08074EAA: - lsls r0, r6, 27 - lsrs r3, r0, 24 - movs r1, 0 - cmp r1, r6 - bcs _08074EC4 - movs r2, 0 -_08074EB6: - adds r0, r7, r1 - strb r2, [r0] - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, r6 - bcc _08074EB6 -_08074EC4: - cmp r4, r3 - bge _08074ED8 - mov r1, r12 - ldr r0, [r1] - muls r0, r3 - adds r1, r4, 0 - bl __divsi3 - asrs r0, 8 - b _08074EE4 -_08074ED8: - mov r1, r12 - ldr r0, [r1] - muls r0, r3 - adds r1, r4, 0 - bl __divsi3 -_08074EE4: - lsls r0, 24 - lsrs r2, r0, 24 - adds r3, r2, 0 - cmp r3, 0 - bne _08074EFA - cmp r5, 0 - ble _08074EFA - movs r0, 0x1 - strb r0, [r7] - movs r3, 0x1 - b _08074F1E -_08074EFA: - movs r1, 0 - movs r4, 0x8 -_08074EFE: - cmp r1, r6 - bcs _08074F1E - cmp r2, 0x7 - bls _08074F1A - adds r0, r7, r1 - strb r4, [r0] - adds r0, r2, 0 - subs r0, 0x8 - lsls r0, 24 - lsrs r2, r0, 24 - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - b _08074EFE -_08074F1A: - adds r0, r7, r1 - strb r2, [r0] -_08074F1E: - adds r0, r3, 0 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8074E8C - - thumb_func_start sub_8074F28 -sub_8074F28: @ 8074F28 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x8 - adds r5, r0, 0 - adds r6, r1, 0 - adds r4, r2, 0 - mov r8, r3 - ldr r0, [r5] - ldr r1, [r5, 0x4] - ldr r2, [r5, 0x8] - movs r3, 0x6 - str r3, [sp] - movs r3, 0x1 - str r3, [sp, 0x4] - adds r3, r6, 0 - bl sub_8074DB8 - lsls r0, 16 - lsrs r7, r0, 16 - adds r0, r5, 0 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_8074F88 - ldr r0, [r5] - cmp r0, 0x2F - bgt _08074F68 - ldr r0, [r6] - lsls r0, 8 - lsrs r1, r0, 16 - b _08074F6A -_08074F68: - ldrh r1, [r6] -_08074F6A: - movs r2, 0 - ldrsh r0, [r5, r2] - lsls r1, 16 - asrs r1, 16 - mov r2, r8 - bl sub_8072304 - lsls r0, r7, 16 - asrs r0, 16 - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8074F28 - - thumb_func_start sub_8074F88 -sub_8074F88: @ 8074F88 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x1C - adds r5, r0, 0 - adds r3, r1, 0 - mov r8, r2 - ldr r0, [r5] - ldr r1, [r5, 0x4] - ldr r2, [r5, 0x8] - add r4, sp, 0x8 - str r4, [sp] - movs r4, 0x6 - str r4, [sp, 0x4] - bl sub_8074E8C - movs r3, 0 - add r7, sp, 0x10 - mov r12, r7 - ldrb r0, [r5, 0xC] - lsls r6, r0, 27 - ldr r4, [r5, 0x10] -_08074FB4: - lsls r2, r3, 1 - add r2, r12 - lsrs r1, r6, 15 - mov r0, sp - adds r0, r3 - adds r0, 0x8 - ldrb r0, [r0] - adds r0, r4, r0 - orrs r1, r0 - strh r1, [r2] - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, 0x5 - bls _08074FB4 - adds r0, r7, 0 - mov r1, r8 - movs r2, 0x6 - bl CpuSet - add sp, 0x1C - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8074F88 - - thumb_func_start sub_8074FE8 -sub_8074FE8: @ 8074FE8 - push {r4-r7,lr} - adds r6, r2, 0 - lsls r3, 27 - lsrs r7, r3, 24 - subs r5, r0, r1 - cmp r5, 0 - bge _08074FFA - movs r5, 0 - b _08075000 -_08074FFA: - cmp r5, r6 - ble _08075000 - adds r5, r6, 0 -_08075000: - muls r0, r7 - adds r1, r6, 0 - bl __divsi3 - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - adds r0, r5, 0 - muls r0, r7 - adds r1, r6, 0 - bl __divsi3 - lsls r4, 24 - asrs r4, 24 - lsls r0, 24 - asrs r0, 24 - subs r0, r4, r0 - cmp r0, 0 - bge _08075028 - negs r0, r0 -_08075028: - lsls r0, 24 - lsrs r0, 24 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8074FE8 - - thumb_func_start GetScaledHPFraction -GetScaledHPFraction: @ 8075034 - push {r4,lr} - lsls r2, 24 - lsrs r2, 24 - lsls r0, 16 - asrs r4, r0, 16 - adds r0, r4, 0 - muls r0, r2 - lsls r1, 16 - asrs r1, 16 - bl __divsi3 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0 - bne _08075058 - cmp r4, 0 - ble _08075058 - movs r0, 0x1 -_08075058: - pop {r4} - pop {r1} - bx r1 - thumb_func_end GetScaledHPFraction - - thumb_func_start sub_8075060 -sub_8075060: @ 8075060 - push {lr} - lsls r0, 16 - asrs r0, 16 - lsls r1, 16 - asrs r1, 16 - cmp r0, r1 - bne _08075072 - movs r0, 0x4 - b _0807508E -_08075072: - movs r2, 0x30 - bl GetScaledHPFraction - lsls r0, 24 - lsrs r1, r0, 24 - movs r0, 0x3 - cmp r1, 0x18 - bhi _0807508E - movs r0, 0x2 - cmp r1, 0x9 - bhi _0807508E - negs r0, r1 - orrs r0, r1 - lsrs r0, 31 -_0807508E: - pop {r1} - bx r1 - thumb_func_end sub_8075060 - - thumb_func_start AddTextPrinterAndCreateWindowOnHealthbox -AddTextPrinterAndCreateWindowOnHealthbox: @ 8075094 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - mov r10, r0 - mov r8, r1 - mov r9, r2 - adds r5, r3, 0 - ldr r7, [sp, 0x40] - ldr r0, =gUnknown_0832C3F8 - ldr r1, [r0, 0x4] - ldr r0, [r0] - str r0, [sp, 0x18] - str r1, [sp, 0x1C] - add r0, sp, 0x18 - bl AddWindow - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - lsls r6, r4, 24 - lsrs r6, 24 - lsls r1, r5, 4 - orrs r1, r5 - lsls r1, 24 - lsrs r1, 24 - adds r0, r6, 0 - bl FillWindowPixelBuffer - add r0, sp, 0x14 - movs r2, 0 - strb r5, [r0] - adds r1, r0, 0 - movs r0, 0x1 - strb r0, [r1, 0x1] - movs r0, 0x3 - strb r0, [r1, 0x2] - mov r0, r8 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - mov r0, r9 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - str r2, [sp] - str r2, [sp, 0x4] - str r1, [sp, 0x8] - movs r0, 0x1 - negs r0, r0 - str r0, [sp, 0xC] - mov r0, r10 - str r0, [sp, 0x10] - adds r0, r6, 0 - movs r1, 0 - mov r2, r8 - mov r3, r9 - bl AddTextPrinterParametrized2 - str r4, [r7] - adds r0, r6, 0 - movs r1, 0x7 - bl GetWindowAttribute - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end AddTextPrinterAndCreateWindowOnHealthbox - - thumb_func_start RemoveWindowOnHealthbox -RemoveWindowOnHealthbox: @ 807512C - push {lr} - lsls r0, 24 - lsrs r0, 24 - bl RemoveWindow - pop {r0} - bx r0 - thumb_func_end RemoveWindowOnHealthbox - - thumb_func_start sub_807513C -sub_807513C: @ 807513C - push {lr} - sub sp, 0x4 - adds r3, r0, 0 - lsls r0, r1, 4 - adds r0, r1 - lsls r1, r0, 8 - adds r0, r1 - lsls r1, r0, 16 - adds r0, r1 - str r0, [sp] - lsls r2, 3 - ldr r0, =0x001fffff - ands r2, r0 - movs r0, 0xA0 - lsls r0, 19 - orrs r2, r0 - mov r0, sp - adds r1, r3, 0 - bl CpuSet - add sp, 0x4 - pop {r0} - bx r0 - .pool - thumb_func_end sub_807513C - - thumb_func_start sub_8075170 -sub_8075170: @ 8075170 - push {lr} - adds r3, r0, 0 - adds r0, r1, 0 - movs r1, 0x80 - lsls r1, 1 - adds r0, r1 - lsls r2, 3 - ldr r1, =0x001fffff - ands r2, r1 - movs r1, 0x80 - lsls r1, 19 - orrs r2, r1 - adds r1, r3, 0 - bl CpuSet - pop {r0} - bx r0 - .pool - thumb_func_end sub_8075170 - - thumb_func_start sub_8075198 -sub_8075198: @ 8075198 - push {r4-r6,lr} - adds r6, r0, 0 - adds r5, r1, 0 - adds r4, r2, 0 - movs r1, 0x80 - lsls r1, 1 - adds r0, r5, r1 - adds r1, r6, r1 - lsls r2, r4, 3 - ldr r3, =0x001fffff - ands r2, r3 - movs r3, 0x80 - lsls r3, 19 - orrs r2, r3 - bl CpuSet - cmp r4, 0 - ble _080751D4 -_080751BC: - adds r0, r5, 0 - adds r0, 0x14 - adds r1, r6, 0 - adds r1, 0x14 - ldr r2, =0x04000003 - bl CpuSet - adds r6, 0x20 - adds r5, 0x20 - subs r4, 0x1 - cmp r4, 0 - bne _080751BC -_080751D4: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8075198 - - thumb_func_start sub_80751E4 -sub_80751E4: @ 80751E4 - push {r4-r6,lr} - adds r6, r0, 0 - adds r5, r1, 0 - lsls r4, r2, 3 - ldr r0, =0x001fffff - ands r4, r0 - movs r0, 0x80 - lsls r0, 19 - orrs r4, r0 - adds r0, r5, 0 - adds r1, r6, 0 - adds r2, r4, 0 - bl CpuSet - movs r0, 0x80 - lsls r0, 1 - adds r5, r0 - adds r6, r0 - adds r0, r5, 0 - adds r1, r6, 0 - adds r2, r4, 0 - bl CpuSet - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80751E4 - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/party_menu.s b/asm/party_menu.s index 50dc3c54e0..f2e681b9b4 100755 --- a/asm/party_menu.s +++ b/asm/party_menu.s @@ -5441,7 +5441,7 @@ sub_81B2E64: @ 81B2E64 mov r2, r9 lsls r1, r2, 16 asrs r1, 16 - bl sub_8075060 + bl GetHPBarLevel lsls r0, 24 lsrs r0, 24 cmp r0, 0x2 @@ -10452,7 +10452,7 @@ sub_81B5A8C: @ 81B5A8C asrs r2, 16 adds r0, r1, 0 adds r1, r2, 0 - bl sub_8075060 + bl GetHPBarLevel lsls r0, 24 lsrs r0, 24 cmp r0, 0x2 diff --git a/asm/trade.s b/asm/trade.s index 31c16195e6..e8b8977977 100644 --- a/asm/trade.s +++ b/asm/trade.s @@ -5954,7 +5954,7 @@ _0807A488: asrs r0, 16 lsls r1, 16 asrs r1, 16 - bl sub_8075060 + bl GetHPBarLevel ldr r1, [r7] adds r1, 0x5D adds r1, r6 @@ -5997,7 +5997,7 @@ _0807A4E8: asrs r0, 16 lsls r1, 16 asrs r1, 16 - bl sub_8075060 + bl GetHPBarLevel ldr r1, [r7] adds r1, 0x63 adds r1, r6 diff --git a/data/battle_interface.s b/data/battle_interface.s deleted file mode 100644 index 39f69ba5f8..0000000000 --- a/data/battle_interface.s +++ /dev/null @@ -1,139 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - .align 2, 0 - - - - .align 2 -gUnknown_0832C220:: @ 832C220 - .byte 0xf0, 0x00, 0x0d, 0x40, 0x30, 0x00, 0x08, 0x42 - .byte 0xf0, 0x20, 0x05, 0x43, 0x10, 0x20, 0x45, 0x43 - .byte 0x30, 0x20, 0x85, 0x43 - - .align 2 -gUnknown_0832C234:: @ 832C234 - .byte 0xf0, 0x00, 0x0d, 0x44, 0x30, 0x00, 0x08, 0x46 - .byte 0xf0, 0x20, 0x05, 0x47, 0x10, 0x20, 0x45, 0x47 - .byte 0x30, 0x20, 0x85, 0x47 - - .align 2 -gUnknown_0832C248:: @ 832C248 - .byte 0xf0, 0x00, 0x0d, 0x40, 0x30, 0x00, 0x08, 0x42 - - .align 2 -gUnknown_0832C250:: @ 832C250 - .byte 0xf0, 0x00, 0x0d, 0x40, 0x30, 0x00, 0x08, 0x42 - - .align 2 -gUnknown_0832C258:: @ 832C258 - .byte 0xf0, 0x00, 0x05, 0x40, 0x10, 0x00, 0x45, 0x40 - - .align 2 -gUnknown_0832C260:: @ 832C260 - .byte 0xf0, 0x00, 0x05, 0x40, 0x10, 0x00, 0x45, 0x40 - .byte 0xe0, 0x00, 0x80, 0x40 - - .align 2 -gUnknown_0832C26C:: @ 832C26C - .4byte 0x00000005, gUnknown_0832C220 - .4byte 0x00000002, gUnknown_0832C248 - .4byte 0x00000005, gUnknown_0832C234 - .4byte 0x00000002, gUnknown_0832C250 - - .align 2 -gUnknown_0832C28C:: @ 832C28C - .4byte 0x00000002, gUnknown_0832C258 - .4byte 0x00000003, gUnknown_0832C260 - - .align 2 -gUnknown_0832C29C:: @ 832C29C - .byte 0xa0, 0x00, 0x05, 0x40, 0xc0, 0x00, 0x45, 0x40 - .byte 0xe0, 0x00, 0x85, 0x40, 0x00, 0x00, 0xc5, 0x40 - - .align 2 -gUnknown_0832C2AC:: @ 832C2AC - .byte 0xa0, 0x00, 0x05, 0x40, 0xc0, 0x00, 0x45, 0x40 - .byte 0xe0, 0x00, 0x85, 0x40, 0x00, 0x00, 0x85, 0x40 - .byte 0x20, 0x00, 0x85, 0x40, 0x40, 0x00, 0xc5, 0x40 - - .align 2 -gUnknown_0832C2C4:: @ 832C2C4 - .4byte 0x00000004, gUnknown_0832C29C - - .align 2 -gUnknown_0832C2CC:: @ 832C2CC - .4byte 0x00000006, gUnknown_0832C2AC - - .align 2 -gUnknown_0832C2D4:: @ 832C2D4 - .2byte 0x0000, 0x0000, 0x3333, 0x3333, 0x4444, 0x4444, 0x2222, 0x2222 - .2byte 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777 - - .2byte 0x0000, 0x0000, 0x3333, 0x3333, 0x4444, 0x4444, 0x2222, 0x2222 - .2byte 0x7777, 0x7777, 0x7777, 0x7717, 0x1777, 0x7177, 0x7777, 0x7771 - - .2byte 0x0000, 0x0000, 0x3333, 0x3333, 0x4444, 0x4444, 0x2222, 0x2222 - .2byte 0x7777, 0x7777, 0x7777, 0x7111, 0x7777, 0x7171, 0x7777, 0x7111 - - .align 2 -gUnknown_0832C334:: @ 832C334 - obj_tiles gBattleInterface_BallStatusBarGfx, 0x0200, 0xd70c - - .align 2 -gUnknown_0832C33C:: @ 832C33C - obj_pal gBattleInterface_BallStatusBarPal, 0xd710 - - .align 2 -gUnknown_0832C344:: @ 832C344 - obj_pal gBattleInterface_BallDisplayPal, 0xd712 - - .align 2 -gUnknown_0832C34C:: @ 832C34C - obj_tiles gBattleInterface_BallDisplayGfx, 0x0080, 0xd714 - - .align 2 -gUnknown_0832C354:: @ 832C354 - .byte 0x00, 0x40, 0x00, 0xc0, 0x00, 0x04, 0x00, 0x00 - - .align 2 -gUnknown_0832C35C:: @ 832C35C - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00 - - .align 2 -gUnknown_0832C364:: @ 832C364 - spr_template 0xd70c, 0xd710, gUnknown_0832C138, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, sub_8074078 - - .align 2 -gUnknown_0832C37C:: @ 832C37C - spr_template 0xd70c, 0xd710, gUnknown_0832C138, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, sub_8074078 - - .align 2 -gUnknown_0832C394:: @ 832C394 - spr_template 0xd714, 0xd712, gUnknown_0832C35C, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, sub_80740C4 - - .align 2 -gUnknown_0832C3AC:: @ 832C3AC - spr_template 0xd714, 0xd712, gUnknown_0832C35C, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, sub_80740C4 - - .align 2 -gUnknown_0832C3C4:: @ 832C3C4 - .byte 0xfc, 0x01, 0x01, 0xfc, 0x02, 0x02, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00 - - .align 2 -gUnknown_0832C3D8:: @ 832C3D8 - .byte 0xfc, 0x01, 0x01, 0xfc, 0x02, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00 - - .align 2 -gBattleInterfaceStatusIcons_DynPals:: @ 832C3EC - .byte 0x98, 0x61, 0xf7, 0x0e, 0x94, 0x46, 0xd1, 0x72 - .byte 0xdc, 0x29, 0x00, 0x00 - - .align 2 -gUnknown_0832C3F8:: @ 832C3F8 - .byte 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00 diff --git a/include/battle.h b/include/battle.h index ae7fa3ce40..719db0fa31 100644 --- a/include/battle.h +++ b/include/battle.h @@ -919,9 +919,9 @@ struct BattleHealthboxInfo struct BattleBarInfo { u8 healthboxSpriteId; - u32 maxValue; - u32 currentValue; - bool32 isDoubleBattle; + s32 maxValue; + s32 currentValue; + s32 field_C; s32 field_10; }; diff --git a/include/battle_interface.h b/include/battle_interface.h index 93387cae0d..016a6e5c40 100644 --- a/include/battle_interface.h +++ b/include/battle_interface.h @@ -19,10 +19,20 @@ enum u8 CreateBankHealthboxSprites(u8 bank); u8 CreateSafariPlayerHealthboxSprites(void); -void SetBankHealthboxSpritePos(u8 bank); -void SetHealthboxSpriteVisible(u8 healthboxSpriteId); +void SetBattleBarStruct(u8 bank, u8 healthboxSpriteId, s32 maxVal, s32 currVal, s32 field_C); void SetHealthboxSpriteInvisible(u8 healthboxSpriteId); -void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elementId); +void SetHealthboxSpriteVisible(u8 healthboxSpriteId); +void DestoryHealthboxSprite(u8 healthboxSpriteId); void nullsub_30(u8 healthboxSpriteId, bool8 isDoubleBattleBankOnly); +void UpdateOamPriorityInAllHealthboxes(u8 priority); +void SetBankHealthboxSpritePos(u8 bank); +void UpdateHpTextInHealthbox(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent); +void SwapHpBarsWithHpText(void); +u8 CreatePartyStatusSummarySprites(u8 bank, struct HpAndStatus *partyInfo, u8 arg2, bool8 isBattleStart); +void sub_8073C30(u8 taskId); +void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elementId); +s32 sub_8074AA0(u8 bank, u8 healthboxSpriteId, u8 whichBar, u8 arg3); +u8 GetScaledHPFraction(s16 hp, s16 maxhp, u8 scale); +u8 GetHPBarLevel(s16 hp, s16 maxhp); #endif // GUARD_BATTLE_INTERFACE_H diff --git a/ld_script.txt b/ld_script.txt index b9dc6290e3..86bd92c7c5 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -80,7 +80,6 @@ SECTIONS { asm/daycare.o(.text); src/egg_hatch.o(.text); src/battle_interface.o(.text); - asm/battle_interface.o(.text); asm/smokescreen.o(.text); asm/pokeball.o(.text); src/load_save.o(.text); @@ -342,7 +341,6 @@ SECTIONS { src/egg_hatch.o(.rodata); data/battle_7.o(.rodata); src/battle_interface.o(.rodata); - data/battle_interface.o(.rodata); data/pokeball.o(.rodata); data/trade.o(.rodata); data/berry_blender.o(.rodata); diff --git a/src/battle_interface.c b/src/battle_interface.c index 27a82d49d2..7d176a9af1 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1,12 +1,12 @@ #include "global.h" #include "battle.h" #include "pokemon.h" +#include "battle_controllers.h" #include "battle_interface.h" #include "sprite.h" #include "window.h" #include "string_util.h" #include "text.h" -#include "battle_controllers.h" #include "sound.h" #include "songs.h" #include "decompress.h" @@ -20,6 +20,21 @@ #include "international_string_util.h" #include "safari_zone.h" +enum +{ + HEALTH_BAR, + EXP_BAR +}; + +struct TestingBar +{ + s32 maxValue; + s32 currValue; + s32 field_8; + u32 unkC_0:5; + u32 unk10; +}; + extern bool8 IsDoubleBattle(void); extern u8 gBanksByIdentity[BATTLE_BANKS_COUNT]; extern u16 gBattlePartyID[BATTLE_BANKS_COUNT]; @@ -27,31 +42,62 @@ extern u8 gNoOfAllBanks; extern u8 gHealthBoxesIds[BATTLE_BANKS_COUNT]; extern const u8 * const gNatureNamePointers[]; +extern const u8 gSpeciesNames[][POKEMON_NAME_LENGTH + 1]; + +// strings extern const u8 gText_Slash[]; +extern const u8 gText_HighlightDarkGrey[]; +extern const u8 gText_DynColor2[]; +extern const u8 gText_DynColor2Male[]; +extern const u8 gText_DynColor1Female[]; +extern const u8 gText_SafariBalls[]; +extern const u8 gText_SafariBallLeft[]; + +// graphics +extern const u8 gBattleInterface_BallStatusBarGfx[]; +extern const u8 gBattleInterface_BallDisplayGfx[]; +extern const u16 gBattleInterface_BallStatusBarPal[]; +extern const u16 gBattleInterface_BallDisplayPal[]; +extern const u8 gHealthboxElementsGfxTable[][32]; + +extern void AddTextPrinterParametrized2(u8 windowId, u8 fontId, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, struct TextColor *color, s8 speed, const u8 *str); // menu.h +extern void LoadBattleBarGfx(u8 arg0); // this file's functions -void sub_8072924(struct Sprite *sprite); -void sub_80728B4(struct Sprite *sprite); -const u32 *GetHealthboxElementGfxPtr(u8 elementId); -u32 AddTextPrinterAndCreateWindowOnHealthbox(const u8 *str, u32 x, u32 y, u32 arg3, u32 *windowId); -void sub_8075198(void *objVram, u32 windowTileData, u32 arg2); -void sub_80751E4(void *objVram, u32 windowTileData, u32 arg2); -void RemoveWindowOnHealthbox(u32 windowId); -void sub_8075170(void *dest, u32 arg1, u32 arg2); -void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent); -void sub_807513C(void *dest, u32 arg1, u32 arg2); -void UpdateStatusIconInHealthbox(u8 healthboxSpriteId); -void sub_80741C8(struct Sprite *sprite); -void sub_8073E08(u8 taskId); -void sub_8073F98(u8 taskId); -void sub_8073E64(u8 taskId); -void sub_8074158(struct Sprite *sprite); -void sub_8074090(struct Sprite *sprite); -u8 GetStatusIconForBankId(u8 statusElementId, u8 bank); -void sub_8074AA0(u8 bank, u8 healthboxSpriteId, u8 whichBar, u8 arg3); + +static const u8 *GetHealthboxElementGfxPtr(u8 elementId); +static u8* AddTextPrinterAndCreateWindowOnHealthbox(const u8 *str, u32 x, u32 y, u32 arg3, u32 *windowId); + +static void RemoveWindowOnHealthbox(u32 windowId); +static void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent); +static void UpdateStatusIconInHealthbox(u8 healthboxSpriteId); + +static void sub_8075198(void *dest, u8 *windowTileData, s32 arg2); +static void sub_80751E4(void *dest, u8 *windowTileData, u32 arg2); +static void sub_8075170(void *dest, u8 *windowTileData, u32 arg2); +static void sub_807513C(void *dest, u32 arg1, u32 arg2); + +static void sub_8073E08(u8 taskId); +static void sub_8073F98(u8 taskId); +static void sub_8073E64(u8 taskId); + +static void sub_8072924(struct Sprite *sprite); +static void sub_80728B4(struct Sprite *sprite); +static void sub_8074158(struct Sprite *sprite); +static void sub_8074090(struct Sprite *sprite); +static void sub_8074078(struct Sprite *sprite); +static void sub_80740C4(struct Sprite *sprite); +static void sub_80741C8(struct Sprite *sprite); + +static u8 GetStatusIconForBankId(u8 statusElementId, u8 bank); +static s32 sub_8074DB8(s32 maxValue, s32 currValue, s32 arg2, s32 *arg3, u8 arg4, u16 arg5); +static u8 GetScaledExpFraction(s32 currValue, s32 arg1, s32 maxValue, u8 scale); +static void sub_8074B9C(u8 bank, u8 whichBar); +static u8 sub_8074E8C(s32 maxValue, s32 currValue, s32 arg2, s32 *arg3, u8 *arg4, u8 arg5); +static void sub_8074F88(struct TestingBar *barInfo, s32 *arg1, u16 *arg2); // const rom data -const struct OamData gUnknown_0832C138 = +static const struct OamData gUnknown_0832C138 = { .y = 0, .affineMode = 0, @@ -68,8 +114,6 @@ const struct OamData gUnknown_0832C138 = .affineParam = 0, }; -extern const struct SubspriteTable gUnknown_0832C28C[2]; - static const struct SpriteTemplate gUnknown_0832C140[2] = { { @@ -125,7 +169,7 @@ static const struct SpriteTemplate gUnknown_0832C1A0 = .callback = SpriteCallbackDummy }; -const struct OamData gUnknown_0832C1B8 = +static const struct OamData gUnknown_0832C1B8 = { .y = 0, .affineMode = 0, @@ -182,26 +226,247 @@ static const struct SpriteTemplate gUnknown_0832C1C0[4] = } }; -extern const u8 gUnknown_0832C3C4[0x14]; -extern const u8 gUnknown_0832C3D8[0x14]; -extern const u32 gHealthboxElementsGfxTable[][8]; -extern const struct CompressedSpriteSheet gUnknown_0832C334; -extern const struct SpriteSheet gUnknown_0832C34C; -extern const struct SpritePalette gUnknown_0832C33C; -extern const struct SpritePalette gUnknown_0832C344; -extern const struct SpriteTemplate gUnknown_0832C364[2]; -extern const struct SpriteTemplate gUnknown_0832C394[2]; -extern const struct SubspriteTable gUnknown_0832C2C4; -extern const struct SubspriteTable gUnknown_0832C2CC; -extern const u16 gBattleInterfaceStatusIcons_DynPals[]; +static const struct Subsprite gUnknown_0832C220[] = +{ + {240, 0, 1, 3, 0, 1}, + {48, 0, 0, 2, 32, 1}, + {240, 32, 1, 1, 48, 1}, + {16, 32, 1, 1, 52, 1}, + {48, 32, 1, 1, 56, 1} +}; -u8 sub_8072304(void) +static const struct Subsprite gUnknown_0832C234[] = +{ + {240, 0, 1, 3, 64, 1}, + {48, 0, 0, 2, 96, 1}, + {240, 32, 1, 1, 112, 1}, + {16, 32, 1, 1, 116, 1}, + {48, 32, 1, 1, 120, 1} +}; + +static const struct Subsprite gUnknown_0832C248[] = +{ + {240, 0, 1, 3, 0, 1}, + {48, 0, 0, 2, 32, 1} +}; + +static const struct Subsprite gUnknown_0832C250[] = +{ + {240, 0, 1, 3, 0, 1}, + {48, 0, 0, 2, 32, 1} +}; + +static const struct Subsprite gUnknown_0832C258[] = +{ + {240, 0, 1, 1, 0, 1}, + {16, 0, 1, 1, 4, 1} +}; + +static const struct Subsprite gUnknown_0832C260[] = +{ + {240, 0, 1, 1, 0, 1}, + {16, 0, 1, 1, 4, 1}, + {224, 0, 0, 0, 8, 1} +}; + +static const struct SubspriteTable gUnknown_0832C26C[] = +{ + {ARRAY_COUNT(gUnknown_0832C220), gUnknown_0832C220}, + {ARRAY_COUNT(gUnknown_0832C248), gUnknown_0832C248}, + {ARRAY_COUNT(gUnknown_0832C234), gUnknown_0832C234}, + {ARRAY_COUNT(gUnknown_0832C250), gUnknown_0832C250} +}; + +static const struct SubspriteTable gUnknown_0832C28C[] = +{ + {ARRAY_COUNT(gUnknown_0832C258), gUnknown_0832C258}, + {ARRAY_COUNT(gUnknown_0832C260), gUnknown_0832C260} +}; + +static const struct Subsprite gUnknown_0832C29C[] = +{ + {160, 0, 1, 1, 0, 1}, + {192, 0, 1, 1, 4, 1}, + {224, 0, 1, 1, 8, 1}, + {0, 0, 1, 1, 12, 1} +}; + +static const struct Subsprite gUnknown_0832C2AC[] = +{ + {160, 0, 1, 1, 0, 1}, + {192, 0, 1, 1, 4, 1}, + {224, 0, 1, 1, 8, 1}, + {0, 0, 1, 1, 8, 1}, + {32, 0, 1, 1, 8, 1}, + {64, 0, 1, 1, 12, 1} +}; + +static const struct SubspriteTable gUnknown_0832C2C4[] = +{ + {ARRAY_COUNT(gUnknown_0832C29C), gUnknown_0832C29C} +}; + +static const struct SubspriteTable gUnknown_0832C2CC[] = +{ + {ARRAY_COUNT(gUnknown_0832C2AC), gUnknown_0832C2AC} +}; + +// unused unknown data +static const u16 gUnknown_0832C2D4[] = +{ + 0x0000, 0x0000, 0x3333, 0x3333, 0x4444, 0x4444, 0x2222, 0x2222, + 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, + + 0x0000, 0x0000, 0x3333, 0x3333, 0x4444, 0x4444, 0x2222, 0x2222, + 0x7777, 0x7777, 0x7777, 0x7717, 0x1777, 0x7177, 0x7777, 0x7771, + + 0x0000, 0x0000, 0x3333, 0x3333, 0x4444, 0x4444, 0x2222, 0x2222, + 0x7777, 0x7777, 0x7777, 0x7111, 0x7777, 0x7171, 0x7777, 0x7111, +}; + +static const struct CompressedSpriteSheet gUnknown_0832C334 = +{ + gBattleInterface_BallStatusBarGfx, 0x200, 0xD70C +}; + +static const struct SpritePalette gUnknown_0832C33C = +{ + gBattleInterface_BallStatusBarPal, 0xD710 +}; + +static const struct SpritePalette gUnknown_0832C344 = +{ + gBattleInterface_BallDisplayPal, 0xD712 +}; + +static const struct SpriteSheet gUnknown_0832C34C = +{ + gBattleInterface_BallDisplayGfx, 0x80, 0xD714 +}; + +static const struct OamData gUnknown_0832C354 = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 1, + .x = 0, + .matrixNum = 0, + .size = 3, + .tileNum = 0, + .priority = 1, + .paletteNum = 0, + .affineParam = 0, +}; + +static const struct OamData gUnknown_0832C35C = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 0, + .x = 0, + .matrixNum = 0, + .size = 0, + .tileNum = 0, + .priority = 1, + .paletteNum = 0, + .affineParam = 0, +}; + +static const struct SpriteTemplate gUnknown_0832C364[2] = +{ + { + .tileTag = 0xd70c, + .paletteTag = 0xd710, + .oam = &gUnknown_0832C138, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_8074078 + }, + { + .tileTag = 0xd70c, + .paletteTag = 0xd710, + .oam = &gUnknown_0832C138, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_8074078 + } +}; + +static const struct SpriteTemplate gUnknown_0832C394[2] = +{ + { + .tileTag = 0xd714, + .paletteTag = 0xd712, + .oam = &gUnknown_0832C35C, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_80740C4 + }, + { + .tileTag = 0xd714, + .paletteTag = 0xd712, + .oam = &gUnknown_0832C35C, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_80740C4 + } +}; + +// possibly text +static const u8 gUnknown_0832C3C4[] = +{ + 0xfc, 0x01, 0x01, 0xfc, 0x02, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, +}; + +// possibly text +static const u8 gUnknown_0832C3D8[] = +{ + 0xfc, 0x01, 0x01, 0xfc, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, +}; + +enum +{ + PAL_STATUS_PSN, + PAL_STATUS_PAR, + PAL_STATUS_SLP, + PAL_STATUS_FRZ, + PAL_STATUS_BRN +}; + +static const u16 sStatusIconPalettes[] = +{ + 0x6198, // PAL_STATUS_PSN + 0xEF7, // PAL_STATUS_PAR + 0x4694, // PAL_STATUS_SLP + 0x72D1, // PAL_STATUS_FRZ + 0x29DC // PAL_STATUS_BRN +}; + +static const struct WindowTemplate sHealthboxWindowTemplate = {0, 0, 0, 8, 2, 0, 0}; // width = 8, height = 2 + +// code + +static s32 DummiedOutFunction(s16 unused1, s16 unused2, s32 unused3) { return 9; } #ifdef NONMATCHING -void sub_8072308(s16 arg0, u16 *arg1, u8 arg2) +static void sub_8072308(s16 arg0, u16 *arg1, u8 arg2) { s8 i, j; s8 array[4]; @@ -276,7 +541,7 @@ void sub_8072308(s16 arg0, u16 *arg1, u8 arg2) #else __attribute__((naked)) -void sub_8072308(s16 arg0, u16 *arg1, u8 arg2) +static void sub_8072308(s16 arg0, u16 *arg1, u8 arg2) { asm(".syntax unified\n\ push {r4-r7,lr}\n\ @@ -613,12 +878,12 @@ u8 CreateSafariPlayerHealthboxSprites(void) return healthboxSpriteId_1; } -const u32 *GetHealthboxElementGfxPtr(u8 elementId) +static const u8 *GetHealthboxElementGfxPtr(u8 elementId) { return gHealthboxElementsGfxTable[elementId]; } -void sub_80728B4(struct Sprite *sprite) +static void sub_80728B4(struct Sprite *sprite) { u8 var = sprite->data5; @@ -643,7 +908,7 @@ void sub_80728B4(struct Sprite *sprite) sprite->pos2.y = gSprites[var].pos2.y; } -void sub_8072924(struct Sprite *sprite) +static void sub_8072924(struct Sprite *sprite) { u8 otherSpriteId = sprite->data5; @@ -654,12 +919,12 @@ void sub_8072924(struct Sprite *sprite) sprite->pos2.y = gSprites[otherSpriteId].pos2.y; } -void SetBattleBarStruct(u8 bank, u8 healthboxSpriteId, u32 maxVal, u32 currVal, bool32 isDoubleBattle) +void SetBattleBarStruct(u8 bank, u8 healthboxSpriteId, s32 maxVal, s32 currVal, s32 field_C) { gBattleSpritesDataPtr->battleBars[bank].healthboxSpriteId = healthboxSpriteId; gBattleSpritesDataPtr->battleBars[bank].maxValue = maxVal; gBattleSpritesDataPtr->battleBars[bank].currentValue = currVal; - gBattleSpritesDataPtr->battleBars[bank].isDoubleBattle = isDoubleBattle; + gBattleSpritesDataPtr->battleBars[bank].field_C = field_C; gBattleSpritesDataPtr->battleBars[bank].field_10 = -32768; } @@ -744,9 +1009,10 @@ void SetBankHealthboxSpritePos(u8 bank) UpdateSpritePos(gHealthBoxesIds[bank], x, y); } -void UpdateLvlInHealthbox(u8 healthboxSpriteId, u8 lvl) +static void UpdateLvlInHealthbox(u8 healthboxSpriteId, u8 lvl) { - u32 windowId, windowTileData, spriteTileNum; + u32 windowId, spriteTileNum; + u8 *windowTileData; u8 text[16]; u32 xPos, var1; void *objVram; @@ -786,7 +1052,8 @@ void UpdateLvlInHealthbox(u8 healthboxSpriteId, u8 lvl) void UpdateHpTextInHealthbox(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent) { - u32 windowId, windowTileData, spriteTileNum; + u32 windowId, spriteTileNum; + u8 *windowTileData; u8 text[32]; void *objVram; @@ -861,9 +1128,10 @@ void UpdateHpTextInHealthbox(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent) } } -void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent) +static void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent) { - u32 windowId, windowTileData, spriteTileNum; + u32 windowId, spriteTileNum; + u8 *windowTileData; u8 text[32]; void *objVram; @@ -955,7 +1223,7 @@ void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 maxOrC } } -void sub_80730D4(u8 healthboxSpriteId, struct Pokemon *mon) +static void sub_80730D4(u8 healthboxSpriteId, struct Pokemon *mon) { u8 text[20]; s32 j, var2; @@ -1131,7 +1399,7 @@ u8 CreatePartyStatusSummarySprites(u8 bank, struct HpAndStatus *partyInfo, u8 ar LoadSpritePalette(&gUnknown_0832C344); barSpriteId = CreateSprite(&gUnknown_0832C364[isOpponent], bar_X, bar_Y, 10); - SetSubspriteTables(&gSprites[barSpriteId], &gUnknown_0832C2C4); + SetSubspriteTables(&gSprites[barSpriteId], gUnknown_0832C2C4); gSprites[barSpriteId].pos2.x = bar_pos2_X; gSprites[barSpriteId].data0 = bar_data0; @@ -1339,7 +1607,7 @@ void sub_8073C30(u8 taskId) gSprites[r10].data0 /= 2; gSprites[r10].data1 = 0; gSprites[r10].callback = sub_8074090; - SetSubspriteTables(&gSprites[r10], &gUnknown_0832C2CC); + SetSubspriteTables(&gSprites[r10], gUnknown_0832C2CC); gTasks[taskId].func = sub_8073E08; } else @@ -1348,7 +1616,7 @@ void sub_8073C30(u8 taskId) } } -void sub_8073E08(u8 taskId) +static void sub_8073E08(u8 taskId) { u16 temp = gTasks[taskId].data[11]++; @@ -1364,7 +1632,7 @@ void sub_8073E08(u8 taskId) gTasks[taskId].func = sub_8073E64; } -void sub_8073E64(u8 taskId) +static void sub_8073E64(u8 taskId) { u8 sp[6]; s32 i; @@ -1404,7 +1672,7 @@ void sub_8073E64(u8 taskId) } } -void sub_8073F98(u8 taskId) +static void sub_8073F98(u8 taskId) { u8 sp[6]; s32 i; @@ -1437,13 +1705,13 @@ void sub_8073F98(u8 taskId) } } -void sub_8074078(struct Sprite *sprite) +static void sub_8074078(struct Sprite *sprite) { if (sprite->pos2.x != 0) sprite->pos2.x += sprite->data0; } -void sub_8074090(struct Sprite *sprite) +static void sub_8074090(struct Sprite *sprite) { sprite->data1 += 32; if (sprite->data0 > 0) @@ -1453,7 +1721,7 @@ void sub_8074090(struct Sprite *sprite) sprite->data1 &= 0xF; } -void sub_80740C4(struct Sprite *sprite) +static void sub_80740C4(struct Sprite *sprite) { u8 var1; u16 var2; @@ -1493,7 +1761,7 @@ void sub_80740C4(struct Sprite *sprite) } } -void sub_8074158(struct Sprite *sprite) +static void sub_8074158(struct Sprite *sprite) { u8 var1; u16 var2; @@ -1519,7 +1787,7 @@ void sub_8074158(struct Sprite *sprite) } } -void sub_80741C8(struct Sprite *sprite) +static void sub_80741C8(struct Sprite *sprite) { u8 barSpriteId = sprite->data0; @@ -1527,18 +1795,13 @@ void sub_80741C8(struct Sprite *sprite) sprite->pos2.y = gSprites[barSpriteId].pos2.y; } -extern const u8 gText_HighlightDarkGrey[]; -extern const u8 gText_DynColor2[]; -extern const u8 gText_DynColor2Male[]; -extern const u8 gText_DynColor1Female[]; -extern const u8 gSpeciesNames[][POKEMON_NAME_LENGTH + 1]; - -void UpdateNickInHealthbox(u8 healthboxSpriteId, struct Pokemon *mon) +static void UpdateNickInHealthbox(u8 healthboxSpriteId, struct Pokemon *mon) { u8 nickname[POKEMON_NAME_LENGTH + 1]; void *ptr; const u8 *genderTxt; - u32 windowId, windowTileData, spriteTileNum; + u32 windowId, spriteTileNum; + u8 *windowTileData; u16 species; u8 gender; @@ -1591,7 +1854,7 @@ void UpdateNickInHealthbox(u8 healthboxSpriteId, struct Pokemon *mon) RemoveWindowOnHealthbox(windowId); } -void TryAddPokeballIconToHealthbox(u8 healthboxSpriteId, bool8 noStatus) +static void TryAddPokeballIconToHealthbox(u8 healthboxSpriteId, bool8 noStatus) { u8 bank, healthboxSpriteId_2; @@ -1614,12 +1877,12 @@ void TryAddPokeballIconToHealthbox(u8 healthboxSpriteId, bool8 noStatus) CpuFill32(0, (void*)(OBJ_VRAM0 + (gSprites[healthboxSpriteId_2].oam.tileNum + 8) * 32), 32); } -void UpdateStatusIconInHealthbox(u8 healthboxSpriteId) +static void UpdateStatusIconInHealthbox(u8 healthboxSpriteId) { s32 i; u8 bank, healthboxSpriteId_2; u32 status, pltAdder; - const u32 *statusGfxPtr; + const u8 *statusGfxPtr; s16 tileNumAdder; u8 statusPalId; @@ -1642,27 +1905,27 @@ void UpdateStatusIconInHealthbox(u8 healthboxSpriteId) if (status & STATUS_SLEEP) { statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBankId(0x1B, bank)); - statusPalId = 2; + statusPalId = PAL_STATUS_SLP; } else if (status & STATUS_PSN_ANY) { statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBankId(0x15, bank)); - statusPalId = 0; + statusPalId = PAL_STATUS_PSN; } else if (status & STATUS_BURN) { statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBankId(0x21, bank)); - statusPalId = 4; + statusPalId = PAL_STATUS_BRN; } else if (status & STATUS_FREEZE) { statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBankId(0x1E, bank)); - statusPalId = 3; + statusPalId = PAL_STATUS_FRZ; } else if (status & STATUS_PARALYSIS) { statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBankId(0x18, bank)); - statusPalId = 1; + statusPalId = PAL_STATUS_PAR; } else { @@ -1681,7 +1944,7 @@ void UpdateStatusIconInHealthbox(u8 healthboxSpriteId) pltAdder = gSprites[healthboxSpriteId].oam.paletteNum * 16; pltAdder += bank + 12; - FillPalette(gBattleInterfaceStatusIcons_DynPals[statusPalId], pltAdder + 0x100, 2); + FillPalette(sStatusIconPalettes[statusPalId], pltAdder + 0x100, 2); CpuCopy16(gPlttBufferUnfaded + 0x100 + pltAdder, (void*)(OBJ_PLTT + pltAdder * 2), 2); CpuCopy32(statusGfxPtr, (void*)(OBJ_VRAM0 + (gSprites[healthboxSpriteId].oam.tileNum + tileNumAdder) * 32), 96); if (IsDoubleBattle() == TRUE || GetBankSide(bank) == SIDE_OPPONENT) @@ -1695,7 +1958,7 @@ void UpdateStatusIconInHealthbox(u8 healthboxSpriteId) TryAddPokeballIconToHealthbox(healthboxSpriteId, FALSE); } -u8 GetStatusIconForBankId(u8 statusElementId, u8 bank) +static u8 GetStatusIconForBankId(u8 statusElementId, u8 bank) { u8 ret = statusElementId; @@ -1755,12 +2018,10 @@ u8 GetStatusIconForBankId(u8 statusElementId, u8 bank) return ret; } -extern const u8 gText_SafariBalls[]; -extern const u8 gText_SafariBallLeft[]; - -void UpdateSafariBallsTextOnHealthbox(u8 healthboxSpriteId) +static void UpdateSafariBallsTextOnHealthbox(u8 healthboxSpriteId) { - u32 windowId, windowTileData, spriteTileNum; + u32 windowId, spriteTileNum; + u8 *windowTileData; windowTileData = AddTextPrinterAndCreateWindowOnHealthbox(gText_SafariBalls, 0, 3, 2, &windowId); spriteTileNum = gSprites[healthboxSpriteId].oam.tileNum * 32; @@ -1769,11 +2030,12 @@ void UpdateSafariBallsTextOnHealthbox(u8 healthboxSpriteId) RemoveWindowOnHealthbox(windowId); } -void UpdateLeftNoOfBallsTextOnHealthbox(u8 healthboxSpriteId) +static void UpdateLeftNoOfBallsTextOnHealthbox(u8 healthboxSpriteId) { u8 text[16]; u8 *txtPtr; - u32 windowId, windowTileData, spriteTileNum; + u32 windowId, spriteTileNum; + u8 *windowTileData; txtPtr = StringCopy(text, gText_SafariBallLeft); ConvertIntToDecimalStringN(txtPtr, gNumSafariBalls, STR_CONV_MODE_LEFT_ALIGN, 2); @@ -1785,11 +2047,9 @@ void UpdateLeftNoOfBallsTextOnHealthbox(u8 healthboxSpriteId) RemoveWindowOnHealthbox(windowId); } -extern void LoadBattleBarGfx(u8 arg0); - void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elementId) { - u32 maxHp, currHp; + s32 maxHp, currHp; u8 bank = gSprites[healthboxSpriteId].data6; if (elementId == HEALTHBOX_ALL && !IsDoubleBattle()) @@ -1810,14 +2070,15 @@ void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elem LoadBattleBarGfx(0); maxHp = GetMonData(mon, MON_DATA_MAX_HP); currHp = GetMonData(mon, MON_DATA_HP); - SetBattleBarStruct(bank, healthboxSpriteId, maxHp, currHp, FALSE); - sub_8074AA0(bank, healthboxSpriteId, 0, 0); + SetBattleBarStruct(bank, healthboxSpriteId, maxHp, currHp, 0); + sub_8074AA0(bank, healthboxSpriteId, HEALTH_BAR, 0); } isDoubles = IsDoubleBattle(); if (!isDoubles && (elementId == HEALTHBOX_EXP_BAR || elementId == HEALTHBOX_ALL)) { u16 species; - u32 exp, currLevelExp, currExpBarValue, maxExpBarValue; + u32 exp, currLevelExp; + s32 currExpBarValue, maxExpBarValue; u8 level; LoadBattleBarGfx(3); @@ -1828,7 +2089,7 @@ void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elem currExpBarValue = exp - currLevelExp; maxExpBarValue = gExperienceTables[gBaseStats[species].growthRate][level + 1] - currLevelExp; SetBattleBarStruct(bank, healthboxSpriteId, maxExpBarValue, currExpBarValue, isDoubles); - sub_8074AA0(bank, healthboxSpriteId, 1, 0); + sub_8074AA0(bank, healthboxSpriteId, EXP_BAR, 0); } if (elementId == HEALTHBOX_NICK || elementId == HEALTHBOX_ALL) UpdateNickInHealthbox(healthboxSpriteId, mon); @@ -1848,8 +2109,8 @@ void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elem LoadBattleBarGfx(0); maxHp = GetMonData(mon, MON_DATA_MAX_HP); currHp = GetMonData(mon, MON_DATA_HP); - SetBattleBarStruct(bank, healthboxSpriteId, maxHp, currHp, FALSE); - sub_8074AA0(bank, healthboxSpriteId, 0, 0); + SetBattleBarStruct(bank, healthboxSpriteId, maxHp, currHp, 0); + sub_8074AA0(bank, healthboxSpriteId, HEALTH_BAR, 0); } if (elementId == HEALTHBOX_NICK || elementId == HEALTHBOX_ALL) UpdateNickInHealthbox(healthboxSpriteId, mon); @@ -1857,3 +2118,374 @@ void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elem UpdateStatusIconInHealthbox(healthboxSpriteId); } } + +s32 sub_8074AA0(u8 bank, u8 healthboxSpriteId, u8 whichBar, u8 arg3) +{ + s32 var; + + if (whichBar == HEALTH_BAR) // health bar + { + var = sub_8074DB8(gBattleSpritesDataPtr->battleBars[bank].maxValue, + gBattleSpritesDataPtr->battleBars[bank].currentValue, + gBattleSpritesDataPtr->battleBars[bank].field_C, + &gBattleSpritesDataPtr->battleBars[bank].field_10, + 6, 1); + } + else // exp bar + { + u16 expFraction = GetScaledExpFraction(gBattleSpritesDataPtr->battleBars[bank].currentValue, + gBattleSpritesDataPtr->battleBars[bank].field_C, + gBattleSpritesDataPtr->battleBars[bank].maxValue, 8); + if (expFraction == 0) + expFraction = 1; + expFraction = abs(gBattleSpritesDataPtr->battleBars[bank].field_C / expFraction); + + var = sub_8074DB8(gBattleSpritesDataPtr->battleBars[bank].maxValue, + gBattleSpritesDataPtr->battleBars[bank].currentValue, + gBattleSpritesDataPtr->battleBars[bank].field_C, + &gBattleSpritesDataPtr->battleBars[bank].field_10, + 8, expFraction); + } + + if (whichBar == EXP_BAR || (whichBar == HEALTH_BAR && !gBattleSpritesDataPtr->bankData[bank].hpNumbersNoBars)) + sub_8074B9C(bank, whichBar); + + if (var == -1) + gBattleSpritesDataPtr->battleBars[bank].field_10 = 0; + + return var; +} + +static void sub_8074B9C(u8 bank, u8 whichBar) +{ + u8 array[7]; + u8 subRet, level; + u8 barElementId; + u8 i; + + switch (whichBar) + { + case HEALTH_BAR: + subRet = sub_8074E8C(gBattleSpritesDataPtr->battleBars[bank].maxValue, + gBattleSpritesDataPtr->battleBars[bank].currentValue, + gBattleSpritesDataPtr->battleBars[bank].field_C, + &gBattleSpritesDataPtr->battleBars[bank].field_10, + array, 6); + barElementId = 3; + if (subRet <= 0x18) + { + barElementId = 0x38; + if (subRet > 9) + barElementId = 0x2F; + } + for (i = 0; i < 6; i++) + { + u8 healthboxSpriteId_2 = gSprites[gBattleSpritesDataPtr->battleBars[bank].healthboxSpriteId].data5; + if (i < 2) + CpuCopy32(GetHealthboxElementGfxPtr(barElementId) + array[i] * 32, + (void*)(OBJ_VRAM0 + (gSprites[healthboxSpriteId_2].oam.tileNum + 2 + i) * 32), 32); + else + CpuCopy32(GetHealthboxElementGfxPtr(barElementId) + array[i] * 32, + (void*)(OBJ_VRAM0 + 64 + (i + gSprites[healthboxSpriteId_2].oam.tileNum) * 32), 32); + } + break; + case EXP_BAR: + sub_8074E8C(gBattleSpritesDataPtr->battleBars[bank].maxValue, + gBattleSpritesDataPtr->battleBars[bank].currentValue, + gBattleSpritesDataPtr->battleBars[bank].field_C, + &gBattleSpritesDataPtr->battleBars[bank].field_10, + array, 8); + level = GetMonData(&gPlayerParty[gBattlePartyID[bank]], MON_DATA_LEVEL); + if (level == MAX_MON_LEVEL) + { + for (i = 0; i < 8; i++) + array[i] = 0; + } + for (i = 0; i < 8; i++) + { + if (i < 4) + CpuCopy32(GetHealthboxElementGfxPtr(0xC) + array[i] * 32, + (void*)(OBJ_VRAM0 + (gSprites[gBattleSpritesDataPtr->battleBars[bank].healthboxSpriteId].oam.tileNum + 0x24 + i) * 32), 32); + else + CpuCopy32(GetHealthboxElementGfxPtr(0xC) + array[i] * 32, + (void*)(OBJ_VRAM0 + 0xB80 + (i + gSprites[gBattleSpritesDataPtr->battleBars[bank].healthboxSpriteId].oam.tileNum) * 32), 32); + } + break; + } +} + +static s32 sub_8074DB8(s32 maxValue, s32 currValue, s32 arg2, s32 *arg3, u8 arg4, u16 arg5) +{ + s32 r6; + s32 ret; + arg4 <<= 3; + + if (*arg3 == -32768) + { + if (maxValue < arg4) + *arg3 = currValue << 8; + else + *arg3 = currValue; + } + + currValue -= arg2; + if (currValue < 0) + currValue = 0; + else if (currValue > maxValue) + currValue = maxValue; + + if (maxValue < arg4) + { + s32 var = *arg3 >> 8; + + r6 = *arg3; + if (currValue == var && (r6 & 0xFF) == 0) + return -1; + } + else + { + r6 = *arg3; + if (currValue == r6) + return -1; + } + + if (maxValue < arg4) + { + s32 var = (maxValue << 8) / arg4; + + if (arg2 < 0) + { + *arg3 = r6 + var; + ret = *arg3 >> 8; + if (ret >= currValue) + { + *arg3 = currValue << 8; + ret = currValue; + } + } + else + { + *arg3 = r6 - var; + ret = *arg3 >> 8; + if ((*arg3 & 0xFF) > 0) + ret++; + if (ret <= currValue) + { + *arg3 = currValue << 8; + ret = currValue; + } + } + } + else + { + if (arg2 < 0) + { + *arg3 += arg5; + if (*arg3 > currValue) + *arg3 = currValue; + ret = *arg3; + } + else + { + *arg3 -= arg5; + if (*arg3 < currValue) + *arg3 = currValue; + ret = *arg3; + } + } + + return ret; +} + +static u8 sub_8074E8C(s32 maxValue, s32 currValue, s32 arg2, s32 *arg3, u8 *arg4, u8 arg5) +{ + s32 r5 = currValue - arg2; + u8 ret; + u8 i; + u8 r2; + + if (r5 < 0) + r5 = 0; + else if (r5 > maxValue) + r5 = maxValue; + + ret = arg5 << 3; + + for (i = 0; i < arg5; i++) + arg4[i] = 0; + + if (maxValue < ret) + r2 = (*arg3 * ret / maxValue) >> 8; + else + r2 = *arg3 * ret / maxValue; + + ret = r2; + + if (ret == 0 && r5 > 0) + { + arg4[0] = 1; + ret = 1; + } + else + { + for (i = 0; i < arg5; i++) + { + if (r2 >= 8) + { + arg4[i] = 8; + } + else + { + arg4[i] = r2; + break; + } + r2 -= 8; + } + } + + return ret; +} + +static s16 sub_8074F28(struct TestingBar *barInfo, s32 *arg1, u16 *arg2, s32 arg3) +{ + s16 ret, var; + + ret = sub_8074DB8(barInfo->maxValue, + barInfo->currValue, + barInfo->field_8, + arg1, 6, 1); + sub_8074F88(barInfo, arg1, arg2); + + if (barInfo->maxValue < 0x30) + var = *arg1 >> 8; + else + var = *arg1; + + DummiedOutFunction(barInfo->maxValue, var, arg3); + + return ret; +} + +static void sub_8074F88(struct TestingBar *barInfo, s32 *arg1, u16 *arg2) +{ + u8 sp8[6]; + u16 sp10[6]; + u8 i; + + sub_8074E8C(barInfo->maxValue, barInfo->currValue, + barInfo->field_8, arg1, sp8, 6); + + for (i = 0; i < 6; i++) + sp10[i] = (barInfo->unkC_0 << 12) | (barInfo->unk10 + sp8[i]); + + CpuCopy16(sp10, arg2, sizeof(sp10)); +} + +static u8 GetScaledExpFraction(s32 currValue, s32 arg1, s32 maxValue, u8 scale) +{ + s32 r5, result; + s8 r4, r0; + + scale *= 8; + r5 = currValue - arg1; + + if (r5 < 0) + r5 = 0; + else if (r5 > maxValue) + r5 = maxValue; + + r4 = currValue * scale / maxValue; + r0 = r5 * scale / maxValue; + result = r4 - r0; + + return abs(result); +} + +u8 GetScaledHPFraction(s16 hp, s16 maxhp, u8 scale) +{ + u8 result = hp * scale / maxhp; + + if (result == 0 && hp > 0) + return 1; + + return result; +} + +u8 GetHPBarLevel(s16 hp, s16 maxhp) +{ + s32 result; + + if (hp == maxhp) + { + result = 4; + } + else + { + u8 fraction = GetScaledHPFraction(hp, maxhp, 48); + if (fraction > 24) + result = 3; + else if (fraction > 9) + result = 2; + else if (fraction > 0) + result = 1; + else + result = 0; + } + + return result; +} + +static u8* AddTextPrinterAndCreateWindowOnHealthbox(const u8 *str, u32 x, u32 y, u32 arg3, u32 *windowId) +{ + u16 winId; + struct TextColor color; + struct WindowTemplate winTemplate = sHealthboxWindowTemplate; + + winId = AddWindow(&winTemplate); + FillWindowPixelBuffer(winId, (arg3 << 4) | (arg3)); + + color.fgColor = arg3; + color.bgColor = 1; + color.shadowColor = 3; + + AddTextPrinterParametrized2(winId, 0, x, y, 0, 0, &color, -1, str); + + *windowId = winId; + return (u8*)(GetWindowAttribute(winId, WINDOW_TILE_DATA)); +} + +static void RemoveWindowOnHealthbox(u32 windowId) +{ + RemoveWindow(windowId); +} + +static void sub_807513C(void *dest, u32 arg1, u32 arg2) +{ + CpuFill32(0x11111111 * arg1, dest, arg2 * 32); +} + +static void sub_8075170(void *dest, u8 *windowTileData, u32 arg2) +{ + CpuCopy32(windowTileData + 256, dest, arg2 * 32); +} + +static void sub_8075198(void *dest, u8 *windowTileData, s32 arg2) +{ + CpuCopy32(windowTileData + 256, dest + 256, arg2 * 32); + + if (arg2 > 0) + { + do + { + CpuCopy32(windowTileData + 20, dest + 20, 12); + dest += 32, windowTileData+= 32; + arg2--; + } while (arg2 != 0); + } +} + +static void sub_80751E4(void *dest, u8 *windowTileData, u32 arg2) +{ + CpuCopy32(windowTileData, dest, arg2 * 32); + CpuCopy32(windowTileData + 256, dest + 256, arg2 * 32); +}