aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/packedfields.zc
blob: 97afef0a9ed220d395cf4c41aa6031798acb6f95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace;
include rt;

// struct fields of the sized types and f32 pack into shared words
struct vtx { f32 x, y, z; u8 r, g, b, a; i16 id; u16 flags; int next; };
struct pair { u8 a; int b; u8 c; };
fn put_f(x) { asm { x @ #1220 } return 0; }
fn sp() { rt.put_c(32); return 0; }
vtx gv;
fn main() {
	vtx v;
	vtx* p = rt.new(vtx);
	pair q;
	vtx[3] arr;
	rt.put_n(sizeof(vtx)); sp(); rt.put_n(sizeof(pair)); sp();
	v.x = 1.5; v.y = 0.1; v.z = 2; v.r = 200; v.g = 255; v.b = 300; v.a = 7; v.id = 0 - 3; v.flags = 65535; v.next = 99;
	put_f(v.x + v.z); sp(); rt.put_n(v.y == 0.1); sp();
	rt.put_n(v.r); sp(); rt.put_n(v.g); sp(); rt.put_n(v.b); sp(); rt.put_n(v.a); sp(); rt.put_n(v.id); sp(); rt.put_n(v.flags); sp(); rt.put_n(v.next); sp();
	v.r += 100; v.flags++; v.id--; v.g = v.g + 1;
	rt.put_n(v.r); sp(); rt.put_n(v.flags); sp(); rt.put_n(v.id); sp(); rt.put_n(v.g); sp();
	p.r = 9; p.a = 8; p.id = 1000; p.next = 5; p.x = 3.25;
	rt.put_n(p.r); rt.put_n(p.a); sp(); rt.put_n(p.id); sp(); rt.put_n(p.next); sp(); put_f(p.x); sp();
	gv.b = 77; gv.flags = 5; rt.put_n(gv.b); sp(); rt.put_n(gv.flags); sp();
	arr[1].a = 42; arr[2].r = 17; arr[1].next = 3; arr[0].id = 0 - 9;
	rt.put_n(arr[1].a); sp(); rt.put_n(arr[2].r); sp(); rt.put_n(arr[1].next); sp(); rt.put_n(arr[0].id); sp(); rt.put_n(arr[0].a); sp();
	rt.put_n(sizeof(arr)); sp();
	q.a = 1; q.b = 123456789; q.c = 2; rt.put_n(q.a); rt.put_n(q.c); sp(); rt.put_n(q.b);
	rt.put_c(10);
	rt.free(d*p);
	second();
	return 0;
}
struct rgba { u8 r, g, b, a; };
o3 int bright(rgba* px, int n) {
	int s = 0;
	for (int i = 0; i < n; i++) { s += px[i].r + px[i].g + px[i].b; px[i].a = px[i].r + 1; }
	return s;
}
fn second() {
	rgba* px = rt.new(rgba, 50);
	for (int i = 0; i < 50; i++) { px[i].r = i; px[i].g = i * 2; px[i].b = 255 - i; }
	rt.put_n(bright(px, 50)); rt.put_c(' '); rt.put_n(px[10].a); rt.put_c(' '); rt.put_n(px[49].a); rt.put_c(10);
	rt.free(d*px);
	return 0;
}