about summary refs log tree commit diff stats
path: root/baremetal/501draw-text.mu
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2021-01-13 16:57:04 -0800
committerKartik Agaram <vc@akkartik.com>2021-01-13 16:57:04 -0800
commitec0d5bb17e22e31c0edfc1b9b1e95ef363d690e7 (patch)
tree0dd6b1dd1b9358f0e9495545bf6679f777706bbd /baremetal/501draw-text.mu
parentf6fd7e1be0780b5b6dee042bef1c4f0264069787 (diff)
downloadmu-ec0d5bb17e22e31c0edfc1b9b1e95ef363d690e7.tar.gz
7510 - baremetal: a game of snake
Diffstat (limited to 'baremetal/501draw-text.mu')
-rw-r--r--baremetal/501draw-text.mu61
1 files changed, 61 insertions, 0 deletions
diff --git a/baremetal/501draw-text.mu b/baremetal/501draw-text.mu
index 5ddb4bf5..fa284d68 100644
--- a/baremetal/501draw-text.mu
+++ b/baremetal/501draw-text.mu
@@ -1,3 +1,64 @@
+# some primitives for moving the cursor without making assumptions about
+# raster order
+fn cursor-left screen: (addr screen) {
+  var cursor-x/eax: int <- copy 0
+  var cursor-y/ecx: int <- copy 0
+  cursor-x, cursor-y <- cursor-position screen
+  compare cursor-x, 0
+  {
+    break-if->
+    return
+  }
+  cursor-x <- subtract 8  # font-width
+  set-cursor-position screen, cursor-x, cursor-y
+}
+
+fn cursor-right screen: (addr screen) {
+  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
+  {
+    break-if-<
+    return
+  }
+  cursor-x <- add 8  # font-width
+  set-cursor-position screen, cursor-x, cursor-y
+}
+
+fn cursor-up screen: (addr screen) {
+  var cursor-x/eax: int <- copy 0
+  var cursor-y/ecx: int <- copy 0
+  cursor-x, cursor-y <- cursor-position screen
+  compare cursor-y, 0
+  {
+    break-if->
+    return
+  }
+  cursor-y <- subtract 0x10  # screen-height
+  set-cursor-position screen, cursor-x, cursor-y
+}
+
+fn cursor-down screen: (addr screen) {
+  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
+  {
+    break-if-<
+    return
+  }
+  cursor-y <- add 0x10  # screen-height
+  set-cursor-position screen, cursor-x, cursor-y
+}
+
+fn draw-grapheme-at-cursor screen: (addr screen), g: grapheme, color: int {
+  var cursor-x/eax: int <- copy 0
+  var cursor-y/ecx: int <- copy 0
+  cursor-x, cursor-y <- cursor-position screen
+  draw-grapheme screen, g, cursor-x, cursor-y, color
+}
+
 # draw a single line of text from x, y to xmax
 # return the next 'x' coordinate
 # if there isn't enough space, return 0 without modifying the screen