diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-05-31 23:43:49 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-05-31 23:43:49 -0700 |
commit | 9cc69d69c6cd83ed4aa367b4a08ca379cae45805 (patch) | |
tree | b469fd1bf0b3e46258cd835f82da72ee3d26e310 /prototypes/browse/5.mu | |
parent | 2f16a74783d830caf2cc01bd67996317195c94c9 (diff) | |
download | mu-9cc69d69c6cd83ed4aa367b4a08ca379cae45805.tar.gz |
6456 - new directory for live-blogging prototypes
I don't have layers yet in Mu. But I can still create lots of versions of a program.
Diffstat (limited to 'prototypes/browse/5.mu')
-rw-r--r-- | prototypes/browse/5.mu | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/prototypes/browse/5.mu b/prototypes/browse/5.mu new file mode 100644 index 00000000..d2d619cc --- /dev/null +++ b/prototypes/browse/5.mu @@ -0,0 +1,83 @@ +fn main args: (addr array (addr array byte)) -> exit-status/ebx: int { + var filename/eax: (addr array byte) <- first-arg args + var file/eax: (addr buffered-file) <- load-file filename + enable-screen-grid-mode + enable-keyboard-immediate-mode + { + render file, 5, 5, 30, 30 + var key/eax: byte <- read-key + compare key, 0x71 # 'q' + loop-if-!= + } + enable-keyboard-type-mode + enable-screen-type-mode + exit-status <- copy 0 +} + +fn render in: (addr buffered-file), toprow: int, leftcol: int, botrow: int, rightcol: int { + clear toprow, leftcol, botrow, rightcol + var row/ecx: int <- copy toprow +$line-loop: { + compare row, botrow + break-if->= + var col/edx: int <- copy leftcol + move-cursor row, col + { + compare col, rightcol + break-if->= + var c/eax: byte <- read-byte-buffered in + compare c, 0xffffffff # EOF marker + break-if-= $line-loop + compare c, 0xa # newline + break-if-= # no need to print newlines + # print c + print-byte c + col <- increment + loop + } # $char-loop + row <- increment + loop + } # $line-loop +} + +fn clear toprow: int, leftcol: int, botrow: int, rightcol: int { + var row/ecx: int <- copy toprow + { + compare row, botrow + break-if->= + var col/edx: int <- copy leftcol + move-cursor row, col + { + compare col, rightcol + break-if->= + print-string " " + col <- increment + loop + } + row <- increment + loop + } +} + +fn first-arg args-on-stack: (addr array (addr array byte)) -> out/eax: (addr array byte) { + var args/eax: (addr array (addr array byte)) <- copy args-on-stack + var result/eax: (addr addr array byte) <- index args, 1 + out <- copy *result +} + +fn load-file filename: (addr array byte) -> out/eax: (addr buffered-file) { + var result: (handle buffered-file) + { + var tmp1/eax: (addr handle buffered-file) <- address result + open filename, 0, tmp1 + } + out <- lookup result +} + +fn dump in: (addr buffered-file) { + var c/eax: byte <- read-byte-buffered in + compare c, 0xffffffff # EOF marker + break-if-= + print-byte c + loop +} |