Sorting Primitives into the OT

Started to add some ergonomic definitions into duffle.
This commit is contained in:
2025-09-15 01:36:25 -04:00
parent e04bcb91b4
commit f35e60877c
10 changed files with 383 additions and 49 deletions
+43 -2
View File
@@ -1,5 +1,6 @@
#ifdef INTELLISENSE_DIRECTIVES
# pragma once
# include "assert.h"
#endif
typedef unsigned char U8;
@@ -27,7 +28,7 @@ enum {
#define alignas _Alignas
#define alignof _Alignof
#define byte_pad(amount, ...) Byte glue(_PAD_, __VA_ARGS__) [amount]
#define byte_pad(amount, ...) BYTE glue(_PAD_, __VA_ARGS__) [amount]
#define farray_len(array) (SSIZE)sizeof(array) / size_of( typeof((array)[0]))
#define farray_init(type, ...) (type[]){__VA_ARGS__}
#define def_farray(type, len) type A ## len ## _ ## type[len]
@@ -38,7 +39,10 @@ enum {
#define opt_args(symbol, ...) &(symbol){__VA_ARGS__}
#define ret_type(type) type
#define local_persist static
#define global static
#define internal static
#define global
#define gknown
#define ct_lit
#define offset_of(type, member) cast(SSIZE, & (((type*) 0)->member))
#define static_assert _Static_assert
#define typeof __typeof__
@@ -70,3 +74,40 @@ typedef def_span(U32);
typedef def_span(SSIZE);
typedef void def_proc(VoidFn) (void);
#define def_Slice(type) \
def_struct(tmpl(Slice,type)) { \
type* ptr; \
SSIZE len; \
}
#define slice_assert(slice) do { assert((slice).ptr != nullptr); assert((slice).len > 0); } while(0)
#define slice_end(slice) ((slice).ptr + (slice).len)
#define size_of_slice_type(slice) size_of( * (slice).ptr )
typedef def_Slice(void);
typedef def_Slice(BYTE);
#define slice_byte(slice) ((Slice_BYTE){cast(Byte*, (slice).ptr), (slice).len * size_of_slice_type(slice)})
#define slice_fmem(mem) ((Slice_BYTE){ mem, size_of(mem) })
void slice__copy(Slice_BYTE dest, SSIZE dest_typewidth, Slice_BYTE src, SSIZE src_typewidth);
void slice__zero(Slice_BYTE mem, SSIZE typewidth);
#define slice_copy(dest, src) do { \
static_assert(typeof_same(dest, src)); \
slice__copy(slice_byte(dest), size_of_slice_type(dest), slice_byte(src), size_of_slice_type(src)); \
} while (0)
#define slice_zero(slice) slice__zero(slice_byte(slice), size_of_slice_type(slice))
#define slice_iter(container, iter) \
typeof((container).ptr) iter = (container).ptr; \
iter != slice_end(container); \
++ iter
#define slice_arg_from_array(type, ...) & (tmpl(Slice,type)) { \
.ptr = farray_init(type, __VA_ARGS__), \
.len = farray_len( farray_init(type, __VA_ARGS__)) \
}
typedef unsigned char UTF8;
typedef def_Slice(UTF8);
typedef Slice_UTF8 Str8;
typedef def_Slice(Str8);
#define txt(string_literal) (Str8){ (UTF8*) string_literal, size_of(string_literal) - 1 }
+31
View File
@@ -0,0 +1,31 @@
#ifdef INTELLISENSE_DIRECTIVES
# pragma once
# include "dsl.h"
# include "memory.h"
# include "strings.h"
#endif
typedef def_struct(Opts_farena) {
Str8 type_name;
SSIZE alignment;
};
typedef def_struct(FArena) {
void* start;
SSIZE capacity;
SSIZE used;
};
FArena farena_make (Slice_BYTE mem);
void farena_init (FArena* arena, Slice_BYTE byte);
Slice_BYTE farena__push (FArena* arena, SSIZE amount, SSIZE type_width, Opts_farena* opts);
void farena_reset (FArena* arena);
void farena_rewind(FArena* arena, AllocatorSP save_point);
AllocatorSP farena_save (FArena arena);
// void farena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out);
// #define ainfo_farena(arena) (AllocatorInfo){ .proc = farena_allocator_proc, .data = & arena }
#define farena_push(arena, type, ...) \
cast(type*, farena__push(arena, size_of(type), 1, opt_args(Opts_farena_push, lit(stringify(type)), __VA_ARGS__))).ptr
#define farena_push_array(arena, type, amount, ...) \
(Slice ## type){ farena__push(arena, size_of(type), amount, opt_args(Opts_farena_push, lit(stringify(type)), __VA_ARGS__)).ptr, amount }
+4
View File
@@ -3,6 +3,10 @@
# include "dsl.h"
#endif
#define min(A, B) (((A) < (B)) ? (A) : (B))
#define max(A, B) (((A) > (B)) ? (A) : (B))
#define clamp_bot(X, B) max(X, B)
typedef def_farray(S16, 2);
typedef def_farray(S32, 2);
// typedef def_farray(F32, 2);
+142
View File
@@ -0,0 +1,142 @@
#ifdef INTELLISENSE_DIRECTIVES
# pragma once
# include "dsl.h"
#endif
inline SSIZE align_pow2(SSIZE x, SSIZE b) {
assert(b != 0);
assert((b & (b - 1)) == 0); // Check power of 2
return ((x + b - 1) & (~(b - 1)));
}
#define align_struct(type_width) ((SSIZE)(((type_width) + 3) & ~3))
#define assert_bounds(point, start, end) do { \
SSIZE pos_point = cast(SSIZE, point); \
SSIZE pos_start = cast(SSIZE, start); \
SSIZE pos_end = cast(SSIZE, end); \
assert(pos_start <= pos_point); \
assert(pos_point <= pos_end); \
} while(0)
// void* memory_copy (void* restrict dest, void const* restrict src, USIZE length);
// void* memory_copy_overlapping(void* restrict dest, void const* restrict src, USIZE length);
// B32 memory_zero (void* dest, USIZE length);
#define check_nil(nil, p) ((p) == 0 || (p) == nil)
#define set_nil(nil, p) ((p) = nil)
#define sll_stack_push_n(f, n, next) do { (n)->next = (f); (f) = (n); } while(0)
#define sll_queue_push_nz(nil, f, l, n, next) \
( \
check_nil(nil, f) ? ( \
(f) = (l) = (n), \
set_nil(nil, (n)->next) \
) \
: ( \
(l)->next=(n), \
(l) = (n), \
set_nil(nil,(n)->next) \
) \
)
#define sll_queue_push_n(f, l, n, next) sll_queue_push_nz(0, f, l, n, next)
#pragma region Allocator Interface
typedef def_enum(U32, AllocatorOp) {
AllocatorOp_Alloc_NoZero = 0, // If Alloc exist, so must No_Zero
AllocatorOp_Alloc,
AllocatorOp_Free,
AllocatorOp_Reset,
AllocatorOp_Grow_NoZero,
AllocatorOp_Grow,
AllocatorOp_Shrink,
AllocatorOp_Rewind,
AllocatorOp_SavePoint,
AllocatorOp_Query, // Must always be implemented
};
typedef def_enum(U32, AllocatorQueryFlags) {
AllocatorQuery_Alloc = (1 << 0),
AllocatorQuery_Free = (1 << 1),
// Wipe the allocator's state
AllocatorQuery_Reset = (1 << 2),
// Supports both grow and shrink
AllocatorQuery_Shrink = (1 << 4),
AllocatorQuery_Grow = (1 << 5),
AllocatorQuery_Resize = AllocatorQuery_Grow | AllocatorQuery_Shrink,
// Ability to rewind to a save point (ex: arenas, stack), must also be able to save such a point
AllocatorQuery_Rewind = (1 << 6),
};
typedef struct AllocatorProc_In AllocatorProc_In;
typedef struct AllocatorProc_Out AllocatorProc_Out;
typedef void def_proc(AllocatorProc) (AllocatorProc_In In, AllocatorProc_Out* Out);
typedef def_struct(AllocatorSP) {
AllocatorProc* type_sig;
SSIZE slot;
};
struct AllocatorProc_In {
void* data;
SSIZE requested_size;
SSIZE alignment;
union {
Slice_BYTE old_allocation;
AllocatorSP save_point;
};
AllocatorOp op;
byte_pad(4);
};
struct AllocatorProc_Out {
union {
Slice_BYTE allocation;
AllocatorSP save_point;
};
AllocatorQueryFlags features;
SSIZE left; // Contiguous memory left
SSIZE max_alloc;
SSIZE min_alloc;
B32 continuity_break; // Whether this allocation broke continuity with the previous (address space wise)
byte_pad(4);
};
typedef def_struct(AllocatorInfo) {
AllocatorProc* proc;
void* data;
};
static_assert(size_of(AllocatorSP) <= size_of(Slice_BYTE));
typedef def_struct(AllocatorQueryInfo) {
AllocatorSP save_point;
AllocatorQueryFlags features;
SSIZE left; // Contiguous memory left
SSIZE max_alloc;
SSIZE min_alloc;
B32 continuity_break; // Whether this allocation broke continuity with the previous (address space wise)
byte_pad(4);
};
static_assert(size_of(AllocatorProc_Out) == size_of(AllocatorQueryInfo));
#define MEMORY_ALIGNMENT_DEFAULT (2 * size_of(void*))
AllocatorQueryInfo allocator_query(AllocatorInfo ainfo);
void mem_free (AllocatorInfo ainfo, Slice_BYTE mem);
void mem_reset (AllocatorInfo ainfo);
void mem_rewind (AllocatorInfo ainfo, AllocatorSP save_point);
AllocatorSP mem_save_point(AllocatorInfo ainfo);
typedef def_struct(Opts_mem_alloc) { SSIZE alignment; B32 no_zero; byte_pad(4); };
typedef def_struct(Opts_mem_grow) { SSIZE alignment; B32 no_zero; byte_pad(4); };
typedef def_struct(Opts_mem_shrink) { SSIZE alignment; };
typedef def_struct(Opts_mem_resize) { SSIZE alignment; B32 no_zero; byte_pad(4); };
Slice_BYTE mem__alloc (AllocatorInfo ainfo, SSIZE size, Opts_mem_alloc* opts);
Slice_BYTE mem__grow (AllocatorInfo ainfo, Slice_BYTE mem, SSIZE size, Opts_mem_grow* opts);
Slice_BYTE mem__resize(AllocatorInfo ainfo, Slice_BYTE mem, SSIZE size, Opts_mem_resize* opts);
Slice_BYTE mem__shrink(AllocatorInfo ainfo, Slice_BYTE mem, SSIZE size, Opts_mem_shrink* opts);
#define mem_alloc(ainfo, size, ...) mem__alloc (ainfo, size, opt_args(Opts_mem_alloc, __VA_ARGS__))
#define mem_grow(ainfo, mem, size, ...) mem__grow (ainfo, mem, size, opt_args(Opts_mem_grow, __VA_ARGS__))
#define mem_resize(ainfo, mem, size, ...) mem__resize(ainfo, mem, size, opt_args(Opts_mem_resize, __VA_ARGS__))
#define mem_shrink(ainfo, mem, size, ...) mem__shrink(ainfo, mem, size, opt_args(Opts_mem_shrink, __VA_ARGS__))
#define alloc_type(ainfo, type, ...) (type*) mem__alloc(ainfo, size_of(type), opt_args(Opts_mem_alloc, __VA_ARGS__)).ptr
#define alloc_slice(ainfo, type, num, ...) (tmpl(Slice,type)){ mem__alloc(ainfo, size_of(type) * num, opt_args(Opts_mem_alloc, __VA_ARGS__)).ptr, num }
#pragma endregion Allocator Interface
+5
View File
@@ -0,0 +1,5 @@
#ifdef INTELLISENSE_DIRECTIVES
# pragma once
# include "dsl.h"
# include "memory.h"
#endif
+116 -24
View File
@@ -1,40 +1,108 @@
// #include <stdlib.h>
#include "stdio.h"
#include <stdlib.h>
#include "assert.h"
#include "libgpu.h"
#include "libetc.h"
#include "duffle/dsl.h"
#include "duffle/memory.h"
#include "duffle/math.h"
#include "duffle/gp.h"
#include "hello_gpu.h"
#include "libgpu.h"
#include "libetc.h"
typedef def_farray(Vec_2S16, 3);
typedef def_struct(TriFlat) {
U32 tag;
RGB8 color;
BYTE code;
union {
struct {
Vec_2S16 p0;
Vec_2S16 p1;
Vec_2S16 p2;
};
A3_Vec_2S16 points;
};
};
typedef def_farray(Vec_2S16, 4);
typedef def_struct(QuadFlat) {
U32 tag;
RGB8 color;
BYTE code;
union {
struct {
Vec_2S16 p0;
Vec_2S16 p1;
Vec_2S16 p2;
Vec_2S16 p3;
};
A4_Vec_2S16 points;
};
};
typedef def_struct(Tile) {
U32 tag;
RGB8 color;
BYTE code;
Rect_S16 rect;
};
DoubleBuffer screen_buffer;
S16 active_screen_buffer;
#define PrimitiveBuff_Len 2048
#define OrderingTbl_Len 16
void gp_screen_init_c11(void)
typedef U32 OrderingTable_Buffer[OrderingTbl_Len];
typedef def_farray(OrderingTable_Buffer, 2);
typedef BYTE PrimitiveBuffer[PrimitiveBuff_Len];
typedef def_farray(PrimitiveBuffer, 2);
typedef def_struct(PrimitiveArena) {
A2_PrimitiveBuffer buf;
SSIZE used;
};
typedef def_struct(SMemory) {
DoubleBuffer screen_buf;
A2_OrderingTable_Buffer ordering_tbl;
PrimitiveArena primitives;
S16 active_screen_buf;
};
global SMemory static_mem;
extern SMemory static_mem;
BYTE* prim__alloc(SSIZE type_width, ct_lit Str8 type_name) {
gknown PrimitiveArena* pa = & static_mem.primitives;
gknown BYTE* buf = (BYTE*) static_mem.primitives.buf[static_mem.active_screen_buf];
assert(pa->used + type_width < PrimitiveBuff_Len);
BYTE* next = buf + pa->used;
pa->used += type_width;
return next;
}
#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)
{
ResetGraph(0);
SetDispMask(1); // gp_DisplayEnabled
// Just setting env data, not interacting with console hw.
// First buffer area
SetDefDispEnv((DISPENV*)& screen_buffer.display[0], 0, 0, ScreenRes_X, ScreenRes_Y);
SetDefDrawEnv((DRAWENV*)& screen_buffer.draw [0], 0, ScreenRes_Y, ScreenRes_X, ScreenRes_Y);
SetDefDispEnv((DISPENV*)& screen_buf->display[0], 0, 0, ScreenRes_X, ScreenRes_Y);
SetDefDrawEnv((DRAWENV*)& screen_buf->draw [0], 0, ScreenRes_Y, ScreenRes_X, ScreenRes_Y);
// Second buffer area
SetDefDispEnv((DISPENV*)& screen_buffer.display[1], 0, ScreenRes_Y, ScreenRes_X, ScreenRes_Y);
SetDefDrawEnv((DRAWENV*)& screen_buffer.draw [1], 0, 0, ScreenRes_X, ScreenRes_Y);
SetDefDispEnv((DISPENV*)& screen_buf->display[1], 0, ScreenRes_Y, ScreenRes_X, ScreenRes_Y);
SetDefDrawEnv((DRAWENV*)& screen_buf->draw [1], 0, 0, ScreenRes_X, ScreenRes_Y);
// Set the back/drawing buffer
screen_buffer.draw[0].enable_auto_clear = true;
screen_buffer.draw[1].enable_auto_clear = true;
screen_buf->draw[0].enable_auto_clear = true;
screen_buf->draw[1].enable_auto_clear = true;
// Set the background clear color
screen_buffer.draw[0].initial_bg_color = (RGB8){ .r = 63, .g = 0, .b = 127 };
screen_buffer.draw[1].initial_bg_color = (RGB8){ .r = 127, .g = 63, .b = 0 };
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 };
// Set the current initial buffer
active_screen_buffer = 0;
* active_screen_buf = 0;
PutDispEnv((DISPENV*)& screen_buffer.display[active_screen_buffer]);
PutDispEnv((DISPENV*)& screen_buf->display[* active_screen_buf]);
DRAWENV* wtf = (DRAWENV*)& screen_buffer.draw [active_screen_buffer];
PutDrawEnv(wtf);
DRAWENV* env = (DRAWENV*)& screen_buf->draw[* active_screen_buf];
PutDrawEnv(env);
// Initialize and setup the GTE geometry offsets
InitGeom();
@@ -43,27 +111,51 @@ void gp_screen_init_c11(void)
SetGeomScreen(ScreenRes_CenterX);
}
void gp_display_frame(void) {
void gp_display_frame(DoubleBuffer* screen_buf, S16* active_screen_buf, U32* ordering_buf) {
DrawSync(0);
VSync(0);
PutDispEnv((DISPENV*)& screen_buffer.display[active_screen_buffer]);
PutDrawEnv((DRAWENV*)& screen_buffer.draw [active_screen_buffer]);
PutDispEnv((DISPENV*)& screen_buf->display[* active_screen_buf]);
PutDrawEnv((DRAWENV*)& screen_buf->draw [* active_screen_buf]);
{
// TODO: Sort objects in ordering table
DrawOTag((u_long*) (ordering_buf + OrderingTbl_Len - 1));
}
active_screen_buffer = !active_screen_buffer; // Swap current buffer
* active_screen_buf = ! (* active_screen_buf); // Swap current buffer
gknown static_mem.primitives.used = 0;
}
void render(void) {
}
void update(PrimitiveArena* pa, S16 active_screen_buff, U32* ordering_buf) {
ClearOTagR((u_long*) ordering_buf, OrderingTbl_Len);
Tile* tile = prim_alloc(Tile); setTile((TILE*) tile);
tile->rect = (Rect_S16){ 82, 32, 64, 64 };
tile->color = (RGB8){ 0, 255, 0};
addPrim(ordering_buf, tile);
TriFlat* tri = prim_alloc(TriFlat); setPolyF3(tri);
tri->p0 = (Vec_2S16){ 64, 100};
tri->p1 = (Vec_2S16){200, 150};
tri->p2 = (Vec_2S16){ 50, 220};
tri->color = (RGB8){ 255, 0, 255 };
addPrim(ordering_buf, tri);
}
int main(void)
{
static_mem.primitives.used = 0;
gp_screen_init();
// gp_screen_init_c11(& static_mem.screen_buf, & static_mem.active_screen_buf);
while (1)
{
gknown S16* active_screen = & static_mem.active_screen_buf;
gknown U32* ordering_buf = static_mem.ordering_tbl[* active_screen];
update(& static_mem.primitives, * active_screen, ordering_buf);
render();
gp_display_frame();
gp_display_frame(& static_mem.screen_buf, active_screen, ordering_buf);
};
return 0;
}
-3
View File
@@ -36,6 +36,3 @@ typedef def_struct(DoubleBuffer) {
#define ScreenRes_Y 240
#define ScreenRes_CenterX (ScreenRes_X >> 1)
#define ScreenRes_CenterY (ScreenRes_Y >> 1)
extern DoubleBuffer screen_buffer;
extern S16 active_screen_buffer;
+16 -13
View File
@@ -42,6 +42,9 @@
.equ ScreenRes_CenterX, (ScreenRes_X >> 1)
.equ ScreenRes_CenterY, (ScreenRes_Y >> 1)
.equ SMemory_screen_buf, DoubleBuffer * 0
.equ SMemory_active_screen_buf, S16 * 0 + DoubleBuffer
.equ CF_Shadow, 16
.extern ResetGraph
@@ -86,7 +89,7 @@ gp_screen_init_asm:
#define gp0 gpio_port0(rio_offset)
#define gp1 gpio_port1(rio_offset)
def_cf_sp_size 0x80;
def_cf_sp_size 0x18; // Should be enough for all calls within this proc, for some reason SetDefDispEnv needs the offset to be CF_Shadow..
stack_alloc cf_ssize
store_word rret_addr, 0($sp)
@@ -97,26 +100,26 @@ gp_screen_init_asm:
load_imm SetDispMask_mask, 1; jump_nlink SetDispMask
// First buffer area
load_addr rtmp_0, screen_buffer; add_ui SetDefDispEnv_env, rtmp_0, DoubleBuffer_display_0
load_addr rtmp_0, static_mem; add_ui SetDefDispEnv_env, rtmp_0, SMemory_screen_buf + DoubleBuffer_display_0
move SetDefDispEnv_x, $zero
move SetDefDispEnv_y, $zero
load_imm SetDefDispEnv_w, ScreenRes_X
load_imm rtmp_0, ScreenRes_Y; store_word rtmp_0, SetDefDispEnv_h($sp)
jump_nlink SetDefDispEnv
load_addr rtmp_0, screen_buffer; add_ui SetDefDrawEnv_env, rtmp_0, DoubleBuffer_draw_0
load_addr rtmp_0, static_mem; add_ui SetDefDrawEnv_env, rtmp_0, SMemory_screen_buf + DoubleBuffer_draw_0
move SetDefDrawEnv_x, $zero
load_imm SetDefDrawEnv_y, ScreenRes_Y
load_imm SetDefDrawEnv_w, ScreenRes_X
load_imm rtmp_0, ScreenRes_Y; store_word rtmp_0, SetDefDrawEnv_h($sp)
jump_nlink SetDefDrawEnv
// Second buffer area
load_addr rtmp_0, screen_buffer; add_ui SetDefDispEnv_env, rtmp_0, DoubleBuffer_display_1
load_addr rtmp_0, static_mem; add_ui SetDefDispEnv_env, rtmp_0, SMemory_screen_buf + DoubleBuffer_display_1
move SetDefDispEnv_x, $zero
load_imm SetDefDispEnv_y, ScreenRes_Y
load_imm SetDefDispEnv_w, ScreenRes_X
load_imm rtmp_0, ScreenRes_Y; store_word rtmp_0, SetDefDispEnv_h($sp)
jump_nlink SetDefDispEnv
load_addr rtmp_0, screen_buffer; add_ui SetDefDrawEnv_env, rtmp_0, DoubleBuffer_draw_1
load_addr rtmp_0, static_mem; add_ui SetDefDrawEnv_env, rtmp_0, SMemory_screen_buf + DoubleBuffer_draw_1
move SetDefDrawEnv_x, $zero
move SetDefDrawEnv_y, $zero
load_imm SetDefDrawEnv_w, ScreenRes_X
@@ -125,7 +128,7 @@ gp_screen_init_asm:
// Set the back/drawing buffer
load_imm rtmp_1, true
load_addr rtmp_0, screen_buffer;
load_addr rtmp_0, static_mem; // At SMemory_screen_buf
store_word rtmp_1, DoubleBuffer_draw_0 + DrawEnv_enable_auto_clear(rtmp_0)
store_word rtmp_1, DoubleBuffer_draw_1 + DrawEnv_enable_auto_clear(rtmp_0)
@@ -139,17 +142,17 @@ gp_screen_init_asm:
store_byte rtmp_3, DoubleBuffer_draw_1 + DrawEnv_initial_bg_color + RGB8_r(rtmp_0)
store_byte rtmp_2, DoubleBuffer_draw_1 + DrawEnv_initial_bg_color + RGB8_g(rtmp_0)
store_byte rtmp_1, DoubleBuffer_draw_1 + DrawEnv_initial_bg_color + RGB8_b(rtmp_0)
load_addr rtmp_0, active_screen_buffer; store_word rtmp_1, 0(rtmp_0)
load_addr rtmp_0, static_mem; store_word rtmp_1, SMemory_active_screen_buf(rtmp_0)
load_addr rtmp_1, active_screen_buffer; load_half rtmp_1, 0(rtmp_1); // rtmp_1 = active_screen_buffer
load_imm rtmp_2, DisplayEnv; mult_u rtmp_1, rtmp_2; mov_from_low rtmp_2 // rtmp_2 = DisplayEnv.type_size * active_screen_Buffer (rtmp_1)
add_ui rtmp_2, rtmp_2, DoubleBuffer_display // rtmp_2 += DoubleBuffer.display
load_addr rtmp_0, screen_buffer; add_u PutDispEnv_env, rtmp_0, rtmp_2 // rarg_0 = rtmp_0 (screen_buffer) + rtmp_2 (.display[active_screen-buffer])
load_addr rtmp_1, static_mem; load_half rtmp_1, SMemory_active_screen_buf(rtmp_1); // rtmp_1 = active_screen_buffer
load_imm rtmp_2, DisplayEnv; mult_u rtmp_1, rtmp_2; mov_from_low rtmp_2 // rtmp_2 = DisplayEnv.type_size * active_screen_Buffer (rtmp_1)
add_ui rtmp_2, rtmp_2, DoubleBuffer_display // rtmp_2 += DoubleBuffer.display
load_addr rtmp_0, static_mem; add_u PutDispEnv_env, rtmp_0, rtmp_2 // rarg_0 = rtmp_0 (screen_buffer) + rtmp_2 (.display[active_screen-buffer])
jump_nlink PutDispEnv
load_addr rtmp_1, active_screen_buffer; load_half rtmp_1, 0(rtmp_1);
load_addr rtmp_1, static_mem; load_half rtmp_1, SMemory_active_screen_buf(rtmp_1);
load_imm rtmp_2, DrawEnv; mult_u rtmp_1, rtmp_2; mov_from_low rtmp_2;
add_ui rtmp_2, rtmp_2, DoubleBuffer_draw
load_addr rtmp_0, screen_buffer; add_u PutDrawEnv_env, rtmp_0, rtmp_2
load_addr rtmp_0, static_mem; add_u PutDrawEnv_env, rtmp_0, rtmp_2
jump_nlink PutDrawEnv
// Initialize and setup the GTE geometry offsets