1 REM HEXBIN 1.1, DECEMBER 1984
2 REM -- BY DAN FLEYSHER --
3 REM (FLEYSHER.WBST@XEROX)
4 REM THIS BASIC PROGRAM CONVERTS A
5 REM HEXADECIMAL TEXT FILE CREATED
6 REM BY COMPANION PROGRAM BINHEX
7 REM BACK INTO ITS ORIGINAL BINARY
8 REM FILE FORMAT.  THE CHECKSUM AT
9 REM THE END OF THE INPUT HEX FILE
10 REM IS VERIFIED.
11 REM 
20 DIM FILEIN$(15),FILEOUT$(15)
30 BUFSIZ=37:DIM BUF$(BUFSIZ)
40 ASCA=ASC("A"):ASCF=ASC("F"):ASC0=ASC("0"):ASC9=ASC("9")
50 ? "}             HEXBIN 1.0":? :? 
60 TRAP 60:? "INPUT FILENAME";:INPUT FILEOUT$
70 IF FILEOUT$<>"" THEN 90
80 FILEOUT$="D:HEXFILE.TXT":? "                ";FILEOUT$:GOTO 100
90 GOSUB 1000
100 FILEIN$=FILEOUT$:? 
110 TRAP 110:? "OUTPUT FILENAME";:INPUT FILEOUT$:GOSUB 1000:? 
120 TRAP 40000:SUM=0
130 OPEN #4,4,0,FILEIN$:OPEN #5,8,0,FILEOUT$
140 TRAP 310:INPUT #4,BUF$:? BUF$:LBUF=LEN(BUF$):IF LBUF<7 THEN 140
142 FOR I=1 TO LBUF-6:IF BUF$(I,I+6)=".START." THEN 146
144 NEXT I:GOTO 140
146 POP :? "       STARTING FILE CONVERSION"
150 TRAP 310:INPUT #4,BUF$:? BUF$:LBUF=LEN(BUF$):EVENODD=0:REM EVEN=0
155 IF LBUF = 0 THEN 150
160 FOR I=1 TO LBUF
170 HEX1=ASC(BUF$(I,I))
180 IF HEX1>=ASC0 AND HEX1<=ASC9 THEN HEX1=HEX1-ASC0:GOTO 200
190 IF HEX1>=ASCA AND HEX1<=ASCF THEN HEX1=HEX1-ASCA+10:GOTO 200
192 IF LBUF<I+5 THEN GOTO 240
194 IF BUF$(I,I+5)=".STOP." THEN 260
196 GOTO 240
200 EVENODD= NOT EVENODD
210 IF EVENODD THEN BYTE=HEX1:GOTO 240
220 BYTE=(16*BYTE)+HEX1
230 SUM=SUM+BYTE:PUT #5,BYTE
240 NEXT I:IF EVENODD THEN ? "ERROR - MISSING 1 OR MORE NIBBLES"
250 GOTO 150
260 POP :TRAP 40000:IF SUM=VAL(BUF$(I+6)) THEN ? "CHECK SUM VERIFIED.":? :GOTO 330
270 ? "CHECK SUM ERROR:":GOTO 320
310 ? "PREMATURE END OF FILE - NO CHECK SUM:"
320 ? "  COMPUTED CHECK SUM = ";SUM
330 CLOSE #4:CLOSE #5
340 END 
1000 IF LEN(FILEOUT$)<3 THEN GOTO 1040
1010 IF FILEOUT$(1,2)="D:" THEN RETURN 
1020 IF LEN(FILEOUT$)<4 THEN GOTO 1040
1030 IF FILEOUT$(1,1)="D" AND FILEOUT$(3,3)=":" THEN RETURN 
1040 BUF$=FILEOUT$:FILEOUT$="D:":FILEOUT$(3)=BUF$:RETURN 
