1 # Demo of reading and writing to disk. 2 # 3 # Steps for trying it out: 4 # 1. Translate this example into a disk image code.img. 5 # ./translate ex9.mu 6 # 2. Build a second disk image data.img containing some text. 7 # dd if=/dev/zero of=data.img count=20160 8 # echo 'abc def ghi' |dd of=data.img conv=notrunc 9 # 3. Familiarize yourself with how the data disk looks within xxd: 10 # xxd data.img |head 11 # 4. Run in an emulator, either Qemu or Bochs. 12 # qemu-system-i386 -hda code.img -hdb data.img 13 # bochs -f bochsrc.2disks 14 # 5. Exit the emulator. 15 # 6. Notice that the data disk now contains the word count of the original text. 16 # xxd data.img |head 17 18 fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) { 19 var text-storage: (stream byte 0x200) 20 var text/esi: (addr stream byte) <- address text-storage 21 load-sectors data-disk, 0/lba, 1/num-sectors, text 22 23 var word-count/eax: int <- word-count text