Advance on FCB disk i/o

This commit is contained in:
Nero 2019-10-12 18:33:26 +00:00
parent e07e13fd35
commit a65f54b121
4 changed files with 84 additions and 39 deletions

View File

@ -67,3 +67,17 @@ drive_read:
jnz .try jnz .try
stc stc
jmp .giveup jmp .giveup
; Seek to fcb_off given in a ptr
; IN BX ptr to FCB
drive_seek:
push ax
push cx
mov cl, [bx+fcb_ss]
add cl, 7
mov ax, 1
sal ax, cl
int3
pop cx
pop ax
ret

View File

@ -3,12 +3,16 @@ exec_chain:
mov si, 0x81 mov si, 0x81
exec: exec:
push bx push bx
sub sp, fcb_size sub sp, 0x20
mov bx, sp mov bx, sp
call fcb_parse call fcb_parse
call fcb_open_rootdir call fcb_open_blockdev
mov cx, 5
.loop:
call fcb_getc
loop .loop
add sp, fcb_size add sp, 0x20
pop bx pop bx
ret ret

View File

@ -1,49 +1,50 @@
; User-accessible part of FCB (12 bytes) ; User-accessible part of FCB (12 bytes)
%define fcb_drv 0 ; 1 byte %define fcb_drv 0 ; 1 byte, 1=A: 2=B: 3=C:
%define fcb_fn 1 ; 8 bytes %define fcb_fn 1 ; 8 bytes
%define fcb_ext 9 ; 3 bytes %define fcb_ext 9 ; 3 bytes
; Drive & FS data (4 bytes) ; Drive & FS data (6 bytes)
%define fcb_spt 12 ; byte sectors per track %define fcb_spt 12 ; byte sectors per track
%define fcb_nos 13 ; byte number of sides/heads %define fcb_nos 13 ; byte number of sides/heads
%define fcb_ss 14 ; byte sector size: 2^ss %define fcb_ss 14 ; byte sector size: 0=128, 1=256, 2=512, ...
%define fcb_cs 15 ; byte cluster size: 2^(ss+cs) %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 (12 bytes): ; Read/Write pointer (6 bytes)
; Will be overwritten by new filename for CL=17 %define fcb_left 18 ; word number of bytes left to read from diskbuf
%define fcb_fsize 16 ; dword file size %define fcb_off 20 ; dword offset in disk (not in file)
%define fcb_fptr 20 ; dword handle position
%define fcb_clus 24 ; word current cluster fptr points in
%define fcb_co 26 ; word start sector for theoretical cluster 0
; Link to directory item (3 bytes) ; Link to directory item (4 bytes)
%define fcb_ds 28 ; word directory sector %define fcb_ds 24 ; dword offset of directory item
%define fcb_do 30 ; byte directory offset
fcb_open_rootdir: %define fcb_end 32
cmp byte [bx], 0
jne .drivedone fcb_open_blockdev:
mov al, default_drive mov dl, 0x01
mov [bx], al mov [bx], dl
.drivedone:
mov dl, [bx]
dec dl dec dl
; Init non-user FCB data with zero
xor ax, ax xor ax, ax
xor dx, dx xor dx, dx
; set directory sector to 0 (=rootdir) lea di, [bx+fcb_spt]
mov [bx+fcb_ds], ax mov cx, (fcb_end - fcb_spt)
rep stosb
; load first sector ; load first sector
call drive_read call drive_read
; transfer sector size ; copy sector size
mov ax, [diskbuf + 0x0B] mov ax, [diskbuf + 0x0B]
call log2 call log2
sub ax, 7
mov byte [bx+fcb_ss], al mov byte [bx+fcb_ss], al
; transfer cluster size ; copy cluster size
xor ah, ah
mov al, [diskbuf + 0x0D] mov al, [diskbuf + 0x0D]
call log2 call log2
add al, [bx+fcb_ss]
mov byte [bx+fcb_cs], al mov byte [bx+fcb_cs], al
; transfer sectors per track ; transfer sectors per track
@ -54,4 +55,32 @@ fcb_open_rootdir:
mov al, [diskbuf + 0x1A] mov al, [diskbuf + 0x1A]
mov byte [bx+fcb_nos], al 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 drive_seek
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 ret

View File

@ -3,17 +3,17 @@ cpu 8086
; Memory layout (starting from top) ; Memory layout (starting from top)
%define self 0xF000 %define self 0xF000
; A single sector for disk i/o ; A single sector for deblocking
%define diskbuf (self-0x200) %define diskbuf (self-0x200)
; DWORD partition offset for C: and D: %define stack (diskbuf)
%define parttab (diskbuf - (2*4))
%define stack (parttab) ; Metadata for current disk sector
%define diskptr 0x50
%define disknum 0x54
%define diskflg 0x55
%define default_drive BYTE [0x5B] %define default_drive BYTE [0x4]
%define fcb_size 31
org self org self
jmp init jmp init
@ -28,11 +28,8 @@ init:
mov dx, banner mov dx, banner
call print_string call print_string
mov dx, 0x79 mov si, init_program
mov byte [0x79], 0x7F call exec
call read_buffer
mov ax, [0x79]
int3
cli cli
.halt: .halt:
@ -63,3 +60,4 @@ cpm_syscall:
%include "fcbparse.asm" %include "fcbparse.asm"
%include "drive.asm" %include "drive.asm"
%include "log2.asm" %include "log2.asm"
%include "dump.asm"