10
20
30
40
50
60 :
70 INPUT"Data file: "in$
80 INPUT"Output file: "out$
90 PRINT"Spool or Basic file? (S/B) ";:f%=FNget("SB")
100 INPUT"Start line number: "ln%:IFln%=0:ln%=10
110 DIM ctrl% 31,name% 255:X%=ctrl%:Y%=X%DIV256
120 in%=0:out%=0:ONERRORREPORT:PROCclose:PRINT:END
130 A%=FNfile(in$,5):ld%=X%!2:ex%=X%!6:sz%=X%!10:at%=X%!14:IFA%:in%=OPENIN(in$)
140 IFin%=0:PRINT"File '"in$"' not found":END
150 A$="SAVE "+out$+" 0+"+STR$~(sz%*3)+" FFFF0000 FFFFF":IFf%=66:A$=A$+"B00" ELSE A$=A$+"F00"
160 OSCLIA$:out%=OPENOUT(out$)
170 A$="REM > "+out$:PROCline:A$=":":PROCline
180 READA$:REPEATPROCline:READA$:UNTILA$="*"
190 A$="RESTORE "+STR$ln%:PROCline
200 A$="DATA "+in$+","+STR$~ld%+","+STR$~ex%+","+STR$~sz%+","+STR$~at%:PROCline
210 REPEATA$="":sum%=0:n%=16:REPEAT
220 b%=BGET#in%:sum%=sum%+b%:A$=A$+RIGHT$("0"+STR$~b%,2):n%=n%-1
230 UNTILn%=0 OR EOF#in%
240 A$="DATA "+A$+","+STR$~sum%:PRINT;ln%;" ";A$;" ";STRING$(LENA$,CHR$8);CHR$13;:PROCline
250 UNTILEOF#in%:PRINTSPC46;CHR$11:CLOSE#in%:in%=0
260 IFf%=66:BPUT#out%,13:BPUT#out%,255
270 CLOSE#out%:out%=0:END
280 :
290 DEFPROCline
300 IFf%=66:A$=FNTokenise_(A$):IFASCA$=&8B:A$=MID$(A$,5):
310 IFf%=66:A$=CHR$13+CHR$(ln%DIV256)+CHR$(ln%)+CHR$(4+LENA$)+A$ ELSE A$=RIGHT$(" "+STR$ln%,6)+" "+A$+CHR$13
320 $name%=A$:PROCgbpb(2,out%,name%,LENA$,0):ln%=ln%+10:ENDPROC
330 DEFFNget(A$):LOCAL A%:REPEATA%=GET AND&DF:UNTILINSTR(A$,CHR$A%)
340 PRINTSTRING$(2+2*LENA$,CHR$127);CHR$A%:=A%
350 DEFPROCclose:IFin%:A%=in%:in%=0:CLOSE#A%
360 IFout%:A%=out%:out%=0:CLOSE#A%
370 ENDPROC
380 DEFFNfile(A$,A%):$name%=A$:?X%=name%:X%?1=name%DIV256:=(USR&FFDD)AND&FF
390 DEFPROCgbpb(A%,chn%,addr%,num%,ptr%):?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:CALL &FFD1:ENDPROC
400 :
410 DATA "READfn$,ld$,ex$,len$,at$:len%=EVAL(""&""+len$)"
420 DATA "IFH.-TOP-2500<len%:P.""Not enough memory"":END"
430 DATA "DIMmem%len%:ptr%=mem%:REP."
440 DATA "READ A$,B$:sum%=0:ln%=ln%+10"
450 DATA "REP.?ptr%=EVAL(""&""+LEFT$(A$,2)):sum%=sum%+?ptr%"
460 DATA "ptr%=ptr%+1:A$=MID$(A$,3):U.LENA$<2"
470 DATA "IFsum%<>EVAL(""&""+B$):P.""Checksum error in DATA line "";ln%:END"
480 DATA "U.ptr%-mem%>=len%"
490 DATA "OS.""SAVE ""+fn$+"" ""+STR$~mem%+"" ""+STR$~ptr%+"" ""+ex$+"" ""+ld$"
500 DATA "END",":",*
510 :
520 DEFFNTokenise_(A$):IFPAGE<&8000:=FNTokenise_65(A$) ELSE =FNTokenise_ARM(A$)
530 DEFFNTokenise_65(A$):LOCAL A%,B%
540 A%=!4AND&FFFF:A%=A%-LENA$-1+4*(A%?-1>0)
550 B%=EVAL("0:"+A$):=$A%
560 DEFFNTokenise_ARM(A$):LOCAL A%,B%
570 SYS "XOS_GenerateError",0,STRING$(255,"*") TO ,A%
580 A%!-36=0:B%=EVAL("0:"+A$):=$(A%-14+4*(A%!-36<>0))