From a1a192b1a2dba0ba6b7a4035f9e1ff0a89db6fc4 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Wed, 18 Sep 2024 21:40:59 +0200 Subject: [PATCH] [headers] z64inventory.h, move savectx/inventory macros to z64save.h (#2209) * [headers] z64inventory.h * move savectx/inventory macros to z64save.h * commit the file * bss --- include/functions.h | 4 +- include/macros.h | 68 ------------------- include/variables.h | 12 +--- include/z64.h | 1 + include/z64inventory.h | 26 ++++++++ include/z64save.h | 73 +++++++++++++++++++++ src/boot/z_std_dma.c | 2 +- src/code/graph.c | 2 +- src/code/main.c | 2 +- src/code/z_camera.c | 2 +- src/code/z_common_data.c | 2 +- src/overlays/actors/ovl_Fishing/z_fishing.c | 2 +- 12 files changed, 108 insertions(+), 88 deletions(-) create mode 100644 include/z64inventory.h diff --git a/include/functions.h b/include/functions.h index 903af90b6f..bd20666ea7 100644 --- a/include/functions.h +++ b/include/functions.h @@ -902,9 +902,7 @@ void Room_Draw(PlayState* play, Room* room, u32 flags); void Room_FinishRoomChange(PlayState* play, RoomContext* roomCtx); void Sample_Destroy(GameState* thisx); void Sample_Init(GameState* thisx); -void Inventory_ChangeEquipment(s16 equipment, u16 value); -u8 Inventory_DeleteEquipment(PlayState* play, s16 equipment); -void Inventory_ChangeUpgrade(s16 upgrade, s16 value); + void Object_InitContext(PlayState* play, ObjectContext* objectCtx); void Object_UpdateEntries(ObjectContext* objectCtx); s32 Object_GetSlot(ObjectContext* objectCtx, s16 objectId); diff --git a/include/macros.h b/include/macros.h index 10d328af65..f599adfd21 100644 --- a/include/macros.h +++ b/include/macros.h @@ -38,74 +38,6 @@ #define RGBA8(r, g, b, a) ((((r) & 0xFF) << 24) | (((g) & 0xFF) << 16) | (((b) & 0xFF) << 8) | (((a) & 0xFF) << 0)) -#define LINK_IS_ADULT (gSaveContext.save.linkAge == LINK_AGE_ADULT) -#define LINK_IS_CHILD (gSaveContext.save.linkAge == LINK_AGE_CHILD) - -#define YEARS_CHILD 5 -#define YEARS_ADULT 17 -#define LINK_AGE_IN_YEARS (!LINK_IS_ADULT ? YEARS_CHILD : YEARS_ADULT) - -#define CLOCK_TIME(hr, min) ((s32)(((hr) * 60 + (min)) * (f32)0x10000 / (24 * 60) + 0.5f)) - -#define IS_DAY (gSaveContext.save.nightFlag == 0) -#define IS_NIGHT (gSaveContext.save.nightFlag == 1) - -#define SLOT(item) gItemSlots[item] -#define INV_CONTENT(item) gSaveContext.save.info.inventory.items[SLOT(item)] -#define AMMO(item) gSaveContext.save.info.inventory.ammo[SLOT(item)] -#define BEANS_BOUGHT AMMO(ITEM_MAGIC_BEAN + 1) - -#define ALL_EQUIP_VALUE(equip) ((s32)(gSaveContext.save.info.inventory.equipment & gEquipMasks[equip]) >> gEquipShifts[equip]) -#define CUR_EQUIP_VALUE(equip) ((s32)(gSaveContext.save.info.equips.equipment & gEquipMasks[equip]) >> gEquipShifts[equip]) -#define OWNED_EQUIP_FLAG(equip, value) (gBitFlags[value] << gEquipShifts[equip]) -#define OWNED_EQUIP_FLAG_ALT(equip, value) ((1 << (value)) << gEquipShifts[equip]) -#define CHECK_OWNED_EQUIP(equip, value) (OWNED_EQUIP_FLAG(equip, value) & gSaveContext.save.info.inventory.equipment) -#define CHECK_OWNED_EQUIP_ALT(equip, value) (gBitFlags[(value) + (equip) * 4] & gSaveContext.save.info.inventory.equipment) - -#define SWORD_EQUIP_TO_PLAYER(swordEquip) (swordEquip) -#define SHIELD_EQUIP_TO_PLAYER(shieldEquip) (shieldEquip) -#define TUNIC_EQUIP_TO_PLAYER(tunicEquip) ((tunicEquip) - 1) -#define BOOTS_EQUIP_TO_PLAYER(bootsEquip) ((bootsEquip) - 1) - -#define CUR_UPG_VALUE(upg) ((s32)(gSaveContext.save.info.inventory.upgrades & gUpgradeMasks[upg]) >> gUpgradeShifts[upg]) -#define CAPACITY(upg, value) gUpgradeCapacities[upg][value] -#define CUR_CAPACITY(upg) CAPACITY(upg, CUR_UPG_VALUE(upg)) - -#define CHECK_QUEST_ITEM(item) (gBitFlags[item] & gSaveContext.save.info.inventory.questItems) -#define CHECK_DUNGEON_ITEM(item, dungeonIndex) (gSaveContext.save.info.inventory.dungeonItems[dungeonIndex] & gBitFlags[item]) - -#define GET_GS_FLAGS(index) \ - ((gSaveContext.save.info.gsFlags[(index) >> 2] & gGsFlagsMasks[(index) & 3]) >> gGsFlagsShifts[(index) & 3]) -#define SET_GS_FLAGS(index, value) \ - (gSaveContext.save.info.gsFlags[(index) >> 2] |= (value) << gGsFlagsShifts[(index) & 3]) - -#define HIGH_SCORE(score) (gSaveContext.save.info.highScores[score]) - -#define GET_EVENTCHKINF(flag) (gSaveContext.save.info.eventChkInf[(flag) >> 4] & (1 << ((flag) & 0xF))) -#define SET_EVENTCHKINF(flag) (gSaveContext.save.info.eventChkInf[(flag) >> 4] |= (1 << ((flag) & 0xF))) -#define CLEAR_EVENTCHKINF(flag) (gSaveContext.save.info.eventChkInf[(flag) >> 4] &= ~(1 << ((flag) & 0xF))) - -#define GET_ITEMGETINF(flag) (gSaveContext.save.info.itemGetInf[(flag) >> 4] & (1 << ((flag) & 0xF))) -#define SET_ITEMGETINF(flag) (gSaveContext.save.info.itemGetInf[(flag) >> 4] |= (1 << ((flag) & 0xF))) - -#define GET_INFTABLE(flag) (gSaveContext.save.info.infTable[(flag) >> 4] & (1 << ((flag) & 0xF))) -#define SET_INFTABLE(flag) (gSaveContext.save.info.infTable[(flag) >> 4] |= (1 << ((flag) & 0xF))) -#define CLEAR_INFTABLE(flag) (gSaveContext.save.info.infTable[(flag) >> 4] &= ~(1 << ((flag) & 0xF))) - -#define GET_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] & (1 << ((flag) & 0xF))) -#define SET_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] |= (1 << ((flag) & 0xF))) -#define CLEAR_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] &= ~(1 << ((flag) & 0xF))) - -#define B_BTN_ITEM ((gSaveContext.buttonStatus[0] == ITEM_NONE) \ - ? ITEM_NONE \ - : (gSaveContext.save.info.equips.buttonItems[0] == ITEM_GIANTS_KNIFE) \ - ? ITEM_SWORD_BIGGORON \ - : gSaveContext.save.info.equips.buttonItems[0]) - -#define C_BTN_ITEM(button) ((gSaveContext.buttonStatus[(button) + 1] != BTN_DISABLED) \ - ? gSaveContext.save.info.equips.buttonItems[(button) + 1] \ - : ITEM_NONE) - #define CHECK_FLAG_ALL(flags, mask) (((flags) & (mask)) == (mask)) // IDO doesn't support variadic macros, but it merely throws a warning for the diff --git a/include/variables.h b/include/variables.h index 2f96222d58..f4e15f7362 100644 --- a/include/variables.h +++ b/include/variables.h @@ -73,17 +73,7 @@ extern Gfx* gPlayerLeftHandBoomerangDLs[]; extern Gfx gCullBackDList[]; extern Gfx gCullFrontDList[]; extern Gfx gEmptyDL[]; -extern u32 gBitFlags[32]; -extern u16 gEquipMasks[EQUIP_TYPE_MAX]; -extern u16 gEquipNegMasks[EQUIP_TYPE_MAX]; -extern u32 gUpgradeMasks[UPG_MAX]; -extern u8 gEquipShifts[EQUIP_TYPE_MAX]; -extern u8 gUpgradeShifts[UPG_MAX]; -extern u16 gUpgradeCapacities[UPG_MAX][4]; -extern u32 gGsFlagsMasks[4]; -extern u32 gGsFlagsShifts[4]; -extern void* gItemIcons[0x82]; -extern u8 gItemSlots[56]; + extern SceneCmdHandlerFunc gSceneCmdHandlers[SCENE_CMD_ID_MAX]; extern s16 gLinkObjectIds[2]; extern u32 gObjectTableSize; diff --git a/include/z64.h b/include/z64.h index 2d36ccd436..c7a0a1ea2b 100644 --- a/include/z64.h +++ b/include/z64.h @@ -23,6 +23,7 @@ #include "z64scene.h" #include "z64effect.h" #include "z64game_over.h" +#include "z64inventory.h" #include "z64item.h" #include "z64animation.h" #include "z64animation_legacy.h" diff --git a/include/z64inventory.h b/include/z64inventory.h new file mode 100644 index 0000000000..9a8133b3da --- /dev/null +++ b/include/z64inventory.h @@ -0,0 +1,26 @@ +#ifndef Z64INVENTORY_H +#define Z64INVENTORY_H + +#include "ultra64.h" +#include "z64item.h" +#include "z64save.h" + +struct PlayState; + +void Inventory_ChangeEquipment(s16 equipment, u16 value); +u8 Inventory_DeleteEquipment(struct PlayState* play, s16 equipment); +void Inventory_ChangeUpgrade(s16 upgrade, s16 value); + +extern u32 gBitFlags[32]; +extern u16 gEquipMasks[EQUIP_TYPE_MAX]; +extern u16 gEquipNegMasks[EQUIP_TYPE_MAX]; +extern u32 gUpgradeMasks[UPG_MAX]; +extern u8 gEquipShifts[EQUIP_TYPE_MAX]; +extern u8 gUpgradeShifts[UPG_MAX]; +extern u16 gUpgradeCapacities[UPG_MAX][4]; +extern u32 gGsFlagsMasks[4]; +extern u32 gGsFlagsShifts[4]; +extern void* gItemIcons[0x82]; +extern u8 gItemSlots[56]; + +#endif diff --git a/include/z64save.h b/include/z64save.h index 4b7513e53a..2c10d76bc6 100644 --- a/include/z64save.h +++ b/include/z64save.h @@ -3,6 +3,7 @@ #include "ultra64.h" #include "versions.h" +#include "z64inventory.h" #include "z64math.h" typedef enum Language { @@ -398,6 +399,59 @@ typedef enum LinkAge { } LinkAge; +#define LINK_IS_ADULT (gSaveContext.save.linkAge == LINK_AGE_ADULT) +#define LINK_IS_CHILD (gSaveContext.save.linkAge == LINK_AGE_CHILD) + +#define YEARS_CHILD 5 +#define YEARS_ADULT 17 +#define LINK_AGE_IN_YEARS (!LINK_IS_ADULT ? YEARS_CHILD : YEARS_ADULT) + +#define CLOCK_TIME(hr, min) ((s32)(((hr) * 60 + (min)) * (f32)0x10000 / (24 * 60) + 0.5f)) + +#define IS_DAY (gSaveContext.save.nightFlag == 0) +#define IS_NIGHT (gSaveContext.save.nightFlag == 1) + +#define SLOT(item) gItemSlots[item] +#define INV_CONTENT(item) gSaveContext.save.info.inventory.items[SLOT(item)] +#define AMMO(item) gSaveContext.save.info.inventory.ammo[SLOT(item)] +#define BEANS_BOUGHT AMMO(ITEM_MAGIC_BEAN + 1) + +#define ALL_EQUIP_VALUE(equip) ((s32)(gSaveContext.save.info.inventory.equipment & gEquipMasks[equip]) >> gEquipShifts[equip]) +#define CUR_EQUIP_VALUE(equip) ((s32)(gSaveContext.save.info.equips.equipment & gEquipMasks[equip]) >> gEquipShifts[equip]) +#define OWNED_EQUIP_FLAG(equip, value) (gBitFlags[value] << gEquipShifts[equip]) +#define OWNED_EQUIP_FLAG_ALT(equip, value) ((1 << (value)) << gEquipShifts[equip]) +#define CHECK_OWNED_EQUIP(equip, value) (OWNED_EQUIP_FLAG(equip, value) & gSaveContext.save.info.inventory.equipment) +#define CHECK_OWNED_EQUIP_ALT(equip, value) (gBitFlags[(value) + (equip) * 4] & gSaveContext.save.info.inventory.equipment) + +#define SWORD_EQUIP_TO_PLAYER(swordEquip) (swordEquip) +#define SHIELD_EQUIP_TO_PLAYER(shieldEquip) (shieldEquip) +#define TUNIC_EQUIP_TO_PLAYER(tunicEquip) ((tunicEquip) - 1) +#define BOOTS_EQUIP_TO_PLAYER(bootsEquip) ((bootsEquip) - 1) + +#define CUR_UPG_VALUE(upg) ((s32)(gSaveContext.save.info.inventory.upgrades & gUpgradeMasks[upg]) >> gUpgradeShifts[upg]) +#define CAPACITY(upg, value) gUpgradeCapacities[upg][value] +#define CUR_CAPACITY(upg) CAPACITY(upg, CUR_UPG_VALUE(upg)) + +#define CHECK_QUEST_ITEM(item) (gBitFlags[item] & gSaveContext.save.info.inventory.questItems) +#define CHECK_DUNGEON_ITEM(item, dungeonIndex) (gSaveContext.save.info.inventory.dungeonItems[dungeonIndex] & gBitFlags[item]) + +#define GET_GS_FLAGS(index) \ + ((gSaveContext.save.info.gsFlags[(index) >> 2] & gGsFlagsMasks[(index) & 3]) >> gGsFlagsShifts[(index) & 3]) +#define SET_GS_FLAGS(index, value) \ + (gSaveContext.save.info.gsFlags[(index) >> 2] |= (value) << gGsFlagsShifts[(index) & 3]) + +#define HIGH_SCORE(score) (gSaveContext.save.info.highScores[score]) + +#define B_BTN_ITEM ((gSaveContext.buttonStatus[0] == ITEM_NONE) \ + ? ITEM_NONE \ + : (gSaveContext.save.info.equips.buttonItems[0] == ITEM_GIANTS_KNIFE) \ + ? ITEM_SWORD_BIGGORON \ + : gSaveContext.save.info.equips.buttonItems[0]) + +#define C_BTN_ITEM(button) ((gSaveContext.buttonStatus[(button) + 1] != BTN_DISABLED) \ + ? gSaveContext.save.info.equips.buttonItems[(button) + 1] \ + : ITEM_NONE) + /* * @@ -599,6 +653,11 @@ typedef enum LinkAge { #define EVENTCHKINF_DE_MASK (1 << 14) +#define GET_EVENTCHKINF(flag) (gSaveContext.save.info.eventChkInf[(flag) >> 4] & (1 << ((flag) & 0xF))) +#define SET_EVENTCHKINF(flag) (gSaveContext.save.info.eventChkInf[(flag) >> 4] |= (1 << ((flag) & 0xF))) +#define CLEAR_EVENTCHKINF(flag) (gSaveContext.save.info.eventChkInf[(flag) >> 4] &= ~(1 << ((flag) & 0xF))) + + /* * SaveContext.itemGetInf */ @@ -658,6 +717,10 @@ typedef enum LinkAge { #define ITEMGETINF_3F 0x3F +#define GET_ITEMGETINF(flag) (gSaveContext.save.info.itemGetInf[(flag) >> 4] & (1 << ((flag) & 0xF))) +#define SET_ITEMGETINF(flag) (gSaveContext.save.info.itemGetInf[(flag) >> 4] |= (1 << ((flag) & 0xF))) + + /* * SaveContext.infTable */ @@ -818,6 +881,11 @@ typedef enum LinkAge { #define INFTABLE_1DX_INDEX 29 +#define GET_INFTABLE(flag) (gSaveContext.save.info.infTable[(flag) >> 4] & (1 << ((flag) & 0xF))) +#define SET_INFTABLE(flag) (gSaveContext.save.info.infTable[(flag) >> 4] |= (1 << ((flag) & 0xF))) +#define CLEAR_INFTABLE(flag) (gSaveContext.save.info.infTable[(flag) >> 4] &= ~(1 << ((flag) & 0xF))) + + /* * SaveContext.eventInf */ @@ -892,6 +960,11 @@ typedef enum EventInfHorsesState { #define EVENTINF_30 0x30 +#define GET_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] & (1 << ((flag) & 0xF))) +#define SET_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] |= (1 << ((flag) & 0xF))) +#define CLEAR_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] &= ~(1 << ((flag) & 0xF))) + + extern SaveContext gSaveContext; #endif diff --git a/src/boot/z_std_dma.c b/src/boot/z_std_dma.c index c3e97aa190..7a8488a8c0 100644 --- a/src/boot/z_std_dma.c +++ b/src/boot/z_std_dma.c @@ -27,7 +27,7 @@ #endif #pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \ - "ntsc-1.2:111" + "ntsc-1.2:110" StackEntry sDmaMgrStackInfo; OSMesgQueue sDmaMgrMsgQueue; diff --git a/src/code/graph.c b/src/code/graph.c index 7c562f160b..95affaf823 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -6,7 +6,7 @@ #define GFXPOOL_TAIL_MAGIC 0x5678 #pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \ - "ntsc-1.2:223" + "ntsc-1.2:192" /** * The time at which the previous `Graph_Update` ended. diff --git a/src/code/main.c b/src/code/main.c index 8024db9412..5c3985b42e 100644 --- a/src/code/main.c +++ b/src/code/main.c @@ -23,7 +23,7 @@ extern struct IrqMgr gIrqMgr; #endif #pragma increment_block_number "gc-eu:192 gc-eu-mq:192 gc-jp:192 gc-jp-ce:192 gc-jp-mq:192 gc-us:192 gc-us-mq:192" \ - "ntsc-1.2:168" + "ntsc-1.2:167" extern u8 _buffersSegmentEnd[]; diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 50485d3bc7..be7cc4d272 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -3638,7 +3638,7 @@ s32 Camera_KeepOn3(Camera* camera) { } #pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \ - "ntsc-1.2:112" + "ntsc-1.2:111" s32 Camera_KeepOn4(Camera* camera) { static Vec3f D_8015BD50; diff --git a/src/code/z_common_data.c b/src/code/z_common_data.c index dcd0ee4d2e..1c70bfb0f4 100644 --- a/src/code/z_common_data.c +++ b/src/code/z_common_data.c @@ -3,7 +3,7 @@ #include "versions.h" #pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \ - "ntsc-1.2:192" + "ntsc-1.2:224" ALIGNED(16) SaveContext gSaveContext; u32 D_8015FA88; diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index 118db21d6e..b0062297e5 100644 --- a/src/overlays/actors/ovl_Fishing/z_fishing.c +++ b/src/overlays/actors/ovl_Fishing/z_fishing.c @@ -16,7 +16,7 @@ #include "cic6105.h" #endif -#pragma increment_block_number "gc-eu:133 gc-eu-mq:133 gc-jp:135 gc-jp-ce:135 gc-jp-mq:135 gc-us:135 gc-us-mq:135" +#pragma increment_block_number "gc-eu:132 gc-eu-mq:132 gc-jp:134 gc-jp-ce:134 gc-jp-mq:134 gc-us:134 gc-us-mq:134" #define FLAGS ACTOR_FLAG_4