about summary refs log tree commit diff stats
path: root/baremetal/101screen.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2021-01-15 20:30:07 -0800
committerKartik Agaram <vc@akkartik.com>2021-01-15 20:30:07 -0800
commit6e36ce06dd035408d43a6599b75b933a0709cc78 (patch)
treeb5b90ee59b5387036d311096fed1c96aa588cacb /baremetal/101screen.subx
parent20d6be52405130930fde9ca5bb5e95131ba4e659 (diff)
downloadmu-6e36ce06dd035408d43a6599b75b933a0709cc78.tar.gz
7521 - new plan for tests
It's not really manageable to make the fake screen pixel-oriented. Feels
excessive to compare things pixel by pixel when we will mostly be
writing text to screen. It'll also make expected screen assertions
more difficult to manage.

So I'm not sure how to make assertions about pixels for now. Instead
we'll introduce fake screens at draw-grapheme.
Diffstat (limited to 'baremetal/101screen.subx')
-rw-r--r--baremetal/101screen.subx56
1 files changed, 25 insertions, 31 deletions
diff --git a/baremetal/101screen.subx b/baremetal/101screen.subx
index 225efeec..5a26a86a 100644
--- a/baremetal/101screen.subx
+++ b/baremetal/101screen.subx
@@ -1,44 +1,38 @@
 # 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:  # screen: (addr screen), x: int, y: int, color: int
+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
-    # ecx = screen
-    8b/-> *(ebp+8) 1/r32/ecx
-    81 7/subop/compare %ecx 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) 1/r32/ecx
-      88/byte<- *eax 1/r32/CL
-      # return
-      eb $pixel:end/disp8
-    }
-    # TODO: fake screen
-$pixel:end:
+    # 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/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/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-> *0x7f28 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