10 REM create program text from INTEL HEX, for basic inclusion as DATA
11 REM output is a DO file
12 REM input is an Intel HEX file, 1 byte per data
13 REM by S. Adolph
20 v$="0123456789ABCDEF"
70 CLS
71 PRINT"Create a loadable .DO from Intel HEX"
80 PRINT"Source Intel HEX file name: ";:INPUT FN$
81 S$ = FN$ + ".HEX": print"input from: ";S$:OPEN S$ FOR INPUT AS 1
82 d$ = FN$ + ".DO": PRINT"Output to: ";d$:OPEN D$ FOR OUTPUT AS 2
84 e=20: print"Starting line #: ";e: e0=e

85 restore 200
86 for i = 1 to 9: read p$: print #2,p$:print p$: next i

90 rem get line of data
91 a$=input$(1,1): if a$ <> ":" then goto 91: rem advance to start of line
92 a$="":a1$=input$(1,1):a2$=input$(1,1):x = 16*(instr(v$,a1$) -1) + instr(v$,a2$) -1:rem get # of bytes in line
93 k=0:for i =3 to 0 step -1:k= k + (16^i)*(instr(v$,input$(1,1)) -1) :next i: REM calculate address
94 if e=e0 then a$=chr$(10)+str$(e)+" DATA "+str$(k):print #2,a$;: print a$;:e=e+1: REM print address line if first line
95 for i=1 to 2:a$=input$(1,1):next i:rem ignore these 2 bytes


100 a$=chr$(10)+str$(e)+" DATA "+chr$(34):print #2,a$;: print a$;
102 if x=0 then a$="/E"+chr$(34):print #2,a$;: print a$;:close #1:close #2:end
107 for i=1 to x: rem loop x times
110 a1$=INPUT$(1,1):a2$=INPUT$(1,1): rem get data bytes
115 k = 16*(instr(v$,a1$) -1) + instr(v$,a2$) -1
120 if k = 34 or k = 47 or k=127 or k <= 32 then a$="/"+chr$(k+128) else a$=chr$(k)
125 print #2,a$;: print a$;
130 next i
135 a$=chr$(34): print #2,a$;: print a$;
140 e=e+1:GOTO 90


200 data "1 cls:readq1:q=q1:printq:ifq<himemthenend"
201 data "2 RESTORE21:GOSUB13"
203 data "5 a$=inkey$+chr$(1):on 2+(asc(a$)=1) goto 5,7"
205 data "7 callq1:END"
206 data "13 READP$:printchr$(46);:e=0:FORX=1TOLEN(P$):a$=MID$(P$,X,1)"
207 data "14 if asc(a$)=47 then e=1:goto 17"
208 data "15 if e=1 and asc(a$)= 69 then print:printq-1:return"
209 data "16 POKEQ,asc(a$)+128*(e=1):Q=Q+1:e=0"
210 data "17 NEXTx:GOTO13"