decompile berry tag screen

This commit is contained in:
DizzyEggg 2018-02-02 14:03:48 +01:00
parent 14d2caaf8d
commit ebc8af50f1
9 changed files with 295 additions and 776 deletions

View File

@ -1,727 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start sub_817836C
sub_817836C: @ 817836C
push {lr}
ldr r0, =sBerryTag
ldr r0, [r0]
ldr r1, =0x00001802
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
ldr r1, =gSprites
adds r0, r1
bl DestroySprite
bl sub_80D510C
pop {r0}
bx r0
.pool
thumb_func_end sub_817836C
thumb_func_start sub_817839C
sub_817839C: @ 817839C
push {r4,lr}
movs r0, 0x40
bl sub_80D518C
ldr r4, =sBerryTag
ldr r1, [r4]
ldr r2, =0x00001803
adds r1, r2
strb r0, [r1]
movs r0, 0x68
bl sub_80D518C
ldr r1, [r4]
ldr r2, =0x00001804
adds r1, r2
strb r0, [r1]
movs r0, 0x90
bl sub_80D518C
ldr r1, [r4]
ldr r2, =0x00001805
adds r1, r2
strb r0, [r1]
movs r0, 0xB8
bl sub_80D518C
ldr r1, [r4]
ldr r2, =0x00001806
adds r1, r2
strb r0, [r1]
movs r0, 0xE0
bl sub_80D518C
ldr r1, [r4]
ldr r2, =0x00001807
adds r1, r2
strb r0, [r1]
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end sub_817839C
thumb_func_start sub_8178404
sub_8178404: @ 8178404
push {r4,r5,lr}
ldr r4, =sBerryTag
ldr r0, [r4]
movs r1, 0xC0
lsls r1, 5
adds r0, r1
ldrb r0, [r0]
bl GetBerryInfo
adds r5, r0, 0
ldrb r0, [r5, 0x15]
cmp r0, 0
beq _08178448
ldr r3, =gSprites
ldr r0, [r4]
ldr r1, =0x00001803
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r3
adds r0, 0x3E
ldrb r2, [r0]
movs r1, 0x5
negs r1, r1
ands r1, r2
b _08178462
.pool
_08178448:
ldr r3, =gSprites
ldr r0, [r4]
ldr r1, =0x00001803
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r3
adds r0, 0x3E
ldrb r1, [r0]
movs r2, 0x4
orrs r1, r2
_08178462:
strb r1, [r0]
adds r4, r3, 0
ldrb r0, [r5, 0x16]
cmp r0, 0
beq _0817849C
ldr r3, =sBerryTag
ldr r0, [r3]
ldr r1, =0x00001804
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r4
adds r0, 0x3E
ldrb r2, [r0]
movs r1, 0x5
negs r1, r1
ands r1, r2
b _081784B6
.pool
_0817849C:
ldr r3, =sBerryTag
ldr r0, [r3]
ldr r1, =0x00001804
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r4
adds r0, 0x3E
ldrb r1, [r0]
movs r2, 0x4
orrs r1, r2
_081784B6:
strb r1, [r0]
ldrb r0, [r5, 0x17]
cmp r0, 0
beq _081784E8
ldr r0, [r3]
ldr r1, =0x00001805
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r4
adds r0, 0x3E
ldrb r2, [r0]
movs r1, 0x5
negs r1, r1
ands r1, r2
b _08178500
.pool
_081784E8:
ldr r0, [r3]
ldr r1, =0x00001805
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r4
adds r0, 0x3E
ldrb r1, [r0]
movs r2, 0x4
orrs r1, r2
_08178500:
strb r1, [r0]
ldrb r0, [r5, 0x18]
cmp r0, 0
beq _0817852C
ldr r0, [r3]
ldr r1, =0x00001806
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r4
adds r0, 0x3E
ldrb r2, [r0]
movs r1, 0x5
negs r1, r1
ands r1, r2
b _08178544
.pool
_0817852C:
ldr r0, [r3]
ldr r1, =0x00001806
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r4
adds r0, 0x3E
ldrb r1, [r0]
movs r2, 0x4
orrs r1, r2
_08178544:
strb r1, [r0]
ldrb r0, [r5, 0x19]
cmp r0, 0
beq _08178570
ldr r0, [r3]
ldr r1, =0x00001807
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r4
adds r0, 0x3E
ldrb r2, [r0]
movs r1, 0x5
negs r1, r1
ands r1, r2
b _08178588
.pool
_08178570:
ldr r0, [r3]
ldr r1, =0x00001807
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r4
adds r0, 0x3E
ldrb r1, [r0]
movs r2, 0x4
orrs r1, r2
_08178588:
strb r1, [r0]
pop {r4,r5}
pop {r0}
bx r0
.pool
thumb_func_end sub_8178404
thumb_func_start sub_8178594
sub_8178594: @ 8178594
push {r4,lr}
movs r4, 0
_08178598:
ldr r0, =sBerryTag
ldr r0, [r0]
ldr r1, =0x00001803
adds r0, r1
adds r0, r4
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
ldr r1, =gSprites
adds r0, r1
bl DestroySprite
adds r0, r4, 0x1
lsls r0, 16
lsrs r4, r0, 16
cmp r4, 0x4
bls _08178598
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end sub_8178594
thumb_func_start sub_81785D0
sub_81785D0: @ 81785D0
push {r4,lr}
sub sp, 0x4
adds r4, r0, 0
lsls r4, 24
lsrs r4, 24
movs r0, 0x5
bl PlaySE
movs r0, 0x1
negs r0, r0
movs r1, 0
str r1, [sp]
movs r2, 0
movs r3, 0x10
bl BeginNormalPaletteFade
ldr r1, =gTasks
lsls r0, r4, 2
adds r0, r4
lsls r0, 3
adds r0, r1
ldr r1, =sub_8178610
str r1, [r0]
add sp, 0x4
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end sub_81785D0
thumb_func_start sub_8178610
sub_8178610: @ 8178610
push {r4,lr}
lsls r0, 24
lsrs r4, r0, 24
ldr r0, =gPaletteFade
ldrb r1, [r0, 0x7]
movs r0, 0x80
ands r0, r1
cmp r0, 0
bne _08178642
bl sub_817836C
bl sub_8178594
ldr r0, =sBerryTag
ldr r0, [r0]
bl Free
bl FreeAllWindowBuffers
ldr r0, =bag_menu_mail_related
bl SetMainCallback2
adds r0, r4, 0
bl DestroyTask
_08178642:
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end sub_8178610
thumb_func_start sub_8178654
sub_8178654: @ 8178654
push {r4,lr}
lsls r0, 24
lsrs r2, r0, 24
adds r4, r2, 0
ldr r0, =gPaletteFade
ldrb r1, [r0, 0x7]
movs r0, 0x80
ands r0, r1
cmp r0, 0
bne _081786A6
ldr r3, =gMain
ldrh r0, [r3, 0x30]
movs r1, 0xF0
ands r1, r0
cmp r1, 0x40
bne _08178688
movs r1, 0x1
negs r1, r1
adds r0, r2, 0
bl sub_81786AC
b _081786A6
.pool
_08178688:
cmp r1, 0x80
bne _08178696
adds r0, r2, 0
movs r1, 0x1
bl sub_81786AC
b _081786A6
_08178696:
ldrh r1, [r3, 0x2E]
movs r0, 0x3
ands r0, r1
cmp r0, 0
beq _081786A6
adds r0, r4, 0
bl sub_81785D0
_081786A6:
pop {r4}
pop {r0}
bx r0
thumb_func_end sub_8178654
thumb_func_start sub_81786AC
sub_81786AC: @ 81786AC
push {r4-r7,lr}
lsls r0, 24
lsrs r5, r0, 24
lsls r1, 24
lsls r0, r5, 2
adds r0, r5
lsls r0, 3
ldr r2, =gTasks + 0x8
adds r4, r0, r2
ldr r2, =gUnknown_0203CE58
ldrh r0, [r2, 0xE]
ldrh r2, [r2, 0x18]
adds r0, r2
lsls r0, 16
asrs r0, 16
lsrs r7, r1, 24
asrs r6, r1, 24
adds r0, r6
cmp r0, 0x2D
bhi _08178718
lsls r1, r0, 16
lsrs r1, 16
movs r0, 0x4
bl BagGetItemIdByPocketPosition
lsls r0, 16
cmp r0, 0
beq _08178718
cmp r6, 0
bge _081786F4
movs r0, 0x2
b _081786F6
.pool
_081786F4:
movs r0, 0x1
_081786F6:
strh r0, [r4, 0x2]
movs r0, 0
strh r0, [r4]
movs r0, 0x5
bl PlaySE
lsls r0, r7, 24
asrs r0, 24
bl sub_8178728
ldr r1, =gTasks
lsls r0, r5, 2
adds r0, r5
lsls r0, 3
adds r0, r1
ldr r1, =sub_81787AC
str r1, [r0]
_08178718:
pop {r4-r7}
pop {r0}
bx r0
.pool
thumb_func_end sub_81786AC
thumb_func_start sub_8178728
sub_8178728: @ 8178728
push {r4-r6,lr}
ldr r5, =gUnknown_0203CE70
adds r6, r5, 0
subs r6, 0xA
lsls r0, 24
asrs r4, r0, 24
cmp r4, 0
ble _08178764
ldrh r0, [r6]
cmp r0, 0x3
bls _08178752
ldrh r1, [r5]
adds r1, 0x8
lsls r1, 16
lsrs r1, 16
movs r0, 0x4
bl BagGetItemIdByPocketPosition
lsls r0, 16
cmp r0, 0
bne _08178760
_08178752:
ldrh r0, [r6]
adds r0, r4
strh r0, [r6]
b _0817877A
.pool
_08178760:
ldrh r0, [r5]
b _08178776
_08178764:
ldrh r1, [r6]
cmp r1, 0x3
bhi _08178770
ldrh r0, [r5]
cmp r0, 0
bne _08178776
_08178770:
adds r0, r1, r4
strh r0, [r6]
b _0817877A
_08178776:
adds r0, r4
strh r0, [r5]
_0817877A:
ldrh r1, [r6]
ldrh r5, [r5]
adds r1, r5
lsls r1, 16
lsrs r1, 16
movs r0, 0x4
bl BagGetItemIdByPocketPosition
lsls r0, 16
lsrs r0, 16
bl ItemIdToBerryType
ldr r1, =sBerryTag
ldr r1, [r1]
lsls r0, 24
lsrs r0, 24
movs r2, 0xC0
lsls r2, 5
adds r1, r2
strh r0, [r1]
pop {r4-r6}
pop {r0}
bx r0
.pool
thumb_func_end sub_8178728
thumb_func_start sub_81787AC
sub_81787AC: @ 81787AC
push {r4-r7,lr}
mov r7, r8
push {r7}
lsls r0, 24
lsrs r0, 24
mov r8, r0
lsls r0, 2
add r0, r8
lsls r0, 3
ldr r1, =gTasks + 0x8
adds r6, r0, r1
ldrh r0, [r6]
adds r0, 0x10
movs r1, 0xFF
ands r0, r1
strh r0, [r6]
movs r1, 0x2
ldrsh r0, [r6, r1]
cmp r0, 0x1
bne _08178828
movs r2, 0
ldrsh r0, [r6, r2]
cmp r0, 0x70
beq _08178888
cmp r0, 0x70
bgt _081787FE
cmp r0, 0x40
beq _0817881A
cmp r0, 0x40
bgt _081787F4
cmp r0, 0x30
beq _08178898
b _081788A6
.pool
_081787F4:
cmp r0, 0x50
beq _0817888E
cmp r0, 0x60
beq _08178820
b _081788A6
_081787FE:
cmp r0, 0xA0
beq _08178824
cmp r0, 0xA0
bgt _08178810
cmp r0, 0x80
beq _08178882
cmp r0, 0x90
beq _08178878
b _081788A6
_08178810:
cmp r0, 0xB0
beq _08178872
cmp r0, 0xC0
beq _0817886C
b _081788A6
_0817881A:
bl sub_8178110
b _081788A6
_08178820:
movs r0, 0x1
b _0817889A
_08178824:
movs r0, 0x2
b _0817889A
_08178828:
movs r1, 0
ldrsh r0, [r6, r1]
cmp r0, 0x70
beq _0817887E
cmp r0, 0x70
bgt _0817884C
cmp r0, 0x40
beq _0817886C
cmp r0, 0x40
bgt _08178842
cmp r0, 0x30
beq _08178868
b _081788A6
_08178842:
cmp r0, 0x50
beq _08178872
cmp r0, 0x60
beq _08178878
b _081788A6
_0817884C:
cmp r0, 0xA0
beq _0817888E
cmp r0, 0xA0
bgt _0817885E
cmp r0, 0x80
beq _08178882
cmp r0, 0x90
beq _08178888
b _081788A6
_0817885E:
cmp r0, 0xB0
beq _08178898
cmp r0, 0xC0
beq _081788A2
b _081788A6
_08178868:
movs r0, 0x2
b _0817889A
_0817886C:
bl sub_8178304
b _081788A6
_08178872:
bl sub_81782D0
b _081788A6
_08178878:
bl sub_8178404
b _081788A6
_0817887E:
movs r0, 0x1
b _0817889A
_08178882:
bl sub_8178250
b _081788A6
_08178888:
bl sub_8178174
b _081788A6
_0817888E:
bl sub_817836C
bl sub_8178338
b _081788A6
_08178898:
movs r0, 0
_0817889A:
movs r1, 0
bl FillWindowPixelBuffer
b _081788A6
_081788A2:
bl sub_8178110
_081788A6:
movs r2, 0x2
ldrsh r0, [r6, r2]
cmp r0, 0x1
bne _081788B8
ldrh r0, [r6]
negs r0, r0
lsls r0, 16
lsrs r5, r0, 16
b _081788BA
_081788B8:
ldrh r5, [r6]
_081788BA:
ldr r2, =gSprites
ldr r3, =sBerryTag
ldr r0, [r3]
ldr r1, =0x00001802
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r2
strh r5, [r0, 0x26]
movs r4, 0
adds r7, r2, 0
ldr r2, =0x00001803
_081788D6:
ldr r0, [r3]
adds r0, r2
adds r0, r4
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r0, r7
strh r5, [r0, 0x26]
adds r0, r4, 0x1
lsls r0, 16
lsrs r4, r0, 16
cmp r4, 0x4
bls _081788D6
movs r4, 0x80
lsls r4, 5
ldrb r2, [r6, 0x2]
movs r0, 0x1
adds r1, r4, 0
bl ChangeBgY
ldrb r2, [r6, 0x2]
movs r0, 0x2
adds r1, r4, 0
bl ChangeBgY
movs r2, 0
ldrsh r0, [r6, r2]
cmp r0, 0
bne _08178922
ldr r0, =gTasks
mov r2, r8
lsls r1, r2, 2
add r1, r8
lsls r1, 3
adds r1, r0
ldr r0, =sub_8178654
str r0, [r1]
_08178922:
pop {r3}
mov r8, r3
pop {r4-r7}
pop {r0}
bx r0
.pool
thumb_func_end sub_81787AC
.align 2, 0 @ Don't pad with nop.

