This commit is contained in:
Kartik K. Agaram 2021-02-10 22:34:08 -08:00
parent 2be221bce8
commit 08c55cb2b7
5 changed files with 20 additions and 14 deletions

View File

@ -90,6 +90,12 @@ fn draw-grapheme screen: (addr screen), g: grapheme, x: int, y: int, color: int,
copy-to *dest-color, src-color
}
# we can't really render non-ASCII yet, but when we do we'll be ready
fn draw-code-point screen: (addr screen), c: code-point, x: int, y: int, color: int, background-color: int {
var g/eax: grapheme <- copy c
draw-grapheme screen, g, x, y, color, background-color
}
# not really needed for a real screen, though it shouldn't do any harm
fn screen-cell-index screen-on-stack: (addr screen), x: int, y: int -> _/ecx: int {
var screen/esi: (addr screen) <- copy screen-on-stack
@ -193,7 +199,6 @@ fn clear-screen screen: (addr screen) {
return
}
# fake screen
var space/edi: grapheme <- copy 0x20
set-cursor-position screen, 0, 0
var screen-addr/esi: (addr screen) <- copy screen
var y/eax: int <- copy 1
@ -206,7 +211,7 @@ fn clear-screen screen: (addr screen) {
{
compare x, *width
break-if->
draw-grapheme screen, space, x, y, 0/fg=black, 0/bg=black
draw-code-point screen, 0x20/space, x, y, 0/fg=black, 0/bg=black
x <- increment
loop
}

View File

@ -69,6 +69,12 @@ fn draw-grapheme-at-cursor screen: (addr screen), g: grapheme, color: int, backg
draw-grapheme screen, g, cursor-x, cursor-y, color, background-color
}
# we can't really render non-ASCII yet, but when we do we'll be ready
fn draw-code-point-at-cursor screen: (addr screen), c: code-point, color: int, background-color: int {
var g/eax: grapheme <- copy c
draw-grapheme-at-cursor screen, g, color, background-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

View File

@ -301,8 +301,7 @@ fn test-draw-single-grapheme {
var screen-on-stack: screen
var screen/esi: (addr screen) <- address screen-on-stack
initialize-screen screen, 5, 4
var c/eax: grapheme <- copy 0x61/a
draw-grapheme screen, c, 0/x, 0/y, 1/fg, 2/bg
draw-code-point screen, 0x61/a, 0/x, 0/y, 1/fg, 2/bg
check-screen-row screen, 0/y, "a", "F - test-draw-single-grapheme" # top-left corner of the screen
check-screen-row-in-color screen, 1/fg, 0/y, "a", "F - test-draw-single-grapheme-fg"
check-screen-row-in-background-color screen, 2/bg, 0/y, "a", "F - test-draw-single-grapheme-bg"

View File

@ -10,6 +10,5 @@
# Expected output: letter 'A' in green near the top-left corner of screen
fn main {
var g/eax: grapheme <- copy 0x41/A
draw-grapheme 0/screen, g, 2/row, 1/col, 0xa/fg, 0/bg
draw-codepoint 0/screen, 0x41/A, 2/row, 1/col, 0xa/fg, 0/bg
}

View File

@ -19,29 +19,26 @@ fn main {
{
compare key, 0x68/h
break-if-!=
var g/eax: grapheme <- copy 0x2d/dash
draw-grapheme-at-cursor 0/screen, g, 0x31/fg, 0/bg
draw-code-point-at-cursor 0/screen, 0x2d/dash, 0x31/fg, 0/bg
move-cursor-left 0
}
{
compare key, 0x6a/j
break-if-!=
var g/eax: grapheme <- copy 0x7c/vertical-bar
draw-grapheme-at-cursor 0/screen, g, 0x31/fg, 0/bg
draw-code-point-at-cursor 0/screen, 0x7c/vertical-bar, 0x31/fg, 0/bg
move-cursor-down 0
}
{
compare key, 0x6b/k
break-if-!=
var g/eax: grapheme <- copy 0x7c/vertical-bar
draw-grapheme-at-cursor 0/screen, g, 0x31/fg, 0/bg
draw-code-point-at-cursor 0/screen, 0x7c/vertical-bar, 0x31/fg, 0/bg
move-cursor-up 0
}
{
compare key, 0x6c/l
break-if-!=
var g/eax: grapheme <- copy 0x2d/dash
draw-grapheme-at-cursor 0/screen, g, 0x31/fg, 0/bg
var g/eax: code-point <- copy 0x2d/dash
draw-code-point-at-cursor 0/screen, 0x2d/dash, 0x31/fg, 0/bg
move-cursor-right 0
}
loop