Mastering Machine Code on Your ZX81
By Toni Baker

Sinclair ZX Spectrum
ALL AVAILABLE DOWNLOADS
Thunor: Added by myself to list all of the available downloads to date along with screenshots and chapter links.

THIS ENTIRE HTML BOOK

htmlbook-screenshot 
This entire HTML book prepared for offline reading i.e. no web icons, no site meter. The left-hand side index is built using JavaScript and so JavaScript must be enabled to use it. If JavaScript is disabled then the index disappears and the page widens - useful for devices with reduced width screens.

COPYING | ChangeLog

Download available -> mmcoyzx81-0.1.9.tar.gz
 

CHAPTER02-SETRAMTOP

chapter02-setramtop-screenshot  A heavily modified version of the author's three line program that enables the user to enter a decimal or hex address and then sets RAMTOP and executes NEW automatically.

Very useful for early on in the book when asked by the author to set RAMTOP to various decimal or hex addresses and finding converting between number systems on a calculator and POKEing becoming a chore.
Download available for 16K ZX81 -> chapter02-setramtop.p
 

CHAPTER02-HEXLD

chapter02-hexld-screenshot  Due to the lack of pixels to showcase (unless string input prompts are your thing) I've chosen to display a listing. This program will accept at least one hex byte as input and POKE it to address 30000 (7530h) onwards until the user inputs "S".

Set RAMTOP to 30000 and type NEW before loading.

Download available for 16K ZX81 -> chapter02-hexld.p
 

CHAPTER03-REPLACE

chapter03-replace-screenshot  This accepts two numbers and POKEs them into a small machine code routine. The numbers are processed and the result is returned to BASIC whereby it's PRINTed.

I have modified this slightly so that RUNning it installs the necessary machine code to 30000 to make it complete and ready to go.

Set RAMTOP to 30000 and type NEW before loading.

Download available for 16K ZX81 -> chapter03-replace.p
 

CHAPTER04-PRINTPOS

chapter04-printpos-screenshot  This program prints the Y part of the system variable S_POSN across and down the screen.

I have modified this slightly so that RUNning it installs the necessary machine code to 30000 to make it complete and ready to go.

Set RAMTOP to 30000 and type NEW before loading.

Download available for 16K ZX81 -> chapter04-printpos.p
 

CHAPTER04-ANTISCROLL

chapter04-antiscroll-screenshot  This demonstrates how fast machine code screen scrolling can be compared to the BASIC SCROLL. Key 6 uses the machine code antiscroll, key 7 the BASIC SCROLL.

I have modified this slightly so that RUNning it installs the necessary machine code to 30000 to make it complete and ready to go.

Set RAMTOP to 30000 and type NEW before loading.

Download available for 16K ZX81 -> chapter04-antiscroll.p
 

CHAPTER05-HEXLDREMLO

chapter05-hexldremlo-screenshot  This is a version of HEXLD that POKEs into a line 1 REM statement instead of above RAMTOP.

Download available for 16K ZX81 -> chapter05-hexldremlo.p
 

CHAPTER05-HEXLDREMHI

chapter05-hexldremhi-screenshot  This is a version of HEXLD that POKEs into a line 9999 REM statement that's been hidden (or will be) by having the most significant byte of its address set to FFh (-1).

Download available for 16K ZX81 -> chapter05-hexldremhi.p
 

CHAPTER07-HEXLD2

chapter07-hexld2-screenshot  This is an updated version of HEXLD that not only prints user input (which makes screenshots more interesting), but enables the user to input character codes in strings e.g. ";LN graphic-A graphic-A TAN ;" is equivalent to "CD0808C9".

For the ZX81: You don't need to set RAMTOP unless you're going to use HEXLD2 to write above it as this program is all BASIC.

Download available for 16K ZX81 -> chapter07-hexld2.p
Download available for 16K ZX80 -> chapter07-hexld2.o
 

CHAPTER07-ASTERISKFILL

chapter07-asteriskfill-screenshot  A very small very fast screen filling routine in a line 1 REM statement.

Download available for 16K ZX81 -> chapter07-asteriskfill.p
 

CHAPTER07-DRAUGHTS

chapter07-draughts-screenshot  This simply prints a draughts board. It's machine code and is stored in and retrieved from an array.

Set RAMTOP to 4C00 and type NEW before loading. After a reset, the easiest way to do this is to POKE 16389,76 followed by NEW.

Download available for 16K ZX81 -> chapter07-draughts.p
 

CHAPTER09-HEXLD3

