Loading hex and bin files

General discussions related to the Altair 8800 Clone

Loading hex and bin files

Postby kwiebe » March 19th, 2019, 9:46 pm

I successfully loaded a hex file front panel program. Got that down.

In figuring that out, I also read the description in the Config Monitor doc regarding binary files. So for bin files a load address is needed. Can someone give an example of what loading bin files would be used for, vs. hex? And I assume all hex files go into address 0?

I just need a better understanding of the bin vs. hex file dynamic.
-Ken
kwiebe
 
Posts: 52
Joined: February 9th, 2019, 1:11 pm

Re: Loading hex and bin files

Postby TomXP411 » March 20th, 2019, 2:09 am

BIN files are just "BINary" data. The file just contains a byte stream of the data. Since there's no provision in a BIN file for any control data, you need to specify a starting address when loading a BIN.
Note that COM files are identical to BIN files, but they always start at 0100h. So if you assemble your BIN files to 0100h, your programs can be run from CP/M.

On the other hand, Hex files have the address built in to the file format, and every line in the file allows you to set a new address. Hex files are plain ASCII files, with the data encoded in hex format.

So a hex file could, for example, load code at 100h-400h, then load a bunch of data at 2000h.

Here's a line from a hex file:
:10010000214601360121470136007EFE09D2190140

