From 13bd14feabf17e16b180d176b488979708391927 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Mon, 23 Oct 2017 23:33:13 -0400 Subject: recast fixes for SetMonData and SetBoxMonData. --- include/pokemon.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/pokemon.h b/include/pokemon.h index dabdff626..77ed10142 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -544,8 +544,8 @@ union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, u32 GetMonData(); u32 GetBoxMonData(); -void SetMonData(struct Pokemon *mon, s32 field, const u8 *data); -void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const u8 *data); +void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg); +void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg); void CopyMon(void *dest, void *src, size_t size); u8 GiveMonToPlayer(struct Pokemon *mon); u8 SendMonToPC(struct Pokemon *mon); -- cgit v1.2.3 From f9282b737e5ac72ad9e946e6bf5441852abad0f8 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 29 Oct 2017 02:06:11 -0400 Subject: use BAD_MEMSET macro for battle files. --- include/battle.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include') diff --git a/include/battle.h b/include/battle.h index f973849b7..2b268c3c8 100644 --- a/include/battle.h +++ b/include/battle.h @@ -686,6 +686,28 @@ extern u8 ewram[]; #define ewram17840 (*(struct Struct2017840 *) (ewram + 0x17840)) #define ewram17000 ((u32 *) (ewram + 0x17100)) +// used in many battle files, it seems as though Hisashi Sogabe wrote +// some sort of macro to replace the use of actually calling memset. +// Perhaps it was thought calling memset was much slower? + +// The compiler wont allow us to locally declare ptr in this macro; some +// functions that invoke this macro will not match without this egregeous +// assumption about the variable names. +#define BAD_MEMSET(data, c, size, var, ptr) \ +{ \ + ptr = (u8 *)data; \ + for(var = 0; var < (u32)size; var++) \ + ptr[var] = c; \ +} \ + +// TODO: Try to combine these macros. +#define BAD_MEMSET_REVERSE(data, ptr2, size, var, ptr) \ +{ \ + ptr = (u8 *)data; \ + for(var = 0; var < (u32)size; var++) \ + ptr2[var] = ptr[var]; \ +} \ + typedef void (*BattleCmdFunc)(void); struct funcStack -- cgit v1.2.3 From e08f3e4398d6c1dc21437e7b6462521ecfd299a6 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 29 Oct 2017 02:22:10 -0400 Subject: change SetMonData and SetBoxMonData prototypes --- include/pokemon.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/pokemon.h b/include/pokemon.h index 1ab326b6a..d653067e4 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -541,11 +541,13 @@ union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, // but they are not used since some code erroneously omits the third arg. // u32 GetMonData(struct Pokemon *mon, s32 field, u8 *data); // u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data); +// void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg); +// void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg); u32 GetMonData(); u32 GetBoxMonData(); +void SetMonData(); +void SetBoxMonData(); -void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg); -void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg); void CopyMon(void *dest, void *src, size_t size); u8 GiveMonToPlayer(struct Pokemon *mon); u8 SendMonToPC(struct Pokemon *mon); -- cgit v1.2.3 From 2f99edc6fd21d0af1bb05fae55302a46c744ffa6 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Fri, 3 Nov 2017 02:43:41 -0400 Subject: NotInBattle --- include/battle.h | 17 +++++++++-------- include/battle_anim.h | 3 +-- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/battle.h b/include/battle.h index 2b268c3c8..95dba4897 100644 --- a/include/battle.h +++ b/include/battle.h @@ -692,20 +692,21 @@ extern u8 ewram[]; // The compiler wont allow us to locally declare ptr in this macro; some // functions that invoke this macro will not match without this egregeous -// assumption about the variable names. -#define BAD_MEMSET(data, c, size, var, ptr) \ +// assumption about the variable names, so in order to avoid this assumption, +// we opt to pass the variables themselves, even though it is likely that +// Sogabe assumed the variables were named src and dest. +#define BAD_MEMSET(data, c, size, var, dest) \ { \ - ptr = (u8 *)data; \ + dest = (u8 *)data; \ for(var = 0; var < (u32)size; var++) \ - ptr[var] = c; \ + dest[var] = c; \ } \ -// TODO: Try to combine these macros. -#define BAD_MEMSET_REVERSE(data, ptr2, size, var, ptr) \ +#define BAD_MEMCPY(data, dest, size, var, src) \ { \ - ptr = (u8 *)data; \ + src = (u8 *)data; \ for(var = 0; var < (u32)size; var++) \ - ptr2[var] = ptr[var]; \ + dest[var] = src[var]; \ } \ typedef void (*BattleCmdFunc)(void); diff --git a/include/battle_anim.h b/include/battle_anim.h index 2386c515c..a9405068d 100644 --- a/include/battle_anim.h +++ b/include/battle_anim.h @@ -55,13 +55,12 @@ struct UnknownStruct3 void DoMoveAnim(const u8 *const moveAnims[], u16 b, u8 c); bool8 IsAnimBankSpriteVisible(u8 a); void sub_8076034(u8, u8); -bool8 IsContest(void); +bool8 NotInBattle(void); void battle_anim_clear_some_data(void); void move_anim_8072740(struct Sprite *sprite); void DestroyAnimVisualTask(u8 task); void DestroyAnimVisualTask(u8 task); bool8 IsAnimBankSpriteVisible(u8); -u8 IsContest(); #endif -- cgit v1.2.3 From 67ea254871134d850e013ee72bd4275b40e8091b Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Fri, 3 Nov 2017 19:09:40 -0400 Subject: BG_CHAR_ADDR and BG_SCREEN_ADDR recast fixes --- include/battle.h | 1 - include/battle_ai.h | 5 ----- include/battle_anim.h | 4 ---- include/gba/defines.h | 4 ++-- include/global.h | 18 ++++++++++++++++++ include/rom3.h | 8 +++++++- 6 files changed, 27 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/battle.h b/include/battle.h index 95dba4897..9adcaaf95 100644 --- a/include/battle.h +++ b/include/battle.h @@ -748,7 +748,6 @@ void EmitEffectivenessSound(u8 a, u16 sound); //0x2B void Emitcmd44(u8 a, u16 sound); //0x2C void EmitFaintingCry(u8 a); //0x2D void EmitIntroSlide(u8 a, u8 b); //0x2E -void Emitcmd48(u8 a, u8 *b, u8 c); //0x30 void Emitcmd49(u8 a); //0x31 void EmitSpriteInvisibility(u8 a, u8 b); //0x33 void EmitBattleAnimation(u8 a, u8 b, u16 c); //0x34 diff --git a/include/battle_ai.h b/include/battle_ai.h index 2922da0b3..60ca5d000 100644 --- a/include/battle_ai.h +++ b/include/battle_ai.h @@ -1,11 +1,6 @@ #ifndef GUARD_BATTLEAI_H #define GUARD_BATTLEAI_H -#define AIScriptRead32(ptr) ((ptr)[0] | (ptr)[1] << 8 | (ptr)[2] << 16 | (ptr)[3] << 24) -#define AIScriptRead16(ptr) ((ptr)[0] | (ptr)[1] << 8) -#define AIScriptRead8(ptr) ((ptr)[0]) -#define AIScriptReadPtr(ptr) (u8*) AIScriptRead32(ptr) - enum { TARGET, diff --git a/include/battle_anim.h b/include/battle_anim.h index a9405068d..3db5ae967 100644 --- a/include/battle_anim.h +++ b/include/battle_anim.h @@ -3,10 +3,6 @@ #include "sprite.h" -#define SCRIPT_READ_8(ptr) ((ptr)[0]) -#define SCRIPT_READ_16(ptr) ((ptr)[0] | ((ptr)[1] << 8)) -#define SCRIPT_READ_32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24)) - #define REG_BGnCNT_BITFIELD(n) (*(struct BGCntrlBitfield *)REG_ADDR_BG##n##CNT) #define REG_BG1CNT_BITFIELD REG_BGnCNT_BITFIELD(1) #define REG_BG2CNT_BITFIELD REG_BGnCNT_BITFIELD(2) diff --git a/include/gba/defines.h b/include/gba/defines.h index 0f7f06755..2a0e6f7d8 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -29,8 +29,8 @@ #define BG_VRAM VRAM #define BG_VRAM_SIZE 0x10000 -#define BG_CHAR_ADDR(n) (BG_VRAM + (0x4000 * (n))) -#define BG_SCREEN_ADDR(n) (BG_VRAM + (0x800 * (n))) +#define BG_CHAR_ADDR(n) (void *)(BG_VRAM + (0x4000 * (n))) +#define BG_SCREEN_ADDR(n) (void *)(BG_VRAM + (0x800 * (n))) // text-mode BG #define OBJ_VRAM0 (VRAM + 0x10000) diff --git a/include/global.h b/include/global.h index 29804a5a9..e0a1c6452 100644 --- a/include/global.h +++ b/include/global.h @@ -55,6 +55,24 @@ enum B_32 = 4 }; +// There are many quirks in the source code which have overarching behavioral differences from +// a number of other files. For example, diploma.c seems to declare rodata before each use while +// other files declare out of order and must be at the beginning. There are also a number of +// macros which differ from one file to the next due to the method of obtaining the result, such +// as these below. Because of this, there is a theory (Two Team Theory) that states that these +// programming projects had more than 1 "programming team" which utilized different macros for +// each of the files that were worked on. +#define T1_READ_8(ptr) ((ptr)[0]) +#define T1_READ_16(ptr) ((ptr)[0] | ((ptr)[1] << 8)) // why do you use OR here but not for READ_32? +#define T1_READ_32(ptr) ((ptr)[0] | ((ptr)[1] << 8) | ((ptr)[2] << 16) | ((ptr)[3] << 24)) +#define T1_READ_PTR(ptr) (u8*) T1_READ_32(ptr) + +// T2_READ_8 is a duplicate to remain consistent with each group. +#define T2_READ_8(ptr) ((ptr)[0]) +#define T2_READ_16(ptr) ((ptr)[0] + ((ptr)[1] << 8)) // why do you use OR here but not for READ_32? +#define T2_READ_32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24)) +#define T2_READ_PTR(ptr) (void*) T2_READ_32(ptr) + enum { VERSION_SAPPHIRE = 1, diff --git a/include/rom3.h b/include/rom3.h index 81bb56df1..19c6def25 100644 --- a/include/rom3.h +++ b/include/rom3.h @@ -1,6 +1,12 @@ #ifndef GUARD_ROM3_H #define GUARD_ROM3_H +struct HpAndStatus +{ + u16 hp; + u32 status; +}; + struct DisableStruct; void sub_800B858(void); @@ -55,7 +61,7 @@ void Emitcmd44(u8 a, u16 b); void EmitFaintingCry(u8 a); void EmitIntroSlide(u8 a, u8 b); void EmitTrainerBallThrow(u8 a); -void Emitcmd48(u8 a, u8 *b, u8 c); +void EmitDrawPartyStatusSummary(u8 a, struct HpAndStatus *hpAndStatus, u8 c); //0x30 void Emitcmd49(u8 a); void Emitcmd50(u8 a); void EmitSpriteInvisibility(u8 a, u8 b); -- cgit v1.2.3 From 581bab1360d5544101b52c0b7616e7fb16ed8a5d Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 4 Nov 2017 20:24:50 -0400 Subject: more fixes --- include/gba/defines.h | 5 +++-- include/gba/flash_internal.h | 10 +++++----- include/save.h | 2 +- include/sprite.h | 2 +- include/string_util.h | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/gba/defines.h b/include/gba/defines.h index 2a0e6f7d8..7fd429d9e 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -31,13 +31,14 @@ #define BG_VRAM_SIZE 0x10000 #define BG_CHAR_ADDR(n) (void *)(BG_VRAM + (0x4000 * (n))) #define BG_SCREEN_ADDR(n) (void *)(BG_VRAM + (0x800 * (n))) +#define BG_TILE_ADDR(n) (void *)(BG_VRAM + (0x80 * (n))) // text-mode BG -#define OBJ_VRAM0 (VRAM + 0x10000) +#define OBJ_VRAM0 (void *)(VRAM + 0x10000) #define OBJ_VRAM0_SIZE 0x8000 // bitmap-mode BG -#define OBJ_VRAM1 (VRAM + 0x14000) +#define OBJ_VRAM1 (void *)(VRAM + 0x14000) #define OBJ_VRAM1_SIZE 0x4000 #define OAM 0x7000000 diff --git a/include/gba/flash_internal.h b/include/gba/flash_internal.h index cbcfb5466..39e14ef73 100644 --- a/include/gba/flash_internal.h +++ b/include/gba/flash_internal.h @@ -35,7 +35,7 @@ struct FlashType { struct FlashSetupInfo { u16 (*programFlashByte)(u16, u32, u8); - u16 (*programFlashSector)(u16, u8 *); + u16 (*programFlashSector)(u16, void *); u16 (*eraseFlashChip)(void); u16 (*eraseFlashSector)(u16); u16 (*WaitForFlashWrite)(u8, u8 *, u8); @@ -46,7 +46,7 @@ struct FlashSetupInfo extern u16 gFlashNumRemainingBytes; extern u16 (*ProgramFlashByte)(u16, u32, u8); -extern u16 (*ProgramFlashSector)(u16, u8 *); +extern u16 (*ProgramFlashSector)(u16, void *); extern u16 (*EraseFlashChip)(void); extern u16 (*EraseFlashSector)(u16); extern u16 (*WaitForFlashWrite)(u8, u8 *, u8); @@ -67,15 +67,15 @@ void SetReadFlash1(u16 *dest); void StopFlashTimer(void); u16 SetFlashTimerIntr(u8 timerNum, void (**intrFunc)(void)); u32 ProgramFlashSectorAndVerify(u16 sectorNum, u8 *src); -void ReadFlash(u16 sectorNum, u32 offset, u8 *dest, u32 size); -u32 ProgramFlashSectorAndVerifyNBytes(u16 sectorNum, u8 *src, u32 n); +void ReadFlash(u16 sectorNum, u32 offset, void *dest, u32 size); +u32 ProgramFlashSectorAndVerifyNBytes(u16 sectorNum, void *dataSrc, u32 n); u16 WaitForFlashWrite_Common(u8 phase, u8 *addr, u8 lastData); u16 EraseFlashChip_MX(void); u16 EraseFlashSector_MX(u16 sectorNum); u16 ProgramFlashByte_MX(u16 sectorNum, u32 offset, u8 data); -u16 ProgramFlashSector_MX(u16 sectorNum, u8 *src); +u16 ProgramFlashSector_MX(u16 sectorNum, void *src); // agb_flash_1m u16 IdentifyFlash(void); diff --git a/include/save.h b/include/save.h index 6c47c6f60..c35ad547a 100644 --- a/include/save.h +++ b/include/save.h @@ -3,7 +3,7 @@ struct SaveSectionLocation { - void *data; + u8 *data; u16 size; }; diff --git a/include/sprite.h b/include/sprite.h index 769e1584d..38687ebd8 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -252,7 +252,7 @@ void SetOamMatrix(u8 matrixNum, u16 a, u16 b, u16 c, u16 d); void CalcCenterToCornerVec(struct Sprite *sprite, u8 shape, u8 size, u8 affineMode); void SpriteCallbackDummy(struct Sprite *sprite); void ProcessSpriteCopyRequests(void); -void RequestSpriteCopy(const u8 *src, u8 *dest, u16 size); +void RequestSpriteCopy(const void *src, u8 *dest, u16 size); void FreeSpriteTiles(struct Sprite *sprite); void FreeSpritePalette(struct Sprite *sprite); void FreeSpriteOamMatrix(struct Sprite *sprite); diff --git a/include/string_util.h b/include/string_util.h index 7a4bfa4c1..55fa988b4 100644 --- a/include/string_util.h +++ b/include/string_util.h @@ -29,7 +29,7 @@ u8 *ConvertIntToHexStringN(u8 *dest, s32 value, enum StringConvertMode mode, u8 u8 *ConvertIntToDecimalString(u8 *dest, s32 value); u8 *StringExpandPlaceholders(u8 *dest, const u8 *src); u8 *StringBraille(u8 *dest, const u8 *src); -u8 *GetExpandedPlaceholder(u32 id); +const u8 *GetExpandedPlaceholder(u32 id); u8 *StringFill(u8 *dest, u8 c, u16 n); u8 *StringCopyPadded(u8 *dest, const u8 *src, u8 c, u16 n); u8 *StringFillWithTerminator(u8 *dest, u16 n); -- cgit v1.2.3 From 003d16e7a178e440c41f2bca365bf8f8f2a60b0e Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 4 Nov 2017 21:44:50 -0400 Subject: finish first wave of fixes --- include/field_map_obj.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/field_map_obj.h b/include/field_map_obj.h index 19482e71f..8e1fdc8bd 100644 --- a/include/field_map_obj.h +++ b/include/field_map_obj.h @@ -344,7 +344,7 @@ void FieldObjectTurnByLocalIdAndMap(u8, u8, u8, u8); const struct MapObjectGraphicsInfo *GetFieldObjectGraphicsInfo(u8); void FieldObjectHandleDynamicGraphicsId(struct MapObject *); void npc_by_local_id_and_map_set_field_1_bit_x20(u8, u8, u8, u8); -void FieldObjectGetLocalIdAndMap(struct MapObject *, u8 *, u8 *, u8 *); +void FieldObjectGetLocalIdAndMap(struct MapObject *, void *, void *, void *); void sub_805BCC0(s16 x, s16 y); void sub_805BCF0(u8, u8, u8, u8); void sub_805BD48(u8, u8, u8); -- cgit v1.2.3 From b4c6e0560a7b1310cc08b93ea04935d4fbb7c3de Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 4 Nov 2017 22:42:28 -0400 Subject: BAD_MEM macros to MEM_ALT --- include/battle.h | 9 ++++++--- include/global.h | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/battle.h b/include/battle.h index 9adcaaf95..dc9ac93cc 100644 --- a/include/battle.h +++ b/include/battle.h @@ -694,15 +694,18 @@ extern u8 ewram[]; // functions that invoke this macro will not match without this egregeous // assumption about the variable names, so in order to avoid this assumption, // we opt to pass the variables themselves, even though it is likely that -// Sogabe assumed the variables were named src and dest. -#define BAD_MEMSET(data, c, size, var, dest) \ +// Sogabe assumed the variables were named src and dest. Trust me: I tried to +// avoid assuming variable names, but the ROM just will not match without the +// assumptions. Therefore, these macros are bad practice, but I'm putting them +// here anyway. +#define MEMSET_ALT(data, c, size, var, dest) \ { \ dest = (u8 *)data; \ for(var = 0; var < (u32)size; var++) \ dest[var] = c; \ } \ -#define BAD_MEMCPY(data, dest, size, var, src) \ +#define MEMCPY_ALT(data, dest, size, var, src) \ { \ src = (u8 *)data; \ for(var = 0; var < (u32)size; var++) \ diff --git a/include/global.h b/include/global.h index e0a1c6452..647f66bc8 100644 --- a/include/global.h +++ b/include/global.h @@ -63,13 +63,13 @@ enum // programming projects had more than 1 "programming team" which utilized different macros for // each of the files that were worked on. #define T1_READ_8(ptr) ((ptr)[0]) -#define T1_READ_16(ptr) ((ptr)[0] | ((ptr)[1] << 8)) // why do you use OR here but not for READ_32? +#define T1_READ_16(ptr) ((ptr)[0] | ((ptr)[1] << 8)) #define T1_READ_32(ptr) ((ptr)[0] | ((ptr)[1] << 8) | ((ptr)[2] << 16) | ((ptr)[3] << 24)) #define T1_READ_PTR(ptr) (u8*) T1_READ_32(ptr) // T2_READ_8 is a duplicate to remain consistent with each group. #define T2_READ_8(ptr) ((ptr)[0]) -#define T2_READ_16(ptr) ((ptr)[0] + ((ptr)[1] << 8)) // why do you use OR here but not for READ_32? +#define T2_READ_16(ptr) ((ptr)[0] + ((ptr)[1] << 8)) #define T2_READ_32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24)) #define T2_READ_PTR(ptr) (void*) T2_READ_32(ptr) -- cgit v1.2.3