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