about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--510disk.mu43
-rw-r--r--apps/ex9.mu4
-rw-r--r--apps/img.mu17
3 files changed, 46 insertions, 18 deletions
diff --git a/510disk.mu b/510disk.mu
new file mode 100644
index 00000000..fd02bd4e
--- /dev/null
+++ b/510disk.mu
@@ -0,0 +1,43 @@
+fn load-sectors disk: (addr disk), lba: int, n: int, out: (addr stream byte) {
+  var curr-lba/ebx: int <- copy lba
+  var remaining/edx: int <- copy n
+  {
+    compare remaining, 0
+    break-if-<=
+    # sectors = min(remaining, 0x100)
+    var sectors/eax: int <- copy remaining
+    compare sectors, 0x100
+    {
+      break-if-<=
+      sectors <- copy 0x100
+    }
+    #
+    read-ata-disk disk, curr-lba, sectors, out
+    #
+    remaining <- subtract sectors
+    curr-lba <- add sectors
+    loop
+  }
+}
+
+fn store-sectors disk: (addr disk), lba: int, n: int, in: (addr stream byte) {
+  var curr-lba/ebx: int <- copy lba
+  var remaining/edx: int <- copy n
+  {
+    compare remaining, 0
+    break-if-<=
+    # sectors = min(remaining, 0x100)
+    var sectors/eax: int <- copy remaining
+    compare sectors, 0x100
+    {
+      break-if-<=
+      sectors <- copy 0x100
+    }
+    #
+    write-ata-disk disk, curr-lba, sectors, in
+    #
+    remaining <- subtract sectors
+    curr-lba <- add sectors
+    loop
+  }
+}
diff --git a/apps/ex9.mu b/apps/ex9.mu
index f256e349..30853c69 100644
--- a/apps/ex9.mu
+++ b/apps/ex9.mu
@@ -18,14 +18,14 @@
 fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
   var text-storage: (stream byte 0x200)
   var text/esi: (addr stream byte) <- address text-storage
-  read-ata-disk data-disk, 0/lba, 1/num-sectors, text
+  load-sectors data-disk, 0/lba, 1/num-sectors, text
 
   var word-count/eax: int <- word-count text
 
   var result-storage: (stream byte 0x10)
   var result/edi: (addr stream byte) <- address result-storage
   write-int32-decimal result, word-count
-  write-ata-disk data-disk, 0/lba, 1/num-sectors, result
+  store-sectors data-disk, 0/lba, 1/num-sectors, result
 }
 
 fn word-count in: (addr stream byte) -> _/eax: int {
diff --git a/apps/img.mu b/apps/img.mu
index b54840ff..9606bd43 100644
--- a/apps/img.mu
+++ b/apps/img.mu
@@ -36,22 +36,7 @@ fn load-image self: (addr image), data-disk: (addr disk) {
   var s/ebx: (addr stream byte) <- address s-storage
   draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "loading sectors from data disk", 3/fg, 0/bg
   move-cursor-to-left-margin-of-next-line 0/screen
-  read-ata-disk data-disk, 0/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0x100/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0x200/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0x300/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0x400/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0x500/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0x600/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0x700/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0x800/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0x900/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0xa00/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0xb00/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0xc00/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0xd00/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0xe00/lba, 0x100/sectors, s
-  read-ata-disk data-disk, 0xf00/lba, 0x100/sectors, s
+  load-sectors data-disk, 0/lba, 0x1000/sectors, s
   draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "parsing", 3/fg, 0/bg
   move-cursor-to-left-margin-of-next-line 0/screen
   initialize-image self, s