The following two programs are not documented in your Configuration Manual, but
are being supplied to you because they may nevertheless be useful to you.

Currently, about the cheapest way to burn EPROMs for HUMBUG or for a system 
boot ROM is by using one of the inexpensive programmers which fits into a PC 
or PC clone. Many of these programmers, however, are supplied with software 
which can only read a pure binary file. Most 68000 crossassemblers, on the 
other hand, do not output such a file. If your assembler comes with a convert
program, then you may consider yourself lucky and use that.

If such a program did not come with the programmer, then it is necessary to 
write a conversion program which takes the output of the assembler, usually in 
Motorola Hex format, and converts it to the binary format. The two programs 
below do just that. They are written in Basic and so they are very slow - 
about 5 or 10 minutes per conversion - but they are better than nothing! 
Moreover, it is easy to customize a Basic program to your needs. 

The programs work well, and we have been using them for some months. But they 
have some limitations you may have to work around (or else make some changes 
to them):

   1. As written, they support only Motorola S2 hex file codes. A typical 
short S2 file might look as follows: 

S214FE80004EF900FE80424EF900FE80EE4EF900FE6E
.
.
S9

In this example:

  S2 tells a file segment is coming which has the following format:

  14 tells $14 bytes (shown as pairs of hex digits) follow

  FE8000 is a 3-byte load address where the bytes go into

  4EF9...00FE are sixteen ($10) bytes of actual data

  6E is the 1's complement of the checksum of all bytes from the 14 to the FE

  S9 signifies the end of the file

S1, S2, and S3 segments are all similar, except that S1 has a 2-byte load 
address, S2 has a 3-byte address, and S3 has a 4-byte load address. Since 
HUMBUG will normally sit at the top of the 16-megabyte space of a 68000 
system, it will usually require 3-byte addresses such as $FE8000, and hence 
use S2 codes.

    2. It is assumed that the very first S2 record of the file specifies the
very first byte of the EPROM. In other words, if the above sample record is 
the first in the file, then the very first byte (4E) in location FE8000 should 
go into byte 0000 of the ROM. Note that a pure binary file contains no 
addresses; hence these programs generate a pure sequence of bytes, in order 
starting with EPROM location 0000. 

    3. It is assumed that the file does not have any backward ORG statements.
In mathematical terms, it is assumed that the file addresses are monotonically 
increasing. Expressed another way, the binary file is generated in order, from 
beginning to end, and is an exact image of how the data in the ROM will be 
stored. Hence addresses or data cannot repeat themselves, and cannot go 
backward - every byte of data must go into a location larger than the previous 
byte of data.

   4. The file may have holes in it (for example, an empty byte left in the
file to force alignment on an even address), but such a hole will be filled 
with random data. 

The programs are slightly different. The first program generates a single 
output file for a 68008 processor, which has a single 8-bit bus and therefore 
has all bytes in the same EPROM. The second program generates two output 
files for a 68000 or 68010 processor. These have a 16-bit bus and therefore 
require two 8-bit EPROMs, one with all the odd-address bytes and the other 
with all the even-address bytes.

The programs ask for an input and output file name, which should be specified 
in their entirety (including path and extension, if any). The output file name 
of program 2 will have appended to it a 0 for the even-byte (high order byte) 
file, and a 1 for the odd-byte (low order byte) file, so make sure to leave 
room for an extra character in the file name. We have not written a 68020 
version to generate four files for a 32-bit bus, but it is an easy extension 
to make once you see the difference in these two programs.

These Basic programs are combined in this text file; you will have to use an 
editor to split them off into separate files if you wish to use them. 


         PROGRAM 1 FOR THE 68008. GENERATES A SINGLE OUTPUT FILE


