about summary refs log tree commit diff stats
path: root/baremetal/101screen.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-12-29 21:08:05 -0800
committerKartik Agaram <vc@akkartik.com>2020-12-29 21:08:05 -0800
commit0daf12c59aa8a6b9d996f56797b6f74c3aa0a738 (patch)
treef10222abdb7e7273cd6ff4974bd31280b808b645 /baremetal/101screen.subx
parent63a247fcd4c7597c93e28fc92e489a7882ae2d7c (diff)
downloadmu-0daf12c59aa8a6b9d996f56797b6f74c3aa0a738.tar.gz
7469 - first working baremetal Mu program
It doesn't _quite_ do what it should, so this is more precisely the first
_buggy_ baremetal Mu program. But the tooling works, at least.
Diffstat (limited to 'baremetal/101screen.subx')
-rw-r--r--baremetal/101screen.subx46
1 files changed, 46 insertions, 0 deletions
diff --git a/baremetal/101screen.subx b/baremetal/101screen.subx
new file mode 100644
index 00000000..3e98d96b
--- /dev/null
+++ b/baremetal/101screen.subx
@@ -0,0 +1,46 @@
+# Primitives for screen control.
+
+pixel:  # screen: (addr screen), x: int, y: int, color: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    56/push-esi
+    # esi = screen
+    8b/-> *(ebp+8) 6/r32/esi
+    81 7/subop/compare %esi 0/imm32
+    {
+      75/jump-if-!= break/disp8
+      # bounds checks
+      8b/-> *(ebp+0xc) 0/r32/eax
+      3d/compare-eax-and 0/imm32
+      7c/jump-if-< $pixel:end/disp8
+      3d/compare-eax-and 0x400/imm32/1024
+      7d/jump-if->= $pixel:end/disp8
+      8b/-> *(ebp+0x10) 0/r32/eax
+      3d/compare-eax-and 0/imm32
+      7c/jump-if-< $pixel:end/disp8
+      3d/compare-eax-and 0x300/imm32/768
+      7d/jump-if->= $pixel:end/disp8
+      # eax = y*1024 + x
+      8b/-> *(ebp+0x10) 0/r32/eax
+      c1/shift 4/subop/left %eax 0xa/imm8
+      03/add-> *(ebp+0xc) 0/r32/eax
+      # eax += location of frame buffer
+      03/add-> *0x7f28 0/r32/eax
+      # *eax = color
+      8b/-> *(ebp+0x14) 6/r32/esi
+      88/byte<- *eax 6/r32/esi
+      # return
+      eb $pixel:end/disp8
+    }
+    # TODO: fake screen
+$pixel:end:
+    # . restore registers
+    5e/pop-to-esi
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return