August 16, 2025

Sun 3 bootrom souce - trouble with loadice

There is nothing worse than software that does different things when you run it with the same input.

I am running loadice to load my prom image into the ROM emulator. I can get it to load an image once, but then it seems to refuse to do subsequent loads. This makes no sense and is totally wrong.

Make loadice use 57600 baud

Putting the crazy load issue aside for the moment, I decided to look into this baud rate limitation. As distributed the unix version of loadice is limited to 19200 baud, while the DOS version can use 57600. Why should this be?

At one time, 57600 was a "wierd" baud rate and was not even supported on unix systems. This has now changed. I am working with the 4.0b sources from the Promice CD. The changes are more or less trivial to add this to the supported rate for my linux build. And it works!

I had expected to have to figure out some command to send to the promice to tell it to change baud rate, but it doesn't work that way. The promice detects the baud rate. Existing code in loadice sends a "auto-baud" character in a loop, watching until it gets one back. The auto-baud character is 0x03.

For a 64K binary image, this reduces the download time from 30 seconds to about 10 seconds, which is very nice.

Make load work in a predictable way

I begin adding printf() statements to pisynf.c to learn just what is going on. I add these to the function piload(). A bit of experimentation reveals that it is executing a branch labeled "else load later". Well, well. I cannot imagine what logic is behind this, but I am at least on the right track.

Anger and betrayal

Why am I going through all of this. It is beginning to look like this is not a bug, but some brain-damaged aspect of how this software is designed. I am angry because using this software in an obvious way does not work and has cost me over half a day of my time.

It is hard to imagine a more common and simple use case. I have a binary image file "xyz.bin" and I want to load it into the emulator to run as a single 27512 EPROM. The simple, common, obvious case should "just work". Why doesn't it? We will find out, and very likely we will "fix" this software so simple obvious things work.

I am reminded of what is called "the principle of least surprise" in software design.

Bonus side notes

First is that a semicolon is a "comment character". Start lines with a semicolon to add comments to your loadrom.ini.

Second is that putting a "dot" in front of a command says "do it right now". Exactly what I wanted for the load command (why it should get delayed by default is beyond me).

Digging deeper into the program

I see that the "procrastination" about loading is designed to put it off until the entire loadice.ini file has been consumed.

I had put and "exit" command at the end of my loadice.ini, and that caused the software to exit and the procrastinated load never happened.

The reason I had put the exit at the end of the file is that it would always enter dialog mode, at which point I would need to type exit. I simply want to type "make load" and have my image downloaded and presented to my target.

(Note: now that I know about putting ". load" rather than "load" to get the sensible "do it now" behavior, I could just leave the exit at the end of the file).

Further investigation reveals that it enters dialog mode because I have a "begin" command in my loadrom.ini file. Without it, the loadice doesn't connect to the promice device and all subsequent commands fail.

Reading the documentation on the "begin" command says that without it, the "normal" mode of operation is to process the entire loadice.ini file, then connect to the promice device and do whatever has been set up.

Conclusion

After spending a few hours with the source code, I can only say that it is written in one of the strangest C coding styles I have yet to see.

Along with that, it uses the idiotic convention of putting newlines at the start of output lines rather than the ends!

The "trick" in all of this is understanding the sequence in which loadice processes things. There are 3 critical times:

I think this is stupid, pointless, and above all confusing. I had assumed that I could try out a sequence of commands using dialog mode, then preserve them in the loadice.ini file, but the fact that there is no connection while the loadice.ini file is processed botches that idea.

We now know how to force the issue, as needed.

I can now use the following file with success. Note the dump, status, and config commands that I added during troubleshooting and will eventually eliminate.

; It seems that this is the comment character
output=/dev/ttyUSB1
baud=57600
; begin - this asks for dialog mode, but we exit
begin
word 8 0
rom 27512
stop
dump 0 1f
; image bootrom.bin
image sun3160.bin
; Putting the "dot" says "Do it now!!"
. load
status
dump 0 1f
go
status
config
exit

Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org