mirror of
https://github.com/Ed94/pikuma_ps1.git
synced 2026-07-18 15:11:31 -07:00
99 lines
3.7 KiB
C
99 lines
3.7 KiB
C
#ifdef INTELLISENSE_DIRECTIVES
|
|
# include "duffle/lottes_tape.h"
|
|
# include "duffle/atom_dsl.h"
|
|
# include "hello_gte.h"
|
|
# include "tape_atom.metadata.h"
|
|
# include "gen/hello_gte_tape.offsets.h"
|
|
#endif
|
|
|
|
#pragma region MACs (Mips Atom components)
|
|
|
|
/* Words: 3; High: 0x20/B, Low: G/R */
|
|
#define mac_format_f3_color(color_hi, color_lo) \
|
|
load_ui(R_AT, color_hi), or_i(R_AT, R_AT, color_lo) \
|
|
, store_word(R_AT, R_PrimCursor, O_(Poly_F3,color)) \
|
|
|
|
/* Words: 3 */
|
|
#define mac_gte_store_f3() \
|
|
gte_sw(C2_SXY0, R_PrimCursor, O_(Poly_F3,p0)) \
|
|
, gte_sw(C2_SXY1, R_PrimCursor, O_(Poly_F3,p1)) \
|
|
, gte_sw(C2_SXY2, R_PrimCursor, O_(Poly_F3,p2))
|
|
|
|
#pragma endregion MACs
|
|
|
|
#pragma region Baked Atoms
|
|
|
|
atom_region( floor_tri, REGION_PRIM_ARENA)
|
|
atom_group( floor_tri, GROUP_RENDER_FLOOR)
|
|
atom_cadence(floor_tri, CADENCE_FRAME)
|
|
atom_annot( floor_tri, phase_work,
|
|
atom_reads( R_PrimCursor, R_FaceCursor, R_VertBase, R_OtBase),
|
|
atom_writes(R_PrimCursor, R_FaceCursor))
|
|
internal
|
|
MipsAtom_(floor_tri) {
|
|
// T0-T2 allocated
|
|
mac_load_tri_indices(R_T0, R_T1, R_T2),
|
|
// load_half_u(R_T0, R_FaceCur, 0 * S_(S2))
|
|
// , load_half_u(R_T1, R_FaceCur, 1 * S_(S2))
|
|
// , load_half_u(R_T2, R_FaceCur, 2 * S_(S2))
|
|
// ,
|
|
mac_load_tri_verts( R_T0, R_T1, R_T2),
|
|
// shift_ll(R_AT, R_T0, 3), add_u(R_AT, R_AT, R_VertBase), load_word(R_V0, R_AT, 0), load_word(R_V1, R_AT, 4), gte_mt(R_V0, C2_VXY0), gte_mt(R_V1, C2_VZ0)
|
|
// , shift_ll(R_AT, R_T1, 3), add_u(R_AT, R_AT, R_VertBase), load_word(R_V0, R_AT, 0), load_word(R_V1, R_AT, 4), gte_mt(R_V0, C2_VXY1), gte_mt(R_V1, C2_VZ1)
|
|
// , shift_ll(R_AT, R_T2, 3), add_u(R_AT, R_AT, R_VertBase), load_word(R_V0, R_AT, 0), load_word(R_V1, R_AT, 4), gte_mt(R_V0, C2_VXY2), gte_mt(R_V1, C2_VZ2)
|
|
// ,
|
|
|
|
/* 3. Execute Math */
|
|
nop, nop, gte_cmdw_rotate_translate_perspective_triple,
|
|
nop, nop, gte_cmdw_nclip,
|
|
nop, nop,
|
|
|
|
/* 4. Culling (Branch forward if Backface) */
|
|
gte_mf(R_T0, C2_MAC0),
|
|
nop, branch_le_zero(R_T0, atom_offset(culling, floor_tri_exit)),
|
|
nop,
|
|
|
|
/* 5. Format Primitive */
|
|
mac_format_f3_color(0x20FF, 0xFFFF),
|
|
mac_gte_store_f3(),
|
|
|
|
/* 6. Calculate Depth */
|
|
nop, nop, gte_avg_sort_z3,
|
|
nop, nop, gte_mf(R_T1, C2_OTZ),
|
|
|
|
/* 7. Bounds Check OTZ < 2048 (Branch forward to skip insertion) */
|
|
add_ui( R_AT, R_0, OrderingTbl_Len),
|
|
slt_u( R_AT, R_T1, R_AT),
|
|
branch_equal(R_AT, R_0, atom_offset(bounds_chk, floor_tri_exit)),
|
|
nop,
|
|
|
|
/* 8. Insert into Ordering Table Linked List */
|
|
mac_insert_ot_tag(R_T1, 0x0400),
|
|
add_ui_1(R_PrimCursor, S_(Poly_F3)), /* Advance Prim Cursor (5 words) */
|
|
// Note(Ed): No bounds checking, should be checked before atom runs.
|
|
|
|
/* 9. Advance Input Cursor & Yield (Both branch targets land here) */
|
|
atom_label(floor_tri_exit)
|
|
add_ui_1(R_FaceCursor, S_(S2) * 4), /* Advance Face Cursor (4 * S2 = 8 bytes) */
|
|
mac_yield()
|
|
};
|
|
|
|
typedef Struct_(Binds_SyncPrimitiveArena) { U4 PrimtiveArena_Used; U4 PrimtiveBase; };
|
|
atom_region( sync_primitive_arena, REGION_PRIM_ARENA)
|
|
atom_group( sync_primitive_arena, GROUP_RENDER_FLOOR)
|
|
atom_cadence(sync_primitive_arena, CADENCE_FRAME)
|
|
atom_annot( sync_primitive_arena, phase_work,
|
|
atom_reads( R_TapePtr, R_PrimCursor),
|
|
atom_writes(R_TapePtr))
|
|
internal MipsAtom_(sync_primitive_arena) {
|
|
load_word(R_AT, R_TapePtr, O_(Binds_SyncPrimitiveArena,PrimtiveArena_Used)),
|
|
load_word(R_T0, R_TapePtr, O_(Binds_SyncPrimitiveArena,PrimtiveBase)),
|
|
add_ui_1( R_TapePtr, S_(Binds_SyncPrimitiveArena)),
|
|
/* Calculate byte offset and store directly back to RAM */
|
|
sub_u( R_T0, R_PrimCursor, R_T0), // R_T0 = R_PrimCursor - prim-base
|
|
store_word(R_T0, R_AT, 0), // R_AT[0] = R_T0
|
|
mac_yield()
|
|
};
|
|
|
|
#pragma endregion Baked Atoms
|