Recalling an old book about the TRS-80 ROM contents

Around 1980, there was a paperback book that contained a commented disassembly of the TRS-80’s ROM BASIC - I can’t remember if it was the 4k ROM BASIC or the improved 12k ROM. Does anyone else remember this book? Does anyone have the book?

I remember specifically that there was a subroutine or function entry point that had the machine instruction for moving the immediate value 0xAF to the Z-80’s accumulator. If you jumped to the instruction, the function was entered with the nonzero value 0xAF in A. If you jumped to the immediate value–the “middle” of the instruction–it was the opcode for XOR A, A which cleared the accumulator. It was a way of passing a zero/nonzero flag. Either Bill Gates or Paul Allen probably wrote this code. I’ve always wondered which one.

I guess it was volume 1 of Tandy/Radio Shack Book:: Disassembled Handbook for TRS-80 - Volume 2 (1980)(Richcraft Engineering Ltd) : Free Download, Borrow, and Streaming : Internet Archive

I found one that handles TRON and TROFF. The TRON entry point is at $1DF7 and does:

  LD  A,$AF
  LD  ($411B),A
  RET

TROFF enters at $1DF8 and does:

  XOR A
  LD  ($411B),A
  RET

They just need to set or clear a byte flag controlling output of program trace information.

There are lots of other similar instances where CP or LD L,N or, most commonly, LD BC,nn opcodes are used to “skip” over other instructions.

Paul Allen has stated that they did quite a bit of size reduction on the interpreter and what they’d do is pick something they felt could be shorter and all worked on it separately declaring they’d saved a byte or saved two bytes and then use whichever version was the smallest.

I believe he said that himself, Bill Gates and Monte Davidoff (who did the floating point routines) would all engage in this activity. When it comes to these little optimizations it could be any one of them who did it.

2 Likes

There was also

Copyright 1981 James Farvour
Microsoft BASIC Decoded & Other Mysteries
ISBN 0 - 936200 - 0l - 4

which contained a disassembly listing of the Level II ROM in chapter 6. Most pages of the disassembly contained only the opcode with no operands. The first 5 chapters are online as a PDF
Miscrosoft BASIC Decoded & Other Mysteries

and here are a couple of example pages - it was a little oddly arranged with info in addition to the comments being on the back of the page it referred to rather than the facing one.


1 Like

Once upon a time, my friends an I wrote a disassembler for the TRS-80. When we ran it against the Basic ROM, we were convinced we had a bug in our code. At one point, the Assembly language we were printing out jumped to the middle of an instruction in the rom!

After going back and forth, we realized that the code was optimized for space and some routine just happened to fit inside another, at a strange offset from the normal word boundary.

This was around 1979 / 1980, so the details are fuzzy…