View File

@ -4524,7 +4524,7 @@ ItemMenu_CheckTag: @ 81AD378
lsrs r0, 24 lsrs r0, 24
ldr r1, =gUnknown_0203CE54 ldr r1, =gUnknown_0203CE54
ldr r2, [r1] ldr r2, [r1]
ldr r1, =sub_8177C14 ldr r1, =DoBerryTagScreen
str r1, [r2] str r1, [r2]
bl unknown_ItemMenu_Confirm bl unknown_ItemMenu_Confirm
pop {r0} pop {r0}

View File

@ -556,15 +556,15 @@ CreateBerryTagSprite: @ 80D50D4
.pool .pool
thumb_func_end CreateBerryTagSprite thumb_func_end CreateBerryTagSprite
thumb_func_start sub_80D510C thumb_func_start FreeBerryTagSpritePalette
sub_80D510C: @ 80D510C FreeBerryTagSpritePalette: @ 80D510C
push {lr} push {lr}
ldr r0, =0x00007544 ldr r0, =0x00007544
bl FreeSpritePaletteByTag bl FreeSpritePaletteByTag
pop {r0} pop {r0}
bx r0 bx r0
.pool .pool
thumb_func_end sub_80D510C thumb_func_end FreeBerryTagSpritePalette
thumb_func_start sub_80D511C thumb_func_start sub_80D511C
sub_80D511C: @ 80D511C sub_80D511C: @ 80D511C
@ -617,8 +617,8 @@ _080D5172:
.pool .pool
thumb_func_end sub_80D511C thumb_func_end sub_80D511C
thumb_func_start sub_80D518C thumb_func_start CreateBerryFlavorCircleSprite
sub_80D518C: @ 80D518C CreateBerryFlavorCircleSprite: @ 80D518C
push {lr} push {lr}
adds r1, r0, 0 adds r1, r0, 0
ldr r0, =gUnknown_0857FE10 ldr r0, =gUnknown_0857FE10
@ -632,6 +632,6 @@ sub_80D518C: @ 80D518C
pop {r1} pop {r1}
bx r1 bx r1
.pool .pool
thumb_func_end sub_80D518C thumb_func_end CreateBerryFlavorCircleSprite
.align 2, 0 @ Don't pad with nop. .align 2, 0 @ Don't pad with nop.

