10
20
30
40
50
60
70
80
90
100
110
120
130
140 :
150 os%=FNfx(0,1)AND&FF:VDU10,8:A%=POS:VDU13:IFA%<50:MODE&87:IFHIMEM>&7C00:MODE&83:IFHIMEM>&4000:MODE&80
160 IFHIMEM<&FFFF:HIMEM=FNfx(132,0)
170 PROCinit:PROChdr:PRINT:ON ERROR IF FNerr:END
180 REPEAT:X%=ctrl%:Y%=X%DIV256:IF POS:PRINT
190 VDU 8:wdt%=POS+1:PRINT
200 IFdrv$="":PRINTCHR$(D%+48)">"; ELSE PRINT"["drv$"]";
210 csd%=home%:INPUTLINE" "A$:PROCdo(FNs(A$))
220 UNTIL FALSE
230 :
240 DEFPROCinit:ver$="1.32":bsz%=1024:fsv%=6
250 DIM ctrl% 127,name% 255,zp% 7,data% bsz%-1,data2% bsz%-1,ientry% 63,dir% bsz%+4,object% 63,thisdir% 63,diskrec% 255 AND (os%=6)
260 X%=ctrl%:Y%=X%DIV256:res%=0:D%=0:dmk%=&FFFF:drv$="":path$="/":title$="":home%=-1:csd%=-1
270 fs%=FNfs:d$=".":s$="/":IFos%AND-24:d$="/":s$=".":IFos%AND-32:d$="\"
280 cmd$=":MOUNT:DIR:CD:CAT:EX:LS:INFO:TYPE:DUMP:IMPORT:EXPORT:FREE:BLOCK:HELP:QUIT:"
290 hlp$=":<drive>|<image>:<dir>|&<inode>:<dir>|&<inode>::::(<file>):<file> [CTRLS]:<file> [7BIT]:<host source> <unix dest> (<opts>):<unix source> <host dest> (<opts>)::<blocknum>:::"
300 ENDPROC
310 DEFPROChdr:PRINT"UxFiler v"ver$" by J.G.Harston":ENDPROC
320 :
330 DEFFNerr:OSCLI"FX229":IF POS:PRINT
340 REPORT:IFFNfs<>fs%:OSCLI"FX143,18,"+STR$fs%
350 PROCCloseAll:A%=ERR<>17 AND ERR<>28:PRINTLEFT$(" at line "+STR$ERL,ERR<128 AND A%):=INKEY-1 AND A%
360 DEFPROCCloseAll:in%=in%:IFin%:A%=in%:in%=0:CLOSE#A%
370 out%=out%:IFout%:A%=out%:out%=0:CLOSE#A%
380 dsk%=dsk%:IFdsk%:A%=dsk%:dsk%=0:CLOSE#A%
390 ENDPROC
400 :
410 DEFPROCdo(A$):IFA$="?":A$="HELP" ELSE IF A$="EXIT":A$="QUIT"
420 IF LEFT$(A$,1)=";" OR A$="":ENDPROC
430 IF LEFT$(A$,1)="*":OSCLIMID$(A$,2):ENDPROC
440 IF LEFT$(A$,1)=".":A$="CAT "+MID$(A$,2)
450 A%=INSTR(A$+" "," "):B$=FNuc(LEFT$(A$,A%-1)):A$=FNs(MID$(A$,A%+1))
460 IF B$="COPY":PRINT"Use EXPORT or IMPORT":ENDPROC
470 IF LENB$=1 AND INSTR("0123",B$):drv$="":D%=VALB$:home%=-1:ENDPROC
480 A%=INSTR(cmd$,":"+B$+":"):IF A%=0:PRINT"Bad command":ENDPROC
490 A%=EVAL("FN_"+B$+"(A$)"):ENDPROC
500 :
510 DEFFNsyn(S$):IF A$="":PRINT "Syntax: "B$" "S$:=TRUE ELSE =FALSE
520 :
530
540
550 ; FN_INFO, FN_QUIT, FN_FREE, FN_DIR, FN_MOUNT, FN_LS, FN_EXPORT, FN_CD :
560 ; FN_HELP, FN_TYPE, FN_DUMP, FN_CAT, FN_BLOCK, FN_EX, FN_IMPORT
570 :
580 DEFFN_QUIT(A$):PRINT"Quit"
590 ON ERROR END
600 IF os%>5:*QUIT
610 END
620 :
630 DEFFN_HELP(A$):PROChdr:p%=2:q%=2:REPEAT
640 A%=INSTR(cmd$,":",p%):PRINT SPC2MID$(cmd$,p%,A%-p%);:p%=A%+1
650 A%=INSTR(hlp$,":",q%):PRINT TAB(9)MID$(hlp$,q%,A%-q%):q%=A%+1
660 UNTIL p%>LENcmd$:=0
670 :
680 DEFFN_MOUNT(A$):home%=-1:IF LENA$<2:PROCdo(A$):=0 ELSE drv$=A$:D%=-1:=0
690 DEFFN_CAT(A$):PROCLstDir(0):=0
700 DEFFN_EX(A$):PROCLstDir(1):=0
710 :
720 DEFFN_LS(A$)=FN_EX(A$)
730 DEFFN_CD(A$)=FN_DIR(A$)
740
750 :
760 DEFFN_DIR(A$):curr%=-1:IF FNsyn("<dir>|&<inode>"):=TRUE
770 IF LEFT$(A$,1)="&":A%=FNMount:home%=EVAL(FNuc(A$)):path$="&"+FNh0(home%,6):=0
780 IF A$="/":A%=FNMount:home%=root%:path$="/":=0
790 IF FNlook:=TRUE
800 IF(mode% AND 16384)=0:PRINT"'"src$"' not a directory":=TRUE
810 path$=path$+fname$+"/":home%=ptr%
820 IF RIGHT$(path$,3)="../":path$=LEFT$(path$,LENpath$-4):REPEAT:path$=LEFT$(path$,LENpath$-1):UNTILRIGHT$(path$,1)="/" OR path$=""
830 IF RIGHT$(path$,2)="./":path$=LEFT$(path$,LENpath$-2)
840 =0
850 :
860 DEFFN_BLOCK(A$):IF FNsyn("<blocknum>"):=TRUE
870 A%=FNMount:blk%=EVAL("&"+FNuc(A$)):PROCRdBlocks(data%,blk%,D%,1):O%=data%:ln%=512:PROCdump(FALSE)
880 =0
890 :
900 DEFFN_DUMP(A$):IF FNsyn("<fsp>"):=TRUE
910 IF FNlook:=TRUE
920 PROCdump(TRUE)
930 =0
940 :
950 DEFPROCdump(F%):cols%=16:IF wdt%<80:cols%=8
960 FOR P%=0 TO ln%-1 STEP cols%:B$=""
970 PRINT FNh0(P%,6)" ";:IF F%:IF (P%AND(bsz%-1))=0:PROCReadData(P%):O%=data%
980 FOR Q%=P% TO P%+cols%-1
990 IF Q%<ln%:PRINT FNh0(?O%,2)" "; ELSE ?O%=32:PRINT SPC3;
1000 A$=CHR$(?O%AND&7F):IF A$>=" " AND A$<="~" B$=B$+A$ ELSE B$=B$+"."
1010 O%=O%+1:NEXT:PRINT B$:NEXT:ENDPROC
1020 :
1030 DEFFN_TYPE(A$):IF FNsyn("<fsp>"):=TRUE
1040 msk%=INSTR(A$," [")<>0:msk%=(msk%AND&80)OR&7F:A$=LEFT$(A$,INSTR(A$+" "," ")-1)
1050 IF FNlook:=TRUE
1060 last%=0:FOR P%=0 TO ln%-1:IF(P%AND(bsz%-1))=0:PROCReadData(P%):O%=data%
1070 Q%=?O%ANDmsk%:IFmsk%=255:VDUQ% ELSE IFQ%=10 OR Q%=13 OR Q%>31 VDUQ%
1080 IF(Q%=10 OR Q%=13) AND Q%<>last%:VDU23-Q%
1090 IFQ%=9:PRINTSPC(8-(POS MOD 8));
1100 last%=?O%:O%=O%+1:NEXT:IF POS:PRINT
1110 =0
1120 :
1130 DEFFN_FREE(A$):A%=FNMount
1140 PROCRdInode(0):PROCRdBlocks(dir%,1,D%,1):isize%=dir%!0 AND &FFFF
1150 IF fsv%=6:fsize%=dir%!2 AND &FFFF:nfree%=dir%!4 AND &FFFF:ptr%=dir%!6 AND &FFFF
1160 IF fsv%>6:fsize%=FNswap32(dir%!2):nfree%=dir%!6 AND &FFFF:ptr%=FNswap32(dir%!8)
1170 free%=nfree%:REPEAT
1180 IF ptr%:PROCRdBlocks(data%,ptr%,D%,1):IF data%?1=0:free%=free%+data%?0-1
1190 IF ptr%:IF fsv%=6:ptr%=data%!2 AND &FFFF
1200 IF ptr%:IF fsv%>6:ptr%=FNswap32(data%!2)
1210 UNTILptr%<2 OR ptr%>=fsize%:used%=fsize%-free%
1220 PRINT"Disk free: &"FNh0(free%,8)" blocks, &"FNh0(free%*bsz%,8)" bytes, ";free%DIV(1024/bsz%);"K"
1230 PRINT"Disk used: &"FNh0(used%,8)" blocks, &"FNh0(used%*bsz%,8)" bytes, ";used%DIV(1024/bsz%);"K"
1240 PRINT"Disk size: &"FNh0(fsize%,8)" blocks, &"FNh0(fsize%*bsz%,8)" bytes, ";fsize%DIV(1024/bsz%);"K"
1250 =0
1260 :
1270 DEFFN_INFO(A$)
1280 IF A$=""ORA$="$":PROCPrSBlock:=0
1290 IF FNlook:=TRUE
1300 inode%=ptr%:x%=0:PROCListFile(1)
1310 FOR p%=all0% TO almx%-1 STEP alsz%:PRINTFNh0(FNblk(ientry%!p%),alsz%*2);" ";:NEXT:PRINT
1320 =0
1330 :
1340 DEFFN_EXPORT(A$):IF FNsyn("<unix source> (inf:)<host dest> (<C>onfirm)"):=TRUE
1350
1360
1370 A%=INSTR(A$+" "," "):src$=LEFT$(A$,A%-1):dst$=FNs(MID$(A$,A%+1))
1380 cnf%=FNuc(RIGHT$(dst$,2))=" C":IF cnf%:dst$=FNs(LEFT$(dst$,LENdst$-2))
1390 inf%=FNuc(LEFT$(dst$,4))="INF:":IFinf%:dst$=MID$(dst$,5)
1400 IFdst$="":PRINT"<dest> missing":=TRUE
1410 IFos%<6:IFINSTR(dst$,"::")ORLEFT$(dst$,1)="-":PRINT"FS prefix unsupported":=TRUE
1420 A$=src$:IF A$<>"/":A%=FNlook:cblk%=ptr%:IF A%:=TRUE
1430 IF A$="/":A%=FNMount:cblk%=root%:IF A%<0:=TRUE
1440 PROCFileInfo(cblk%)
1450 IF(mode%AND24576)<>16384:fptr%=ientry%:leaf$=src$:PROCCopyOneFile(src$,dst$):=0:
1460 :
1470
1480 A%=FNfile(dst$,8):dst$=dst$+d$:PROCCopyDirectory(dst$)
1490 PROCMetaInfo(thisdir%):PROCAcornInfo
1500 PROCSetInfo(LEFT$(dst$,LENdst$-1)):
1510 =0
1520 :
1530 DEFFN_IMPORT(A$):IF FNsyn("<host source> <unix dest>"):=TRUE
1540 A%=INSTR(A$," "):src$=LEFT$(A$,A%-1):A$=MID$(A$,A%+1)
1550 A%=INSTR(A$," "):dst$=LEFT$(A$,A%-1):A$=MID$(A$,A%+1)
1560 ptr%=FNfind(dst$):IFptr%=0:PRINT"'"dst$"' not found":=TRUE
1570 PROCFileInfo(ptr%):
1580 in%=FNf_openin(src$):IFin%=0:PRINT"'"src$"' not found":=TRUE
1590 ln%=EXT#in%:IFln%>length%:CLOSE#in%:in%=0:PRINT"Source file longer than dest":=TRUE
1600
1610 IF ln%>1024*1024-1:CLOSE#in%:in%=0:PRINT"Can't 1M+ files yet":=TRUE
1620 PRINT"Copying "src$;" to "dst$;SPC4;
1630 FOR P%=0 TO ln%-1:B%=0:
1640 IF(P%AND(bsz%-1))=0:PROCf_gbpb(3,in%,data%,bsz%,P%):PROCWriteData(P%):PRINTSTRING$(3,CHR$8)FNd(100*P%DIVlength%,2)"%";
1650 NEXT:CLOSE#in%:in%=0:PRINTSTRING$(3,CHR$127)
1660 =0
1670 :
1680 :
1690
1700
1710
1720 :
1730 DEFPROCCopyDirectory(dst$):LOCAL entry%,bit%,inode%,fptr%,fname$,blk%,dptr%,alloc%
1740
1750
1760
1770 FOR A%=0 TO 63 STEP 4:thisdir%!A%=ientry%!A%:NEXT
1780 alloc%=all0%
1790 REPEAT
1800 blk%=FNblk(thisdir%!alloc%):IF blk%:PROCCopyBlock
1810 alloc%=alloc%+alsz%
1820
1830 UNTIL blk%=0 OR alloc%>almx%-1
1840 ENDPROC
1850 :
1860
1870 DEFPROCCopyBlock
1880 PROCRdBlocks(dir%,blk%,D%,1):dptr%=dir%
1890 REPEAT
1900 inode%=!dptr% AND &FFFF
1910 A%=dptr%?16:dptr%?16=13:fname$=$(dptr%+2)+CHR$0:dptr%?16=A%
1920 fname$=LEFT$(fname$,INSTR(fname$,CHR$0)-1)
1930 IF inode% THEN PROCCopyObject
1940 dptr%=dptr%+16
1950 UNTIL dptr%>=dir%+bsz%
1960 ENDPROC
1970 :
1980 DEFPROCCopyObject:LOCAL ptr%,bit%,old_cblk%,thisdir$,bitmap$,object$
1990 IF fname$="." OR fname$="..":ENDPROC
2000 IFcnf%:PRINT"Copy "fname$;:cnf%=FNyna(cnf%):IFcnf%>0:PRINT:ENDPROC ELSE VDU13
2010 PROCFileInfo(inode%):leaf$=fname$:fname$=LEFT$(FNfn_undos(fname$),10):fptr%=ientry%
2020 IF(mode%AND24576)<>16384:PROCCopyOneFile(leaf$,dst$+fname$):ENDPROC
2030 :
2040
2050 old_cblk%=cblk% :
2060 FOR A%=0 TO 63:thisdir$=thisdir$+CHR$thisdir%?A%:NEXT :
2070 FOR A%=0 TO 63:object$ =object$ +CHR$fptr%?A% :NEXT :
2080 cblk%=inode% :
2090 A%=FNfile(dst$+fname$,8) :
2100 PROCCopyDirectory(dst$+fname$+d$) :
2110 FOR A%=0 TO 63:object%?A%=ASCMID$(object$,A%+1):NEXT :
2120 PROCMetaInfo(object%)
2130 PROCAcornInfo:PROCSetInfo(dst$+fname$) :
2140 :
2150
2160 FOR A%=0 TO 63:thisdir%?A%=ASCMID$(thisdir$,A%+1):NEXT :
2170 cblk%=old_cblk%:PROCRdBlocks(dir%,blk%,D%,1) :
2180 ENDPROC
2190 :
2200 DEFPROCCopyOneFile(src$,dst$):LOCAL cblk%
2210 PRINT"Copying "src$;SPC(15-LENsrc$)"to "dst$SPC4;
2220 FOR A%=0 TO 63 STEP 4:object%!A%=fptr%!A%:NEXT
2230 PROCMetaInfo(object%):IFFNfile(dst$,5):X%?14=&33:A%=FNfile(dst$,4)
2240 PROCAcornInfo:X%!2=load%:X%!6=exec%:X%!10=0:X%!14=length%:A%=FNfile(dst$,7)
2250 IFlength%:PROCCopyData :
2260 PROCSetInfo(dst$):PRINTSTRING$(3,CHR$127):ENDPROC
2270 :
2280 DEFPROCCopyData
2290 out%=FNf_openout(dst$):P%=0:REPEAT:PROCReadData(P%):IF POS=0:PRINTSPC4;
2300 IF(P%AND1023)=0:PRINT STRING$(3,CHR$8)FNd(100*P%DIVlength%,2)"%";
2310 num%=bsz%:IFP%+num%>length%:num%=length%-P%
2320 PROCf_gbpb(2,out%,data%,num%,0):P%=P%+num%:UNTILP%>=length%
2330 CLOSE#out%:out%=0:ENDPROC
2340 :
2350 DEFPROCSetInfo(dst$):X%!2=load%:X%!6=exec%:X%!10=length%:X%!14=attr%:A%=FNfile(dst$,1)
2360 A$=leaf$+STRING$(15-LENleaf$," ")+FNh0(load%,8)+" "+FNh0(exec%,8)+" "+FNh0(length%,8)+CHR$13+CHR$10:
2370 IFinf%:out%=OPENOUT(dst$+s$+"inf"):FOR p%=1 TO LEN A$:BPUT#out%,ASCMID$(A$,p%,1):NEXT:CLOSE#out%:out%=0
2380 IFfs%<>5:ENDPROC
2390
2400 X%!8=cdate%:A%=FNNetFS_OpN(19,5,10,dst$) :
2410 IF FNNetFS_Op(18,CHR$64+dst$):ENDPROC :
2420 X%!8=cdate%:X%!10=ctime%:X%!13=mdate%:X%!15=mtime%
2430 A%=FNNetFS_OpN(19,64,18,dst$) :
2440 A%=FNNetFS_Op(0,"ACCOUNT "+dst$+" "+STR$~acc%+" ("+STR$~aux%+")")
2450 ENDPROC
2460 :
2470 :
2480
2490
2500 :
2510 DEFPROCLstDir(cflg%):x%=0:IF FNMount:PRINT"Not a UNIX disk":ENDPROC
2520
2530 PROCRdInode(csd%):
2540 IF(ientry%?1 AND (64+32))<>64 THEN PRINT "inode "FNh0(csd%,4)" is not a directory":ENDPROC
2550 PRINT "Path: "path$
2560 IF(cflg%AND1):PRINT "inode filename"SPC12"mode"SPC6"nd uid gid len ctime"SPC4"mtime"SPC4"atime"
2570 alloc%=all0%
2580 REPEAT
2590 blk%=FNblk(ientry%!alloc%):IFblk%:PROCListBlock
2600 alloc%=alloc%+alsz%
2610 IF alloc%<almx%:PROCRdInode(csd%)
2620 UNTIL blk%=0 OR alloc%>almx%-1
2630 IF(cflg%AND1)=0:IF(x%AND3):PRINT
2640 ENDPROC
2650 :
2660
2670 DEFPROCListBlock
2680 PROCRdBlocks(dir%,blk%,D%,1):dptr%=dir%
2690 REPEAT
2700 inode%=!dptr% AND &FFFF
2710 A%=dptr%?16:dptr%?16=13:fname$=$(dptr%+2)+CHR$0:dptr%?16=A%
2720 fname$=LEFT$(fname$,INSTR(fname$,CHR$0)-1)
2730 IF inode%:PROCListFile(cflg%)
2740 dptr%=dptr%+16
2750 UNTIL dptr%>=dir%+bsz%
2760 ENDPROC
2770 :
2780 DEFPROCListFile(cflg%)
2790 IF(cflg%AND1):PRINT FNh0(inode%,4)" ";
2800 PROCFileInfo(inode%):PRINTfname$;SPC(15-LENfname$);
2810 IF(cflg%AND1)=0:x%=x%+1:IF x%<wdt% DIV 15:PRINT " "; ELSE IF(cflg%AND1)=0:x%=0:PRINTCHR$8
2820 IF(cflg%AND1)=0:ENDPROC
2830 PRINT FNattr(mode%)" "; :
2840 PRINT FNh0(nlink%,2)" "; :
2850 PRINT FNh0(uid%,2)" "; :
2860 PRINT FNh0(gid%,2)" "; :
2870 PRINT FNd(length%,6);" "; :
2880 PRINT FNdate(cdate%);" "FNdate(mdate%);" "FNdate(adate%)
2890 ENDPROC
2900 :
2910 DEFPROCPrSBlock
2920 A%=FN_FREE("")
2930 PRINT"UnixFS version:";SPC14;fsv%;" (";4*LEN(STR$~dmk%);"-bit) bsz=";bsz%;" naddr=";naddr%
2940 PRINT "isize: inode table size:"SPC5"&"FNh0(isize%,4)" blocks, max inode: &";~isize%*bsz%/isz%
2950
2960
2970
2980 PRINT "in-core free blocks: &"FNh0(nfree%,4)
2990 IF fsv%=6:fbk%=6:stp%=2:ino%=&CE:in1%=&197
3000 IF fsv%>6:fbk%=8:stp%=4:ino%=&D0:in1%=&199
3010 FOR n%=fbk% TO ino%-1 STEP stp%:IF fsv%=6:PRINT FNh0(dir%!n%,4); ELSE IF fsv%>6:PRINT FNh0(FNswap32(dir%!n%),8);
3020 IF (n% AND 31)=4:PRINTCHR$8 ELSE PRINT" ";
3030 NEXT:PRINT
3040 PRINT "in-core free inodes: &"FNh0(dir%!ino%,4)
3050 FOR n%=ino%+2 TO in1% STEP 2:PRINT FNh0(dir%!n%,4);:IF ((n%-ino%-2) AND 31)=30:PRINTCHR$8 ELSE PRINT" ";
3060 NEXT:PRINT
3070 PRINT "flock: free list lock:"SPC7FNh0(dir%?(in1%+1),2);SPC8;
3080 PRINT "ilock: inode table lock: "FNh0(dir%?(in1%+2),2)
3090 PRINT "fmod: superblock modified: "FNh0(dir%?(in1%+3),2);SPC8;
3100 PRINT "dlock: disk read only:"SPC3FNh0(dir%?(in1%+4),2)
3110 PRINT "time: disk last update:"SPC5FNdate(FNswap32(dir%!(in1%+5)))
3120 FOR n%=in1%+9 TO &1FF STEP 2:PRINT FNh0(dir%!n%,4);:IF ((n%-in1%-9) AND 31)=30:PRINTCHR$8 ELSE PRINT" ";
3130 NEXT:IF POS:PRINT
3140 ENDPROC
3150 :
3160 DEFFNattr(A%):A$=""
3170 IF(A%AND1) THEN A$="x" ELSE A$="-"
3180 IF(A%AND2) THEN A$="w"+A$ ELSE A$="-"+A$
3190 IF(A%AND4) THEN A$="r"+A$ ELSE A$="-"+A$
3200 IF(A%AND8) THEN A$="x"+A$ ELSE A$="-"+A$
3210 IF(A%AND16) THEN A$="w"+A$ ELSE A$="-"+A$
3220 IF(A%AND32) THEN A$="r"+A$ ELSE A$="-"+A$
3230 IF(A%AND64) THEN A$="x"+A$ ELSE A$="-"+A$
3240 IF(A%AND128) THEN A$="w"+A$ ELSE A$="-"+A$
3250 IF(A%AND256) THEN A$="r"+A$ ELSE A$="-"+A$
3260 IF(A%AND512) THEN A$="s"+A$ ELSE A$="-"+A$
3270 IF(A%AND1024) THEN A$="g"+A$ ELSE A$="-"+A$
3280 IF(A%AND2048) THEN A$="u"+A$ ELSE A$="-"+A$
3290 IF(A%AND4096) THEN A$="l"+A$ ELSE A$="-"+A$
3300 IF(A%AND8192) THEN A$="c"+A$ ELSE A$="-"+A$
3310 IF(A%AND16384) THEN A$="d"+A$ ELSE A$="-"+A$
3320 IF(A%AND32768) THEN A$="a"+A$ ELSE A$="-"+A$
3330 =A$
3340 :
3350 DEFFNdate(A%):
3360 LOCAL day%,month%,year%,hour%,minute%,second%
3370 X%!1=A%/2.56:X%!1=X%!1+&336E996A:PROCDate_ToOrd(X%)
3380 =FNd0(day%,2)+"/"+FNd0(month%,2)+"/"+FNd0(year%,2)
3390 :
3400 DEFFNtime(A%):
3410 LOCAL day%,month%,year%,hour%,minute%,second%
3420 X%!1=A%/2.56:X%!1=X%!1+&336E996A:PROCDate_ToOrd(X%)
3430 =FNd0(hour%,2)+":"+FNd0(minute%,2)
3440 :
3450 DEFPROCUnixDateToAcorn(A%):
3460 X%!1=A%/2.56:X%!1=X%!1+&336E996A:PROCDate_ToOrd(X%)
3470 date%=&101:IFyear%>1980:date%=FNf_date(day%,month%,year%)
3480 time%=FNf_time(hour%,minute%,second%)
3490 ENDPROC
3500 :
3510 DEFPROCAcornInfo
3520 attr%=(mode%AND256)DIV256+(mode%AND128)DIV64+(mode%AND64)DIV16
3530 attr%=attr%+(((mode%AND32)/2)OR((mode%AND4)*4))+(((mode%AND16)*2)OR((mode%AND2)*16))+(((mode%AND8)*8)OR((mode%AND1)*64))
3540 IF cdate%>mdate%:cdate%=mdate%:
3550
3560 PROCUnixDateToAcorn(cdate%):cdate%=date%:ctime%=time%
3570 PROCUnixDateToAcorn(mdate%):mdate%=date%:mtime%=time%
3580 PROCDate_FromOrd(X%,day%,month%,year%,hour%,minute%,second%,0)
3590 X%!5=&FFFFFF:IF(mode%AND&49):X%!5=&FFFFE6
3600 load%=X%!4:exec%=!X%:attr%=attr%+256*mdate%:acc%=uid%:aux%=gid%
3610 ENDPROC
3620 :
3630
3640
3650 :
3660 DEFFNlook:src$=A$:ptr%=FNfind(src$):IFptr%:PROCFileInfo(ptr%):ln%=length%:=FALSE
3670 PRINT"'"src$"' not found":=TRUE
3680 :
3690 DEFFNfind(A$):match$=LEFT$(A$,14):match%=0:IFFNMount:=0
3700 PROCRdInode(csd%):IFcsd%=-1:csd%=root%
3710 alloc%=all0%:match%=0
3720 REPEAT
3730 blk%=FNblk(ientry%!alloc%):IFblk%:PROCFileBlock
3740 alloc%=alloc%+alsz%
3750 IF NOT match%:IF alloc%<almx%:PROCRdInode(csd%)
3760 UNTIL blk%=0 OR alloc%>almx%-1 OR match%
3770 IF match%:=inode% ELSE =0
3780 :
3790
3800 DEFPROCFileBlock
3810 PROCRdBlocks(dir%,blk%,D%,1):dptr%=dir%
3820 REPEAT
3830 inode%=!dptr% AND &FFFF
3840 A%=dptr%?16:dptr%?16=13:fname$=$(dptr%+2)+CHR$0:dptr%?16=A%
3850 fname$=LEFT$(fname$,INSTR(fname$,CHR$0)-1)
3860 match%=fname$=match$
3870 dptr%=dptr%+16
3880 UNTIL dptr%>=dir%+bsz% OR match%
3890 ENDPROC
3900 :
3910 DEFPROCFileInfo(f%):PROCRdInode(f%):PROCMetaInfo(ientry%):ENDPROC
3920 :
3930 DEFPROCMetaInfo(i%)
3940
3950 mode% =i%!0 AND &FFFF
3960 nlink% =i%!2 AND imk%
3970 uid% =i%!(2+usz%/2) AND imk%
3980 gid% =i%!(2+2*(usz%/2)) AND imk%
3990 IFisz%=32:length%=FNswap24(i%!5)
4000 IFisz%>32:length%=FNswap32(i%!8)
4010 IFisz%=32:adate%=FNswap32(i%!tm%) :mdate%=FNswap32(i%!(tm%+4)):cdate%=mdate%
4020 IFisz%>32:adate%=FNswap32(i%!(tm%+8)):mdate%=FNswap32(i%!(tm%+4)):cdate%=FNswap32(i%!tm%)
4030 ENDPROC
4040 :
4050
4060
4070
4080 :
4090 :
4100
4110
4120 :
4130 DEFPROCRdInode(i%)
4140
4150 PROCRdBlocks(data%,(bsz%*2+i%*isz%-isz%)DIV(bsz%),D%,1)
4160 i%=(bsz%*2+i%*isz%-isz%)AND(bsz%-1)
4170 FOR A%=0 TO isz%-1 STEP 4:ientry%!A%=data%!(A%+i%):NEXT
4180 ENDPROC
4190 :
4200 DEFFNMount:IFcsd%<>-1:=0
4210 bsz%=512:PROCfdcInit(diskrec%,9,9,2,2,80,1):PROCRdBlocks(data%,2,D%,1)
4220 IFerr%=-2:PRINT "Disk error: Image file not found":=-2
4230 ::::::::::::::fsv%=6:isz%=32:root%=1:all0%=08:alsz%=2:naddr%=08:tm%=&18:usz%=2:bsz%=0512
4240 IFdata%!8=0:::fsv%=7:isz%=64:root%=2:all0%=12:alsz%=3:naddr%=13:tm%=&34:usz%=4:bsz%=0512
4250 IFdata%?1<&80:fsv%=9:isz%=64:root%=2:all0%=12:alsz%=3:naddr%=07:tm%=&34:usz%=4:bsz%=1024
4260
4270
4280
4290 almx%=all0%+alsz%*naddr%:dmk%=EVAL("&"+STRING$(alsz%,"FF")):imk%=EVAL("&"+STRING$(usz%,"FF"))
4300 csd%=root%:home%=csd%:path$="/"
4310 =0
4320 :
4330 DEFFNblk(b%)
4340 IFalsz%=2:=b%AND&FFFF
4350 IFalsz%=3:=FNswap24(b%)
4360 =FNswap32(b%)
4370 :
4380 DEFPROCReadData(ptr%):PROCTxData(FALSE):ENDPROC
4390 DEFPROCWriteData(ptr%):PROCTxData(TRUE):ENDPROC
4400 :
4410 DEFPROCTxData(write%):LOCAL p%
4420 IF alsz%=2:PROCTx16 ELSE PROCTx24
4430 IF p%=0:IF NOT write%:FOR A%=0 TO bsz%-1 STEP 4:data%!A%=0:NEXT:ENDPROC
4440 IF p%:PROCTxBlocks(data%,p%,D%,1,write%)
4450 ENDPROC
4460 :
4470 DEFPROCTx24
4480 p%=ptr%DIVbsz%:IF p%<naddr%-3:p%=all0%+p%*alsz%:p%=FNblk(ientry%!p%):ENDPROC
4490 ptr%=(p%-naddr%+3) :
4500 p%=ptr%DIV(bsz%/4) :
4510 PROCRdBlocks(data2%,FNblk(ientry%!(almx%+(p%-3)*alsz%)),D%,1)
4520 IF p%>1:p%=0:ENDPROC:
4530 IF p%=1:PROCRdBlocks(data2%,data2%!((ptr%DIV(bsz%/4))*4),D%,1):ptr%=ptr%MOD(bsz%/4)
4540 p%=FNswap32(data2%!(ptr%*4))
4550 ENDPROC
4560 :
4570 DEFPROCTx16
4580 IF (mode%AND4096)=0:p%=all0%+2*(ptr%DIVbsz%):p%=ientry%!p%:ENDPROC
4590 p%=all0%+2*(ptr%DIV(128*1024))
4600 PROCRdBlocks(data2%,ientry%!p%,D%,1)
4610 p%=(ptr%DIVbsz%)AND&FF:p%=data2%!(p%*2)
4620 ENDPROC
4630 :
4640 DEFPROCRdBlocks(a%,b%,d%,n%):PROCTxBlocks(a%,b%,d%,n%,FALSE):ENDPROC
4650 DEFPROCWrBlocks(a%,b%,d%,n%):PROCTxBlocks(a%,b%,d%,n%,TRUE):ENDPROC
4660 :
4670 DEFPROCTxBlocks(addr%,block%,drive%,number%,write%):LOCAL q%
4680 err%=0:block%=block% AND dmk%
4690 FOR q%=0 TO number%-1:PROCfdcAct(2+(write%=0),addr%+q%*bsz%,block%+res%+q%,drive%,1,0):NEXT
4700 ENDPROC
4710 :
4720 :
4730
4740
4750 :
4760 DEFPROCfdcInit(dskrec%,bps%,spt%,hds%,den%,trks%,sec0%)
4770 LOCAL i%:IFos%<>6:ENDPROC
4780 dskrec%?0=bps%:dskrec%?1=spt%:dskrec%?2=hds%:dskrec%?3=den%:IFden%=1:dskrec%?2=1
4790 FOR i%=4 TO 59 STEP 4:dskrec%!i%=0:NEXT:dskrec%!60=&20000000:dskrec%!64=&20000000
4800 dskrec%?8=sec0%:dskrec%!16=trks%*spt%*(2^bps%)*hds%
4810 ENDPROC
4820 :
4830 DEFPROCfdcAct(op%,ad%,sc%,dv%,nm%,dn%)
4840 IF op%=1:FOR A%=0 TO bsz%-1 STEP4:ad%!A%=0:NEXT:drv%=drv%AND-5:IFdrv%>7:err%=-1:ENDPROC
4850 IF drv$="":REPEAT:PROCfdcOp(op%):ad%=ad%+bsz%:sc%=sc%+1:nm%=nm%-1:UNTIL nm%<1:ENDPROC
4860 IF op%=2:dsk%=FNf_openup(drv$):IF dsk%=0:err%=-2:ENDPROC
4870 IF op%=1:dsk%=FNf_openin(drv$):IF dsk%=0:err%=-2:ENDPROC
4880 IF op%=1:IF sc%*bsz%>EXT#dsk%:CLOSE#dsk%:dsk%=0:err%=-3:PRINT"Disk error: Past end of image":ENDPROC
4890 PROCf_gbpb(5-op%*2,dsk%,ad%,nm%*bsz%,sc%*bsz%):CLOSE#dsk%:dsk%=0
4900 ENDPROC
4910 :
4920 DEFPROCfdcOp(op%)
4930 IF os%>6:err%=-1
4940 IF os%=6:SYS"XADFS_DiscOp",,op%+(diskrec%<<6),sc%*bsz%+((dv%AND3)<<29),ad%,bsz% TO err%
4950 IF os%<6:trk%=sc%DIV9:trk%=trk%DIV2+80*(trk%AND1):err%=FNscsi(ad%,6+op%*2,dv%OR4,trk%*16+sc%MOD9+1,1)
4960 IF csd%=0:ENDPROC
4970 IF err%:IF POS:PRINT
4980 IF err%=-1:PRINT"Unsupported":ENDPROC
4990 IF err%:PRINT"Disk error &"FNh0(err%,2)" at ";dv%":"FNh0(sc%,6)
5000 ENDPROC
5010 :
5020 DEFFNswap24(A%):zp%!0=A%:zp%!3=A%:=zp%!1 AND &FFFFFF
5030 DEFFNswap32(A%):zp%!0=A%:zp%!4=A%:=zp%!2
5040 DEFFNs(A$):IFLEFT$(A$,1)=" ":REPEATA$=MID$(A$,2):UNTILLEFT$(A$,1)<>" "
5050 IFRIGHT$(A$,1)=" ":REPEATA$=LEFT$(A$,LENA$-1):UNTILRIGHT$(A$,1)<>" "
5060 =A$
5070 DEFFNuc(A$):IFA$="":=""
5080 FORA%=1TOLENA$:IFMID$(A$,A%,1)>"_":A$=LEFT$(A$,A%-1)+CHR$(ASCMID$(A$,A%,1)AND&5F)+MID$(A$,A%+1)
5090 NEXT:=A$
5100 DEFFNfx(A%,X%):LOCAL Y%:Y%=X%DIV256:=(USR&FFF4 AND &FFFF00)DIV256
5110 :
5120
5130
5140
5150 DEFFNfn_undos(A$):LOCALB%:IF(os%AND-32):=A$
5160 FORA%=1TOLENA$:B%=INSTR(".#$^&@%~",MID$(A$,A%,1)):IFB%:A$=LEFT$(A$,A%-1)+MID$("/?<>+=;\",B%,1)+MID$(A$,A%+1)
5170 NEXT:=A$
5180 :
5190 DEFFNyna(A%):IFA%=0:=0
5200 PRINT"? (Y/N/A)";:REPEAT:A%=INSTR("YAN",CHR$(GETAND&DF)):UNTILA%
5210 PRINTSTRING$(7,CHR$127);MID$("YesAllNo ",A%*3-2,3);:=A%-2
5220 :
5230
5240
5250 DEFFNh0(A%,N%):=RIGHT$("00000000"+STR$~A%,N%)
5260 DEFFNd0(A%,N%):=RIGHT$("00000000"+STR$A%,N%)
5270 DEFFNd(A%,N%):=RIGHT$(" "+STR$A%,N%)
5280 :
5290
5300
5310 DEFFNdisk(addr%,cmd%,drv%,trk%,sec%,num%,den%):LOCALfs%,n%
5320 fs%=FNfs:IFfs%<>4:*FX143,18,4
5330 REPEAT:n%=num%:IFsec%+n%>10:n%=10-sec%
5340 REPEAT:X%?0=drv%+den%*24+8+2*(trk%DIV80):X%!1=addr%:X%?5=3-7*(cmd%>127)
5350 X%?6=cmd%:X%?7=trk%MOD80:X%?8=sec%:X%!9=n%OR&1E20:A%=127:CALL&FFF1
5360 A%=X%?(7+X%?5):UNTILA%<>&10:addr%=addr%+n%*256:num%=num%-n%:sec%=(sec%+n%)MOD10:trk%=trk%+1
5370 UNTILA%<>0ORnum%<1:IFfs%<>4:OSCLI"FX143,18,"+STR$fs%
5380 =A%
5390 :
5400 DEFFNscsi(addr%,cmd%,drv%,sect%,num%):LOCALfs%
5410 fs%=FNfs:IFfs%<>8:*FADFS
5420 X%?0=0:X%!1=addr%:X%?5=cmd%:X%?6=drv%*32+((sect%AND&1F0000)DIV65536)
5430 X%?7=((sect%AND&FF00)DIV256):X%?8=sect%:X%!9=num%:X%!11=0
5440 A%=&72:CALL&FFF1:A%=?X%:IFfs%<>8:OSCLI"FX143,18,"+STR$fs%
5450 =A%
5460 :
5470 DEFFNlvfs(addr%,cmd%,drv%,sect%,num%):LOCALfs%
5480 fs%=FNfs:IFfs%<>10:*FX143,18,10
5490 X%?0=0:X%!1=addr%:X%?5=cmd%:X%?6=drv%*32+((sect%AND&1F0000)DIV65536)
5500 X%?7=((sect%AND&FF00)DIV256):X%?8=sect%:X%!9=num%:X%!11=0
5510 A%=&62:CALL&FFF1:A%=?X%:IFfs%<>10:OSCLI"FX143,18,"+STR$fs%
5520 =A%
5530 :
5540 DEFFNscsi_err(A%,S%)
5550 IFA%:PRINT"Disk error "FNh0(A%,2)" ("MID$("fddhdd",(A%AND64)/64+1,3)") at "FNh0(S%,6)
5560 =A%
5570 :
5580 DEFFNdisk_err(A%,S%)
5590 IFA%:PRINT"Disk error "FNh0(A%,2)" at "FNh0(S%,4)
5600 =A%
5610 :
5620
5630
5640 DEFFNfs:IF(os%AND-32)=0:LOCAL A%,Y%,E%:=(USR&FFDA)AND&FF
5650 =29
5660 :
5670 DEFPROCf_gbpb(A%,chn%,addr%,num%,ptr%)
5680 ?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:IFPAGE<&FFFFF:CALL&FFD1:ENDPROC
5690 IFA%=1ORA%=3:PTR#?X%=X%!9
5700 REPEAT:IFA%=1ORA%=2:BPUT#?X%,?X%!1 ELSE IFA%=3ORA%=4:?X%!1=BGET#?X%
5710 X%!1=X%!1+1:X%!5=X%!5-1:UNTIL(EOF#?X% AND A%>2)OR X%!5<1:ENDPROC
5720 :
5730 DEFFNfile(A$,A%):IFA%-8:IFPAGE<&FFFFF:$name%=A$:?X%=name%:X%?1=name%DIV256:=(USR&FFDD)AND&FF
5740 A$=FNf_name(A$):IFA%=255 OR A%=5:X%!14=OPENIN(A$):IFX%!14:X%!10=EXT#X%!14:CLOSE#X%!14:X%!14=&33
5750 IFA%=255:IFX%?6=0:OSCLI"LOAD """+A$+""" "+STR$~X%!2:=1
5760 IFA%=5:IFX%!14:=1 ELSE IFA%=5:=0
5770 IFA%=0:OSCLI"SAVE """+A$+""" "+STR$~X%!10+" "+STR$~X%!14:X%!10=X%!14-X%!10:=1
5780 IFA%=7:OSCLI"SAVE """+A$+""" "+STR$~PAGE+"+"+STR$~X%!10:X%!10=X%!14-X%!10:=1
5790 IFA%-8:=0
5800 IF(os%AND-24):A$="mkdir "+A$ ELSE A$="cdir "+A$
5810 IFHIMEM>&FFFF:LOCAL ERROR:ON ERROR LOCAL:=0
5820 OSCLIA$:=2
5830 :
5840 DEFFNf_openin(A$)=OPENIN(FNf_name(A$))
5850 DEFFNf_openout(A$)=OPENOUT(FNf_name(A$))
5860 DEFFNf_openup(A$)=OPENUP(FNf_name(A$))
5870 DEFFNf_name(A$):IFos%AND-32:LOCALA%,B%:REPEATB%=A%:A%=INSTR(A$,"\",A%+1):UNTILA%=0:IFINSTR(A$,".",B%)=0:A$=A$+"."
5880 =A$
5890 :
5900
5910
5920 DEFFNNetFS_Op(A%,A$)=FNNetFS_OpN(A%,0,7,A$)
5930 DEFFNNetFS_OpN(A%,T%,O%,A$):LOCAL N%:!X%=0:X%?1=O%+1+LENA$:X%!3=A%:X%?7=T%:$(X%+O%)=A$
5940 IFHIMEM>&FFFF:FORN%=4TOX%?1:X%?N%=X%?(N%+3):NEXT:SYS&60048,A%,X%+4,O%+LENA$,120TOA%:IFA%=0:X%?3=0:=0
5950 IFHIMEM>&FFFF:IFA%>&FFFF:X%?3=?A%:SYS&2002B,A%+4TO$(X%+4):=X%?3
5960 A%=&14:CALL&FFF1:=X%?3
5970 :
5980
5990
6000 DEFPROCDate_FromOrd(mem%,d%,m%,y%,hr%,mn%,sc%,cs%):y%=y%MOD400
6010 d%=y%*365.25+m%*30+d%+VALMID$("120112234455",m%,1)+((y%MOD4)=0)-((y%-1)DIV100)-(m%>2AND((y%MOD4)=0AND(y%MOD100)<>0ORy%=0))+36493
6020 IFd%>146066:d%=d%-146097
6030 d%=d%*&41EB:mem%!1=d%+d%:d%=((hr%*60+mn%)*60+sc%)*100+cs%
6040 ?mem%=d%:mem%!1=mem%!1+d%DIV256:ENDPROC
6050 :
6060 DEFPROCDate_ToOrd(mem%):LOCAL A%,B%,C%,D%
6070 year%=0:month%=0:day%=0:hour%=0:minute%=0:second%=0:centi%=0
6080 IFmem%!1<0:ENDPROC:
6090 D%=mem%!1DIV&83D6+2447065:C%=mem%?0+256*(mem%!1MOD&83D6):centi%=C%MOD100
6100 C%=C%DIV100:second%=C%MOD60:C%=C%DIV60:minute%=C%MOD60:hour%=C%DIV60
6110 B%=((D%*4+3)MOD146097AND-4)+3:C%=B%MOD1461DIV4*5+2:D%=D%*4+3
6120 A%=C%DIV153+2:day%=C%MOD153DIV5+1:month%=A%MOD12+1
6130 year%=D%DIV146097*100+B%DIV1461+A%DIV12-4800
6140 ENDPROC
6150 :
6160
6170
6180 DEFFNf_date(d%,m%,y%):y%=y%-1981:=d%+m%*256+(y%AND15)*4096+(y%DIV16)*32
6190 DEFFNf_time(h%,m%,s%):=h%+m%*256+s%*65536
6200 DEFPROCf_date(d%):day%=d%AND31:month%=(d%AND&F00)DIV256
6210 year%=(d%AND&F000)DIV4096+(d%AND&E0)/2+1981:ENDPROC
6220 DEFPROCf_time(t%):hour%=t%AND255:minute%=(t%AND&FF00)DIV256
6230 second%=(t%AND&FF0000)DIV65536:ENDPROC
6240 :