diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-05-16 08:27:24 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-05-16 08:27:24 -0700 |
commit | 4d17068bc0a82dfa189ac9f8aa88dc0e1f741d9c (patch) | |
tree | fe6604916240a5a1ba77a1403e81b9533c31e725 | |
parent | 5e484fb2d53bfdaa4394ada4927d80a91008d600 (diff) | |
download | mu-4d17068bc0a82dfa189ac9f8aa88dc0e1f741d9c.tar.gz |
.
-rw-r--r-- | 507line.mu | 22 | ||||
-rw-r--r-- | ex11.mu | 30 |
2 files changed, 51 insertions, 1 deletions
diff --git a/507line.mu b/507line.mu index 7afdf9cc..8da67b07 100644 --- a/507line.mu +++ b/507line.mu @@ -60,3 +60,25 @@ fn draw-line screen: (addr screen), x0: int, y0: int, x1: int, y1: int, color: i loop } } + +fn draw-horizontal-line screen: (addr screen), y: int, x0: int, x1: int, color: int { + var x/eax: int <- copy x0 + { + compare x, x1 + break-if->= + pixel screen, x, y, color + x <- increment + loop + } +} + +fn draw-vertical-line screen: (addr screen), x: int, y0: int, y1: int, color: int { + var y/eax: int <- copy y0 + { + compare y, y1 + break-if->= + pixel screen, x, y, color + y <- increment + loop + } +} diff --git a/ex11.mu b/ex11.mu index 9b11c606..b62ff237 100644 --- a/ex11.mu +++ b/ex11.mu @@ -3,7 +3,7 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) { var env-storage: environment var env/esi: (addr environment) <- address env-storage - initialize-environment env, 5 5, 0x80 0x100, 0x200 0x140 + initialize-environment env, 0x10 0x10, 0x80 0x100, 0x200 0x140 render screen, env } @@ -39,6 +39,10 @@ fn render screen: (addr screen), _self: (addr environment) { disc screen, p0, 3/radius, 7/color 0xf/border disc screen, p1, 3/radius, 7/color 0xf/border disc screen, p2, 3/radius, 7/color 0xf/border + # cursor last of all + var cursor-ah/eax: (addr handle point) <- get self, cursor + var cursor/eax: (addr point) <- lookup *cursor-ah + cursor screen, cursor, 0xa/side, 3/color } fn bezier screen: (addr screen), _p0: (addr point), _p1: (addr point), _p2: (addr point), color: int { @@ -54,6 +58,30 @@ fn bezier screen: (addr screen), _p0: (addr point), _p1: (addr point), _p2: (add draw-monotonic-bezier screen, *x0 *y0, *x1 *y1, *x2 *y2, color } +fn cursor screen: (addr screen), _p: (addr point), side: int, color: int { + var half-side/eax: int <- copy side + half-side <- shift-right 1 + var p/esi: (addr point) <- copy _p + var x-a/ecx: (addr int) <- get p, x + var left-x/ecx: int <- copy *x-a + left-x <- subtract half-side + var y-a/edx: (addr int) <- get p, y + var top-y/edx: int <- copy *y-a + top-y <- subtract half-side + var max/eax: int <- copy left-x + max <- add side + draw-horizontal-line screen, top-y, left-x, max, color + max <- copy top-y + max <- add side + draw-vertical-line screen, left-x, top-y, max, color + var right-x/ebx: int <- copy left-x + right-x <- add side + draw-vertical-line screen, right-x, top-y, max, color + var bottom-y/edx: int <- copy top-y + bottom-y <- add side + draw-horizontal-line screen, bottom-y, left-x, right-x, color +} + fn line screen: (addr screen), _p0: (addr point), _p1: (addr point), color: int { var p0/esi: (addr point) <- copy _p0 var x0/ecx: (addr int) <- get p0, x |