From 119e661f20c0b4d9d82cad3cd26b42a947a68521 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 19 May 2021 23:23:49 -0700 Subject: [PATCH] a second place with lousy storage management --- 501draw-text.mu | 20 ++++++++++++++++---- shell/tokenize.mu | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/501draw-text.mu b/501draw-text.mu index 8dbe0f4b..e9d4abd5 100644 --- a/501draw-text.mu +++ b/501draw-text.mu @@ -164,10 +164,22 @@ fn render-grapheme screen: (addr screen), g: grapheme, xmin: int, ymin: int, xma # return the next (x, y) coordinate in raster order where drawing stopped # that way the caller can draw more if given the same min and max bounding-box. # if there isn't enough space, truncate -fn draw-text-wrapping-right-then-down screen: (addr screen), text: (addr array byte), xmin: int, ymin: int, xmax: int, ymax: int, _x: int, _y: int, color: int, background-color: int -> _/eax: int, _/ecx: int { - var stream-storage: (stream byte 0x100) - var stream/esi: (addr stream byte) <- address stream-storage - write stream, text +fn draw-text-wrapping-right-then-down screen: (addr screen), _text: (addr array byte), xmin: int, ymin: int, xmax: int, ymax: int, _x: int, _y: int, color: int, background-color: int -> _/eax: int, _/ecx: int { + # TODO: obscenely pessimally sized + var stream-storage: (stream byte 0x200) + var stream/edi: (addr stream byte) <- address stream-storage + var text/esi: (addr array byte) <- copy _text + var len/eax: int <- length text + compare len, 0x200 + { + break-if-< + write stream, "ERROR: stream too small in draw-text-wrapping-right-then-down" + } + compare len, 0x200 + { + break-if->= + write stream, text + } var x/eax: int <- copy _x var y/ecx: int <- copy _y x, y <- draw-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color diff --git a/shell/tokenize.mu b/shell/tokenize.mu index 03c04910..b280a049 100644 --- a/shell/tokenize.mu +++ b/shell/tokenize.mu @@ -15,6 +15,7 @@ fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace) break-if-!= # initialize token data each iteration to avoid aliasing var dest-ah/eax: (addr handle stream byte) <- get token, text-data + # TODO: obscenely pessimally sized # I'm allocating 1KB for every. single. token. Just because a whole definition needs to fit in a string sometimes. Absolutely bonkers. populate-stream dest-ah, 0x400/max-definition-size #