diff --git a/101screen.subx b/101screen.subx index 2aab293d..b957d5d2 100644 --- a/101screen.subx +++ b/101screen.subx @@ -6,6 +6,19 @@ == code pixel-on-real-screen: # x: int, y: int, color: int + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # + (pixel-on-screen-buffer *Video-memory-addr *(ebp+8) *(ebp+0xc) *(ebp+0x10) 0x400 0x300) +$pixel-on-real-screen:end: + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + +# 'buffer' here is not a valid Mu type: a naked address without a length. +pixel-on-screen-buffer: # buffer: (addr byte), x: int, y: int, color: int, width: int, height: int # . prologue 55/push-ebp 89/<- %ebp 4/r32/esp @@ -13,26 +26,26 @@ pixel-on-real-screen: # x: int, y: int, color: int 50/push-eax 51/push-ecx # bounds checks - 8b/-> *(ebp+8) 0/r32/eax + 8b/-> *(ebp+0xc) 0/r32/eax # foo 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 + 7c/jump-if-< $pixel-on-screen-buffer:end/disp8 + 3b/compare 0/r32/eax *(ebp+0x18) + 7d/jump-if->= $pixel-on-screen-buffer:end/disp8 + 8b/-> *(ebp+0x10) 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 + 7c/jump-if-< $pixel-on-screen-buffer:end/disp8 + 3b/compare 0/r32/eax *(ebp+0x1c) + 7d/jump-if->= $pixel-on-screen-buffer:end/disp8 + # eax = y*width + x + 8b/-> *(ebp+0x10) 0/r32/eax + 0f af/multiply-> *(ebp+0x18) 0/r32/eax + 03/add-> *(ebp+0xc) 0/r32/eax # eax += location of frame buffer - 03/add-> *Video-memory-addr 0/r32/eax + 03/add-> *(ebp+8) 0/r32/eax # *eax = color - 8b/-> *(ebp+0x10) 1/r32/ecx + 8b/-> *(ebp+0x14) 1/r32/ecx 88/byte<- *eax 1/r32/CL -$pixel-on-real-screen:end: +$pixel-on-screen-buffer:end: # . restore registers 59/pop-to-ecx 58/pop-to-eax diff --git a/103grapheme.subx b/103grapheme.subx index 8f1f9e61..ac0cef95 100644 --- a/103grapheme.subx +++ b/103grapheme.subx @@ -15,6 +15,21 @@ # Doesn't update the cursor; where the cursor should go after printing the # current grapheme is a higher-level concern. draw-grapheme-on-real-screen: # g: grapheme, x: int, y: int, color: int, background-color: int + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # + (draw-grapheme-on-screen-buffer *Video-memory-addr *(ebp+8) *(ebp+0xc) *(ebp+0x10) *(ebp+0x14) *(ebp+0x18) 0x400 0x300) +$draw-grapheme-on-real-screen:end: + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + +# 'buffer' here is not a valid Mu type: a naked address without a length. +# 'x' and 'y' are in graphemes +# 'screen-width' and 'screen-height' are in pixels +draw-grapheme-on-screen-buffer: # buffer: (addr byte), g: grapheme, x: int, y: int, color: int, background-color: int, screen-width: int, screen-height: int # . prologue 55/push-ebp 89/<- %ebp 4/r32/esp @@ -25,30 +40,30 @@ draw-grapheme-on-real-screen: # g: grapheme, x: int, y: int, color: int, backgr 53/push-ebx 56/push-esi # esi = g - 8b/-> *(ebp+8) 6/r32/esi + 8b/-> *(ebp+0xc) 6/r32/esi # if (g >= 128) return # characters beyond ASCII currently not supported 81 7/subop/compare %esi 0x80/imm32 - 7d/jump-if->= $draw-grapheme-on-real-screen:end/disp8 + 0f 8d/jump-if->= $draw-grapheme-on-screen-buffer:end/disp32 # var letter-bitmap/esi = font[g] c1 4/subop/shift-left %esi 4/imm8 81 0/subop/add %esi Font/imm32 # var ycurr/edx: int = y*16 - 8b/-> *(ebp+0x10) 2/r32/edx + 8b/-> *(ebp+0x14) 2/r32/edx c1 4/subop/shift-left %edx 4/imm8 # var ymax/ebx: int = ycurr + 16 - 8b/-> *(ebp+0x10) 3/r32/ebx + 8b/-> *(ebp+0x14) 3/r32/ebx c1 4/subop/shift-left %ebx 4/imm8 81 0/subop/add %ebx 0x10/imm32 { # if (ycurr >= ymax) break 39/compare %edx 3/r32/ebx - 7d/jump-if->= break/disp8 + 0f 8d/jump-if->= break/disp32 # var xcurr/eax: int = x*8 + 7 - 8b/-> *(ebp+0xc) 0/r32/eax # font-width - 1 + 8b/-> *(ebp+0x10) 0/r32/eax # font-width - 1 c1 4/subop/shift-left %eax 3/imm8 05/add-to-eax 7/imm32 # var xmin/ecx: int = x*8 - 8b/-> *(ebp+0xc) 1/r32/ecx + 8b/-> *(ebp+0x10) 1/r32/ecx c1 4/subop/shift-left %ecx 3/imm8 # var row-bitmap/ebx: int = *letter-bitmap 53/push-ebx @@ -62,12 +77,12 @@ draw-grapheme-on-real-screen: # g: grapheme, x: int, y: int, color: int, backgr # if LSB, draw a pixel in the given color { 73/jump-if-not-CF break/disp8 - (pixel-on-real-screen %eax %edx *(ebp+0x14)) - eb/jump $draw-grapheme-on-real-screen:continue/disp8 + (pixel-on-screen-buffer *(ebp+8) %eax %edx *(ebp+0x18) *(ebp+0x20) *(ebp+0x24)) + eb/jump $draw-grapheme-on-screen-buffer:continue/disp8 } # otherwise use the background color - (pixel-on-real-screen %eax %edx *(ebp+0x18)) -$draw-grapheme-on-real-screen:continue: + (pixel-on-screen-buffer *(ebp+8) %eax %edx *(ebp+0x1c) *(ebp+0x20) *(ebp+0x24)) +$draw-grapheme-on-screen-buffer:continue: # --x 48/decrement-eax # @@ -80,9 +95,9 @@ $draw-grapheme-on-real-screen:continue: # next bitmap row 46/increment-esi # - eb/jump loop/disp8 + e9/jump loop/disp32 } -$draw-grapheme-on-real-screen:end: +$draw-grapheme-on-screen-buffer:end: # . restore registers 5e/pop-to-esi 5b/pop-to-ebx