5 'FBF-FM by JUN 2010
10 CLEAR:WK=&H1793:DR=&H18D1:RES=&H17A7:SL=1:GOSUB1070:MODE110(Z)JP
20 MODE110(Z)SI:MAX=PEEK(WK+1)
25 CLS:FN$="":ST=0:SZ=0:EX=0:EN=0:IFMAX>0THENPOKEWK,0:POKEWK+1,SL:GOSUB1000:GOSUB1040 ELSELOCATE13,2:PRINT"No files"
30 LOCATE0,0:PRINTFN$:LOCATE13,3:PRINT"S/I/L/D/F/R/EXE";:GOSUB1020:A=-(K$="S")-(K$="I")*2-(K$="L")*3-(K$="D")*4-(K$="F")*5-(K$="R")*6-(K$=CHR$(13))*7-(K$="2")*8-(K$="8")*9-(K$=CHR$(30))*10-(K$=CHR$(31))*11:IFMAX=0ANDA>2THEN30
40 ONA GOTO70,50,250,170,130,230,280,150,160,160,150:GOTO20 ELSE20
50 CLS:MODE110(Z)SI:A=WK+2:GOSUB1030:DD=B:PRINT"FBF area=";:A=&H18D1:GOSUB1030:B=B+1:PRINTHEX$(B);"-";HEX$(DD):PRINT DD-B+1;"B allocated."
60 PRINT MAX;"file(s).":A=&H18D1:GOSUB1030:C=B:A=&H18CF:GOSUB1030:PRINTC-B;"B free.";:GOTO910
70 IFMAX=255THEN30ELSEFN$="":ST=0:EN=0:EX=0:CLS:PRINT"** save **":INPUT"name(8)=";FN$:IFFN$=""THEN25ELSEIFLEN(FN$)>8THEN70
80 INPUT "start add=";ST$,"end add=";EN$,"call add=";EX$:ST=VAL(ST$):EN=VAL(EN$):EX=VAL(EX$):IFEN<0THENEN=EN+65536
90 IFST<0THENST=ST+65536
100 IFST>EN THEN70 ELSECLS:SZ=EN-ST+1:IFSZ>65535THEN70ELSEPRINTFN$:GOSUB1040:GOSUB1050:IFK$<>"Y"THEN20
110 MODE110(Z)BS FN$,ST,SZ,EX:IFPEEK(RES)=0THENMODE110(Z)SI:MAX=PEEK(WK+1):A$=FN$:GOTO135ELSEB$="save":GOTO900
120 GOSUB1040:GOTO35
130 LOCATE13,0:PRINT"search?";:A=20:B=27:GOSUB1060
135 IFA$=""THEN25ELSEMODE110(Z)SF A$:IFPEEK(RES)<>0THENA$="file not found.":GOTO905ELSELOCATE13,2:PRINT"wait.....":FORJ=1TOMAX:A=2:POKEWK,0:POKEWK+1,J:GOSUB1000:IFA$=FN$THENSL=J:J=999
140 NEXT:GOTO25
150 SL=SL-(K$="2")-(K$=CHR$(31))*5:IFSL>MAX THENIFK$="2"THENSL=1:GOTO25 ELSESL=MAX:GOTO25ELSE25
160 SL=SL+(K$="8")+(K$=CHR$(30))*5:IFSL<1 THENIFK$="8"THENSL=MAX:GOTO25 ELSESL=1:GOTO25ELSE25
170 LOCATE13,0:PRINT"delete?(YES):";:A=26:B=28:GOSUB1060:IFA$="ALL"THEN190ELSEIFA$<>"YES"THEN25
180 MODE110(Z)KL FN$:IFPEEK(RES)<>0THENB$="delete":GOTO900ELSELOCATE13,2:PRINT"file deleted.";:GOSUB1020:SL=SL+(SL>1):GOTO20
190 CLS:LOCATE13,0:PRINT"all file delete";:LOCATE13,1:PRINT"OK?(YES):";:A=54:B=56:GOSUB1060:IFA$<>"YES"THEN25ELSEI=1:LOCATE13,2:PRINT"wait...";
200 K=0:FORJ=0TO1:MODE110(Z)SI:MAX=PEEK&H1794:FORI=1TOMAX:LOCATE20,2:PRINTMID$("-I",1+K*1,1):POKEWK+1,I:POKEWK,0:GOSUB1000:IFRC<>0THENI=999ELSEPOKEWK,2:GOSUB1000:J=J*RC:I=I-(RC=0)*999
210 K=K+1+(K=1)*2:NEXTI,J:GOTO25
220 A$="delete failed.":GOTO905
230 LOCATE13,0:PRINT"new name?";:A=22:B=29:GOSUB1060:IFA$=""THEN25ELSEIFLEN(A$)>8THEN25
240 MODE110(Z)RN FN$,A$:IFPEEK(RES)<>0THENB$="rename":GOTO900ELSE25
250 LD=0:LOCATE13,0:PRINT"load=";:A=18:B=23:GOSUB1060:IFA$=""THENLD=ST ELSELD=VAL("&H"+A$)
260 LOCATE13,1:PRINT"load to &H";HEX$(LD);:GOSUB1050:IFK$<>"Y"THEN25
270 GOSUB800:IFPEEK(RES)<>0THEN840ELSEA$="file loaded.":GOTO905
280 A$=RIGHT$(FN$,2):IFA$=".r"THEN30ELSEIFA$=".R"THENMODE110(Z)RR FN$:GOSUB1020:GOTO25
290 LOCATE13,0:PRINT"load &H"+HEX$(ST)+" & EXE";:GOSUB1050:IFK$<>"Y"THEN25
300 LD=ST:GOSUB800:IFPEEK(RES)<>0THEN840ELSEMODE110(EX):GOSUB1020:GOTO25
799 END
800 A=&H1895:GOSUB1030:IOBF=B:IFLD>IOBF THEN820
810 IFLD>=&H1CD0THENIF LD+SZ-1=>IOBF THENA$="Need MAC area.":RETURN905ELSE830ELSE830
820 MODE110(Z)SI:A=WK+4:GOSUB1030:MD=B:A=DR:GOSUB1030:ND=B:IFLD>ND ANDLD<=MD THENRETURN840
830 MODE110(Z)BL FN$,LD:RETURN
840 B$="load":GOTO900
899 END
900 A$=B$+" failed."
905 LOCATE13,2:PRINTA$
910 GOSUB1020:GOTO20
1000 MODE110(Z):RC=PEEK(RES):RETURN
1020 LOCATE31,0:K$=INPUT$(1):RETURN
1030 B=PEEK(A+1)*256+PEEK(A):RETURN
1040 LOCATE0,1:PRINT"start=&H";HEX$(ST),"size =";MID$(STR$(SZ),2);"B","call =&H";HEX$(EX);:RETURN
1050 LOCATE13,2:PRINT"OK?(Y/N)";:GOSUB1020:RETURN
1060 C=PEEK(&H1100):POKE&H1100,C OR 8:POKE&H1106,A:POKE&H1107,B:INPUT"",A$:POKE &H1100,C:RETURN
1070 B=(PEEK&H18D1+PEEK&H18D2*256)+2:Z=PEEK(B)+PEEK(B+1)*256:RETURN
10000 CLS:CLEAR:GOSUB1070:PRINT"FBF release/file all delete","OK?(YES=release)";:INPUT"";A$:IFA$<>"YES"THENEND
10010 MODE110(Z)OF:PRINT"FBF release successfully." :END
