vbr: Reorder code, improve error behavior

This commit is contained in:
Nero 2019-03-31 13:08:39 +00:00
parent 6e209d9e55
commit 208b2f95b5

View File

@ -1,4 +1,4 @@
org 0x0500
org 0x0600
fdc: ; FDC Descriptor as per ECMA-107
jmp _startup
@ -51,7 +51,7 @@ _startup:
xor sp, sp
; relocate
mov si, 0x7C00
mov di, 0x0500
mov di, 0x0600
mov cx, 0x0100
rep movsw
; adjust CS
@ -60,10 +60,35 @@ _startup:
main:
mov [fdc.drv], dl ; backup drive number
adjustchs:
call fix_chs
call find_first_sector
call error
db "END OF IMPLEMENTATION", 0
; Write AX, a string and bail out
; Return pointer is the string start
; String must be 0 suffixed
error:
call print16
pop si
mov bx, 0x0000
mov al, 0x20
.loop:
mov ah, 0x0e
int 0x10
lodsb
cmp al, 0x00
jne .loop
.hlt:
hlt
jmp .hlt
; Read CHS data from BIOS and fix fdc values
fix_chs:
mov ah, 0x08
int 0x13
jc loaddir ; skip if function does not exist
jc .end ; skip if function does not exist
inc dh
mov [fdc.nos], dh
mov ax, cx
@ -77,69 +102,54 @@ adjustchs:
mul word [fdc.nos] ; number of tracks = number of cylinders * heads
mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track
mov [fdc.ts], ax
.end:
ret
loaddir:
mov bx, [fdc.ss] ; bytes per sector
; Load the root directory [buffer]
find_first_sector:
mov bx, [fdc.ss] ; bytes per sector
mov cl, 5
shr bx, cl ; div by 2^5, 32 bytes per directory entity
mov ax, [fdc.rde] ; number of root directory entities
shr bx, cl ; div by 2^5, 32 bytes per directory entity
mov ax, [fdc.rde] ; number of root directory entities
xor dx, dx
div bx
mov cx, ax ; cx = number of rootdir sectors
mov cx, ax ; cx = number of rootdir sectors
mov ax, [fdc.sf] ; sectors per fat
mul byte [fdc.fn] ; number of fats
add ax, [fdc.rsc] ; ax = starting sector of rootdir
mov bx, buffer
.loop:
.blkloop:
call loadblk
add bx, buffer
add ax, 1
loop .loop
scandir:
loop .blkloop
mov cx, [fdc.rde]
mov bx, buffer
.loop:
.dirloop:
push cx
mov cx, 0x000B
mov si, bx
mov di, bootfilename
repe cmpsb
pop cx
jz found
jz .found
add bx, 0x0020 ; 32 bytes per directory entry
loop .loop
loop .dirloop
call error
db "NOT FOUND", 0
found:
.found:
add bx, 26
mov ax, [bx]
call print16
jmp hlt
error:
call print16
pop si
mov bx, 0x0000
mov al, 0x20
.loop:
mov ah, 0x0e
int 0x10
lodsb
cmp al, 0x00
jne .loop
; fall through into htl
hlt:
hlt
jmp hlt
ret
; Load a single FAT cluster into memory
; in ax cluster number
; bx buffer
; in ax cluster number
; bx buffer
;
loadsec:
call print16
mov ax, bx
call print16
ret
; Load a single block into memory