From 6fd094fc1793c91110c3360a82aa09756e5b95b1 Mon Sep 17 00:00:00 2001 From: water111 Date: Fri, 7 Aug 2026 22:42:03 -0400 Subject: [PATCH] clean up to quaternion --- decompiler/IR2/FormExpressionAnalysis.cpp | 9 +- decompiler/config/jak1/all-types.gc | 114 ++++++------ goal_src/jak1/engine/dma/dma-h.gc | 10 +- goal_src/jak1/engine/geometry/bounding-box.gc | 4 - goal_src/jak1/engine/geometry/geometry-h.gc | 3 +- goal_src/jak1/engine/math/matrix.gc | 17 -- goal_src/jak1/engine/math/quaternion.gc | 100 +++++----- goal_src/jak1/engine/math/trigonometry-h.gc | 5 - goal_src/jak1/engine/math/vector-h.gc | 20 +- goal_src/jak1/engine/ps2/vu1-macros.gc | 4 +- goal_src/jak1/kernel/gcommon.gc | 173 ++++++++++++------ goal_src/jak1/kernel/gkernel.gc | 4 - 12 files changed, 240 insertions(+), 223 deletions(-) diff --git a/decompiler/IR2/FormExpressionAnalysis.cpp b/decompiler/IR2/FormExpressionAnalysis.cpp index 423cd243a0..077d29ab03 100644 --- a/decompiler/IR2/FormExpressionAnalysis.cpp +++ b/decompiler/IR2/FormExpressionAnalysis.cpp @@ -3823,6 +3823,7 @@ bool is_deref_to_quad(DerefElement* deref) { struct DerefContainerInfo { TypeSpec type; bool is_matrix_row = false; + bool is_quaternion_view = false; }; std::optional deref_container_info(DerefElement* deref, const Env& env) { @@ -3855,9 +3856,12 @@ std::optional deref_container_info(DerefElement* deref, cons TypeSpec current = *base_type; bool is_matrix_row = current == TypeSpec("matrix") || current == TypeSpec("matrix3"); + bool is_quaternion_view = false; for (size_t i = 0; i + 1 < deref->tokens().size(); ++i) { const auto& token = deref->tokens().at(i); if (token.kind() == DerefToken::Kind::FIELD_NAME) { + is_quaternion_view = + is_quaternion_view || (current == TypeSpec("quaternion") && token.field_name() == "vec"); try { current = env.dts->ts.lookup_field_info(current.base_type(), token.field_name()).type; } catch (const std::exception&) { @@ -3878,7 +3882,7 @@ std::optional deref_container_info(DerefElement* deref, cons is_matrix_row = is_matrix_row || current == TypeSpec("matrix") || current == TypeSpec("matrix3"); } - return DerefContainerInfo{current, is_matrix_row}; + return DerefContainerInfo{current, is_matrix_row, is_quaternion_view}; } Form* pop_last_deref_token(Form* form) { @@ -3947,7 +3951,8 @@ FormElement* try_to_rewrite_vector_zero(Form* dst, Form* value, FormPool& pool, auto dst_deref = dst ? dst->try_as_element() : nullptr; const auto dst_info = dst_deref ? deref_container_info(dst_deref, env) : std::nullopt; - if (!dst_info || !env.dts->ts.tc(TypeSpec("vector"), dst_info->type)) { + if (!dst_info || dst_info->is_quaternion_view || + !env.dts->ts.tc(TypeSpec("vector"), dst_info->type)) { return nullptr; } if (!match(Matcher::cast("uint128", Matcher::integer(0)), value, &env).matched) { diff --git a/decompiler/config/jak1/all-types.gc b/decompiler/config/jak1/all-types.gc index f8c1ea3d22..482d3ae132 100644 --- a/decompiler/config/jak1/all-types.gc +++ b/decompiler/config/jak1/all-types.gc @@ -3072,7 +3072,7 @@ and max-speed. Leave the velocity unchanged otherwise." ;; - Functions (define-extern deg-diff "Return the shortest signed rotation-unit difference from the first angle to the second." (function float float float)) -(define-extern vector-y-angle (function vector float)) +(define-extern vector-y-angle "Return vec's yaw in rotation units from its XZ projection." (function vector float)) ;; ---------------------- @@ -3173,69 +3173,77 @@ and max-speed. Leave the velocity unchanged otherwise." ;; - Functions -(define-extern quaternion->matrix (function matrix quaternion matrix)) -(define-extern quaternion-vector-angle! (function quaternion vector float quaternion)) +(define-extern quaternion->matrix "Convert quaternion to matrix." (function matrix quaternion matrix)) +(define-extern quaternion-vector-angle! "Construct a quaternion from an axis and angle. The axis should be normalized." (function quaternion vector float quaternion)) (define-extern vector-xz-length "Return the Euclidean length of value.xz." (function vector float)) (define-extern vector-xz-normalize! "Scale value.xz in place to the requested length when its current xz length is nonzero." (function vector float vector)) (define-extern quaternion-from-two-vectors-max-angle! "Build the shortest-arc quaternion between two unit vectors, capped at max-angle." (function quaternion vector vector float quaternion)) -(define-extern vector-z-quaternion! (function vector quaternion vector)) -(define-extern quaternion-normalize! (function quaternion quaternion)) -(define-extern quaternion*! (function quaternion quaternion quaternion quaternion)) +(define-extern vector-z-quaternion! "Store q's world-space local Z (forward) axis in dst." (function vector quaternion vector)) +(define-extern quaternion-normalize! "Normalize q in place. A zero quaternion is invalid input." (function quaternion quaternion)) +(define-extern quaternion*! "Set dst to the Hamilton product a * b." (function quaternion quaternion quaternion quaternion)) (define-extern acos "Return inverse cosine in rotation units." (function float float)) -(define-extern vector-x-quaternion! (function vector quaternion vector)) -(define-extern quaternion-y-angle (function quaternion float)) +(define-extern vector-x-quaternion! "Store q's world-space local X axis in dst." (function vector quaternion vector)) +(define-extern quaternion-y-angle "Return the yaw of q's forward axis in rotation units." (function quaternion float)) (define-extern vector-rad<-vector-deg/2! "Halve and wrap four rotation-unit angles, then convert them to radians." (function vector vector int)) (define-extern vector-sincos-rad! "Compute per-lane sine and cosine for radian inputs in the supported polynomial interval." (function vector vector vector int)) -(define-extern quaternion-dot (function quaternion quaternion float)) +(define-extern quaternion-dot "Treat quaternions as vectors and take the dot product." (function quaternion quaternion float)) (define-extern atan-series-rad "Evaluate atan in radians from reduced = (x-1)/(x+1), with pi/4 supplied by the polynomial's constant term." (function float float)) (define-extern vector-sin-rad! "Compute per-lane sine for radian inputs in the supported polynomial interval." (function vector vector vector)) (define-extern vector-length "Return the Euclidean length of value.xyz." (function vector float)) -(define-extern sincos-rad! "Write sine and cosine for a radian angle with the shared scalar polynomial." (function (pointer float) float int)) -(define-extern quaternion-vector-len (function quaternion float)) +(define-extern sincos-rad! "Write sine and cosine for an angle in radians." (function (pointer float) float int)) +(define-extern quaternion-vector-len "Assuming quaternion is normalized, get the length of the xyz part." (function quaternion float)) (define-extern atan2-rad "Return atan2(y, x) in radians." (function float float float)) -(define-extern matrix->quaternion (function quaternion matrix quaternion)) -(define-extern quaternion-float*! (function quaternion quaternion float quaternion)) +(define-extern matrix->quaternion "Convert the upper 3x3 rotation of src-mat to dst, choosing its largest diagonal component for numerical stability." (function quaternion matrix quaternion)) +(define-extern quaternion-float*! "Multiply every component of src by scalar into dst." (function quaternion quaternion float quaternion)) (define-extern acos-rad "Return inverse cosine in radians." (function float float)) -(define-extern quaternion-norm (function quaternion float)) -(define-extern quaternion-axis-angle! (function quaternion float float float float quaternion)) -(define-extern vector-angle<-quaternion! (function vector quaternion vector)) -(define-extern quaternion-zero! (function quaternion quaternion)) -(define-extern quaternion-identity! (function quaternion quaternion)) -(define-extern quaternion-i! (function quaternion quaternion)) -(define-extern quaternion-j! (function quaternion quaternion)) -(define-extern quaternion-k! (function quaternion quaternion)) -(define-extern quaternion-copy! (function quaternion quaternion quaternion)) -(define-extern quaternion-set! (function quaternion float float float float quaternion)) -(define-extern quaternion+! (function quaternion quaternion quaternion quaternion)) -(define-extern quaternion-! (function quaternion quaternion quaternion quaternion)) -(define-extern quaternion-negate! (function quaternion quaternion quaternion)) -(define-extern quaternion-conjugate! (function quaternion quaternion quaternion)) -(define-extern quaternion-float/! (function quaternion quaternion float quaternion)) -(define-extern quaternion-norm2 (function quaternion float)) -(define-extern quaternion-inverse! (function quaternion quaternion quaternion)) -(define-extern quaternion-right-mult-matrix! (function matrix quaternion matrix)) -(define-extern quaternion-left-mult-matrix! (function matrix quaternion matrix)) -(define-extern matrix-with-scale->quaternion (function quaternion matrix quaternion)) -(define-extern quaternion-log! (function quaternion quaternion quaternion)) -(define-extern quaternion-exp! (function quaternion quaternion quaternion)) -(define-extern quaternion-slerp! (function quaternion quaternion quaternion float quaternion)) -(define-extern quaternion-pseudo-slerp! (function quaternion quaternion quaternion float quaternion)) -(define-extern quaternion-zxy! (function quaternion vector quaternion)) -(define-extern vector-y-quaternion! (function vector quaternion vector)) -(define-extern quaternion-vector-y-angle (function quaternion vector float)) -(define-extern quaternion-rotate-local-x! (function quaternion quaternion float quaternion)) -(define-extern quaternion-rotate-local-y! (function quaternion quaternion float quaternion)) -(define-extern quaternion-rotate-local-z! (function quaternion quaternion float quaternion)) -(define-extern quaternion-rotate-y! (function quaternion quaternion float quaternion)) -(define-extern quaternion-rotate-x! (function quaternion quaternion float quaternion)) -(define-extern quaternion-rotate-z! (function quaternion quaternion float quaternion)) -(define-extern quaternion-delta-y (function quaternion quaternion float)) -(define-extern quaternion-rotate-y-to-vector! (function quaternion quaternion vector float quaternion)) -(define-extern vector-rotate-y! (function vector vector float vector)) -(define-extern vector-x-angle (function vector float)) -(define-extern quaterion<-rotate-y-vector (function quaternion vector quaternion)) -(define-extern quaternion-validate (function quaternion none)) -(define-extern quaternion-xz-angle (function quaternion float)) +(define-extern quaternion-norm "Return the norm of q." (function quaternion float)) +(define-extern quaternion-axis-angle! "Construct a quaternion from an axis and angle. The axis should be normalized." (function quaternion float float float float quaternion)) +(define-extern vector-angle<-quaternion! "Convert normalized src to an axis in dst.xyz and a radian angle in dst.w. Identity rotations make the axis normalization singular." (function vector quaternion vector)) +(define-extern quaternion-zero! "Set all four components of dst to zero." (function quaternion quaternion)) +(define-extern quaternion-identity! "Set dst to the identity quaternion (0, 0, 0, 1)." (function quaternion quaternion)) +(define-extern quaternion-i! "Set dst to the unit i quaternion." (function quaternion quaternion)) +(define-extern quaternion-j! "Create unit j quaternion." (function quaternion quaternion)) +(define-extern quaternion-k! "Set dst to the unit k quaternion." (function quaternion quaternion)) +(define-extern quaternion-copy! "Copy src to dst." (function quaternion quaternion quaternion)) +(define-extern quaternion-set! "Set the four components of dst." (function quaternion float float float float quaternion)) +(define-extern quaternion+! "Add quaternions as vectors." (function quaternion quaternion quaternion quaternion)) +(define-extern quaternion-! "Subtract quaternions as vectors." (function quaternion quaternion quaternion quaternion)) +(define-extern quaternion-negate! "Set dst = -src." (function quaternion quaternion quaternion)) +(define-extern quaternion-conjugate! "Conjugate src into dst by negating xyz. For a unit quaternion this is its inverse rotation." (function quaternion quaternion quaternion)) +(define-extern quaternion-float/! "Divide every component of src by divisor into dst." (function quaternion quaternion float quaternion)) +(define-extern quaternion-norm2 "Return the squared norm of q." (function quaternion float)) +(define-extern quaternion-inverse! + "Invert a quaternion. The inverse will satisfy q * q^-1 = identity, even if q is not normalized. + If your quaternion is normalized, it is faster/more accurate to do quaternion-conjugate!" + (function quaternion quaternion quaternion)) +(define-extern quaternion-right-mult-matrix! + "Place quaternion coefficients into a matrix. + You can convert a quaternion to a matrix by taking the product of this + right-mult and left-mult matrix, but this method is not used. + Instead, quaternion->matrix is a more efficient implementation." + (function matrix quaternion matrix)) +(define-extern quaternion-left-mult-matrix! "Place quaternion coefficients into a matrix. Unused." (function matrix quaternion matrix)) +(define-extern matrix-with-scale->quaternion "Remove independent row scale from src-mat and convert the remaining rotation to dst." (function quaternion matrix quaternion)) +(define-extern quaternion-log! "Store the vector part of the logarithm of unit src in dst.xyz. Unused in Jak 1." (function quaternion quaternion quaternion)) +(define-extern quaternion-exp! "Exponentiate a pure-vector quaternion src into unit dst. Unused in Jak 1." (function quaternion quaternion quaternion)) +(define-extern quaternion-slerp! "Spherically interpolate from a to b, selecting the shortest quaternion hemisphere and using normalized lerp near zero angle." (function quaternion quaternion quaternion float quaternion)) +(define-extern quaternion-pseudo-slerp! "Normalized linear interpolation with hemisphere correction. It is not constant-speed and degenerates for antipodal rotations; unused in Jak 1." (function quaternion quaternion quaternion float quaternion)) +(define-extern quaternion-zxy! "Build dst from Z, then X, then Y rotations stored in angles." (function quaternion vector quaternion)) +(define-extern vector-y-quaternion! "Store q's world-space local Y axis in dst." (function vector quaternion vector)) +(define-extern quaternion-vector-y-angle "Return the signed yaw error from q's forward axis to direction in the XZ plane." (function quaternion vector float)) +(define-extern quaternion-rotate-local-x! "Post-multiply src by a local X rotation and normalize into dst." (function quaternion quaternion float quaternion)) +(define-extern quaternion-rotate-local-y! "Post-multiply src by a local Y rotation and normalize into dst." (function quaternion quaternion float quaternion)) +(define-extern quaternion-rotate-local-z! "Post-multiply src by a local Z rotation and normalize into dst." (function quaternion quaternion float quaternion)) +(define-extern quaternion-rotate-y! "Pre-multiply src by a world Y rotation and normalize into dst." (function quaternion quaternion float quaternion)) +(define-extern quaternion-rotate-x! "Rotate src about its current world-space X axis and normalize into dst." (function quaternion quaternion float quaternion)) +(define-extern quaternion-rotate-z! "Rotate src about its current world-space Z axis and normalize into dst." (function quaternion quaternion float quaternion)) +(define-extern quaternion-delta-y "Return the unsigned angle between the two forward axes. Despite the name, pitch also affects the result." (function quaternion quaternion float)) +(define-extern quaternion-rotate-y-to-vector! "Turn src's forward axis toward direction projected onto XZ, capped by max-angle, and normalize into dst." (function quaternion quaternion vector float quaternion)) +(define-extern vector-rotate-y! "Rotate src about world Y into dst through a temporary quaternion and matrix." (function vector vector float vector)) +(define-extern vector-x-angle "Return vec's pitch in rotation units." (function vector float)) +(define-extern quaterion<-rotate-y-vector "Build a pure-yaw quaternion facing direction. The function name retains its original misspelling." (function quaternion vector quaternion)) +(define-extern quaternion-validate "Verify that a quaternion is valid, print an error if not." (function quaternion none)) +(define-extern quaternion-xz-angle "Return q's yaw by rotating a temporary forward vector through a temporary matrix." (function quaternion float)) ;; ---------------------- diff --git a/goal_src/jak1/engine/dma/dma-h.gc b/goal_src/jak1/engine/dma/dma-h.gc index cc71834dd7..f573ad3691 100644 --- a/goal_src/jak1/engine/dma/dma-h.gc +++ b/goal_src/jak1/engine/dma/dma-h.gc @@ -115,16 +115,16 @@ ;; These addresses are the location of DMA banks for each channel. ;; These addresses name EE hardware registers and are not dereferenced on PC. -(defconstant VIF0_DMA_BANK (the dma-bank-vif (get-vm-ptr #x10008000))) +(defconstant VIF0_DMA_BANK (the dma-bank-vif #x10008000)) -(defconstant VIF1_DMA_BANK (the dma-bank-vif (get-vm-ptr #x10009000))) +(defconstant VIF1_DMA_BANK (the dma-bank-vif #x10009000)) -(defconstant GIF_DMA_BANK (the dma-bank (get-vm-ptr #x1000a000))) +(defconstant GIF_DMA_BANK (the dma-bank #x1000a000)) ;; ipuFrom, ipTop, sif0, sif1, sif2 believed unused. -(defconstant SPR_FROM_BANK (the dma-bank-spr (get-vm-ptr #x1000d000))) +(defconstant SPR_FROM_BANK (the dma-bank-spr #x1000d000)) -(defconstant SPR_TO_BANK (the dma-bank-spr (get-vm-ptr #x1000d400))) +(defconstant SPR_TO_BANK (the dma-bank-spr #x1000d400)) (defconstant VU0_DATA_MEM_MAP (the (pointer uint32) #x11004000)) diff --git a/goal_src/jak1/engine/geometry/bounding-box.gc b/goal_src/jak1/engine/geometry/bounding-box.gc index c94ef8b246..6aa74caf98 100644 --- a/goal_src/jak1/engine/geometry/bounding-box.gc +++ b/goal_src/jak1/engine/geometry/bounding-box.gc @@ -6,10 +6,6 @@ ;; A bounding-box is a pair of vectors holding the low and high corner. Every method here works on ;; whole quadwords, so the w lanes take part in the arithmetic whether or not they mean anything. -;; set-from-point-offset!, set-from-point-offset-pad! and set-from-sphere! write w = 1.0 explicitly; -;; add-point! and add-box! do not, and leave w as the min or max of the two inputs' w. That is -;; harmless when both are boxes, and it is why the point methods are declared to take vector3s but -;; must be handed something with sixteen readable bytes: the load is a quadword load regardless. ;; ;; The multi-sphere methods below expand a sphere into its own bounding box with the same trick used ;; throughout: (.sub.w.vf.xyz out in in) subtracts a sphere's w, its radius, from each of its xyz diff --git a/goal_src/jak1/engine/geometry/geometry-h.gc b/goal_src/jak1/engine/geometry/geometry-h.gc index 872a0241bc..412e8b7aff 100644 --- a/goal_src/jak1/engine/geometry/geometry-h.gc +++ b/goal_src/jak1/engine/geometry/geometry-h.gc @@ -19,8 +19,7 @@ (num-knots int32) (length float))) -;; Named trigger plane. The implementation can draw it and test which side contains -;; a point, but no shipped Jak 1 system instantiates one. +;; Named trigger plane. Unused. (deftype border-plane (basic) ((name symbol) (action basic) diff --git a/goal_src/jak1/engine/math/matrix.gc b/goal_src/jak1/engine/math/matrix.gc index 606e9c3188..50b162ad4d 100644 --- a/goal_src/jak1/engine/math/matrix.gc +++ b/goal_src/jak1/engine/math/matrix.gc @@ -4,8 +4,6 @@ (require "engine/math/vector-h.gc") (require "engine/math/matrix-h.gc") -;; The PC implementation of the register-argument entry point delegates forward -;; to the ordinary axis/sine/cosine routine defined later in this file. (defun-extern matrix-axis-sin-cos! matrix vector float float matrix) ;; This file implements the GOAL matrix library. @@ -50,18 +48,6 @@ ;; src in matrix-inverse-of-rot-trans!, matrix-3x3-inverse!, matrix-3x3-inverse-transpose! and ;; matrix-4x4-inverse-transpose!, all of which read src after they have started writing dst. -;; matrix3 shares the layout, but only the upper 3x3 means anything. Nothing here writes its -;; fourth column, so reading one back as a matrix finds garbage in every w. - -;; A few idioms recur. (.mul.x.vf acc a b) opens the VU0 accumulator, .add.mul..vf keeps -;; adding broadcast products, and the last one writes a register; one matrix row is four of those -;; and never needs a temporary. (.mov gpr vf) and (.mov vf gpr) are bit moves between the -;; register files rather than conversions, which is how an FPU float becomes a broadcast lane and -;; how a lane's sign gets tested with an integer branch. pceqw, ppach, add one, branch on zero -;; asks whether a group of lanes were all zero in a single test. (.xor.vf r r r) stands where the -;; EE cleared a register by subtracting it from itself: subtraction preserves NaN, xor does not, -;; and NaN lanes are very slow on the host. - ;; DECOMP BEGINS (defmethod inspect ((this matrix)) @@ -777,8 +763,6 @@ (defun matrix-axis-sin-cos-vu! ((dst matrix) (axis vector) (sin-angle float) (cos-angle float)) "Build an axis-angle rotation matrix from precomputed sine and cosine passed in EE registers." (#unless PC_PORT - ;; This entry point is the register-argument twin of matrix-axis-sin-cos!. - ;; Preserve the original schedule, including the VU pipeline spacing. (rlet ((dst-reg :reg a0) (axis-reg :reg a1) (sin-bits :reg a2) @@ -887,7 +871,6 @@ (nop!) (nop!))) (#when PC_PORT - ;; The special register calling convention is irrelevant on the host. (matrix-axis-sin-cos! dst axis sin-angle cos-angle)) (none)) diff --git a/goal_src/jak1/engine/math/quaternion.gc b/goal_src/jak1/engine/math/quaternion.gc index 2b7708eda4..8a8b9ce32e 100644 --- a/goal_src/jak1/engine/math/quaternion.gc +++ b/goal_src/jak1/engine/math/quaternion.gc @@ -17,37 +17,33 @@ (defun quaternion-axis-angle! ((dst quaternion) (x float) (y float) (z float) (angle float)) "Construct a quaternion from an axis and angle. The axis should be normalized." - (let* ((half-angle (* 0.5 angle)) + (let* ((half-angle (/ angle 2)) (sin-half-angle (sin half-angle)) (cos-half-angle (cos half-angle))) - (set! (-> dst x) (* x sin-half-angle)) - (set! (-> dst y) (* y sin-half-angle)) - (set! (-> dst z) (* z sin-half-angle)) - (set! (-> dst w) cos-half-angle)) + (set-vector! dst (* x sin-half-angle) (* y sin-half-angle) (* z sin-half-angle) cos-half-angle)) dst) (defun quaternion-vector-angle! ((dst quaternion) (axis vector) (angle float)) "Construct a quaternion from an axis and angle. The axis should be normalized." - (let* ((half-angle (* 0.5 angle)) + (let* ((half-angle (/ angle 2)) (sin-half-angle (sin half-angle)) (cos-half-angle (cos half-angle))) - (set! (-> dst x) (* (-> axis x) sin-half-angle)) - (set! (-> dst y) (* (-> axis y) sin-half-angle)) - (set! (-> dst z) (* (-> axis z) sin-half-angle)) - (set! (-> dst w) cos-half-angle)) + (set-vector! dst + (* (-> axis x) sin-half-angle) + (* (-> axis y) sin-half-angle) + (* (-> axis z) sin-half-angle) + cos-half-angle)) dst) (defun vector-angle<-quaternion! ((dst vector) (src quaternion)) "Convert normalized src to an axis in dst.xyz and a radian angle in dst.w. Identity rotations make the axis normalization singular." - (let* ((f0-0 1.0) - (f1-0 1.0) - (f2-0 (-> src w)) - (inverse-axis-length (/ f0-0 (sqrtf (- f1-0 (* f2-0 f2-0))))) - (angle-rad (* 2.0 (acos-rad (-> src w))))) - (set! (-> dst x) (* (-> src x) inverse-axis-length)) - (set! (-> dst y) (* (-> src y) inverse-axis-length)) - (set! (-> dst z) (* (-> src z) inverse-axis-length)) - (set! (-> dst w) angle-rad)) + (let ((inverse-axis-length (/ 1.0 (sqrtf (- 1.0 (square (-> src w)))))) + (angle-rad (* 2.0 (acos-rad (-> src w))))) + (set-vector! dst + (* (-> src x) inverse-axis-length) + (* (-> src y) inverse-axis-length) + (* (-> src z) inverse-axis-length) + angle-rad)) dst) (defun quaternion-zero! ((dst quaternion)) @@ -81,15 +77,12 @@ (defun quaternion-copy! ((dst quaternion) (src quaternion)) "Copy src to dst." - (set! (-> dst vec quad) (-> src vec quad)) + (vector-copy! (-> dst vec) (-> src vec)) dst) (defun quaternion-set! ((dst quaternion) (x float) (y float) (z float) (w float)) "Set the four components of dst." - (set! (-> dst x) x) - (set! (-> dst y) y) - (set! (-> dst z) z) - (set! (-> dst w) w) + (set-vector! dst x y z w) dst) (defun quaternion+! ((dst quaternion) (a quaternion) (b quaternion)) @@ -149,11 +142,12 @@ (defun quaternion-float/! ((dst quaternion) (src quaternion) (divisor float)) "Divide every component of src by divisor into dst." - (let ((f0-1 (/ 1.0 divisor))) (quaternion-float*! dst src f0-1)) + (let ((f0-1 (/ 1.0 divisor))) + (quaternion-float*! dst src f0-1)) dst) (defun quaternion-norm2 ((q quaternion)) - "Return the squared four-dimensional norm of q." + "Return the squared norm of q." (local-vars (v0-0 float)) (rlet ((acc :class vf) (vf0 :class vf) @@ -169,7 +163,7 @@ v0-0)) (defun quaternion-norm ((q quaternion)) - "Return the four-dimensional norm of q." + "Return the norm of q." (local-vars (v1-1 float)) (rlet ((acc :class vf) (vf0 :class vf) @@ -372,7 +366,7 @@ (cond ((< 0.0 trace) (let ((f0-4 (sqrtf (+ 1.0 trace)))) - (set! (-> dst w) (* 0.5 f0-4)) + (set! (-> dst w) (/ f0-4 2)) (let ((f0-5 (/ 0.5 f0-4))) (set! (-> dst x) (* f0-5 (- (-> src-mat vector 1 z) (-> src-mat vector 2 y)))) (set! (-> dst y) (* f0-5 (- (-> src-mat vector 2 x) (-> src-mat vector 0 z)))) @@ -394,8 +388,9 @@ (+ (-> (the-as (pointer float) (+ (+ (* next-axis 4) (* next-axis 16)) (the-as int src-mat)))) (-> (the-as (pointer float) (+ (+ (* previous-axis 4) (* previous-axis 16)) (the-as int src-mat)))))) (-> (the-as (pointer float) (+ (+ (* largest-axis 4) (* largest-axis 16)) (the-as int src-mat)))))))) - (set! (-> dst data largest-axis) (* 0.5 diagonal-root)) - (if (!= diagonal-root 0.0) (set! diagonal-root (/ 0.5 diagonal-root))) + (set! (-> dst data largest-axis) (/ diagonal-root 2)) + (if (!= diagonal-root 0.0) + (set! diagonal-root (/ 0.5 diagonal-root))) (set! (-> dst w) (* (- (-> (the-as (pointer float) (+ (+ (* previous-axis 4) (* next-axis 16)) (the-as int src-mat)))) (-> (the-as (pointer float) (+ (+ (* next-axis 4) (* previous-axis 16)) (the-as int src-mat))))) @@ -451,10 +446,7 @@ (defun quaternion-vector-len ((q quaternion)) "Assuming quaternion is normalized, get the length of the xyz part." - (let ((f0-0 1.0) - (f1-0 (-> q w))) - ;; sqrt(1 - w^2) = sqrt(x^2 + y^2 + z^2) = length - (sqrtf (- f0-0 (* f1-0 f1-0))))) + (sqrtf (- 1.0 (square (-> q w))))) (defun quaternion-log! ((dst quaternion) (src quaternion)) "Store the vector part of the logarithm of unit src in dst.xyz. Unused in Jak 1." @@ -473,12 +465,13 @@ (defun quaternion-exp! ((dst quaternion) (src quaternion)) "Exponentiate a pure-vector quaternion src into unit dst. Unused in Jak 1." - (let ((imaginary-length (vector-length (the-as vector src)))) + (let ((imaginary-length (vector-length (-> src vec)))) (cond - ((= imaginary-length 0.0) (set! (-> dst x) 0.0) (set! (-> dst y) 0.0) (set! (-> dst z) 0.0) (set! (-> dst w) 1.0)) + ((= imaginary-length 0.0) + (set-vector! dst 0.0 0.0 0.0 1.0)) (else (let ((sincos (new 'stack-no-clear 'vector))) - (sincos-rad! (the-as (pointer float) sincos) imaginary-length) + (sincos-rad! (&-> sincos x) imaginary-length) (let ((sin-over-length (/ (-> sincos x) imaginary-length))) (set! (-> dst x) (* (-> src x) sin-over-length)) (set! (-> dst y) (* (-> src y) sin-over-length)) @@ -501,8 +494,10 @@ (set! hemisphere-sign -1.0)) (cond ((< (- 1.0 cos-angle) 0.0001) - (let ((a-weight (- 1.0 alpha))) (.mov vf1 a-weight)) - (let ((b-weight (* alpha hemisphere-sign))) (.mov vf2 b-weight)) + (let ((a-weight (- 1.0 alpha))) + (.mov vf1 a-weight)) + (let ((b-weight (* alpha hemisphere-sign))) + (.mov vf2 b-weight)) (.lvf vf3 (&-> a vec quad)) (.lvf vf4 (&-> b vec quad)) (.mul.x.vf acc vf3 vf1) @@ -514,9 +509,7 @@ ;; s=sqrt(1-c^2), (s-c)/(s+c)=tan(theta-pi/4); atan-series-rad ;; folds the pi/4 offset into its result. Dividing the two sine ;; weights by s gives the standard constant-angular-speed slerp. - (let* ((f1-4 1.0) - (f2-1 cos-angle) - (sin-angle (sqrtf (- f1-4 (* f2-1 f2-1)))) + (let* ((sin-angle (sqrtf (- 1.0 (square cos-angle)))) (atan-argument (/ (- sin-angle cos-angle) (+ sin-angle cos-angle))) (inverse-sin-angle (/ 1.0 sin-angle))) (let ((angle-rad (atan-series-rad atan-argument)) @@ -525,7 +518,8 @@ (set! (-> blend-angles y) (* alpha angle-rad hemisphere-sign)) (vector-sin-rad! blend-angles blend-angles) (.lvf vf1 (&-> blend-angles quad))) - (let ((v1-6 inverse-sin-angle)) (.mov vf2 v1-6))) + (let ((v1-6 inverse-sin-angle)) + (.mov vf2 v1-6))) (.mul.x.vf vf1 vf1 vf2) (.lvf vf3 (&-> a vec quad)) (.lvf vf4 (&-> b vec quad)) @@ -549,8 +543,10 @@ ;; needed to choose the equivalent endpoint in the nearer hemisphere. (- cos-angle) (set! hemisphere-sign -1.0)) - (let ((a-weight (- 1.0 alpha))) (.mov vf1 a-weight)) - (let ((b-weight (* alpha hemisphere-sign))) (.mov vf2 b-weight))) + (let ((a-weight (- 1.0 alpha))) + (.mov vf1 a-weight)) + (let ((b-weight (* alpha hemisphere-sign))) + (.mov vf2 b-weight))) (.lvf vf3 (&-> a vec quad)) (.lvf vf4 (&-> b vec quad)) (.mul.x.vf acc vf3 vf1) @@ -628,7 +624,8 @@ (defun quaternion-y-angle ((q quaternion)) "Return the yaw of q's forward axis in rotation units." - (let ((forward (vector-z-quaternion! (new 'stack-no-clear 'vector) q))) (atan (-> forward x) (-> forward z)))) + (let ((forward (vector-z-quaternion! (new 'stack-no-clear 'vector) q))) + (atan (-> forward x) (-> forward z)))) (defun quaternion-vector-y-angle ((q quaternion) (direction vector)) "Return the signed yaw error from q's forward axis to direction in the XZ plane." @@ -675,13 +672,10 @@ (let ((delta (new 'stack-no-clear 'quaternion))) (let ((normalize-xz-fn vector-xz-normalize!) (flat-direction (new 'stack-no-clear 'vector))) - (set! (-> flat-direction x) (-> direction x)) - (set! (-> flat-direction y) 0.0) - (set! (-> flat-direction z) (-> direction z)) - (set! (-> flat-direction w) 1.0) + (set-vector! flat-direction (-> direction x) 0.0 (-> direction z) 1.0) (let ((target-direction (normalize-xz-fn flat-direction 1.0))) (quaternion-from-two-vectors-max-angle! delta - (vector-z-quaternion! (new 'stack-no-clear 'vector) src) + (vector-z-quaternion! (-> (new 'stack-no-clear 'quaternion) vec) src) target-direction max-angle))) (quaternion-normalize! (quaternion*! dst delta src)))) @@ -714,7 +708,9 @@ (let ((magnitude (quaternion-norm q))) (when (or (< 1.01 magnitude) (< magnitude 0.99)) (format #t "WARNING: bad quaternion (magnitude ~F) process is " magnitude) - (if (and pp (type-type? (-> pp type) process-tree)) (format #t "~A~%" (-> pp name)) (format #t "#f~%")))) + (if (and pp (type-type? (-> pp type) process-tree)) + (format #t "~A~%" (-> pp name)) + (format #t "#f~%")))) 0 (none))) diff --git a/goal_src/jak1/engine/math/trigonometry-h.gc b/goal_src/jak1/engine/math/trigonometry-h.gc index aef622dada..37a81783d3 100644 --- a/goal_src/jak1/engine/math/trigonometry-h.gc +++ b/goal_src/jak1/engine/math/trigonometry-h.gc @@ -7,7 +7,6 @@ ;; Angles without a -rad suffix use rotation units: 65536.0 is one full turn. (defun-extern sin float float) - (defun-extern cos float float) ;; Compute componentwise sine and cosine in rotation units. @@ -15,13 +14,11 @@ ;; Return the angle of (y, x) in rotation units. (defun-extern atan float float float) - (defun-extern acos float float) ;; Radian APIs expect their inputs to have already been reduced to the range ;; required by their polynomial approximations. (defun-extern acos-rad float float) - (defun-extern atan2-rad float float float) ;; Store sine and cosine of a radian angle in a two-float destination. @@ -31,9 +28,7 @@ ;; Componentwise vector helpers; destination arguments come first. (defun-extern vector-sin-rad! vector vector vector) - (defun-extern vector-rad<-vector-deg/2! vector vector int) - (defun-extern vector-sincos-rad! vector vector vector int) ;; Return the shortest signed difference from the first angle to the second. diff --git a/goal_src/jak1/engine/math/vector-h.gc b/goal_src/jak1/engine/math/vector-h.gc index 3c052da262..6a015acfef 100644 --- a/goal_src/jak1/engine/math/vector-h.gc +++ b/goal_src/jak1/engine/math/vector-h.gc @@ -18,7 +18,6 @@ (deftype bit-array (basic) ((length int32) (allocated-length int32) - ;; The generated inspector omits the overlaid storage fields. (_pad uint8) (bytes uint8 :dynamic :overlay-at _pad)) (:methods @@ -60,7 +59,6 @@ (defmethod clear-all! ((this bit-array)) "Clear every storage byte, including unused bits in the final byte, and return this array." (countdown (i (/ (logand -8 (+ (-> this allocated-length) 7)) 8)) - ;; Space the counter update from the byte-address calculation. (nop!) (nop!) (set! (-> this bytes i) (the-as uint 0))) @@ -74,8 +72,6 @@ "Make the VU0 constant vector (0, 0, 0, 1) available to portable VU operations." `(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))) -;; the GOAL vector types are structures, storing values in memory. - ;; Vector of 4 unsigned bytes. (deftype vector4ub (structure) ((data uint8 4) @@ -109,7 +105,7 @@ (val uint32 :overlay-at (-> data 0))) :pack-me) -;; Vector of 3 signed halfwords. data names only the first two; z follows them. +;; Vector of 3 signed halfwords. (deftype vector3h (structure) ((data int16 2) (x int16 :overlay-at (-> data 0)) @@ -246,7 +242,7 @@ (c float :overlay-at z) (d float :overlay-at w))) -;; x, y, and z are the center; r overlays w. +;; x, y, and z are the center and the radius overlays `w`. (deftype sphere (vector) ((r float :overlay-at w))) @@ -556,27 +552,15 @@ (define *zero-vector* (new 'static 'vector :x 0. :y 0. :z 0. :w 0.)) (define-extern vector-identity! (function vector vector)) - (define-extern vector-length (function vector float)) - (define-extern vector-xz-normalize! (function vector float vector)) - (define-extern vector-xz-length (function vector float)) - (defun-extern vector+float*! vector vector vector float vector) - (defun-extern vector-normalize! vector float vector) - (defun-extern vector-float*! vector vector float vector) - (define-extern vector-normalize-copy! (function vector vector float vector)) - (define-extern vector-cross! (function vector vector vector vector)) - (define-extern vector-negate! (function vector vector vector)) - (define-extern vector-normalize-ret-len! (function vector float float)) - (define-extern vector-vector-distance (function vector vector float)) - (define-extern vector-vector-distance-squared (function vector vector float)) diff --git a/goal_src/jak1/engine/ps2/vu1-macros.gc b/goal_src/jak1/engine/ps2/vu1-macros.gc index bf4e5790d1..1dbffde5fb 100644 --- a/goal_src/jak1/engine/ps2/vu1-macros.gc +++ b/goal_src/jak1/engine/ps2/vu1-macros.gc @@ -31,9 +31,7 @@ (logior! ,flags 32))) ,flags))) -;; Jak 1 uses only whole-register XYZW forms of these fixed-point conversions. The PC fallbacks -;; scale in floating point before or after the host integer conversion. Extremely large values can -;; therefore lose precision before conversion. +;; Jak 1 uses only whole-register XYZW forms of these fixed-point conversions. (defmacro vftoi4.xyzw (dst src) "Convert every source lane from float to signed 28.4 fixed point." diff --git a/goal_src/jak1/kernel/gcommon.gc b/goal_src/jak1/kernel/gcommon.gc index 60393ea6d0..4a73521dac 100644 --- a/goal_src/jak1/kernel/gcommon.gc +++ b/goal_src/jak1/kernel/gcommon.gc @@ -20,10 +20,6 @@ (defglobalconstant PC_BIG_MEMORY (and PC_PORT BIG_MEMORY)) -;; redirects access to EE memory mapped registers through get-vm-ptr to valid addresses that -;; are monitored in the runtime for debugging. -(defglobalconstant USE_VM #f) - ;; enables the with-profiler statements, which send profiling data from ;; GOAL code to the frame profiler in C++. (defglobalconstant PC_PROFILER_ENABLE #t) @@ -43,9 +39,7 @@ ;; GOAL boxed offsets use the lower three bits to indicate if they are ;; an integer (binteger), a pair, or a strucutre with type info (basic) (defconstant BINTEGER_OFFSET 0) - (defconstant PAIR_OFFSET 2) - (defconstant BASIC_OFFSET 4) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -56,12 +50,6 @@ "Convert a symbol to a goal string." `(-> (the-as (pointer string) (+ SYM_TO_STRING_OFFSET (the-as int ,sym))))) -(defmacro get-vm-ptr (ptr) - "Turn an EE register address into a valid PS2 VM address" - `(#cond - (USE_VM (vm-ptr ,ptr)) - (#t ,ptr))) - ;; DECOMP BEGINS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -262,10 +250,12 @@ (local-vars (current-method function)) (let ((original-method (-> child-type method-table method-id))) (until (!= current-method original-method) - (if (= child-type object) (return nothing)) + (if (= child-type object) + (return nothing)) (set! child-type (-> child-type parent)) (set! current-method (-> child-type method-table method-id)) - (if (zero? current-method) (return nothing)))) + (if (zero? current-method) + (return nothing)))) current-method) (defmacro call-parent-method (&rest args) @@ -308,7 +298,12 @@ (defun last ((list object)) "Return the last pair in a proper list." - (let ((iter list)) (while (not (null? (cdr iter))) (nop!) (nop!) (set! iter (cdr iter))) iter)) + (let ((iter list)) + (while (not (null? (cdr iter))) + (nop!) + (nop!) + (set! iter (cdr iter))) + iter)) (defun member ((item object) (list object)) "Return the list tail whose car is item, or false when item is absent." @@ -343,7 +338,10 @@ (defun nassoc ((item-name string) (alist object)) "Return the named key-value pair from an association list. A key may be a single named object or a list of aliases." (while (not (or (null? alist) - (let ((key (car (car alist)))) (if (pair? key) (nmember item-name key) (name= (the-as basic key) item-name))))) + (let ((key (car (car alist)))) + (if (pair? key) + (nmember item-name key) + (name= (the-as basic key) item-name))))) (set! alist (cdr alist))) (if (not (null? alist)) (car alist))) @@ -351,23 +349,24 @@ "Return the named key-value pair from an association list. Keys may be alias lists, and a single else key acts as a fallback." (while (not (or (null? alist) (let ((key (car (car alist)))) - (if (pair? key) (nmember item-name key) (or (name= (the-as basic key) item-name) (= key 'else)))))) + (if (pair? key) + (nmember item-name key) + (or (name= (the-as basic key) item-name) (= key 'else)))))) (set! alist (cdr alist))) (if (not (null? alist)) (car alist))) (defun append! ((front object) (back object)) "Destructively attach back to the final pair of front and return the combined list. If front is empty, return back directly." (cond - ((null? front) - ;; can't append to '(), just return back. - back) + ((null? front) back) (else (let ((iter front)) (while (not (null? (cdr iter))) (nop!) (nop!) (set! iter (cdr iter))) - (if (not (null? iter)) (set! (cdr iter) back))) + (if (not (null? iter)) + (set! (cdr iter) back))) front))) (defun delete! ((item object) (list object)) @@ -381,7 +380,8 @@ (while (not (or (null? iter) (= (car iter) item))) (set! iter-prev iter) (set! iter (cdr iter))) - (if (not (null? iter)) (set! (cdr iter-prev) (cdr iter)))) + (if (not (null? iter)) + (set! (cdr iter-prev) (cdr iter)))) list)))) (defun delete-car! ((item object) (list object)) @@ -394,13 +394,15 @@ (while (not (or (null? iter) (= (car (car iter)) item))) (set! iter-prev iter) (set! iter (cdr iter))) - (if (not (null? iter)) (set! (cdr iter-prev) (cdr iter)))) + (if (not (null? iter)) + (set! (cdr iter-prev) (cdr iter)))) list))) (defun insert-cons! ((entry object) (alist object)) "Insert a key-value pair into an association list, replacing an existing entry. This allocates one pair on the global heap." - (let ((updated-list (delete-car! (car entry) alist))) (cons entry updated-list))) - + (let ((updated-list (delete-car! (car entry) alist))) + (cons entry updated-list))) + (defun sort ((list pair) (compare-func (function object object object))) "Destructively bubble-sort a list by swapping adjacent out-of-order cars until a pass makes no swaps. An integer comparator returns a positive value when the first item should follow the second, so (sort list -) is ascending. A boolean comparator must return exactly #t for an in-order pair; another truthy value can be mistaken for a positive integer." ;; the compare function can return a few possible things. @@ -496,24 +498,46 @@ (cond ((type-type? (-> this content-type) integer) (case (-> this content-type symbol) - (('int32) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int32) this) i)))) - (('uint32) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array uint32) this) i)))) - (('int64) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int64) this) i)))) - (('uint64) (dotimes (i (-> this length)) (format #t (if (zero? i) "#x~X" " #x~X") (-> (the-as (array uint64) this) i)))) - (('int8) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int8) this) i)))) - (('uint8) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array uint8) this) i)))) - (('int16) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int16) this) i)))) - (('uint16) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array uint16) this) i)))) + (('int32) + (dotimes (i (-> this length)) + (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int32) this) i)))) + (('uint32) + (dotimes (i (-> this length)) + (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array uint32) this) i)))) + (('int64) + (dotimes (i (-> this length)) + (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int64) this) i)))) + (('uint64) + (dotimes (i (-> this length)) + (format #t (if (zero? i) "#x~X" " #x~X") (-> (the-as (array uint64) this) i)))) + (('int8) + (dotimes (i (-> this length)) + (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int8) this) i)))) + (('uint8) + (dotimes (i (-> this length)) + (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array uint8) this) i)))) + (('int16) + (dotimes (i (-> this length)) + (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int16) this) i)))) + (('uint16) + (dotimes (i (-> this length)) + (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array uint16) this) i)))) (('uint128 'int128) (dotimes (i (-> this length)) (format #t (if (zero? i) "#x~X" " #x~X") (-> (the-as (array uint128) this) i)))) - (else (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int32) this) i)))))) + (else + (dotimes (i (-> this length)) + (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int32) this) i)))))) ((= (-> this content-type) float) (dotimes (i (-> this length)) - (if (zero? i) (format #t "~f" (-> (the-as (array float) this) i)) (format #t " ~f" (-> (the-as (array float) this) i))))) + (if (zero? i) + (format #t "~f" (-> (the-as (array float) this) i)) + (format #t " ~f" (-> (the-as (array float) this) i))))) (else (dotimes (i (-> this length)) - (if (zero? i) (format #t "~A" (-> (the-as (array basic) this) i)) (format #t " ~A" (-> (the-as (array basic) this) i)))))) + (if (zero? i) + (format #t "~A" (-> (the-as (array basic) this) i)) + (format #t " ~A" (-> (the-as (array basic) this) i)))))) (format #t ")") this) @@ -526,20 +550,42 @@ (cond ((type-type? (-> this content-type) integer) (case (-> this content-type symbol) - (('int32) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int32) this) i)))) - (('uint32) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array uint32) this) i)))) - (('int64) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int64) this) i)))) - (('uint64) (dotimes (i (-> this length)) (format #t "~T [~D] #x~X~%" i (-> (the-as (array uint64) this) i)))) - (('int8) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int8) this) i)))) - (('uint8) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int8) this) i)))) - (('int16) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int16) this) i)))) - (('uint16) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array uint16) this) i)))) - (('int128 'uint128) (dotimes (i (-> this length)) (format #t "~T [~D] #x~X~%" i (-> (the-as (array uint128) this) i)))) - (else (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int32) this) i)))))) + (('int32) + (dotimes (i (-> this length)) + (format #t "~T [~D] ~D~%" i (-> (the-as (array int32) this) i)))) + (('uint32) + (dotimes (i (-> this length)) + (format #t "~T [~D] ~D~%" i (-> (the-as (array uint32) this) i)))) + (('int64) + (dotimes (i (-> this length)) + (format #t "~T [~D] ~D~%" i (-> (the-as (array int64) this) i)))) + (('uint64) + (dotimes (i (-> this length)) + (format #t "~T [~D] #x~X~%" i (-> (the-as (array uint64) this) i)))) + (('int8) + (dotimes (i (-> this length)) + (format #t "~T [~D] ~D~%" i (-> (the-as (array int8) this) i)))) + (('uint8) + (dotimes (i (-> this length)) + (format #t "~T [~D] ~D~%" i (-> (the-as (array int8) this) i)))) + (('int16) + (dotimes (i (-> this length)) + (format #t "~T [~D] ~D~%" i (-> (the-as (array int16) this) i)))) + (('uint16) + (dotimes (i (-> this length)) + (format #t "~T [~D] ~D~%" i (-> (the-as (array uint16) this) i)))) + (('int128 'uint128) + (dotimes (i (-> this length)) + (format #t "~T [~D] #x~X~%" i (-> (the-as (array uint128) this) i)))) + (else + (dotimes (i (-> this length)) + (format #t "~T [~D] ~D~%" i (-> (the-as (array int32) this) i)))))) ((= (-> this content-type) float) (dotimes (i (-> this length)) (format #t "~T [~D] ~f~%" i (-> (the-as (array float) this) i)))) - (else (dotimes (i (-> this length)) (format #t "~T [~D] ~A~%" i (-> (the-as (array basic) this) i))))) + (else + (dotimes (i (-> this length)) + (format #t "~T [~D] ~A~%" i (-> (the-as (array basic) this) i))))) this) (defmethod length ((this array)) @@ -547,11 +593,12 @@ (-> this length)) (defmethod asize-of ((this array)) - "Get the size in memory of an array" (the-as int (+ (-> array size) - (* (-> this allocated-length) (if (type-type? (-> this content-type) number) (-> this content-type size) 4))))) - + (* (-> this allocated-length) + (if (type-type? (-> this content-type) number) + (the-as int (-> this content-type size)) + 4))))) ;;;;;;;;;;;;;;;;;;;;;;;; ;; memory manipulation ;;;;;;;;;;;;;;;;;;;;;;;; @@ -589,7 +636,12 @@ (defun mem-set32! ((dst pointer) (word-count int) (value int)) "Fill word-count 32-bit words with value. The count precedes the fill value." - (let ((result dst)) (dotimes (i word-count) (set! (-> (the-as (pointer int32) dst)) value) (&+! dst 4) (nop!)) result)) + (let ((result dst)) + (dotimes (i word-count) + (set! (-> (the-as (pointer int32) dst)) value) + (&+! dst 4) + (nop!)) + result)) (defun mem-or! ((dst pointer) (src pointer) (byte-count int)) "Bitwise-or byte-count bytes from src into dst." @@ -696,7 +748,8 @@ (defun printl ((object object)) "Print a boxed object followed by a newline." - (let ((value object)) ((method-of-type (rtype-of value) print) value)) + (let ((value object)) + ((method-of-type (rtype-of value) print) value)) (format #t "~%") object) @@ -726,7 +779,9 @@ (defun print-tree-bitmask ((bits int) (count int)) "Print one indentation row for a process-tree diagram from the active-column bitmask." (dotimes (i count) - (if (zero? (logand bits 1)) (format #t " ") (format #t "| ")) + (if (not (logtest? bits 1)) + (format #t " ") + (format #t "| ")) (set! bits (shr bits 1))) #f) @@ -767,14 +822,16 @@ (cond ((nonzero? (logand (the-as int this) 3)) ;; alignment is bad! - (if name (format print-dest "ERROR: object #x~X ~S is not a valid object (misaligned)~%" this name)) - '#f) + (if name + (format print-dest "ERROR: object #x~X ~S is not a valid object (misaligned)~%" this name)) + #f) ((not in-goal-mem) ;; address isn't within the memory we expect. - (if name (format print-dest "ERROR: object #x~X ~S is not a valid object (bad address)~%" this name)) - '#f) + (if name + (format print-dest "ERROR: object #x~X ~S is not a valid object (bad address)~%" this name)) + #f) ;; otherwise, we're good! - (else '#t))) ;; end (not expected-type) check + (else #t))) ;; end (not expected-type) check ((and allow-false (not this)) ;; we got a false, but its allowed! ;; note that we don't reject falses otherwise, as false is a perfectly valid symbol. diff --git a/goal_src/jak1/kernel/gkernel.gc b/goal_src/jak1/kernel/gkernel.gc index 2c593cedef..baa78f796b 100644 --- a/goal_src/jak1/kernel/gkernel.gc +++ b/goal_src/jak1/kernel/gkernel.gc @@ -86,10 +86,6 @@ (set! *kernel-packages* (delete! (car pack) *kernel-packages*))) *kernel-packages*)) -(define *test-vec4s* (new 'static 'vec4s :x 0. :y 0. :z 0. :w 0.)) - -(inspect *test-vec4s*) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Kernel Globals ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;