diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-07-01 16:46:06 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-07-01 16:47:20 -0700 |
commit | 996402e8fdb30cc29735d9dd190ff78676d6c907 (patch) | |
tree | 072507f0fe76bd4102230123625477b2a0600e02 /apps/tile.mu | |
parent | 792451d1be576dfd35c2473cb4ede75ccca63782 (diff) | |
download | mu-996402e8fdb30cc29735d9dd190ff78676d6c907.tar.gz |
6604 - new app
https://archive.org/details/akkartik-2min-2020-07-01 In the process I found a bug, added a new syscall, and 'emulated' it.
Diffstat (limited to 'apps/tile.mu')
-rw-r--r-- | apps/tile.mu | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/apps/tile.mu b/apps/tile.mu new file mode 100644 index 00000000..44451aa1 --- /dev/null +++ b/apps/tile.mu @@ -0,0 +1,60 @@ +# little example program: animate a line in text-mode + +fn main -> exit-status/ebx: int { + clear-screen + move-cursor-on-screen 5, 5 + print-string-to-screen "_________" + enable-keyboard-immediate-mode + var dummy/eax: byte <- read-key + var row/eax: int <- copy 5 + { + compare row, 0xe # 15 + break-if-= + animate row + row <- increment + sleep 0 0x5f5e100 # 100ms + loop + } + var dummy/eax: byte <- read-key + enable-keyboard-type-mode + clear-screen + exit-status <- copy 0 +} + +fn animate row: int { + var col/eax: int <- copy 5 + { + compare col, 0xe + break-if-= + move-cursor-on-screen row, col + print-string-to-screen " " + increment row + move-cursor-on-screen row, col + print-string-to-screen "_" + decrement row + 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 +} |