From 77f19321cd8d4851efdfae9bc3d5c71bb4b6f6ae Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 12 Aug 2026 20:24:13 -0400 Subject: [PATCH] pain --- code/duffle/gen/macs.h | 27 ++++++++++++--------------- code/duffle/gte.atom.c | 27 ++++++++++++--------------- code/hello_camera/hello_camera.c | 5 ++++- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/code/duffle/gen/macs.h b/code/duffle/gen/macs.h index 2069ac4..0123d30 100644 --- a/code/duffle/gen/macs.h +++ b/code/duffle/gen/macs.h @@ -199,11 +199,14 @@ WORD_COUNT(mac_gte_gpf_scale, 13) , gte_lw(C2_VXY0, r_vec, 0) \ , load_word(r_t0, r_vec, 4) \ , nop \ -, gte_lw(C2_VZ0, r_vec, 4) /* RTPS cv=1 (no translation accumulation; BK is zero-initialized), sf=0, v=0, mx=0. +, gte_lw(C2_VZ0, r_vec, 4) /* RTPS cv=3 (no translation contribution: TRX/TRY/TRZ are zeroed, BK is zero-initialized), + * sf=1 (integer, no shift = full 32-bit R*pos product), v=0 (uses V0 input), mx=0 (rotation matrix). * MAC1 = RT11*V0.x + RT12*V0.y + RT13*V0.z + 0 * MAC2 = RT21*V0.x + RT22*V0.y + RT23*V0.z + 0 * MAC3 = RT31*V0.x + RT32*V0.y + RT33*V0.z + 0 - * Side effect: RTPS also writes SXY0/1/2 and SZ0..SZ3 (perspective projection). Ignored. */ /* gte_cmdw_rtps_no_tr, /* Read MAC1/2/3 → out. */ */ \ + * Side effect: RTPS also writes SXY0/1/2 and SZ0..SZ3 (perspective projection). Ignored. + * Note: gte_cmdw_rtps_no_tr (the cv=3 alias) was removed from gte.h. Use gte_cmdw_rtps_sf1. */ \ +, gte_cmdw_rtps_sf1 /* Read MAC1/2/3 → out. */ \ , gte_mv_from_data_r(r_t0, C2_MAC1) \ , gte_mv_from_data_r(r_t1, C2_MAC2) \ , gte_mv_from_data_r(r_t2, C2_MAC3) \ @@ -211,22 +214,16 @@ WORD_COUNT(mac_gte_gpf_scale, 13) , store_word(r_t0, r_out, 0) \ , store_word(r_t1, r_out, 4) \ , store_word(r_t2, r_out, 8) -WORD_COUNT(mac_apply_matrix_lv, 30) +WORD_COUNT(mac_apply_matrix_lv, 31) -#define mac_trans_matrix(r_mtx, r_off, r_t0, r_t1) \ - load_word(r_t0, r_mtx, O_(MT3_S2S4,t[0])) \ -, load_word(r_t1, r_off, O_(V3_S4,x)) \ -, add_u(r_t0, r_t0, r_t1) \ -, store_word(r_t0, r_mtx, O_(MT3_S2S4,t[0])) \ -, load_word(r_t0, r_mtx, O_(MT3_S2S4,t[1])) \ +#define mac_trans_matrix(r_mtx, r_off, r_t1) \ + load_word(r_t1, r_off, O_(V3_S4,x)) \ +, store_word(r_t1, r_mtx, O_(MT3_S2S4,t[0])) \ , load_word(r_t1, r_off, O_(V3_S4,y)) \ -, add_u(r_t0, r_t0, r_t1) \ -, store_word(r_t0, r_mtx, O_(MT3_S2S4,t[1])) \ -, load_word(r_t0, r_mtx, O_(MT3_S2S4,t[2])) \ +, store_word(r_t1, r_mtx, O_(MT3_S2S4,t[1])) \ , load_word(r_t1, r_off, O_(V3_S4,z)) \ -, add_u(r_t0, r_t0, r_t1) \ -, store_word(r_t0, r_mtx, O_(MT3_S2S4,t[2])) -WORD_COUNT(mac_trans_matrix, 12) +, store_word(r_t1, r_mtx, O_(MT3_S2S4,t[2])) +WORD_COUNT(mac_trans_matrix, 6) #define mac_gcmd_push(cmd, reg_transfer, reg_base, port) \ load_upper_i(reg_transfer, u4_hi(cmd)) \ diff --git a/code/duffle/gte.atom.c b/code/duffle/gte.atom.c index 9e3224a..c278b65 100644 --- a/code/duffle/gte.atom.c +++ b/code/duffle/gte.atom.c @@ -126,12 +126,14 @@ FI_ Slice_MipsCode ac_apply_matrix_lv(AtomBuilder_R ab load_word(r_t0, r_vec, 4), nop, gte_lw(C2_VZ0, r_vec, 4), - /* RTPS cv=1 (no translation accumulation; BK is zero-initialized), sf=0, v=0, mx=0. + /* RTPS cv=3 (no translation contribution: TRX/TRY/TRZ are zeroed, BK is zero-initialized), + * sf=1 (integer, no shift = full 32-bit R*pos product), v=0 (uses V0 input), mx=0 (rotation matrix). * MAC1 = RT11*V0.x + RT12*V0.y + RT13*V0.z + 0 * MAC2 = RT21*V0.x + RT22*V0.y + RT23*V0.z + 0 * MAC3 = RT31*V0.x + RT32*V0.y + RT33*V0.z + 0 - * Side effect: RTPS also writes SXY0/1/2 and SZ0..SZ3 (perspective projection). Ignored. */ - // gte_cmdw_rtps_no_tr, + * Side effect: RTPS also writes SXY0/1/2 and SZ0..SZ3 (perspective projection). Ignored. + * Note: gte_cmdw_rtps_no_tr (the cv=3 alias) was removed from gte.h. Use gte_cmdw_rtps_sf1. */ + gte_cmdw_rtps_sf1, /* Read MAC1/2/3 → out. */ gte_mv_from_data_r(r_t0, C2_MAC1), @@ -145,26 +147,21 @@ FI_ Slice_MipsCode ac_apply_matrix_lv(AtomBuilder_R ab /* ─── TRANS MATRIX (libgte TransMatrix port) ─── * Atom component — auto-generates mac_trans_matrix Mac composer macro. - * m->t += off. Uses 2 GPRs via per-axis load-delay-slot pattern. - * Words: 12. Clobbers: r_t0, r_t1. */ + * m->t = v (struct copy; libgte's TransMatrix at 0x8001a540 is just 3 store_words, no GTE, no add). + * Uses 1 GPR (r_t1 = off value) per axis; per-axis load-delay-slot pattern. + * Words: 9. Clobbers: r_t1. */ FI_ Slice_MipsCode ac_trans_matrix(AtomBuilder_R ab , U4 r_mtx, U4 r_off - , U4 r_t0, U4 r_t1 + , U4 r_t1 ) MipsAtomComp_Proc_(ac_trans_matrix, ab, { - load_word(r_t0, r_mtx, O_(MT3_S2S4,t[0])), load_word(r_t1, r_off, O_(V3_S4,x)), - add_u(r_t0, r_t0, r_t1), - store_word(r_t0, r_mtx, O_(MT3_S2S4,t[0])), + store_word(r_t1, r_mtx, O_(MT3_S2S4,t[0])), - load_word(r_t0, r_mtx, O_(MT3_S2S4,t[1])), load_word(r_t1, r_off, O_(V3_S4,y)), - add_u(r_t0, r_t0, r_t1), - store_word(r_t0, r_mtx, O_(MT3_S2S4,t[1])), + store_word(r_t1, r_mtx, O_(MT3_S2S4,t[1])), - load_word(r_t0, r_mtx, O_(MT3_S2S4,t[2])), load_word(r_t1, r_off, O_(V3_S4,z)), - add_u(r_t0, r_t0, r_t1), - store_word(r_t0, r_mtx, O_(MT3_S2S4,t[2])), + store_word(r_t1, r_mtx, O_(MT3_S2S4,t[2])), }) #pragma endregion MACs (Mips Atom Components) diff --git a/code/hello_camera/hello_camera.c b/code/hello_camera/hello_camera.c index 58552c1..002ea34 100644 --- a/code/hello_camera/hello_camera.c +++ b/code/hello_camera/hello_camera.c @@ -360,9 +360,12 @@ void update(PrimitiveArena* pa, U4* ordering_buf) uz = scratch->uz; right = scratch->right; ux = scratch->ux; + up = scratch->up; // ← atom 4's output (replaces C-side cross_v3s4) + uy = scratch->uy; // ← atom 5's output (replaces C-side normalize_v3s4) // cross_v3s4(& uz, & ux, & up); normalize_v3s4(& up, & uy); - + + // Atom 6 not yet enabled: populate look_at.m[][] from ux/uy/uz here. smem.cam.look_at.m[0][0] = ux.x; smem.cam.look_at.m[0][1] = ux.y; smem.cam.look_at.m[0][2] = ux.z; smem.cam.look_at.m[1][0] = uy.x; smem.cam.look_at.m[1][1] = uy.y; smem.cam.look_at.m[1][2] = uy.z; smem.cam.look_at.m[2][0] = uz.x; smem.cam.look_at.m[2][1] = uz.y; smem.cam.look_at.m[2][2] = uz.z;