View File

@ -1,6 +1,6 @@
#ifndef GUARD_BERRY_TAG_SCREEN_H #ifndef GUARD_BERRY_TAG_SCREEN_H
#define GUARD_BERRY_TAG_SCREEN_H #define GUARD_BERRY_TAG_SCREEN_H
void BerryTagScreen_814625C(u8 taskId);
#endif // GUARD_BERRY_TAG_SCREEN_H #endif // GUARD_BERRY_TAG_SCREEN_H

View File

@ -60,5 +60,6 @@ u8 ItemId_GetBattleUsage(u16 itemId);
ItemUseFunc ItemId_GetBattleFunc(u16 itemId); ItemUseFunc ItemId_GetBattleFunc(u16 itemId);
u8 ItemId_GetSecondaryId(u16 itemId); u8 ItemId_GetSecondaryId(u16 itemId);
u16 itemid_get_market_price(u16 itemId); u16 itemid_get_market_price(u16 itemId);
u16 BagGetItemIdByPocketPosition(u8 pocketId, u16 pocketPos);
#endif // ITEM_H #endif // ITEM_H

View File

@ -2,11 +2,24 @@
#define GUARD_item_menu_H #define GUARD_item_menu_H
// Exported type declarations // Exported type declarations
struct BagStruct
{
void *func;
u8 unk4;
u8 pocket;
u8 unk6[2];
u16 unk8[5];
u16 unk12[5];
void *unk1C;
};
extern struct BagStruct gUnknown_0203CE58;
// Exported RAM declarations // Exported RAM declarations
// Exported ROM declarations // Exported ROM declarations
void sub_81AAC50(void); void sub_81AAC50(void);
void sub_81AAC70(void); void sub_81AAC70(void);
void bag_menu_mail_related(void);
#endif //GUARD_item_menu_H #endif //GUARD_item_menu_H

