about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--126write-int-decimal.subx7
-rw-r--r--501draw-text.mu54
-rw-r--r--boot.subx207
-rw-r--r--linux/126write-int-decimal.subx3
-rw-r--r--linux/ex1.subx1
5 files changed, 123 insertions, 149 deletions
diff --git a/126write-int-decimal.subx b/126write-int-decimal.subx
index ed2077a2..bc4a510e 100644
--- a/126write-int-decimal.subx
+++ b/126write-int-decimal.subx
@@ -43,24 +43,18 @@ write-int32-decimal:  # out: (addr stream byte), n: int
     51/push-ecx
     52/push-edx
     53/push-ebx
-    56/push-esi
     57/push-edi
-    be/copy-to-esi 3/imm32/x
     # const ten/ecx = 10
     b9/copy-to-ecx  0xa/imm32
     # push sentinel
     68/push  0/imm32/sentinel
     # var eax: int = abs(n)
     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
-    (draw-vertical-line-on-real-screen %eax 0x40 0x50 %eax)
-    81 0/subop/add %esi 3/imm32
     3d/compare-eax-with  0/imm32
     7d/jump-if->=  $write-int32-decimal:read-loop/disp8
 $write-int32-decimal:negative:
     f7          3/subop/negate      3/mod/direct    0/rm32/eax    .           .             .           .           .               .                 # negate eax
 $write-int32-decimal:read-loop:
-    (draw-vertical-line-on-real-screen %esi 0x80 0x90 %esi)
-    81 0/subop/add %esi 3/imm32
     # eax, edx = eax / 10, eax % 10
     99/sign-extend-eax-into-edx
     f7          7/subop/idiv        3/mod/direct    1/rm32/ecx    .           .             .           .           .               .                 # divide edx:eax by ecx, storing quotient in eax and remainder in edx
@@ -110,7 +104,6 @@ $write-int32-decimal:write-break:
 $write-int32-decimal:end:
     # . restore registers
     5f/pop-to-edi
-    5e/pop-to-esi
     5b/pop-to-ebx
     5a/pop-to-edx
     59/pop-to-ecx
diff --git a/501draw-text.mu b/501draw-text.mu
index 6f0b8011..ce87634e 100644
--- a/501draw-text.mu
+++ b/501draw-text.mu
@@ -105,15 +105,6 @@ fn draw-text-rightward screen: (addr screen), text: (addr array byte), x: int, x
   return xcurr
 }
 
-fn draw-int32-decimal-rightward screen: (addr screen), n: int, x: int, xmax: int, y: int, color: int, background-color: int -> _/eax: int {
-  var stream-storage: (stream byte 0x100)
-  var stream/esi: (addr stream byte) <- address stream-storage
-  write-int32-decimal stream, n
-#?   write-int32-hex stream, n
-  var xcurr/eax: int <- draw-stream-rightward screen, stream, x, xmax, y, color, background-color
-  return xcurr
-}
-
 # draw a single-line stream from x, y to xmax
 # return the next 'x' coordinate
 # if there isn't enough space, truncate
@@ -253,9 +244,23 @@ fn draw-int32-hex-wrapping-right-then-down screen: (addr screen), n: int, xmin:
   var stream-storage: (stream byte 0x100)
   var stream/esi: (addr stream byte) <- address stream-storage
   write-int32-hex stream, n
-  var xcurr/eax: int <- copy x
+  var xcurr/edx: int <- copy x
   var ycurr/ecx: int <- copy y
-  xcurr, ycurr <- draw-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color
+  {
+    var g/eax: grapheme <- read-grapheme stream
+    compare g, 0xffffffff/end-of-file
+    break-if-=
+    draw-grapheme screen, g, xcurr, ycurr, color, background-color
+    xcurr <- increment
+    compare xcurr, xmax
+    {
+      break-if-<
+      xcurr <- copy xmin
+      ycurr <- increment
+    }
+    loop
+  }
+  set-cursor-position screen, xcurr, ycurr
   return xcurr, ycurr
 }
 
