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 fdc: ; FDC Descriptor as per ECMA-107
jmp _startup jmp _startup
@ -51,7 +51,7 @@ _startup:
xor sp, sp xor sp, sp
; relocate ; relocate
mov si, 0x7C00 mov si, 0x7C00
mov di, 0x0500 mov di, 0x0600
mov cx, 0x0100 mov cx, 0x0100
rep movsw rep movsw
; adjust CS ; adjust CS
@ -60,10 +60,35 @@ _startup:
main: main:
mov [fdc.drv], dl ; backup drive number 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 mov ah, 0x08
int 0x13 int 0x13
jc loaddir ; skip if function does not exist jc .end ; skip if function does not exist
inc dh inc dh
mov [fdc.nos], dh mov [fdc.nos], dh
mov ax, cx mov ax, cx
@ -77,69 +102,54 @@ adjustchs:
mul word [fdc.nos] ; number of tracks = number of cylinders * heads mul word [fdc.nos] ; number of tracks = number of cylinders * heads
mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track
mov [fdc.ts], ax mov [fdc.ts], ax
.end:
ret
loaddir: ; Load the root directory [buffer]
mov bx, [fdc.ss] ; bytes per sector find_first_sector:
mov bx, [fdc.ss] ; bytes per sector
mov cl, 5 mov cl, 5
shr bx, cl ; div by 2^5, 32 bytes per directory entity shr bx, cl ; div by 2^5, 32 bytes per directory entity
mov ax, [fdc.rde] ; number of root directory entities mov ax, [fdc.rde] ; number of root directory entities
xor dx, dx xor dx, dx
div bx 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 mov ax, [fdc.sf] ; sectors per fat
mul byte [fdc.fn] ; number of fats mul byte [fdc.fn] ; number of fats
add ax, [fdc.rsc] ; ax = starting sector of rootdir add ax, [fdc.rsc] ; ax = starting sector of rootdir
mov bx, buffer mov bx, buffer
.loop: .blkloop:
call loadblk call loadblk
add bx, buffer add bx, buffer
add ax, 1 add ax, 1
loop .loop loop .blkloop
scandir:
mov cx, [fdc.rde] mov cx, [fdc.rde]
mov bx, buffer mov bx, buffer
.loop: .dirloop:
push cx push cx
mov cx, 0x000B mov cx, 0x000B
mov si, bx mov si, bx
mov di, bootfilename mov di, bootfilename
repe cmpsb repe cmpsb
pop cx pop cx
jz found jz .found
add bx, 0x0020 ; 32 bytes per directory entry add bx, 0x0020 ; 32 bytes per directory entry
loop .loop loop .dirloop
call error call error
db "NOT FOUND", 0 db "NOT FOUND", 0
found: .found:
add bx, 26 add bx, 26
mov ax, [bx] mov ax, [bx]
call print16 ret
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
; Load a single FAT cluster into memory ; Load a single FAT cluster into memory
; in ax cluster number ; in ax cluster number
; bx buffer ; bx buffer
; ;
loadsec: loadsec:
call print16
mov ax, bx
call print16
ret ret
; Load a single block into memory ; Load a single block into memory