Z80 Quality Indicators
By Paul Flo Williams
I’m 78% through my annotated disassembly of Tehkan’s arcade game Star Force and I was just wondering what quality indicators other people use to rate Z80 code that they read? What makes you nod in satisfaction, or sneer in disapproval?
Positive quality indicators I can see in this code:
-
Excellent use of IX and IY to index structures, which makes it really easy to comment, by adding equates for structure offsets.
-
Self-initialising structures, where the assumption is that they’ll receive a pointer to a block of zeroed memory, and the code uses the first byte as a flag as to whether it is initialised yet. This brings initialisation and usage code right together in the listing, again easing understanding of code that manipulates maps, enemy waves and sprite structures.
-
Great use of jump tables, which enables a lot of common code to be used, while adding hooks for exceptions.
-
Nice use of flags for interrupt service routines, to limit the amount of data transfers that needs to be done every frame (OK, this one is specific to game programming.)
Negative quality indicators I can see:
-
cp 0
instead ofor a
-
BCD arithmetic in some places, but hacky workarounds in others: why would you do this when
daa
is 4 T-states? -
Multiple
ldir
s with address shuffling (and a bug when they lost count), whenlddr
should have been used. -
mask and shift, instead of shift and mask (which would’ve enabled single byte 8080-compatible rotates instead of Z80 extensions)
All of this is reminding me why I loved Z80 coding, 40 years ago!