jhs@MITRE-BEDFORD.ARPA (01/12/87)
Recently Turbo BASIC was distributed in BINHEX format. The program HEXBIN, listed below, will convert the distributed version back into binary so it can be run using the DOS "L" command. BINHEX and the documentation for both is included for completeness; all of this is being posted per the request of Dan Fleysher, the author of BINHEX and HEXBIN. NOTE: BINHEX and HEXBIN are V E R Y slow, as they are written in Atari BASIC. Plan on 10 to 15 minutes of CPU time to decode Turbo BASIC. But believe me, it is worth it. -John Sangster jhs@mitre-bedford.arpa ============================================================================== From: Dan Fleysher <Fleysher.wbst@Xerox.COM> The precise definition of BINHEX output. ----------------------------------- The following is the a collection of background messages on BINHEX/HEXBIN: BINHEX and HEXBIN are BASIC programs written for the Atari 400/800 and XL (8-bit) machines, so they are excruciatingly slow. You really have to want to send a binary file to someone if you are going to use them! I never took the time to speed things up with machine language assist - anyone who wants to do so is welcome to it. (Please share your improvements with the rest of us, however). The attachments below contain background on how BINHEX and HEXBIN work. The two messages which follow this one contain the Atari-BASIC source code for the two utilities respectively. I trust you have download capability, so that you do not have to re-type the source code into your Atari. The most successful use of BINHEX and HEXBIN was for distributing the VT100 80 column terminal emulator and a VT52 over the last couple of years. Little more has been done since then. My apologies to everyone who has seen this stuff before - just toss it out as you see fit. Dan ---------------------------------------------------------------- Subject: HELP for the Tired Typer In-reply-to: <KPETERSEN.12051730238.BABYL@SIMTEL20> From: Dan Fleysher <Fleysher.wbst@xerox.com> Exchanging home-brew BASIC programs within messages over the net requires a modem and a good upload terminal emulator program (such as ATERM, distributed on the net in Oct. '82). Even with this set up, plenty of information can get lost in the transmission - e.g., inverse-video and graphics characters. Sometimes these are crucial when the BASIC program contains machine language assist in the form of text strings (rather than data statements). I have written a pair of companion BASIC programs which enable the exchange of arbitrary files over the net with no loss of data. This is accomplished by converting the file to be sent into a text file containing hexadecimal characters, two for each byte of the original file. One of the programs does the conversion to hexadecimal format, and the other converts the received hex file back into its Atari-useable form. Before I publish these two programs, I would like to invite agreement/disagreement on a standard format for exchange. The format I propose is: -------------------- message header, explanatory text, and general comments .START. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxx .STOP.nnnnn optional extra text -------------------- The translator for the received program ignores all text until it encounters the record ".START." Subsequent records contain hexadecimal characters (x's, above) in convenient (although unspecified) record lengths. The receiving program translates the hex characters into bytes until it encounters the .STOP. record. The number that follows ".STOP." is a decimal checksum, computed by adding up all the preceding bytes encoded as hex characters. (The checksum limit of 10 digits corresponds to a file length of more than 78 megabytes of average data) My programs use record lengths of 36 hex characters so that they fit easily on the 40 character screen. Although the programs are written in Atari BASIC, there is no reason they could not be re-implemented as machine language programs (for speed). These could also be distributed to the net using this facility. Needless to say, this facility is proposed for exchanging PERSONAL or public-domain software only. Opinions anyone? Dan ----------------------------------- Subject: Exchanging Binary Files over the net From: Dan Fleysher <Fleysher.wbst@xerox.com> Last month I proposed a standard for exchanging binary files over the net in text messages by first converting them to hexadecimal. That message is attached. I received an excellent suggestion from ken@ROCHESTER to add checksums to the end of each line, rather than just the end of the document, in order to enable easier recovery. Unfortunately I haven't had the time to incorporate this change, but my experience has been that if I receive a message at all, I get it without errors 99.999% of the time. I also received suggestions to look at KERMIT protocol, but I already have an reliable underlying transmission protocol - the message system. Consequently, I am distributing two BASIC programs - BINHEX & HEXBIN - that can be downloaded and used to encode and decode binary files to/from hex (text) format. Someday, I'll convert them to machine language and redistribute them (I apologize for the performance of the BASIC versions). In the meanwhile, if anybody uses them and finds bugs or has suggestions, I would appreciate hearing about your experiences. Dan ------------------------------------------------------------------------------ BASIC .LST files for BINHEX and HEXBIN (use "ENTER" to load them): ------------------c-u-t---h-e-r-e---f-o-r---B-I-N-H-E-X-.-L-S-T--------------- 1 REM BINHEX 1.0, OCTOBER 1984 2 REM -- BY DAN FLEYSHER -- 3 REM (FLEYSHER.WBST@XEROX) 4 REM THIS BASIC PROGRAM CONVERTS A 5 REM BINARY DISK FILE TO THE EQUIV- 6 REM VALENT TEXT FILE CONTAINING 7 REM HEXIDECIMAL CHARACTERS. THIS 8 REM FILE IS SUITABLE FOR LONG 9 REM DISTANCE (MODEM) TRANSMISSION, 10 REM AND CONTAINS A FULL CHECKSUM. 11 REM A COMPANION PROGRAM, HEXBIN, 12 REM CONVERTS THE HEX FILE BACK TO 13 REM THE ORIGINAL BINARY FORMAT. 14 REM 20 DIM FILEIN$(15),FILEOUT$(15),BYTE$(2) 30 BUFSIZ=37:DIM BUF$(BUFSIZ),HEX$(16) 40 HEX$="0123456789ABCDEF" 50 ? "} BINHEX 1.0":? :? 60 TRAP 60:? "INPUT FILENAME";:INPUT FILEOUT$ 70 GOSUB 1000:FILEIN$=FILEOUT$:? 80 TRAP 80:? "OUTPUT FILENAME";:INPUT FILEOUT$ 90 IF FILEOUT$<>"" THEN 110 100 FILEOUT$="D:HEXFILE.TXT":? " ";FILEOUT$:GOTO 120 110 GOSUB 1000:? 120 TRAP 40000:SUM=0 130 OPEN #4,4,0,FILEIN$:OPEN #5,8,0,FILEOUT$ 140 PRINT #5:PRINT #5;".START." 150 BUF$="" 160 TRAP 300:FOR I=1 TO INT(BUFSIZ/2) 170 GET #4,BYTE:SUM=SUM+BYTE 180 NIBBLE=INT(BYTE/16) 190 INDEX=1+NIBBLE 200 BYTE$(1)=HEX$(INDEX,INDEX) 210 INDEX=1+BYTE-(16*NIBBLE) 220 BYTE$(2)=HEX$(INDEX,INDEX) 230 BUF$(LEN(BUF$)+1)=BYTE$ 240 NEXT I:TRAP 40000 250 ? BUF$:PRINT #5;BUF$:GOTO 150 300 ? BUF$:PRINT #5;BUF$:POP 310 ? "CHECK SUM = ";SUM 320 PRINT #5;".STOP.";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 ------------------c-u-t---h-e-r-e---f-o-r---H-E-X-B-I-N-.-L-S-T-------------- 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 ---------------------------end of HEXBIN--------------------------------------