Hex file lines always start with a :
10 is the record size (16 bytes)
0100 is the address of this line of data.
00 is the record type (00=data, 01=end of file)
the next 32 characters are the data in hex (16 bytes worth)
the 40 at the end is a checksum of all the bytes on the line. (Add the values and get the two's complement.)

The Wikipedia page is actually pretty good, and I've written both hex encoders and loaders from this description:
https://en.wikipedia.org/wiki/Intel_HEX
TomXP411
 
Posts: 42
Joined: March 8th, 2018, 4:13 pm

Re: Loading hex and bin files

Postby kwiebe » April 2nd, 2019, 6:54 pm

TomXP411 wrote:BIN files are just "BINary" data. The file just contains a byte stream of the data. Since there's no provision in a BIN file for any control data, you need to specify a starting address when loading a BIN.
Note that COM files are identical to BIN files, but they always start at 0100h. So if you assemble your BIN files to 0100h, your programs can be run from CP/M.

On the other hand, Hex files have the address built in to the file format, and every line in the file allows you to set a new address. Hex files are plain ASCII files, with the data encoded in hex format.

So a hex file could, for example, load code at 100h-400h, then load a bunch of data at 2000h.

Here's a line from a hex file:
:10010000214601360121470136007EFE09D2190140

Hex file lines always start with a :
10 is the record size (16 bytes)
0100 is the address of this line of data.
00 is the record type (00=data, 01=end of file)
the next 32 characters are the data in hex (16 bytes worth)
the 40 at the end is a checksum of all the bytes on the line. (Add the values and get the two's complement.)

The Wikipedia page is actually pretty good, and I've written both hex encoders and loaders from this description:
https://en.wikipedia.org/wiki/Intel_HEX


Good info, thanks! So, this got me wondering:

Let's say I have run across a program in hex format that says it's for the 8080. It starts out like this:

0000: 31 82 0D CD AC 09 21 6D 0B CD DA 01 21 93 0B CD
0010: DA 01 21 B9 0B CD DA 01 CD AC 09 CD AF 05 21 95
0020: 0A 22 7D 0A 21 CB 0A 22 7F 0A 21 01 0B 22 79 0A
0030: 21 37 0B 22 7B 0A AF 32 74 0A 32 78 0A 32 82 0A
...

I can massage the lines to match the template you provided:

:10010000214601360121470136007EFE09D2190140

If I load this into the Altair, will it run?

Besides the statement saying it's for the 8080, are there any other considerations?
-Ken
kwiebe
 
Posts: 52
Joined: February 9th, 2019, 1:11 pm

Re: Loading hex and bin files

Postby toml_12953 » April 2nd, 2019, 8:23 pm

kwiebe wrote:Good info, thanks! So, this got me wondering:

Let's say I have run across a program in hex format that says it's for the 8080. It starts out like this:

0000: 31 82 0D CD AC 09 21 6D 0B CD DA 01 21 93 0B CD
0010: DA 01 21 B9 0B CD DA 01 CD AC 09 CD AF 05 21 95
0020: 0A 22 7D 0A 21 CB 0A 22 7F 0A 21 01 0B 22 79 0A
0030: 21 37 0B 22 7B 0A AF 32 74 0A 32 78 0A 32 82 0A
...

I can massage the lines to match the template you provided:

:10010000214601360121470136007EFE09D2190140

If I load this into the Altair, will it run?

Besides the statement saying it's for the 8080, are there any other considerations?


It may or may not run. If it depends on certain peripherals (such as serial I/O) being at certain addresses, and
those addresses are different than yours, it won't run. Likewise disk access instructions (if any) would have
to match the locations and protocols of your floppy controller. Also if the original program called ROM routines
that were present in the ROM of the original system, you'd have to have a compatible ROM in your system or
load a compatible monitor at the same addresses. The chances of taking a machine language routine written
for an unknown computer and having it run without change on your system are small.
toml_12953
 
Posts: 297
Joined: June 7th, 2013, 12:54 pm

Re: Loading hex and bin files

Postby TomXP411 » April 3rd, 2019, 1:20 am

Besides the statement saying it's for the 8080, are there any other considerations?


Yes.... the CPU is only part of the computer. You have the display, input devices, storage devices, and potentially the operating system.

An 8080 program can be made to work, but you have to know specifically what hardware it was made for, so if nothing else, you can convert the I/O routines to the Altair.

I wouldn't even bother trying to convert a binary program in the way you describe. You should be looking at source code: preferably a commented assembly file.
TomXP411
 
Posts: 42
Joined: March 8th, 2018, 4:13 pm

Re: Loading hex and bin files

Postby kwiebe » April 4th, 2019, 10:23 am

I kinda figured someone would say that. But this at least helps me further understand all the variables.

My knowledge of source, assembly, machine, etc. code is from textbooks. I know the basic concepts, but I trained as a high-level language programmer so I was insulated. So I'm looking forward to getting more practical experience (in the hobbyist sense) with the lower-level code and how to work with it.
-Ken
kwiebe
 
Posts: 52
Joined: February 9th, 2019, 1:11 pm

Re: Loading hex and bin files

Postby kwiebe » April 7th, 2019, 4:36 pm

Can anyone suggest a book or two which would be helpful for me to bridge the gap in my knowledge of Altair machine/assembly programming?

I do see the manual on the clone site but was hoping for something which might flatten the learning curve, first.
-Ken
kwiebe
 
Posts: 52
Joined: February 9th, 2019, 1:11 pm

Re: Loading hex and bin files

Postby mail@gabrielegan.com » April 14th, 2019, 6:49 am

I found that this book told me everything I needed to know, having started with no knowledge of 8080 assembly language programming:

https://www.tramm.li/i8080/Intel%208080 ... 0Intel.pdf

Regards

Gabriel Egan
mail@gabrielegan.com
 
Posts: 104
Joined: October 11th, 2014, 8:12 am

Re: Loading hex and bin files

Postby toml_12953 » April 14th, 2019, 10:05 pm

mail@gabrielegan.com wrote:I found that this book told me everything I needed to know, having started with no knowledge of 8080 assembly language programming:

https://www.tramm.li/i8080/Intel%208080 ... 0Intel.pdf

Regards

Gabriel Egan


Thanks for the link! I have a paper copy but the PDF is certainly welcome. I made it searchable to it's easier to use than the paper copy.

Tom L
toml_12953
 
Posts: 297
Joined: June 7th, 2013, 12:54 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 18 guests

cron