> TAPtoMDR 1.15  (C) J.G.Harston 1 Copy Spectrum tapefile to a microdrive file (: 2$ v1.00 Based on FileToMDR v1.03 <1 v1.01 Uses platform-independant file access FH v1.02 Updated ProgEnv library for BB4Wv6+Brandy, added TZX support P< v1.15 Spectrum filename cleaned, Print files supported Z: d! :Close_All::exit(): n)A$=OS_GetEnv+" ":os%>31:Win_TextIO xZseclen%=543: ctrl% 31,name% 80,mem% seclen%-1,type$(4):X%=ctrl%:Y%=X%256:wr%=2:rd%=4 Xtype$(0)="Print":type$(1)="Basic":type$(2)="Num ":type$(3)="Char ":type$(4)="Bytes" A$=" ": "Source tapefile: "in$: "Destination microdrive file: "out$: "Microdrive cartridge title: "title$:A$=in$+" "+out$+" "+title$+" " SpTitle$=cl("-t",1) 7 CmdLine bugfix requires space before final option A$=A$+" ":vb%=cl("-v",0) Ain$=cl("",0):out$=cl("",0): SpTitle$="":SpTitle$=cl("",0) [in$="-?" (in$<>"" out$=""):"Usage: TAPtoMDR () -v":exit(0): �in$=""out$="":exit(0): �: �Din%=f_openin(in$):in%=0:"File '"in$"' not found":exit(214): �(f_gbpb(rd%,in%,mem%,10,0):mem%?7=13 �8tap%=(($mem%="ZXTape!"4))(((!mem%&FFFFFF)=&11)1) �(tap%4)=0:#in%=0  b0: 0=TAP, 1=SpecTape  b2: TZX file : "Yout%=f_openout(out$):out%=0:"Couldn't open file '"out$"'":#in%:in%=0:exit(192): ,Gos%<8:A%=file(out$,5):X%?5=&FF:X%?4=&FF:X%?3=&FD:A%=file(out$,1) 6ok%=: ok%= @6os%<8:ok%:"SetType "+out$+" 054":"Stamp "+out$ J: T! :Close_All::exit(): ^-vb%: "Filename Type Len Start Extr"; h sect%=255 r |((tap%4):#in%=&10:A%=#in%+#in% 1len%=(#in%+256*#in%)+(tap%1)-1:flag%=#in% 7flag%=&00:RdHeader flag%=&FF:RdData RdSkip  #in% 4FillToEnd:#out%,0:vb%:: Not write protected (#out%:out%=0:#in%:in%=0:exit(0): : RdSkip:#in%=#in%+len%: : RdHeader 3len%>32:RdSkip: : Header is too long 9f_gbpb(rd%,in%,mem%,len%,0) : Read header block SpType% =mem%?0 SpLen% =mem%!11 &FFFF SpStart%=mem%!13 &FFFF SpExtra%=mem%!15 &FFFF  mem%?11=13:SpName$=$(mem%+1) &=(SpStart%SpExtra%&FFFF)=&FFFF:SpType%=-1 : Print file 0 vb%: :X'fn_clean(SpName$);" ";: SpType%<4: type$(SpType%+1); " &"h0(SpType%,2)" "; D:" "h0(SpLen%,4)" "h0(SpStart%,4)" "h0(SpExtra%,4); N X: b RdData llen%=len%-1 vSpLen% =len% SpLine%=SpStart% &(SpStart%SpExtra%)=-1:SpType%=-1 +SpType%=0:SpLine% =SpStart%:SpStart%=0 USpType%=1:SpStart%=SpExtra%:SpExtra%=(SpLine%256)+256*(SpLine%255): Bigendian USpType%=2:SpStart%=SpExtra%:SpExtra%=(SpLine%256)+256*(SpLine%255): Bigendian :  Do first block: off%=9: SpType%=-1:off%=0 ;sect%=sect%-1:rec%=0:num%=512-off%:len%<num%:num%=len%  chkfull: SecHeader -mem%!17=num%+9 : Block size *$(mem%+19)=pad(SpName$,10): Filename 8mem%?29=sum(15,28) : Checksum next 14 bytes  mem%?30=SpType% mem%!31=SpLen%  mem%!33=SpStart% *mem%!35=SpExtra% 4mem%!37=SpLine% >9f_gbpb(4,in%,mem%+30+off%,num%,0): Read first block H;mem%?542=sum(30,541) : Checksum of data R:f_gbpb(2,out%,mem%,543,0) : Write first block \len%=len%-num% f! len%<1:(tap%1)=0:A%=#in% p3 len%<1: : Only one block z:  Do following blocks:  <sect%=sect%-1:rec%=rec%+1:num%=512: len%<num%:num%=len%  chkfull: SecHeader 4mem%!17=num% : Block size 1$(mem%+19)=pad(SpName$,10) : Filename ?mem%?29=sum(15,28) : Checksum next 14 bytes 3f_gbpb(4,in%,mem%+30,num%,0) : Read a block 9mem%?542=sum(30,541) : Checksum of data 8f_gbpb(2,out%,mem%,543,0) : Write first block len%=len%-num% ! len%<1:(tap%1)=0:A%=#in%  : )SecClear: A%=0 542:mem%?A%=0:: $: .SecHeader 8 SecClear B4mem%?0=1 : Header block L5mem%?1=sect% : Sector number V5$(mem%+4)=pad(SpTitle$,10) : Cartridge name `>mem%?14=sum(0,13) : Checksum first 14 bytes j9mem%?15=(SpType%<>-1) 4 : Data or Print block t/ num%=len%:mem%?15=mem%?15 2: EOF block ~mem%?16=rec%  : FillToEnd ) sect%<1: : Microdrive full #SpType%=-1:rec%=0:num%=0:len%=0 :sect%=sect%-1 &SecHeader:mem%?15=0 : Free block f_gbpb(2,out%,mem%,543,0)  sect%<2: :  ݤchkfull / sect%<1:'"Microdrive full":#in%=#in:= �=  : ݤsum(st%,en%): chk% H A%=st% en%:chk%=chk%+mem%?A%:chk%<256:chk%=chk%+1 chk%=chk%+2 (&chk%=chk%&FF:chk%<>0:chk%=chk%-1 2 :=chk% <: F-ݤpad(A$,L%):A$=A$,L%):=A$+L%- A$," ") P: Zݤfn_clean(A$): A$="":="" dL A%=1 A$: A$,A%,1)<" " A$,A%,1)>"~":A$=A$,A%-1)+"_"+A$,A%+1) n :=A$ x: #ݤh0(A%,N%)="0000000"+~A%,N%) : Close_All:*EXEC "in%=in%:in%:A%=in%:in%=0:#A% 'out%=out%:out%:A%=out%:out%=0:#A%  : Lݤfile(A$,A%):<&FFFFF:$name%=A$:?X%=name%:X%?1=name%256:=(&FFDD)&FF =0 : !ݤf_openin(A$)=(f_name(A$)) "ݤf_openout(A$)=(f_name(A$)) !ݤf_openup(A$)=(f_name(A$)) Vݤf_name(A$):os%>31:A%,B%:B%=A%:A%=A$,"\",A%+1):A%=0:A$,".",B%)=0:A$=A$+"." =A$ : "%f_gbpb(A%,chn%,addr%,num%,ptr%) ,??X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:<&FFFFF: &FFD1: 6A%=1A%=3:#?X%=X%!9 @5:A%=1A%=2:#?X%,?X%!1 A%=3A%=4:?X%!1=#?X% J5X%!1=X%!1+1:X%!5=X%!5-1:(#?X% A%>2) X%!5<1: T: ^cݤcl(l$,n%):l$="":A$=s(A$):A$=34:A%=A$+" "" ",""" ",2):l$=A$,2,A%-2):A$=s(A$,A%+1)):=l$ h<l$="":A%=A$+" "," "):l$=A$,A%-1):A$=s(A$,A%+1)):=l$ rKn%=0:l$<>"":A%=A$,l$):A%:A$=s(A$,A%-1)+A$,A$," ",A%)+1))+" ":= |n%=0:l$<>"":= %A%=" ",l$=32)+A$,l$):A%=0:="" 'A$=A$,A%-1)+s(A$,A$," ",A%)+1)) Cl$=32:l$=A$,A%):A$=A$,A%-1):=l$,1-(l$=34),l$+2*(l$=34)) PA$,A%,1)<>34:l$=A$,A%,A$+" "," ",A%)-A%):A$=A$,A%-1)+A$,A%+l$+1):=l$ Jl$=A$,A%+1,A$+""" ",""" ",A%+1)-A%-1):A$=A$,A%-1)+A$,A%+l$+3):=l$ /ݤs(A$):A$,1)=" ":A$=A$,2):A$,1)<>" " +A$,1)=" ":A$=A$,A$-1):A$,1)<>" " =A$ : BݤOS_GetEnv:A%,X%,Y%,P%,A$:X%=1:os%=((&FFF4)&FF00)256:X% d!=&D7C1C7C5:run$=ARGV$(0):ARGC:A%=1ARGC:A$=A$+ARGV$(A%)+" "::=A$,A$-1)!=&D7C1C7C5:="" _>&FFFFF:X%256:A$=@cmd$:ș"GetModuleFileName",0,X%,255:run$=$$X%:Y%=@lib$,@tmp$)=0:P%= P%=0:>&FFFF:run$=$&8100:ș"OS_GetEnv"A$,,A%:ș"OS_WriteEnv","",A%:A$=A$,1+A$+" "," ",1+A$," "))):P%=:Y%=:A$," ")=0:A$=run$+" " P%=0:P%=X%:[OPT 0:NOP:]:P%=?X%:Y%=:P%=&EAP%=18:A$=$&600 P%=0:A$=$(-&300)P%=&A0:A$=$(^@%-256):Y%=?(-2)64P%=&90:A$=$&100:Y%=!&200 KA$=" "+A$:A$=A$,2):A$<>32:A$=34:A%=A$,"""",2)+1A%=A$+" "," ") (Y%:run$=A$,A%-1):A$=A$,A%+1):Y%=0 &A$<>32:=A$ 0: :&os(A$):A$=42:A$ A$<>"":A$ D N: XFexit(A%):"FX1,"+(A%255):quit$=quit$:A$=quit$:quit$="":os(A$) b>&FFFFF:Ș A% l v: Win_TextIO 0ș "GetStdHandle",-10 @hfile%(1):*INPUT 13 1ș "GetStdHandle",-11 @hfile%(2):*OUTPUT 14 &ș "SetConsoleMode",@hfile%(1),0: :