@@ -292,17 +297,24 @@ fn draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen:
 fn draw-int32-decimal-wrapping-right-then-down screen: (addr screen), n: int, xmin: int, ymin: int, xmax: int, ymax: int, x: int, y: int, color: int, background-color: int -> _/eax: int, _/ecx: int {
   var stream-storage: (stream byte 0x100)
   var stream/esi: (addr stream byte) <- address stream-storage
-#?   compare n, 0x48
-#?   {
-#?     break-if-!=
-#?     abort "aa"
-#?   }
   write-int32-decimal stream, n
-#?   write-int32-decimal stream, 0x48
-#?   write-int32-hex stream, n
-  var xcurr/eax: int <- copy 0
-  var ycurr/ecx: int <- copy 0
-  xcurr, ycurr <- draw-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color
+  var xcurr/edx: int <- copy x
+  var ycurr/ecx: int <- copy y
+  {
+    var g/eax: grapheme <- read-grapheme stream
+    compare g, 0xffffffff/end-of-file
+    break-if-=
+    draw-grapheme screen, g, xcurr, ycurr, color, background-color
+    xcurr <- increment
+    compare xcurr, xmax
+    {
+      break-if-<
+      xcurr <- copy xmin
+      ycurr <- increment
+    }
+    loop
+  }
+  set-cursor-position screen, xcurr, ycurr
   return xcurr, ycurr
 }
 
diff --git a/boot.subx b/boot.subx
index ed2d213e..6982fccb 100644
--- a/boot.subx
+++ b/boot.subx
@@ -359,125 +359,96 @@ keyboard-interrupt-handler:
   3c/compare-al-and 0/imm8
   75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8
   # - read keycode
-  31/xor %eax 0/r32/eax
   e4/read-port-into-al 0x60/imm8
