Code: Select all
;****************************************************************
; _fat12_Initialize: Initialize the FAT12 device
; Parameters: DL - device number
; Returns: AX = 0 on success, 1 on failure
;****************************************************************
_fat12_Initialize:
; save all registers. Five error retries
mov di,5
; save the current disk number in _currentDisk
mov byte [_currentDisk],dl
.try_loop:
xor ax,ax ; BIOS function 0 (reset disk)
int 0x13 ; reset
; since we have invalid data in the table, we need to raw-load sector 0
mov ax,0x0
mov es,ax
mov bx,_fat12_BPB ; our buffer for the sector
mov ah,0x02 ; bios function 2
mov al,1 ; read one sector
mov cl,0x01 ; read sector 1
mov ch,0x00 ; the cylinder number is zero
mov dh,0x00 ; the head number is zero, and dl already contains the drive number
mov dl,byte [_currentDisk] ; load the disk number (just in case?)
int 0x13 ; call the interrupt
jnc .loaded ; if we were successful, finish
; setup for retry
dec di ; decrement error counter
jnz .try_loop ; if we have tries left, try again
stc ; otherwise, set carry flag and return
.loaded:
; return
ret