From abba997d1bc7357f0509821c995833be66a749a0 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 6 Nov 2020 16:03:09 -0800 Subject: 7197 - tile: render screen contents and cursor --- 405screen.mu | 3 +-- apps/tile/value.mu | 48 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/405screen.mu b/405screen.mu index 7007e704..e271bf79 100644 --- a/405screen.mu +++ b/405screen.mu @@ -316,8 +316,7 @@ fn screen-grapheme-at-idx screen-on-stack: (addr screen), idx-on-stack: int -> _ var offset/ecx: (offset screen-cell) <- compute-offset data, idx var cell/eax: (addr screen-cell) <- index data, offset var src/eax: (addr grapheme) <- get cell, data - var result/eax: grapheme <- copy *src - return result + return *src } fn screen-color-at screen-on-stack: (addr screen), row: int, col: int -> _/eax: int { diff --git a/apps/tile/value.mu b/apps/tile/value.mu index 8e3e7a51..b874ac16 100644 --- a/apps/tile/value.mu +++ b/apps/tile/value.mu @@ -131,25 +131,26 @@ fn render-array screen: (addr screen), row: int, col: int, _a: (addr array value print-grapheme screen, 0x5d # ']' } -fn render-screen screen: (addr screen), row: int, col: int, _val: (addr screen) { +fn render-screen screen: (addr screen), row: int, col: int, _target-screen: (addr screen) { + reset-formatting screen + start-color screen, 0xf2, 7 move-cursor screen, row, col - start-color screen, 0, 0xf6 - var val/esi: (addr screen) <- copy _val - var ncols-a/ecx: (addr int) <- get val, num-cols + var target-screen/esi: (addr screen) <- copy _target-screen + var ncols-a/ecx: (addr int) <- get target-screen, num-cols print-upper-border screen, *ncols-a - var r/edx: int <- copy 0 - var nrows-a/ebx: (addr int) <- get val, num-rows + var r/edx: int <- copy 1 + var nrows-a/ebx: (addr int) <- get target-screen, num-rows { compare r, *nrows-a - break-if->= + break-if-> increment row # mutate arg move-cursor screen, row, col print-string screen, " " - var c/edi: int <- copy 0 + var c/edi: int <- copy 1 { compare c, *ncols-a - break-if->= - print-string screen, " " # TODO + break-if-> + print-screen-cell-of-fake-screen screen, target-screen, r, c c <- increment loop } @@ -159,6 +160,7 @@ fn render-screen screen: (addr screen), row: int, col: int, _val: (addr screen) } increment row # mutate arg move-cursor screen, row, col + start-color screen, 0xf2, 7 print-lower-border screen, *ncols-a } @@ -167,6 +169,32 @@ fn hash-color val: int -> _/eax: int { return result } +fn print-screen-cell-of-fake-screen screen: (addr screen), _target: (addr screen), _row: int, _col: int { + start-color screen, 0, 0xf6 + var target/esi: (addr screen) <- copy _target + var row/ecx: int <- copy _row + var col/edx: int <- copy _col + # if cursor is at screen-cell, add some fancy + { + var cursor-row/eax: (addr int) <- get target, cursor-row + compare *cursor-row, row + break-if-!= + var cursor-col/eax: (addr int) <- get target, cursor-col + compare *cursor-col, col + break-if-!= + start-blinking screen + start-color screen, 0, 1 + } + var g/eax: grapheme <- screen-grapheme-at target, row, col + { + compare g, 0 + break-if-!= + g <- copy 0x20 # space + } + print-grapheme screen, g + reset-formatting screen +} + fn print-upper-border screen: (addr screen), width: int { print-code-point screen, 0x250c # top-left corner var i/eax: int <- copy 0 -- cgit 1.4.1-2-gfad0