about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--103screen.subx2
-rw-r--r--105files.subx58
-rwxr-xr-xapps/mubin255962 -> 256130 bytes
3 files changed, 59 insertions, 1 deletions
diff --git a/103screen.subx b/103screen.subx
index 0273a43a..75753a1d 100644
--- a/103screen.subx
+++ b/103screen.subx
@@ -42,7 +42,7 @@ screen-size:  # -> nrows/eax: int, ncols/ecx: int
     50/push-eax
     51/push-ecx
     52/push-edx
-    53/push-edx
+    53/push-ebx
     56/push-esi
     57/push-edi
     #
diff --git a/105files.subx b/105files.subx
new file mode 100644
index 00000000..ae85b493
--- /dev/null
+++ b/105files.subx
@@ -0,0 +1,58 @@
+== code
+
+open:  # filename: (addr array byte), write?: boolean, out: (addr handle buffered-file)
+    # hard-coded parameter: file-buffer-size of created buffered-file
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    51/push-ecx
+    52/push-edx
+    53/push-ebx
+    56/push-esi
+    57/push-edi
+    # ecx = filename
+    8b/-> *(ebp+8) 1/r32/ecx
+    # var size/edx: int = filename->length + 1 for the trailing null character
+    8b/-> *ecx 2/r32/edx
+    42/increment-edx
+    # var s/esi: (stream size)
+    29/subtract-from %esp 0/r32/eax
+    50/push-eax  # size
+    68/push 0/imm32/read
+    68/push 0/imm32/write
+    89/<- %esi 4/r32/esp
+    # copy filename and a final null character
+    (clear-stream %esi)
+    (write %esi %ecx)
+    # var fd/ecx: fd = open(filename)
+    8d/copy-address *(esi+0xc) 3/r32/ebx
+    8b/-> *(ebp+0xc) 1/r32/ecx/flags
+    e8/call syscall_open/disp32
+    89/<- %ecx 0/r32/eax
+    # allocate a buffered-file
+    (allocate Heap 0x1010 *(ebp+0x10))  # file-buffer-size + 16 for other fields
+    # var out-addr/edi: (addr buffered-file)
+    8b/-> *(ebp+0x10) 7/r32/edi
+    (lookup *edi *(edi+4))  # => eax
+    89/<- %edi 0/r32/eax
+    # out-addr->size = 4KB
+    c7 0/subop/copy *(edi+0xc) 0x1000/imm32/file-buffer-size  # Stream-size + 4 for fd
+    # out-addr->fd = fd
+    89/<- *edi 1/r32/ecx
+$open:end:
+    # . reclaim locals
+    01/add-to %esp 2/r32/edx
+    81 0/subop/add %esp 0xc/imm32
+    # . restore registers
+    5f/pop-to-edi
+    5e/pop-to-esi
+    5b/pop-to-ebx
+    5a/pop-to-edx
+    59/pop-to-ecx
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
diff --git a/apps/mu b/apps/mu
index 49eb1390..5158562c 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differ