decompile item icon

This commit is contained in:
DizzyEggg 2018-02-02 16:06:20 +01:00
parent eb6aed50e5
commit e13eacda39
15 changed files with 378 additions and 508 deletions

View File

@ -5764,7 +5764,7 @@ sub_813ABD4: @ 813ABD4
adds r0, r4, 0
adds r1, r4, 0
adds r2, r5, 0
bl AddItemIconObject
bl AddItemIconSprite
ldr r4, =gUnknown_0203AB6C
strb r0, [r4]
lsls r0, 24

View File

@ -1,468 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start AllocItemIconTemporaryBuffers
@ bool8 AllocItemIconTemporaryBuffers()
AllocItemIconTemporaryBuffers: @ 81AFDE4
push {r4,r5,lr}
ldr r5, =gUnknown_0203CEBC
movs r0, 0x90
lsls r0, 1
bl Alloc
str r0, [r5]
cmp r0, 0
beq _081AFE1A
ldr r4, =gUnknown_0203CEC0
movs r0, 0x80
lsls r0, 2
bl AllocZeroed
str r0, [r4]
cmp r0, 0
beq _081AFE14
movs r0, 0x1
b _081AFE1C
.pool
_081AFE14:
ldr r0, [r5]
bl Free
_081AFE1A:
movs r0, 0
_081AFE1C:
pop {r4,r5}
pop {r1}
bx r1
thumb_func_end AllocItemIconTemporaryBuffers
thumb_func_start FreeItemIconTemporaryBuffers
@ void FreeItemIconTemporaryBuffers()
FreeItemIconTemporaryBuffers: @ 81AFE24
push {lr}
ldr r0, =gUnknown_0203CEBC
ldr r0, [r0]
bl Free
ldr r0, =gUnknown_0203CEC0
ldr r0, [r0]
bl Free
pop {r0}
bx r0
.pool
thumb_func_end FreeItemIconTemporaryBuffers
thumb_func_start CopyItemIconPicTo4x4Buffer
@ void CopyItemIconPicTo4x4Buffer(void *src, void *dest)
CopyItemIconPicTo4x4Buffer: @ 81AFE44
push {r4-r6,lr}
adds r6, r0, 0
adds r5, r1, 0
movs r4, 0
_081AFE4C:
lsls r0, r4, 1
adds r0, r4
lsls r0, 5
adds r0, r6, r0
lsls r1, r4, 7
adds r1, r5, r1
movs r2, 0x30
bl CpuSet
adds r0, r4, 0x1
lsls r0, 24
lsrs r4, r0, 24
cmp r4, 0x2
bls _081AFE4C
pop {r4-r6}
pop {r0}
bx r0
thumb_func_end CopyItemIconPicTo4x4Buffer
thumb_func_start AddItemIconObject
@ u8 AddItemIconObject(u16 tilesTag, u16 paletteTag, u16 itemId)
AddItemIconObject: @ 81AFE70
push {r4-r7,lr}
sub sp, 0x10
lsls r0, 16
lsrs r7, r0, 16
lsls r1, 16
lsrs r6, r1, 16
lsls r2, 16
lsrs r5, r2, 16
bl AllocItemIconTemporaryBuffers
lsls r0, 24
cmp r0, 0
beq _081AFF28
adds r0, r5, 0
movs r1, 0
bl GetItemIconPicOrPalette
ldr r4, =gUnknown_0203CEBC
ldr r1, [r4]
bl LZDecompressWram
ldr r0, [r4]
ldr r4, =gUnknown_0203CEC0
ldr r1, [r4]
bl CopyItemIconPicTo4x4Buffer
ldr r0, [r4]
str r0, [sp]
ldr r4, =0xffff0000
ldr r0, [sp, 0x4]
ands r0, r4
movs r1, 0x80
lsls r1, 2
orrs r0, r1
lsls r2, r7, 16
ldr r1, =0x0000ffff
ands r0, r1
orrs r0, r2
str r0, [sp, 0x4]
mov r0, sp
bl LoadSpriteSheet
adds r0, r5, 0
movs r1, 0x1
bl GetItemIconPicOrPalette
str r0, [sp, 0x8]
add r0, sp, 0x8
ldr r1, [r0, 0x4]
ands r1, r4
orrs r1, r6
str r1, [r0, 0x4]
bl LoadCompressedObjectPalette
movs r0, 0x18
bl Alloc
adds r5, r0, 0
ldr r0, =gUnknown_08614FF4
adds r1, r5, 0
movs r2, 0xC
bl CpuSet
strh r7, [r5]
strh r6, [r5, 0x2]
adds r0, r5, 0
movs r1, 0
movs r2, 0
movs r3, 0
bl CreateSprite
adds r4, r0, 0
lsls r4, 24
lsrs r4, 24
bl FreeItemIconTemporaryBuffers
adds r0, r5, 0
bl Free
adds r0, r4, 0
b _081AFF2A
.pool
_081AFF28:
movs r0, 0x40
_081AFF2A:
add sp, 0x10
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end AddItemIconObject
thumb_func_start AddItemIconObjectWithCustomObjectTemplate
@ u8 AddItemIconObjectWithCustomObjectTemplate(struct objtemplate *objectTemplate, u16 tilesTag, u16 paletteTag, u16 itemId)
AddItemIconObjectWithCustomObjectTemplate: @ 81AFF34
push {r4-r7,lr}
mov r7, r8
push {r7}
sub sp, 0x10
mov r8, r0
lsls r1, 16
lsrs r7, r1, 16
lsls r2, 16
lsrs r6, r2, 16
lsls r3, 16
lsrs r5, r3, 16
bl AllocItemIconTemporaryBuffers
lsls r0, 24
cmp r0, 0
beq _081AFFEC
adds r0, r5, 0
movs r1, 0
bl GetItemIconPicOrPalette
ldr r4, =gUnknown_0203CEBC
ldr r1, [r4]
bl LZDecompressWram
ldr r0, [r4]
ldr r4, =gUnknown_0203CEC0
ldr r1, [r4]
bl CopyItemIconPicTo4x4Buffer
ldr r0, [r4]
str r0, [sp]
ldr r4, =0xffff0000
ldr r0, [sp, 0x4]
ands r0, r4
movs r1, 0x80
lsls r1, 2
orrs r0, r1
lsls r2, r7, 16
ldr r1, =0x0000ffff
ands r0, r1
orrs r0, r2
str r0, [sp, 0x4]
mov r0, sp
bl LoadSpriteSheet
adds r0, r5, 0
movs r1, 0x1
bl GetItemIconPicOrPalette
str r0, [sp, 0x8]
add r0, sp, 0x8
ldr r1, [r0, 0x4]
ands r1, r4
orrs r1, r6
str r1, [r0, 0x4]
bl LoadCompressedObjectPalette
movs r0, 0x18
bl Alloc
adds r5, r0, 0
mov r0, r8
adds r1, r5, 0
movs r2, 0xC
bl CpuSet
strh r7, [r5]
strh r6, [r5, 0x2]
adds r0, r5, 0
movs r1, 0
movs r2, 0
movs r3, 0
bl CreateSprite
adds r4, r0, 0
lsls r4, 24
lsrs r4, 24
bl FreeItemIconTemporaryBuffers
adds r0, r5, 0
bl Free
adds r0, r4, 0
b _081AFFEE
.pool
_081AFFEC:
movs r0, 0x40
_081AFFEE:
add sp, 0x10
pop {r3}
mov r8, r3
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end AddItemIconObjectWithCustomObjectTemplate
thumb_func_start GetItemIconPicOrPalette
@ u32 GetItemIconPicOrPalette(u16 itemId, u8 which)
GetItemIconPicOrPalette: @ 81AFFFC
push {lr}
lsls r0, 16
lsrs r3, r0, 16
lsls r1, 24
lsrs r1, 24
ldr r0, =0x0000ffff
cmp r3, r0
bne _081B0018
ldr r3, =0x00000179
b _081B0022
.pool
_081B0018:
movs r0, 0xBC
lsls r0, 1
cmp r3, r0
bls _081B0022
movs r3, 0
_081B0022:
ldr r2, =gItemIconTable
lsls r0, r1, 2
lsls r1, r3, 3
adds r0, r1
adds r0, r2
ldr r0, [r0]
pop {r1}
bx r1
.pool
thumb_func_end GetItemIconPicOrPalette
thumb_func_start sub_81B0038
sub_81B0038: @ 81B0038
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x4
ldr r4, [sp, 0x24]
lsls r0, 24
lsrs r0, 24
mov r8, r0
lsls r1, 24
lsrs r1, 24
mov r9, r1
lsls r2, 24
lsrs r7, r2, 24
lsls r3, 24
lsrs r3, 24
str r3, [sp]
lsls r4, 24
lsrs r6, r4, 24
bl reset_brm
ldr r0, =gUnknown_0203CEC4
mov r10, r0
movs r0, 0x8E
lsls r0, 2
bl Alloc
adds r5, r0, 0
mov r1, r10
str r5, [r1]
cmp r5, 0
bne _081B0088
ldr r0, [sp, 0x2C]
bl SetMainCallback2
b _081B0194
.pool
_081B0088:
ldr r3, =gUnknown_0203CEC8
movs r1, 0xF
mov r4, r8
ands r1, r4
ldrb r2, [r3, 0x8]
movs r0, 0x10
negs r0, r0
ands r0, r2
orrs r0, r1
strb r0, [r3, 0x8]
ldr r0, [sp, 0x2C]
str r0, [r3]
movs r4, 0
strb r7, [r3, 0xB]
lsls r2, r6, 2
ldrh r1, [r5, 0xA]
movs r0, 0x3
ands r0, r1
orrs r0, r2
strh r0, [r5, 0xA]
ldr r0, [sp, 0x28]
str r0, [r5]
str r4, [r5, 0x4]
ldrb r1, [r5, 0x8]
movs r0, 0xF
negs r0, r0
ands r0, r1
strb r0, [r5, 0x8]
mov r1, r10
ldr r2, [r1]
ldrh r0, [r2, 0x8]
movs r4, 0xFE
lsls r4, 3
adds r1, r4, 0
orrs r0, r1
strh r0, [r2, 0x8]
ldr r0, [r2, 0x8]
movs r1, 0xFE
lsls r1, 10
orrs r0, r1
str r0, [r2, 0x8]
adds r6, r3, 0
mov r5, r8
cmp r5, 0x4
bne _081B00F0
ldrb r0, [r2, 0x8]
movs r1, 0x1
orrs r0, r1
b _081B00F8
.pool
_081B00F0:
ldrb r1, [r2, 0x8]
movs r0, 0x2
negs r0, r0
ands r0, r1
_081B00F8:
strb r0, [r2, 0x8]
mov r0, r9
cmp r0, 0xFF
beq _081B0114
movs r0, 0x3
mov r1, r9
ands r0, r1
lsls r0, 4
ldrb r2, [r6, 0x8]
movs r1, 0x31
negs r1, r1
ands r1, r2
orrs r1, r0
strb r1, [r6, 0x8]
_081B0114:
movs r2, 0
ldr r5, =gUnknown_0203CEC4
movs r4, 0x86
lsls r4, 2
movs r3, 0
_081B011E:
ldr r0, [r5]
lsls r1, r2, 1
adds r0, r4
adds r0, r1
strh r3, [r0]
adds r0, r2, 0x1
lsls r0, 16
lsrs r2, r0, 16
cmp r2, 0xF
bls _081B011E
movs r2, 0
ldr r4, =gUnknown_0203CEC4
movs r3, 0xFF
_081B0138:
ldr r0, [r4]
adds r0, 0xC
adds r0, r2
ldrb r1, [r0]
orrs r1, r3
strb r1, [r0]
adds r0, r2, 0x1
lsls r0, 16
lsrs r2, r0, 16
cmp r2, 0x2
bls _081B0138
ldr r4, [sp]
cmp r4, 0
bne _081B015C
strb r4, [r6, 0x9]
b _081B017E
.pool
_081B015C:
adds r1, r6, 0
movs r0, 0x9
ldrsb r0, [r1, r0]
cmp r0, 0x5
bgt _081B017A
adds r1, r0, 0
movs r0, 0x64
muls r0, r1
ldr r1, =gPlayerParty
adds r0, r1
movs r1, 0xB
bl GetMonData
cmp r0, 0
bne _081B017E
_081B017A:
movs r0, 0
strb r0, [r6, 0x9]
_081B017E:
ldr r2, =gTextFlags
ldrb r1, [r2]
movs r0, 0x5
negs r0, r0
ands r0, r1
strb r0, [r2]
bl CalculatePlayerPartyCount
ldr r0, =c2_811EBD0
bl SetMainCallback2
_081B0194:
add sp, 0x4
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
.pool
thumb_func_end sub_81B0038
.align 2, 0 @ Don't pad with nop.

