finished GTE Coprrocessor normal clip vod

This commit is contained in:
2025-10-11 03:03:40 -04:00
parent afc0e1a818
commit 7c607e82ab
7 changed files with 99 additions and 32 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ indent_size = 4
indent_style = space
indent_size = 4
[*.{h, c, hpp, cpp}]
[*{.h, .c, .hpp, .cpp}]
indent_style = tab
indent_size = 2
+5 -4
View File
@@ -53,11 +53,12 @@ enum { false = 0, true = 1, true_overflow, };
#define farray_len(array) (SSIZE)sizeof(array) / size_of( typeof((array)[0]))
#define farray_init(type, ...) (type[]){__VA_ARGS__}
#define def_farray_impl(_type, _len) _type A ## _len ## _ ## _type[_len]
#define def_farray_sym(_type, _len) A ## _len ## _ ## _type
#define def_farray_impl(_type, _len) _type def_farray_sym(_type, _len)[_len]; typedef def_ptr_set(def_farray_sym(_type, _len))
#define def_farray(type, len) def_farray_impl(type, len)
#define def_enum(underlying_type, symbol) underlying_type symbol; enum symbol
#define def_struct(symbol) struct symbol symbol; struct symbol
#define def_union(symbol) union symbol symbol; union symbol
#define def_enum(underlying_type, symbol) underlying_type def_tset(symbol); enum symbol
#define def_struct(symbol) struct symbol def_tset(symbol); struct symbol
#define def_union(symbol) union symbol def_tset(symbol); union symbol
#define def_proc(symbol) symbol
#define opt_args(symbol, ...) &(symbol){__VA_ARGS__}
#define ret_type(type) type
+1 -1
View File
@@ -74,7 +74,7 @@ typedef def_enum(U4, gp_Commands) {
#define gp_SetArea_BottomRight (gcmd_SetDrawArea_BotRight << gcmd_offset)
typedef def_struct(RGB8) { B1 r; B1 g; B1 b; };
#define rgba8(r, g, b) (RGB8){ r, g, b }
#define rgb8(r, g, b) (RGB8){ r, g, b }
typedef B1 gp_Pixel16[1];
typedef B1 gp_Pixel24[3];
+4 -1
View File
@@ -7,6 +7,7 @@
#define max(A, B) (((A) > (B)) ? (A) : (B))
#define clamp_bot(X, B) max(X, B)
typedef def_farray(U4, 2);
typedef def_farray(S2, 2);
typedef def_farray(S2, 3);
typedef def_farray(S4, 2);
@@ -27,4 +28,6 @@ typedef def_struct(Rect_S4) { S4 x; S4 y; S4 width; S4 height; };
typedef def_struct(M3_S2) { A3A3_S2 m; A3_S4 t; };
#define v2s2(x, y) (V2_S2){ x, y }
#define v2s2(x,y) (V2_S2){x,y}
#define v3s2(x,y,z) (V3_S2){x,y,z}
#define v3s4(x,y,z) (V3_S4){x,y,z}
+67 -19
View File
@@ -3,6 +3,7 @@
#include "assert.h"
// #include "libgpu.h"
// #include "libetc.h"
// #include "libgte.h"
#include "duffle/dsl.h"
#include "duffle/memory.h"
@@ -11,7 +12,7 @@
#include "hello_gpu.h"
typedef def_farray(V2_S2, 3);
typedef def_struct(TriFlat) {
typedef def_struct(Poly_F3) {
U4 tag;
RGB8 color;
B1 code;
@@ -24,8 +25,14 @@ typedef def_struct(TriFlat) {
A3_V2_S2 points;
};
};
typedef def_struct(Poly_G3) {
U4 tag; RGB8 c0; B1 code;
V2_S2 p0; RGB8 c1; B1 pad1;
V2_S2 p1; RGB8 c2; B1 pad2;
V2_S2 p2;
};
typedef def_farray(V2_S2, 4);
typedef def_struct(QuadFlat) {
typedef def_struct(Poly_F4) {
U4 tag;
RGB8 color;
B1 code;
@@ -39,7 +46,7 @@ typedef def_struct(QuadFlat) {
A4_V2_S2 points;
};
};
typedef def_struct(QuadGouraud) {
typedef def_struct(Poly_G4) {
U4 tag; RGB8 c0; B1 code;
V2_S2 p0; RGB8 c1; B1 pad1;
V2_S2 p1; RGB8 c2; B1 pad2;
@@ -54,7 +61,7 @@ typedef def_struct(Tile) {
};
#define PrimitiveBuff_Len 2048
#define OrderingTbl_Len 256
#define OrderingTbl_Len 1024
typedef U4 OrderingTable_Buffer[OrderingTbl_Len];
typedef def_farray(OrderingTable_Buffer, 2);
@@ -134,7 +141,6 @@ B1* prim__alloc(U4 type_width, Str8 type_name) {
void gp_screen_init_c11(DoubleBuffer* screen_buf, S2* active_buf_id)
{
reset_graph(0);
set_display_enabled(1); // gp_DisplayEnabled
// Set the current initial buffer
active_buf_id[0] = 0;
@@ -150,8 +156,8 @@ void gp_screen_init_c11(DoubleBuffer* screen_buf, S2* active_buf_id)
screen_buf->draw[0].enable_auto_clear = true;
screen_buf->draw[1].enable_auto_clear = true;
// Set the background clear color
screen_buf->draw[0].initial_bg_color = rgba8( .r = 63, .g = 0, .b = 127 );
screen_buf->draw[1].initial_bg_color = rgba8( .r = 127, .g = 63, .b = 0 );
screen_buf->draw[0].initial_bg_color = rgb8( .r = 13, .g = 0, .b = 47 );
screen_buf->draw[1].initial_bg_color = rgb8( .r = 47, .g = 13, .b = 0 );
displayenv_put(& r_(screen_buf->display)[ active_buf_id[0] ]);
drawenv_put (& r_(screen_buf->draw )[ active_buf_id[0] ]);
@@ -159,6 +165,8 @@ void gp_screen_init_c11(DoubleBuffer* screen_buf, S2* active_buf_id)
geom_init();
geom_set_offset(ScreenRes_CenterX, ScreenRes_CenterY);
geom_set_screen(ScreenZ);
set_display_enabled(1); // gp_DisplayEnabled
}
void gp_display_frame(DoubleBuffer* screen_buf, S2* active_buf_id, U4* ordering_buf, PrimitiveArena* pa) {
@@ -187,11 +195,48 @@ void update(PrimitiveArena* pa, U4* ordering_buf)
gte_matrix_set_rotation (& static_mem.tform_world);
gte_matrix_set_translation(& static_mem.tform_world);
// TriFlat* tri = prim_alloc(TriFlat); set_tri_flat(tri);
// tri->color = rgba8(255, 0, 0);
#if 1
S4 nclip = 0;
S4 orderingtbl_z = 0;
A2_S2 p; //???
S4 flag; //????
S4 otz = 0;
// otz += vec_3s16_rtp(& )
for (U4 face_id = 0; face_id < Cube_num_faces; face_id += 1)
{
Poly_G3* tri = prim_alloc(Poly_G3); set_poly_g3(tri);
tri->c0 = rgb8(255, 0, 255);
tri->c1 = rgb8(255, 255, 0);
tri->c2 = rgb8( 0, 255, 255);
V3_S2* face = & static_mem.cube_faces[face_id];
V3_S2* p0 = & static_mem.cube_verts[face->x];
V3_S2* p1 = & static_mem.cube_verts[face->y];
V3_S2* p2 = & static_mem.cube_verts[face->z];
// orderingtbl_z = 0;
// orderingtbl_z += rtp_v3s2(p0, & tri->p0, & p, & flag);
// orderingtbl_z += rtp_v3s2(p1, & tri->p1, & p, & flag);
// orderingtbl_z += rtp_v3s2(p2, & tri->p2, & p, & flag);
// orderingtbl_z /= 3;
nclip = rtp_avg_nclip_a3_v3s2(
p0, p1, p2,
& tri->p0, & tri->p1, & tri->p2,
& p, & orderingtbl_z, & flag
);
if (nclip <= 0) {
continue;
}
if ((orderingtbl_z > 0) && (orderingtbl_z < OrderingTbl_Len)) {
orderingtbl_add_primitive(ordering_buf[orderingtbl_z], tri);
}
}
static_mem.rotation.x += 6;
static_mem.rotation.y += 8;
static_mem.rotation.z += 12;
#endif
#if 0
Tile* tile = prim_alloc(Tile); set_tile(tile);
@@ -199,29 +244,29 @@ void update(PrimitiveArena* pa, U4* ordering_buf)
tile->color = (RGB8){ 0, 255, 0};
orderingtbl_add_primitive(ordering_buf, tile);
TriFlat* tri = prim_alloc(TriFlat); set_tri_flat(tri);
Poly_F3* tri = prim_alloc(Poly_F3); set_poly_f3(tri);
tri->p0 = v2s2(64, 100);
tri->p1 = v2s2(200, 150);
tri->p2 = v2s2(50, 220);
tri->color = rgba8(255, 0, 255);
tri->color = rgb8(255, 0, 255);
orderingtbl_add_primitive(ordering_buf, tri);
QuadGouraud* quad = prim_alloc(QuadGouraud); set_quad_gouraud(quad);
Poly_G4* quad = prim_alloc(Poly_G4); set_poly_g4(quad);
quad->p0 = v2s2(140, 50);
quad->p1 = v2s2(200, 40);
quad->p2 = v2s2(170, 120);
quad->p3 = v2s2(220, 80);
quad->c0 = rgba8(255, 0, 0);
quad->c1 = rgba8(0, 255, 0);
quad->c3 = rgba8(0, 0, 255);
quad->c0 = rgb8(255, 0, 0);
quad->c1 = rgb8(0, 255, 0);
quad->c3 = rgb8(0, 0, 255);
orderingtbl_add_primitive(ordering_buf, quad);
QuadFlat* quadf = prim_alloc(QuadFlat); set_quad_flat(quadf);
Poly_F4* quadf = prim_alloc(Poly_F4); set_poly_f4(quadf);
quadf->p0 = v2s2(140 + 15, 50 + 9);
quadf->p1 = v2s2(200 + 15, 40 + 9);
quadf->p2 = v2s2(170 + 15, 120 + 9);
quadf->p3 = v2s2(220 + 15, 80 + 9);
quadf->color = rgba8(22, 22, 22);
quadf->color = rgb8(22, 22, 22);
orderingtbl_add_primitive(ordering_buf, quadf);
#endif
}
@@ -230,6 +275,9 @@ int main(void)
{
static_mem.primitives.used = 0;
cube128_init(& static_mem.cube_verts, & static_mem.cube_faces);
static_mem.rotation = v3s2(0, 0, 0);
static_mem.translation = v3s4(0, 0, 900);
static_mem.scale = v3s4(m3s2_one, m3s2_one, m3s2_one);
gknown gp_screen_init();
// gp_screen_init_c11(& static_mem.screen_buf, & static_mem.active_screen_buf);
while (1)
+20 -5
View File
@@ -81,13 +81,13 @@ typedef def_struct(PolyTag) {
#define orderingtbl_add_primitives(ot, p0, p1) set_addr(p1, get_addr(ot)), set_addr(ot, p0)
/* Primitive Length Code */
#define set_tri_flat(p) set_len(p, 4), set_code(p, 0x20)
#define set_poly_f3(p) set_len(p, 4), set_code(p, 0x20)
// #define setPolyFT3(p) set_len(p, 7), set_code(p, 0x24)
// #define setPolyG3(p) set_len(p, 6), set_code(p, 0x30)
#define set_poly_g3(p) set_len(p, 6), set_code(p, 0x30)
// #define setPolyGT3(p) set_len(p, 9), set_code(p, 0x34)
#define set_quad_flat(p) set_len(p, 5), set_code(p, 0x28)
#define set_poly_f4(p) set_len(p, 5), set_code(p, 0x28)
// #define setPolyFT4(p) set_len(p, 9), set_code(p, 0x2c)
#define set_quad_gouraud(p) set_len(p, 8), set_code(p, 0x38)
#define set_poly_g4(p) set_len(p, 8), set_code(p, 0x38)
// #define setPolyGT4(p) set_len(p, 12), set_code(p, 0x3c)
// #define setSprt8(p) setlen(p, 3), setcode(p, 0x74)
@@ -113,7 +113,22 @@ M3_S2* m3s2_rotation (V3_S2* vec, M3_S2* mat) __asm__("RotMatrix");
M3_S2* m3s2_translation(M3_S2* mat, V3_S4* vec) __asm__("TransMatrix");
M3_S2* m3s2_scale (M3_S2* mat, V3_S4* vec) __asm__("ScaleMatrix");
S4 v3s2_rtp(V3_S2* vec, A2_S2 xy, A2_S2* pp, S4* flag) __asm__("RotTransPers"); // Rotation, Translate, Perspective
S4 rtp_v3s2_raw(V3_S2* vec, S4* xy, S4* pp, S4* flag) __asm__("RotTransPers"); // Rotation, Translate, Perspective
finline S4 rtp_v3s2(V3_S2* vec, V2_S2* xy, A2_S2* pp, S4* flag) { return rtp_v3s2_raw(vec, cast(S4*R_, & xy->x), cast(S4*R_, pp), r_(flag)); }
S4 rtp_avg_nclip_a3_v3s2_raw(V3_S2* v0, V3_S2* v1, V3_S2* v2, S4* xy1, S4* xy2, S4* xy3, S4* pp, S4* otz, S4* flag) __asm__("RotAverageNclip3");
finline S4 rtp_avg_nclip_a3_v3s2(
V3_S2* v0, V3_S2* v1, V3_S2* v2,
V2_S2* xy0, V2_S2* xy1, V2_S2* xy2,
A2_S2* pp, S4* otz, S4* flag) {
return rtp_avg_nclip_a3_v3s2_raw(
v0, v1, v2,
cast(S4*R_, xy0), cast(S4*R_, xy1), cast(S4*R_, xy2),
cast(S4*R_, pp), cast(S4*R_, otz), cast(S4*R_, flag)
);
}
void gte_matrix_set_rotation (M3_S2* mat) __asm__("SetRotMatrix");
void gte_matrix_set_translation(M3_S2* mat) __asm__("SetTransMatrix");
#define m3s2_one (1 << 12)
+1 -1
View File
@@ -133,7 +133,7 @@ gp_screen_init_asm:
store_word rtmp_1, DoubleBuffer_draw_1 + DrawEnv_enable_auto_clear(rtmp_0)
// Set background clear color
move rtmp_1, $zero; load_imm rtmp_2, 63; load_imm rtmp_3, 127
load_imm rtmp_1, 28; load_imm rtmp_2, 22; load_imm rtmp_3, 25
// 63, 0, 127
store_byte rtmp_2, DoubleBuffer_draw_0 + DrawEnv_initial_bg_color + RGB8_r(rtmp_0)
store_byte rtmp_1, DoubleBuffer_draw_0 + DrawEnv_initial_bg_color + RGB8_g(rtmp_0)