about summary refs log tree commit diff stats
path: root/500fake-screen.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-05-18 10:23:54 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-05-18 10:23:54 -0700
commitfd57c48c60851cd39a7105e3805c57d78cf2ea98 (patch)
treefb692b64462e45fdf3ac4f6c04fe7b72b4e94c0e /500fake-screen.mu
parent2952a2996060070c529d9b9692f6a6c4b6009d22 (diff)
downloadmu-fd57c48c60851cd39a7105e3805c57d78cf2ea98.tar.gz
start double-buffering
Amazing how much difference it makes even when the implementation is so
naive and slow.
Diffstat (limited to '500fake-screen.mu')
-rw-r--r--500fake-screen.mu39
1 files changed, 39 insertions, 0 deletions
diff --git a/500fake-screen.mu b/500fake-screen.mu
index fc907885..607f1ce8 100644
--- a/500fake-screen.mu
+++ b/500fake-screen.mu
@@ -516,3 +516,42 @@ fn pixel-index _screen: (addr screen), x: int, y: int -> _/ecx: int {
   result <- add x
   return result
 }
+
+# double-buffering primitive
+# 'screen' must be a fake screen. 'target-screen' is usually real.
+# Both screens must have the same size.
+fn copy-pixels _screen: (addr screen), target-screen: (addr screen) {
+  var screen/esi: (addr screen) <- copy _screen
+  var pixels-ah/eax: (addr handle array byte) <- get screen, pixels
+  var _pixels/eax: (addr array byte) <- lookup *pixels-ah
+  var pixels/edi: (addr array byte) <- copy _pixels
+  var width-a/edx: (addr int) <- get screen, width
+  var width/edx: int <- copy *width-a
+  width <- shift-left 3/log2-font-width
+  var height-a/ebx: (addr int) <- get screen, height
+  var height/ebx: int <- copy *height-a
+  height <- shift-left 4/log2-font-height
+  var i/esi: int <- copy 0
+  var y/ecx: int <- copy 0
+  {
+    # screen top left pixels x y width height
+    compare y, height
+    break-if->=
+    var x/eax: int <- copy 0
+    {
+      compare x, width
+      break-if->=
+      {
+        var color-addr/ebx: (addr byte) <- index pixels, i
+        var color/ebx: byte <- copy-byte *color-addr
+        var color2/ebx: int <- copy color
+        pixel target-screen, x, y, color2
+      }
+      x <- increment
+      i <- increment
+      loop
+    }
+    y <- increment
+    loop
+  }
+}