Merge pull request #113 from DizzyEggg/decompile_pss

Start Pokemon Storage System
This commit is contained in:
Diegoisawesome 2017-11-15 20:55:38 -06:00 committed by GitHub
commit 6a73c89e54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 132 additions and 236 deletions

View File

@ -5,224 +5,8 @@
.text
thumb_func_start CountMonsInBox
CountMonsInBox: @ 80C6FA0
push {r4-r6,lr}
lsls r0, 24
lsrs r6, r0, 24
movs r4, 0
movs r5, 0
_080C6FAA:
lsls r1, r4, 24
lsrs r1, 24
adds r0, r6, 0
movs r2, 0xB
bl GetBoxMonDataFromAnyBox
cmp r0, 0
beq _080C6FC0
adds r0, r5, 0x1
lsls r0, 16
lsrs r5, r0, 16
_080C6FC0:
adds r0, r4, 0x1
lsls r0, 16
lsrs r4, r0, 16
cmp r4, 0x1D
bls _080C6FAA
lsls r0, r5, 24
lsrs r0, 24
pop {r4-r6}
pop {r1}
bx r1
thumb_func_end CountMonsInBox
thumb_func_start sub_80C6FD4
sub_80C6FD4: @ 80C6FD4
push {r4,r5,lr}
lsls r0, 24
lsrs r5, r0, 24
movs r4, 0
_080C6FDC:
lsls r1, r4, 24
lsrs r1, 24
adds r0, r5, 0
movs r2, 0xB
bl GetBoxMonDataFromAnyBox
cmp r0, 0
bne _080C6FF2
lsls r0, r4, 16
asrs r0, 16
b _080C7000
_080C6FF2:
adds r0, r4, 0x1
lsls r0, 16
lsrs r4, r0, 16
cmp r4, 0x1D
bls _080C6FDC
movs r0, 0x1
negs r0, r0
_080C7000:
pop {r4,r5}
pop {r1}
bx r1
thumb_func_end sub_80C6FD4
thumb_func_start sub_80C7008
sub_80C7008: @ 80C7008
push {r4-r6,lr}
movs r5, 0
movs r6, 0
_080C700E:
movs r0, 0x64
adds r1, r5, 0
muls r1, r0
ldr r0, =gPlayerParty
adds r4, r1, r0
adds r0, r4, 0
movs r1, 0xB
bl GetMonData
cmp r0, 0
beq _080C7036
adds r0, r4, 0
movs r1, 0x2D
bl GetMonData
cmp r0, 0
bne _080C7036
adds r0, r6, 0x1
lsls r0, 16
lsrs r6, r0, 16
_080C7036:
adds r0, r5, 0x1
lsls r0, 16
lsrs r5, r0, 16
cmp r5, 0x5
bls _080C700E
lsls r0, r6, 24
lsrs r0, 24
pop {r4-r6}
pop {r1}
bx r1
.pool
thumb_func_end sub_80C7008
thumb_func_start sub_80C7050
sub_80C7050: @ 80C7050
push {r4-r7,lr}
lsls r0, 24
movs r5, 0
movs r6, 0
lsrs r7, r0, 24
_080C705A:
cmp r5, r7
beq _080C7092
movs r0, 0x64
adds r1, r5, 0
muls r1, r0
ldr r0, =gPlayerParty
adds r4, r1, r0
adds r0, r4, 0
movs r1, 0xB
bl GetMonData
cmp r0, 0
beq _080C7092
adds r0, r4, 0
movs r1, 0x2D
bl GetMonData
cmp r0, 0
bne _080C7092
adds r0, r4, 0
movs r1, 0x39
bl GetMonData
cmp r0, 0
beq _080C7092
adds r0, r6, 0x1
lsls r0, 16
lsrs r6, r0, 16
_080C7092:
adds r0, r5, 0x1
lsls r0, 16
lsrs r5, r0, 16
cmp r5, 0x5
bls _080C705A
lsls r0, r6, 24
lsrs r0, 24
pop {r4-r7}
pop {r1}
bx r1
.pool
thumb_func_end sub_80C7050
thumb_func_start sub_80C70AC
sub_80C70AC: @ 80C70AC
push {lr}
ldr r0, =gSpecialVar_0x8004
ldrb r0, [r0]
bl sub_80C7050
lsls r0, 24
lsrs r0, 24
pop {r1}
bx r1
.pool
thumb_func_end sub_80C70AC
thumb_func_start sub_80C70C4
sub_80C70C4: @ 80C70C4
push {r4,r5,lr}
movs r4, 0
movs r5, 0
_080C70CA:
movs r0, 0x64
muls r0, r4
ldr r1, =gPlayerParty
adds r0, r1
movs r1, 0xB
bl GetMonData
cmp r0, 0
beq _080C70E2
adds r0, r5, 0x1
lsls r0, 16
lsrs r5, r0, 16
_080C70E2:
adds r0, r4, 0x1
lsls r0, 16
lsrs r4, r0, 16
cmp r4, 0x5
bls _080C70CA
lsls r0, r5, 24
lsrs r0, 24
pop {r4,r5}
pop {r1}
bx r1
.pool
thumb_func_end sub_80C70C4
thumb_func_start sub_80C70FC
sub_80C70FC: @ 80C70FC
push {r4,r5,lr}
adds r5, r0, 0
lsls r4, r2, 16
lsrs r4, 16
bl StringCopy
adds r1, r0, 0
adds r5, r4
cmp r1, r5
bcs _080C711A
movs r0, 0
_080C7112:
strb r0, [r1]
adds r1, 0x1
cmp r1, r5
bcc _080C7112
_080C711A:
movs r0, 0xFF
strb r0, [r1]
adds r0, r1, 0
pop {r4,r5}
pop {r1}
bx r1
thumb_func_end sub_80C70FC
thumb_func_start sub_80C7128
thumb_func_start sub_80C7128
sub_80C7128: @ 80C7128
push {r4-r7,lr}
mov r7, r9
@ -578,7 +362,7 @@ _080C73F6:
ldrsh r4, [r5, r3]
cmp r4, 0
bne _080C7428
bl sub_80C70C4
bl CountPartyMons
lsls r0, 24
lsrs r0, 24
cmp r0, 0x6
@ -601,7 +385,7 @@ _080C7428:
ldrsh r0, [r5, r1]
cmp r0, 0x1
bne _080C745C
bl sub_80C70C4
bl CountPartyMons
lsls r0, 24
lsrs r4, r0, 24
cmp r4, 0x1
@ -13381,7 +13165,7 @@ sub_80CE19C: @ 80CE19C
lsls r0, 24
lsrs r6, r0, 24
adds r0, r6, 0
bl sub_80C6FD4
bl GetFirstFreeBoxSpot
lsls r0, 16
lsrs r4, r0, 16
asrs r0, 16
@ -14127,7 +13911,7 @@ _080CE838:
ldr r2, =0x00002187
adds r1, r2
strb r0, [r1]
bl sub_80C70C4
bl CountPartyMons
ldr r1, [r4]
subs r0, 0x1
ldr r2, =0x00002186
@ -14347,7 +14131,7 @@ sub_80CEA30: @ 80CEA30
bne _080CEA64
ldr r0, =gUnknown_02039D79
ldrb r0, [r0]
bl sub_80C7050
bl CountPartyAliveNonEggMonsExcept
lsls r0, 24
cmp r0, 0
bne _080CEA64
@ -14376,7 +14160,7 @@ sub_80CEA6C: @ 80CEA6C
bne _080CEAAC
ldr r0, =gUnknown_02039D79
ldrb r0, [r0]
bl sub_80C7050
bl CountPartyAliveNonEggMonsExcept
lsls r0, 24
cmp r0, 0
bne _080CEAAC

