@@ -122,8 +122,8 @@ reallocatedEntry:
122122;---------------------------------------------------
123123
124124allocDiskbuffer:
125- xor ax , ax
126- mov dx , ax ; Calculate the size of fat in sectors
125+ xor ah , ah
126+ xor dx , dx ; Calculate the size of fat in sectors
127127 mov al , byte [ fats ] ; Take the number of fats
128128 mul word [ fatSectors ] ; And multiply that by the number of sectors per fat
129129
@@ -166,7 +166,7 @@ loadRoot:
166166;---------------------------------------------------
167167
168168findFile:
169- mov dx , word [ rootDirEntries ] ; Search through all of the root dir entrys for the kernel
169+ mov dx , word [ rootDirEntries ] ; Search through all of the root dir entries for the kernel
170170 push di
171171
172172 .searchRoot:
@@ -251,8 +251,7 @@ readClusters:
251251 mul bx ; Multiply the cluster by the sectors per cluster
252252 add ax , word [ cs :startOfData ] ; Finally add the first data sector
253253
254- xor ch , ch
255- mov cl , byte [ sectorsPerCluster ] ; Sectors to read
254+ mov cx , bx ; Sectors to read
256255 call readSectors ; Read the sectors
257256
258257 pop ax
@@ -261,14 +260,14 @@ readClusters:
261260 push ds
262261 push si
263262
264- xor dx , dx ; Get the next cluster for FAT
265- mov bx , 3 ; We want to multiply by 1.5 so divide by 3/2
263+ xor dx , dx ; Get the next cluster for fat
264+ mov bl , 3 ; We want to multiply by 1.5 so divide by 3/2
266265 mul bx ; Multiply the cluster by the numerator
267- mov bl , 2 ; Return value in ax and remainder in dx
266+ dec bx ; Return value in ax and remainder in dx
268267 div bx ; Divide the cluster by the denominator
269268
270- add si , ax ; Point to the next cluster in the FAT entry
271- mov ax , word [ ds : si ] ; Load ax to the next cluster in FAT
269+ add si , ax ; Point to the next cluster in the fat entry
270+ mov ax , word [ ds : si ] ; Load ax to the next cluster in fat
272271
273272 pop si
274273 pop ds
@@ -301,8 +300,8 @@ readClusters:
301300 add ch , dl ; Then add the lower half to the segment
302301 mov es , cx
303302
304- clc
305- add di , bx ; Add to the pointer offset
303+ clc ; Add to the pointer offset
304+ add di , bx
306305 jnc .clusterLoop
307306
308307 .fixBuffer: ; An error will occur if the buffer in memory
@@ -342,7 +341,7 @@ readSectors:
342341 push cx
343342 push dx
344343
345- div word [ sectorsPerTrack ] ; Divide the lba (value in ax:dx) by sectorsPerTrack
344+ div word [ sectorsPerTrack ] ; Divide lba by the sectors per track
346345 mov cx , dx ; Save the absolute sector value
347346 inc cx
348347
@@ -382,7 +381,9 @@ readSectors:
382381 pop cx
383382 pop ax
384383
385- inc ax ; Increase the next sector to read
384+ clc
385+ add ax , 1 ; Add one for the the next lba value
386+ adc dx , 0 ; Make sure to adjust dx for carry
386387
387388 clc
388389 add bx , word [ bytesPerSector ] ; Add to the buffer address for the next sector
0 commit comments