(module (import "env" "memory" (memory 4)) (import "env" "_emscripten_set_main_loop" (func $emscripten_set_main_loop (param i32 i32 i32))) (import "env" "_SDL_SetVideoMode" (func $SDL_SetVideoMode (param i32 i32 i32 i32) (result i32))) (import "env" "_SDL_GetMouseState" (func $SDL_GetMouseState (param i32 i32) (result i32))) (import "env" "_SDL_LockSurface" (func $SDL_LockSurface (param i32) (result i32))) (import "env" "_SDL_PollEvent" (func $SDL_PollEvent (param i32) (result i32))) (import "env" "_SDL_UnlockSurface" (func $SDL_UnlockSurface (param i32))) (func (export "___emscripten_environ_constructor")) (global $ptr (mut i32) (i32.const 65536)) (func $alloc (export "stackAlloc") (export "_malloc") (param $size i32) (result i32) (local $ret i32) (local.set $ret (global.get $ptr)) (global.set $ptr (i32.and (i32.add (i32.add (global.get $ptr) (local.get $size)) (i32.const 15)) (i32.const -16))) (local.get $ret)) (global $surface (mut i32) (i32.const 0)) (global $event (mut i32) (i32.const 0)) (global $mouse_x (mut i32) (i32.const 0)) (global $mouse_y (mut i32) (i32.const 0)) (global $key_z (mut i32) (i32.const 0)) (global $key_x (mut i32) (i32.const 0)) (func (export "_main") (param i32 i32) (result i32) (global.set $surface (call $SDL_SetVideoMode (i32.const 128) (i32.const 128) (i32.const 32) (i32.const 0))) (global.set $event (call $alloc (i32.const 36))) (call $emscripten_set_main_loop (i32.const 1) (i32.const 0) (i32.const 0)) (i32.const 0)) (func (export "dynCall_v") (param i32) (local $pixels i32) (local $w i32) (local $h i32) (local $pitch i32) (local $mx i32) (local $my i32) (local $buttons i32) (local $x i32) (local $y i32) (local $addr i32) (local $color i32) (local $bg i32) (local $type i32) (local $sym i32) (block $poll_done (loop $poll_loop (br_if $poll_done (i32.eqz (call $SDL_PollEvent (global.get $event)))) (local.set $type (i32.load (global.get $event))) (if (i32.eq (local.get $type) (i32.const 0x400)) (then (global.set $mouse_x (i32.load (i32.add (global.get $event) (i32.const 20)))) (global.set $mouse_y (i32.load (i32.add (global.get $event) (i32.const 24)))))) (if (i32.or (i32.eq (local.get $type) (i32.const 0x300)) (i32.eq (local.get $type) (i32.const 0x301))) (then (local.set $sym (i32.load (i32.add (global.get $event) (i32.const 16)))) (if (i32.eq (local.get $sym) (i32.const 122)) (then (global.set $key_z (i32.eq (local.get $type) (i32.const 0x300))))) (if (i32.eq (local.get $sym) (i32.const 120)) (then (global.set $key_x (i32.eq (local.get $type) (i32.const 0x300))))) (if (i32.and (i32.eq (local.get $sym) (i32.const 27)) (i32.eq (local.get $type) (i32.const 0x300))) (then unreachable)))) (br $poll_loop))) (local.set $buttons (call $SDL_GetMouseState (i32.const 0) (i32.const 0))) (local.set $mx (global.get $mouse_x)) (local.set $my (global.get $mouse_y)) (local.set $bg (i32.const 0xff532b1d)) (if (global.get $key_z) (then (local.set $bg (i32.const 0xff53257e)))) (if (global.get $key_x) (then (local.set $bg (i32.const 0xff518700)))) (if (i32.and (global.get $key_z) (global.get $key_x)) (then (local.set $bg (i32.const 0xff3652ab)))) (drop (call $SDL_LockSurface (global.get $surface))) (local.set $w (i32.load (i32.add (global.get $surface) (i32.const 8)))) (local.set $h (i32.load (i32.add (global.get $surface) (i32.const 12)))) (local.set $pitch (i32.load (i32.add (global.get $surface) (i32.const 16)))) (local.set $pixels (i32.load (i32.add (global.get $surface) (i32.const 20)))) (local.set $y (i32.const 0)) (block $y_done (loop $y_loop (br_if $y_done (i32.ge_s (local.get $y) (local.get $h))) (local.set $x (i32.const 0)) (block $x_done (loop $x_loop (br_if $x_done (i32.ge_s (local.get $x) (local.get $w))) (local.set $addr (i32.add (local.get $pixels) (i32.add (i32.mul (local.get $y) (local.get $pitch)) (i32.shl (local.get $x) (i32.const 2))))) (if (i32.or (i32.eq (local.get $x) (local.get $mx)) (i32.eq (local.get $y) (local.get $my))) (then (local.set $color (i32.const 0xff000000)) (if (i32.and (local.get $buttons) (i32.const 1)) (then (local.set $color (i32.or (local.get $color) (i32.const 0x000000ff))))) (if (i32.and (local.get $buttons) (i32.const 2)) (then (local.set $color (i32.or (local.get $color) (i32.const 0x0000ff00))))) (if (i32.and (local.get $buttons) (i32.const 4)) (then (local.set $color (i32.or (local.get $color) (i32.const 0x00ff0000))))) ) (else (local.set $color (local.get $bg)))) (i32.store (local.get $addr) (local.get $color)) (local.set $x (i32.add (local.get $x) (i32.const 1))) (br $x_loop))) (local.set $y (i32.add (local.get $y) (i32.const 1))) (br $y_loop))) (call $SDL_UnlockSurface (global.get $surface))) (func (export "_mix_0") (param $a i32) (param $b i32) (result i32) (i32.mul (local.get $a) (local.get $b))) )