about summary refs log tree commit diff stats
path: root/101screen.subx
diff options
context:
space:
mode:
Diffstat (limited to '101screen.subx')
-rw-r--r--101screen.subx42
1 files changed, 42 insertions, 0 deletions
diff --git a/101screen.subx b/101screen.subx
new file mode 100644
index 00000000..46cee777
--- /dev/null
+++ b/101screen.subx
@@ -0,0 +1,42 @@
+# Primitives for screen control.
+#
+# We need to do this in machine code because Mu doesn't have global variables
+# yet (for the start of video memory).
+
+== code
+
+pixel-on-real-screen:  # x: int, y: int, color: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    51/push-ecx
+    # bounds checks
+    8b/-> *(ebp+8) 0/r32/eax
+    3d/compare-eax-and 0/imm32
+    7c/jump-if-< $pixel-on-real-screen:end/disp8
+    3d/compare-eax-and 0x400/imm32/screen-width=1024
+    7d/jump-if->= $pixel-on-real-screen:end/disp8
+    8b/-> *(ebp+0xc) 0/r32/eax
+    3d/compare-eax-and 0/imm32
+    7c/jump-if-< $pixel-on-real-screen:end/disp8
+    3d/compare-eax-and 0x300/imm32/screen-height=768
+    7d/jump-if->= $pixel-on-real-screen:end/disp8
+    # eax = y*1024 + x
+    8b/-> *(ebp+0xc) 0/r32/eax
+    c1/shift 4/subop/left %eax 0xa/imm8
+    03/add-> *(ebp+8) 0/r32/eax
+    # eax += location of frame buffer
+    03/add-> *0x8128 0/r32/eax  # unsafe
+    # *eax = color
+    8b/-> *(ebp+0x10) 1/r32/ecx
+    88/byte<- *eax 1/r32/CL
+$pixel-on-real-screen:end:
+    # . restore registers
+    59/pop-to-ecx
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return