about summary refs log tree commit diff stats
path: root/baremetal/309stream.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2021-01-15 21:27:52 -0800
committerKartik Agaram <vc@akkartik.com>2021-01-15 21:27:52 -0800
commit0d246473c5270a0f13a2706a1f0204d375f62d30 (patch)
tree7fc1fa8109a3d929f4197a88c8efe5b0cca6a0f4 /baremetal/309stream.subx
parent49424b1933051b6cf1ce3371ada9cd7fa2d31df0 (diff)
downloadmu-0d246473c5270a0f13a2706a1f0204d375f62d30.tar.gz
7524 - bring back some abort messages
Our infrastructure for displaying errors is far more rudimentary in
baremetal. Many ways things can go wrong. But making the attempt seems
better than not.

I'm also making some effort to keep it easy to see what has been copied
over from the top-level, by not modifying copied code to use syntax
sugar and so on. It may not be an important enough reason to mix
notations in a single file.
Diffstat (limited to 'baremetal/309stream.subx')
-rw-r--r--baremetal/309stream.subx21
1 files changed, 17 insertions, 4 deletions
diff --git a/baremetal/309stream.subx b/baremetal/309stream.subx
index 720ee0eb..0d470ca6 100644
--- a/baremetal/309stream.subx
+++ b/baremetal/309stream.subx
@@ -65,11 +65,11 @@ write-to-stream:  # s: (addr stream _), in: (addr byte), n: int
     8b/-> *(ebp+8) 7/r32/edi
     # var swrite/edx: int = s->write
     8b/-> *edi 2/r32/edx
-    # if (swrite + n > s->size) return
+    # if (swrite + n > s->size) abort
     8b/-> *(ebp+0x10) 1/r32/ecx
     01/add-to %ecx 2/r32/edx
     3b/compare 1/r32/ecx *(edi+8)
-    0f 8f/jump-if-> $write-to-stream:end/disp32  # TODO: abort
+    0f 8f/jump-if-> $write-to-stream:abort/disp32
     # var out/edx: (addr byte) = s->data + s->write
     8d/copy-address *(edi+edx+0xc) 2/r32/edx
     # var outend/ebx: (addr byte) = out + n
@@ -97,6 +97,13 @@ $write-to-stream:end:
     5d/pop-to-ebp
     c3/return
 
+$write-to-stream:abort:
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "write-to-stream: stream full" 3)  # 3=cyan
+    {
+      eb/jump loop/disp8
+    }
+    # never gets here
+
 read-from-stream:  # s: (addr stream _), out: (addr byte), n: int
     # . prologue
     55/push-ebp
@@ -111,11 +118,11 @@ read-from-stream:  # s: (addr stream _), out: (addr byte), n: int
     8b/-> *(ebp+8) 6/r32/esi
     # var sread/edx: int = s->read
     8b/-> *(esi+4) 2/r32/edx
-    # if (sread + n > s->write) return
+    # if (sread + n > s->write) abort
     8b/-> *(ebp+0x10) 1/r32/ecx
     01/add-to %ecx 2/r32/edx
     3b/compare 1/r32/ecx *esi
-    0f 8f/jump-if-> $read-from-stream:end/disp32  # TODO: abort
+    0f 8f/jump-if-> $read-from-stream:abort/disp32
     # var in/edx: (addr byte) = s->data + s->read
     8d/copy-address *(esi+edx+0xc) 2/r32/edx
     # var inend/ebx: (addr byte) = in + n
@@ -143,6 +150,12 @@ $read-from-stream:end:
     5d/pop-to-ebp
     c3/return
 
+$read-from-stream:abort:
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "read-from-stream: stream empty" 3)  # 3=cyan
+    {
+      eb/jump loop/disp8
+    }
+
 stream-first:  # s: (addr stream byte) -> result/eax: byte
     # . prologue
     55/push-ebp