about summary refs log tree commit diff stats
path: root/linux/apps/texture.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-07-16 08:09:42 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-16 08:28:56 -0700
commit44d26b77c45668c9b0c99894a4294cec004361fe (patch)
tree68a5dcd4971873efd4ce184e9bf9a531c2161813 /linux/apps/texture.mu
parentac45f097153afd3a89f43886e4124c5b2c26b98a (diff)
downloadmu-44d26b77c45668c9b0c99894a4294cec004361fe.tar.gz
.
Diffstat (limited to 'linux/apps/texture.mu')
-rw-r--r--linux/apps/texture.mu58
1 files changed, 58 insertions, 0 deletions
diff --git a/linux/apps/texture.mu b/linux/apps/texture.mu
new file mode 100644
index 00000000..038a9790
--- /dev/null
+++ b/linux/apps/texture.mu
@@ -0,0 +1,58 @@
+# Playing with emitting cool textures.
+#
+# To run (on Linux):
+#   $ git clone https://github.com/akkartik/mu
+#   $ cd mu
+#   $ ./translate apps/texture.mu
+#   $ ./a.elf > a.ppm
+
+fn main -> _/ebx: int {
+#?   var width/esi: int <- copy 0x190  # 400
+#?   var height/edi: int <- copy 0xe1  # 225; aspect ratio 16:9
+  var width/esi: int <- copy 0xff
+  var height/edi: int <- copy 0xff
+  print-string 0/screen, "P3\n"
+  print-int32-decimal 0/screen, width
+  print-string 0/screen, " "
+  print-int32-decimal 0/screen, height
+  print-string 0/screen, "\n"
+  print-string 0/screen, "255\n"  # color depth
+  var row/ecx: int <- copy 0
+  {
+    compare row, height
+    break-if->=
+    var col/edx: int <- copy 0
+    {
+      compare col, width
+      break-if->=
+      # r
+      var tmp/eax: int <- copy col
+      tmp <- multiply row
+      tmp <- and 0x7f
+      tmp <- add 0x80
+      tmp <- copy 0xff
+      print-int32-decimal 0/screen, tmp
+      print-string 0/screen, " "
+      # g
+      tmp <- copy row
+      tmp <- multiply col
+      tmp <- and 0x7f
+      tmp <- add 0x80
+#?       tmp <- copy 0xcf
+      print-int32-decimal 0/screen, tmp
+      print-string 0/screen, " "
+      # b
+      tmp <- copy row
+      tmp <- multiply col
+      tmp <- and 0x7f
+      tmp <- add 0x80
+      print-int32-decimal 0/screen, tmp
+      print-string 0/screen, "\n"
+      col <- increment
+      loop
+    }
+    row <- increment
+    loop
+  }
+  return 0
+}