about summary refs log tree commit diff stats
path: root/prototypes
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-07-05 08:17:55 -0700
committerKartik Agaram <vc@akkartik.com>2020-07-05 08:19:00 -0700
commitff856aa0ba9a84998255c5af4fbeeef7f086c499 (patch)
treede8c8a17c9a425dfdbb87438ae46bb41225633ea /prototypes
parentb5984ac5b67aea5757f38cffb4710ad082c973a2 (diff)
downloadmu-ff856aa0ba9a84998255c5af4fbeeef7f086c499.tar.gz
6609
Diffstat (limited to 'prototypes')
-rw-r--r--prototypes/tile/1.mu2
-rw-r--r--prototypes/tile/2.mu99
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
+}
tter Kartik K. Agaram <vc@akkartik.com> 2015-01-02 18:20:18 -0800 497 - strengthen the concept of 'space'' href='/akkartik/mu/commit/channel.mu?h=hlt&id=d1c12218229989dc9a6e15b0190ae0ca05ecb20f'>d1c12218 ^
d4b4d018 ^
f192d655 ^

5b698455 ^
f192d655 ^
afadac25 ^
f192d655 ^
7d2c2d55 ^
4b62edd8 ^
7d2c2d55 ^
be440cb6 ^
f192d655 ^


0ca35d02 ^
8b00ce3f ^
68c45cb8 ^
f192d655 ^
ea0d661b ^



f192d655 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49