Advance on FCB disk i/o
This commit is contained in:
parent
e07e13fd35
commit
a65f54b121
@ -67,3 +67,17 @@ drive_read:
|
||||
jnz .try
|
||||
stc
|
||||
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
|
||||
|
@ -3,12 +3,16 @@ exec_chain:
|
||||
mov si, 0x81
|
||||
exec:
|
||||
push bx
|
||||
sub sp, fcb_size
|
||||
sub sp, 0x20
|
||||
mov bx, sp
|
||||
|
||||
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
|
||||
ret
|
||||
|
@ -1,49 +1,50 @@
|
||||
; 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_ext 9 ; 3 bytes
|
||||
|
||||
; Drive & FS data (4 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: 2^ss
|
||||
%define fcb_cs 15 ; byte cluster size: 2^(ss+cs)
|
||||
%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 (12 bytes):
|
||||
; Will be overwritten by new filename for CL=17
|
||||
%define fcb_fsize 16 ; dword file size
|
||||
%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
|
||||
; 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 (3 bytes)
|
||||
%define fcb_ds 28 ; word directory sector
|
||||
%define fcb_do 30 ; byte directory offset
|
||||
; Link to directory item (4 bytes)
|
||||
%define fcb_ds 24 ; dword offset of directory item
|
||||
|
||||
fcb_open_rootdir:
|
||||
cmp byte [bx], 0
|
||||
jne .drivedone
|
||||
mov al, default_drive
|
||||
mov [bx], al
|
||||
.drivedone:
|
||||
mov dl, [bx]
|
||||
%define fcb_end 32
|
||||
|
||||
fcb_open_blockdev:
|
||||
mov dl, 0x01
|
||||
mov [bx], dl
|
||||
dec dl
|
||||
|
||||
; Init non-user FCB data with zero
|
||||
xor ax, ax
|
||||
xor dx, dx
|
||||
; set directory sector to 0 (=rootdir)
|
||||
mov [bx+fcb_ds], ax
|
||||
lea di, [bx+fcb_spt]
|
||||
mov cx, (fcb_end - fcb_spt)
|
||||
rep stosb
|
||||
|
||||
; load first sector
|
||||
call drive_read
|
||||
|
||||
; transfer sector size
|
||||
; copy sector size
|
||||
mov ax, [diskbuf + 0x0B]
|
||||
call log2
|
||||
sub ax, 7
|
||||
mov byte [bx+fcb_ss], al
|
||||
|
||||
; transfer cluster size
|
||||
; 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
|
||||
@ -54,4 +55,32 @@ fcb_open_rootdir:
|
||||
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 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
|
||||
|
@ -3,17 +3,17 @@ cpu 8086
|
||||
; Memory layout (starting from top)
|
||||
%define self 0xF000
|
||||
|
||||
; A single sector for disk i/o
|
||||
; A single sector for deblocking
|
||||
%define diskbuf (self-0x200)
|
||||
|
||||
; DWORD partition offset for C: and D:
|
||||
%define parttab (diskbuf - (2*4))
|
||||
%define stack (diskbuf)
|
||||
|
||||
%define stack (parttab)
|
||||
; Metadata for current disk sector
|
||||
%define diskptr 0x50
|
||||
%define disknum 0x54
|
||||
%define diskflg 0x55
|
||||
|
||||
%define default_drive BYTE [0x5B]
|
||||
|
||||
%define fcb_size 31
|
||||
%define default_drive BYTE [0x4]
|
||||
|
||||
org self
|
||||
jmp init
|
||||
@ -28,11 +28,8 @@ init:
|
||||
mov dx, banner
|
||||
call print_string
|
||||
|
||||
mov dx, 0x79
|
||||
mov byte [0x79], 0x7F
|
||||
call read_buffer
|
||||
mov ax, [0x79]
|
||||
int3
|
||||
mov si, init_program
|
||||
call exec
|
||||
|
||||
cli
|
||||
.halt:
|
||||
@ -63,3 +60,4 @@ cpm_syscall:
|
||||
%include "fcbparse.asm"
|
||||
%include "drive.asm"
|
||||
%include "log2.asm"
|
||||
%include "dump.asm"
|
||||
|
Loading…
Reference in New Issue
Block a user