View File

@ -348,7 +348,7 @@ AddBagItemIconObject: @ 80D4F38
adds r0, r4, 0
adds r1, r4, 0
adds r2, r6, 0
bl AddItemIconObject
bl AddItemIconSprite
lsls r0, 24
lsrs r2, r0, 24
cmp r2, 0x40

View File

@ -46462,7 +46462,7 @@ _080214C6:
lsrs r3, 16
ldr r0, =gUnknown_082F436C
adds r1, r2, 0
bl AddItemIconObjectWithCustomObjectTemplate
bl AddCustomItemIconSprite
lsls r0, 24
lsrs r0, 24
mov r2, r9

View File

@ -4,6 +4,192 @@
.syntax unified
.text
thumb_func_start sub_81B0038
sub_81B0038: @ 81B0038
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x4
ldr r4, [sp, 0x24]
lsls r0, 24
lsrs r0, 24
mov r8, r0
lsls r1, 24
lsrs r1, 24
mov r9, r1
lsls r2, 24
lsrs r7, r2, 24
lsls r3, 24
lsrs r3, 24
str r3, [sp]
lsls r4, 24
lsrs r6, r4, 24
bl reset_brm
ldr r0, =gUnknown_0203CEC4
mov r10, r0
movs r0, 0x8E
lsls r0, 2
bl Alloc
adds r5, r0, 0
mov r1, r10
str r5, [r1]
cmp r5, 0
bne _081B0088
ldr r0, [sp, 0x2C]
bl SetMainCallback2
b _081B0194
.pool
_081B0088:
ldr r3, =gUnknown_0203CEC8
movs r1, 0xF
mov r4, r8
ands r1, r4
ldrb r2, [r3, 0x8]
movs r0, 0x10
negs r0, r0
ands r0, r2
orrs r0, r1
strb r0, [r3, 0x8]
ldr r0, [sp, 0x2C]
str r0, [r3]
movs r4, 0
strb r7, [r3, 0xB]
lsls r2, r6, 2
ldrh r1, [r5, 0xA]
movs r0, 0x3
ands r0, r1
orrs r0, r2
strh r0, [r5, 0xA]
ldr r0, [sp, 0x28]
str r0, [r5]
str r4, [r5, 0x4]
ldrb r1, [r5, 0x8]
movs r0, 0xF
negs r0, r0
ands r0, r1
strb r0, [r5, 0x8]
mov r1, r10
ldr r2, [r1]
ldrh r0, [r2, 0x8]
movs r4, 0xFE
lsls r4, 3
adds r1, r4, 0
orrs r0, r1
strh r0, [r2, 0x8]
ldr r0, [r2, 0x8]
movs r1, 0xFE
lsls r1, 10
orrs r0, r1
str r0, [r2, 0x8]
adds r6, r3, 0
mov r5, r8
cmp r5, 0x4
bne _081B00F0
ldrb r0, [r2, 0x8]
movs r1, 0x1
orrs r0, r1
b _081B00F8
.pool
_081B00F0:
ldrb r1, [r2, 0x8]
movs r0, 0x2
negs r0, r0
ands r0, r1
_081B00F8:
strb r0, [r2, 0x8]
mov r0, r9
cmp r0, 0xFF
beq _081B0114
movs r0, 0x3
mov r1, r9
ands r0, r1
lsls r0, 4
ldrb r2, [r6, 0x8]
movs r1, 0x31
negs r1, r1
ands r1, r2
orrs r1, r0
strb r1, [r6, 0x8]
_081B0114:
movs r2, 0
ldr r5, =gUnknown_0203CEC4
movs r4, 0x86
lsls r4, 2
movs r3, 0
_081B011E:
ldr r0, [r5]
lsls r1, r2, 1
adds r0, r4
adds r0, r1
strh r3, [r0]
adds r0, r2, 0x1
lsls r0, 16
lsrs r2, r0, 16
cmp r2, 0xF
bls _081B011E
movs r2, 0
ldr r4, =gUnknown_0203CEC4
movs r3, 0xFF
_081B0138:
ldr r0, [r4]
adds r0, 0xC
adds r0, r2
ldrb r1, [r0]
orrs r1, r3
strb r1, [r0]
adds r0, r2, 0x1
lsls r0, 16
lsrs r2, r0, 16
cmp r2, 0x2
bls _081B0138
ldr r4, [sp]
cmp r4, 0
bne _081B015C
strb r4, [r6, 0x9]
b _081B017E
.pool
_081B015C:
adds r1, r6, 0
movs r0, 0x9
ldrsb r0, [r1, r0]
cmp r0, 0x5
bgt _081B017A
adds r1, r0, 0
movs r0, 0x64
muls r0, r1
ldr r1, =gPlayerParty
adds r0, r1
movs r1, 0xB
bl GetMonData
cmp r0, 0
bne _081B017E
_081B017A:
movs r0, 0
strb r0, [r6, 0x9]
_081B017E:
ldr r2, =gTextFlags
ldrb r1, [r2]
movs r0, 0x5
negs r0, r0
ands r0, r1
strb r0, [r2]
bl CalculatePlayerPartyCount
ldr r0, =c2_811EBD0
bl SetMainCallback2
_081B0194:
add sp, 0x4
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
.pool
thumb_func_end sub_81B0038
thumb_func_start sub_81B01B0
sub_81B01B0: @ 81B01B0

