From 447afe45057d0cca1866af7bfff3c5bc97ed9466 Mon Sep 17 00:00:00 2001 From: KDSKardabox Date: Fri, 13 Apr 2018 17:51:49 +0530 Subject: [PATCH] Decompile pokemon icon --- asm/battle_anim_80A5C6C.s | 2 +- asm/battle_frontier_1.s | 14 +- asm/party_menu.s | 6 +- asm/pokemon_icon.s | 822 ----------------------------------- asm/pokemon_storage_system.s | 2 +- asm/rom_8011DC0.s | 4 +- asm/trade.s | 2 +- include/pokemon_icon.h | 15 +- ld_script.txt | 1 - src/mail.c | 6 +- src/naming_screen.c | 124 +++--- src/pokemon_icon.c | 304 +++++++++++++ 12 files changed, 394 insertions(+), 908 deletions(-) delete mode 100644 asm/pokemon_icon.s diff --git a/asm/battle_anim_80A5C6C.s b/asm/battle_anim_80A5C6C.s index a3be18667..c87d7718d 100644 --- a/asm/battle_anim_80A5C6C.s +++ b/asm/battle_anim_80A5C6C.s @@ -1224,7 +1224,7 @@ _080A65D8: bl sub_80A62DC _080A65DE: adds r0, r4, 0 - bl sub_80D30DC + bl UpdateMonIconFrame pop {r4} pop {r0} bx r0 diff --git a/asm/battle_frontier_1.s b/asm/battle_frontier_1.s index e72b8b156..729140801 100644 --- a/asm/battle_frontier_1.s +++ b/asm/battle_frontier_1.s @@ -3326,7 +3326,7 @@ _0819064A: adds r6, 0x1 cmp r6, 0xF ble _0819064A - bl sub_80D2F04 + bl LoadMonIconPalettes ldr r0, =sub_8190CD4 movs r1, 0 bl CreateTask @@ -3695,7 +3695,7 @@ sub_8190938: @ 8190938 cmp r0, 0 bne _0819094A adds r0, r1, 0 - bl sub_80D30DC + bl UpdateMonIconFrame _0819094A: pop {r0} bx r0 @@ -3710,7 +3710,7 @@ sub_8190950: @ 8190950 cmp r0, 0 bne _08190962 adds r0, r4, 0 - bl sub_80D30DC + bl UpdateMonIconFrame _08190962: ldrh r0, [r4, 0x22] adds r1, r0, 0x4 @@ -3774,7 +3774,7 @@ sub_81909CC: @ 81909CC cmp r0, 0 bne _081909DE adds r0, r4, 0 - bl sub_80D30DC + bl UpdateMonIconFrame _081909DE: ldrh r0, [r4, 0x22] subs r1, r0, 0x4 @@ -3838,7 +3838,7 @@ sub_8190A48: @ 8190A48 cmp r0, 0 bne _08190A5A adds r0, r4, 0 - bl sub_80D30DC + bl UpdateMonIconFrame _08190A5A: ldrh r0, [r4, 0x20] adds r1, r0, 0x4 @@ -3902,7 +3902,7 @@ sub_8190AC4: @ 8190AC4 cmp r0, 0 bne _08190AD6 adds r0, r4, 0 - bl sub_80D30DC + bl UpdateMonIconFrame _08190AD6: ldrh r0, [r4, 0x20] subs r1, r0, 0x4 @@ -6471,7 +6471,7 @@ _0819218E: adds r6, 0x1 cmp r6, 0xF ble _08192158 - bl sub_80D2F9C + bl FreeMonIconPalettes ldr r4, =gUnknown_0203CD78 ldr r0, [r4] bl Free diff --git a/asm/party_menu.s b/asm/party_menu.s index 5d01bd745..29e2e67a6 100644 --- a/asm/party_menu.s +++ b/asm/party_menu.s @@ -410,7 +410,7 @@ _081B03A6: b _081B048C .pool _081B03B8: - bl sub_80D2F04 + bl LoadMonIconPalettes b _081B0484 _081B03BE: bl party_menu_add_per_mon_objects @@ -10793,7 +10793,7 @@ _081B5BD0: sub_81B5BDC: @ 81B5BDC push {r4,lr} adds r4, r0, 0 - bl sub_80D30DC + bl UpdateMonIconFrame lsls r0, 24 lsrs r0, 24 cmp r0, 0 @@ -10817,7 +10817,7 @@ _081B5C02: thumb_func_start sub_81B5C08 sub_81B5C08: @ 81B5C08 push {lr} - bl sub_80D30DC + bl UpdateMonIconFrame pop {r0} bx r0 thumb_func_end sub_81B5C08 diff --git a/asm/pokemon_icon.s b/asm/pokemon_icon.s deleted file mode 100644 index 40291bee4..000000000 --- a/asm/pokemon_icon.s +++ /dev/null @@ -1,822 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start CreateMonIcon -@ int CreateMonIcon(u16 speciesId, int a2, u16 a3, u16 a4, u8 a5, u32 personality, int a7) -CreateMonIcon: @ 80D2CC4 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x30 - adds r4, r0, 0 - adds r6, r1, 0 - ldr r0, [sp, 0x4C] - ldr r1, [sp, 0x50] - ldr r5, [sp, 0x54] - lsls r4, 16 - lsrs r4, 16 - lsls r2, 16 - lsrs r2, 16 - mov r8, r2 - lsls r3, 16 - lsrs r7, r3, 16 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - ldr r0, =sMonIconOamData - str r0, [sp, 0x18] - adds r0, r4, 0 - adds r2, r5, 0 - bl GetMonIconPtr - str r0, [sp, 0x1C] - ldr r0, =sMonIconAnims - str r0, [sp, 0x20] - ldr r0, =sMonIconAffineAnims - str r0, [sp, 0x24] - str r6, [sp, 0x28] - ldr r0, =gMonIconPaletteIndices - adds r0, r4, r0 - ldr r1, =0x0000dac0 - adds r5, r1, 0 - ldrb r0, [r0] - adds r1, r5, r0 - add r0, sp, 0x2C - strh r1, [r0] - add r1, sp, 0x18 - mov r0, sp - movs r2, 0x18 - bl memcpy - movs r0, 0xCE - lsls r0, 1 - cmp r4, r0 - bls _080D2D2A - mov r0, sp - strh r5, [r0, 0x14] -_080D2D2A: - mov r0, r8 - lsls r1, r0, 16 - asrs r1, 16 - lsls r2, r7, 16 - asrs r2, 16 - mov r0, sp - mov r3, r9 - bl sub_80D31B4 - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - lsls r0, r4, 4 - adds r0, r4 - lsls r0, 2 - ldr r1, =gSprites - adds r0, r1 - bl sub_80D30DC - adds r0, r4, 0 - add sp, 0x30 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end CreateMonIcon - - thumb_func_start sub_80D2D78 -sub_80D2D78: @ 80D2D78 - push {r4-r7,lr} - sub sp, 0x18 - adds r4, r2, 0 - adds r5, r3, 0 - ldr r6, [sp, 0x2C] - lsls r0, 16 - lsrs r0, 16 - lsls r4, 16 - lsrs r4, 16 - lsls r5, 16 - lsrs r5, 16 - lsls r6, 24 - lsrs r6, 24 - mov r3, sp - ldr r2, =sMonIconOamData - str r2, [sp] - movs r2, 0 - str r2, [sp, 0x4] - ldr r2, =sMonIconAnims - str r2, [sp, 0x8] - ldr r2, =sMonIconAffineAnims - str r2, [sp, 0xC] - str r1, [sp, 0x10] - ldr r2, =gMonIconPaletteIndices - adds r2, r0, r2 - ldr r7, =0x0000dac0 - adds r1, r7, 0 - ldrb r2, [r2] - adds r1, r2 - strh r1, [r3, 0x14] - ldr r1, [sp, 0x30] - bl GetMonIconTiles - str r0, [sp, 0x4] - lsls r4, 16 - asrs r4, 16 - lsls r5, 16 - asrs r5, 16 - mov r0, sp - adds r1, r4, 0 - adds r2, r5, 0 - adds r3, r6, 0 - bl sub_80D31B4 - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - lsls r0, r4, 4 - adds r0, r4 - lsls r0, 2 - ldr r1, =gSprites - adds r0, r1 - bl sub_80D30DC - adds r0, r4, 0 - add sp, 0x18 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_80D2D78 - - thumb_func_start mon_icon_convert_unown_species_id -@ u16 mon_icon_convert_unown_species_id(u16 speciesId, u32 personality) -mon_icon_convert_unown_species_id: @ 80D2E08 - push {lr} - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0xC9 - bne _080D2E32 - adds r0, r1, 0 - bl GetUnownLetterByPersonality - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0 - bne _080D2E24 - movs r0, 0xC9 - b _080D2E2E -_080D2E24: - movs r1, 0xCE - lsls r1, 1 - adds r0, r1 - lsls r0, 16 - lsrs r0, 16 -_080D2E2E: - adds r1, r0, 0 - b _080D2E40 -_080D2E32: - movs r0, 0xCE - lsls r0, 1 - adds r1, r2, 0 - cmp r1, r0 - bls _080D2E40 - movs r1, 0x82 - lsls r1, 1 -_080D2E40: - adds r0, r1, 0 - pop {r1} - bx r1 - thumb_func_end mon_icon_convert_unown_species_id - - thumb_func_start GetUnownLetterByPersonality -GetUnownLetterByPersonality: @ 80D2E48 - push {lr} - adds r2, r0, 0 - cmp r2, 0 - beq _080D2E7E - movs r0, 0xC0 - lsls r0, 18 - ands r0, r2 - lsrs r0, 18 - movs r1, 0xC0 - lsls r1, 10 - ands r1, r2 - lsrs r1, 12 - orrs r0, r1 - movs r1, 0xC0 - lsls r1, 2 - ands r1, r2 - lsrs r1, 6 - orrs r0, r1 - movs r1, 0x3 - ands r1, r2 - orrs r0, r1 - movs r1, 0x1C - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - b _080D2E80 -_080D2E7E: - movs r0, 0 -_080D2E80: - pop {r1} - bx r1 - thumb_func_end GetUnownLetterByPersonality - - thumb_func_start sub_80D2E84 -sub_80D2E84: @ 80D2E84 - push {r4,lr} - sub sp, 0x4 - lsls r0, 16 - lsrs r4, r0, 16 - adds r0, r4, 0 - mov r1, sp - bl MailSpeciesToSpecies - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0xC9 - bne _080D2EBA - mov r0, sp - ldrh r0, [r0] - cmp r0, 0 - bne _080D2EAA - mov r1, sp - adds r0, 0xC9 - b _080D2EB2 -_080D2EAA: - mov r1, sp - movs r2, 0xCE - lsls r2, 1 - adds r0, r2 -_080D2EB2: - strh r0, [r1] - mov r0, sp - ldrh r0, [r0] - b _080D2ED2 -_080D2EBA: - movs r0, 0xCE - lsls r0, 1 - cmp r4, r0 - bls _080D2EC6 - movs r4, 0x82 - lsls r4, 1 -_080D2EC6: - adds r0, r4, 0 - movs r1, 0 - bl mon_icon_convert_unown_species_id - lsls r0, 16 - lsrs r0, 16 -_080D2ED2: - add sp, 0x4 - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_80D2E84 - - thumb_func_start GetMonIconPtr -@ void *GetMonIconPtr(u16 speciesId, u32 personality, bool32) -GetMonIconPtr: @ 80D2EDC - push {r4,lr} - adds r4, r2, 0 - lsls r0, 16 - lsrs r0, 16 - bl mon_icon_convert_unown_species_id - lsls r0, 16 - lsrs r0, 16 - adds r1, r4, 0 - bl GetMonIconTiles - pop {r4} - pop {r1} - bx r1 - thumb_func_end GetMonIconPtr - - thumb_func_start sub_80D2EF8 -sub_80D2EF8: @ 80D2EF8 - push {lr} - bl sub_80D328C - pop {r0} - bx r0 - thumb_func_end sub_80D2EF8 - - thumb_func_start sub_80D2F04 -sub_80D2F04: @ 80D2F04 - push {r4,r5,lr} - movs r4, 0 - ldr r5, =gMonIconPaletteTable -_080D2F0A: - lsls r0, r4, 3 - adds r0, r5 - bl LoadSpritePalette - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x5 - bls _080D2F0A - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D2F04 - - thumb_func_start sub_80D2F28 -sub_80D2F28: @ 80D2F28 - push {r4,lr} - lsls r0, 16 - lsrs r1, r0, 16 - movs r0, 0xCE - lsls r0, 1 - cmp r1, r0 - bls _080D2F3A - movs r1, 0x82 - lsls r1, 1 -_080D2F3A: - ldr r0, =gMonIconPaletteIndices - adds r0, r1, r0 - ldrb r0, [r0] - ldr r1, =gMonIconPaletteTable - lsls r0, 3 - adds r4, r0, r1 - ldrh r0, [r4, 0x4] - bl IndexOfSpritePaletteTag - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - bne _080D2F5A - adds r0, r4, 0 - bl LoadSpritePalette -_080D2F5A: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D2F28 - - thumb_func_start sub_80D2F68 -sub_80D2F68: @ 80D2F68 - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - ldr r1, =gMonIconPaletteIndices - adds r0, r1 - ldrb r0, [r0] - ldr r1, =gMonIconPaletteTable - lsls r0, 3 - adds r4, r0, r1 - ldrh r0, [r4, 0x4] - bl IndexOfSpritePaletteTag - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - bne _080D2F8E - adds r0, r4, 0 - bl LoadSpritePalette -_080D2F8E: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D2F68 - - thumb_func_start sub_80D2F9C -sub_80D2F9C: @ 80D2F9C - push {r4,r5,lr} - movs r4, 0 - ldr r5, =gMonIconPaletteTable -_080D2FA2: - lsls r0, r4, 3 - adds r0, r5 - ldrh r0, [r0, 0x4] - bl FreeSpritePaletteByTag - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x5 - bls _080D2FA2 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D2F9C - - thumb_func_start sub_80D2FC0 -sub_80D2FC0: @ 80D2FC0 - push {lr} - lsls r0, 16 - lsrs r1, r0, 16 - movs r0, 0xCE - lsls r0, 1 - cmp r1, r0 - bls _080D2FD2 - movs r1, 0x82 - lsls r1, 1 -_080D2FD2: - ldr r0, =gMonIconPaletteIndices - adds r0, r1, r0 - ldrb r0, [r0] - ldr r1, =gMonIconPaletteTable - lsls r0, 3 - adds r0, r1 - ldrh r0, [r0, 0x4] - bl FreeSpritePaletteByTag - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D2FC0 - - thumb_func_start sub_80D2FF0 -sub_80D2FF0: @ 80D2FF0 - push {lr} - lsls r0, 16 - lsrs r0, 16 - ldr r1, =gMonIconPaletteIndices - adds r0, r1 - ldrb r0, [r0] - ldr r1, =gMonIconPaletteTable - lsls r0, 3 - adds r0, r1 - ldrh r0, [r0, 0x4] - bl FreeSpritePaletteByTag - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D2FF0 - - thumb_func_start sub_80D3014 -sub_80D3014: @ 80D3014 - push {lr} - bl sub_80D30DC - pop {r0} - bx r0 - thumb_func_end sub_80D3014 - - thumb_func_start GetMonIconTiles -@ void *GetMonIconTiles(u16 speciesId, bool32) -GetMonIconTiles: @ 80D3020 - push {lr} - adds r3, r1, 0 - lsls r0, 16 - lsrs r0, 16 - ldr r2, =gMonIconTable - lsls r1, r0, 2 - adds r1, r2 - ldr r2, [r1] - movs r1, 0xCD - lsls r1, 1 - cmp r0, r1 - bne _080D3042 - cmp r3, 0x1 - bne _080D3042 - movs r0, 0x80 - lsls r0, 3 - adds r2, r0 -_080D3042: - adds r0, r2, 0 - pop {r1} - bx r1 - .pool - thumb_func_end GetMonIconTiles - - thumb_func_start sub_80D304C -sub_80D304C: @ 80D304C - push {r4-r6,lr} - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0xA0 - bhi _080D3074 - ldr r6, =gMonIconPaletteTable - movs r5, 0x5 -_080D305A: - ldr r0, [r6] - adds r1, r4, 0 - movs r2, 0x20 - bl LoadPalette - adds r0, r4, 0 - adds r0, 0x10 - lsls r0, 16 - lsrs r4, r0, 16 - adds r6, 0x8 - subs r5, 0x1 - cmp r5, 0 - bge _080D305A -_080D3074: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D304C - - thumb_func_start sub_80D3080 -sub_80D3080: @ 80D3080 - push {lr} - lsls r0, 16 - lsrs r1, r0, 16 - movs r0, 0xCE - lsls r0, 1 - cmp r1, r0 - bls _080D3092 - movs r1, 0x82 - lsls r1, 1 -_080D3092: - ldr r0, =gMonIconPaletteIndices - adds r0, r1, r0 - ldrb r0, [r0] - pop {r1} - bx r1 - .pool - thumb_func_end sub_80D3080 - - thumb_func_start sub_80D30A0 -sub_80D30A0: @ 80D30A0 - lsls r0, 16 - lsrs r0, 16 - ldr r1, =gMonIconPaletteIndices - adds r0, r1 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_80D30A0 - - thumb_func_start GetValidMonIconPalettePtr -GetValidMonIconPalettePtr: @ 80D30B0 - push {lr} - lsls r0, 16 - lsrs r2, r0, 16 - movs r0, 0xCE - lsls r0, 1 - cmp r2, r0 - bls _080D30C2 - movs r2, 0x82 - lsls r2, 1 -_080D30C2: - ldr r1, =gMonIconPaletteTable - ldr r0, =gMonIconPaletteIndices - adds r0, r2, r0 - ldrb r0, [r0] - lsls r0, 3 - adds r0, r1 - ldr r0, [r0] - pop {r1} - bx r1 - .pool - thumb_func_end GetValidMonIconPalettePtr - - thumb_func_start sub_80D30DC -sub_80D30DC: @ 80D30DC - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - adds r4, r0, 0 - movs r7, 0 - adds r6, r4, 0 - adds r6, 0x2C - ldrb r2, [r6] - movs r0, 0x3F - mov r9, r0 - ands r0, r2 - cmp r0, 0 - bne _080D3190 - movs r1, 0x2A - adds r1, r4 - mov r8, r1 - ldrb r1, [r1] - ldr r0, [r4, 0x8] - lsls r1, 2 - adds r1, r0 - adds r5, r4, 0 - adds r5, 0x2B - ldrb r0, [r5] - ldr r1, [r1] - lsls r0, 2 - adds r0, r1 - movs r1, 0 - ldrsh r3, [r0, r1] - movs r0, 0x2 - negs r0, r0 - cmp r3, r0 - beq _080D3126 - adds r0, 0x1 - cmp r3, r0 - bne _080D312A - b _080D31A4 -_080D3126: - strb r7, [r5] - b _080D31A4 -_080D312A: - ldr r2, =sSpriteImageSizes - ldrb r1, [r4, 0x3] - lsrs r1, 6 - lsls r1, 1 - ldrb r0, [r4, 0x1] - lsrs r0, 6 - lsls r0, 3 - adds r1, r0 - adds r1, r2 - ldrh r2, [r1] - adds r1, r2, 0 - muls r1, r3 - ldr r0, [r4, 0xC] - adds r0, r1 - ldrh r1, [r4, 0x4] - lsls r1, 22 - lsrs r1, 17 - ldr r3, =0x06010000 - adds r1, r3 - bl RequestSpriteCopy - mov r0, r8 - ldrb r1, [r0] - ldr r0, [r4, 0x8] - lsls r1, 2 - adds r1, r0 - ldrb r0, [r5] - ldr r1, [r1] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - lsls r0, 10 - lsrs r0, 26 - mov r1, r9 - ands r1, r0 - ldrb r2, [r6] - movs r0, 0x40 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r6] - ldrb r0, [r5] - adds r0, 0x1 - strb r0, [r5] - ldrb r7, [r5] - b _080D31A4 - .pool -_080D3190: - lsls r0, r2, 26 - lsrs r0, 26 - subs r0, 0x1 - movs r1, 0x3F - ands r0, r1 - movs r1, 0x40 - negs r1, r1 - ands r1, r2 - orrs r1, r0 - strb r1, [r6] -_080D31A4: - adds r0, r7, 0 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_80D30DC - - thumb_func_start sub_80D31B4 -sub_80D31B4: @ 80D31B4 - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - sub sp, 0x38 - mov r9, r0 - adds r4, r1, 0 - adds r5, r2, 0 - mov r8, r3 - lsls r4, 16 - lsrs r4, 16 - lsls r5, 16 - lsrs r5, 16 - mov r0, r8 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - movs r0, 0 - str r0, [sp, 0x30] - ldr r2, =sSpriteImageSizes - mov r0, r9 - ldr r6, [r0] - ldrb r1, [r6, 0x3] - lsrs r1, 6 - lsls r1, 1 - ldrb r0, [r6, 0x1] - lsrs r0, 6 - lsls r0, 3 - adds r1, r0 - adds r1, r2 - ldrh r2, [r1] - ldr r1, =0xffff0000 - add r3, sp, 0x30 - ldr r0, [r3, 0x4] - ands r0, r1 - orrs r0, r2 - str r0, [r3, 0x4] - add r1, sp, 0x18 - ldr r0, =0x0000ffff - strh r0, [r1] - mov r0, r9 - ldrh r2, [r0, 0x14] - mov r0, sp - adds r0, 0x1A - strh r2, [r0] - str r6, [sp, 0x1C] - mov r2, r9 - ldr r0, [r2, 0x8] - str r0, [sp, 0x20] - str r3, [sp, 0x24] - ldr r0, [r2, 0xC] - str r0, [sp, 0x28] - ldr r0, [r2, 0x10] - str r0, [sp, 0x2C] - mov r0, sp - movs r2, 0x18 - bl memcpy - lsls r4, 16 - asrs r4, 16 - lsls r5, 16 - asrs r5, 16 - mov r0, sp - adds r1, r4, 0 - adds r2, r5, 0 - mov r3, r8 - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - ldr r6, =gSprites - lsls r3, r0, 4 - adds r3, r0 - lsls r3, 2 - adds r4, r3, r6 - adds r5, r4, 0 - adds r5, 0x2C - ldrb r1, [r5] - movs r2, 0x40 - orrs r1, r2 - strb r1, [r5] - adds r4, 0x3F - ldrb r2, [r4] - movs r1, 0x5 - negs r1, r1 - ands r1, r2 - strb r1, [r4] - adds r6, 0xC - adds r3, r6 - mov r2, r9 - ldr r1, [r2, 0x4] - str r1, [r3] - add sp, 0x38 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end sub_80D31B4 - - thumb_func_start sub_80D328C -sub_80D328C: @ 80D328C - push {lr} - sub sp, 0x8 - movs r1, 0 - str r1, [sp] - ldr r3, =sSpriteImageSizes - ldrb r2, [r0, 0x3] - lsrs r2, 6 - lsls r2, 1 - ldrb r1, [r0, 0x1] - lsrs r1, 6 - lsls r1, 3 - adds r2, r1 - adds r2, r3 - ldrh r3, [r2] - ldr r2, =0xffff0000 - ldr r1, [sp, 0x4] - ands r1, r2 - orrs r1, r3 - str r1, [sp, 0x4] - mov r1, sp - str r1, [r0, 0xC] - bl DestroySprite - add sp, 0x8 - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D328C - - thumb_func_start sub_80D32C8 -sub_80D32C8: @ 80D32C8 - mov r12, r0 - adds r0, 0x2A - movs r3, 0 - strb r1, [r0] - mov r2, r12 - adds r2, 0x2C - ldrb r1, [r2] - movs r0, 0x40 - negs r0, r0 - ands r0, r1 - strb r0, [r2] - mov r0, r12 - adds r0, 0x2B - strb r3, [r0] - bx lr - thumb_func_end sub_80D32C8 - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/pokemon_storage_system.s b/asm/pokemon_storage_system.s index a74538fb1..21647dfdf 100644 --- a/asm/pokemon_storage_system.s +++ b/asm/pokemon_storage_system.s @@ -7034,7 +7034,7 @@ _080CAEFA: thumb_func_start sub_80CAF04 sub_80CAF04: @ 80CAF04 push {r4-r6,lr} - bl sub_80D2F04 + bl LoadMonIconPalettes movs r2, 0 ldr r3, =gUnknown_02039D08 ldr r5, =0x00000b08 diff --git a/asm/rom_8011DC0.s b/asm/rom_8011DC0.s index 4d50a5271..3a7f41d0b 100644 --- a/asm/rom_8011DC0.s +++ b/asm/rom_8011DC0.s @@ -17828,7 +17828,7 @@ _0801BD1A: bl CopyBgTilemapBufferToVram b _0801BD86 _0801BD34: - bl sub_80D2F04 + bl LoadMonIconPalettes b _0801BD86 _0801BD3A: movs r0, 0x1 @@ -17991,7 +17991,7 @@ _0801BE56: .pool _0801BE94: bl sub_801C61C - bl sub_80D2F9C + bl FreeMonIconPalettes b _0801BEDA _0801BE9E: ldr r0, =gUnknown_02022C60 diff --git a/asm/trade.s b/asm/trade.s index 7d3ec4a8a..b96fb8ca9 100644 --- a/asm/trade.s +++ b/asm/trade.s @@ -246,7 +246,7 @@ _08077310: movs r1, 0x1 movs r2, 0xE0 bl sub_809882C - bl sub_80D2F04 + bl LoadMonIconPalettes ldr r2, =gUnknown_0203229C ldr r0, [r2] adds r0, 0x69 diff --git a/include/pokemon_icon.h b/include/pokemon_icon.h index e7fc81ce4..f1c8a3e61 100644 --- a/include/pokemon_icon.h +++ b/include/pokemon_icon.h @@ -1,15 +1,20 @@ #ifndef GUARD_POKEMON_ICON_H #define GUARD_POKEMON_ICON_H +const u8 *GetMonIconTiles(u16 species, bool32); const u8 *GetMonIconPtr(u16 speciesId, u32 personality, u32 frameNo); const u16 *GetValidMonIconPalettePtr(u16 speciesId); u16 GetUnownLetterByPersonality(u32 personality); u16 sub_80D2E84(u16 speciesId); -void sub_80D2F04(void); -void sub_80D2F68(u16 iconId); -u8 sub_80D2D78(u16 iconId, void callback(struct Sprite *), u16 x, u16 y, u16 a4, u8 a5); -void sub_80D2FF0(u16 iconId); +void LoadMonIconPalettes(void); +void LoadMonIconPalette(u16 species); +void FreeMonIconPalettes(void); +u8 sub_80D2D78(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority, bool32 extra); +void FreeMonIconPalette(u16 species); void sub_80D2EF8(struct Sprite *sprite); -u8 CreateMonIcon(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority, u32 personality, int a7); +u8 CreateMonIcon(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority, u32 personality, bool32 extra); +u8 UpdateMonIconFrame(struct Sprite *sprite); +void LoadMonIconPalette(u16 species); +void sub_80D328C(struct Sprite *sprite); #endif // GUARD_POKEMON_ICON_H diff --git a/ld_script.txt b/ld_script.txt index 96717763d..dda870d54 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -130,7 +130,6 @@ SECTIONS { src/pokemon_storage_system.o(.text); asm/pokemon_storage_system.o(.text); src/pokemon_icon.o(.text); - asm/pokemon_icon.o(.text); src/script_movement.o(.text); asm/fldeff_cut.o(.text); src/mail_data.o(.text); diff --git a/src/mail.c b/src/mail.c index ac263ac67..85ba86974 100644 --- a/src/mail.c +++ b/src/mail.c @@ -403,11 +403,11 @@ static bool8 MailReadBuildGraphics(void) switch (sMailRead->animsActive) { case 1: - sub_80D2F68(icon); + LoadMonIconPalette(icon); sMailRead->monIconSprite = sub_80D2D78(icon, SpriteCallbackDummy, 0x60, 0x80, 0, 0); break; case 2: - sub_80D2F68(icon); + LoadMonIconPalette(icon); sMailRead->monIconSprite = sub_80D2D78(icon, SpriteCallbackDummy, 0x28, 0x80, 0, 0); break; } @@ -540,7 +540,7 @@ static void CB2_ExitMailReadFreeVars(void) { case 1: case 2: - sub_80D2FF0(sub_80D2E84(sMailRead->mail->species)); + FreeMonIconPalette(sub_80D2E84(sMailRead->mail->species)); sub_80D2EF8(&gSprites[sMailRead->monIconSprite]); } memset(sMailRead, 0, sizeof(*sMailRead)); diff --git a/src/naming_screen.c b/src/naming_screen.c index be306c765..0e350aa35 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -75,7 +75,7 @@ static const u8 gSpriteImage_858BCB8[] = INCBIN_U8("graphics/naming_screen/pc_ic static const u16 gUnknown_0858BD78[] = INCBIN_U16("graphics/naming_screen/0.gbapal"); static const u16 gUnknown_0858BD98[] = INCBIN_U16("graphics/naming_screen/1.gbapal"); -static const u8 *const gUnknown_0858BDB8[] = +static const u8 *const gUnknown_0858BDB8[] = { gText_PkmnTransferredSomeonesPC, gText_PkmnTransferredLanettesPC, @@ -85,7 +85,7 @@ static const u8 *const gUnknown_0858BDB8[] = static const u8 gUnknown_0858BDC8[] = _("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!"); -static const struct BgTemplate gUnknown_0858BE00[] = +static const struct BgTemplate gUnknown_0858BE00[] = { { .bg = 0, @@ -226,10 +226,10 @@ void DoNamingScreen(u8 templateNum, u8 *destBuffer, u16 monSpecies, u16 monGende gNamingScreenData->monPersonality = monPersonality; gNamingScreenData->destBuffer = destBuffer; gNamingScreenData->returnCallback = returnCallback; - + if (templateNum == 0) StartTimer1(); - + SetMainCallback2(C2_NamingScreen); } } @@ -316,15 +316,15 @@ static void sub_80E2FA4(void) static void NamingScreen_InitBGs(void) { u8 i; - + DmaClearLarge16(3, (void *)VRAM, VRAM_SIZE, 0x1000); DmaClear32(3, (void *)OAM, OAM_SIZE); DmaClear16(3, (void *)PLTT, PLTT_SIZE); - + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, gUnknown_0858BE00, 4); - + ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); ChangeBgX(1, 0, 0); @@ -333,21 +333,21 @@ static void NamingScreen_InitBGs(void) ChangeBgY(2, 0, 0); ChangeBgX(3, 0, 0); ChangeBgY(3, 0, 0); - + sub_81971D0(); sub_8197200(); - + for (i = 0; i < 5; i++) gNamingScreenData->windows[i] = AddWindow(&gUnknown_0858BE10[i]); - + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0xC, 0x8)); - + SetBgTilemapBuffer(1, gNamingScreenData->tilemapBuffer1); SetBgTilemapBuffer(2, gNamingScreenData->tilemapBuffer2); SetBgTilemapBuffer(3, gNamingScreenData->tilemapBuffer3); - + FillBgTilemapBufferRect_Palette0(1, 0, 0, 0, 0x20, 0x20); FillBgTilemapBufferRect_Palette0(2, 0, 0, 0, 0x20, 0x20); FillBgTilemapBufferRect_Palette0(3, 0, 0, 0, 0x20, 0x20); @@ -511,7 +511,7 @@ static bool8 MainState_WaitFadeOutAndExit(void) static void DisplaySentToPCMessage(void) { u8 stringToDisplay = 0; - + if (!sub_813B260()) { StringCopy(gStringVar1, GetBoxNamePtr(VarGet(VAR_STORAGE_UNKNOWN))); @@ -524,10 +524,10 @@ static void DisplaySentToPCMessage(void) StringCopy(gStringVar3, GetBoxNamePtr(get_unknown_box_id())); stringToDisplay = 2; } - + if (FlagGet(FLAG_SYS_PC_LANETTE)) stringToDisplay++; - + StringExpandPlaceholders(gStringVar4, gUnknown_0858BDB8[stringToDisplay]); NewMenuHelpers_DrawDialogueFrame(0, 0); gTextFlags.flag_0 = TRUE; @@ -538,10 +538,10 @@ static void DisplaySentToPCMessage(void) static bool8 sub_80E3604(void) { RunTextPrinters(); - + if (!IsTextPrinterActive(0) && (gMain.newKeys & A_BUTTON)) gNamingScreenData->state = MAIN_STATE_BEGIN_FADE_OUT; - + return FALSE; } @@ -562,17 +562,17 @@ static bool8 MainState_WaitPageSwap(void) s16 cursorX; s16 cursorY; bool32 var3; - + if (IsPageSwapAnimNotInProgress()) { - + GetCursorPos(&cursorX, &cursorY); var3 = (cursorX == GetCurrentPageColumnCount()); - + gNamingScreenData->state = MAIN_STATE_HANDLE_INPUT; gNamingScreenData->currentPage++; gNamingScreenData->currentPage %= 3; - + if (var3) { cursorX = GetCurrentPageColumnCount(); @@ -582,7 +582,7 @@ static bool8 MainState_WaitPageSwap(void) if (cursorX >= GetCurrentPageColumnCount()) cursorX = GetCurrentPageColumnCount() - 1; } - + SetCursorPos(cursorX, cursorY); sub_80E4E5C(); SetInputState(INPUT_STATE_ENABLED); @@ -603,7 +603,7 @@ static bool8 PageSwapAnimState_1(struct Task *); static bool8 PageSwapAnimState_2(struct Task *); static bool8 PageSwapAnimState_Done(struct Task *); -static bool8 (*const sPageSwapAnimStateFuncs[])(struct Task *) = +static bool8 (*const sPageSwapAnimStateFuncs[])(struct Task *) = { PageSwapAnimState_Init, PageSwapAnimState_1, @@ -754,7 +754,7 @@ static void Task_80E39BC(u8 taskId) task->data[3] += task->data[4]; task->data[6] += task->data[4]; } - + if (task->data[3] == 16 && task->data[6] == 22) { task->data[4] = -4; @@ -893,7 +893,7 @@ static void CursorInit(void) static void SetCursorPos(s16 x, s16 y) { struct Sprite *cursorSprite = &gSprites[gNamingScreenData->cursorSpriteId]; - + if (x < gUnknown_0858BEA0[sub_80E3274()]) cursorSprite->pos1.x = gUnknown_0858BEA3[x + sub_80E3274() * 8] + 38; else @@ -909,7 +909,7 @@ static void SetCursorPos(s16 x, s16 y) static void GetCursorPos(s16 *x, s16 *y) { struct Sprite *cursorSprite = &gSprites[gNamingScreenData->cursorSpriteId]; - + *x = cursorSprite->data[0]; *y = cursorSprite->data[1]; } @@ -1133,7 +1133,7 @@ static void CreateInputTargetIcon(void) static void TaskDummy2(void) { - + } static void NamingScreen_CreatePlayerIcon(void) @@ -1160,7 +1160,7 @@ static void NamingScreen_CreateMonIcon(void) { u8 spriteId; - sub_80D2F04(); + LoadMonIconPalettes(); spriteId = CreateMonIcon(gNamingScreenData->monSpecies, SpriteCallbackDummy, 0x38, 0x28, 0, gNamingScreenData->monPersonality, 1); gSprites[spriteId].oam.priority = 3; } @@ -1331,7 +1331,7 @@ static void InputState_Disabled(struct Task *task) static void InputState_Enabled(struct Task *task) { task->tKeyboardEvent = 0; - + if (gMain.newKeys & A_BUTTON) task->tKeyboardEvent = KBEVENT_PRESSED_A; else if (gMain.newKeys & B_BUTTON) @@ -1454,7 +1454,7 @@ static void sub_80E4894(void) static void sub_80E48E8(void) { u8 buffer[0x20]; - + StringCopy(buffer, gSpeciesNames[gNamingScreenData->monSpecies]); StringAppendN(buffer, gNamingScreenData->template->title, 15); FillWindowPixelBuffer(gNamingScreenData->windows[3], 0x11); @@ -1492,10 +1492,10 @@ static void sub_80E498C(void) static void TaskDummy3(void) { - + } -static const u8 sGenderColors[2][3] = +static const u8 sGenderColors[2][3] = { {0, 9, 8}, {0, 5, 4} @@ -1505,7 +1505,7 @@ static void sub_80E49BC(void) { u8 genderSymbol[2]; bool8 isFemale = FALSE; - + StringCopy(genderSymbol, gText_MaleSymbol); if (gNamingScreenData->monGender != MON_GENDERLESS) @@ -1575,7 +1575,7 @@ static bool8 sub_80E4B54(void) sub_80E4D10(); CopyBgTilemapBufferToVram(3); PlaySE(SE_SELECT); - + if (GetPreviousTextCaretPosition() != gNamingScreenData->template->maxChars - 1) return FALSE; else @@ -1633,7 +1633,7 @@ static void sub_80E4CF8(u8 bg, const void *src) static void nullsub_10(u8 a1, u8 a2) { - + } static void sub_80E4D10(void) @@ -1643,18 +1643,18 @@ static void sub_80E4D10(void) u16 unk2; u8 maxChars = gNamingScreenData->template->maxChars; u16 unk = gNamingScreenData->inputCharBaseXPos - 0x40; - + FillWindowPixelBuffer(gNamingScreenData->windows[2], 0x11); - + for (i = 0; i < maxChars; i++) { temp[0] = gNamingScreenData->textBuffer[i]; temp[1] = gExpandedPlaceholder_Empty[0]; unk2 = (sub_80E503C(temp[0]) == 1) ? 2 : 0; - + PrintTextOnWindow(gNamingScreenData->windows[2], 1, temp, i * 8 + unk + unk2, 1, 0xFF, NULL); } - + sub_80E498C(); CopyWindowToVram(gNamingScreenData->windows[2], 2); PutWindowTilemap(gNamingScreenData->windows[2]); @@ -1674,12 +1674,12 @@ static const struct TextColorThing sUnkColorStruct = } }; -static const u8 sFillValues[3] = +static const u8 sFillValues[3] = { 0xEE, 0xDD, 0xFF }; -static const u8 *const sUnkColors[3] = +static const u8 *const sUnkColors[3] = { sUnkColorStruct.colors[1], sUnkColorStruct.colors[0], @@ -1689,18 +1689,18 @@ static const u8 *const sUnkColors[3] = static void sub_80E4DE4(u8 window, u8 a1) { u8 i; - + FillWindowPixelBuffer(window, sFillValues[a1]); - + for (i = 0; i < 4; i++) { box_print(window, 1, 0, i * 16 + 1, sUnkColors[a1], 0, gUnknown_0858C198[a1][i]); } - + PutWindowTilemap(window); } -static const u8 *const gUnknown_0858BF98[] = +static const u8 *const gUnknown_0858BF98[] = { gUnknown_08DD4620, gUnknown_08DD46E0, @@ -1714,7 +1714,7 @@ static void sub_80E4E5C(void) u8 unk3; u8 bg1Priority = GetGpuReg(REG_OFFSET_BG1CNT) & 3; u8 bg2Priority = GetGpuReg(REG_OFFSET_BG2CNT) & 3; - + if (bg1Priority > bg2Priority) { unk1 = 1; @@ -1727,7 +1727,7 @@ static void sub_80E4E5C(void) unk2 = 2; unk3 = gNamingScreenData->windows[1]; } - + sub_80E4CF8(unk1, gUnknown_0858BF98[gNamingScreenData->currentPage]); sub_80E4DE4(unk3, sub_80E3254()); nullsub_10(unk1, sub_80E3254()); @@ -1737,7 +1737,7 @@ static void sub_80E4E5C(void) static void sub_80E4EF0(void) { const u8 color[3] = { 15, 1, 2 }; - + FillWindowPixelBuffer(gNamingScreenData->windows[4], 0xFF); box_print(gNamingScreenData->windows[4], 0, 2, 1, color, 0, gText_MoveOkBack); PutWindowTilemap(gNamingScreenData->windows[4]); @@ -1787,7 +1787,7 @@ static void sub_80E501C(void) static bool8 sub_80E503C(u8 character) { u8 i; - + for (i = 0; gUnknown_0858BDC8[i] != EOS; i++) { if (character == gUnknown_0858BDC8[i]) @@ -1987,20 +1987,20 @@ static const struct SpriteFrameImage gUnknown_0858C080[] = {gSpriteImage_858BCB8, sizeof(gSpriteImage_858BCB8)}, }; -static const union AnimCmd gSpriteAnim_858C090[] = +static const union AnimCmd gSpriteAnim_858C090[] = { ANIMCMD_FRAME(0, 1), ANIMCMD_JUMP(0) }; -static const union AnimCmd gSpriteAnim_858C098[] = +static const union AnimCmd gSpriteAnim_858C098[] = { ANIMCMD_FRAME(4, 8), ANIMCMD_FRAME(8, 8), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_858C0A4[] = +static const union AnimCmd gSpriteAnim_858C0A4[] = { ANIMCMD_FRAME(0, 2), ANIMCMD_FRAME(1, 2), @@ -2023,7 +2023,7 @@ static const union AnimCmd *const gSpriteAnimTable_858C0BC[] = gSpriteAnim_858C0A4 }; -static const struct SpriteTemplate gUnknown_0858C0C0 = +static const struct SpriteTemplate gUnknown_0858C0C0 = { .tileTag = 0x0002, .paletteTag = 0x0004, @@ -2034,7 +2034,7 @@ static const struct SpriteTemplate gUnknown_0858C0C0 = .callback = sub_80E4084 }; -static const struct SpriteTemplate gUnknown_0858C0D8 = +static const struct SpriteTemplate gUnknown_0858C0D8 = { .tileTag = 0x0003, .paletteTag = 0x0001, @@ -2045,7 +2045,7 @@ static const struct SpriteTemplate gUnknown_0858C0D8 = .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_0858C0F0 = +static const struct SpriteTemplate gUnknown_0858C0F0 = { .tileTag = 0x0004, .paletteTag = 0x0004, @@ -2056,7 +2056,7 @@ static const struct SpriteTemplate gUnknown_0858C0F0 = .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_0858C108 = +static const struct SpriteTemplate gUnknown_0858C108 = { .tileTag = 0x0000, .paletteTag = 0x0006, @@ -2067,7 +2067,7 @@ static const struct SpriteTemplate gUnknown_0858C108 = .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_0858C120 = +static const struct SpriteTemplate gUnknown_0858C120 = { .tileTag = 0x0001, .paletteTag = 0x0007, @@ -2078,7 +2078,7 @@ static const struct SpriteTemplate gUnknown_0858C120 = .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_0858C138 = +static const struct SpriteTemplate gUnknown_0858C138 = { .tileTag = 0x0007, .paletteTag = 0x0005, @@ -2089,7 +2089,7 @@ static const struct SpriteTemplate gUnknown_0858C138 = .callback = sub_80E3B30 }; -static const struct SpriteTemplate sSpriteTemplate_InputArrow = +static const struct SpriteTemplate sSpriteTemplate_InputArrow = { .tileTag = 0x000A, .paletteTag = 0x0003, @@ -2100,7 +2100,7 @@ static const struct SpriteTemplate sSpriteTemplate_InputArrow = .callback = sub_80E3C20 }; -static const struct SpriteTemplate sSpriteTemplate_Underscore = +static const struct SpriteTemplate sSpriteTemplate_Underscore = { .tileTag = 0x000B, .paletteTag = 0x0003, @@ -2111,7 +2111,7 @@ static const struct SpriteTemplate sSpriteTemplate_Underscore = .callback = sub_80E3C6C }; -static const struct SpriteTemplate gUnknown_0858C180 = +static const struct SpriteTemplate gUnknown_0858C180 = { .tileTag = 0xFFFF, .paletteTag = 0x0000, @@ -2122,7 +2122,7 @@ static const struct SpriteTemplate gUnknown_0858C180 = .callback = SpriteCallbackDummy }; -static const u8* const gUnknown_0858C198[][4] = +static const u8* const gUnknown_0858C198[][4] = { { gUnknown_0862B88D, diff --git a/src/pokemon_icon.c b/src/pokemon_icon.c index 4d1cc51c5..253ab2cb4 100644 --- a/src/pokemon_icon.c +++ b/src/pokemon_icon.c @@ -1,9 +1,28 @@ #include "global.h" #include "sprite.h" +#include "mail.h" #include "graphics.h" +#include "constants/species.h" +#include "palette.h" +#include "pokemon_icon.h" #define POKE_ICON_BASE_PAL_TAG 56000 +struct MonIconSpriteTemplate +{ + const struct OamData *oam; + const u8 *image; + const union AnimCmd *const *anims; + const union AffineAnimCmd *const *affineAnims; + void (*callback)(struct Sprite *); + u16 paletteTag; +}; + +// static functions +static u8 CreateMonIconSprite(struct MonIconSpriteTemplate *, s16, s16, u8); + +// .rodata + const u8 * const gMonIconTable[] = { gMonIcon_Bulbasaur, @@ -1012,3 +1031,288 @@ const u16 sSpriteImageSizes[3][4] = 0x400, // 4×8 }, }; + +u8 CreateMonIcon(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority, u32 personality, bool32 extra) +{ + u8 spriteId; + struct MonIconSpriteTemplate iconTemplate = + { + .oam = &sMonIconOamData, + .image = GetMonIconPtr(species, personality, extra), + .anims = sMonIconAnims, + .affineAnims = sMonIconAffineAnims, + .callback = callback, + .paletteTag = POKE_ICON_BASE_PAL_TAG + gMonIconPaletteIndices[species], + }; + + if (species > SPECIES_EGG) + iconTemplate.paletteTag = POKE_ICON_BASE_PAL_TAG; + + spriteId = CreateMonIconSprite(&iconTemplate, x, y, subpriority); + + UpdateMonIconFrame(&gSprites[spriteId]); + + return spriteId; +} + +u8 sub_80D2D78(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority, bool32 extra) +{ + u8 spriteId; + struct MonIconSpriteTemplate iconTemplate = + { + .oam = &sMonIconOamData, + .image = NULL, + .anims = sMonIconAnims, + .affineAnims = sMonIconAffineAnims, + .callback = callback, + .paletteTag = POKE_ICON_BASE_PAL_TAG + gMonIconPaletteIndices[species], + }; + + iconTemplate.image = GetMonIconTiles(species, extra); + spriteId = CreateMonIconSprite(&iconTemplate, x, y, subpriority); + + UpdateMonIconFrame(&gSprites[spriteId]); + + return spriteId; +} + +u16 mon_icon_convert_unown_species_id(u16 species, u32 personality) +{ + u16 result; + + if (species == SPECIES_UNOWN) + { + u16 letter = GetUnownLetterByPersonality(personality); + if (letter == 0) + letter = SPECIES_UNOWN; + else + letter += (SPECIES_UNOWN_B - 1); + result = letter; + } + else + { + if (species > SPECIES_EGG) + result = 260; + else + result = species; + } + + return result; +} + +u16 GetUnownLetterByPersonality(u32 personality) +{ + if (!personality) + return 0; + return (((personality & 0x3000000) >> 18) | ((personality & 0x30000) >> 12) | ((personality & 0x300) >> 6) | (personality & 0x3)) % 0x1C; +} + +u16 sub_80D2E84(u16 species) +{ + u16 value; + + if (MailSpeciesToSpecies(species, &value) == SPECIES_UNOWN) + { + if (value == 0) + value += SPECIES_UNOWN; + else + value += (SPECIES_UNOWN_B - 1); + return value; + } + else + { + if(species > (SPECIES_UNOWN_B - 1)) + species = 260; + return mon_icon_convert_unown_species_id(species, 0); + } +} + +const u8 *GetMonIconPtr(u16 species, u32 personality, bool32 extra) +{ + return GetMonIconTiles(mon_icon_convert_unown_species_id(species, personality), extra); +} + + + +void sub_80D2EF8(struct Sprite *sprite) +{ + sub_80D328C(sprite); +} + +void LoadMonIconPalettes(void) +{ + u8 i; + for (i = 0; i < 6; i++) + LoadSpritePalette(&gMonIconPaletteTable[i]); +} + +// unused +void SafeLoadMonIconPalette(u16 species) +{ + u8 palIndex; + if (species > SPECIES_EGG) + species = 260; + palIndex = gMonIconPaletteIndices[species]; + if (IndexOfSpritePaletteTag(gMonIconPaletteTable[palIndex].tag) == 0xFF) + LoadSpritePalette(&gMonIconPaletteTable[palIndex]); +} + +void LoadMonIconPalette(u16 species) +{ + u8 palIndex = gMonIconPaletteIndices[species]; + if (IndexOfSpritePaletteTag(gMonIconPaletteTable[palIndex].tag) == 0xFF) + LoadSpritePalette(&gMonIconPaletteTable[palIndex]); +} + +void FreeMonIconPalettes(void) +{ + u8 i; + for (i = 0; i < 6; i++) + FreeSpritePaletteByTag(gMonIconPaletteTable[i].tag); +} + +// unused +void SafeFreeMonIconPalette(u16 species) +{ + u8 palIndex; + if (species > SPECIES_EGG) + species = 260; + palIndex = gMonIconPaletteIndices[species]; + FreeSpritePaletteByTag(gMonIconPaletteTable[palIndex].tag); +} + +void FreeMonIconPalette(u16 species) +{ + u8 palIndex; + palIndex = gMonIconPaletteIndices[species]; + FreeSpritePaletteByTag(gMonIconPaletteTable[palIndex].tag); +} + +void sub_80D3014(struct Sprite *sprite) +{ + UpdateMonIconFrame(sprite); +} + +const u8* GetMonIconTiles(u16 species, bool32 extra) +{ + const u8* iconSprite = gMonIconTable[species]; + if(species == SPECIES_DEOXYS && extra == TRUE) + { + iconSprite = (const u8*)(0x400 + (u32)iconSprite); //WTF? + } + return iconSprite; +} + +void sub_80D304C(u16 offset) +{ + s32 i; + const struct SpritePalette* monIconPalettePtr; + + if(offset <= 0xA0) + { + monIconPalettePtr = gMonIconPaletteTable; + for(i = 5; i >= 0 ; i--) + { + LoadPalette(monIconPalettePtr->data, offset, 0x20); + offset += 0x10; + monIconPalettePtr++; + } + } +} + +u8 sub_80D3080(u16 species) +{ + if (species > SPECIES_EGG) + species = 260; + return gMonIconPaletteIndices[species]; +} + +u8 sub_80D30A0(u16 species) +{ + return gMonIconPaletteIndices[species]; +} + +const u16* GetValidMonIconPalettePtr(u16 species) +{ + if (species > SPECIES_EGG) + species = 260; + return gMonIconPaletteTable[gMonIconPaletteIndices[species]].data; +} + +// TODO: try to find a way to avoid using asm statement +u8 UpdateMonIconFrame(struct Sprite *sprite) +{ + u8 result = 0; + + if (sprite->animDelayCounter == 0) + { + s16 frame = sprite->anims[sprite->animNum][sprite->animCmdIndex].frame.imageValue; + + switch (frame) + { + case -1: + break; + case -2: + sprite->animCmdIndex = 0; + break; + default: + RequestSpriteCopy( + // pointer arithmetic is needed to get the correct pointer to perform the sprite copy on. + // because sprite->images is a struct def, it has to be casted to (u8 *) before any + // arithmetic can be performed. + (u8 *)sprite->images + (sSpriteImageSizes[sprite->oam.shape][sprite->oam.size] * frame), + (u8 *)(OBJ_VRAM0 + sprite->oam.tileNum * TILE_SIZE_4BPP), + sSpriteImageSizes[sprite->oam.shape][sprite->oam.size]); + { + register u8 duration asm("r0") = sprite->anims[sprite->animNum][sprite->animCmdIndex].frame.duration; + sprite->animDelayCounter = duration; + } + sprite->animCmdIndex++; + result = sprite->animCmdIndex; + break; + } + } + else + { + sprite->animDelayCounter--; + } + return result; +} + +static u8 CreateMonIconSprite(struct MonIconSpriteTemplate *iconTemplate, s16 x, s16 y, u8 subpriority) +{ + u8 spriteId; + + struct SpriteFrameImage image = { NULL, sSpriteImageSizes[iconTemplate->oam->shape][iconTemplate->oam->size] }; + + struct SpriteTemplate spriteTemplate = + { + .tileTag = 0xFFFF, + .paletteTag = iconTemplate->paletteTag, + .oam = iconTemplate->oam, + .anims = iconTemplate->anims, + .images = &image, + .affineAnims = iconTemplate->affineAnims, + .callback = iconTemplate->callback, + }; + + spriteId = CreateSprite(&spriteTemplate, x, y, subpriority); + gSprites[spriteId].animPaused = TRUE; + gSprites[spriteId].animBeginning = FALSE; + gSprites[spriteId].images = (const struct SpriteFrameImage *)iconTemplate->image; + return spriteId; +} + +void sub_80D328C(struct Sprite *sprite) +{ + struct SpriteFrameImage image = { NULL, sSpriteImageSizes[sprite->oam.shape][sprite->oam.size] }; + sprite->images = ℑ + DestroySprite(sprite); +} + +void sub_80D32C8(struct Sprite *sprite, u8 animNum) +{ + sprite->animNum = animNum; + sprite->animDelayCounter = 0; + sprite->animCmdIndex = 0; +}