diff --git a/headers/functions/arm9.h b/headers/functions/arm9.h index 2619bca7..6695476d 100644 --- a/headers/functions/arm9.h +++ b/headers/functions/arm9.h @@ -171,8 +171,8 @@ int FindItemInInventory(enum item_id item_id); int SprintfStatic(char* str, const char* format, ...); void ItemZInit(struct item* item); bool AreItemsEquivalent(struct item* item1, struct item* item2, int bitmask); -int WriteItemsToSave(void* start_address, uint32_t total_length); -int ReadItemsFromSave(void* start_address, uint32_t total_length); +int GetItemsForSave(void* dst, uint32_t len); +int ReadItemsFromSave(void* src, uint32_t len); bool IsItemAvailableInDungeonGroup(enum dungeon_id dungeon_id, enum item_id item_id); enum item_id GetItemIdFromList(int list_id, int category_num, int item_num); enum item_id NormalizeTreasureBox(enum item_id item_id); @@ -378,10 +378,10 @@ void DungeonToGroundMoveset(undefined* dst, undefined* src); void GetInfoGroundMoveset(undefined* moveset, struct move_id_16* moves); int FindFirstFreeMovesetIdx(undefined* moveset); void LearnMoves(undefined* moveset, struct move_id_16* moves); -void CopyMoveTo(undefined* write_info, void* buffer_write); -void CopyMoveFrom(undefined* read_info, void* buffer_read); -void CopyMovesetTo(undefined* write_info, void* buffer_write); -void CopyMovesetFrom(undefined* read_info, void* buffer_read); +void CopyMoveToStream(struct bitstream* bitstream, struct ground_move* src); +void CopyMoveFromStream(struct bitstream* bitstream, struct ground_move* dst); +void CopyMovesetToStream(struct bitstream* bitstream, struct ground_move* src); +void CopyMovesetFromStream(struct bitstream* bitstream, struct ground_move* dst); bool Is2TurnsMove(enum move_id move_id); bool IsRegularAttackOrProjectile(enum move_id move_id); bool IsPunchMove(enum move_id move_id); @@ -893,10 +893,10 @@ void IncrementNbAdventures(void); int GetNbAdventures(void); bool CanMonsterSpawn(enum monster_id monster_id); void IncrementExclusiveMonsterCounts(enum monster_id monster_id); -void CopyProgressInfoTo(undefined* write_info, undefined4 param_2, undefined4 param_3, int param_4); -undefined4 CopyProgressInfoFromScratchTo(void* start_addr, uint32_t total_len); -void CopyProgressInfoFrom(undefined* read_info); -undefined4 CopyProgressInfoFromScratchFrom(void* start_addr, uint32_t total_len); +void CopyProgressInfoToStream(struct bitstream* stream); +uint32_t GetProgressInfoForSave(void* dst, uint32_t len); +void CopyProgressInfoFromStream(struct bitstream* stream); +uint32_t ReadProgressInfoFromSave(void* src, uint32_t len); void InitKaomadoStream(void); void InitPortraitParams(struct portrait_params* portrait); void InitPortraitParamsWithMonsterId(struct portrait_params* portrait, enum monster_id monster_id); @@ -967,14 +967,17 @@ uint32_t GetNbItemAcquired(void); void SetChallengeLetterCleared(uint32_t challenge_id); uint32_t GetSentryDutyGamePoints(int32_t rank); int32_t SetSentryDutyGamePoints(uint32_t points); -void CopyLogTo(undefined* write_info); -void CopyLogFrom(undefined* read_info); +void CopyLogToStream(struct bitstream* stream); +void CopyLogFromStream(struct bitstream* stream); void GetAbilityString(undefined* buf, enum ability_id ability_id); int GetAbilityDescStringId(enum ability_id ability_id); int GetTypeStringId(enum type_id type_id); enum type_id GetConversion2ConvertToType(enum type_id attack_type_id); -void CopyBitsTo(undefined* write_info, void* buf_write, int nbits); -void CopyBitsFrom(undefined* read_info, void* buf_read, int nbits); +void InitBitstreamForWrite(struct bitstream* stream, void* src, uint32_t len); +void InitBitstreamForRead(struct bitstream* stream, void* dst, uint32_t len); +void BitstreamDebug(struct bitstream* stream); +void CopyBitsToStream(struct bitstream* stream, void* src, int nbits); +void CopyBitsFromStream(struct bitstream* stream, void* dst, int nbits); void StoreDefaultTeamData(void); void GetMainTeamNameWithCheck(char* buf); void GetMainTeamName(char* buf); @@ -1010,8 +1013,8 @@ bool IsSpecialEpisodeDungeon(enum dungeon_id dungeon_id); enum item_id RetrieveFromItemList1(undefined* dungeon_info, undefined4 param_2); bool IsForbiddenFloor(undefined* dungeon_info, undefined4 param_2, undefined4 param_3, undefined4 param_4); -void Copy16BitsTo(undefined* write_info, void* buf_write); -void Copy16BitsFrom(undefined* read_info, void* buf_read); +void Copy16BitsToStream(struct bitstream* stream, void* src); +void Copy16BitsFromStream(struct bitstream* stream, void* dst); enum item_id RetrieveFromItemList2(undefined* dungeon_info, undefined4 param_2); bool IsInvalidForMission(enum dungeon_id dungeon_id); bool IsExpEnabledInDungeon(enum dungeon_id dungeon_id); @@ -1150,10 +1153,10 @@ enum iq_skill_id GetNextIqSkill(enum monster_id monster_id, int monster_iq); bool ExplorerMazeMonsterExists(void); void GetExplorerMazeTeamName(char* buffer); struct ground_monster* GetExplorerMazeMonster(uint8_t entry_number); -undefined4 WriteMonsterInfoToSave(void* start_addr, uint32_t total_len); -undefined4 ReadMonsterInfoFromSave(void* start_addr, uint32_t total_len); -void WriteMonsterToSave(undefined* write_info, struct ground_monster* monster); -void ReadMonsterFromSave(undefined* read_info, struct ground_monster* monster); +uint32_t GetMonsterInfoForSave(void* dst, uint32_t len); +uint32_t ReadMonsterInfoFromSave(void* src, uint32_t len); +void CopyMonsterToStream(struct bitstream* stream, struct ground_monster* monster); +void CopyMonsterFromStream(struct bitstream* stream, struct ground_monster* monster); void GetEvolutionPossibilities(struct ground_monster* monster, undefined* evo); int GetMonsterEvoStatus(struct ground_monster* monster); bool HandleShedinjaEvolution(int16_t* member_idx, enum monster_id monster_id); diff --git a/headers/types/common/common.h b/headers/types/common/common.h index 0535cec8..888e117f 100644 --- a/headers/types/common/common.h +++ b/headers/types/common/common.h @@ -1437,4 +1437,13 @@ struct buttons { }; ASSERT_SIZE(struct buttons, 2); +struct bitstream { + char* ptr; // 0x0: Current byte + undefined4 end; // 0x4: End of the region the bitstream can read from / write to. Doesn't seem + // to do anything with this information? + uint32_t bit_idx; // 0x8: Bit position in current byte + uint32_t bit_count; // 0xC: Total bits this stream has used +}; +ASSERT_SIZE(struct bitstream, 16); + #endif diff --git a/symbols/arm9.yml b/symbols/arm9.yml index c51279c7..41c0fc15 100644 --- a/symbols/arm9.yml +++ b/symbols/arm9.yml @@ -1825,16 +1825,20 @@ arm9: r1: item r2: bitmask return: bool - - name: WriteItemsToSave + - name: GetItemsForSave + aliases: + - WriteItemsToSave address: EU: 0x200D9E4 NA: 0x200D95C JP: 0x200D98C description: |- - Note: unverified, ported from Irdkwia's notes + Reads item data from BAG_ITEMS_PTR_MIRROR and compresses it using bitstreams. + + Read equivalent of ReadItemsFromSave. - r0: start_address - r1: total_length + r0: Destination for compressed item data + r1: Data length return: ? - name: ReadItemsFromSave address: @@ -1842,10 +1846,12 @@ arm9: NA: 0x200DC44 JP: 0x200DC74 description: |- - Note: unverified, ported from Irdkwia's notes + Takes compressed item data and decompresses it using bitstreams, putting the decompressed item data in BAG_ITEMS_PTR_MIRROR. + + Write equivalent of GetItemsForSave. - r0: start_address - r1: total_length + r0: Pointer to compressed item data to read from + r1: Data length return: ? - name: IsItemAvailableInDungeonGroup address: @@ -3688,46 +3694,62 @@ arm9: r0: moveset_str r1: moves_id - - name: CopyMoveTo + - name: CopyMoveToStream + aliases: + - CopyMoveTo address: EU: 0x2014AF4 NA: 0x2014A4C JP: 0x2014A1C description: |- - Note: unverified, ported from Irdkwia's notes + Reads the provided ground_move and compresses it using the provided bitstream. - r0: write_info - r1: buffer_write - - name: CopyMoveFrom + Read equivalent of CopyMoveFromStream. + + r0: bitstream + r1: Source move + - name: CopyMoveFromStream + aliases: + - CopyMoveFrom address: EU: 0x2014B2C NA: 0x2014A84 JP: 0x2014A54 description: |- - Note: unverified, ported from Irdkwia's notes + Decompresses a ground_move from the provided bitstream. + + Write equivalent of CopyMoveToStream. - r0: read_info - r1: buffer_read - - name: CopyMovesetTo + r0: bitstream + r1: [output] move + - name: CopyMovesetToStream + aliases: + - CopyMovesetTo address: EU: 0x2014B64 NA: 0x2014ABC JP: 0x2014A8C description: |- - Note: unverified, ported from Irdkwia's notes + Reads the provided ground_moves and compresses it using the provided bitstream. + + Read equivalent of CopyMovesetFromStream. - r0: write_info - r1: buffer_write - - name: CopyMovesetFrom + r0: bitstream + r1: moveset + - name: CopyMovesetFromStream + aliases: + - CopyMovesetFrom address: EU: 0x2014B94 NA: 0x2014AEC JP: 0x2014ABC description: |- - Note: unverified, ported from Irdkwia's notes + Decompresses 4 ground_moves from the provided bitstream. - r0: read_info - r1: buffer_read + Write equivalent of CopyMovesetFromStream. + + r0: bitstream + r1: [output] moveset - name: Is2TurnsMove address: EU: 0x2014D0C @@ -8429,46 +8451,62 @@ arm9: Note: unverified, ported from Irdkwia's notes r0: monster ID - - name: CopyProgressInfoTo + - name: CopyProgressInfoToStream + aliases: + - CopyProgressInfoTo address: EU: 0x204D6F8 NA: 0x204D3C0 JP: 0x204D720 description: |- - Note: unverified, ported from Irdkwia's notes + Reads progress data from the global_progress struct and compresses it using bitstreams. - r0: write_info - others: ? - - name: CopyProgressInfoFromScratchTo + Read equivalent of CopyProgressInfoFromStream. + + r0: bitstream + - name: GetProgressInfoForSave + aliases: + - CopyProgressInfoFromScratchTo address: EU: 0x204D880 NA: 0x204D548 JP: 0x204D8A8 description: |- - Note: unverified, ported from Irdkwia's notes + Compresses progress info using CopyProgressInfoToStream, writing the compressed data to the provided destination. - r0: start_address - r1: total_length - return: ? - - name: CopyProgressInfoFrom + Read equivalent of ReadProgressInfoFromSave. + + r0: [output] Destination for compressed progress data + r1: Data length + return: Final bit_idx of the bitstream used + - name: CopyProgressInfoFromStream + aliases: + - CopyProgressInfoFrom address: EU: 0x204D8B8 NA: 0x204D580 JP: 0x204D8E0 description: |- - Note: unverified, ported from Irdkwia's notes + Decompresses progress data using the provided bitstream and populates the global_progress struct. - r0: read_info - - name: CopyProgressInfoFromScratchFrom + Write equivalent of CopyProgressInfoToStream. + + r0: bitstream + - name: ReadProgressInfoFromSave + aliases: + - CopyProgressInfoFromScratchFrom address: EU: 0x204DA80 NA: 0x204D748 JP: 0x204DAA8 description: |- - Note: unverified, ported from Irdkwia's notes + Decompresses progress data from the source address to populate the global_progress struct using CopyProgressInfoFromStream. + + Write equivalent of GetProgressInfoForSave. - r0: start_address - r1: total_length + r0: Location of source compressed progress data + r1: Data length + return: Final bit_idx of the bitstream used - name: InitKaomadoStream address: EU: 0x204DAB8 @@ -9151,24 +9189,32 @@ arm9: r0: points return: the rank (range 0-4, 1st to 5th; -1 if out of ranking) - - name: CopyLogTo + - name: CopyLogToStream + aliases: + - CopyLogTo address: EU: 0x2050884 NA: 0x205054C JP: 0x2050898 description: |- - Note: unverified, ported from Irdkwia's notes + Reads adventure log data from ADVENTURE_LOG_PTR and compresses it using bitstreams. - r0: write_info - - name: CopyLogFrom + Read equivalent of CopyLogFromStream. + + r0: bitstream + - name: CopyLogFromStream + aliases: + - CopyLogFrom address: EU: 0x2050A70 NA: 0x2050738 JP: 0x2050A84 description: |- - Note: unverified, ported from Irdkwia's notes + Decompresses adventure log data from a bitstream, putting the decompressed data in ADVENTURE_LOG_PTR. + + Write equivalent of CopyLogToStream. - r0: read_info + r0: bitstream - name: GetAbilityString address: EU: 0x2050C54 @@ -9210,28 +9256,69 @@ arm9: r0: type ID return: type ID - - name: CopyBitsTo + - name: InitBitstreamForWrite + address: + EU: 0x2050CAC + NA: 0x2050974 + JP: 0x2050CC0 + description: |- + Initializes a bitstream at addr, preserving the contents of the region. For using the bitstream to write somewhere else. + + Used with CopyBitsFromStream. + + r0: [Output] Pointer to bitstream to initialize + r1: Pointer to where the bitstream should read from. This is the source, so bits will be written from somewhere else into here. + r2: Length of data to read (in bytes) + - name: InitBitstreamForRead + address: + EU: 0x2050CC8 + NA: 0x2050990 + JP: 0x2050CDC + description: |- + Initializes a bitstream at addr, and zeroes out the region it uses (dst to dst+len). For writing from somewhere else into the bitstream. + + Used with CopyBitsToStream. + + r0: [Output] bitstream to initialize + r1: Pointer to where the bitstream should write to. This is the destination, so bits will be read from somewhere else into here. + r2: Length of data to read (in bytes) + - name: BitstreamDebug + address: + EU: 0x2050CF4 + NA: 0x20509BC + JP: 0x2050D08 + description: |- + Potentially a debug function. Gets called by many functions that use bitstreams. + + Likely a debug function, but does nothing in the final release. + + r0: Bitstream + - name: CopyBitsToStream + aliases: + - CopyBitsTo address: EU: 0x2050CF8 NA: 0x20509C0 JP: 0x2050D0C description: |- - Note: unverified, ported from Irdkwia's notes + Copies n bits from src into the provided bitstream. - r0: write_info - r1: buffer_write - r2: nb_bits - - name: CopyBitsFrom + r0: bitstream + r1: Source to read from + r2: Number of bits to read from source + - name: CopyBitsFromStream + aliases: + - CopyBitsFrom address: EU: 0x2050D78 NA: 0x2050A40 JP: 0x2050D8C description: |- - Note: unverified, ported from Irdkwia's notes + Copies n bits from the provided bitstream into the destination. - r0: read_info - r1: buffer_read - r2: nb_bits + r0: bitstream + r1: [output] Destination to write to + r2: Number of bits to read from stream - name: StoreDefaultTeamData address: EU: 0x2050E04 @@ -9581,26 +9668,30 @@ arm9: r0: dungeon_info others: ? return: bool - - name: Copy16BitsTo + - name: Copy16BitsToStream + aliases: + - Copy16BitsTo address: EU: 0x20518FC NA: 0x20515C4 JP: 0x2051914 description: |- - Writes 16 bits of data from buffer_write to write_info. + Copies a halfword from src into the provided bitstream. - r0: write_info - r1: buffer_write - - name: Copy16BitsFrom + r0: bitstream + r1: src + - name: Copy16BitsFromStream + aliases: + - Copy16BitsFrom address: EU: 0x2051924 NA: 0x20515EC JP: 0x205193C description: |- - Note: unverified, ported from Irdkwia's notes + Copies a halfword from the provided bitstream into dst. - r0: read_info - r1: buffer_read + r0: bitstream + r1: [output] dst - name: RetrieveFromItemList2 address: EU: 0x20519B4 @@ -11013,47 +11104,62 @@ arm9: r0: Entry number (0-3) return: Ground monster data of the specified entry - - name: WriteMonsterInfoToSave + - name: GetMonsterInfoForSave + aliases: + - WriteMonsterInfoToSave address: EU: 0x2059494 NA: 0x2059118 JP: 0x2059414 description: |- - Note: unverified, ported from Irdkwia's notes + Compresses monster info from the team_member_table struct using CopyMonsterToStream, writing the compressed data to the provided destination. - r0: start_address - r1: total_length - return: ? + Read equivalent of ReadMonsterInfoFromSave. + + r0: [output] Destination for compressed monster info + r1: Data length + return: Final bit_idx of the bitstream used - name: ReadMonsterInfoFromSave address: EU: 0x20595A0 NA: 0x2059224 JP: 0x2059520 description: |- - Note: unverified, ported from Irdkwia's notes + Decompresses monster info from the source address to populate the team_member_table struct using CopyMonsterFromStream. + + Write equivalent of GetMonsterInfoForSave. - r0: start_address - r1: total_length - - name: WriteMonsterToSave + r0: Location of source monster info + r1: Data length + return: Final bit_idx of the bitstream used + - name: CopyMonsterToStream + aliases: + - WriteMonsterToSave address: EU: 0x20596B0 NA: 0x2059334 JP: 0x2059630 description: |- - Note: unverified, ported from Irdkwia's notes + Compresses the provided ground_monster struct using the provided bitstream. - r0: write_info - r1: ground_monster - - name: ReadMonsterFromSave + Read equivalent of CopyMonsterFromStream. + + r0: bitstream + r1: Ground monster + - name: CopyMonsterFromStream + aliases: + - ReadMonsterFromSave address: EU: 0x20597C0 NA: 0x2059444 JP: 0x2059740 description: |- - Note: unverified, ported from Irdkwia's notes + Decompresses from the provided bitstream to create a ground_monster struct. + + Write equivalent of CopyMonsterToStream. - r0: read_info - r1: ground_monster + r0: bitstream + r1: [output] Ground monster - name: GetEvolutionPossibilities address: EU: 0x2059E94