View File

@ -142,8 +142,8 @@ gSpecials:: @ 81DBA64
def_special sub_8122A30
def_special sub_80D6EDC
def_special CalculatePlayerPartyCount
def_special sub_80C7008
def_special sub_80C70AC
def_special CountPartyNonEggMons
def_special CountPartyAliveNonEggMons_IgnoreVar0x8004Slot
def_special sub_80F88E8
def_special sub_80F88DC
def_special sub_80F8864

View File

@ -1,8 +1,12 @@
#ifndef GUARD_POKEMON_STORAGE_SYSTEM_H
#define GUARD_POKEMON_STORAGE_SYSTEM_H
#define TOTAL_BOXES_COUNT 14
#define IN_BOX_COUNT 30
u8* GetBoxNamePtr(u8 boxNumber);
struct BoxPokemon *GetBoxedMonPtr(u8, u8);
void SetBoxMonNickFromAnyBox(u8, u8, u8 *);
u32 GetBoxMonDataFromAnyBox(u8 boxId, u8 monPosition, u32 request);
#endif // GUARD_POKEMON_STORAGE_SYSTEM_H

View File

@ -130,6 +130,7 @@ SECTIONS {
asm/option_menu.o(.text);
asm/pokedex.o(.text);
asm/trainer_card.o(.text);
src/pokemon_storage_system.o(.text);
asm/pokemon_storage_system.o(.text);
asm/pokemon_icon.o(.text);
asm/script_movement.o(.text);

View File

@ -75,7 +75,7 @@ extern void CreateYesNoMenu(const struct WindowTemplate*, u16, u8, u8);
extern void DoNamingScreen(u8, const u8*, u16, u8, u32, MainCallback);
extern void AddTextPrinterParametrized2(u8 windowId, u8 fontId, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, struct TextColor* colors, s8 speed, u8 *str);
extern u16 sub_80D22D0(void);
extern u8 sub_80C7050(u8);
extern u8 CountPartyAliveNonEggMonsExcept(u8);
static void Task_EggHatch(u8 taskID);
static void CB2_EggHatch_0(void);
@ -888,6 +888,6 @@ u8 GetEggStepsToSubtract(void)
u16 sub_80722E0(void)
{
u16 value = sub_80D22D0();
value += sub_80C7050(6);
value += CountPartyAliveNonEggMonsExcept(6);
return value;
}

View File

@ -1,15 +1,122 @@
// Includes
#include "global.h"
// Static type declarations
// Static RAM declarations
#include "pokemon_storage_system.h"
#include "pokemon.h"
#include "species.h"
#include "event_data.h"
#include "string_util.h"
#include "text.h"
IWRAM_DATA u8 gUnknown_03000F78[0x188];
// Static ROM declarations
u8 CountMonsInBox(u8 boxId)
{
u16 i, count;
// .rodata
for (i = 0, count = 0; i < IN_BOX_COUNT; i++)
{
if (GetBoxMonDataFromAnyBox(boxId, i, MON_DATA_SPECIES) != SPECIES_NONE)
count++;
}
// .text
return count;
}
s16 GetFirstFreeBoxSpot(u8 boxId)
{
u16 i;
for (i = 0; i < IN_BOX_COUNT; i++)
{
if (GetBoxMonDataFromAnyBox(boxId, i, MON_DATA_SPECIES) == SPECIES_NONE)
return i;
}
return -1; // all spots are taken
}
u8 CountPartyNonEggMons(void)
{
u16 i, count;
for (i = 0, count = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE
&& !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG))
{
count++;
}
}
return count;
}
u8 CountPartyAliveNonEggMonsExcept(u8 slotToIgnore)
{
u16 i, count;
for (i = 0, count = 0; i < PARTY_SIZE; i++)
{
if (i != slotToIgnore
&& GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE
&& !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)
&& GetMonData(&gPlayerParty[i], MON_DATA_HP) != 0)
{
count++;
}
}
return count;
}
u16 CountPartyAliveNonEggMons_IgnoreVar0x8004Slot(void)
{
return CountPartyAliveNonEggMonsExcept(gSpecialVar_0x8004);
}
u8 CountPartyMons(void)
{
u16 i, count;
for (i = 0, count = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE)
{
count++;
}
}
return count;
}
static u8 *StringCopyAndFillWithSpaces(u8 *dst, const u8 *src, u16 n)
{
u8 *str;
for (str = StringCopy(dst, src); str < dst + n; str++)
*str = CHAR_SPACE;
*str = EOS;
return str;
}
/* can't match
static void sub_80C7128(u16 *dst, u16 dstToAdd, u16 dstToMul, const u16 *src, u16 srcToAdd, u16 srcToMul, u32 size, u16 count, u16 srcBy)
{
u16 i;
size <<= 0x11;
dst += (dstToMul * 32) + dstToAdd;
src += (srcToMul * srcBy) + srcToAdd;
i = 0;
if (i < count)
{
size >>= 1;
for (i = 0; i < count; i++)
{
CpuSet(src, dst, size >> 0x10);
dst += 0x20;
src += srcBy;
}
}
}*/