minor changes

This commit is contained in:
2025-09-15 01:51:46 -04:00
parent f35e60877c
commit fd61fc56db
2 changed files with 30 additions and 25 deletions
+6 -1
View File
@@ -42,7 +42,6 @@ enum {
#define internal static #define internal static
#define global #define global
#define gknown #define gknown
#define ct_lit
#define offset_of(type, member) cast(SSIZE, & (((type*) 0)->member)) #define offset_of(type, member) cast(SSIZE, & (((type*) 0)->member))
#define static_assert _Static_assert #define static_assert _Static_assert
#define typeof __typeof__ #define typeof __typeof__
@@ -58,6 +57,12 @@ enum {
#define giga(n) (cast(SSIZE, n) << 30) #define giga(n) (cast(SSIZE, n) << 30)
#define tera(n) (cast(SSIZE, n) << 40) #define tera(n) (cast(SSIZE, n) << 40)
#if 1
# define dbg_args(...) __VA_ARGS__
#else
# define dbg_args(...)
#endif
#define span_iter(type, iter, m_begin, op, m_end) \ #define span_iter(type, iter, m_begin, op, m_end) \
tmpl(Iter_Span,type) iter = { \ tmpl(Iter_Span,type) iter = { \
.r = {(m_begin), (m_end)}, \ .r = {(m_begin), (m_end)}, \
+24 -24
View File
@@ -40,10 +40,10 @@ typedef def_struct(QuadFlat) {
}; };
}; };
typedef def_struct(Tile) { typedef def_struct(Tile) {
U32 tag; U32 tag;
RGB8 color; RGB8 color;
BYTE code; BYTE code;
Rect_S16 rect; Rect_S16 rect;
}; };
#define PrimitiveBuff_Len 2048 #define PrimitiveBuff_Len 2048
@@ -63,22 +63,22 @@ typedef def_struct(SMemory) {
DoubleBuffer screen_buf; DoubleBuffer screen_buf;
A2_OrderingTable_Buffer ordering_tbl; A2_OrderingTable_Buffer ordering_tbl;
PrimitiveArena primitives; PrimitiveArena primitives;
S16 active_screen_buf; S16 active_buf_id;
}; };
global SMemory static_mem; global SMemory static_mem;
extern SMemory static_mem; extern SMemory static_mem;
BYTE* prim__alloc(SSIZE type_width, ct_lit Str8 type_name) { BYTE* prim__alloc(SSIZE type_width, dbg_args(Str8 type_name)) {
gknown PrimitiveArena* pa = & static_mem.primitives; gknown PrimitiveArena* pa = & static_mem.primitives;
gknown BYTE* buf = (BYTE*) static_mem.primitives.buf[static_mem.active_screen_buf]; gknown BYTE* buf = (BYTE*) static_mem.primitives.buf[static_mem.active_buf_id];
assert(pa->used + type_width < PrimitiveBuff_Len); assert(pa->used + type_width < PrimitiveBuff_Len);
BYTE* next = buf + pa->used; BYTE* next = buf + pa->used;
pa->used += type_width; pa->used += type_width;
return next; return next;
} }
#define prim_alloc(type) (type*)prim__alloc(size_of(type), txt( stringify(type) )) #define prim_alloc(type) (type*)prim__alloc(size_of(type), txt( stringify(type)))
void gp_screen_init_c11(DoubleBuffer* screen_buf, S16* active_screen_buf) void gp_screen_init_c11(DoubleBuffer* screen_buf, S16* active_buf_id)
{ {
ResetGraph(0); ResetGraph(0);
SetDispMask(1); // gp_DisplayEnabled SetDispMask(1); // gp_DisplayEnabled
@@ -97,11 +97,11 @@ void gp_screen_init_c11(DoubleBuffer* screen_buf, S16* active_screen_buf)
screen_buf->draw[0].initial_bg_color = (RGB8){ .r = 63, .g = 0, .b = 127 }; screen_buf->draw[0].initial_bg_color = (RGB8){ .r = 63, .g = 0, .b = 127 };
screen_buf->draw[1].initial_bg_color = (RGB8){ .r = 127, .g = 63, .b = 0 }; screen_buf->draw[1].initial_bg_color = (RGB8){ .r = 127, .g = 63, .b = 0 };
// Set the current initial buffer // Set the current initial buffer
* active_screen_buf = 0; * active_buf_id = 0;
PutDispEnv((DISPENV*)& screen_buf->display[* active_screen_buf]); PutDispEnv((DISPENV*)& screen_buf->display[* active_buf_id]);
DRAWENV* env = (DRAWENV*)& screen_buf->draw[* active_screen_buf]; DRAWENV* env = (DRAWENV*)& screen_buf->draw[* active_buf_id];
PutDrawEnv(env); PutDrawEnv(env);
// Initialize and setup the GTE geometry offsets // Initialize and setup the GTE geometry offsets
@@ -111,23 +111,22 @@ void gp_screen_init_c11(DoubleBuffer* screen_buf, S16* active_screen_buf)
SetGeomScreen(ScreenRes_CenterX); SetGeomScreen(ScreenRes_CenterX);
} }
void gp_display_frame(DoubleBuffer* screen_buf, S16* active_screen_buf, U32* ordering_buf) { void gp_display_frame(DoubleBuffer* screen_buf, S16* active_buf_id, U32* ordering_buf, PrimitiveArena* pa) {
DrawSync(0); DrawSync(0);
VSync(0); VSync(0);
PutDispEnv((DISPENV*)& screen_buf->display[* active_screen_buf]); PutDispEnv((DISPENV*)& screen_buf->display[* active_buf_id]);
PutDrawEnv((DRAWENV*)& screen_buf->draw [* active_screen_buf]); PutDrawEnv((DRAWENV*)& screen_buf->draw [* active_buf_id]);
{ {
DrawOTag((u_long*) (ordering_buf + OrderingTbl_Len - 1)); DrawOTag((u_long*) (ordering_buf + OrderingTbl_Len - 1));
} }
* active_screen_buf = ! (* active_screen_buf); // Swap current buffer * active_buf_id = ! (* active_buf_id); // Swap current buffer
pa->used = 0;
gknown static_mem.primitives.used = 0;
} }
void render(void) { void render(void) {
} }
void update(PrimitiveArena* pa, S16 active_screen_buff, U32* ordering_buf) { void update(PrimitiveArena* pa, U32* ordering_buf) {
ClearOTagR((u_long*) ordering_buf, OrderingTbl_Len); ClearOTagR((u_long*) ordering_buf, OrderingTbl_Len);
@@ -147,15 +146,16 @@ void update(PrimitiveArena* pa, S16 active_screen_buff, U32* ordering_buf) {
int main(void) int main(void)
{ {
static_mem.primitives.used = 0; static_mem.primitives.used = 0;
gp_screen_init(); gknown gp_screen_init();
// gp_screen_init_c11(& static_mem.screen_buf, & static_mem.active_screen_buf); // gp_screen_init_c11(& static_mem.screen_buf, & static_mem.active_screen_buf);
while (1) while (1)
{ {
gknown S16* active_screen = & static_mem.active_screen_buf; gknown S16* active_buf_id = & static_mem.active_buf_id;
gknown U32* ordering_buf = static_mem.ordering_tbl[* active_screen]; gknown U32* ordering_buf = static_mem.ordering_tbl[* active_buf_id];
update(& static_mem.primitives, * active_screen, ordering_buf); gknown PrimitiveArena* pa = & static_mem.primitives;
update(pa, ordering_buf);
render(); render();
gp_display_frame(& static_mem.screen_buf, active_screen, ordering_buf); gp_display_frame(& static_mem.screen_buf, active_buf_id, ordering_buf, pa);
}; };
return 0; return 0;
} }