7502 - baremetal text: better interface

This commit is contained in:
Kartik Agaram 2021-01-12 00:28:25 -08:00
parent bb0e67a308
commit 0d12f6676b
2 changed files with 13 additions and 9 deletions

View File

@ -35,10 +35,11 @@ fn draw-text-rightward screen: (addr screen), text: (addr array byte), x: int, x
return xcurr 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 # 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 # 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-storage: (stream byte 0x100)
var stream/esi: (addr stream byte) <- address stream-storage var stream/esi: (addr stream byte) <- address stream-storage
write stream, text write stream, text
@ -55,7 +56,7 @@ fn draw-text-rightward-wrapped screen: (addr screen), text: (addr array byte), x
compare xcurr, xmax compare xcurr, xmax
{ {
break-if-< break-if-<
xcurr <- copy x xcurr <- copy xmin
ycurr <- add 0x10 # font-height ycurr <- add 0x10 # font-height
} }
loop loop
@ -78,7 +79,7 @@ fn draw-text-rightward-wrapped screen: (addr screen), text: (addr array byte), x
compare xcurr, xmax compare xcurr, xmax
{ {
break-if-< break-if-<
xcurr <- copy x xcurr <- copy xmin
ycurr <- add 0x10 # font-height ycurr <- add 0x10 # font-height
} }
loop loop

View File

@ -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: # To build a disk image:
# ./translate_mu_baremetal baremetal/ex6.mu # emits disk.img # ./translate_mu_baremetal baremetal/ex6.mu # emits disk.img
@ -10,8 +10,11 @@
# Expected output: a box and text that doesn't overflow it # Expected output: a box and text that doesn't overflow it
fn main { fn main {
draw-box 0, 0xf, 0xf, 0x61, 0x41, 0x4 draw-box 0, 0xf, 0x1f, 0x79, 0x51, 0x4
var x/eax: int <- copy 0 var x/eax: int <- copy 0x20
var y/ecx: int <- copy 0 var y/ecx: int <- copy 0x20
x, y <- draw-text-rightward-wrapped 0, "hello from baremetal Mu!", 0x10, 0x10, 0x60, 0x40, 0xa # xmax = 0x60, ymax = 0x40 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
} }