BASIC SmartWriter File Viewer

I’m happy to announce that this weekend I was able to complete and release my SmartWriter File Viewer BASIC program.

This has been a really fun project and the end result is a utility that I will personally get a lot of use from. One of the main reasons this project was so fun was that it involved disassembling SmartBASIC’s BLOAD routine and modifying it to do what I needed. I haven’t had much experience with assembly language so this gave me a chance to dig in and learn. I used the disassembler included with the legendary Hacker’s Guide To The ADAM. The Hacker’s Guide Volume 2 was also incredibly helpful as a reference for this project. Without its section on Tape Routines I don’t think I would’ve been able to do this at all. Huge shout-out to Peter and Ben Hinkle for writing these awesome guides back in 1985/86. The other book I used as a reference was “Programming the Z80” by Rodney Zaks which I’m sure I’ll be returning to again and again.

As I mentioned in a previous post the main thing I needed to do was get the BLOAD routine to accept SmartWriter files. After reading through the assembly code I found what I was looking for here at 21083:

21083 525B  3A9641  LD   A,(nn)    4196
21086 525E  FE02    CP   n
21088 5260  C2255F  JP   NZ,nn    5F25

Just before these instructions the routine loads the file header into memory location $4194. So the first line above is looking at the 3rd byte of the header (the file type) and the second line is comparing it to the value 02. If it doesn’t equal 2, the third line jumps to an error display routine (File Type Mismatch). In ADAM’s EOS, binary files have a file type of 2 whereas SmartWriter files have a file type of 1. Therefore all I had to do was modify memory location 21087 to contain the value of 1 like this:

POKE 21087, 1

Eureka! That was enough to get BLOAD to accept SmartWriter files. As a bonus, the routine would now neatly reject other binary files that would obviously be incompatible with my viewer program. Once I had this in place I started to figure out more of the routine and how it worked. There are some other modifications I had to make before I was done but this one was definitely the key. You can check out the rest of the changes and the entire code if you’d like by downloading the disk image over at the ADAM Archive.