GetClustr.asm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. .286
  2. .model small
  3. .code
  4. org 100h
  5. jumps
  6. include structs.inc
  7. COUNT = 8
  8. DRIVE = 'D'
  9. BOOT32 struc
  10. _jumps db 3 dup (?)
  11. OEM db 8 dup (?)
  12. ExtBPB A_BF_BPB <?>
  13. bDrvNo db ?
  14. bt32_res1 db ?
  15. bExtBootSig db ?
  16. wSerNo dw ?
  17. wSerNoHi dw ?
  18. abVolLabel db 11 dup (?)
  19. abFileSysCode db 8 dup (?)
  20. abBootCode db 200h-38-SIZE A_BF_BPB dup (?)
  21. BOOT32 ends
  22. start:
  23. ;{
  24. push cs ;
  25. push offset _Boot ; Rec_Buf
  26. push 1 ; Count
  27. push 0 ; Sector
  28. push 0 ; Cyl
  29. push 0 ; Head
  30. push DRIVE-'@' ; Drive
  31. call ReadCyl
  32. jc error
  33. xor ax, ax
  34. mov al, _boot.ExtBPB.A_BF_BPB_SectorsPerCluster
  35. mov _ClustSize, ax
  36. mov ax, _boot.ExtBPB.A_BF_BPB_ReservedSectors
  37. mov bp, ax
  38. mov _FAT32Beg, ax
  39. mov ax, _boot.ExtBPB.A_BF_BPB_BigSectorsPerFat
  40. xor bx, bx
  41. mov bl, _boot.ExtBPB.A_BF_BPB_NumberOfFATs
  42. mul bx
  43. add bp, ax
  44. adc dx, 0
  45. mov _DataBeg, bp
  46. mov _DataBegHi, dx
  47. ;} Read Extended Boot Sector
  48. mov ax, 0
  49. mov dx, 0
  50. call GetFat32
  51. jc error
  52. mov dx, 0
  53. mov ax, 0ah
  54. call GetValFromFAT
  55. push cs
  56. push offset _buf
  57. ; push _boot.ExtBPB.A_BF_BPB_RootDirStrtClusHi
  58. ; push _boot.ExtBPB.A_BF_BPB_RootDirStrtClus
  59. push 0
  60. push 0Ah
  61. push Drive-'@'
  62. call ReadClust
  63. mov ah, 3ch
  64. lea dx, _fname
  65. mov cx, 0
  66. int 21h
  67. mov bx, ax
  68. mov ah, 40h
  69. mov cx, 200h*COUNT
  70. lea dx, _buf
  71. int 21h
  72. mov ah, 3eh
  73. int 21h
  74. jmp exit
  75. error:
  76. mov dl, ah
  77. mov cl, al
  78. mov ah, 2
  79. int 21h
  80. mov dl, cl
  81. int 21h
  82. mov ah, 9
  83. lea dx, _err
  84. int 21h
  85. exit:
  86. mov ah, 4ch
  87. int 21h
  88. ;===================================================================
  89. ;===================================================================
  90. ;===================================================================
  91. ;===================================================================
  92. ;===================================================================
  93. ;===================================================================
  94. GetValFromFat proc near ; AX=Clstr, DX=ClstrHi
  95. push si
  96. push di
  97. mov vl_cls, ax
  98. mov vl_clshi, dx
  99. cmp dx, FtBegHi
  100. jb @NeedRd
  101. ja @Big
  102. cmp ax, FtBeg
  103. jb @NeedRd
  104. @BIG:
  105. cmp dx, FtEndHi
  106. ja @NeedRD
  107. jb @TblOK
  108. cmp ax, FtEnd
  109. jbe @TblOK
  110. @NeedRd:
  111. mov ax, vl_cls
  112. mov dx, vl_clshi
  113. call GetFAT32
  114. @TblOK:
  115. mov ax, vl_cls
  116. sub ax, ftBeg
  117. shl ax, 2
  118. mov bx, ax
  119. add bx, offset FAT32
  120. mov ax, [bx]
  121. mov dx, [bx+2]
  122. pop di
  123. pop si
  124. ret
  125. vl_cls dw 0
  126. vl_clshi dw 0
  127. endp
  128. ;-----------------------------------------------------
  129. GetFAT32 proc Near ; AX=Clstr, DX = ClstrHi (Guarantied present)
  130. push di
  131. push si
  132. mov FtBeg, ax
  133. mov FtBegHi, dx
  134. mov FtEndHi, dx
  135. and FtBeg, 1111111110000000b
  136. xor cx, cx ;
  137. shr ax, 7 ; Div
  138. mov cl, dl ; Cluster Num by 128
  139. shl cl, 1 ; to get sectorNum
  140. shr dx, 7 ; from begining of FAT32
  141. or ah, cl ;
  142. add ax, _FAT32Beg
  143. adc dx, 0
  144. push cs
  145. push offset FAT32
  146. push 1
  147. push dx
  148. push ax
  149. push Drive-'@'
  150. call ReadAbsCyl
  151. mov ax, FtBeg
  152. mov FtEnd, ax
  153. add FtEnd, 128
  154. adc FtEndHi, 0
  155. pop si
  156. pop di
  157. ret
  158. endp
  159. ;-------------------------------------------------------------------
  160. ReadClust proc Near
  161. push bp
  162. mov bp, sp
  163. push si
  164. push di
  165. cls_drv equ word ptr [bp+4]
  166. cls_clstr equ word ptr [bp+6]
  167. cls_clstrHi equ word ptr [bp+8]
  168. cls_bufOf equ word ptr [bp+10]
  169. cls_bufSeg equ word ptr [bp+12]
  170. mov si, cls_clstrHi
  171. mov ax, cls_clstr
  172. sub ax, 2
  173. sbb si, 0
  174. mov bx, _ClustSize
  175. mul bx
  176. push ax
  177. mov di, dx
  178. mov ax, si
  179. mul bx
  180. add ax, di
  181. mov dx, ax
  182. pop ax
  183. add ax, _DataBeg
  184. adc dx, _DataBegHi
  185. push cls_bufSeg
  186. push cls_bufof
  187. push bx
  188. push dx
  189. push ax
  190. push cls_drv
  191. call ReadAbsCyl
  192. pop di
  193. pop si
  194. pop bp
  195. ret 10
  196. endp
  197. ;-------------------
  198. ReadAbsCyl proc Near
  199. push bp
  200. mov bp, sp
  201. abs_drv equ word ptr [bp+4]
  202. abs_cyl equ word ptr [bp+6]
  203. abs_cylHi equ word ptr [bp+8]
  204. abs_count equ word ptr [bp+10]
  205. abs_BufOf equ word ptr [bp+12]
  206. abs_BufSeg equ word ptr [bp+14]
  207. push si
  208. push di
  209. mov ax, abs_cyl
  210. mov _NeedRead, ax
  211. mov ax, abs_cylHi
  212. mov _NeedReadHi, ax
  213. mov bx, _Boot.ExtBPB.A_BF_BPB_SectorsPerTrack ;
  214. mov ax, _Boot.ExtBPB.A_BF_BPB_Heads ; Calc
  215. mul bx ; Sect per
  216. mov bx, ax ; Cyl
  217. mov dx, _NeedReadHi ; Calc
  218. mov ax, _NeedRead ; Cyl
  219. div bx ; Number
  220. mov si, ax ; SI = Cyl Number
  221. mov ax, dx ; Ostatok
  222. mov bx, _Boot.ExtBPB.A_BF_BPB_SectorsPerTrack ; Calc
  223. xor dx, dx ; Head
  224. div bx ; Number
  225. mov di, ax ; Head
  226. push abs_bufSeg
  227. push abs_bufOf
  228. push abs_count
  229. push dx
  230. push si
  231. push di
  232. push abs_drv
  233. call ReadCyl
  234. pop di
  235. pop si
  236. pop bp
  237. ret 12
  238. _NeedRead dw 0
  239. _NeedReadHi dw 0
  240. endp
  241. ;=======================
  242. ReadCyl PROC near
  243. push bp
  244. mov bp,sp
  245. par_Drive equ word ptr [bp+4]
  246. push cs
  247. pop es
  248. mov ax, ss
  249. mov ds, ax
  250. mov di, offset _rb+1
  251. lea si, [bp+6]
  252. mov cx, 6
  253. repe movsw
  254. mov bx, par_Drive ;See below
  255. mov ch, 48h ;See below
  256. mov cl, 61h ;Read track on logical drive
  257. mov dx, offset _RB ;ds:dx points to RWBLOCK structure
  258. mov ax, 440Dh ;IOCTL for block device
  259. int 21h
  260. pop bp
  261. ret 14
  262. _RB RWBLOCK <?>
  263. endp
  264. ;
  265. ;-------------------------------------
  266. ; Global Varicables
  267. ;-------------------------------------
  268. ;
  269. FtBeg dw ?
  270. FtBegHi dw ?
  271. FtEnd dw ?
  272. FtEndHi dw ?
  273. _FAT32Beg dw ?
  274. _DataBeg dw ?
  275. _DataBegHi dw ?
  276. _ClustSize dw ?
  277. _err db 'Error',10,13,'$'
  278. _fname db 'RF2.dat',0
  279. FAT32 dd 128 dup (?)
  280. _Boot BOOT32 <?>
  281. _buf db 200h*COUNT dup (?)
  282. end start