Advertisement
Madmouse

A FAT formatted floppy disk in assembly

Dec 19th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;////////////////////////////////////////////////////////////////////////////////
  2. ;// THE SCOTCH-WARE LICENSE (Revision 0):
  3. ;// <aaronryool@gmail.com> wrote this file. As long as you retain this notice you
  4. ;// can do whatever you want with this stuff. If we meet some day, and you think
  5. ;// this stuff is worth it, you can buy me a shot of scotch in return
  6. ;////////////////////////////////////////////////////////////////////////////////
  7. ; This assembles to a floppy disk image
  8. [bits 16]
  9. [org 0x7C00]
  10.  
  11. ;;;;;;;;;;;;;;;;;;;;;;;;
  12. ; BIOS Parameter Block
  13. jmp short boot_code
  14. nop
  15. db "MadOSv01"          ; OEM identifier
  16. dw 512                 ; Bytes per sector
  17. db 1                   ; sectors per cluster
  18. dw 1                   ; reserved sectors
  19. db 1                   ; number of fats
  20. dw 112                 ; directory entries
  21. dw 1280                ; logical sectors
  22. db 0xFB                ; media descriptor type
  23. dw 1                   ; sectors per fat, fat12/fat16 only
  24. dw 18                  ; sectors per track
  25. dw 2                   ; number of heads / sides on media
  26. dd 0                   ; number of hidden sectors
  27. dd 0                   ; Large amount of sector on media. This field is set if there are more than 65535 sectors in the volume.
  28.  
  29. ; Extended Boot Record
  30. db 0                   ; drive number
  31. db 0                   ; reserved / NT flags (maybe use for MadOS, More research needed)
  32. db 0x29                ; signiture, 0x28 or 0x29 for fat12 /fat16
  33. dd 0x1337              ; volume serial number
  34. db "MadOS Disk "       ; volume label
  35. db "FAT12   "          ; identifier string
  36.  
  37. ; Boot code
  38. boot_code:
  39.     xor ax, ax
  40.     mov ds, ax
  41.     mov es, ax
  42.     mov ss, ax
  43.     mov sp, boot_code_end + (1024 * 4)
  44.  
  45.     lea si, [message]
  46.     call print_string
  47.     jmp $
  48.  
  49. print_string:
  50.     lodsb
  51.     or al, al
  52.     jz done
  53.     mov ah, 0x0E
  54.     int 0x10
  55.     jmp print_string
  56. done:
  57.    ret
  58.  
  59. message:
  60.     db "MadOS disk not bootable...", 0xd, 0xa
  61.  
  62. ;dw 0xAA55 ; bootable partition signiture, uncomment to make the floppy boot
  63. boot_code_end:
  64. times 450 - (boot_code_end - boot_code) db 0
  65.  
  66. ;;;;;;;;;;;;;;;;;;;;;
  67. ; DATA AREA START
  68.  
  69. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  70. ; FAT entries
  71. ; an entry is 3 nibbles:
  72. ;   000         -> unused
  73. ;   0xFF0-0xFF6 -> reserved cluster
  74. ;   0xFF7       -> bad cluster
  75. ;   0xFF8-0xFFF -> last cluster in file
  76. ;   ***         -> next data cluster
  77. ; position:
  78. ;   If n is even, then the physical location of the entry is the low four bits in location 1+(3*n)/2
  79. ;   and the 8 bits in location (3*n)/2
  80. ;
  81. ;   If n is odd, then the physical location of the entry is the high four bits in location (3*n)/2 and
  82. ;   the 8 bits in location 1+(3*n)/2
  83. fat1:
  84.     db 0xFB, 0xFF, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xF0, 0xFF, 0x00, 0x00
  85.     ;    0     1     2     3     4     5     6     7     8     9     10    11    12    13
  86.     times 512 - ($ - fat1) db 0
  87. fat2:
  88.     times 512 - ($ - fat2) db 0
  89. ;;;;;;;;;;;;;;;;;;
  90. ; root directory
  91. root:
  92.     folder:
  93.         db "folder     "
  94.         db 0x20 | 0x10         ; attributes: a, d
  95.         dw 0                   ; reserved
  96.         dw 0xA496              ; creation time (h,m,s)
  97.         dw 0x4793              ; creation date
  98.         dw 0x4793              ; access date
  99.         dw 0                   ; high order bits of first cluster address, 0 on fat12
  100.         dw 0xA496              ; write time (h,m,s)
  101.         dw 0x4793              ; write date
  102.         dw 3                   ; low order bits of first cluster address
  103.         dd 64                  ; file size
  104.  
  105.     file:
  106.         db "file       "
  107.         db 0x20                ; attributes: a
  108.         dw 0                   ; reserved
  109.         dw 0xA496              ; creation time (h,m,s)
  110.         dw 0x4793              ; creation date
  111.         dw 0x4793              ; access date
  112.         dw 0                   ; high order bits of first cluster address, 0 on fat12
  113.         dw 0xA496              ; write time (h,m,s)
  114.         dw 0x4793              ; write date
  115.         dw 2                   ; low order bits of first cluster address
  116.         dd 40                  ; file size
  117.  
  118. ; padd out the rest of the root directory
  119. times (512 * 4) - ($ - root) db 0
  120.  
  121.  
  122. times 1024 db 0     ; first two data blocks are reserved
  123.  
  124. ; 2 file
  125. file_data:
  126.     db "This is a file in the root directory :D", 0xa
  127. ; cluster padding
  128. times 512 - ($ - file_data) db 0
  129.  
  130. ; 3 folder
  131. folder_data:
  132.     file2:
  133.         db "file2      "
  134.         db 0x20                ; attributes: a
  135.         dw 0                   ; reserved
  136.         dw 0xA496              ; creation time (h,m,s)
  137.         dw 0x4793              ; creation date
  138.         dw 0x4793              ; access date
  139.         dw 0                   ; high order bits of first cluster address, 0 on fat12
  140.         dw 0xA496              ; write time (h,m,s)
  141.         dw 0x4793              ; write date
  142.         dw 4                   ; low order bits of first cluster address
  143.         dd 34                  ; file size
  144.     folder2:
  145.         db "folder2    "
  146.         db 0x20 | 0x10         ; attributes: a, d
  147.         dw 0                   ; reserved
  148.         dw 0xA496              ; creation time (h,m,s)
  149.         dw 0x4793              ; creation date
  150.         dw 0x4793              ; access date
  151.         dw 0                   ; high order bits of first cluster address, 0 on fat12
  152.         dw 0xA496              ; write time (h,m,s)
  153.         dw 0x4793              ; write date
  154.         dw 5                   ; low order bits of first cluster address
  155.         dd 32                  ; file size
  156. ; cluster padding
  157. times 512 - ($ - file2) db 0
  158.  
  159. ; 4 file2
  160. file2_data:
  161.     db "This is a file in a sub directory", 0xa
  162. ; cluster padding
  163. times 512 - ($ - file2_data) db 0
  164.  
  165.  
  166. ; 5 folder2_data
  167. folder2_data:
  168.     file3:
  169.         db "file3      "
  170.         db 0x20                ; attributes: a
  171.         dw 0                   ; reserved
  172.         dw 0xA496              ; creation time (h,m,s)
  173.         dw 0x4793              ; creation date
  174.         dw 0x4793              ; access date
  175.         dw 0                   ; high order bits of first cluster address, 0 on fat12
  176.         dw 0xA496              ; write time (h,m,s)
  177.         dw 0x4793              ; write date
  178.         dw 6                   ; low order bits of first cluster address
  179.         dd 1024                ; file size
  180. ; cluster padding
  181. times 512 - ($ - folder2_data) db 0
  182.  
  183. ; 6 file3_data
  184. file3_data:
  185. times 512 - ($ - file3_data) db 'A'
  186.  
  187. ; 7 file3_data2
  188. file3_data2:
  189. times 512 - ($ - file3_data2) db 'B'
  190.  
  191.  
  192.  
  193.  
  194. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  195. ; padd out the rest of the floppy
  196. times ((1024 * 1024) + 461373) - ($ - $$) db 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement