commit 104b18bf2937946f741ccb136f4b96f724df8d26 Author: Emi Simpson Date: Sat Feb 26 18:42:15 2022 -0500 Added basic centered hello world diff --git a/cart.wat b/cart.wat new file mode 100644 index 0000000..8626c53 --- /dev/null +++ b/cart.wat @@ -0,0 +1,84 @@ +(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 + + ;; Length: 12 bytes + (data (i32.const 98316) "HI FROM WAT") + + (func $tic + (if (call $is_initted) + (call $init)) + (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 $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)))