8-Bit Software Online Conversion
MkMap ADFS Rescue ADFS ONLY - Listing
10REM > MkMap 1.01 - 06-Apr-2013 J.G.
Harston
20REM Create a free space map from ex
amining directory structure
30:
40MODE7:PRINT"Build a free space map
from directory"'"structure"
50DIM ctrl% 31,name% 31,map% 511,fsm%
511:X%=ctrl%:Y%=X%DIV256:fs%=FNfs
60IFfs%=8:aD%=&7C0B:aL%=&7C28:aS%=&7C
32:IFHIMEM<>&7C00:PRINT"Needs to run in
I/O memory":END
70OSCLI"DIR $":*INFO $
80IFfs%=8 :drive%=VALFNgbpb(6):name%?
(1+?name%)=13:drive%=VAL$(name%+1)
90IFfs%=16:drive%=FNargs(&FE,0,0)
100IFfs%=8 :PROCerr(FNscsi(fsm%,8,driv
e%,0,2)):secmax%=fsm%!&FC
110IFfs%=16:PROCerr(FNhadfs(fsm%,&80,d
rive%,&46,1)):secmax%=fsm%!28:IFfsm%?31<
128:secmax%=secmax%AND&FFFF
120secmax%=(secmax%AND&FFFFFF)-1
130PRINT"Total disk sectors (&";÷secma
x%+1;"): &";:INPUT""A$:IFA$<>"":secmax%=
EVAL("&"+A$)-1
140FOR A%=0 TO 255 STEP4:map%!A%=0:NEX
T
150sec%=2:num%=secmax%-num%-1:PROCmapa
dd:REM Add whole disk to FSM
160IFfs%=8 :sec%=2 :num%=5:PROCmaprem
:REM Remove root directory
170IFfs%=16:sec%=70:num%=4:PROCmaprem
:REM Remove FSM and root directory
180CLS:PROCscan:IFPOS:PRINT
190PRINT"(W)rite new free space map to
disk"'"(S)ave free space map as a file"
'"(Q)uit"
200PRINT":";:REPEATA$=CHR$(GETAND&DF):
UNTILINSTR("WSQ",A$):VDU127
210IFA$="W":IFfs%=8 :PROCmapwriteA
220IFA$="W":IFfs%=16:PROCmapwriteH
230IFA$="S":PROCmapsave
240END
250:
260DEFPROCscan
270LOCAL idx%,ret%:REPEATf$=FNgbpb8(id
x%):idx%=X%!9:ret%=LENf$:IFret%:PROCfile
280UNTILret%=0:ENDPROC
290:
300DEFPROCfile
310VDU30:OSCLI"INFO "+f$:IFVPOS<2:PRIN
TSPC39
320REM HADFS has 'read sector start' c
ommand:
330IFfs%=16:dir%=FNfile(f$,&FD)=2:sec%
=X%!14 AND &FFFFFF:num%=X%!11 AND &7FFFF
F
340REM ADFS, need to peek output of *I
NFO command:
350IFfs%=8 :dir%=(aD%?0=ASC"D" OR aD%?
1=ASC"D")
360IFfs%=8 :aL%?8=13:A$=$aL%:aL%?8=32:
num%=-1:IF?aL%<>32:num%=EVAL("&"+A$):num
%=(num%+255)DIV256
370IFfs%=8 :aS%?6=13:A$=$aS%:aS%?6=32:
sec%=-1:IF?aS%<>32:sec%=EVAL("&"+A$)
380IFfs%=8 :IFsec%=-1:aD%?15=13:A$=$(a
D%+9):aD%?15=32:sec%=EVAL("&"+A$):num%=5
390PRINT:PROCmaprem:PROCmaplist
400IFdir%:IFfs%=16:PROClinks
410IFdir%:OSCLI"Dir "+f$:PROCscan:OSCL
I"Dir ^"
420ENDPROC
430:
440DEFPROClinks
450link%=sec%:REPEAT
460PROCerr(FNhadfs(fsm%,&80,drive%,lin
k%,1))
470link%=fsm%!14 AND &FFFF:IFfsm%?12>1
27:link%=fsm%!24 AND &FFFFFF
480IFlink%:sec%=link%:num%=3:PROCmapre
m
490UNTILlink%=0
500ENDPROC
510:
520DEFPROCmaprem:IFnum%=0:ENDPROC
530ptr%=-8:REPEATptr%=ptr%+8
540UNTILmap%!ptr%=0 OR map%!ptr%>=sec%
550IFptr%>512-9:PRINT"FSM too full":EN
D
560IFmap%!ptr%=sec%:map%!ptr%=map%!ptr
%+num%:map%!(ptr%+4)=map%!(ptr%+4)-num%:
PROCmaprem2:ENDPROC
570IFmap%!ptr%+map%!(ptr%+4)=sec%+num%
:map%!(ptr%+4)=map%!(ptr%+4)-num%:PROCma
prem2:ENDPROC
580FOR A%=512-4 TO ptr% STEP -4:map%!A
%=map%!(A%-8):NEXT
590map%!(ptr%-4)=sec%-map%!(ptr%-8)
600map%!(ptr%+4)=map%!ptr%+map%!(ptr%+
4)-(sec%+num%)
610map%!(ptr%+0)=sec%+num%
620PROCmaprem2
630ENDPROC
640:
650DEFPROCmaprem2
660IFmap%!(ptr%+4)=0:FOR A%=ptr% TO 51
1 STEP 4:map%!A%=map%!(A%+8):NEXT
670ENDPROC
680:
690DEFPROCmapadd:IFnum%=0:ENDPROC
700ptr%=-8:REPEATptr%=ptr%+8
710UNTILmap%!ptr%=0 OR map%!ptr%>=sec%
OR map%!ptr%+map%!(ptr%+4)=sec%
720IFptr%>512-9:PRINT"FSM too full":EN
D
730IFmap%!ptr%=0:map%!ptr%=sec%:map%!(
ptr%+4)=num%:PROCmapadd2:ENDPROC
740IFsec%+num%=map%!ptr%:map%!ptr%=map
%!ptr%-num%:PROCmapadd2:ENDPROC
750IFmap%!ptr%+map%!(ptr%+4)=sec%:map%
!(ptr%+4)=map%!(ptr%+4)+num%:PROCmapadd2
:ENDPROC
760FOR A%=512-4 TO ptr% STEP -4:map%!A
%=map%!(A%-8):NEXT
770map%!ptr%=sec%:map%!(ptr%+4)=num%
780ENDPROC
790:
800DEFPROCmapadd2
810IFmap%!ptr%+map%!(ptr%+4)=map%!(ptr
%+8):ptr%=ptr%+8
820IFptr%<>0:IFmap%!(ptr%-8)+map%!(ptr
%-4)=map%!ptr%:map%!(ptr%-4)=map%!(ptr%-
4)+map%!(ptr%+4):FOR A%=ptr% TO 511 STEP
4:map%!A%=map%!(A%+8):NEXT:ENDPROC
830ENDPROC
840:
850DEFPROCmaplist
860LOCAL ptr%
870ptr%=-8:REPEATptr%=ptr%+8
880PRINTFNh0(map%!ptr%,5);"+";FNh0(map
%!(ptr%+4),5);SPC(2-(POS>35));
890IFmap%!ptr%>secmax%:PRINT"Sector to
o big":END
900UNTILmap%!ptr%=0 OR VPOS=24:PRINTSP
C11;
910ENDPROC
920:
930DEFPROCmapsave
940INPUTLINE"File to save: "A$:OSCLI"S
AVE "+A$+" "+STR$÷map%+"+200 0 FFFFFD0"
950A$="":ENDPROC
960:
970DEFFNadfs`sum(mem%):LOCAL sum%:sum%
=255
980FOR A%=254 TO 0 STEP -1
990IF sum%>255:sum%=(sum%+1)AND255
1000sum%=sum%+mem%?A%:NEXT:=sum%AND255
1010:
1020DEFPROCmapwriteA
1030IFptr%DIV8>82:PRINT"FSM too big":EN
DPROC
1040PROCerr(FNscsi(fsm%,8,drive%,0,2))
1050src%=0:dst%=0:REPEAT
1060fsm%!dst%=map%!src%
1070fsm%!(dst%+256)=map%!(src%+4)
1080src%=src%+8:dst%=dst%+3
1090UNTILmap%!(src%-8)=0
1100fsm%?&1FE=dst%-3
1110REPEATfsm%!dst%=0:fsm%!(dst%+256)=0
:dst%=dst%+3:UNTILdst%>&FB
1120fsm%!&0FC=secmax%+1
1130fsm%?&0FF=FNadfs`sum(fsm%)
1140fsm%?&1FF=FNadfs`sum(fsm%+&100)
1150PROCerr(FNscsi(fsm%,10,drive%,0,2))
1160OSCLI"MOUNT "+STR$drive%
1170ENDPROC
1180:
1190DEFPROCmapwriteH
1200IFptr%DIV8>35:PRINT"FSM too big":EN
DPROC
1210PROCerr(FNhadfs(fsm%,&80,drive%,&47
,1))
1220dskid%=fsm%!16 AND &FFFF
1230PROCerr(FNhadfs(fsm%,&80,drive%,&46
,1))
1240fsm%?24=dskid%:fsm%?25=dskid%DIV256
1250fsm%!28=secmax%+1:size%=2:IFfsm%?30
:fsm%?31=&80:size%=3
1260src%=0:dst%=&20:REPEAT
1270fsm%!dst%=map%!src%
1280fsm%!(dst%+size%)=map%!(src%+4)
1290src%=src%+8:dst%=dst%+size%*2
1300UNTILmap%!(src%-8)=0
1310PROCerr(FNhadfs(fsm%,&81,drive%,&46
,1))
1320OSCLI"MOUNT "+CHR$(48+drive%-7*(dri
ve%>9))
1330ENDPROC
1340:
1350DEFFNscsi(addr%,cmd%,drv%,sect%,num
%):LOCALfs%
1360fs%=FNfs:IFfs%<>8:*FADFS
1370X%?0=0:X%!1=addr%:X%?5=cmd%:X%?6=dr
v%*32+((sect%AND&1F0000)DIV65536)
1380X%?7=((sect%AND&FF00)DIV256):X%?8=s
ect%:X%!9=num%:X%!11=0
1390A%=&72:CALL&FFF1:A%=?X%:IFfs%<>8:OS
CLI"FX143,18,"+STR$fs%
1400=A%
1410:
1420DEFFNhadfs(addr%,cmd%,drv%,sect%,nu
m%):LOCALfs%:REM cmd%=&80 read, &81 writ
e
1430X%!0=&600:X%!2=addr%:X%!6=sect%:X%?
9=drv%:X%?10=num%:X%?11=cmd%:A%=90:CALL&
FFF1:=X%?11
1440:
1450DEFPROCerr(A%):IFA%=0:ENDPROC
1460PRINT"Disk error &"FNh0(A%,2);" at
"FNh0(sect%,8):END
1470ENDPROC
1480:
1490DEFFNfs:LOCALA%,Y%,E%:=(USR&FFDA)AN
D&FF
1500DEFFNfile(A$,A%):$name%=A$:?X%=name
%:X%?1=name%DIV256:=(USR&FFDD)AND&FF
1510DEFFNgbpb(A%):X%!1=name%:CALL&FFD1:
A%=name%+((1+?name%)AND((A%AND-2)=6)):A%
?(1+?A%)=13:=$(A%+1)
1520DEFFNgbpb8(ptr%):X%!1=name%:X%!5=1:
X%!9=ptr%:A%=8:CALL&FFD1:IFX%!5=1:=""
1530A%=name%+1:A%!(A%?-1)=&D20:A%?(INST
R($A%," ")-1)=13:=$A%
1540DEFFNh0(A%,N%)=RIGHT$("0000000"+STR
$÷A%,N%)
1550DEFFNargs(A%,Y%,ptr%):LOCALX%,E%:IF
?(TOP-3)=0:E%=Y%:Y%=0
1560IFHIMEM<&10000:LOCAL!&70:X%=&70:!X%
=ptr%:CALL&FFDA:=!X%
1570LOADATN"OS`Args",A%,Y%,ptr%TO,,ptr%
:=ptr%
1580: