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