diff --git a/boot/fat.asm b/boot/fat.asm index 46f093d..cdbe931 100644 --- a/boot/fat.asm +++ b/boot/fat.asm @@ -55,8 +55,14 @@ readr: ; add offset to rootdir to DX:AX (FAT12/FAT16 only) push cx xor ch, ch mov cl, byte [bp+bpb_fn] -fatlp: add ax, [bp+bpb7_lsf] +fatlp: + %ifdef FAT32 + add ax, [bp+bpb7_lsf] adc dx, [bp+bpb7_lsf+2] + %else + add ax, [bp+bpb_sf] + adc dx, 0 + %endif loop fatlp pop cx readf: ; add offset to FAT table to DX:AX @@ -168,30 +174,49 @@ shftl: clc pop bx - ; get lower part of cluster number + ; get address of cluster within sector pop si + %ifdef FAT12 + push si + ; times 1.5 + mov ax, si + shr ax, 1 + add si, ax + add si, buf + lodsw + pop si + test si, 1 + jz .odd +.even: mov cl, 4 + shr ax, cl + jmp .done +.odd: and ax, 0x0FFF +.done: xor dx, dx + %endif + %ifdef FAT16 ; double sal si, 1 + ; make sure its within sector range + and si, 0x1FF + add si, buf + ; load word + lodsw + xor dx, dx %endif + %ifdef FAT32 ; multiply with 4 sal si, 1 sal si, 1 - %endif ; make sure its within sector range - and si, 0x1FF + and si, 0x1FF add si, buf - %ifdef FAT16 - ; load word from FAT - lodsw - xor dx, dx - %endif - %ifdef FAT32 - ; load dword from FAT + ; load dword lodsw mov dx, [si] %endif + ret ; reads current cluster into [dest] @@ -230,9 +255,21 @@ l02e: ret ; Load root directory -loadr: mov ax, 2 +loadr: + %ifdef FAT32 + mov ax, 2 xor dx, dx jmp load + %else + mov ax, [bp+bpb_rde] + mov cl, 4 + shr ax, cl + mov cx, ax + xor ax, ax + xor dx, dx + mov bx, 0x07C0 + jmp readr + %endif ; Load file identified by fsattr ; Directory data is expected at 0x07C00 @@ -259,8 +296,16 @@ sloop: add si, 0x20 load: mov bx, 0x07C0 lloop: call readc call next + %ifdef FAT12 + cmp word ax, 0x0FF8 + %endif + %ifdef FAT16 + cmp word ax, 0xFFF8 + %endif + %ifdef FAT32 cmp word dx, 0x0FFF - jne lloop + %endif + jc lloop ret main: ; Set up BP to point to BPB