View File

@ -2179,7 +2179,7 @@ sub_816C060: @ 816C060
adds r0, r4, 0
adds r1, r4, 0
adds r2, r6, 0
bl AddItemIconObject
bl AddItemIconSprite
lsls r0, 24
lsrs r2, r0, 24
cmp r2, 0x40

View File

@ -5756,7 +5756,7 @@ sub_81C6F90: @ 81C6F90
adds r0, r4, 0
adds r1, r4, 0
adds r2, r6, 0
bl AddItemIconObject
bl AddItemIconSprite
lsls r0, 24
lsrs r2, r0, 24
cmp r2, 0x40

View File

@ -969,7 +969,7 @@ _080E02AE:
ldr r0, =0x0000083e
adds r1, r3, r0
adds r0, r1, 0
bl AddItemIconObject
bl AddItemIconSprite
lsls r0, 24
lsrs r2, r0, 24
cmp r2, 0x40

View File

@ -6,18 +6,3 @@
@ 8614410
.include "data/graphics/items/item_icon_table.inc"
gUnknown_08614FE0:: @ 8614FE0
.2byte 0
.2byte 0x8000
.2byte 0x2400
.2byte 0
gUnknown_08614FE8:: @ 8614FE8
obj_image_anim_frame 0, 0
obj_image_anim_end
gUnknown_08614FF0:: @ 8614FF0
.4byte gUnknown_08614FE8
gUnknown_08614FF4:: @ 8614FF4
spr_template 0, 0, gUnknown_08614FE0, gUnknown_08614FF0, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy

