Guest User

Untitled

a guest
May 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. ;cx, contains loop or how many sectors to load
  2. ;bx, contains what address to load it too
  3. ;ax, contains lba
  4.  
  5. LBA dw 0x0000
  6. Sector db 0x00
  7. Track db 0x00
  8. Head db 0x00
  9.  
  10. ReadSectors:
  11.  
  12. mov [LBA], WORD ax ;;save lba, ax will be used for division and will be modified
  13. push dx ;;dx will be used in the disk loading operation, so save it, but pop it before ending.
  14. ;;we then push cx, pop dx after poping cx
  15. .ReadSectorLoop:
  16. cmp cx, 0
  17. je .ReadSectorEnd ;put here for loop purposes, cx will have been popped before getting
  18. ;here a second time first time, push wont have been done yet
  19. sub cx,1 ;;read one sector
  20. push cx ;cx will be used in disk loading operation
  21.  
  22. ;;do calculations
  23.  
  24. ;;calc for track LBA/ (bpbSectorsPerTrack X bpbHeadsPerCylinder) ;;\ Calc for track
  25. xor ax,ax
  26. xor cx,cx
  27. xor dx,dx
  28. mov cl, BYTE [bpbSectorsPerTrack]
  29. mov al, BYTE [bpbHeadsPerCylinder]
  30. mul cl ;ax contains data, perfect for our division. Problem is we are dividing our lba
  31. ;;with the data so..
  32. mov dl, al ;;we arent using this register yet, and we've pushed it anyway
  33. mov ax, WORD [LBA]
  34.  
  35.  
  36. div dl ;ax or al contains new track data.
  37.  
  38. mov [Track], BYTE al ;data in al after a 16/8 division
  39.  
  40. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Calc for head
  41. xor cx,cx
  42. xor dx,dx
  43. xor ax,ax ;al and ah contain quotient and remainder after 16/8 division
  44. mov ax, WORD [LBA] ;;get head count. (LBA / bpbSectorsPerTrack) / bpbHeadsPerCylinder. Modulus = heads
  45.  
  46. mov cl, BYTE [bpbSectorsPerTrack] ;;18 is bigger than 15 so its a 5 bit number 5<8 10010 16+2
  47. div cl
  48.  
  49. xor dx,dx ;we dont need this remainder
  50. mov ah, 0 ;we dont need remainder from last divide so ax isnt a big number remainder|quotient
  51.  
  52. mov cl, BYTE [bpbHeadsPerCylinder]
  53. div cl ;ah contains remainder we need this one tho
  54.  
  55. mov [Head], BYTE ah
  56.  
  57. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; calc for Sector
  58. xor ax,ax
  59. xor cx,cx
  60. xor dx,dx
  61.  
  62. mov ax, WORD [LBA]
  63. mov cl, BYTE [bpbSectorsPerTrack]
  64.  
  65. div cl
  66.  
  67. inc ah ;modulus + 1 16 / 8 remainder is in ah
  68. mov [Sector], BYTE ah
  69.  
  70. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; read sectors
  71. mov ah, 0x02
  72. mov al, 1
  73. mov ch, BYTE [Track]
  74. mov cl, BYTE [Sector]
  75. mov dh, BYTE [Head]
  76. mov dl, 0
  77. int 0x13
  78. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;get ready for next loop
  79. add bx, 512
  80. pop cx
  81. .ReadSectorEnd:
  82.  
  83. pop dx
  84. ret
Add Comment
Please, Sign In to add comment