Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,38 @@ PSYQ40_MASPSXFLAGS := --aspsx-version=2.56 # used by O0_SRCS
PSYQ41_MASPSXFLAGS := --aspsx-version=2.67 # default for PsyQ 4.1 sources
PSYQ43_MASPSXFLAGS := --aspsx-version=2.77 # used by PSYQ43_SRCS

# ASPSX expands an integer division into `div` plus the range checks that break
# on a zero divisor and on INT_MIN / -1 -- nine instructions the original build
# selected per assembler invocation, so it is a property of the OBJECT.
#
# Counted over the shipped code: every effect overlay is uniform, 198 expanding
# and 70 not, so those are keyed by binary. Every other overlay is bare.
# SLUS_008.92 is the one binary whose own objects disagree, 45 expanded against
# 9 bare, so its sources take the override below rather than a binary-wide rule.
#
# Do not key the effect overlays on filenames: the same engine source will be
# linked into overlays from both sets, and ten functions already ship both ways.
NO_EXPAND_DIV := effect_011 effect_012 effect_017 effect_044 effect_063 effect_064 \
effect_065 effect_069 effect_070 effect_089 effect_102 effect_105 \
effect_107 effect_108 effect_110 effect_112 effect_113 effect_116 \
effect_117 effect_118 effect_123 effect_124 effect_126 effect_128 \
effect_129 effect_131 effect_132 effect_134 effect_135 effect_136 \
effect_138 effect_139 effect_140 effect_207 effect_210 effect_212 \
effect_213 effect_214 effect_216 effect_226 effect_227 effect_251 \
effect_260 effect_275 effect_276 effect_277 effect_278 effect_279 \
effect_280 effect_283 effect_284 effect_285 effect_287 effect_290 \
effect_291 effect_297 effect_298 effect_300 effect_302 effect_304 \
effect_308 effect_311 effect_314 effect_316 effect_317 effect_320 \
effect_322 effect_323 effect_325 effect_338

# Sources whose object expands inside a binary that otherwise does not. Only
# SLUS_008.92 mixes, so only its sources belong here.
EXPAND_DIV_SRCS :=

# $(call expand_div,<binary>,<source>): the source override wins, else effect
# overlays expand unless listed above, and nothing else expands.
expand_div = $(if $(filter $(2),$(EXPAND_DIV_SRCS)),--expand-div,$(if $(filter effect_%,$(1)),$(if $(filter $(1),$(NO_EXPAND_DIV)),,--expand-div)))

# Source files compiled with PsyQ 4.3 (default is PsyQ 4.1)
PSYQ43_SRCS := src/snd_init.c src/snd_dma.c src/snd_voice.c src/snd_bank.c src/snd_param.c src/snd_note.c src/snd_track.c src/snd_cmd.c \
src/world/we_object0.c \
Expand Down Expand Up @@ -108,7 +140,7 @@ CODE_OVERLAYS := field_init intro field \
tripletriad battle_render battle world

ALL_EFFECT_OVERLAYS := $(filter effect_%,$(SPLAT_BINARIES))
EFFECTS ?= effect_001
EFFECTS ?= effect_001 effect_025
EFFECT_OVERLAYS := $(if $(filter all,$(EFFECTS)),$(ALL_EFFECT_OVERLAYS),$(EFFECTS))
OVERLAYS := $(MENU_OVERLAYS) $(CODE_OVERLAYS) $(EFFECT_OVERLAYS)
ALL_OVERLAYS := $(MENU_OVERLAYS) $(CODE_OVERLAYS) $(ALL_EFFECT_OVERLAYS)
Expand Down Expand Up @@ -242,9 +274,9 @@ $$($(1)_DIR)/%.o: %.c
$$(CPP) -E -lang-c -nostdinc -Iinclude $$< -o $$($(1)_DIR)/$$(*F).i && \
$$(if $$(filter $$<,$$(PSYQ43_SRCS)), \
$$(PSYQ43_CC1) -quiet $$(CC_FLAGS) $$($(1)_DIR)/$$(*F).i -o $$($(1)_DIR)/$$(*F).s && \
cat $$($(1)_DIR)/$$(*F).s | $$(MASPSX) $$(PSYQ43_MASPSXFLAGS) --run-assembler $$(ASFLAGS) -o $$@, \
cat $$($(1)_DIR)/$$(*F).s | $$(MASPSX) $$(PSYQ43_MASPSXFLAGS) $$(call expand_div,$(1),$$<) --run-assembler $$(ASFLAGS) -o $$@, \
$$(PSYQ41_CC1) -quiet $$(CC_FLAGS) $$($(1)_DIR)/$$(*F).i -o $$($(1)_DIR)/$$(*F).s && \
cat $$($(1)_DIR)/$$(*F).s | $$(MASPSX) $$(PSYQ41_MASPSXFLAGS) --run-assembler $$(ASFLAGS) -o $$@)
cat $$($(1)_DIR)/$$(*F).s | $$(MASPSX) $$(PSYQ41_MASPSXFLAGS) $$(call expand_div,$(1),$$<) --run-assembler $$(ASFLAGS) -o $$@)

