diff --git a/com/@rdos.asm b/com/@rdos.asm index fe8fa6f..f3fb108 100644 --- a/com/@rdos.asm +++ b/com/@rdos.asm @@ -10,6 +10,8 @@ banner: db "RDOS KERNEL ", V, 0x0A, 0x0D, '$', 0x1A %include "inc/bpb.asm" %include "kernel/drive.asm" %include "kernel/fcb.asm" +%include "kernel/rootdir.asm" +%include "kernel/cluster.asm" section .text @@ -23,7 +25,12 @@ init: call rstseg mov dx, testdta call setdta mov dx, testfcb - call fndfst + + call open + + int 3 + + call read int 3 diff --git a/kernel/cluster.asm b/kernel/cluster.asm new file mode 100644 index 0000000..2dd33b2 --- /dev/null +++ b/kernel/cluster.asm @@ -0,0 +1,7 @@ +; read/write data from FAT clusters +; requires defines from fcb.asm + +read mov bp, sp + call fcbdrv + + ret diff --git a/kernel/drive.asm b/kernel/drive.asm index 8037ff5..248dfc5 100644 --- a/kernel/drive.asm +++ b/kernel/drive.asm @@ -199,12 +199,12 @@ maprel add ax, [bpb+BPBHS] ; skip doing a read if sector number matches ; IN dx:ax sector number mapabs cmp ax, [dskseek] - jne read + jne dskread cmp dx, [dskseek+2] - jne read + jne dskread ret -read push ax +dskread push ax push dx call flush pop dx diff --git a/kernel/fcb.asm b/kernel/fcb.asm index 61bc2f5..a2625a9 100644 --- a/kernel/fcb.asm +++ b/kernel/fcb.asm @@ -55,114 +55,3 @@ setdta mov [cs:dta], dx ; OUT ES:BX dta ptr getdta les bx, [cs:dta] ret - - ; Load root directory entry - ; IN ax number of directory entry - ; OUT cs:di ptr to directory entry -lddir push ax - push ax - call rstseg - pop ax - mov cl, 4 - shr ax, cl - xor dx, dx - ; dx:ax = sector number in rootdir - ; add sizes of FAT tables - xor ch, ch - mov cl, byte [bpb+BPBFN] -.loop: add ax, [bpb+BPBFS] - adc dx, 0 - loop .loop - ; add reserved sector count - add ax, [bpb+BPBRSC] - adc dx, 0 - ; fetch sector (relative to partition) - call maprel - ; get di to point to entry - pop di - mov cl, 5 - shl di, cl - and di, 0x1FF - add di, dskbuf - ret - - ; find first matching file - ; IN DS:DX input fcb -fndfst mov bp, sp - call fcbdrv - ; set search state to zero - les di, [cs:dta] - xor ax, ax - mov [es:di+FCBSIZ], ax - ; find next matching file - ; state is kept in DTA -fndnxt mov bp, sp - call fcbdrv - ; get next direntry to fetch - ; get number of current entry from DTA -.loop les di, [cs:dta] - mov ax, [es:di+FCBSIZ] - inc word [es:di+FCBSIZ] - ; bail out if we are at end of dir - cmp ax, [bpb+BPBRDE] - jnc .err - ; load entry and first byte - push ds - push dx - call lddir - pop dx - pop ds - ; next if hidden, dir or vol label - test byte [cs:di+0x0B], 0xDA - jnz .loop - ; bail out if end of dir - mov al, [di] - cmp al, 0 - je .err - ; next if deleted entry - cmp al, 0xE5 - je .loop - ; DS:SI := FCB+1 - ; ES:DI := CS:dirent - mov si, dx - push si - inc si - mov ax, cs - mov es, ax - ; compare and ; try next if mismatch - mov cx, 11 - push di - rep cmpsb - pop di - pop si - jne .loop - ; create FCB in DTA - call getdta - xchg bx, di - ; copy over drive byte - movsb - ; copy filename - push ds - mov ax, cs - mov ds, ax - mov si, bx - mov cx, 11 - rep movsb - pop ds - ; done! - xor ax, ax - ret - -.err: stc -.ret: sbb al, al - ret - -open call fndfst - test al, al - jnz .ret - ; read start cluster - mov ax, [cs:bx+26] - mov [ds:bx+FCBCLUS], ax - ; reset record number - mov byte [ds:bx+FCBRN], 0 -.ret ret diff --git a/kernel/rootdir.asm b/kernel/rootdir.asm new file mode 100644 index 0000000..21876a9 --- /dev/null +++ b/kernel/rootdir.asm @@ -0,0 +1,110 @@ + ; Load root directory entry into buffer + ; IN ax number of directory entry + ; OUT cs:di ptr to directory entry +lddir push ax + push ax + call rstseg + pop ax + mov cl, 4 + shr ax, cl + xor dx, dx + ; dx:ax = sector number in rootdir + ; add sizes of FAT tables + xor ch, ch + mov cl, byte [bpb+BPBFN] +.loop: add ax, [bpb+BPBFS] + adc dx, 0 + loop .loop + ; add reserved sector count + add ax, [bpb+BPBRSC] + adc dx, 0 + ; fetch sector (relative to partition) + call maprel + ; get di to point to entry + pop di + mov cl, 5 + shl di, cl + and di, 0x1FF + add di, dskbuf + ret + + ; find first matching file + ; IN DS:DX input fcb +fndfst mov bp, sp + call fcbdrv + ; set search state to zero + les di, [cs:dta] + xor ax, ax + mov [es:di+FCBSIZ], ax + ; find next matching file + ; state is kept in DTA +fndnxt mov bp, sp + call fcbdrv + ; get next direntry to fetch + ; get number of current entry from DTA +.loop les di, [cs:dta] + mov ax, [es:di+FCBSIZ] + inc word [es:di+FCBSIZ] + ; bail out if we are at end of dir + cmp ax, [bpb+BPBRDE] + jnc .err + ; load entry and first byte + push ds + push dx + call lddir + pop dx + pop ds + ; next if hidden, dir or vol label + test byte [cs:di+0x0B], 0xDA + jnz .loop + ; bail out if end of dir + mov al, [di] + cmp al, 0 + je .err + ; next if deleted entry + cmp al, 0xE5 + je .loop + ; DS:SI := FCB+1 + ; ES:DI := CS:dirent + mov si, dx + push si + inc si + mov ax, cs + mov es, ax + ; compare and ; try next if mismatch + mov cx, 11 + push di + rep cmpsb + pop di + pop si + jne .loop + ; create FCB in DTA + call getdta + xchg bx, di + ; copy over drive byte + movsb + ; copy filename + push ds + mov ax, cs + mov ds, ax + mov si, bx + mov cx, 11 + rep movsb + pop ds + ; done! + xor ax, ax + ret + +.err: stc +.ret: sbb al, al + ret + +open call fndfst + test al, al + jnz .ret + ; read start cluster + mov ax, [cs:bx+26] + mov [ds:bx+FCBCLUS], ax + ; reset record number + mov byte [ds:bx+FCBRN], 0 +.ret ret