2/7 Fixed-Point math

This commit is contained in:
2026-05-24 21:06:05 -04:00
parent d1919137a3
commit e409fe0b2d
6 changed files with 63 additions and 113 deletions
+1 -1
View File
@@ -76,7 +76,7 @@ enum { false = 0, true = 1, true_overflow, };
#define alignof _Alignof
#define byte_pad(amount, ...) B1 glue(_PAD_, __VA_ARGS__) [amount]
#define cast(type, data) ((type)(data))
#define pcast(type, data) * cast(type*, & (data))
#define pcast(type, data) (cast(type*, & (data)) [0])
#define nullptr cast(void*, 0)
#define size_of(data) cast(U4, sizeof(data))
+12 -4
View File
@@ -33,12 +33,20 @@ typedef def_enum(U4, gp_Commands) {
gcmd_SetVramSize = 0x09,
};
#define gpio_port0 0x1810
#define gpio_port1 0x1814
enum {
gpio_port_0 = 0x1810,
gpio_port_1 = 0x1814,
#define gcmd_offset 24
gmcd_offset = 24,
#define gp_Reset (gcmd_Reset << gcmd_offset)
gp_Reset = (gcmd_Reset << gmcd_offset),
};
// #define gpio_port0 0x1810
// #define gpio_port1 0x1814
// #define gcmd_offset 24
// #define gp_Reset (gcmd_Reset << gcmd_offset)
#define gp_DisplayEnabled (gcmd_DisplayEnable << gcmd_offset | 0x0)
#define gp_DisplayDisabled (gcmd_DisplayEnable << gcmd_offset | 0x1)
+13 -2
View File
@@ -12,6 +12,7 @@ typedef def_farray(S2, 2);
typedef def_farray(S2, 3);
typedef def_farray(S4, 2);
typedef def_farray(S4, 3);
typedef def_farray(S4, 4);
typedef S2 A3A3_S2[3][3];
typedef def_struct(Extent2_S2) { S2 width; S2 height; };
@@ -33,7 +34,17 @@ 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 v3s2(x,y,z) (V3_S2){x,y,z}
#define v3s4(x,y,z) (V3_S4){x,y,z}
#define v3s2(x,y,z) (V3_S2){x,y,z,0}
#define v3s4(x,y,z) (V3_S4){x,y,z,0}
#define v4s2(x,y,z,w) (V4_S2){x,y,z,w}
#define v4s4(x,y,z,w) (V4_S4){x,y,z,w}
FI_ void add_a3s4(A3_S4_R out_a, A3_S4 b) {
(out_a[0])[0] += b[0];
(out_a[0])[1] += b[1];
(out_a[0])[2] += b[2];
}
FI_ void add_v3s4(V3_S4_R out_a, V3_S4 b) {
add_a3s4(pcast(A3_S4_R, out_a), pcast(A3_S4, b));
}
+2
View File
@@ -43,6 +43,7 @@ B4 memory_zero (void* dest, U4 length);
#define sll_queue_push_n(f, l, n, next) sll_queue_push_nz(0, f, l, n, next)
#pragma region Allocator Interface
#if 0
typedef def_enum(U4, AllocatorOp) {
AllocatorOp_Alloc_NoZero = 0, // If Alloc exist, so must No_Zero
AllocatorOp_Alloc,
@@ -137,4 +138,5 @@ Slice_B1 mem__shrink(AllocatorInfo ainfo, Slice_B1 mem, U4 size, Opts_mem_shrink
#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 }
#endif
#pragma endregion Allocator Interface