From b045856dd6fd84add6968bcd1a201755049698f4 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 8 Aug 2026 18:23:28 -0400 Subject: [PATCH] converted pad input for cam to mips atom --- code/hello_camera/gen/offsets.h | 18 +++++++++ code/hello_camera/hello_camera.atom.c | 54 ++++++++++++++++++++++++--- code/hello_camera/hello_camera.c | 41 ++++++++++---------- 3 files changed, 87 insertions(+), 26 deletions(-) diff --git a/code/hello_camera/gen/offsets.h b/code/hello_camera/gen/offsets.h index 7daa1ea..4b3fdc2 100644 --- a/code/hello_camera/gen/offsets.h +++ b/code/hello_camera/gen/offsets.h @@ -26,6 +26,24 @@ enum { atom_offset_end_low_exit_stick = _atom_offset_end_low_exit_stick, }; +// --- atom: pad_input_cam (41 words) --- + +#define _atom_offset_left_x_exit_left_x 3 +#define _atom_offset_right_x_exit_right_x 3 +#define _atom_offset_up_y_exit_up_y 3 +#define _atom_offset_down_y_exit_down_y 3 +#define _atom_offset_cross_z_exit_cross_z 3 +#define _atom_offset_circle_z_exit_circle_z 3 + +enum { + atom_offset_left_x_exit_left_x = _atom_offset_left_x_exit_left_x, + atom_offset_right_x_exit_right_x = _atom_offset_right_x_exit_right_x, + atom_offset_up_y_exit_up_y = _atom_offset_up_y_exit_up_y, + atom_offset_down_y_exit_down_y = _atom_offset_down_y_exit_down_y, + atom_offset_cross_z_exit_cross_z = _atom_offset_cross_z_exit_cross_z, + atom_offset_circle_z_exit_circle_z = _atom_offset_circle_z_exit_circle_z, +}; + // --- atom: cube_g4_face (76 words) --- #define _atom_offset_cull_cube_g4_face_exit 41 diff --git a/code/hello_camera/hello_camera.atom.c b/code/hello_camera/hello_camera.atom.c index bbd7e14..f03df45 100644 --- a/code/hello_camera/hello_camera.atom.c +++ b/code/hello_camera/hello_camera.atom.c @@ -313,15 +313,57 @@ atom_label(exit_stick) }; enum { - R_Cam = R_T4 atom_reg, + R_Cam = R_T4 atom_reg, + R_CamPadState = R_T5 atom_reg, }; typedef Struct_(Binds_PadInputCam) { - Camera* cam; + PadState* state; + Camera* cam; }; -internal MipsAtom_(pad_input_cam) atom_info(atom_bind(Binds_PadInputCam)) { - load_word(R_Cam, R_TapePtr, O_(Binds_PadInputCam,cam)), - add_ui_self( R_TapePtr, S_(Binds_PadInputCam)), - // TODO(Ed): Implement. +internal MipsAtom_(pad_input_cam) atom_info(atom_bind(Binds_PadInputCam) +, atom_reads( R_Cam, R_CamPadState, R_TapePtr) +, atom_writes(R_Cam) +) { + /* Bind pop: state → R_CamPadState (R_T5), cam → R_Cam (R_T4), advance R_TapePtr by 8. */ + load_word(R_CamPadState, R_TapePtr, O_(Binds_PadInputCam,state)), + load_word(R_Cam, R_TapePtr, O_(Binds_PadInputCam,cam)), + add_ui_self( R_TapePtr, S_(Binds_PadInputCam)), + + /* Load pad[0].buttons into R_T0; nop fills the load-delay slot. */ + load_word(R_T0, R_CamPadState, O_(PadState,buttons)), + load_word(R_T1, R_Cam, O_(Camera,pos.x)), // BD-Slot. + + // D-pad Left → cam.pos.x -= 50. and_i fulfills BD-slot for load on R_Cam. + and_i(R_T3, R_T0, Pad_Left), branch_le_zero(R_T3, atom_offset(left_x, exit_left_x)), nop, + add_si(R_T1, R_T1, -50), store_word(R_T1, R_Cam, O_(Camera,pos.x)), +atom_label(exit_left_x) + + /* D-pad Right → cam.pos.x += 50. Reuses R_T1 from Left. */ + and_i(R_T3, R_T0, Pad_Right), branch_le_zero(R_T3, atom_offset(right_x, exit_right_x)), nop, + add_si(R_T1, R_T1, 50), store_word(R_T1, R_Cam, O_(Camera,pos.x)), +atom_label(exit_right_x) + + /* D-pad Up → cam.pos.y -= 50. Load pos.y BEFORE the andi. */ + load_word(R_T1, R_Cam, O_(Camera,pos.y)), + and_i(R_T3, R_T0, Pad_Up), branch_le_zero(R_T3, atom_offset(up_y, exit_up_y)), nop, + add_si(R_T1, R_T1, -50), store_word(R_T1, R_Cam, O_(Camera,pos.y)), +atom_label(exit_up_y) + + /* D-pad Down → cam.pos.y += 50. Reuses R_T1 from Up. */ + and_i(R_T3, R_T0, Pad_Down), branch_le_zero(R_T3, atom_offset(down_y, exit_down_y)), nop, + add_si(R_T1, R_T1, 50), store_word(R_T1, R_Cam, O_(Camera,pos.y)), +atom_label(exit_down_y) + + /* D-pad Cross → cam.pos.z -= 50. Load pos.z BEFORE the andi. */ + load_word(R_T1, R_Cam, O_(Camera,pos.z)), + and_i(R_T3, R_T0, Pad_Cross), branch_le_zero(R_T3, atom_offset(cross_z, exit_cross_z)), nop, + add_si(R_T1, R_T1, -50), store_word(R_T1, R_Cam, O_(Camera,pos.z)), +atom_label(exit_cross_z) + + /* D-pad Circle → cam.pos.z += 50. Reuses R_T1 from Cross. */ + and_i(R_T3, R_T0, Pad_Circle), branch_le_zero(R_T3, atom_offset(circle_z, exit_circle_z)), nop, + add_si(R_T1, R_T1, 50), store_word(R_T1, R_Cam, O_(Camera,pos.z)), +atom_label(exit_circle_z) mac_yield(), }; diff --git a/code/hello_camera/hello_camera.c b/code/hello_camera/hello_camera.c index 52e24d3..551a97c 100644 --- a/code/hello_camera/hello_camera.c +++ b/code/hello_camera/hello_camera.c @@ -134,27 +134,28 @@ void update(PrimitiveArena* pa, U4* ordering_buf) tb_data_(state, & smem.pad[1]); // TODO(Ed): Implement based on below. - // tb_emit_(pad_input_cam); - // tb_data_(cam, & smem.cam); + tb_emit_(pad_input_cam); + tb_data_(state, & smem.pad[0]); + tb_data_(cam, & smem.cam); - if (pad0_btn_(Pad_Left)) { - smem.cam.pos.x -= 50; - } - if (pad0_btn_(Pad_Right)) { - smem.cam.pos.x += 50; - } - if (pad0_btn_(Pad_Up)) { - smem.cam.pos.y -= 50; - } - if (pad0_btn_(Pad_Down)) { - smem.cam.pos.y += 50; - } - if (pad0_btn_(Pad_Cross)) { - smem.cam.pos.z -= 50; - } - if (pad0_btn_(Pad_Circle)) { - smem.cam.pos.z += 50; - } + // if (pad0_btn_(Pad_Left)) { + // smem.cam.pos.x -= 50; + // } + // if (pad0_btn_(Pad_Right)) { + // smem.cam.pos.x += 50; + // } + // if (pad0_btn_(Pad_Up)) { + // smem.cam.pos.y -= 50; + // } + // if (pad0_btn_(Pad_Down)) { + // smem.cam.pos.y += 50; + // } + // if (pad0_btn_(Pad_Cross)) { + // smem.cam.pos.z -= 50; + // } + // if (pad0_btn_(Pad_Circle)) { + // smem.cam.pos.z += 50; + // } // Demo input (not longer using)