interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / omega / allen / surface.om

185 lines · 3959 bytes Raw Blame History
1note Bounded text surface at native scale. See SURFACE.md. The screens lay out on a logical
2note 768 x 384 grid (Cv); every glyph and fill lands in the native frame Nfrm (look-paint.om) at
3note Cvs[0] native pixels per logical pixel, centred by Cvs[2], Cvs[3]. Glyphs are rasterised at
4note the logical cap height times the scale, so type stays crisp on a 4K panel.
5note Cvs: 0 scale, 1 logical cap, 2 x offset, 3 y offset, 4..7 the clip in native pixels.
6global Canvas uchar 884736
7global Cv ulong 8
8global Cvs ulong 8
9global Cvpose long 2
10fn cvinit w ulong h ulong to bool
11if or eq w 0 gt w 768
12ret false
13end
14if or eq h 0 gt h 384
15ret false
16end
17for i ulong 8
18put Cv i 0
19end
20put Cv 0 w
21put Cv 1 h
22put Cv 4 w
23put Cv 5 h
24put Cv 6 1
25for i ulong 8
26put Cvs i 0
27end
28put Cvs 0 1
29sw = ulong get Lg 0
30sh = ulong get Lg 1
31if and ge sw w ge sh h
32s = div sw w
33if lt div sh h s
34s = div sh h
35end
36if eq s 0
37s = 1
38end
39put Cvs 0 s
40put Cvs 2 div sub sw mul w s 2
41put Cvs 3 div sub sh mul h s 2
42end
43put Cvs 4 get Cvs 2
44put Cvs 5 get Cvs 3
45put Cvs 6 mul w get Cvs 0
46put Cvs 7 mul h get Cvs 0
47ret true
48end
49fn cvclip x ulong y ulong w ulong h ulong to bool
50if eq get Cv 6 0
51ret false
52end
53if or gt x get Cv 0 gt y get Cv 1
54ret false
55end
56if gt w sub get Cv 0 x
57ret false
58end
59if gt h sub get Cv 1 y
60ret false
61end
62put Cv 2 x
63put Cv 3 y
64put Cv 4 w
65put Cv 5 h
66s = get Cvs 0
67put Cvs 4 add mul x s get Cvs 2
68put Cvs 5 add mul y s get Cvs 3
69put Cvs 6 mul w s
70put Cvs 7 mul h s
71ret true
72end
73fn cvfont cap ulong wt ulong to bool
74note The face for the following glyphs: cap in logical pixels, rasterised at native size.
75put Cvs 1 cap
76n = mul cap get Cvs 0
77if gt n 64
78n = 64
79end
80ret afinit n wt
81end
82fn cvblend bg ulong fg ulong a ulong to ulong
83v = mul bg sub ulong 255 a
84v = add v mul fg a
85ret div v 255
86end
87fn cvin x long y long to bool
88if or lt x long get Cvs 4 lt y long get Cvs 5
89ret false
90end
91if ge x long add get Cvs 4 get Cvs 6
92ret false
93end
94ret lt y long add get Cvs 5 get Cvs 7
95end
96fn cvmixat at ulong a ulong color ulong to void
97note One native pixel of the frame toward color by a/255.
98d = ulong get Nfrm at
99r = cvblend and shr d 16 255 and shr color 16 255 a
100g = cvblend and shr d 8 255 and shr color 8 255 a
101b = cvblend and d 255 and color 255 a
102put Nfrm at uint or or shl r 16 shl g 8 b
103end
104fn cvpixel x long y long a uchar color ulong to void
105note Native coordinates, held inside the clip.
106if not cvin x y
107ret
108end
109at = add mul ulong y ulong get Lg 0 ulong x
110cvmixat at ulong a color
111end
112fn cvrow yy ulong color ulong to void
113y = add get Cvpose 1 long yy
114at = mul yy get Af 3
115for x ulong get Af 3
116px = add get Cvpose 0 long x
117cvpixel px y get Alpha add at x color
118end
119end
120fn cvblit x long y long color ulong to void
121note x, y: the glyph's logical origin and baseline; the mask offsets Ab are native already.
122s = long get Cvs 0
123ox = add mul x s long get Cvs 2
124oy = add mul y s long get Cvs 3
125put Cvpose 0 add ox get Ab 0
126put Cvpose 1 add oy get Ab 1
127for yy ulong get Af 4
128cvrow yy color
129end
130end
131fn cvargs x long y long color ulong to bool
132if or eq get Cv 6 0 eq get Af 0 0
133ret false
134end
135if or lt x -4096 gt x 4096
136ret false
137end
138if or lt y -4096 gt y 4096
139ret false
140end
141ret le color 16777215
142end
143fn cvglyph c uchar x long y long color ulong to bool
144if not cvargs x y color
145ret false
146end
147if not afglyph c
148ret false
149end
150cvblit x y color
151put Cv 7 div get Af 5 get Cvs 0
152ret true
153end
154fn cvfillrow y long x0 long n long a ulong color ulong to void
155for k ulong ulong n
156cvpixel add x0 long k y uchar a color
157end
158end
159fn cvfill x ulong y ulong w ulong h ulong color ulong a ulong to void
160note A logical rectangle mixed toward color by a/255 (255: solid), inside the clip.
161if eq get Cv 6 0
162ret
163end
164if gt x get Cv 0
165ret
166end
167if gt y get Cv 1
168ret
169end
170if gt w sub get Cv 0 x
171ret
172end
173if gt h sub get Cv 1 y
174ret
175end
176if gt a 255
177a = 255
178end
179s = get Cvs 0
180x0 = long add mul x s get Cvs 2
181y0 = long add mul y s get Cvs 3
182for yy ulong mul h s
183cvfillrow add y0 long yy x0 long mul w s a color
184end
185end