> MkTorch v0.02 - v0.01 Filename handling assumes Windows V v0.02 Fixed allocation table and overflow, directory overflow, forces upper case (: 24 ctrl% 31,data% 512,name% 31:X%=ctrl%:Y%=X%256 <@ "MkTorch - Create Torch CPN disk images from source files" F> "Source directory: "indir$: indir$="":indir$="CISCobol" P< "Output file: "out$: out$="":out$="COBOLCPN.ssd" Z. out$,out$-3,1)=".":out$=out$,out$-4) d mkcpn(indir$,out$+".ssd",) n mkcpn(indir$,out$+".dsd",) xȘ : mkcpn(indir$,out$,dsd%) ssd%=(dsd%=0)  % track_number = track<<2 + head . sector_number = track_number<<4 + sector   logical sector number:  %ttttttttttthssss + ||||||||||||++++--- sector 0-15 * |||||||||||+------- head (side) 0-1 - +++++++++++-------- track 0-2047 * sector number allows up to 16M disk   Sector  &0000-&0009 directory " &000A-&000F reserved , &0010-&0015 directory 6X &0016-&0017 allocation map, bit n=sector n is not free - space for up to 512K disk @ &0018 test pattern JE &0019 system information, all zeros except byte 254 = &66 T &001A-&001F reserved ^ &0020- data h r Directory |( &00-&01 sector of allocation block D &0000=end of dir, &0000+n=L3 block, &8000+n=L2 block & &02-&03 size in 128-byte records  &04 user number  &05-&0C file name  &0D-&0F file extension   L3 Allocation block Y &00-&01 sector of bytes 0-255, b14 set if 0-127 written, b15 set if 128-255 written [ &02-&03 sector of bytes 256-512, b14 set if 0-127 written, b15 set if 128-255 written  etc.   L2 Allocation block 1 &00-&01 sector of first L3 allocation block 2 &02-&03 sector of second L3 allocation block  etc.  & dirend%=0 0diskend%=&20 :out%=(out$) D idx%=0 NF:file$=f_scan(indir$,idx%):idx%=X%!9: file$<>"":addfile(file$) X file$="" bbdata%!0=0:data%!4=0:data%!8=0:data%!12=0 : Clear to end of directory lO dirend%<256::write(data%,16,dirend%*16):dirend%=dirend%+1: dirend%>255 vP A%=0 511 4:data%!A%=&FC00FC00: A% : Allocation table > A%=0 diskend%-1:data%?(A%8)=data%?(A%8) 2^(A%7): write(data%,512,&1600) L A%=0 255:data%?A%=A%+&D6: A%:write(data%,256,&1800): Test pattern R A%=0 255 4:data%!A%=0: A%:data%?254=&66 : System information write(data%,256,&1900) #out%:out%=0  : addfile(file$) ;fname$=file$: file$,4)=",fe4":fname$=file$,file$-4)  fname$;(14-fname$); ) dirend%>255: " - directory full": Bin%=(indir$+"\"+file$): in%=0:in%=(indir$+"\"+file$+",fe4")  in%=0:" - can't open":  OA%=fname$,"."):fname$=fname$,A%-1)+" ",8)+fname$,A%+1)+" ",3) 3fsize%=(#in%+127)128: fsize%:fsize%=fsize%-1  % h0(#in%,6);" ";h0(fsize%,4); *: 4!dir0%=dirend%:disk0%=diskend% >sec%=nextsec: diskfull: HM " ";h0(sec%,4);" T:";d0(sec%&20,3);" H:";(sec%&10)1;" S:";sec%15; Rl2%=0:a2%=2:l3%=sec%:a3%=0 \h fsize%>256:l2%=l3%:l3%=nextsec:!data%=l3%:write(data%,2,l2%*256):sec%=sec% &8000: diskfull: f.data%!0=sec% : Allocation block p;data%!2=fsize% : File size in 128-byte records z)data%?4=0 : User number &$(data%+5)=uc(fname$): File name write(data%,16,dirend%*16) dirend%=dirend%+1  sec%=nextsec: diskfull: !data%=sec% &C000 )write(data%,2,l3%*256+a3%):a3%=a3%+2 Q a3%>255:l3%=nextsec:!data%=l3%:write(data%,2,l2%*256+a2%):a2%=a2%+2:a3%=0 ! A%=0 255 4:data%!A%=0: f_gbpb(4,in%,data%,256,0) write(data%,256,sec%*256) fsize%=fsize%-2  fsize%<0 #in%:in%=0:  : $ ݤnextsec .LA%=diskend%:diskend%=diskend%+1: (diskend% 15)=10:diskend%=diskend%+6 8=A% B: L+ݤdiskfull: diskend%<=&A00 ssd%=0:= VA " - disk full":#in%:in%=0:diskend%=disk0%:dirend%=dir0%:= `: j&write(addr%,num%,ptr%): hd%,tk% t2 ssd%:hd%=(ptr% &1000) 1:tk%=ptr% &2000 ~/ ssd%:ptr%=(hd%*80+tk%)*&A00+(ptr% &FFF) 1 dsd%:ptr%=(ptr% &1000)*&A00+(ptr% &FFF) #f_gbpb(1,out%,addr%,num%,ptr%)  : : %f_gbpb(A%,chn%,addr%,num%,ptr%) =?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:<&FFFF:&FFD1: A%=1A%=3:#?X%=X%!9 5:A%=1A%=2:#?X%,?X%!1 A%=3A%=4:?X%!1=#?X% 5X%!1=X%!1+1:X%!5=X%!5-1:(#?X% A%>2) X%!5<1: : 3ݤf_scan(dir$,ptr%):X%!1=name%:X%!5=1:X%!9=ptr% .<&FFFF:dir$<>"":="": Not yet supported  $<&FFFF:A%=8:&FFD1:X%!5=1:="" @<&FFFF:A%=name%+1:A%!(A%?-1)=&D20:A%?($A%," ")-1)=13:=$A% 4-256<>"W":="": Non-Windows not yet supported (:dir%,sh%,res%:dir%319:X%!9=ptr%+1:dir$="":dir$="." 26ș"FindFirstFile",dir$+"\*.*",dir%sh%:sh%=-1:="" <0:A$=$$(dir%+44):A$="."A$="..":ptr%=ptr%+1 F!ptr%=0:ș"FindClose",sh%:=A$ P.ptr%=ptr%-1:ș"FindNextFile",sh%,dir%res% Z"res%=0:ș "FindClose",sh%:="" d: n#ݤh0(A%,N%)="0000000"+~A%,N%) x#ݤd0(A%,N%)="00000000"+A%,N%) ݤuc(A$):A$="":="" EA%=1A$:A$,A%,1)>"_":A$=A$,A%-1)+(A$,A%,1)&5F)+A$,A%+1)  :=A$