(module (import "env" "trace" (func $trace (param i32) (param i32))) (import "env" "print" (func $print (param i32 ;; Text i32 ;; X i32 ;; Y i32 ;; Color i32 ;; Fixed Width (actually a bool) i32 ;; Scale i32 ;; Smoll Font ) (result i32))) (import "env" "mem" (memory 4)) ;; Offset: 98304 ;; Length: 8 bytes ;; (x & y of the displayed text) ;; x is the high order bits, y is the low order bits ;; Offset: 98312 ;; Length: 4 bytes ;; The width of the text, initialized lazily at first TIC ;; A value of zero indicates uninitialization ;; Offset: 98320 ;; Length: 8 bytes ;; Velocity of text, stored in the same manor as position ;; Length: 12 bytes (data (i32.const 98316) "HI FROM WAT") (func $tic (if (call $is_initted) (call $init)) (call $update) (call $view)) (func $view (local $pos i64) (drop (call $print (i32.const 98316) ;; Preset text (i32.wrap_i64 ;; X (i64.shr_u (local.tee $pos ;; Complete position (both attributes) (i64.load (i32.const 98304))) (i64.const 32))) (i32.wrap_i64 ;; Y (local.get $pos)) (i32.const 1) ;; Color (i32.const 0) ;; Not Fixed Width (i32.const 3) ;; Scale (i32.const 0)))) ;; Not small font (func $update (local $newpos v128) (local $tests v128) (i64.store (i32.const 98330) (i64x2.extract_lane 0 (i32x4.sub (v128.const i32x4 1 1 1 1) ;; Unit vector (i32x4.mul (v128.or ;; Velocities that we need to swap (i32x4.lt_s ;; Position components < 0 (v128.const i32x4 0 0 0 0) (local.tee $newpos ;; Position updated with velocity (i32x4.add (v128.load (i32.const 98304)) ;; Position (v128.load (i32.const 98330))))) ;; Velocity (i32x4.gt_s (local.get $newpos) (v128.const i32x4 239 135 0 0))) ;; Window upper bounds (i32x4.splat (i32.const 2)))))) (v128.store (i32.const 98304) (local.get $newpos))) (func $is_initted (result i32) (i32.eqz (i32.load (i32.const 98312)))) ;; Text Width (func $init (local $text_width i32) (i32.store (i32.const 98312) ;; &Text width (local.tee $text_width (call $print (i32.const 98316) ;; Preset text (i32.const 0) ;; X (i32.const -50) ;; Y (i32.const 0) ;; Color (i32.const 0) ;; Fixed Width (i32.const 3) ;; Scale (i32.const 0) ;; Small font ))) (call $trace (i32.const 98316) (i32.const 4)) (i64.store (i32.const 98304) ;; &Text position (i64.or ;; Combined positions (i64.shl ;; Transformed X position (i64.shr_u ;; Space on the left of text (i64.sub ;; Total space around text (i64.const 240) ;; Stage width (i64.extend_i32_u (local.get $text_width))) ;; Text width (i64.const 1)) (i64.const 32)) (i64.const 61)))) ;; Space above text (Y) (export "TIC" (func $tic)))