Converting machine Language to BASIC strings

(machine language, binary, machine language subroutines, assembly
language subroutines all refer to machine language generated by an
assembler.)

BINSTNBH.BAS converts binary files to a BASIC listed file that can be
merged with a BASIC program.  BINSTNBH.BAS writes binary code as string
statements.  The string statements are DIMed.  A REM statement with the
file name of the binary source file is added.

Quotation marks (34, $22) and RETURN characters (155, $9B) are handled
as
STRING$(LEN(STRING$)+1)=CHR$(34)
or
STRING$(LEN(STRING$)+1)=CHR$(155)

34 and 155 cause problems with the BASIC Editor.  Other bytes can cause
strange looking displays when the lines are listed but cause no problems.
Never edit the lines in the BASIC Editor.  It can make your machine
language subroutines unuseable.

When BASIC looks for lines, it starts with the lowest numbered line and
searches for the line number.  So to speed up your programs, put lines
that are only executed once at the back of the program.  I suggest that
you tell BINSTNBH.BAS to number lines starting 31000 or higher and set
the line interval to 1.  When entered in your program, put a RETURN after
the routine and near the top of the program put a GOSUB to the routine.

BINSTNBH.BAS searches though the file for all the load segments.  The
first two bytes in an Atari DOS binary file are $FF,$FF.  The next four 
bytes are 2 bytes for the start address of the segment and 2 bytes for  
the end address.  Data follows.  What follows the data is either the End
Of the File or the start and end addresses of the next segment.  Binary
files can be all one segment, but more commonly, files are made up of 
multiple segments.  The MAC/65 assembler writes files of 252 byte
segments or less.

Running BINSTNBH.BAS

The first choice is to read from memory or disk.  Don't read from memory.
This is just a relic. I haven't used it in years.  I no longer remember
what is does.  I no longer know if it even works.  Choose D.

Now put in the starting line number and line interval seperated by a
comma.  I suggest 32000,1.

Enter the string variable name, such as: A$, ML$, etc.

Enter the output file

Enter the input file

The first thing you will see as the program runs is BINSTNBH.BAS looking
at all the segment addresses to determine the length of the binary code.
BINSTNBH.BAS will then going through the segments reading and assembling
the BASIC lines.  As the bytes are read they are echoed (sent) to the
screen.  All bytes that could possibly goof up the display are replaced
by $23 - the character #.

The program ends normally with something like this:

1 Quotation marks
1 Return characters
error - 136  EOF No Error

Error 136 is the End Of File error.  This is not an error in the normal
sense.

I replaced BINSTNBH.BAS with BINSTNBI.BAS.  BINSTNBI.BAS has slightly
better error trapping.


Download BINSTNBI.ZIP
9,543 bytes

Download BINSTNBI.EXE
25,313 bytes

Back