diff options
Diffstat (limited to 'baremetal')
-rw-r--r-- | baremetal/103grapheme.subx | 23 | ||||
-rw-r--r-- | baremetal/500text-screen.mu | 3 | ||||
-rw-r--r-- | baremetal/501draw-text.mu | 68 | ||||
-rw-r--r-- | baremetal/ex4.mu | 2 |
4 files changed, 54 insertions, 42 deletions
diff --git a/baremetal/103grapheme.subx b/baremetal/103grapheme.subx index f854e03d..5b160bfe 100644 --- a/baremetal/103grapheme.subx +++ b/baremetal/103grapheme.subx @@ -2,9 +2,16 @@ # # We need to do this in machine code because Mu doesn't have global variables # yet (for the start of video memory). +# +# There are uncomfortable assumptions baked in here about english/latin +# script. We convert the grid of pixels into a fixed-width grid of graphemes, +# which may not work well with other language families. == code +# The Mu computer's screen is 1024px wide and 768px tall. +# The Mu computer's font is 8px wide and 16px tall. +# Therefore 'x' here is in [0, 128), and 'y' is in [0, 48) draw-grapheme-on-real-screen: # g: grapheme, x: int, y: int, color: int, background-color: int # . prologue 55/push-ebp @@ -22,25 +29,29 @@ draw-grapheme-on-real-screen: # g: grapheme, x: int, y: int, color: int, backgr # if (letter-bitmap >= 0x9000) return # characters beyond ASCII currently not supported 81 7/subop/compare %esi 0x9000/imm32 7d/jump-if->= $draw-grapheme-on-real-screen:end/disp8 - # edx = y + # var ycurr/edx: int = y*16 8b/-> *(ebp+0x10) 2/r32/edx - # var ymax/ebx: int = y + 16 + c1 4/subop/shift-left %edx 4/imm8 + # var ymax/ebx: int = ycurr + 16 8b/-> *(ebp+0x10) 3/r32/ebx + c1 4/subop/shift-left %ebx 4/imm8 81 0/subop/add %ebx 0x10/imm32 { - # if (y >= ymax) break + # if (ycurr >= ymax) break 39/compare %edx 3/r32/ebx 7d/jump-if->= break/disp8 - # eax = x + 7 + # var xcurr/eax: int = x*8 + 7 8b/-> *(ebp+0xc) 0/r32/eax # font-width - 1 + c1 4/subop/shift-left %eax 3/imm8 81 0/subop/add %eax 7/imm32 - # var xmin/ecx: int = x + # var xmin/ecx: int = x*8 8b/-> *(ebp+0xc) 1/r32/ecx + c1 4/subop/shift-left %ecx 3/imm8 # var row-bitmap/ebx: int = *letter-bitmap 53/push-ebx 8b/-> *esi 3/r32/ebx { - # if (x < xmin) break + # if (xcurr < xmin) break 39/compare %eax 1/r32/ecx 7c/jump-if-< break/disp8 # shift LSB from row-bitmap into carry flag (CF) diff --git a/baremetal/500text-screen.mu b/baremetal/500text-screen.mu index 96c6644f..b387496f 100644 --- a/baremetal/500text-screen.mu +++ b/baremetal/500text-screen.mu @@ -45,13 +45,14 @@ fn initialize-screen screen: (addr screen), width: int, height: int { copy-to *dest, 0 } +# in graphemes fn screen-size screen: (addr screen) -> _/eax: int, _/ecx: int { var width/eax: int <- copy 0 var height/ecx: int <- copy 0 compare screen, 0 { break-if-!= - return 0x400, 0x300 # 1024x768 + return 0x80, 0x30 # 128x48 } # fake screen var screen-addr/esi: (addr screen) <- copy screen diff --git a/baremetal/501draw-text.mu b/baremetal/501draw-text.mu index ca100831..0bb95dee 100644 --- a/baremetal/501draw-text.mu +++ b/baremetal/501draw-text.mu @@ -9,7 +9,7 @@ fn cursor-left screen: (addr screen) { break-if-> return } - cursor-x <- subtract 8 # font-width + cursor-x <- decrement set-cursor-position screen, cursor-x, cursor-y } @@ -26,7 +26,7 @@ fn cursor-right screen: (addr screen) { break-if-< return } - cursor-x <- add 8 # font-width + cursor-x <- increment set-cursor-position screen, cursor-x, cursor-y } @@ -39,7 +39,7 @@ fn cursor-up screen: (addr screen) { break-if-> return } - cursor-y <- subtract 0x10 # screen-height + cursor-y <- decrement set-cursor-position screen, cursor-x, cursor-y } @@ -56,7 +56,7 @@ fn cursor-down screen: (addr screen) { break-if-< return } - cursor-y <- add 0x10 # screen-height + cursor-y <- increment set-cursor-position screen, cursor-x, cursor-y } @@ -82,7 +82,7 @@ fn draw-text-rightward screen: (addr screen), text: (addr array byte), x: int, x var g/eax: grapheme <- read-grapheme stream compare g, 0xffffffff # end-of-file break-if-= - xcurr <- add 8 # font-width + xcurr <- increment loop } compare xcurr, xmax @@ -98,7 +98,7 @@ fn draw-text-rightward screen: (addr screen), text: (addr array byte), x: int, x compare g, 0xffffffff # end-of-file break-if-= draw-grapheme screen, g, xcurr, y, color - xcurr <- add 8 # font-width + xcurr <- increment loop } set-cursor-position screen, xcurr, y @@ -130,12 +130,12 @@ fn draw-text-wrapping-right-then-down screen: (addr screen), text: (addr array b var g/eax: grapheme <- read-grapheme stream compare g, 0xffffffff # end-of-file break-if-= - xcurr <- add 8 # font-width + xcurr <- increment compare xcurr, xmax { break-if-< xcurr <- copy xmin - ycurr <- add 0x10 # font-height + ycurr <- increment } loop } @@ -153,12 +153,12 @@ fn draw-text-wrapping-right-then-down screen: (addr screen), text: (addr array b compare g, 0xffffffff # end-of-file break-if-= draw-grapheme screen, g, xcurr, ycurr, color - xcurr <- add 8 # font-width + xcurr <- increment compare xcurr, xmax { break-if-< xcurr <- copy xmin - ycurr <- add 0x10 # font-height + ycurr <- increment } loop } @@ -170,12 +170,12 @@ fn move-cursor-rightward-and-downward screen: (addr screen), xmin: int, xmax: in var cursor-x/eax: int <- copy 0 var cursor-y/ecx: int <- copy 0 cursor-x, cursor-y <- cursor-position screen - cursor-x <- add 8 # font-width + cursor-x <- increment compare cursor-x, xmax { break-if-< cursor-x <- copy xmin - cursor-y <- add 0x10 # font-height + cursor-y <- increment } set-cursor-position screen, cursor-x, cursor-y } @@ -193,12 +193,12 @@ fn draw-text-wrapping-right-then-down-from-cursor screen: (addr screen), text: ( var cursor-y/ecx: int <- copy 0 cursor-x, cursor-y <- cursor-position screen var end-x/edx: int <- copy cursor-x - end-x <- add 8 # font-width + end-x <- increment compare end-x, xmax { break-if-< cursor-x <- copy xmin - cursor-y <- add 0x10 # font-height + cursor-y <- increment } cursor-x, cursor-y <- draw-text-wrapping-right-then-down screen, text, xmin, ymin, xmax, ymax, cursor-x, cursor-y, color } @@ -223,12 +223,12 @@ fn draw-int32-hex-wrapping-right-then-down screen: (addr screen), n: int, xmin: var g/eax: grapheme <- read-grapheme stream compare g, 0xffffffff # end-of-file break-if-= - xcurr <- add 8 # font-width + xcurr <- increment compare xcurr, xmax { break-if-< xcurr <- copy xmin - ycurr <- add 0x10 # font-height + ycurr <- increment } loop } @@ -246,12 +246,12 @@ fn draw-int32-hex-wrapping-right-then-down screen: (addr screen), n: int, xmin: compare g, 0xffffffff # end-of-file break-if-= draw-grapheme screen, g, xcurr, ycurr, color - xcurr <- add 8 # font-width + xcurr <- increment compare xcurr, xmax { break-if-< xcurr <- copy xmin - ycurr <- add 0x10 # font-height + ycurr <- increment } loop } @@ -272,12 +272,12 @@ fn draw-int32-hex-wrapping-right-then-down-from-cursor screen: (addr screen), n: var cursor-y/ecx: int <- copy 0 cursor-x, cursor-y <- cursor-position screen var end-x/edx: int <- copy cursor-x - end-x <- add 8 # font-width + end-x <- increment compare end-x, xmax { break-if-< cursor-x <- copy xmin - cursor-y <- add 0x10 # font-height + cursor-y <- increment } cursor-x, cursor-y <- draw-int32-hex-wrapping-right-then-down screen, n, xmin, ymin, xmax, ymax, cursor-x, cursor-y, color } @@ -302,12 +302,12 @@ fn draw-int32-decimal-wrapping-right-then-down screen: (addr screen), n: int, xm var g/eax: grapheme <- read-grapheme stream compare g, 0xffffffff # end-of-file break-if-= - xcurr <- add 8 # font-width + xcurr <- increment compare xcurr, xmax { break-if-< xcurr <- copy xmin - ycurr <- add 0x10 # font-height + ycurr <- increment } loop } @@ -325,12 +325,12 @@ fn draw-int32-decimal-wrapping-right-then-down screen: (addr screen), n: int, xm compare g, 0xffffffff # end-of-file break-if-= draw-grapheme screen, g, xcurr, ycurr, color - xcurr <- add 8 # font-width + xcurr <- increment compare xcurr, xmax { break-if-< xcurr <- copy xmin - ycurr <- add 0x10 # font-height + ycurr <- increment } loop } @@ -351,12 +351,12 @@ fn draw-int32-decimal-wrapping-right-then-down-from-cursor screen: (addr screen) var cursor-y/ecx: int <- copy 0 cursor-x, cursor-y <- cursor-position screen var end-x/edx: int <- copy cursor-x - end-x <- add 8 # font-width + end-x <- increment compare end-x, xmax { break-if-< cursor-x <- copy xmin - cursor-y <- add 0x10 # font-height + cursor-y <- increment } cursor-x, cursor-y <- draw-int32-decimal-wrapping-right-then-down screen, n, xmin, ymin, xmax, ymax, cursor-x, cursor-y, color } @@ -385,7 +385,7 @@ fn draw-text-downward screen: (addr screen), text: (addr array byte), x: int, y: var g/eax: grapheme <- read-grapheme stream compare g, 0xffffffff # end-of-file break-if-= - ycurr <- add 0x10 # font-height + ycurr <- increment loop } compare ycurr, ymax @@ -401,7 +401,7 @@ fn draw-text-downward screen: (addr screen), text: (addr array byte), x: int, y: compare g, 0xffffffff # end-of-file break-if-= draw-grapheme screen, g, x, ycurr, color - ycurr <- add 0x10 # font-height + ycurr <- increment loop } set-cursor-position screen, x, ycurr @@ -432,11 +432,11 @@ fn draw-text-wrapping-down-then-right screen: (addr screen), text: (addr array b var g/eax: grapheme <- read-grapheme stream compare g, 0xffffffff # end-of-file break-if-= - ycurr <- add 0x10 # font-height + ycurr <- increment compare ycurr, ymax { break-if-< - xcurr <- add 8 # font-width + xcurr <- increment ycurr <- copy ymin } loop @@ -455,11 +455,11 @@ fn draw-text-wrapping-down-then-right screen: (addr screen), text: (addr array b compare g, 0xffffffff # end-of-file break-if-= draw-grapheme screen, g, xcurr, ycurr, color - ycurr <- add 0x10 # font-height + ycurr <- increment compare ycurr, ymax { break-if-< - xcurr <- add 8 # font-width + xcurr <- increment ycurr <- copy ymin } loop @@ -481,11 +481,11 @@ fn draw-text-wrapping-down-then-right-from-cursor screen: (addr screen), text: ( var cursor-y/ecx: int <- copy 0 cursor-x, cursor-y <- cursor-position screen var end-y/edx: int <- copy cursor-y - end-y <- add 0x10 # font-height + end-y <- increment compare end-y, ymax { break-if-< - cursor-x <- add 8 # font-width + cursor-x <- increment cursor-y <- copy ymin } cursor-x, cursor-y <- draw-text-wrapping-down-then-right screen, text, xmin, ymin, xmax, ymax, cursor-x, cursor-y, color diff --git a/baremetal/ex4.mu b/baremetal/ex4.mu index 52b681bc..8a3e285e 100644 --- a/baremetal/ex4.mu +++ b/baremetal/ex4.mu @@ -11,5 +11,5 @@ fn main { var g/eax: grapheme <- copy 0x41 # 'A' - draw-grapheme 0, g, 0x10, 0x10, 0xa + draw-grapheme 0, g, 2, 1, 0xa # x of 2 graphemes = 16px from top-left; y of 1 grapheme = 16px down from top-left } |