View File

@ -383,6 +383,9 @@
#define ITEM_MAGMA_EMBLEM 375
#define ITEM_OLD_SEA_MAP 376
#define ITEM_LAST_ID 376
#define ITEM_FIELD_ARROW 377
#define FIRST_BERRY_INDEX ITEM_CHERI_BERRY
#define LAST_BERRY_INDEX ITEM_ENIGMA_BERRY
#define ITEM_TO_BERRY(itemId)(((itemId - FIRST_BERRY_INDEX) + 1))

View File

@ -1,17 +1,16 @@
//
// Created by scott on 10/20/2017.
//
#ifndef GUARD_ITEM_ICON_H
#define GUARD_ITEM_ICON_H
extern EWRAM_DATA void *gUnknown_0203CEBC;
extern EWRAM_DATA void *gUnknown_0203CEC0;
extern void *gItemIconDecompressionBuffer;
extern void *gItemIcon4x4Buffer;
extern const struct SpriteTemplate gUnknown_08614FF4;
extern const struct SpriteTemplate gItemIconSpriteTemplate;
bool8 AllocItemIconTemporaryBuffers(void);
void CopyItemIconPicTo4x4Buffer(void *src, void *dest);
void FreeItemIconTemporaryBuffers(void);
void CopyItemIconPicTo4x4Buffer(const void *src, void *dest);
u8 AddItemIconSprite(u16 tilesTag, u16 paletteTag, u16 itemId);
u8 AddCustomItemIconSprite(struct SpriteTemplate *customSpriteTemplate, u16 tilesTag, u16 paletteTag, u16 itemId);
const void *GetItemIconPicOrPalette(u16 itemId, u8 which);
#endif //GUARD_ITEM_ICON_H