1 REM THIS PROGRAM CONVERTS AN S2 FILE, AS OUTPUT BY A CROSS-ASSEMBLER
2 REM INTO A PURE BINARY FILE WHICH IS SUITABLE FOR AN EPROM PROGRAMMER.
10 INPUT "INPUT FILE NAME"; F$
20 INPUT "OUTPUT FILE NAME"; S$
30 OPEN F$ FOR INPUT AS 1
40 OPEN "R", 2, S$, 1
50 FIELD 2, 1 AS C$
60 SFLAG = 1                            'START PROCESSING FLAG
70 ADDRESS = 0
100 INPUT #1, A$
110 IF LEFT$(A$,2)<>"S2" THEN 100     'WAIT FOR AN S2 LINE
120 B$=MID$(A$,3,2) : GOSUB 9000        'LENGTH
130 LENGTH=B-4                          'NUMBER OF BYTES TO READ
140 B$=MID$(A$,7,2) : GOSUB 9000        'LEFT HALF OF ADDRESS
150 ADDRESS = B*256
160 B$=MID$(A$,9,2) : GOSUB 9000        'RIGHT HALF
170 ADDRESS = ADDRESS + B               'COMPLETE ADDRESS TO LOAD
180 IF SFLAG = 1 THEN BASE=ADDRESS : SFLAG=0
190 NXT = 11                            'POINTER TO NEXT BYTE IN S2 LINE
200 FOR I = 1 TO LENGTH
210 B$=MID$(A$,NXT,2) : GOSUB 9000      'NEXT BYTE
220 NXT = NXT + 2
230 N$=CHR$(B)                          'THE BYTE
235 LSET C$ = N$
240 PUT #2, ADDRESS-BASE+1              'WRITE INTO FILE
250 ADDRESS = ADDRESS + 1
260 NEXT I
270 GOTO 100
8999 REM SUBROUTINE TO CONVERT HEX BYTE IN B$ INTO DECIMAL IN B
9000 D1=ASC(LEFT$(B$,1))-48
9010 IF D1>9 THEN D1=D1-7
9020 D2=ASC(RIGHT$(B$,1))-48
9030 IF D2>9 THEN D2=D2-7
9040 B=D1*16 + D2
9050 RETURN


    PROGRAM 2 FOR THE 68000/10, GENERATES TWO OUTPUT FILES


1 REM THIS PROGRAM CONVERTS AN S2 FILE, AS OUTPUT BY A CROSS-ASSEMBLER
2 REM INTO TWO PURE BINARY FILES (ONE FOR A HIGH ROM AND ONE FOR A LOW ROM) 
3 REM WHICH ARE SUITABLE FOR AN EPROM PROGRAMMER.
10 INPUT "INPUT FILE NAME"; F$
20 INPUT "OUTPUT FILE NAME (<8 CHARS!)"; S$
30 OPEN F$ FOR INPUT AS 1
40 OPEN "R", 2, S$+"0", 1               'FOR HIGH ORDER BYTE
45 OPEN "R", 3, S$+"1", 1               '    LOW
50 FIELD 2, 1 AS C$                     '    HIGH
55 FIELD 3, 1 AS D$                     '    LOW
60 SFLAG = 1                            'START PROCESSING FLAG
70 ADDRESS = 0
100 INPUT #1, A$
110 IF LEFT$(A$,2)<>"S2" THEN 100       'WAIT FOR AN S2 LINE
120 B$=MID$(A$,3,2) : GOSUB 9000        'LENGTH
130 LENGTH=B-4                          'NUMBER OF BYTES TO READ
140 B$=MID$(A$,7,2) : GOSUB 9000        'LEFT HALF OF ADDRESS
150 ADDRESS = B*256
160 B$=MID$(A$,9,2) : GOSUB 9000        'RIGHT HALF
170 ADDRESS = ADDRESS + B               'COMPLETE ADDRESS TO LOAD
180 IF SFLAG = 1 THEN BASE=ADDRESS : SFLAG=0
190 NXT = 11                            'POINTER TO NEXT BYTE IN S2 LINE
200 FOR I = 1 TO LENGTH
210 B$=MID$(A$,NXT,2) : GOSUB 9000      'NEXT BYTE
220 NXT = NXT + 2
230 N$=CHR$(B)                          'THE BYTE
235 LSET C$ = N$                        'FOR HIGH ORDER BYTE
236 LSET D$ = N$                        'OR MAYBE LOW ORDER?
237 RADDR = ADDRESS-BASE                'ABSOLUTE ROM ADDRESS
238 IF INT(RADDR/2)*2=RADDR THEN 240 ELSE 245 'CHOOSE EVEN OR ODD
240 PUT #2, RADDR/2+1 : GOTO 250        'WRITE INTO EVEN/HIGH FILE
245 PUT #3, INT(RADDR/2)+1              '    OR ODD/LOW BYTE
250 ADDRESS = ADDRESS + 1
260 NEXT I
270 GOTO 100
8999 REM SUBROUTINE TO CONVERT HEX BYTE IN B$ INTO DECIMAL IN B
9000 D1=ASC(LEFT$(B$,1))-48
9010 IF D1>9 THEN D1=D1-7
9020 D2=ASC(RIGHT$(B$,1))-48
9030 IF D2>9 THEN D2=D2-7
9040 B=D1*16 + D2
9050 RETURN

