rdos/kernel/fcb.asm
2019-10-14 17:59:48 +00:00

90 lines
1.9 KiB
NASM

; diskbuf needs to be defined
; User-accessible part of FCB (12 bytes)
%define fcb_drv 0 ; 1 byte, 1=A: 2=B: 3=C:
%define fcb_fn 1 ; 8 bytes
%define fcb_ext 9 ; 3 bytes
; Drive & FS data (6 bytes)
%define fcb_spt 12 ; byte sectors per track
%define fcb_nos 13 ; byte number of sides/heads
%define fcb_ss 14 ; byte sector size: 0=128, 1=256, 2=512, ...
%define fcb_cs 15 ; byte cluster size: 0=128, 1=256, 2=512, ...
%define fcb_co 16 ; word start sector for theoretical cluster 0
; Read/Write pointer (6 bytes)
%define fcb_left 18 ; word number of bytes left to read from diskbuf
%define fcb_off 20 ; dword offset in disk (not in file)
; Link to directory item (4 bytes)
%define fcb_ds 24 ; dword offset of directory item
%define fcb_end 32
fcb_open_rootdir:
mov dl, 0x01
mov [bx], dl
dec dl
; Setup default data
; Default 2 heads, 9 sectors
mov word [bx+fcb_spt], 0x0209
xor ax, ax
lea di, [bx+fcb_ss]
; Sector & Cluster size 128 bytes
mov cx, (fcb_end - fcb_ss)
rep stosb
; load first sector
call drive_read
; copy sector size
mov ax, [diskbuf + 0x0B]
call log2
sub ax, 7
mov byte [bx+fcb_ss], al
; copy cluster size
xor ah, ah
mov al, [diskbuf + 0x0D]
call log2
add al, [bx+fcb_ss]
mov byte [bx+fcb_cs], al
; transfer sectors per track
mov al, [diskbuf + 0x18]
mov byte [bx+fcb_spt], al
; transfer number of heads/sides
mov al, [diskbuf + 0x1A]
mov byte [bx+fcb_nos], al
; first 128 bytes are always valid
mov WORD [bx+fcb_left], 0x80
ret
fcb_get_sector_mask:
push cx
xor ax, ax
not ax
mov cl, [bx+fcb_ss]
add cl, 7
shl ax, cl
pop cx
ret
fcb_getc:
push bx
call fcb_get_sector_mask
not ax
and ax, [bx+fcb_off]
xchg ax, bx
add bx, diskbuf
mov al, [bx]
pop bx
add word [bx+fcb_off], 1
adc word [bx+fcb_off+2], 0
dec word [bx+fcb_left]
ret