about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--103screen.subx309
-rwxr-xr-xapps/assortbin44275 -> 44283 bytes
-rwxr-xr-xapps/bracesbin46146 -> 46154 bytes
-rwxr-xr-xapps/callsbin50807 -> 50815 bytes
-rwxr-xr-xapps/crenshaw2-1bin43626 -> 43634 bytes
-rwxr-xr-xapps/crenshaw2-1bbin44173 -> 44181 bytes
-rwxr-xr-xapps/dquotesbin47897 -> 47905 bytes
-rwxr-xr-xapps/ex1bin197 -> 205 bytes
-rwxr-xr-xapps/ex10bin264 -> 272 bytes
-rwxr-xr-xapps/ex11bin1178 -> 1186 bytes
-rwxr-xr-xapps/ex12bin234 -> 242 bytes
-rwxr-xr-xapps/ex13bin211 -> 219 bytes
-rwxr-xr-xapps/ex2bin198 -> 206 bytes
-rwxr-xr-xapps/ex3bin215 -> 223 bytes
-rwxr-xr-xapps/ex4bin236 -> 244 bytes
-rwxr-xr-xapps/ex5bin238 -> 246 bytes
-rwxr-xr-xapps/ex6bin232 -> 240 bytes
-rwxr-xr-xapps/ex7bin366 -> 374 bytes
-rwxr-xr-xapps/ex8bin234 -> 242 bytes
-rwxr-xr-xapps/ex9bin228 -> 236 bytes
-rwxr-xr-xapps/factorialbin42719 -> 42727 bytes
-rwxr-xr-xapps/hexbin46465 -> 46473 bytes
-rwxr-xr-xapps/mubin254274 -> 255698 bytes
-rwxr-xr-xapps/packbin56610 -> 56618 bytes
-rw-r--r--apps/screen.mu20
-rwxr-xr-xapps/sigilsbin58531 -> 58539 bytes
-rwxr-xr-xapps/surveybin54221 -> 54229 bytes
-rwxr-xr-xapps/testsbin43047 -> 43055 bytes
-rw-r--r--init.linux5
-rw-r--r--mu.vim2
30 files changed, 335 insertions, 1 deletions
diff --git a/103screen.subx b/103screen.subx
new file mode 100644
index 00000000..811630bf
--- /dev/null
+++ b/103screen.subx
@@ -0,0 +1,309 @@
+# Primitives for screen control.
+# Require Linux and a modern terminal.
+
+== code
+
+enable-screen-grid-mode:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    (flush Stdout)
+    (flush Stderr)
+    # switch to second screen buffer
+    (write 2 Esc)
+    (write 2 "[?1049h")
+    #
+    (clear-screen 0)
+$enable-screen-grid-mode:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+enable-screen-type-mode:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    (flush Stdout)
+    (flush Stderr)
+    # switch to first screen buffer
+    (write 2 Esc)
+    (write 2 "[?1049l")
+$enable-screen-type-mode:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+screen-size:  # -> nrows/eax: int, ncols/ecx: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (_maybe-open-terminal)
+    # var window-size-info/esi: (addr winsize)
+    # winsize is a type from the Linux kernel. We don't care how large it is.
+    81 5/subop/subtract %esp 0x40/imm32
+    89/<- %esi 4/r32/esp
+    # ioctl(*Terminal-file-descriptor, TIOCGWINSZ, window-size-info)
+    89/<- %edx 6/r32/esi
+    b9/copy-to-ecx 0x5413/imm32/TIOCGWINSZ
+    8b/-> *Terminal-file-descriptor 3/r32/ebx
+    e8/call syscall_ioctl/disp32
+    # some bitworking to extract 2 16-bit shorts
+    8b/-> *esi 0/r32/eax
+    81 4/subop/and %eax 0xffff/imm32
+    8b/-> *esi 1/r32/ecx
+    c1/shift 5/subop/logical-right %ecx 0x10/imm8
+$screen-size:end:
+    # . reclaim locals
+    81 0/subop/add %esp 0x40/imm32
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+clear-screen:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write 2 Esc)
+    (write 2 "[H")
+    (write 2 Esc)
+    (write 2 "[2J")
+$clear-screen:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+move-cursor:  # row: int, column: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    51/push-ecx
+    # var buf/ecx: (stream byte 32)
+    81 5/subop/subtract %esp 0x20/imm32
+    68/push 0x20/imm32/size
+    68/push 0/imm32/read
+    68/push 0/imm32/write
+    89/<- %ecx 4/r32/esp
+    # construct directive in buf
+    (write %ecx Esc)
+    (write %ecx "[")
+    (print-int32-decimal %ecx *(ebp+8))
+    (write %ecx ";")
+    (print-int32-decimal %ecx *(ebp+0xc))
+    (write %ecx "H")
+    # flush
+    (write-stream 2 %ecx)
+$move-cursor:end:
+    # . reclaim locals
+    81 0/subop/add %esp 0x2c/imm32
+    # . restore registers
+    59/pop-to-ecx
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+print-string:  # s: (addr array byte)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write 2 *(ebp+8))
+$print-string:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+print-int32-to-screen:  # n: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (print-int32-buffered Stdout *(ebp+8))
+    (flush Stdout)
+$print-int32-to-screen:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+reset-formatting:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write 2 Esc)
+    (write 2 "(B")
+    (write 2 Esc)
+    (write 2 "[m")
+$reset-formatting:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+start-color:  # fg: int, bg: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    51/push-ecx
+    # var buf/ecx: (stream byte 32)
+    81 5/subop/subtract %esp 0x20/imm32
+    68/push 0x20/imm32/size
+    68/push 0/imm32/read
+    68/push 0/imm32/write
+    89/<- %ecx 4/r32/esp
+    # construct directive in buf
+    # . set fg
+    (write %ecx Esc)
+    (write %ecx "[38;5;")
+    (print-int32-decimal %ecx *(ebp+8))
+    (write %ecx "m")
+    # . set bg
+    (write %ecx Esc)
+    (write %ecx "[48;5;")
+    (print-int32-decimal %ecx *(ebp+0xc))
+    (write %ecx "m")
+    # flush
+    (write-stream 2 %ecx)
+$start-color:end:
+    # . reclaim locals
+    81 0/subop/add %esp 0x2c/imm32
+    # . restore registers
+    59/pop-to-ecx
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+start-bold:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write 2 Esc)
+    (write 2 "[1m")
+$start-bold:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+start-underline:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write 2 Esc)
+    (write 2 "[4m")
+$start-underline:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+start-reverse-video:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write 2 Esc)
+    (write 2 "[7m")
+$start-reverse-video:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+# might require enabling blinking in your terminal program
+start-blinking:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write 2 Esc)
+    (write 2 "[5m")
+$start-blinking:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+hide-cursor:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write 2 Esc)
+    (write 2 "[?25l")
+$hide-cursor:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+show-cursor:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write 2 Esc)
+    (write 2 "[?12l")
+    (write 2 Esc)
+    (write 2 "[?25h")
+$show-cursor:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+# This is a low-level detail; I don't think everything should be a file.
+#
+# Open "/dev/tty" if necessary and cache its file descriptor in Terminal-file-descriptor
+# where later primitives can use it.
+_maybe-open-terminal:
+    81 7/subop/compare *Terminal-file-descriptor -1/imm32
+    75/jump-if-!= $_maybe-open-terminal:epilogue/disp8
+    # . save registers
+    50/push-eax
+    51/push-ecx
+    53/push-ebx
+    # open("/dev/tty", O_RDWR)
+    bb/copy-to-ebx Terminal-filename/imm32
+    b9/copy-to-ecx 2/imm32/O_RDWR
+    e8/call syscall_open/disp32
+    89/<- *Terminal-file-descriptor 0/r32/eax
+$_maybe-open-terminal:end:
+    # . restore registers
+    5b/pop-to-ebx
+    59/pop-to-ecx
+    58/pop-to-eax
+$_maybe-open-terminal:epilogue:
+    c3/return
+
+== data
+
+Terminal-file-descriptor:  # (addr int)
+  -1/imm32
+
+Esc:  # (addr array byte)
+  # size
+  1/imm32
+  # data
+  0x1b
+
+Terminal-filename:  # (addr kernel-string)
+  # "/dev/null"
+  2f/slash 64/d 65/e 76/v 2f/slash 74/t 74/t 79/y 0/nul
diff --git a/apps/assort b/apps/assort
index bc4b2eb9..7cbf2e7a 100755
--- a/apps/assort
+++ b/apps/assort
Binary files differdiff --git a/apps/braces b/apps/braces
index e7618b4e..864662ef 100755
--- a/apps/braces
+++ b/apps/braces
Binary files differdiff --git a/apps/calls b/apps/calls
index 16a1c90b..e4c185ed 100755
--- a/apps/calls
+++ b/apps/calls
Binary files differdiff --git a/apps/crenshaw2-1 b/apps/crenshaw2-1
index 34a50dcb..0791f0c4 100755
--- a/apps/crenshaw2-1
+++ b/apps/crenshaw2-1
Binary files differdiff --git a/apps/crenshaw2-1b b/apps/crenshaw2-1b
index cc00dc48..3b5d0bef 100755
--- a/apps/crenshaw2-1b
+++ b/apps/crenshaw2-1b
Binary files differdiff --git a/apps/dquotes b/apps/dquotes
index a49d897d..a9ba6ab5 100755
--- a/apps/dquotes
+++ b/apps/dquotes
Binary files differdiff --git a/apps/ex1 b/apps/ex1
index 5f17bc66..16371a7b 100755
--- a/apps/ex1
+++ b/apps/ex1
Binary files differdiff --git a/apps/ex10 b/apps/ex10
index cb8973fe..9529b921 100755
--- a/apps/ex10
+++ b/apps/ex10
Binary files differdiff --git a/apps/ex11 b/apps/ex11
index 1cb1aa5c..ffc1b034 100755
--- a/apps/ex11
+++ b/apps/ex11
Binary files differdiff --git a/apps/ex12 b/apps/ex12
index 80e5deeb..40ba51f5 100755
--- a/apps/ex12
+++ b/apps/ex12
Binary files differdiff --git a/apps/ex13 b/apps/ex13
index 6a4c16b8..46652134 100755
--- a/apps/ex13
+++ b/apps/ex13
Binary files differdiff --git a/apps/ex2 b/apps/ex2
index 5e0c1be1..2e1e0de8 100755
--- a/apps/ex2
+++ b/apps/ex2
Binary files differdiff --git a/apps/ex3 b/apps/ex3
index af787c11..e554f535 100755
--- a/apps/ex3
+++ b/apps/ex3
Binary files differdiff --git a/apps/ex4 b/apps/ex4
index 35ade1ee..b8f93eb9 100755
--- a/apps/ex4
+++ b/apps/ex4
Binary files differdiff --git a/apps/ex5 b/apps/ex5
index 805cadc3..a3c4f494 100755
--- a/apps/ex5
+++ b/apps/ex5
Binary files differdiff --git a/apps/ex6 b/apps/ex6
index 06fdfd7b..2fcd0897 100755
--- a/apps/ex6
+++ b/apps/ex6
Binary files differdiff --git a/apps/ex7 b/apps/ex7
index 0a535d45..731f4c21 100755
--- a/apps/ex7
+++ b/apps/ex7
Binary files differdiff --git a/apps/ex8 b/apps/ex8
index 78f1773d..6cb660fb 100755
--- a/apps/ex8
+++ b/apps/ex8
Binary files differdiff --git a/apps/ex9 b/apps/ex9
index 5140cf68..e067b833 100755
--- a/apps/ex9
+++ b/apps/ex9
Binary files differdiff --git a/apps/factorial b/apps/factorial
index 92e0523a..8d73facb 100755
--- a/apps/factorial
+++ b/apps/factorial
Binary files differdiff --git a/apps/hex b/apps/hex
index cd183977..806481f0 100755
--- a/apps/hex
+++ b/apps/hex
Binary files differdiff --git a/apps/mu b/apps/mu
index 700919ca..1e372839 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/pack b/apps/pack
index 22a66caf..997c34dd 100755
--- a/apps/pack
+++ b/apps/pack
Binary files differdiff --git a/apps/screen.mu b/apps/screen.mu
new file mode 100644
index 00000000..4f36809e
--- /dev/null
+++ b/apps/screen.mu
@@ -0,0 +1,20 @@
+# test some primitives for text-mode 
+
+fn main -> exit-status/ebx: int {
+  var nrows/eax: int <- copy 0
+  var ncols/ecx: int <- copy 0
+  nrows, ncols <- screen-size
+  enable-screen-grid-mode
+  move-cursor 5, 35
+  start-color 1, 0x7a
+  start-blinking
+  print-string "Hello world!"
+  reset-formatting
+  move-cursor 6, 35
+  print-string "tty dimensions: "
+  print-int32-to-screen nrows
+  print-string " rows, "
+  print-int32-to-screen ncols
+  print-string " rows\n"
+  exit-status <- copy 0
+}
diff --git a/apps/sigils b/apps/sigils
index 76becaf3..ef6518ec 100755
--- a/apps/sigils
+++ b/apps/sigils
Binary files differdiff --git a/apps/survey b/apps/survey
index 018e9fa7..c1c8e9c5 100755
--- a/apps/survey
+++ b/apps/survey
Binary files differdiff --git a/apps/tests b/apps/tests
index 4b1eea42..408ead69 100755
--- a/apps/tests
+++ b/apps/tests
Binary files differdiff --git a/init.linux b/init.linux
index a50a9147..f59cde48 100644
--- a/init.linux
+++ b/init.linux
@@ -67,3 +67,8 @@ syscall_mmap:  # arg/ebx: (addr mmap_arg_struct) -> status/eax: int
     b8/copy-to-eax 0x5a/imm32
     cd/syscall 0x80/imm8
     c3/return
+
+syscall_ioctl:  # fd/ebx: int, cmd/ecx: int, arg/edx: (addr _)
+    b8/copy-to-eax 0x36/imm32
+    cd/syscall 0x80/imm8
+    c3/return
diff --git a/mu.vim b/mu.vim
index bbbaebec..b36ed330 100644
--- a/mu.vim
+++ b/mu.vim
@@ -53,7 +53,7 @@ syntax match muControl "\<loop\>\|\<loop-if[^ ]*"
 highlight link muControl PreProc
 
 syntax match muKeyword " -> "
-syntax keyword muKeyword fn type var
+syntax keyword muKeyword fn type
 highlight link muKeyword PreProc
 
 syntax match muFunction "\(fn\s*\)\@<=\(\S\+\)"