-  #
-#?   50/push-eax
-#?   51/push-ecx
-#?   (draw-int32-hex-wrapping-right-then-down-over-full-screen 0 %eax 0 0 7 0)
-#?   59/pop-to-ecx
-#?   58/pop-to-eax
-  #
-#?   50/push-eax
-#?   51/push-ecx
-#?   (draw-int32-decimal-wrapping-right-then-down 0 %eax 0 2 0x400 2 0 2 7 0)
-  89/<- %ecx 0/r32/eax
-  # . . push args
-  68/push 0/imm32/bg
-  68/push 7/imm32/fg
-  68/push 2/imm32/y
-  68/push 0x400/imm32/xmax
-  68/push 0/imm32/xmin
-#?   68/push 0x48/imm32/n
-  51/push-ecx
-  68/push 0/imm32/screen
-  # . . call
-#?   e8/call draw-int32-hex-wrapping-right-then-down/disp32
-#?   e8/call draw-int32-decimal-wrapping-right-then-down/disp32
-  e8/call draw-int32-decimal-rightward/disp32
-  # . . discard args
-  81 0/subop/add %esp 0x1c/imm32
-#?   59/pop-to-ecx
-#?   58/pop-to-eax
-#?   # - key released
-#?   # if (al == 0xaa) shift = false  # left shift is being lifted
-#?   {
-#?     3c/compare-al-and 0xaa/imm8
-#?     75/jump-if-!= break/disp8
-#?     # *shift = 0
-#?     c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32
-#?   }
-#?   # if (al == 0xb6) shift = false  # right shift is being lifted
-#?   {
-#?     3c/compare-al-and 0xb6/imm8
-#?     75/jump-if-!= break/disp8
-#?     # *shift = 0
-#?     c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32
-#?   }
-#?   # if (al == 0x9d) ctrl = false  # ctrl is being lifted
-#?   {
-#?     3c/compare-al-and 0x9d/imm8
-#?     75/jump-if-!= break/disp8
-#?     # *ctrl = 0
-#?     c7 0/subop/copy *Keyboard-ctrl-pressed? 0/imm32
-#?   }
-#?   # if (al & 0x80) a key is being lifted; return
-#?   50/push-eax
-#?   24/and-al-with 0x80/imm8
-#?   3c/compare-al-and 0/imm8
-#?   58/pop-to-eax
-#?   75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8
-#?   # - key pressed
-#?   # if (al == 0x2a) shift = true, return  # left shift pressed
-#?   {
-#?     3c/compare-al-and 0x2a/imm8
-#?     75/jump-if-!= break/disp8
-#?     # *shift = 1
-#?     c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32
-#?     # return
-#?     eb/jump $keyboard-interrupt-handler:epilogue/disp8
-#?   }
-#?   # if (al == 0x36) shift = true, return  # right shift pressed
-#?   {
-#?     3c/compare-al-and 0x36/imm8
-#?     75/jump-if-!= break/disp8
-#?     # *shift = 1
-#?     c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32
-#?     # return
-#?     eb/jump $keyboard-interrupt-handler:epilogue/disp8
-#?   }
-#?   # if (al == 0x1d) ctrl = true, return
-#?   {
-#?     3c/compare-al-and 0x1d/imm8
-#?     75/jump-if-!= break/disp8
-#?     # *ctrl = 1
-#?     c7 0/subop/copy *Keyboard-ctrl-pressed? 1/imm32
-#?     # return
-#?     eb/jump $keyboard-interrupt-handler:epilogue/disp8
-#?   }
-#?   # - convert key to character
-#?   # if (shift) use keyboard shift map
-#?   {
-#?     81 7/subop/compare *Keyboard-shift-pressed? 0/imm32
-#?     74/jump-if-= break/disp8
-#?     # sigils don't currently support labels inside *(eax+label)
-#?     05/add-to-eax Keyboard-shift-map/imm32
-#?     8a/byte-> *eax 0/r32/al
-#?     eb/jump $keyboard-interrupt-handler:select-map-done/disp8
-#?   }
-#?   # if (ctrl) al = *(ctrl map + al)
-#?   {
-#?     81 7/subop/compare *Keyboard-ctrl-pressed? 0/imm32
-#?     74/jump-if-= break/disp8
-#?     05/add-to-eax Keyboard-ctrl-map/imm32
-#?     8a/byte-> *eax 0/r32/al
-#?     eb/jump $keyboard-interrupt-handler:select-map-done/disp8
-#?   }
-#?   # otherwise al = *(normal map + al)
-#?   05/add-to-eax Keyboard-normal-map/imm32
-#?   8a/byte-> *eax 0/r32/al
-#? $keyboard-interrupt-handler:select-map-done:
-#?   # - if there's no character mapping, return
-#?   {
-#?     3c/compare-al-and 0/imm8
-#?     74/jump-if-= break/disp8
-#?     # - store al in keyboard buffer
-#?     88/<- *ecx 0/r32/al
-#?     # increment index
-#?     fe/increment-byte *Keyboard-buffer:write
-#?     # clear top nibble of index (keyboard buffer is circular)
-#?     80 4/subop/and-byte *Keyboard-buffer:write 0x0f/imm8
-#?   }
+  # - key released
+  # if (al == 0xaa) shift = false  # left shift is being lifted
+  {
+    3c/compare-al-and 0xaa/imm8
+    75/jump-if-!= break/disp8
+    # *shift = 0
+    c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32
+  }
+  # if (al == 0xb6) shift = false  # right shift is being lifted
+  {
+    3c/compare-al-and 0xb6/imm8
+    75/jump-if-!= break/disp8
+    # *shift = 0
+    c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32
+  }
+  # if (al == 0x9d) ctrl = false  # ctrl is being lifted
+  {
+    3c/compare-al-and 0x9d/imm8
+    75/jump-if-!= break/disp8
+    # *ctrl = 0
+    c7 0/subop/copy *Keyboard-ctrl-pressed? 0/imm32
+  }
+  # if (al & 0x80) a key is being lifted; return
+  50/push-eax
+  24/and-al-with 0x80/imm8
+  3c/compare-al-and 0/imm8
+  58/pop-to-eax
+  75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8
+  # - key pressed
+  # if (al == 0x2a) shift = true, return  # left shift pressed
+  {
+    3c/compare-al-and 0x2a/imm8
+    75/jump-if-!= break/disp8
+    # *shift = 1
+    c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32
+    # return
+    eb/jump $keyboard-interrupt-handler:epilogue/disp8
+  }
+  # if (al == 0x36) shift = true, return  # right shift pressed
+  {
+    3c/compare-al-and 0x36/imm8
+    75/jump-if-!= break/disp8
+    # *shift = 1
+    c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32
+    # return
+    eb/jump $keyboard-interrupt-handler:epilogue/disp8
+  }
+  # if (al == 0x1d) ctrl = true, return
+  {
+    3c/compare-al-and 0x1d/imm8
+    75/jump-if-!= break/disp8
+    # *ctrl = 1
+    c7 0/subop/copy *Keyboard-ctrl-pressed? 1/imm32
+    # return
+    eb/jump $keyboard-interrupt-handler:epilogue/disp8
+  }
+  # - convert key to character
+  # if (shift) use keyboard shift map
+  {
+    81 7/subop/compare *Keyboard-shift-pressed? 0/imm32
+    74/jump-if-= break/disp8
+    # sigils don't currently support labels inside *(eax+label)
+    05/add-to-eax Keyboard-shift-map/imm32
+    8a/byte-> *eax 0/r32/al
+    eb/jump $keyboard-interrupt-handler:select-map-done/disp8
+  }
+  # if (ctrl) al = *(ctrl map + al)
+  {
+    81 7/subop/compare *Keyboard-ctrl-pressed? 0/imm32
+    74/jump-if-= break/disp8
+    05/add-to-eax Keyboard-ctrl-map/imm32
+    8a/byte-> *eax 0/r32/al
+    eb/jump $keyboard-interrupt-handler:select-map-done/disp8
+  }
+  # otherwise al = *(normal map + al)
+  05/add-to-eax Keyboard-normal-map/imm32
+  8a/byte-> *eax 0/r32/al
+$keyboard-interrupt-handler:select-map-done:
+  # - if there's no character mapping, return
+  {
+    3c/compare-al-and 0/imm8
+    74/jump-if-= break/disp8
+    # - store al in keyboard buffer
+    88/<- *ecx 0/r32/al
+    # increment index
+    fe/increment-byte *Keyboard-buffer:write
+    # clear top nibble of index (keyboard buffer is circular)
+    80 4/subop/and-byte *Keyboard-buffer:write 0x0f/imm8
+  }
 $keyboard-interrupt-handler:epilogue:
   # epilogue
   9d/pop-flags
diff --git a/linux/126write-int-decimal.subx b/linux/126write-int-decimal.subx
index d38e1a17..bff585a7 100644
--- a/linux/126write-int-decimal.subx
+++ b/linux/126write-int-decimal.subx
@@ -167,10 +167,9 @@ test-write-int32-decimal-zero:
     e8/call  clear-stream/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-    b8/copy-to-eax 0x48/imm32
     # write-int32-decimal(_test-stream, 0)
     # . . push args
-    50/push-eax
+    68/push  0/imm32
     68/push  _test-stream/imm32
     # . . call
     e8/call  write-int32-decimal/disp32
diff --git a/linux/ex1.subx b/linux/ex1.subx
index 3a8f700c..183c014a 100644
--- a/linux/ex1.subx
+++ b/linux/ex1.subx
@@ -11,7 +11,6 @@
 == code
 
 Entry:
-e8/call test-write-int32-decimal-zero/disp32
 # exit(42)
 bb/copy-to-ebx  0x2a/imm32  # 42 in hex
 e8/call  syscall_exit/disp32