$$($(1)_DIR)/assets/%.o: assets/%.bin
@mkdir -p $$(dir $$@)
Expand Down
1 change: 1 addition & 0 deletions config/symbols.extern.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SquareRoot0 = 0x8003F4A4;
VectorNormalS = 0x8003F5C0;
VectorNormal = 0x8003F5D4;
SquareRoot12 = 0x8003FA74;
MulMatrix0 = 0x8003FB14;
CompMatrix = 0x8003FC24;
ApplyMatrixLV = 0x8003FD84;
ApplyMatrixSV = 0x800404D4;
Expand Down
33 changes: 33 additions & 0 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,39 @@ typedef struct {
/** @brief Per-entity battle records the effect overlays pose their models from. */
extern BattleEffectSlot D_800EF2D0[];

/**
* @brief One of the four screen-tint entries battle steps every frame.
*
* @c level rises and falls under an effect's control; the three colour bytes
* are also written together as one word.
*/
typedef struct {
/* 0x00 */ u16 unk000;
/* 0x02 */ u16 level;
/* 0x04 */ u8 pad004[0x28 - 0x4];
/* 0x28 */ u8 r;
/* 0x29 */ u8 g;
/* 0x2A */ u8 b;
/* 0x2B */ u8 pad02B[0x2C - 0x2B];
} BattleTint; /* 0x2C */

extern BattleTint D_800EF738[];

/**
* @name Battle state flags -- @ref D_800EEC5C
*
* One word the battle loop and its effects both test. The names are
* placeholders; only the bit positions are established.
* @{
*/
#define BATTLE_STATE_UNK001 0x1
#define BATTLE_STATE_UNK100 0x100
#define BATTLE_STATE_UNK200 0x200
/** @} */

/** @brief State the battle loop and its effects share; see the flags above. */
extern s32 D_800EEC5C;

/** @brief Angle every sprite prim is rolled by unless it opts out. */
extern s16 D_800F02A0;

Expand Down
130 changes: 128 additions & 2 deletions include/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "battle/bc_object11.h"
#include "battle/bc_object12.h"
#include "battle/bc_object13.h"
#include "battle/bc_object15.h"

/**
* @file
Expand All @@ -29,6 +28,7 @@
/** @brief @ref EffectEntity::flags -- the script's counter reached its limit. */
#define EFFECT_FLAG_DONE 0x4
#define EFFECT_FLAG_UNK08 0x8
#define EFFECT_FLAG_UNK10 0x10
/**
* @brief @ref EffectAnimSet::flags -- the effect's own assets are already up.
*
Expand Down Expand Up @@ -266,7 +266,18 @@ typedef struct EffectEntity {
/* 0x63 */ u8 unk063;
/* 0x64 */ u8 pad064[0x68 - 0x64];
/* 0x68 */ s16 unk068;
/* 0x6A */ u8 pad06A[0x100 - 0x6A];
/* 0x6A */ u8 pad06A[0x6C - 0x6A];
/* 0x6C */ s16 unk06C;
/* 0x6E */ u8 pad06E[0x70 - 0x6E];
/* 0x70 */ BattleSpriteAnim *unk070;
/* 0x74 */ u8 pad074[0x78 - 0x74];
/* 0x78 */ s16 unk078;
/* 0x7A */ s16 unk07A;
/* 0x7C */ s16 unk07C;
/* 0x7E */ s16 unk07E;
/* 0x80 */ u8 pad080[0xC4 - 0x80];
/* 0xC4 */ s16 unk0C4;
/* 0xC6 */ u8 pad0C6[0x100 - 0xC6];
} EffectEntity; /* >= 0x100 */

/** @brief One step of an effect script: the handler for a single @c pc value. */
Expand All @@ -292,4 +303,119 @@ typedef void (*EffectHandler)(EffectEntity *);

/** @} */

/**
* @name Engine scratch
*
* Types every effect overlay's copy of the engine shares: the scratchpad
* records the transform helpers work in, and the mesh stream they draw.
* @{
*/
/** @brief Scratch a model's bounding box is accumulated in. */
typedef struct {
/* 0x00 */ SVECTOR v;
/* 0x08 */ VECTOR pos;
/* 0x18 */ SVECTOR min;
/* 0x20 */ SVECTOR max;
/* 0x28 */ s32 flag;
} EffectBoundsScratch; /* 0x2C */

