From 4254408a385f90ffe212e85a7b405054f4e73f5e Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 23 Jan 2021 11:14:07 -0800 Subject: 7549 --- html/baremetal/101screen.subx.html | 88 ++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 47 deletions(-) (limited to 'html/baremetal/101screen.subx.html') diff --git a/html/baremetal/101screen.subx.html b/html/baremetal/101screen.subx.html index 1f204a59..b41c8b85 100644 --- a/html/baremetal/101screen.subx.html +++ b/html/baremetal/101screen.subx.html @@ -55,53 +55,47 @@ if ('onhashchange' in window) { https://github.com/akkartik/mu/blob/main/baremetal/101screen.subx
  1 # Primitives for screen control.
- 2 
- 3 == code
- 4 
- 5 pixel:  # screen: (addr screen), x: int, y: int, color: int
- 6     # . prologue
- 7     55/push-ebp
- 8     89/<- %ebp 4/r32/esp
- 9     # . save registers
-10     50/push-eax
-11     51/push-ecx
-12     # ecx = screen
-13     8b/-> *(ebp+8) 1/r32/ecx
-14     81 7/subop/compare %ecx 0/imm32
-15     {
-16       75/jump-if-!= break/disp8
-17       # bounds checks
-18       8b/-> *(ebp+0xc) 0/r32/eax
-19       3d/compare-eax-and 0/imm32
-20       7c/jump-if-< $pixel:end/disp8
-21       3d/compare-eax-and 0x400/imm32/1024
-22       7d/jump-if->= $pixel:end/disp8
-23       8b/-> *(ebp+0x10) 0/r32/eax
-24       3d/compare-eax-and 0/imm32
-25       7c/jump-if-< $pixel:end/disp8
-26       3d/compare-eax-and 0x300/imm32/768
-27       7d/jump-if->= $pixel:end/disp8
-28       # eax = y*1024 + x
-29       8b/-> *(ebp+0x10) 0/r32/eax
-30       c1/shift 4/subop/left %eax 0xa/imm8
-31       03/add-> *(ebp+0xc) 0/r32/eax
-32       # eax += location of frame buffer
-33       03/add-> *0x7f28 0/r32/eax
-34       # *eax = color
-35       8b/-> *(ebp+0x14) 1/r32/ecx
-36       88/byte<- *eax 1/r32/CL
-37       # return
-38       eb $pixel:end/disp8
-39     }
-40     # TODO: fake screen
-41 $pixel:end:
-42     # . restore registers
-43     59/pop-to-ecx
-44     58/pop-to-eax
-45     # . epilogue
-46     89/<- %esp 5/r32/ebp
-47     5d/pop-to-ebp
-48     c3/return
+ 2 #
+ 3 # We need to do this in machine code because Mu doesn't have global variables
+ 4 # yet (for the start of video memory).
+ 5 
+ 6 == code
+ 7 
+ 8 pixel-on-real-screen:  # x: int, y: int, color: int
+ 9     # . prologue
+10     55/push-ebp
+11     89/<- %ebp 4/r32/esp
+12     # . save registers
+13     50/push-eax
+14     51/push-ecx
+15     # bounds checks
+16     8b/-> *(ebp+8) 0/r32/eax
+17     3d/compare-eax-and 0/imm32
+18     7c/jump-if-< $pixel-on-real-screen:end/disp8
+19     3d/compare-eax-and 0x400/imm32/screen-width=1024
+20     7d/jump-if->= $pixel-on-real-screen:end/disp8
+21     8b/-> *(ebp+0xc) 0/r32/eax
+22     3d/compare-eax-and 0/imm32
+23     7c/jump-if-< $pixel-on-real-screen:end/disp8
+24     3d/compare-eax-and 0x300/imm32/screen-height=768
+25     7d/jump-if->= $pixel-on-real-screen:end/disp8
+26     # eax = y*1024 + x
+27     8b/-> *(ebp+0xc) 0/r32/eax
+28     c1/shift 4/subop/left %eax 0xa/imm8
+29     03/add-> *(ebp+8) 0/r32/eax
+30     # eax += location of frame buffer
+31     03/add-> *0x7f28 0/r32/eax  # unsafe
+32     # *eax = color
+33     8b/-> *(ebp+0x10) 1/r32/ecx
+34     88/byte<- *eax 1/r32/CL
+35 $pixel-on-real-screen:end:
+36     # . restore registers
+37     59/pop-to-ecx
+38     58/pop-to-eax
+39     # . epilogue
+40     89/<- %esp 5/r32/ebp
+41     5d/pop-to-ebp
+42     c3/return
 
-- cgit 1.4.1-2-gfad0