X;SAVE #D9:FMSALLOC.M65AFREE SECTORAX;#X; FRESECT - FREE CURRENT SECTORX; FRESECT$'QFCBCSN9;; get lsb of sector number."5;; save for just a tick or two8)M>;; use 3 least significant bits...B?;; ...as an indexL7;; get FCBCSN,X backV,LFCBCSN9;; check out complete sec num`%F:FRRTS;; can't free sector zero!jX;t/X; okay...real sector and Y-reg has index...~#X; ...into single bit mask tableX;"QBITTBL8;; so get a single bit#5;; save mask until ready for itX;QFCBCSN9;; get lsb again#%>;; shifting right 3 times.../:FRE1VFCBCSN9;; will divide sector #...$W?;; ...by 8, making a byte index1 H:FRE1X;,.O>DVDSMP;; offset to start of vtoc bit map ?;; ...true index..."7;; (recover proper bit number)L@VTOCPTR7;; set bit..(,P@VTOCPTR7;; ...meaning sector available2X;<2X; now we must increment one of the sector cntsFX;PX; which one?ZX;d))>DVDVTOP;; past top of regular vtoc?n"%>DVDNSA;; assume regular vtocxD:FRE2;; it is regular(%>DVDAUX;; not regular...use aux cnt :FRE2-Q@VTOCPTR7;; clumsy way to bump by one...,;; but only way with 6502O>;; instruction set when$P@VTOCPTR7;; using (xxx),Y form.3Q@VTOCPTR7O>P@VTOCPTR7X; :FRRTS :X;AGET SECTORAX;"(X; GET SECTOR - GET A FREE SECTOR FOR,%X; USE BY FCB POINTED TO BY X-reg.6+X; The sector number is placed in FCBLSN@X;J)X; THE SEARCH FOR A FREE SECTOR STARTST&X; AT THE DVDSMP BYTE. SECTORS ARE^(X; NUMBERED SEQUENTIALLY FROM ZERO TOh2X; MAXVTOC*8-1, WITH THE LEFT BIT OF THE DVDSMPrX; BEING BIT #ZERO.|X; GETSECTOR+%>DVDSMP;; start one byte before mapX;:GS13;; to next byte of map&)MAXVTOC;; at end of this map yet?'EGSERR;; yes...no sectors available*Q@VTOCPTR7;; no...try this byte of map'F:GS1;; no free sector in this byteX;&X; found a byte with a free sector!X;X;.X; before proceeding, let's find bit numberX; and flip the bitX;*$>;; simply initializing the bit cntr&X;0 :GSBIT:2;; count a bitDT?;; is this it?ND:GSBIT;; noXX;bX; X has bit numberlQBITTBL9;; get the bitv N@VTOCPTR7;; flip it in vtocP@VTOCPTR7;; thusly.X;*X; VTOC bit map changed, bit # in X-regX;A;; so we save bit number!5;; on stack for a bit of timeX;)X; now generate the sector # in FCBLSNX;!$CURFCB;; work with FCB againX;C;; byte displacement to A;%S>DVDSMP;; becomes INT(sector#/8) )PFCBLSN9;; prepare to first mult by 8X; 'Q>;; 2 upper bits on=3 left shifts*X;4-X; note that after shifting A three times,>$X; we will shift out a zero bitH(X; and, if nothing gets shifted in,R)X; A will hold zero. Thus $C0 is as\%X; good as $00 for initial valuefX; of MSByte of LSNpX;zX; :GSLP1 TFCBLSN9;; shift low byte...U?;; ...into high byteE:GSLP1;; 3 times?X;&PFCBLSN9;; and set up high byte7;; recover bit number'LFCBLSN9;; becomes part of sector #PFCBLSN9;; thusX;X;2X; now we must decrement one of the sector cntsX; X; which one? X; ))>DVDVTOP;; past top of regular vtoc?$ "%>DVDNSA;; assume regular vtoc. D:GS2;; it is regular8 (%>DVDAUX;; not regular...use aux cntB +QFCBEFLAG9;; AHA! If this sector is...L &M>;; ...in extended VTOC, then...V %L>;; ...we must change its EFLAG` -PFCBEFLAG9;; to indicated 'extended file'j :GS2t #;;; the only 6502 way to do this~ Q@VTOCPTR7 S> P@VTOCPTR7 3 Q@VTOCPTR7 S> P@VTOCPTR7 X; ,X; as long as we are messing with VTOC... X; +%>DVDWRQ;; set WRITE VTOC REQUIRED flag #C;; (any non-zero value will do) P@VTOCPTR7 4QFCBLSN9;; for callers: expected of GETSECTOR :;; and that's it X; X;;;;;;;;;;;;;;;;;;;;;;;;;;;;( X;2 -GSERR@ERROR E.NSA;;NO SECTOR AVAILABLE< X;