diff options
author | Kartik Agaram <vc@akkartik.com> | 2021-01-12 00:28:25 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2021-01-12 00:32:06 -0800 |
commit | 0d12f6676bab81d1d68239dcd26089612450232d (patch) | |
tree | be66d577d24437aafffa7553ffe50d825f6183c7 /baremetal | |
parent | bb0e67a308922fc1a1a6972b00fcc37909a028ce (diff) | |
download | mu-0d12f6676bab81d1d68239dcd26089612450232d.tar.gz |
7502 - baremetal text: better interface
Diffstat (limited to 'baremetal')
-rw-r--r-- | baremetal/501draw-text.mu | 9 | ||||
-rw-r--r-- | baremetal/ex6.mu | 13 |
2 files changed, 13 insertions, 9 deletions
diff --git a/baremetal/501draw-text.mu b/baremetal/501draw-text.mu index af165e78..0f091952 100644 --- a/baremetal/501draw-text.mu +++ b/baremetal/501draw-text.mu @@ -35,10 +35,11 @@ fn draw-text-rightward screen: (addr screen), text: (addr array byte), x: int, x return xcurr } -# draw text from (x, y) to (xmax, ymax), wrapping as necessary +# draw text in the rectangle from (xmin, ymin) to (xmax, ymax), starting from (x, y), wrapping as necessary # return the next (x, y) coordinate in raster order where drawing stopped +# that way the caller can draw more if given the same min and max bounding-box. # if there isn't enough space, return 0 without modifying the screen -fn draw-text-rightward-wrapped screen: (addr screen), text: (addr array byte), x: int, y: int, xmax: int, ymax: int, color: int -> _/eax: int, _/ecx: int { +fn draw-text-wrapping-right-then-down screen: (addr screen), text: (addr array byte), xmin: int, ymin: int, xmax: int, ymax: int, x: int, y: int, color: int -> _/eax: int, _/ecx: int { var stream-storage: (stream byte 0x100) var stream/esi: (addr stream byte) <- address stream-storage write stream, text @@ -55,7 +56,7 @@ fn draw-text-rightward-wrapped screen: (addr screen), text: (addr array byte), x compare xcurr, xmax { break-if-< - xcurr <- copy x + xcurr <- copy xmin ycurr <- add 0x10 # font-height } loop @@ -78,7 +79,7 @@ fn draw-text-rightward-wrapped screen: (addr screen), text: (addr array byte), x compare xcurr, xmax { break-if-< - xcurr <- copy x + xcurr <- copy xmin ycurr <- add 0x10 # font-height } loop diff --git a/baremetal/ex6.mu b/baremetal/ex6.mu index f0c1f896..21922dab 100644 --- a/baremetal/ex6.mu +++ b/baremetal/ex6.mu @@ -1,4 +1,4 @@ -# Draw ASCII text within a bounding box, while wrapping. +# Drawing ASCII text incrementally within a bounding box. # # To build a disk image: # ./translate_mu_baremetal baremetal/ex6.mu # emits disk.img @@ -10,8 +10,11 @@ # Expected output: a box and text that doesn't overflow it fn main { - draw-box 0, 0xf, 0xf, 0x61, 0x41, 0x4 - var x/eax: int <- copy 0 - var y/ecx: int <- copy 0 - x, y <- draw-text-rightward-wrapped 0, "hello from baremetal Mu!", 0x10, 0x10, 0x60, 0x40, 0xa # xmax = 0x60, ymax = 0x40 + draw-box 0, 0xf, 0x1f, 0x79, 0x51, 0x4 + var x/eax: int <- copy 0x20 + var y/ecx: int <- copy 0x20 + x, y <- draw-text-wrapping-right-then-down 0, "hello ", 0x10, 0x20, 0x78, 0x50, x, y, 0xa # (0x10, 0x20) -> (0x78, 0x50) + x, y <- draw-text-wrapping-right-then-down 0, "from ", 0x10, 0x20, 0x78, 0x50, x, y, 0xa + x, y <- draw-text-wrapping-right-then-down 0, "baremetal ", 0x10, 0x20, 0x78, 0x50, x, y, 0xa + x, y <- draw-text-wrapping-right-then-down 0, "Mu!", 0x10, 0x20, 0x78, 0x50, x, y, 0xa } |