chapter09-hexld3-screenshot  This is a new and much improved version of HEXLD2 that operates mostly in machine code, although there's a fair chunk of BASIC too. I recommend reading the operating instructions in appendix one (ZX80 or ZX81) before attempting to use this program.

For the ZX81: You don't need to set RAMTOP unless you're going to use HEXLD3 to write above it as HEXLD3 is stored in a line 1 REM statement.

Download available for 16K ZX81 -> chapter09-hexld3.p
Download available for 16K ZX80 -> chapter09-hexld3.o
 

CHAPTER10-ENLARGE

chapter10-enlarge-screenshot  This program uses an efficient method of displaying enlarged versions of the character set. ZX80 Enlarge uses additional subroutines that the ROM lacks (but doesn't work (yet)) which I used again in ZX81 Enlarge2 to test that it works - and it does. I may return to the OLD ROM version.

For the ZX81: Set RAMTOP to 4D00 and type NEW before loading. After a reset, the easiest way to do this is to POKE 16389,77 followed by NEW.

Download available for 16K ZX81 -> chapter10-enlarge.p
Download available for 16K ZX81 -> chapter10-enlarge2.p
Download available for 16K ZX80 -> chapter10-enlarge.o
 

CHAPTER10-GRAFFITTI

chapter10-graffitti-screenshot  This is an update of the ENLARGE program that should wrap enlarged text both across and down the screen, but for some reason it only wraps across it. I may return to this program and attempt to fix it, although I have already made some effort to do so.

Set RAMTOP to 4D00 and type NEW before loading.

Download available for 16K ZX81 -> chapter10-graffitti.p
 

CHAPTER11-HEXLD3D

chapter11-hexld3d-screenshot  This is a modified version of HEXLD3 with HEXLD3's machine code relocated from 4082 in the line 1 REM statement to 4A82 above RAMTOP. Therefore user machine code follows HEXLD3D's at 4B78 and everything gets saved together in an array when typing RUN 400. ZX80 HEXLD3 already works in this way.

Set RAMTOP to 4A00 and type NEW before loading. After a reset, the easiest way to do this is to POKE 16389,74 followed by NEW.

Download available for 16K ZX81 -> chapter11-hexld3d.p
 

CHAPTER11-DRAUGHTS1

chapter11-draughts1-screenshot  This is the first part of the DRAUGHTS program which incorporates the earlier draughts board drawing subroutine. It was built using HEXLD3D as instructed by the author. Currently the player can move pieces but the computer AI is not yet implemented and so it doesn't respond. Read the operating instructions before playing.

Set RAMTOP to 4A00 and type NEW before loading.

Download available for 16K ZX81 -> chapter11-draughts1.p
 

CHAPTER12-CATHYS

chapter12-cathys-screenshot  There's no screenshot - it's an audio experience. You and your ZX can make beautiful music together through this program. Jesting aside, I've never heard anything like this before and I think it's very impressive. Under emulation, you'll need TV speaker support (sz81 supports this via the GUI VSYNC sound option (->)).

For the ZX81: Set RAMTOP to 4A00 and type NEW before loading.

Download available for 16K ZX81 -> chapter12-cathys.p
Download available for 16K ZX80 -> chapter12-cathys.o
 

CHAPTER12-LIFE

chapter12-life-screenshot  This is a version of Life with wrapping grid edges and is one of my favourite programs from this book. The author wrote it to a line 1 REM statement using HEXLD3 but I wrote it high with HEXLD3D as the 76s in the REM statement were problematic.

Set RAMTOP to 4A00 and type NEW before loading.

Download available for 16K ZX81 -> chapter12-life.p
 

CHAPTER13-DRAUGHTS2

chapter13-draughts2-screenshot  This is the second part of the DRAUGHTS program which includes the code from the previous DRAUGHTS1 program. Currently the player can move pieces but the computer AI still isn't implemented and so it doesn't respond. Read the operating instructions before playing.

Set RAMTOP to 4A00 and type NEW before loading.

Download available for 16K ZX81 -> chapter13-draughts2.p
 

CHAPTER14-SPIRALS

chapter14-spirals-screenshot  This game is a race against the clock to hastily advance your little man (or woman) into the very heart of the spiral. If you walk into a wall then you must back-up first to get back to the path. Keys are top row up, 2nd row left, 3rd row right and bottom row down. As this (like everything else I've recently coded) is written with HEXLD3D you can use it to modify the game speed at 4C4D - change 04 to 08 for example.

Set RAMTOP to 4A00 and type NEW before loading.

Download available for 16K ZX81 -> chapter14-spirals.p
 

CHAPTER14-BREAKOUT

chapter14-breakout-screenshot  This is a version of BREAKOUT for the ZX81 that gets very fast if you're not very good. To control the bat the keyboard is split down the middle. You can modify the game's initial speed at 4BCO - change 09 to 0B for example.

Although RAMTOP should be set to 4A00, doing so upsets the program, so don't set it. I don't know why this is - possibly it needs to be written much higher up in memory.

Download available for 16K ZX81 -> chapter14-breakout.p
 

CHAPTER15-DRAUGHTS3

chapter15-draughts3-screenshot  This is the third and final part of the DRAUGHTS program which includes the code from the previous DRAUGHTS2 program. This is as far as the author takes the project -- the reader is required to complete it -- and unfortunately my downloadable version crashes when the computer AI makes a jump - more about this here. Read the operating instructions before playing.

Set RAMTOP to 4A00 and type NEW before loading.

Download available for 16K ZX81 -> chapter15-draughts3.p
 

CHAPTER16-LENSLIST

chapter16-lenslist-screenshot  This is essentially HEXLD3D with a new LIST function which I've called LENSLIST after the name of the author's data table. Instead of the simple one byte per line list of HEXLD3, the bytes are now disassembled into instructions. The method the author used to compress the necessary information required to achieve this is excellent, but the program itself has some issues dealing with invalid prefixed instructions.

Set RAMTOP to 4A00 and type NEW before loading.

Download available for 16K ZX81 -> chapter16-lenslist.p
 

CHAPTER17-FLOATCHK

chapter17-floatchk-screenshot  This is a heavily modified version of the author's BASIC program that accepts Sinclair floating point form numbers and then PRINTs them in decimal. This version also enables the user to enter decimal numbers to see their Sinclair Form.

Download available for 16K ZX81 -> chapter17-floatchk.p
 

FAREWELL

So farewell ZX machine code programmers. The author Toni Baker has left you this secret Sinclair character code encoded message and I'm not going to spoil the surprise by showing you a screenshot!

Download available for 16K ZX81 -> farewell.p

Finishing the Book

Once you've read the book through to the end, you might be considering writing the disassembler from the algorithm in chapter 16. If you are then read on because I attempted it and wrote a few more useful (actually necessary) development tools along the way. The only program remaining for myself to complete is draughts, but if I do return to finish it then it'll be with a cross-assembler rather than a hex loader.

LENSLIST2

sif-lenslist2-screenshot  This is my attempt to overcome the shortcomings of the LENSLIST program from chapter 16. I've used a similar method to the author but my LENS table uses 1 byte for each potential instruction with 2 bits each for ordinary, after DD, after ED and after FD. Instructions starting CB, DDCB and FDCB can easily be dealt with in code because if they are valid they are the same size and it's trivial to filter out invalid instructions.

Set RAMTOP to 4A00 and type NEW before loading.

Download available for 16K ZX81 -> sif-lenslist2.p
 

DUMP

sif-dump-screenshot  I wrote this simple (but very fast and useful) memory dumper to assist with development, but I thought it was too good to leave hidden away and so I've written up a listing and offered it as a download. If you're new to ZX81 machine code programming then this is a nice little program to play around with as I've designed it so that you can easily append your own dump types. Note that this includes four dump types when the version within HEXLD3E below has just two.

Download available for 16K ZX81 -> sif-dump.p
 

HEXLD3E

sif-hexld3e-screenshot  This is a modified version of HEXLD3D relocated to between 6400h and 6737h, the inclusion of both LENSLIST2 and DUMP and the addition of a menu system. User machine code follows HEXLD3E's at 6738h and everything gets saved together in an array when selecting SAVE from the menu. BEGIN is now at 6411h and LIMIT at 6417h. STKEND is dumped on SAVE so that you can see how full the memory is below 6400h.

Set RAMTOP to 6400h and type NEW before loading. After a reset, the easiest way to do this is to POKE 16389,100 followed by NEW.

Download available for 16K ZX81 -> sif-hexld3e.p
 

DISASM

sif-disasm-screenshot  This is my implementation of the disassembler algorithm from chapter 16. This was written with HEXLD3E between addresses 6738h and 72CD. Also because I didn't want to type in a program of this complexity without being able to move it to another part of memory I made it relocatable i.e. it relocates itself from an address POKEd in by the caller. Possibly this added somewhere between 1/2 and 3/4 of a KB (I had to refrain from using absolute addresses) but moving this to a REM statement and running it from there is trivial and more than compensates for the increased size.

Set RAMTOP to 6400h and type NEW before loading.

Download available for 16K ZX81 -> sif-disasm.p

Sinclair ZX Spectrum

  Previous Page Back Next Page