View File

@ -255,7 +255,7 @@ SECTIONS {
asm/menu_indicators.o(.text);
src/unk_text_util.o(.text);
src/save_location.o(.text);
asm/item_icon.o(.text);
src/item_icon.o(.text);
asm/party_menu.o(.text);
asm/battle_tent.o(.text);
src/unk_text_util_2.o(.text);
@ -526,6 +526,7 @@ SECTIONS {
data/menu_indicators.o(.rodata);
src/save_location.o(.rodata);
data/item_icon.o(.rodata);
src/item_icon.o(.rodata);
data/party_menu.o(.rodata);
data/battle_tent.o(.rodata);
src/unk_text_util_2.o(.rodata);

View File

@ -2013,9 +2013,9 @@ u8 AddDecorationIconObjectFromIconTable(u16 tilesTag, u16 paletteTag, u8 decor)
{
return MAX_SPRITES;
}
LZDecompressWram(GetDecorationIconPicOrPalette(decor, 0), gUnknown_0203CEBC);
CopyItemIconPicTo4x4Buffer(gUnknown_0203CEBC, gUnknown_0203CEC0);
sheet.data = gUnknown_0203CEC0;
LZDecompressWram(GetDecorationIconPicOrPalette(decor, 0), gItemIconDecompressionBuffer);
CopyItemIconPicTo4x4Buffer(gItemIconDecompressionBuffer, gItemIcon4x4Buffer);
sheet.data = gItemIcon4x4Buffer;
sheet.size = 0x200;
sheet.tag = tilesTag;
LoadSpriteSheet(&sheet);
@ -2023,7 +2023,7 @@ u8 AddDecorationIconObjectFromIconTable(u16 tilesTag, u16 paletteTag, u8 decor)
palette.tag = paletteTag;
LoadCompressedObjectPalette(&palette);
template = malloc(sizeof(struct SpriteTemplate));
*template = gUnknown_08614FF4;
*template = gItemIconSpriteTemplate;
template->tileTag = tilesTag;
template->paletteTag = paletteTag;
spriteId = CreateSprite(template, 0, 0, 0);

169
src/item_icon.c Normal file
View File

@ -0,0 +1,169 @@
#include "global.h"
#include "item_icon.h"
#include "malloc.h"
#include "sprite.h"
#include "decompress.h"
#include "constants/items.h"
// EWRAM vars
EWRAM_DATA void *gItemIconDecompressionBuffer = NULL;
EWRAM_DATA void *gItemIcon4x4Buffer = NULL;
// const rom data
extern const void *const gItemIconTable[][2]; // todo: move to C file
static const struct OamData sOamData_ItemIcon =
{
.y = 0,
.affineMode = 0,
.objMode = 0,
.mosaic = 0,
.bpp = 0,
.shape = 0,
.x = 0,
.matrixNum = 0,
.size = 2,
.tileNum = 0,
.priority = 1,
.paletteNum = 2,
.affineParam = 0
};
static const union AnimCmd sSpriteAnim_ItemIcon[] =
{
ANIMCMD_FRAME(0, 0),
ANIMCMD_END
};
static const union AnimCmd *const sSpriteAnimTable_ItemIcon[] =
{
sSpriteAnim_ItemIcon
};
const struct SpriteTemplate gItemIconSpriteTemplate =
{
.tileTag = 0,
.paletteTag = 0,
.oam = &sOamData_ItemIcon,
.anims = sSpriteAnimTable_ItemIcon,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCallbackDummy,
};
// code
bool8 AllocItemIconTemporaryBuffers(void)
{
gItemIconDecompressionBuffer = gItemIconDecompressionBuffer; // needed to match
gItemIconDecompressionBuffer = Alloc(0x120);
if (gItemIconDecompressionBuffer == NULL)
return FALSE;
gItemIcon4x4Buffer = gItemIcon4x4Buffer; // needed to match
gItemIcon4x4Buffer = AllocZeroed(0x200);
if (gItemIcon4x4Buffer == NULL)
{
Free(gItemIconDecompressionBuffer);
return FALSE;
}
return TRUE;
}
void FreeItemIconTemporaryBuffers(void)
{
Free(gItemIconDecompressionBuffer);
Free(gItemIcon4x4Buffer);
}
void CopyItemIconPicTo4x4Buffer(const void *src, void *dest)
{
u8 i;
for (i = 0; i < 3; i++)
CpuCopy16(src + i * 96, dest + i * 128, 0x60);
}
u8 AddItemIconSprite(u16 tilesTag, u16 paletteTag, u16 itemId)
{
if (!AllocItemIconTemporaryBuffers())
{
return MAX_SPRITES;
}
else
{
u8 spriteId;
struct SpriteSheet spriteSheet;
struct CompressedSpritePalette spritePalette;
struct SpriteTemplate *spriteTemplate;
LZDecompressWram(GetItemIconPicOrPalette(itemId, 0), gItemIconDecompressionBuffer);
CopyItemIconPicTo4x4Buffer(gItemIconDecompressionBuffer, gItemIcon4x4Buffer);
spriteSheet.data = gItemIcon4x4Buffer;
spriteSheet.size = 0x200;
spriteSheet.tag = tilesTag;
LoadSpriteSheet(&spriteSheet);
spritePalette.data = GetItemIconPicOrPalette(itemId, 1);
spritePalette.tag = paletteTag;
LoadCompressedObjectPalette(&spritePalette);
spriteTemplate = Alloc(sizeof(*spriteTemplate));
CpuCopy16(&gItemIconSpriteTemplate, spriteTemplate, sizeof(*spriteTemplate));
spriteTemplate->tileTag = tilesTag;
spriteTemplate->paletteTag = paletteTag;
spriteId = CreateSprite(spriteTemplate, 0, 0, 0);
FreeItemIconTemporaryBuffers();
Free(spriteTemplate);
return spriteId;
}
}
u8 AddCustomItemIconSprite(struct SpriteTemplate *customSpriteTemplate, u16 tilesTag, u16 paletteTag, u16 itemId)
{
if (!AllocItemIconTemporaryBuffers())
{
return MAX_SPRITES;
}
else
{
u8 spriteId;
struct SpriteSheet spriteSheet;
struct CompressedSpritePalette spritePalette;
struct SpriteTemplate *spriteTemplate;
LZDecompressWram(GetItemIconPicOrPalette(itemId, 0), gItemIconDecompressionBuffer);
CopyItemIconPicTo4x4Buffer(gItemIconDecompressionBuffer, gItemIcon4x4Buffer);
spriteSheet.data = gItemIcon4x4Buffer;
spriteSheet.size = 0x200;
spriteSheet.tag = tilesTag;
LoadSpriteSheet(&spriteSheet);
spritePalette.data = GetItemIconPicOrPalette(itemId, 1);
spritePalette.tag = paletteTag;
LoadCompressedObjectPalette(&spritePalette);
spriteTemplate = Alloc(sizeof(*spriteTemplate));
CpuCopy16(customSpriteTemplate, spriteTemplate, sizeof(*spriteTemplate));
spriteTemplate->tileTag = tilesTag;
spriteTemplate->paletteTag = paletteTag;
spriteId = CreateSprite(spriteTemplate, 0, 0, 0);
FreeItemIconTemporaryBuffers();
Free(spriteTemplate);
return spriteId;
}
}
const void *GetItemIconPicOrPalette(u16 itemId, u8 which)
{
if (itemId == 0xFFFF)
itemId = ITEM_FIELD_ARROW;
else if (itemId > ITEM_LAST_ID)
itemId = 0;
return gItemIconTable[itemId][which];
}

View File

@ -1409,12 +1409,7 @@ gUnknown_0203CE8C: @ 203CE8C
.space 0x10
.include "src/unk_text_util.o"
gUnknown_0203CEBC: @ 203CEBC
.space 0x4
gUnknown_0203CEC0: @ 203CEC0
.space 0x4
.include "src/item_icon.o"
gUnknown_0203CEC4: @ 203CEC4
.space 0x4