diff options
-rw-r--r-- | 500fake-screen.mu | 103 |
1 files changed, 44 insertions, 59 deletions
diff --git a/500fake-screen.mu b/500fake-screen.mu index 1d13f2cf..43f6152c 100644 --- a/500fake-screen.mu +++ b/500fake-screen.mu @@ -18,10 +18,8 @@ type screen { data: (handle array screen-cell) cursor-x: int # [0..width) cursor-y: int # [0..height) - invalid-cell-index: int # pixel graphics pixels: (handle array byte) - invalid-pixel-index: int } type screen-cell { @@ -48,14 +46,10 @@ fn initialize-screen _screen: (addr screen), width: int, height: int, pixel-grap var data-ah/edi: (addr handle array screen-cell) <- get screen, data var capacity/eax: int <- copy width capacity <- multiply height - # add 1 for sentinel - capacity <- increment # populate data-ah, capacity # save sentinel index capacity <- decrement - var dest/ecx: (addr int) <- get screen, invalid-cell-index - copy-to *dest, capacity } # if necessary, populate screen->pixels { @@ -66,14 +60,10 @@ fn initialize-screen _screen: (addr screen), width: int, height: int, pixel-grap capacity <- shift-left 3/log2-font-width capacity <- multiply height capacity <- shift-left 4/log2-font-height - # add 1 for sentinel - capacity <- increment # populate pixels-ah, capacity # save sentinel index capacity <- decrement - var dest/ecx: (addr int) <- get screen, invalid-pixel-index - copy-to *dest, capacity } # screen->cursor-x = 0 dest <- get screen, cursor-x @@ -111,6 +101,32 @@ fn draw-grapheme _screen: (addr screen), g: grapheme, x: int, y: int, color: int return } # fake screen + # ignore if out of bounds + { + compare x, 0 + break-if->= + return + } + { + var xmax/eax: (addr int) <- get screen, width + var xcurr/ecx: int <- copy x + compare xcurr, *xmax + break-if-< + return + } + { + compare y, 0 + break-if->= + return + } + { + var ymax/eax: (addr int) <- get screen, height + var ycurr/ecx: int <- copy y + compare ycurr, *ymax + break-if-< + return + } + # var index/ecx: int <- screen-cell-index screen, x, y var data-ah/eax: (addr handle array screen-cell) <- get screen, data var data/eax: (addr array screen-cell) <- lookup *data-ah @@ -136,35 +152,6 @@ fn draw-code-point screen: (addr screen), c: code-point, x: int, y: int, color: # fake screens only fn screen-cell-index _screen: (addr screen), x: int, y: int -> _/ecx: int { var screen/esi: (addr screen) <- copy _screen - # if out of bounds, silently return a pixel that's never checked - { - compare x, 0 - break-if->= - var invalid/eax: (addr int) <- get screen, invalid-cell-index - return *invalid - } - { - var xmax/eax: (addr int) <- get screen, width - var xcurr/ecx: int <- copy x - compare xcurr, *xmax - break-if-< - var invalid/eax: (addr int) <- get screen, invalid-cell-index - return *invalid - } - { - compare y, 0 - break-if->= - var invalid/eax: (addr int) <- get screen, invalid-cell-index - return *invalid - } - { - var ymax/eax: (addr int) <- get screen, height - var ycurr/ecx: int <- copy y - compare ycurr, *ymax - break-if-< - var invalid/eax: (addr int) <- get screen, invalid-cell-index - return *invalid - } var width-addr/eax: (addr int) <- get screen, width var result/ecx: int <- copy y result <- multiply *width-addr @@ -515,44 +502,42 @@ fn pixel screen: (addr screen), x: int, y: int, color: int { break-if-!= abort "pixel graphics not enabled for this screen" } - var index/ecx: int <- pixel-index screen, x, y - var dest/ecx: (addr byte) <- index pixels, index - var src/eax: byte <- copy-byte color - copy-byte-to *dest, src -} - -fn pixel-index _screen: (addr screen), x: int, y: int -> _/ecx: int { - var screen/esi: (addr screen) <- copy _screen + # ignore if out of bounds { compare x, 0 break-if->= - var invalid/eax: (addr int) <- get screen, invalid-pixel-index - return *invalid + return } { - var xmax-a/eax: (addr int) <- get screen, width - var xmax/eax: int <- copy *xmax-a + var xmax-addr/eax: (addr int) <- get screen, width + var xmax/eax: int <- copy *xmax-addr xmax <- shift-left 3/log2-font-width compare x, xmax break-if-< - var invalid/eax: (addr int) <- get screen, invalid-pixel-index - return *invalid + return } { compare y, 0 break-if->= - var invalid/eax: (addr int) <- get screen, invalid-pixel-index - return *invalid + return } { - var ymax-a/eax: (addr int) <- get screen, height - var ymax/eax: int <- copy *ymax-a + var ymax-addr/eax: (addr int) <- get screen, height + var ymax/eax: int <- copy *ymax-addr ymax <- shift-left 4/log2-font-height compare y, ymax break-if-< - var invalid/eax: (addr int) <- get screen, invalid-pixel-index - return *invalid + return } + # + var index/ecx: int <- pixel-index screen, x, y + var dest/ecx: (addr byte) <- index pixels, index + var src/eax: byte <- copy-byte color + copy-byte-to *dest, src +} + +fn pixel-index _screen: (addr screen), x: int, y: int -> _/ecx: int { + var screen/esi: (addr screen) <- copy _screen var width-addr/eax: (addr int) <- get screen, width var result/ecx: int <- copy y result <- multiply *width-addr |