summaryrefslogtreecommitdiff
path: root/rtl/legacy_gfx/gfx_fix_vertex.sv
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2024-05-05 17:34:22 -0600
committerAlejandro Soto <alejandro@34project.org>2024-05-05 17:38:27 -0600
commit081a8a3ba8bfe036f31da53f9c041a2caa30fce2 (patch)
tree7d712b67d3dc1ad3d37041562774ba3c4e5a7f49 /rtl/legacy_gfx/gfx_fix_vertex.sv
parente5b64ea353678baabd16d245fcfaa3384e1acf8f (diff)
rtl/legacy_gfx: rename gfx -> legacy_gfx
Diffstat (limited to 'rtl/legacy_gfx/gfx_fix_vertex.sv')
-rw-r--r--rtl/legacy_gfx/gfx_fix_vertex.sv64
1 files changed, 64 insertions, 0 deletions
diff --git a/rtl/legacy_gfx/gfx_fix_vertex.sv b/rtl/legacy_gfx/gfx_fix_vertex.sv
new file mode 100644
index 0000000..728f3b6
--- /dev/null
+++ b/rtl/legacy_gfx/gfx_fix_vertex.sv
@@ -0,0 +1,64 @@
+`include "gfx/gfx_defs.sv"
+
+module gfx_fix_vertex
+(
+ input logic clk,
+
+ input vec4 in_vertex,
+ input logic stall,
+
+ output raster_xyzw out_vertex
+);
+
+ fixed x, y;
+ raster_xyzw fixed_vertex, corrected;
+ fixed[`FLOATS_PER_VEC - 1:0] fixed_vals, corrected_vals, skid_vals;
+
+ assign out_vertex = skid_vals;
+ assign fixed_vertex = fixed_vals;
+ assign corrected_vals = corrected;
+
+ assign x = fixed_vertex.xy.x;
+ assign y = fixed_vertex.xy.y;
+
+ genvar i;
+ generate
+ for (i = 0; i < `FLOATS_PER_VEC; ++i) begin: components
+ gfx_fp_fix fix
+ (
+ .in(in_vertex[i]),
+ .out(fixed_vals[i]),
+ .*
+ );
+
+ gfx_skid_buf #(.WIDTH($bits(fixed))) skid
+ (
+ .in(corrected_vals[i]),
+ .out(skid_vals[i]),
+ .*
+ );
+ end
+ endgenerate
+
+ always_ff @(posedge clk)
+ if (!stall) begin
+ /* x * `GFX_X_RES / 2
+ * = x * 320
+ * = x * 64 * 5
+ * = (x * 5) << 6
+ * = (x * (4 + 1)) << 6
+ * = ((x << 2) + x) << 6
+ *
+ * y * `GFX_Y_RES / 2
+ * = y * 240
+ * = y * 16 * 15
+ * = (y * 15) << 4
+ * = (y * (16 - 1)) << 4
+ * = ((y << 4) - y) << 4
+ */
+ corrected.zw <= fixed_vertex.zw;
+ corrected.xy.x <= ((x << 2) + x) << 6;
+ corrected.xy.y <= ((y << 4) - y) << 4;
+ end
+
+endmodule