mirror of
https://github.com/Ed94/pikuma_ps1.git
synced 2026-07-31 20:00:14 +00:00
need to finally make a metaprogram for offset math...
This commit is contained in:
+17
-16
@@ -14,11 +14,7 @@
|
||||
#include "duffle/gte.h"
|
||||
#include "duffle/lottes_tape.h"
|
||||
#include "hello_gte.h"
|
||||
|
||||
enum {
|
||||
PrimitiveBuff_Len = 4096,
|
||||
OrderingTbl_Len = 2048
|
||||
};
|
||||
#include "hello_gte_tape.c"
|
||||
|
||||
typedef U4 OrderingTable_Buffer[OrderingTbl_Len];
|
||||
typedef Array_(OrderingTable_Buffer, 2);
|
||||
@@ -104,6 +100,8 @@ typedef Struct_(SMemory) {
|
||||
|
||||
Ent_Cube cube;
|
||||
Ent_Floor floor;
|
||||
|
||||
|
||||
};
|
||||
global SMemory static_mem;
|
||||
extern SMemory static_mem;
|
||||
@@ -245,10 +243,10 @@ void update(PrimitiveArena* pa, U4* ordering_buf)
|
||||
LP_ U4 mem_temp_tape[512]; FArena tape_arena; farena_init(& tape_arena, slice_ut_arr(mem_temp_tape));
|
||||
TapeBuilder tb = tb_make(&tape_arena); tb_scope(& tb) {
|
||||
tb_emit(& tb, code_rbind_cube_tri);
|
||||
tb_data(& tb, prim_cursor);
|
||||
tb_data(& tb, u4_(static_mem.cube.faces));
|
||||
tb_data(& tb, u4_(static_mem.cube.verts));
|
||||
tb_data(& tb, u4_(ordering_buf));
|
||||
tb_data(& tb, prim_cursor);
|
||||
tb_data(& tb, u4_(static_mem.cube.faces));
|
||||
tb_data(& tb, u4_(static_mem.cube.verts));
|
||||
tb_data(& tb, u4_(ordering_buf));
|
||||
|
||||
for (U4 i = 0; i < Cube_num_faces; i++) {
|
||||
// Two triangles per quad face: (x,y,z) and (x,z,w)
|
||||
@@ -256,8 +254,8 @@ void update(PrimitiveArena* pa, U4* ordering_buf)
|
||||
}
|
||||
|
||||
tb_emit(& tb, code_sync_prim_cursor);
|
||||
tb_data(& tb, u4_(& pa->used));
|
||||
tb_data(& tb, prim_base);
|
||||
tb_data(& tb, u4_(& pa->used));
|
||||
tb_data(& tb, prim_base);
|
||||
}
|
||||
tape_run(tb_slice(tb));
|
||||
|
||||
@@ -334,21 +332,24 @@ void update(PrimitiveArena* pa, U4* ordering_buf)
|
||||
LP_ U4 mem_temp_tape[512]; FArena tape_arena; farena_init(& tape_arena, slice_ut_arr(mem_temp_tape));
|
||||
TapeBuilder tb = tb_make(&tape_arena); tb_scope(& tb) {
|
||||
// Push "Protocol" to tape
|
||||
tb_emit_(& tb, rbind_floor_tri);
|
||||
tb_emit(& tb, code_rbind_floor_tri);
|
||||
// Note(Ed): This is technically argument shuffle and would be better if we did a single reference at most to a global batch context.
|
||||
// Note(Ed): We can technically allocate a single ptr with the global offset to the working context instead of utilizing the tape for this stack of refs.
|
||||
tb_data(& tb, prim_cursor);
|
||||
tb_data(& tb, u4_(static_mem.floor.faces));
|
||||
tb_data(& tb, u4_(static_mem.floor.verts));
|
||||
tb_data(& tb, u4_(ordering_buf));
|
||||
|
||||
tb_emit(& tb, code_set_gte_world);
|
||||
tb_data(& tb, u4_(& static_mem.tform_world));
|
||||
|
||||
tb_data(& tb, u4_(& static_mem.tform_world));
|
||||
|
||||
for (U4 i = 0; i < Floor_num_faces; i++) {
|
||||
tb_emit(& tb, code_floor_tri);
|
||||
}
|
||||
|
||||
tb_emit(& tb, code_sync_prim_cursor);
|
||||
tb_data(& tb, u4_(& pa->used));
|
||||
tb_data(& tb, prim_base);
|
||||
tb_data(& tb, u4_(& pa->used));
|
||||
tb_data(& tb, prim_base);
|
||||
}
|
||||
|
||||
// Fire off the tape.
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
# include "duffle/gp.h"
|
||||
#endif
|
||||
|
||||
enum {
|
||||
PrimitiveBuff_Len = 4096,
|
||||
OrderingTbl_Len = 2048
|
||||
};
|
||||
|
||||
typedef Struct_(DrawEnv_Packed) { U4 tag; U4 code[15]; };
|
||||
typedef Struct_(DrawEnv) {
|
||||
Rect_S2 clip_area;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# include "duffle/lottes_tape.h"
|
||||
# include "hello_gte.h"
|
||||
#endif
|
||||
|
||||
#pragma region MACs
|
||||
|
||||
/* 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_PrimCur, O_(Poly_F3,color)) \
|
||||
|
||||
/* Words: 3 */
|
||||
#define mac_gte_store_f3() \
|
||||
gte_sw(C2_SXY0, R_PrimCur, O_(Poly_F3,p0)) \
|
||||
, gte_sw(C2_SXY1, R_PrimCur, O_(Poly_F3,p1)) \
|
||||
, gte_sw(C2_SXY2, R_PrimCur, O_(Poly_F3,p2))
|
||||
|
||||
#pragma endregion MACs
|
||||
|
||||
#pragma region Baked Atoms
|
||||
|
||||
internal MipsAtom_(floor_tri) {
|
||||
// T0-T2 allocated
|
||||
mac_load_tri_indices(R_T0, R_T1, R_T2),
|
||||
mac_load_tri_verts( R_T0, R_T1, R_T2),
|
||||
|
||||
/* 3. Execute Math */
|
||||
nop, nop, gte_cmdw_rotate_translate_perspective_triple,
|
||||
nop, nop, gte_cmdw_nclip,
|
||||
nop, nop,
|
||||
|
||||
/* 4. Culling (Branch forward 29 instructions if Backface) */
|
||||
gte_mf(R_T0, C2_MAC0),
|
||||
nop, branch_le_zero(R_T0, 29),
|
||||
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 13 instructions 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, 13),
|
||||
nop,
|
||||
|
||||
/* 8. Insert into Ordering Table Linked List */
|
||||
mac_insert_ot_tag(R_T1, 0x0400),
|
||||
add_ui(R_PrimCur, R_PrimCur, S_(Poly_F3)), /* Advance Prim Cursor (5 words) */
|
||||
|
||||
/* 9. Advance Input Cursor & Yield (Both branch targets land here) */
|
||||
add_ui(R_FaceCur, R_FaceCur, S_(S2) * 4), /* Advance Face Cursor (4 * S2 = 8 bytes) */
|
||||
mac_yield()
|
||||
};
|
||||
|
||||
#pragma endregion Baked Atoms
|
||||
Reference in New Issue
Block a user