10
20
30 :
40 INPUT"Input file: "in$
50 INPUT"Output file: "out$
60 in%=OPENIN(in$):IF in%=0:PRINT"Can't open '"in$"'":END
70 max%=HIMEM-LOMEM-256:DIM mem% max%-1:addr%=mem%
80 REPEAT
90 A$=FNuc(FNrd(in%))
100 A%=INSTR(A$,"DEFB")
110 IF A%=0:A%=INSTR(A$,"EQUB")
120 IF A%=0:A%=INSTR(A$,"BYTE")
130 IF A%=0:A%=INSTR(A$,"FCB")
140 IF A%=0:A%=INSTR(A$,"DB")
150 IF A%:A$=MID$(A$,A%):PROCbyte
160 UNTIL EOF#in% OR max%<1
170 IF NOT EOF#in%:PRINT"File truncated"
180 CLOSE#in%:in%=0
190 OSCLI "SAVE "+out$+" "+STR$~mem%+" "+STR$~addr%
200 END
210 :
220 DEFPROCbyte
230 A%=INSTR(A$," "):IF A%=0:A%=INSTR(A$,CHR$9):IF A%=0:ENDPROC
240 A$=MID$(A$,A%)+",":REPEAT
250 REPEAT:A$=MID$(A$,2):UNTIL LEFT$(A$,1)<>" ":n%=VAL A$
260 IF LEFT$(A$,2)="0X":n%=EVAL("&"+MID$(A$,3,2)):A$=MID$(A$,5)
270 IF LEFT$(A$,1)="%":n%=0:A$=MID$(A$,2):REPEAT:n%=n%*2+VALLEFT$(A$,1):A$=MID$(A$,2):UNTIL ((ASC LEFT$(A$,1)) AND -2)<>ASC"0"
280 ?addr%=n%:addr%=addr%+1
290 IF LEFT$(A$,1)=" ":REPEAT:A$=MID$(A$,2):UNTIL LEFT$(A$,1)<>" "
300 IF LEFT$(A$,1)=",":A$=MID$(A$,2)
310 UNTIL A$=""
320 ENDPROC
330 :
340 DEFFNrd(i%):LOCALA%,B%,A$:REPEAT:A%=BGET#i%:IFA%<>10ANDA%<>13:A$=A$+CHR$A%
350 UNTILA%=10ORA%=13OREOF#i%:IFNOTEOF#i%:B%=BGET#i%:IFA%=B%OR(B%<>13ANDB%<>10):PTR#i%=PTR#i%-1
360 =A$
370 DEFFNuc(A$):LOCAL B$:IFA$="":=""
380 REPEATB$=B$+CHR$(ASCA$AND((A$<"@")OR&DF)):A$=MID$(A$,2):UNTILA$="":=B$