diff options
-rw-r--r-- | prototypes/tile/1.mu | 2 | ||||
-rw-r--r-- | prototypes/tile/2.mu | 99 |
2 files changed, 100 insertions, 1 deletions
diff --git a/prototypes/tile/1.mu b/prototypes/tile/1.mu index d7185075..f0f42709 100644 --- a/prototypes/tile/1.mu +++ b/prototypes/tile/1.mu @@ -3,7 +3,7 @@ # To run (on Linux and x86): # $ git clone https://github.com/akkartik/mu # $ cd mu -# $ ./translate_mu apps/tile.mu +# $ ./translate_mu prototypes/tile/1.mu # $ ./a.elf # You should see a line drawn on a blank screen. Press a key. You should see # the line seem to fall down the screen. Press a second key to quit. diff --git a/prototypes/tile/2.mu b/prototypes/tile/2.mu new file mode 100644 index 00000000..078cac17 --- /dev/null +++ b/prototypes/tile/2.mu @@ -0,0 +1,99 @@ +# load test: animate a whole lot of text + +fn main -> exit-status/ebx: int { + var num-lines/ecx: int <- copy 0x10 + clear-screen + # open a file + var f: (addr buffered-file) + { + var f-handle: (handle buffered-file) + var f-in/eax: (addr handle buffered-file) <- address f-handle + open "x", 0, f-in # for reading + var f-out/eax: (addr buffered-file) <- lookup f-handle + copy-to f, f-out + } + # main loop + var row/eax: int <- copy 1 + { + compare row, 0x10 # 16 + break-if-> + render f, row, num-lines + row <- increment +#? sleep 0 0x5f5e100 # 100ms + loop + } + # wait for a key + { + enable-keyboard-immediate-mode + var dummy/eax: byte <- read-key + enable-keyboard-type-mode + } + # clean up + clear-screen + exit-status <- copy 0 +} + +fn render f: (addr buffered-file), start-row: int, num-rows: int { + var num-cols/ecx: int <- copy 0xb9 # 185 + rewind-stream f + # if necessary, clear the row above +$render:clear-loop: { + compare start-row, 1 + break-if-<= + decrement start-row + var col/eax: int <- copy 1 + move-cursor-on-screen start-row, col + { + compare col, num-cols + break-if-> + print-string-to-screen " " + col <- increment + loop + } + increment start-row + } + # render rest of screen below + var row/edx: int <- copy start-row + var col/ebx: int <- copy 1 + move-cursor-on-screen row, col +$render:render-loop: { + compare row, num-rows + break-if->= + var c/eax: byte <- read-byte-buffered f + compare c, 0xffffffff # EOF marker + break-if-= + compare c, 0xa # newline + { + break-if-!= + row <- increment + col <- copy 0 + move-cursor-on-screen row, col + loop $render:render-loop + } + print-byte-to-screen c + col <- increment + loop + } +} + +type timespec { + tv_sec: int + tv_nsec: int +} + +# prototype wrapper around syscall_nanosleep +# nsecs must be less than 999999999 or 0x3b9ac9ff nanoseconds +fn sleep secs: int, nsecs: int { + var t: timespec + # initialize t + var tmp/eax: (addr int) <- get t, tv_sec + var tmp2/ecx: int <- copy secs + copy-to *tmp, tmp2 + tmp <- get t, tv_nsec + tmp2 <- copy nsecs + copy-to *tmp, tmp2 + # perform the syscall + var t-addr/ebx: (addr timespec) <- address t + var rem-addr/ecx: (addr timespec) <- copy 0 + syscall_nanosleep +} |