/** @brief Scratch the billboard basis is built in. */
typedef struct {
/* 0x00 */ VECTOR delta;
/* 0x10 */ SVECTOR up;
/* 0x18 */ SVECTOR dir;
/* 0x20 */ MATRIX rot;
/* 0x40 */ MATRIX out;
/* 0x60 */ s32 distSq;
/* 0x64 */ s32 dist;
/* 0x68 */ SVECTOR pos;
} EffectAimScratch; /* 0x70 */

/** @brief Scratch a rotation is built in before being folded into a matrix. */
typedef struct {
/* 0x00 */ MATRIX m;
/* 0x20 */ s16 sin;
/* 0x22 */ s16 cos;
} EffectRotScratch; /* 0x24 */

/** @brief One posed mesh vertex; only the position is written here. */
typedef struct EffectMeshVertex {
/* 0x00 */ u8 pad000[0x4];
/* 0x04 */ SVECTOR pos;
/* 0x0C */ u8 pad00C[0x10 - 0xC];
} EffectMeshVertex; /* 0x10 */

/** @brief One triangle of a mesh part: three 12-bit vertex indices and UVs. */
typedef struct {
/* 0x00 */ u16 idx0;
/* 0x02 */ u16 idx1;
/* 0x04 */ u16 idx2;
/* 0x06 */ u16 uv2;
/* 0x08 */ u32 uv0;
/* 0x0C */ u16 uv1;
/* 0x0E */ u16 tpage; /**< Bit 0x200 selects the semi-transparent blend. */
} EffectMeshTri; /* 0x10 */

/** @brief One quad of a mesh part. */
typedef struct {
/* 0x00 */ u16 idx0;
/* 0x02 */ u16 idx1;
/* 0x04 */ u16 idx2;
/* 0x06 */ u16 idx3;
/* 0x08 */ u32 uv0;
/* 0x0C */ u16 uv1;
/* 0x0E */ u16 tpage;
/* 0x10 */ u16 uv2;
/* 0x12 */ u16 uv3;
} EffectMeshQuad; /* 0x14 */

/** @brief Vertex indices in a mesh part are 12 bits wide. */
#define EFFECT_MESH_INDEX_MASK 0xFFF
/** @brief @ref EffectMeshTri::tpage -- draw the textured prim semi-transparent. */
#define EFFECT_MESH_TPAGE_ABE 0x200
/** @brief Screen centre the clip rect and the projected points are offset by. */
#define EFFECT_SCREEN_CX 0xA0
/** @brief @copybrief EFFECT_SCREEN_CX */
#define EFFECT_SCREEN_CY 0x78
/** @brief A prim's tag word with no link: its length in words. */
#define EFFECT_PRIM_TAG(type) (((sizeof(type) - sizeof(u32)) / sizeof(u32)) << 24)
/** @brief A libgpu prim code in the top byte of an RGB word. */
#define EFFECT_PRIM_CODE(code) ((u32)(code) << 24)
/** @brief The 24 colour bits of that word, with the code byte taken off. */
#define EFFECT_PRIM_RGB 0xFFFFFF

/** @brief Scratch @ref func_801A1EBC works a mesh in; taken from the battle scratchpad. */
typedef struct {
/* 0x00 */ MATRIX view;
/* 0x20 */ MATRIX light;
/* 0x40 */ DVECTOR sxy[4]; /**< Projected vertices, offset into the clip rect. */
/* 0x50 */ u8 pad050[0x70 - 0x50];
/* 0x70 */ SVECTOR normal;
/* 0x78 */ u8 pad078[0x8C - 0x78];
/* 0x8C */ s32 nclip;
/* 0x90 */ s32 otz;
/* 0x94 */ s32 idx0;
/* 0x98 */ s32 idx1;
/* 0x9C */ s32 idx2;
/* 0xA0 */ s32 idx3;
/* 0xA4 */ u16 unk0A4;
/* 0xA6 */ u16 unk0A6;
/* 0xA8 */ u32 colour; /**< Shaded triangle RGB + code word. */
/* 0xAC */ u32 unk0AC; /**< Shaded quad RGB + code word. */
/* 0xB0 */ u32 unk0B0; /**< Textured triangle RGB + code word. */
/* 0xB4 */ u32 unk0B4; /**< Textured quad RGB + code word. */
/* 0xB8 */ u32 visible; /**< Copy of the slot's part mask. */
/* 0xBC */ u16 tpage;
/* 0xBE */ u16 clut;
/* 0xC0 */ s16 clipX0;
/* 0xC2 */ s16 clipX1;
/* 0xC4 */ s16 clipY0;
/* 0xC6 */ s16 clipY1;
/* 0xC8 */ s16 offX;
/* 0xCA */ s16 offY;
/* 0xCC */ s16 reject; /**< Set once a primitive fails the cull or clip test. */
/* 0xCE */ s16 unk0CE; /**< Copy of @ref EffectRender::unk0F4. */
} EffectMeshScratch; /* 0xD0 */
/** @} */

#endif /* EFFECT_H */
Loading
Loading