diff options
author | Kartik Agaram <vc@akkartik.com> | 2021-01-17 10:43:31 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2021-01-17 10:43:31 -0800 |
commit | 851959ccc6d728b9a6fa02ff42d170cbebd272bb (patch) | |
tree | 1fe4b43d9c4f22f9aca528f29b8b9e6726ce146b | |
parent | 9822a2429f549491b1c7dfa4035260bb6c44ff77 (diff) | |
download | mu-851959ccc6d728b9a6fa02ff42d170cbebd272bb.tar.gz |
7534
Don't assume screen dimensions.
-rw-r--r-- | baremetal/500text-screen.mu | 4 | ||||
-rw-r--r-- | baremetal/501draw-text.mu | 68 |
2 files changed, 47 insertions, 25 deletions
diff --git a/baremetal/500text-screen.mu b/baremetal/500text-screen.mu index 5458398b..4fa7a00e 100644 --- a/baremetal/500text-screen.mu +++ b/baremetal/500text-screen.mu @@ -50,9 +50,7 @@ fn screen-size screen: (addr screen) -> _/eax: int, _/ecx: int { compare screen, 0 { break-if-!= - width <- copy 0x30 # 768/16 - height <- copy 0x80 # 1024/8 - return width, height + return 0x400, 0x300 # 1024x768 } # fake screen var screen-addr/esi: (addr screen) <- copy screen diff --git a/baremetal/501draw-text.mu b/baremetal/501draw-text.mu index dd55d7a1..ca100831 100644 --- a/baremetal/501draw-text.mu +++ b/baremetal/501draw-text.mu @@ -14,10 +14,14 @@ fn cursor-left screen: (addr screen) { } fn cursor-right screen: (addr screen) { + var _width/eax: int <- copy 0 + var dummy/ecx: int <- copy 0 + _width, dummy <- screen-size screen + var width/edx: int <- copy _width var cursor-x/eax: int <- copy 0 var cursor-y/ecx: int <- copy 0 cursor-x, cursor-y <- cursor-position screen - compare cursor-x, 0x400 # screen-width + compare cursor-x, width { break-if-< return @@ -40,10 +44,14 @@ fn cursor-up screen: (addr screen) { } fn cursor-down screen: (addr screen) { + var dummy/eax: int <- copy 0 + var _height/ecx: int <- copy 0 + dummy, _height <- screen-size screen + var height/edx: int <- copy _height var cursor-x/eax: int <- copy 0 var cursor-y/ecx: int <- copy 0 cursor-x, cursor-y <- cursor-position screen - compare cursor-y, 0x300 # screen-height + compare cursor-y, height { break-if-< return @@ -173,10 +181,11 @@ fn move-cursor-rightward-and-downward screen: (addr screen), xmin: int, xmax: in } fn draw-text-wrapping-right-then-down-over-full-screen screen: (addr screen), text: (addr array byte), x: int, y: int, color: int -> _/eax: int, _/ecx: int { - var cursor-x/eax: int <- copy 0 - var cursor-y/ecx: int <- copy 0 - cursor-x, cursor-y <- draw-text-wrapping-right-then-down screen, text, 0, 0, 0x400, 0x300, x, y, color # 1024, 768 - return cursor-x, cursor-y + var x2/eax: int <- copy 0 + var y2/ecx: int <- copy 0 + x2, y2 <- screen-size screen # width, height + x2, y2 <- draw-text-wrapping-right-then-down screen, text, 0, 0, x2, y2, x, y, color + return x2, y2 # cursor-x, cursor-y } fn draw-text-wrapping-right-then-down-from-cursor screen: (addr screen), text: (addr array byte), xmin: int, ymin: int, xmax: int, ymax: int, color: int { @@ -195,7 +204,10 @@ fn draw-text-wrapping-right-then-down-from-cursor screen: (addr screen), text: ( } fn draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen: (addr screen), text: (addr array byte), color: int { - draw-text-wrapping-right-then-down-from-cursor screen, text, 0, 0, 0x400, 0x300, color # 1024, 768 + var width/eax: int <- copy 0 + var height/ecx: int <- copy 0 + width, height <- screen-size screen + draw-text-wrapping-right-then-down-from-cursor screen, text, 0, 0, width, height, color } fn draw-int32-hex-wrapping-right-then-down screen: (addr screen), n: int, xmin: int, ymin: int, xmax: int, ymax: int, x: int, y: int, color: int -> _/eax: int, _/ecx: int { @@ -248,10 +260,11 @@ fn draw-int32-hex-wrapping-right-then-down screen: (addr screen), n: int, xmin: } fn draw-int32-hex-wrapping-right-then-down-over-full-screen screen: (addr screen), n: int, x: int, y: int, color: int -> _/eax: int, _/ecx: int { - var cursor-x/eax: int <- copy 0 - var cursor-y/ecx: int <- copy 0 - cursor-x, cursor-y <- draw-int32-hex-wrapping-right-then-down screen, n, 0, 0, 0x400, 0x300, x, y, color # 1024, 768 - return cursor-x, cursor-y + var x2/eax: int <- copy 0 + var y2/ecx: int <- copy 0 + x2, y2 <- screen-size screen # width, height + x2, y2 <- draw-int32-hex-wrapping-right-then-down screen, n, 0, 0, x2, y2, x, y, color + return x2, y2 # cursor-x, cursor-y } fn draw-int32-hex-wrapping-right-then-down-from-cursor screen: (addr screen), n: int, xmin: int, ymin: int, xmax: int, ymax: int, color: int { @@ -270,7 +283,10 @@ fn draw-int32-hex-wrapping-right-then-down-from-cursor screen: (addr screen), n: } fn draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen: (addr screen), n: int, color: int { - draw-int32-hex-wrapping-right-then-down-from-cursor screen, n, 0, 0, 0x400, 0x300, color # 1024, 768 + var width/eax: int <- copy 0 + var height/ecx: int <- copy 0 + width, height <- screen-size screen + draw-int32-hex-wrapping-right-then-down-from-cursor screen, n, 0, 0, width, height, color } 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 -> _/eax: int, _/ecx: int { @@ -323,10 +339,11 @@ fn draw-int32-decimal-wrapping-right-then-down screen: (addr screen), n: int, xm } fn draw-int32-decimal-wrapping-right-then-down-over-full-screen screen: (addr screen), n: int, x: int, y: int, color: int -> _/eax: int, _/ecx: int { - var cursor-x/eax: int <- copy 0 - var cursor-y/ecx: int <- copy 0 - cursor-x, cursor-y <- draw-int32-decimal-wrapping-right-then-down screen, n, 0, 0, 0x400, 0x300, x, y, color # 1024, 768 - return cursor-x, cursor-y + var x2/eax: int <- copy 0 + var y2/ecx: int <- copy 0 + x2, y2 <- screen-size screen # width, height + x2, y2 <- draw-int32-decimal-wrapping-right-then-down screen, n, 0, 0, x2, y2, x, y, color + return x2, y2 # cursor-x, cursor-y } fn draw-int32-decimal-wrapping-right-then-down-from-cursor screen: (addr screen), n: int, xmin: int, ymin: int, xmax: int, ymax: int, color: int { @@ -345,7 +362,10 @@ fn draw-int32-decimal-wrapping-right-then-down-from-cursor screen: (addr screen) } fn draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen: (addr screen), n: int, color: int { - draw-int32-decimal-wrapping-right-then-down-from-cursor screen, n, 0, 0, 0x400, 0x300, color # 1024, 768 + var width/eax: int <- copy 0 + var height/ecx: int <- copy 0 + width, height <- screen-size screen + draw-int32-decimal-wrapping-right-then-down-from-cursor screen, n, 0, 0, width, height, color } ## Text direction: down then right @@ -449,10 +469,11 @@ fn draw-text-wrapping-down-then-right screen: (addr screen), text: (addr array b } fn draw-text-wrapping-down-then-right-over-full-screen screen: (addr screen), text: (addr array byte), x: int, y: int, color: int -> _/eax: int, _/ecx: int { - var cursor-x/eax: int <- copy 0 - var cursor-y/ecx: int <- copy 0 - cursor-x, cursor-y <- draw-text-wrapping-down-then-right screen, text, 0, 0, 0x400, 0x300, x, y, color # 1024, 768 - return cursor-x, cursor-y + var x2/eax: int <- copy 0 + var y2/ecx: int <- copy 0 + x2, y2 <- screen-size screen # width, height + x2, y2 <- draw-text-wrapping-down-then-right screen, text, 0, 0, x2, y2, x, y, color + return x2, y2 # cursor-x, cursor-y } fn draw-text-wrapping-down-then-right-from-cursor screen: (addr screen), text: (addr array byte), xmin: int, ymin: int, xmax: int, ymax: int, color: int { @@ -471,5 +492,8 @@ fn draw-text-wrapping-down-then-right-from-cursor screen: (addr screen), text: ( } fn draw-text-wrapping-down-then-right-from-cursor-over-full-screen screen: (addr screen), text: (addr array byte), color: int { - draw-text-wrapping-down-then-right-from-cursor screen, text, 0, 0, 0x400, 0x300, color # 1024, 768 + var width/eax: int <- copy 0 + var height/ecx: int <- copy 0 + width, height <- screen-size screen + draw-text-wrapping-down-then-right-from-cursor screen, text, 0, 0, width, height, color } |