interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / aienux / allen / look-show.om

592 lines · 13228 bytes Raw Blame History
1note SPDX-License-Identifier: MIT
2note Allen's look, the show: what the firmware loop draws each frame and where. Native resolution
3note (Lg[0] x Lg[1], the GOP mode), the frame Nfrm (look-paint.om) composed in allen_ui.c's order:
4note night base, lights, the merger flash, Allen's being, his words and the bar; in repository mode
5note the repository screen (repository-screen.om, drawn through surface.om at native scale) on top.
6note Only rectangles that changed are composed; their rows are blitted from two persistent BGRA
7note halves (Efa rows 0..hh-1, Efb rows hh..h-1; each at most 16 MiB, the compiler's array limit).
8note Sh: 0 ms at start, 1 last t, 2 rows per half (hh), 3 full redraw pending, 4 frames drawn,
9note 5 repository screen dirty, 6 last full-screen compose ms, 7 fade strip, 8 the request is
10note with the Spark (thinking), 9 the fade's last full pass is done, 10 the ripple radius last
11note drawn, 11 now (ms), 12 the ripple was on screen last frame, 13 pixels composed this frame,
12note 14 rectangles composed this frame, 15 this frame redrew the whole screen (look-stat.om).
13global Sh long 16
14global Efa uchar 16777216
15global Efb uchar 16777216
16global Shrow uchar 2176
17global Shd long 1280
18global Shdn ulong 1
19global Shr long 4
20global Shl long 10
21global Shb long 20
22global Shbn ulong 1
23const SHRECTS ulong 320
24const SHBORN ulong 12300
25const SHFADE ulong 6800
26const SHMERGE ulong 12000
27const SHGONE ulong 15600
28const SHCOARSE ulong 0
29text Shnet "Spark is not connected yet. Your message is still here."
30fn shfits w ulong h ulong to bool
31if or lt w 640 lt h 400
32ret false
33end
34if or gt w 3840 gt h 2176
35ret false
36end
37hh = div add h 1 2
38ret le mul mul hh w 4 len Efa
39end
40fn shclipr x long y long w long h long to bool
41note Shr becomes (x,y,w,h) held inside the screen; false when nothing is left.
42x1 = add x w
43y1 = add y h
44if lt x 0
45x = 0
46end
47if lt y 0
48y = 0
49end
50if gt x1 get Lg 0
51x1 = get Lg 0
52end
53if gt y1 get Lg 1
54y1 = get Lg 1
55end
56put Shr 0 x
57put Shr 1 y
58put Shr 2 sub x1 x
59put Shr 3 sub y1 y
60if or le sub x1 x 0 le sub y1 y 0
61ret false
62end
63ret true
64end
65fn shmark x long y long w long h long to void
66note Remember a rectangle to compose this frame. Past the list's room, the whole screen is marked.
67if not shclipr x y w h
68ret
69end
70n = get Shdn 0
71if ge n SHRECTS
72put Sh 3 1
73ret
74end
75at = mul n 4
76put Shd at get Shr 0
77put Shd add at 1 get Shr 1
78put Shd add at 2 get Shr 2
79put Shd add at 3 get Shr 3
80put Shdn 0 add n 1
81end
82fn shmarkall to void
83put Sh 3 1
84end
85fn shrowa i ulong at ulong n ulong to void
86note n pixels from Nfrm[i..] as BGRA into Efa[at..] (rows of the upper half).
87for k ulong n
88c = get Nfrm add i k
89put Efa at uchar and c 255
90put Efa add at 1 uchar and shr c 8 255
91put Efa add at 2 uchar and shr c 16 255
92put Efa add at 3 0
93at = add at 4
94end
95end
96fn shrowb i ulong at ulong n ulong to void
97note The same into Efb (rows of the lower half).
98for k ulong n
99c = get Nfrm add i k
100put Efb at uchar and c 255
101put Efb add at 1 uchar and shr c 8 255
102put Efb add at 2 uchar and shr c 16 255
103put Efb add at 3 0
104at = add at 4
105end
106end
107fn shrow y ulong x0 ulong n ulong to void
108note One row's pixels x0..x0+n-1 from Nfrm into the BGRA half that holds row y.
109w = ulong get Lg 0
110hh = ulong get Sh 2
111i = add mul y w x0
112if lt y hh
113shrowa i mul i 4 n
114else
115shrowb i mul add mul sub y hh w x0 4 n
116end
117put Shrow y 1
118end
119fn shconvert x long y long w long h long to void
120note Nfrm -> BGRA for the rectangle, and its rows are remembered for the blit.
121for r ulong ulong h
122shrow add ulong y r ulong x ulong w
123end
124end
125fn shblit y0 ulong rows ulong to bool
126note Rows y0..y0+rows-1 (whole width) to the screen from the half that holds them; a run that
127note crosses the halves is sent as two.
128w = ulong get Lg 0
129hh = ulong get Sh 2
130if and lt y0 hh gt add y0 rows hh
131if not shblit y0 sub hh y0
132ret false
133end
134ret shblit hh sub add y0 rows hh
135end
136arg = or or w shl rows 32 shl y0 48
137n = mul mul w rows 4
138put Stw 10 add get Stw 10 n
139st = ulong 0
140if lt y0 hh
141st = efi 3 arg Efa mul mul y0 w 4 n
142else
143st = efi 3 arg Efb mul mul sub y0 hh w 4 n
144end
145ret eq st 0
146end
147fn shflush to bool
148note Blit every run of rows marked by shrow, then clear the marks.
149h = ulong get Lg 1
150y = ulong 0
151ok = true
152while lt y h bound 2176
153if eq get Shrow y 0
154y = add y 1
155else
156n = ulong 0
157while and lt add y n h ne get Shrow add y n 0 bound 2176
158put Shrow add y n 0
159n = add n 1
160end
161if not shblit y n
162ok = false
163end
164y = add y n
165end
166end
167ret ok
168end
169fn shrepo to void
170note The repository screen, through surface.om at native scale, over the composed sky.
171if ne get Dmo 0 1
172ret
173end
174ok = ghrender
175end
176fn shcompose x long y long w long h long to void
177note allen_ui.c compose: night base, lights, flash, the being, words and bar.
178pkclip x y w h
179ntbase x y w h
180ntlights x y w h 0 0
181hmflash x y w h
182mddraw x y w h
183hmtext x y w h
184end
185fn shfull to void
186note The whole screen, then the repository screen if it is up, then BGRA.
187w = get Lg 0
188h = get Lg 1
189shcompose 0 0 w h
190shrepo
191shconvert 0 0 w h
192put Sh 13 mul w h
193put Sh 14 1
194put Sh 15 1
195put Shdn 0 0
196put Sh 3 0
197end
198fn shrects to void
199note Every marked rectangle: compose and convert. Rectangles may overlap; drawing twice is harmless
200note because every layer is a pure function of position and time.
201n = get Shdn 0
202px = long 0
203for i ulong n
204at = mul i 4
205x = get Shd at
206y = get Shd add at 1
207w = get Shd add at 2
208h = get Shd add at 3
209shcompose x y w h
210shconvert x y w h
211px = add px mul w h
212end
213put Sh 13 px
214put Sh 14 long n
215put Sh 15 0
216put Shdn 0 0
217end
218fn shtwinkles to void
219note The twinkling stars' boxes (ck_night_star_box) as in allen_ui.c: every star, every frame.
220n = ntcount
221for i ulong n
222ntstarbox i
223shmark get Pa 0 get Pa 1 get Pa 2 get Pa 3
224end
225end
226fn shstrip to void
227note The eyes adjust over 6.8 s in slow patches: the screen is composed a sixth at a time, so a
228note frame stays cheap and every part of the sky is refreshed about twice a second.
229h = get Lg 1
230k = rem get Sh 7 6
231y0 = div mul h k 6
232y1 = div mul h add k 1 6
233shmark 0 y0 get Lg 0 sub y1 y0
234put Sh 7 add get Sh 7 1
235end
236fn shchord r long dy long to long
237note Half the width of a circle of radius r at dy from its centre (0 outside).
238if ge dy r
239ret 0
240end
241ret long pkisqrt ulong sub mul r r mul dy dy
242end
243fn shringband hi long lo long ya long yb long to void
244note The ring between radii lo and hi within rows ya..yb-1: one rectangle, or two when the band
245note misses the ring's hollow middle. Distances are from (cx, cy).
246cy = get Lg 4
247cx = get Lg 3
248near = long 0
249if gt ya cy
250near = sub ya cy
251end
252if lt yb cy
253near = sub cy yb
254end
255far = pkmax pkabs sub ya cy pkabs sub yb cy
256xo = shchord hi near
257xi = shchord lo far
258if eq xo 0
259ret
260end
261if eq xi 0
262shmark sub cx xo ya mul xo 2 sub yb ya
263else
264shmark sub cx xo ya sub xo xi sub yb ya
265shmark add cx xi ya sub xo xi sub yb ya
266end
267end
268fn shring to void
269note The ripple bends the sky only within reach of its crest (night.c in_ripple); since the last
270note frame the crest moved out, so the band from the old inner edge to the new outer edge changes.
271r = get Ntrip 0
272w = get Ntrip 1
273if eq w 0
274ret
275end
276reach = add div mul w 22 10 9
277hi = add r reach
278lo = sub get Sh 10 reach
279if or lt lo 0 eq get Sh 10 0
280lo = 0
281end
282put Sh 10 r
283cy = get Lg 4
284ya = sub cy hi
285if lt ya 0
286ya = 0
287end
288yend = add cy hi
289if gt yend get Lg 1
290yend = get Lg 1
291end
292while lt ya yend bound 64
293yb = add ya 64
294if gt yb yend
295yb = yend
296end
297shringband hi lo ya yb
298ya = yb
299end
300end
301fn shbadd x long y long w long h long to void
302note A box onto the list Shb (at most 5: two holes now, two before, one spare).
303n = get Shbn 0
304if ge n 5
305ret
306end
307at = mul n 4
308put Shb at x
309put Shb add at 1 y
310put Shb add at 2 w
311put Shb add at 3 h
312put Shbn 0 add n 1
313end
314fn shbmeet a ulong b ulong to bool
315note Do boxes a and b of Shb overlap (share at least one pixel column and row).
316a = mul a 4
317b = mul b 4
318if ge get Shb a add get Shb b get Shb add b 2
319ret false
320end
321if ge get Shb b add get Shb a get Shb add a 2
322ret false
323end
324if ge get Shb add a 1 add get Shb add b 1 get Shb add b 3
325ret false
326end
327if ge get Shb add b 1 add get Shb add a 1 get Shb add a 3
328ret false
329end
330ret true
331end
332fn shbjoin a ulong b ulong to void
333note Box a becomes the union of a and b; the last box moves into b's place.
334n = get Shbn 0
335a = mul a 4
336b = mul b 4
337x1 = add get Shb a get Shb add a 2
338y1 = add get Shb b get Shb add b 2
339x1 = pkmax x1 y1
340y1 = add get Shb add a 1 get Shb add a 3
341x0 = add get Shb add b 1 get Shb add b 3
342y1 = pkmax y1 x0
343x0 = pkmin get Shb a get Shb b
344put Shb a x0
345x0 = pkmin get Shb add a 1 get Shb add b 1
346put Shb add a 1 x0
347put Shb add a 2 sub x1 get Shb a
348put Shb add a 3 sub y1 get Shb add a 1
349n = sub n 1
350put Shbn 0 n
351n = mul n 4
352for i ulong 4
353put Shb add b i get Shb add n i
354end
355end
356fn shbmerge to void
357note Join overlapping boxes until none overlap: every layer is a pure function of position and
358note time, so one union costs less than two boxes composed twice where they meet.
359for pass ulong 8
360joined = false
361n = get Shbn 0
362for a ulong n
363for b ulong n
364if and lt a b not joined
365if shbmeet a b
366shbjoin a b
367joined = true
368end
369end
370end
371end
372if not joined
373ret
374end
375end
376end
377fn shlens to void
378note The holes' lens boxes now (Shl remembers them for the next frame) and the boxes of the
379note frame before, merged where they meet, then marked.
380put Shbn 0 0
381n = ulong get Shl 8
382for i ulong n
383at = mul i 4
384shbadd get Shl at get Shl add at 1 get Shl add at 2 get Shl add at 3
385end
386put Shl 8 0
387for i ulong ntholes
388if ntholebox i
389shbadd get Pa 0 get Pa 1 get Pa 2 get Pa 3
390k = ulong get Shl 8
391at = mul k 4
392for j ulong 4
393put Shl add at j get Pa j
394end
395put Shl 8 add long k 1
396end
397end
398shbmerge
399n = get Shbn 0
400for i ulong n
401at = mul i 4
402shmark get Shb at get Shb add at 1 get Shb add at 2 get Shb add at 3
403end
404end
405fn shdecide t ulong to void
406note Which parts of the screen change at t (ms since the sky started). Sh[9]: the fade's last
407note full pass is done; Sh[12]: the ripple was on screen last frame; Shl: the lens rect last frame.
408if lt t add SHFADE 400
409shstrip
410else
411if eq get Sh 9 0
412put Sh 9 1
413shmarkall
414end
415end
416if ne get Ntrip 1 0
417shring
418put Sh 12 1
419put Ntcoarse 0 SHCOARSE
420else
421put Ntcoarse 0 0
422if ne get Sh 12 0
423put Sh 12 0
424shmarkall
425end
426end
427note The holes' lens regions now and where they were, Allen, his words and bar, the twinkles.
428shlens
429mddirty
430shmark get Mdbox 0 get Mdbox 1 get Mdbox 2 get Mdbox 3
431shmark get Hmdirty 0 get Hmdirty 1 get Hmdirty 2 get Hmdirty 3
432shtwinkles
433end
434fn shstep now ulong to bool
435note Move the show on to now and draw what changed. False when the screen refused a blit.
436if eq get Sh 0 0
437put Sh 0 long now
438end
439put Sh 11 long now
440t = sub now ulong get Sh 0
441ntat t
442hmstep long t
443mdat long t
444if eq get Dmo 0 1
445note Repository mode: a still picture, redrawn only when the screen says it changed.
446if or ne get Sh 5 0 ne get Sh 3 0
447shfull
448put Sh 5 0
449ret shflush
450end
451ret true
452end
453shdecide t
454if ne get Sh 3 0
455shfull
456else
457shrects
458end
459put Sh 1 long t
460put Sh 4 add get Sh 4 1
461t1 = efms
462ok = shflush
463shstat now t1 efms t
464ret ok
465end
466fn shstat t0 ulong t1 ulong t2 ulong t ulong to void
467note The frame's clocks and what it composed, for the stopwatch (look-stat.om).
468rf = ulong add mul get Sh 14 2 get Sh 15
469stframe t0 t1 t2 t ulong get Sh 13 rf
470end
471fn shsubmit to void
472note Enter in the bar: a recognised repository request opens the repository screen; anything else
473note goes to the Spark through the courier (look-chat.om) and Allen thinks until the answer comes.
474n = get Hminn 0
475if or eq n 0 gt n 159
476ret
477end
478for i ulong n
479put In i get Hmin i
480put Dprm i get Hmin i
481end
482put Inlen 0 n
483put Dprmn 0 n
484if stasked
485hmkey 13
486ret
487end
488if inmatch
489hmkey 13
490ininstall ulong get Sh 11
491ret
492end
493if ghask
494put Dmo 0 1
495put Sh 5 1
496hmkey 13
497ret
498end
499if eq get Es 6 0
500note A disconnected firmware network must not make Enter silently do nothing.
501note Keep the unsent input for retry and give a local answer without claiming it was delivered.
502for i ulong len Shnet
503put Hmsay i get Shnet i
504end
505put Hmsayn 0 len Shnet
506hmsaid
507note The local notice did not consume input; the next frame must still draw that line.
508put Hm 15 add get Hm 15 1
509ret
510end
511if chask ulong get Sh 11
512put Sh 8 1
513hmthink 1
514end
515hmkey 13
516end
517fn shkey key ulong to bool
518note Keys: the repository screen takes them while it is up (Escape closes it); otherwise the bar.
519if eq get Dmo 0 1
520if eq key 27
521put Dmo 0 0
522ghinit
523shmarkall
524ret true
525end
526ghkey key
527put Sh 5 1
528ret true
529end
530if or eq key 10 eq key 13
531shsubmit
532ret true
533end
534hmkey key
535ret true
536end
537fn shanswer to void
538note The courier's visible text becomes what Allen says.
539if ne get Chevent 0 1
540if or eq get Chevent 0 5 eq get Chevent 0 6
541if eq get Chevent 0 6
542hmthink 0
543put Sh 8 0
544end
545put Chevent 0 0
546end
547ret
548end
549n = get Chsayn 0
550if gt n len Hmsay
551n = len Hmsay
552end
553for i ulong n
554put Hmsay i get Chsay i
555end
556put Hmsayn 0 n
557hmsaid
558hmthink 0
559put Sh 8 0
560put Chevent 0 0
561end
562fn shinit now ulong to bool
563note Sizes from the screen (Es), then every module of the look.
564w = get Es 0
565h = get Es 1
566if not shfits w h
567ret false
568end
569put Lg 0 long w
570put Lg 1 long h
571kw = div mul w 256 1920
572kh = div mul h 256 1080
573if lt kh kw
574kw = kh
575end
576put Lg 2 long kw
577put Lg 3 long div w 2
578put Lg 4 long div mul h 40 100
579put Sh 2 long div add h 1 2
580for i ulong 2176
581put Shrow i 0
582end
583put Shdn 0 0
584put Shl 8 0
585pkinit
586ntinit
587mdinit long SHBORN
588hminit
589put Sh 0 long now
590put Sh 3 1
591ret true
592end