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-sky.om

360 lines · 9844 bytes Raw Blame History
1note SPDX-License-Identifier: MIT
2note Allen's look: the real sky. Handwritten Omega port of native/kernel/ui/sky_real.c (aienux 4b24df65):
3note the gnomonic projection of the catalogue's stars (look-skydata.om) into Nsky, the list of the bright
4note ones that twinkle, the twinkle itself (into Nfrm, inside the clip), and the two Magellanic Clouds'
5note light and phase maps for the sweeping light. Same integers as the C; tests/look-sky.om compares the
6note sky byte for byte with the C oracle.
7note Ported: ck_sky_project (skproj), ck_sky_draw_stars (skstars), ck_sky_twinkle (sktwink),
8note ck_sky_galaxy_bound/in_view/box/maps (skgbound skginview skgbox skgmaps), and ck_night_init's sky
9note construction (skmake, night.c:120-133). Not ported, never reached by the default iMac build (sky_mode 0,
10note allen_ui.c:1226): ck_sky_draw_milkyway and its helpers, ck_sky_gmst, ck_sky_zenith, ck_sky_view_at.
11note Interface (NIGHT reads these; the names were agreed with LookNight):
12note skmake: reads Lg 0..4 (w h k cx cy), runs skinit, clears Nsky w*h, draws the stars into Nsky, fills
13note Sktwn/Sktw, then every galaxy's box, offset and maps. Never touches Nfrm or the clip.
14note Sktwn: how many stars twinkle (<= 256). Sktw: 8 longs per star i at 8*i: 0 x16, 1 y16 (16ths of a
15note pixel), 2 peak (catalogue flux, linear Q16), 3 4 5 col (linear, brightest channel 4096), 6 period
16note (ms), 7 phase (ms).
17note sktwink i amount: ck_sky_twinkle of star i with amount (1/256 of its flux) into Nfrm, clipped by Lg 5..8.
18note Skgbox: x y w h per galaxy (w 0: empty; only galaxies 0 and 1 exist). Skgtint: its sRGB tint.
19note Skgper: ms for the sweep to come round. Skgoff: where its maps start in Skglit (light 0..255) and
20note Skgpha (phase 0..255), row-major box w*h each. The pools hold every box a 3840-wide screen can need:
21note sum of (2a+1)^2 over ck_sky_galaxy_bound = 445^2 + 231^2 = 251386 (Wolfram).
22const SKGPOOL ulong 251386
23global Sktwn ulong 1
24global Sktw long 2048
25global Skgbox long 24
26global Skgtint uint 6
27global Skgper ulong 6
28global Skgoff ulong 6
29global Skglit uchar SKGPOOL
30global Skgpha uchar SKGPOOL
31note scratch: Skpx 0 x16 1 y16 (skproj's result), Skgp 0 gx 1 gy (skginview's result);
32note Skpk 0 peak 1 2 3 colour, Skclip x y w h, Sktgt 0 Nsky 1 Nfrm (skpoint's arguments);
33note Skgw 0 gx 1 gy 2 a 3 b 4 cos 5 sin 6 box x 7 box y 8 a^2 9 b^2 (skgmaps' per-galaxy values for skgpx)
34global Skpx long 2
35global Skgp long 2
36global Skpk ulong 4
37global Skclip long 4
38global Sktgt ulong 1
39global Skgw long 10
40note ck_sky_project: where direction (dx dy dz) (Q15) lands on the Lg 0 wide screen whose view centre is
41note (Lg 3, Lg 4): Skpx 0 1 in 16ths of a pixel; 0 when behind the camera (more than 88 degrees away).
42fn skproj dx long dy long dz long to long
43a2 = add mul get Skview 11 dx mul get Skview 12 dy
44a2 = add a2 mul get Skview 13 dz
45if lt a2 1099511627776
46ret 0
47end
48a2 = shr a2 16
49u = add mul get Skview 5 dx mul get Skview 6 dy
50u = add u mul get Skview 7 dz
51u = div mul u 16384 a2
52t = add mul get Skview 8 dx mul get Skview 9 dy
53t = add t mul get Skview 10 dz
54t = div mul t 16384 a2
55s = mul get Lg 0 8
56u = div mul u s get Skview 4
57t = div mul t s get Skview 4
58put Skpx 0 add mul get Lg 3 16 u
59put Skpx 1 sub mul get Lg 4 16 t
60ret 1
61end
62note one native pixel of point_add: pixel (x, y) of the target gets weight/256 of the light Skpk
63fn skdep x long y long wt ulong to void
64i = ulong add mul y get Lg 0 x
65c = ulong 0
66if eq get Sktgt 0 0
67c = ulong get Nsky i
68else
69c = ulong get Nfrm i
70end
71out = ulong 0
72for k ulong 3
73lv = and shr c sub 16 mul 8 k 255
74a = mul get Skpk 0 get Skpk add k 1
75a = shr mul shr a 13 wt 8
76if ne a 0
77l = add ulong get Slin lv a
78if ge l 32767
79l = 4095
80else
81l = shr l 3
82end
83lv = shr add ulong get Ssrgb l 8 4
84if gt lv 255
85lv = 255
86end
87end
88out = or shl out 8 lv
89end
90c = or and c 4278190080 out
91if eq get Sktgt 0 0
92put Nsky i uint c
93else
94put Nfrm i uint c
95end
96end
97note the clip for skpoint: (x, y, w, h) cut to the screen, kept as x0 y0 x1 y1 (ends exclusive) in Skclip
98fn skclip x long y long w long h long to void
99put Skclip 0 pkmax x 0
100put Skclip 1 pkmax y 0
101put Skclip 2 pkmin add x w get Lg 0
102put Skclip 3 pkmin add y h get Lg 1
103end
104note point_add: a point source at (x16, y16) deposits the light Skpk on the 2 x 2 native pixels round it,
105note inside Skclip (already cut to the screen), into Nsky (Sktgt 0) or Nfrm (Sktgt 1). Weights sum to 256.
106fn skpoint x16 long y16 long to void
107x0 = shr sub x16 8 4
108y0 = shr sub y16 8 4
109fx = ulong and sub x16 8 15
110fy = ulong and sub y16 8 15
111for j ulong 2
112y = add y0 long j
113if ge y get Skclip 1
114if lt y get Skclip 3
115for i ulong 2
116x = add x0 long i
117if ge x get Skclip 0
118if lt x get Skclip 2
119wt = sub 16 fx
120if eq i 1
121wt = fx
122end
123if eq j 1
124wt = mul wt fy
125else
126wt = mul wt sub 16 fy
127end
128if ne wt 0
129skdep x y wt
130end
131end
132end
133end
134end
135end
136end
137end
138note ck_sky_draw_stars for star i: project it, add its light to Nsky, list it to twinkle when V <= 1.0
139fn skstar1 i ulong to void
140j = mul i 3
141if eq skproj get Skstar j get Skstar add j 1 get Skstar add j 2 0
142ret
143end
144x = get Skpx 0
145y = get Skpx 1
146if lt x -32
147ret
148end
149if lt y -32
150ret
151end
152if gt x add mul get Lg 0 16 32
153ret
154end
155if gt y add mul get Lg 1 16 32
156ret
157end
158bv = get Skbv i
159if ge bv 128
160bv = 127
161end
162bv = mul bv 3
163put Skpk 0 get Skflux get Skmag i
164put Skpk 1 get Skpal bv
165put Skpk 2 get Skpal add bv 1
166put Skpk 3 get Skpal add bv 2
167skpoint x y
168if le get Skmag i 59
169n = get Sktwn 0
170if lt n 256
171n = mul n 8
172put Sktw n x
173put Sktw add n 1 y
174put Sktw add n 2 long get Skpk 0
175put Sktw add n 3 long get Skpk 1
176put Sktw add n 4 long get Skpk 2
177put Sktw add n 5 long get Skpk 3
178put Sktw add n 6 long add 1200 rem mul i 137 2400
179put Sktw add n 7 long rem mul i 919 65536
180put Sktwn 0 add get Sktwn 0 1
181end
182end
183end
184note ck_sky_draw_stars: every catalogue star in the view into Nsky (clip: the whole screen), the bright
185note ones listed in Sktw
186fn skstars to void
187put Sktwn 0 0
188put Sktgt 0 0
189skclip 0 0 get Lg 0 get Lg 1
190for i ulong SKNST
191skstar1 i
192end
193end
194note ck_sky_twinkle: star i of Sktw with amount/256 more of its light, into Nfrm inside the clip Lg 5..8
195fn sktwink i ulong amount ulong to void
196n = mul i 8
197put Skpk 0 shr mul ulong get Sktw add n 2 amount 8
198put Skpk 1 ulong get Sktw add n 3
199put Skpk 2 ulong get Sktw add n 4
200put Skpk 3 ulong get Sktw add n 5
201put Sktgt 0 1
202skclip get Lg 5 get Lg 6 get Lg 7 get Lg 8
203skpoint get Sktw n get Sktw add n 1
204end
205note ck_sky_galaxy_bound: the side of the largest box galaxy i can need on a w-wide screen (0: no galaxy i)
206fn skgbound w long i ulong to long
207if ge i SKNGAL
208ret 0
209end
210a = add shr mul get Skgal add mul i 7 3 w 16 4
211ret add mul a 2 1
212end
213note ck_sky_galaxy_in_view: galaxy i's centre pixel into Skgp 0 1; 1 when it is on the Lg 0 x h screen
214fn skginview i ulong h long to long
215if ge i SKNGAL
216ret 0
217end
218j = mul i 7
219if eq skproj get Skgal j get Skgal add j 1 get Skgal add j 2 0
220ret 0
221end
222x = shr add get Skpx 0 8 4
223y = shr add get Skpx 1 8 4
224put Skgp 0 x
225put Skgp 1 y
226if lt x 0
227ret 0
228end
229if ge x get Lg 0
230ret 0
231end
232if lt y 0
233ret 0
234end
235if ge y h
236ret 0
237end
238ret 1
239end
240note ck_sky_galaxy_box: galaxy i's box on the screen into Skgbox (clipped; empty when out of view or none)
241fn skgbox i ulong to void
242b = mul i 4
243put Skgbox b 0
244put Skgbox add b 1 0
245put Skgbox add b 2 0
246put Skgbox add b 3 0
247if eq skginview i get Lg 1 0
248ret
249end
250a = add shr mul get Skgal add mul i 7 3 get Lg 0 16 4
251x0 = pkmax 0 sub get Skgp 0 a
252y0 = pkmax 0 sub get Skgp 1 a
253x1 = pkmin sub get Lg 0 1 add get Skgp 0 a
254y1 = pkmin sub get Lg 1 1 add get Skgp 1 a
255if ge x0 x1
256ret
257end
258if ge y0 y1
259ret
260end
261put Skgbox b x0
262put Skgbox add b 1 y0
263put Skgbox add b 2 sub x1 x0
264put Skgbox add b 3 sub y1 y0
265end
266note one map pixel (px, py) of the galaxy Skgw describes, at pool offset off: its light and phase
267fn skgpx px long py long off ulong to void
268px = sub add get Skgw 6 px get Skgw 0
269py = sub add get Skgw 7 py get Skgw 1
270u = mul px get Skgw 4
271u = shr add u mul py get Skgw 5 14
272v = mul neg px get Skgw 5
273v = shr add v mul py get Skgw 4 14
274a = get Skgw 2
275note f < 0: no galaxy there (a or b 0, or outside the ellipse u^2 b^2 + v^2 a^2 > a^2 b^2);
276note Skgw 8 is a^2, Skgw 9 is b^2
277f = long -1
278if ne a 0
279if ne get Skgw 3 0
280f = mul mul u u get Skgw 9
281f = add f mul mul v v get Skgw 8
282f = sub mul get Skgw 8 get Skgw 9 f
283end
284end
285if lt f 0
286put Skglit off 0
287put Skgpha off 128
288ret
289end
290note light falls off as (1 - (u/a)^2 - (v/b)^2)^2
291f = mul mul u u 65536
292f = sub 65536 div f get Skgw 8
293v = mul mul v v 65536
294f = sub f div v get Skgw 9
295if lt f 0
296f = 0
297end
298f = shr mul f f 16
299f = shr mul f 255 16
300put Skglit off uchar f
301f = mul add u a 255
302f = div f add mul a 2 1
303put Skgpha off uchar f
304end
305note ck_sky_galaxy_maps: galaxy i's light and phase over its box into Skglit / Skgpha at Skgoff i
306fn skgmaps i ulong to void
307if ge i SKNGAL
308ret
309end
310b = mul i 4
311if eq get Skgbox add b 2 0
312ret
313end
314if eq skginview i 2147483647 0
315ret
316end
317j = mul i 7
318put Skgw 0 get Skgp 0
319put Skgw 1 get Skgp 1
320put Skgw 2 shr mul get Skgal add j 3 get Lg 0 16
321put Skgw 3 add shr mul get Skgal add j 4 get Lg 0 16 1
322put Skgw 4 pkcos ulong get Skgal add j 5
323put Skgw 5 pksin ulong get Skgal add j 5
324put Skgw 6 get Skgbox b
325put Skgw 7 get Skgbox add b 1
326put Skgw 8 mul get Skgw 2 get Skgw 2
327put Skgw 9 mul get Skgw 3 get Skgw 3
328put Skgtint i uint get Skgal add j 6
329put Skgper i add 2400 mul i 400
330w = ulong get Skgbox add b 2
331h = ulong get Skgbox add b 3
332off = get Skgoff i
333for py ulong h
334for px ulong w
335skgpx long px long py off
336off = add off 1
337end
338end
339end
340note the sky as ck_night_init makes it (night.c:120-133): black, the stars, the galaxies
341fn skmake to void
342skinit
343w = ulong get Lg 0
344h = ulong get Lg 1
345for y ulong h
346r = mul y w
347for x ulong w
348put Nsky add r x 0
349end
350end
351skstars
352off = ulong 0
353for i ulong 6
354skgbox i
355put Skgoff i off
356b = mul i 4
357off = add off mul ulong get Skgbox add b 2 ulong get Skgbox add b 3
358skgmaps i
359end
360end