commit 655c4ea67a7d431de2541febccfd587bad1fa8d6
parent 69f29a79e6ce34a55c1fdb3449e8b2568d6452a1
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sat, 23 Jul 2022 15:20:10 -0400
fs/fat: handle sector cross-over special case in FAT12
Diffstat:
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/fs/fs/fat.fs b/fs/fs/fat.fs
@@ -25,11 +25,13 @@ $ffff const EOC
: writecursector ( -- ) bufsec fatbuf( (drv!) ;
: FAT12! ( entry cluster -- )
- dup FAT12' dup w@ ( entry cl a n ) rot 1 and if ( entry a n )
+ dup FAT@ ( entry cl old ) over FAT12' ( entry cl old a )
+ ( entry cl a n ) swap rot 1 and if ( entry a old )
$f and rot 4 lshift or ( a n )
- else ( entry a n )
+ else ( entry a old )
$f000 and rot $fff and or then ( a n )
- swap w! ;
+ over w! ( a ) )fatbuf 1- = if \ end-of-sector cross-over!
+ bufsec 1+ (drv@) )fatbuf 1+ c@ fatbuf( c! bufsec 1+ (drv!) then ;
: FAT16! ( entry cluster -- ) FAT16' w! ;
: FAT! ( entry cluster ) FAT12? if FAT12! else FAT16! then writecursector ;
diff --git a/fs/fs/fatlo.fs b/fs/fs/fatlo.fs
@@ -42,6 +42,8 @@ create bpb 0 here (drv@) $18 allot
\ in size and knows the number of sequential sector read it has in front of it.
create fatbuf( BPB_BytsPerSec allot
here const )fatbuf
+0 c, \ extra byte for FAT12 cross-sector exception
+
0 value bufsec \ sector number of current buf
0 value bufseccnt \ number of sectors ahead for sequential read
0 value bufcluster \ cluster number of current buf
@@ -52,7 +54,10 @@ here const )fatbuf
: FAT12' ( cluster -- 'entry )
dup >> + ( cl offset ) BPB_BytsPerSec /mod ( cl secoff sec )
- BPB_RsvdSecCnt + 0 readsector ( cl secoff )
+ BPB_RsvdSecCnt +
+ over 1+ BPB_BytsPerSec = if \ end-of-sector cross-over!
+ dup 1 + fatbuf( (drv@) fatbuf( c@ )fatbuf c! then
+ 0 readsector ( cl secoff )
fatbuf( + ;
: FAT12@ ( cluster -- entry )
dup FAT12' w@ swap 1 and if 4 rshift else $fff and then ;
diff --git a/fs/xcomp/pc/mbr.fs b/fs/xcomp/pc/mbr.fs
@@ -11,6 +11,8 @@ forward8 jmp, to L1 \ bypass BPB
$23 allot L1 forward!
cli, cld, GDTADDR m) lgdt,
ax $0003 i) mov, $10 int, \ video mode 80x25
+\ read 16 sectors, starting from sector 2 from boot floppy in memory at
+\ address $8000
ax $0210 i) mov, bx $8000 i) mov, cx $0002 i) mov, dx $0000 i) mov, $13 int,
ax cr0 mov, ax 1 i) or, cr0 ax mov,
$08 0 jmpfar, here org - binstart + here 4 - w! 0 to realmode