View File

@ -6,5 +6,7 @@ extern const struct CompressedSpritePalette gUnknown_0857FDF4;
u8 sub_80D511C(u8 a0, u8 a1, u8 a2, u8 a3); u8 sub_80D511C(u8 a0, u8 a1, u8 a2, u8 a3);
u8 CreateBerryTagSprite(u8 id, s16 x, s16 y); u8 CreateBerryTagSprite(u8 id, s16 x, s16 y);
void FreeBerryTagSpritePalette(void);
u8 CreateBerryFlavorCircleSprite(s16 x);
#endif // GUARD_ITEM_MENU_ICONS #endif // GUARD_ITEM_MENU_ICONS

View File

@ -230,7 +230,6 @@ SECTIONS {
src/lottery_corner.o(.text); src/lottery_corner.o(.text);
src/diploma.o(.text); src/diploma.o(.text);
src/berry_tag_screen.o(.text); src/berry_tag_screen.o(.text);
asm/berry_tag_screen.o(.text);
src/mystery_event_menu.o(.text); src/mystery_event_menu.o(.text);
src/save_failed_screen.o(.text); src/save_failed_screen.o(.text);
src/braille_puzzles.o(.text); src/braille_puzzles.o(.text);

View File

@ -5,6 +5,7 @@
#include "field_map_obj.h" #include "field_map_obj.h"
#include "item_menu.h" #include "item_menu.h"
#include "constants/items.h" #include "constants/items.h"
#include "item.h"
#include "item_use.h" #include "item_use.h"
#include "main.h" #include "main.h"
#include "menu.h" #include "menu.h"
@ -29,7 +30,7 @@
#include "international_string_util.h" #include "international_string_util.h"
// const rom data // const rom data
const struct BgTemplate gUnknown_085EFCF0[] = static const struct BgTemplate gUnknown_085EFCF0[] =
{ {
{ {
.bg = 0, .bg = 0,
@ -69,15 +70,15 @@ const struct BgTemplate gUnknown_085EFCF0[] =
} }
}; };
const u16 gUnknown_085EFD00[] = INCBIN_U16("graphics/interface/berry_tag_screen.gbapal"); static const u16 gUnknown_085EFD00[] = INCBIN_U16("graphics/interface/berry_tag_screen.gbapal");
const struct TextColor gUnknown_085EFD20[] = static const struct TextColor gUnknown_085EFD20[] =
{ {
{0, 2, 3}, {0, 2, 3},
{15, 14, 13} {15, 14, 13}
}; };
const struct WindowTemplate gUnknown_085EFD28[] = static const struct WindowTemplate gUnknown_085EFD28[] =
{ {
{0x01, 0x0b, 0x04, 0x08, 0x02, 0x0f, 0x0045}, {0x01, 0x0b, 0x04, 0x08, 0x02, 0x0f, 0x0045},
{0x01, 0x0b, 0x07, 0x12, 0x04, 0x0f, 0x0055}, {0x01, 0x0b, 0x07, 0x12, 0x04, 0x0f, 0x0055},
@ -86,7 +87,7 @@ const struct WindowTemplate gUnknown_085EFD28[] =
DUMMY_WIN_TEMPLATE DUMMY_WIN_TEMPLATE
}; };
const u8 *const gBerryFirmnessStringPointers[] = static const u8 *const gBerryFirmnessStringPointers[] =
{ {
gBerryFirmnessString_VerySoft, gBerryFirmnessString_VerySoft,
gBerryFirmnessString_Soft, gBerryFirmnessString_Soft,
@ -96,22 +97,26 @@ const u8 *const gBerryFirmnessStringPointers[] =
}; };
// this file's functions // this file's functions
void sub_8177C84(void); static void sub_8177C84(void);
void sub_8177E14(void); static void sub_8177E14(void);
void sub_8178008(void); static void sub_8178008(void);
void sub_8178090(void); static void sub_8178090(void);
void sub_81780F4(void); static void sub_81780F4(void);
void sub_8178338(void); static void sub_8178338(void);
void sub_817839C(void); static void sub_817839C(void);
void sub_8178404(void); static void sub_8178404(void);
void sub_8178110(void); static void sub_8178110(void);
void sub_8178174(void); static void sub_8178174(void);
void sub_8178250(void); static void sub_8178250(void);
void sub_81782D0(void); static void sub_81782D0(void);
void sub_8178304(void); static void sub_8178304(void);
bool8 sub_8177CB0(void); static bool8 sub_8177CB0(void);
bool8 sub_8177E88(void); static bool8 sub_8177E88(void);
void sub_8178654(u8 taskId); static void sub_8178654(u8 taskId);
static void sub_8178610(u8 taskId);
static void sub_81787AC(u8 taskId);
static void sub_81786AC(u8 taskId, s8 toMove);
static void sub_8178728(s8 toMove);
// code // code
struct BerryTagScreenStruct struct BerryTagScreenStruct
@ -119,21 +124,20 @@ struct BerryTagScreenStruct
u16 tilemapBuffers[3][0x400]; u16 tilemapBuffers[3][0x400];
u16 berryId; u16 berryId;
u8 berrySpriteId; u8 berrySpriteId;
u16 field_1804; u8 flavorCircleIds[FLAVOR_COUNT];
u16 field_1806;
u16 field_1808; u16 field_1808;
}; };
extern struct BerryTagScreenStruct *sBerryTag; extern struct BerryTagScreenStruct *sBerryTag;
void sub_8177C14(void) void DoBerryTagScreen(void)
{ {
sBerryTag = AllocZeroed(0x180C); sBerryTag = AllocZeroed(0x180C);
sBerryTag->berryId = ItemIdToBerryType(gSpecialVar_ItemId); sBerryTag->berryId = ItemIdToBerryType(gSpecialVar_ItemId);
SetMainCallback2(sub_8177C84); SetMainCallback2(sub_8177C84);
} }
void sub_8177C54(void) static void sub_8177C54(void)
{ {
RunTasks(); RunTasks();
AnimateSprites(); AnimateSprites();
@ -142,14 +146,14 @@ void sub_8177C54(void)
UpdatePaletteFade(); UpdatePaletteFade();
} }
void sub_8177C70(void) static void sub_8177C70(void)
{ {
LoadOam(); LoadOam();
ProcessSpriteCopyRequests(); ProcessSpriteCopyRequests();
TransferPlttBuffer(); TransferPlttBuffer();
} }
void sub_8177C84(void) static void sub_8177C84(void)
{ {
while (1) while (1)
{ {
@ -162,7 +166,7 @@ void sub_8177C84(void)
} }
} }
bool8 sub_8177CB0(void) static bool8 sub_8177CB0(void)
{ {
switch (gMain.state) switch (gMain.state)
{ {
@ -246,7 +250,7 @@ bool8 sub_8177CB0(void)
return FALSE; return FALSE;
} }
void sub_8177E14(void) static void sub_8177E14(void)
{ {
ResetBgsAndClearDma3BusyFlags(0); ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, gUnknown_085EFCF0, ARRAY_COUNT(gUnknown_085EFCF0)); InitBgsFromTemplates(0, gUnknown_085EFCF0, ARRAY_COUNT(gUnknown_085EFCF0));
@ -263,7 +267,7 @@ void sub_8177E14(void)
ShowBg(3); ShowBg(3);
} }
bool8 sub_8177E88(void) static bool8 sub_8177E88(void)
{ {
u16 i; u16 i;
@ -314,7 +318,7 @@ bool8 sub_8177E88(void)
return FALSE; return FALSE;
} }
void sub_8178008(void) static void sub_8178008(void)
{ {
u16 i; u16 i;
@ -327,12 +331,12 @@ void sub_8178008(void)
schedule_bg_copy_tilemap_to_vram(1); schedule_bg_copy_tilemap_to_vram(1);
} }
void sub_817804C(u8 windowId, const u8 *text, u8 x, u8 y, s32 speed, u8 colorStructId) static void sub_817804C(u8 windowId, const u8 *text, u8 x, u8 y, s32 speed, u8 colorStructId)
{ {
AddTextPrinterParameterized2(windowId, 1, x, y, 0, 0, &gUnknown_085EFD20[colorStructId], speed, text); AddTextPrinterParameterized2(windowId, 1, x, y, 0, 0, &gUnknown_085EFD20[colorStructId], speed, text);
} }
void sub_8178090(void) static void sub_8178090(void)
{ {
memcpy(GetBgTilemapBuffer(0), sBerryTag->tilemapBuffers[2], sizeof(sBerryTag->tilemapBuffers[2])); memcpy(GetBgTilemapBuffer(0), sBerryTag->tilemapBuffers[2], sizeof(sBerryTag->tilemapBuffers[2]));
FillWindowPixelBuffer(3, 0xFF); FillWindowPixelBuffer(3, 0xFF);
@ -341,7 +345,7 @@ void sub_8178090(void)
schedule_bg_copy_tilemap_to_vram(0); schedule_bg_copy_tilemap_to_vram(0);
} }
void sub_81780F4(void) static void sub_81780F4(void)
{ {
sub_8178110(); sub_8178110();
sub_8178174(); sub_8178174();
@ -350,7 +354,7 @@ void sub_81780F4(void)
sub_8178304(); sub_8178304();
} }
void sub_8178110(void) static void sub_8178110(void)
{ {
const struct Berry *berry = GetBerryInfo(sBerryTag->berryId); const struct Berry *berry = GetBerryInfo(sBerryTag->berryId);
ConvertIntToDecimalStringN(gStringVar1, sBerryTag->berryId, 2, 2); ConvertIntToDecimalStringN(gStringVar1, sBerryTag->berryId, 2, 2);
@ -359,7 +363,7 @@ void sub_8178110(void)
sub_817804C(0, gStringVar4, 0, 1, 0, 0); sub_817804C(0, gStringVar4, 0, 1, 0, 0);
} }
void sub_8178174(void) static void sub_8178174(void)
{ {
const struct Berry *berry = GetBerryInfo(sBerryTag->berryId); const struct Berry *berry = GetBerryInfo(sBerryTag->berryId);
PrintTextOnWindow(1, 1, gText_SizeSlash, 0, 1, TEXT_SPEED_FF, NULL); PrintTextOnWindow(1, 1, gText_SizeSlash, 0, 1, TEXT_SPEED_FF, NULL);
@ -384,7 +388,7 @@ void sub_8178174(void)
} }
} }
void sub_8178250(void) static void sub_8178250(void)
{ {
const struct Berry *berry = GetBerryInfo(sBerryTag->berryId); const struct Berry *berry = GetBerryInfo(sBerryTag->berryId);
PrintTextOnWindow(1, 1, gText_FirmSlash, 0, 0x11, TEXT_SPEED_FF, NULL); PrintTextOnWindow(1, 1, gText_FirmSlash, 0, 0x11, TEXT_SPEED_FF, NULL);
@ -394,19 +398,246 @@ void sub_8178250(void)
PrintTextOnWindow(1, 1, gText_ThreeMarks, 0x28, 0x11, 0, NULL); PrintTextOnWindow(1, 1, gText_ThreeMarks, 0x28, 0x11, 0, NULL);
} }
void sub_81782D0(void) static void sub_81782D0(void)
{ {
const struct Berry *berry = GetBerryInfo(sBerryTag->berryId); const struct Berry *berry = GetBerryInfo(sBerryTag->berryId);
PrintTextOnWindow(2, 1, berry->description1, 0, 1, 0, NULL); PrintTextOnWindow(2, 1, berry->description1, 0, 1, 0, NULL);
} }
void sub_8178304(void) static void sub_8178304(void)
{ {
const struct Berry *berry = GetBerryInfo(sBerryTag->berryId); const struct Berry *berry = GetBerryInfo(sBerryTag->berryId);
PrintTextOnWindow(2, 1, berry->description2, 0, 0x11, 0, NULL); PrintTextOnWindow(2, 1, berry->description2, 0, 0x11, 0, NULL);
} }
void sub_8178338(void) static void sub_8178338(void)
{ {
sBerryTag->berrySpriteId = CreateBerryTagSprite(sBerryTag->berryId - 1, 56, 64); sBerryTag->berrySpriteId = CreateBerryTagSprite(sBerryTag->berryId - 1, 56, 64);
} }
static void sub_817836C(void)
{
DestroySprite(&gSprites[sBerryTag->berrySpriteId]);
FreeBerryTagSpritePalette();
}
static void sub_817839C(void)
{
sBerryTag->flavorCircleIds[FLAVOR_SPICY] = CreateBerryFlavorCircleSprite(64);
sBerryTag->flavorCircleIds[FLAVOR_DRY] = CreateBerryFlavorCircleSprite(104);
sBerryTag->flavorCircleIds[FLAVOR_SWEET] = CreateBerryFlavorCircleSprite(144);
sBerryTag->flavorCircleIds[FLAVOR_BITTER] = CreateBerryFlavorCircleSprite(184);
sBerryTag->flavorCircleIds[FLAVOR_SOUR] = CreateBerryFlavorCircleSprite(224);
}
static void sub_8178404(void)
{
const struct Berry *berry = GetBerryInfo(sBerryTag->berryId);
if (berry->spicy)
gSprites[sBerryTag->flavorCircleIds[FLAVOR_SPICY]].invisible = 0;
else
gSprites[sBerryTag->flavorCircleIds[FLAVOR_SPICY]].invisible = 1;
if (berry->dry)
gSprites[sBerryTag->flavorCircleIds[FLAVOR_DRY]].invisible = 0;
else
gSprites[sBerryTag->flavorCircleIds[FLAVOR_DRY]].invisible = 1;
if (berry->sweet)
gSprites[sBerryTag->flavorCircleIds[FLAVOR_SWEET]].invisible = 0;
else
gSprites[sBerryTag->flavorCircleIds[FLAVOR_SWEET]].invisible = 1;
if (berry->bitter)
gSprites[sBerryTag->flavorCircleIds[FLAVOR_BITTER]].invisible = 0;
else
gSprites[sBerryTag->flavorCircleIds[FLAVOR_BITTER]].invisible = 1;
if (berry->sour)
gSprites[sBerryTag->flavorCircleIds[FLAVOR_SOUR]].invisible = 0;
else
gSprites[sBerryTag->flavorCircleIds[FLAVOR_SOUR]].invisible = 1;
}
static void sub_8178594(void)
{
u16 i;
for (i = 0; i < FLAVOR_COUNT; i++)
DestroySprite(&gSprites[sBerryTag->flavorCircleIds[i]]);
}
static void sub_81785D0(u8 taskId)
{
PlaySE(SE_SELECT);
BeginNormalPaletteFade(-1, 0, 0, 0x10, 0);
gTasks[taskId].func = sub_8178610;
}
static void sub_8178610(u8 taskId)
{
if (!gPaletteFade.active)
{
sub_817836C();
sub_8178594();
Free(sBerryTag);
FreeAllWindowBuffers();
SetMainCallback2(bag_menu_mail_related);
DestroyTask(taskId);
}
}
static void sub_8178654(u8 taskId)
{
if (!gPaletteFade.active)
{
u16 arrowKeys = gMain.newAndRepeatedKeys & DPAD_ANY;
if (arrowKeys == DPAD_UP)
sub_81786AC(taskId, -1);
else if (arrowKeys == DPAD_DOWN)
sub_81786AC(taskId, 1);
else if (gMain.newKeys & (A_BUTTON | B_BUTTON))
sub_81785D0(taskId);
}
}
static void sub_81786AC(u8 taskId, s8 toMove)
{
s16 *data = gTasks[taskId].data;
s16 currPocketPosition = gUnknown_0203CE58.unk12[3] + gUnknown_0203CE58.unk8[3];
u32 newPocketPosition = currPocketPosition + toMove;
if (newPocketPosition < 46 && BagGetItemIdByPocketPosition(BAG_BERRIES, newPocketPosition) != 0)
{
if (toMove < 0)
data[1] = 2;
else
data[1] = 1;
data[0] = 0;
PlaySE(SE_SELECT);
sub_8178728(toMove);
gTasks[taskId].func = sub_81787AC;
}
}
static void sub_8178728(s8 toMove)
{
u16 *scrollPos = &gUnknown_0203CE58.unk12[3];
u16 *cursorPos = &gUnknown_0203CE58.unk8[3];
if (toMove > 0)
{
if (*cursorPos < 4 || BagGetItemIdByPocketPosition(BAG_BERRIES, *scrollPos + 8) == 0)
*cursorPos += toMove;
else
*scrollPos += toMove;
}
else
{
if (*cursorPos > 3 || *scrollPos == 0)
*cursorPos += toMove;
else
*scrollPos += toMove;
}
sBerryTag->berryId = ItemIdToBerryType(BagGetItemIdByPocketPosition(BAG_BERRIES, *scrollPos + *cursorPos));
}
static void sub_81787AC(u8 taskId)
{
u16 i;
s16 posY;
s16 *data = gTasks[taskId].data;
data[0] += 0x10;
data[0] &= 0xFF;
if (data[1] == 1)
{
switch (data[0])
{
case 0x30:
FillWindowPixelBuffer(0, 0);
break;
case 0x40:
sub_8178110();
break;
case 0x50:
sub_817836C();
sub_8178338();
break;
case 0x60:
FillWindowPixelBuffer(1, 0);
break;
case 0x70:
sub_8178174();
break;
case 0x80:
sub_8178250();
break;
case 0x90:
sub_8178404();
break;
case 0xA0:
FillWindowPixelBuffer(2, 0);
break;
case 0xB0:
sub_81782D0();
break;
case 0xC0:
sub_8178304();
break;
}
}
else
{
switch (data[0])
{
case 0x30:
FillWindowPixelBuffer(2, 0);
break;
case 0x40:
sub_8178304();
break;
case 0x50:
sub_81782D0();
break;
case 0x60:
sub_8178404();
break;
case 0x70:
FillWindowPixelBuffer(1, 0);
break;
case 0x80:
sub_8178250();
break;
case 0x90:
sub_8178174();
break;
case 0xA0:
sub_817836C();
sub_8178338();
break;
case 0xB0:
FillWindowPixelBuffer(0, 0);
break;
case 0xC0:
sub_8178110();
break;
}
}
if (data[1] == 1)
posY = -data[0];
else
posY = data[0];
gSprites[sBerryTag->berrySpriteId].pos2.y = posY;
for (i = 0; i < FLAVOR_COUNT; i++)
gSprites[sBerryTag->flavorCircleIds[i]].pos2.y = posY;
ChangeBgY(1, 0x1000, data[1]);
ChangeBgY(2, 0x1000, data[1]);
if (data[0] == 0)
gTasks[taskId].func = sub_8178654;
}