Patricia’s Spectrum Next Dev Links


Because I am collecting many more links I have decided to split them up into programming and art, this page is for the programming links.

The Art Links can be found here

Something for the people learning

John Blackburn, one of my old school programmer friends reminded me that there were many great magazines we all learned from back in the day, luckily they have been preserved for future generations at the archive.org.

https://luckyredfish.com/something-for-the-people-learning

Coding for the Spectrum Next emulator CSpect

As you can see by my site, I have lots and lots of game development and programming experience https://luckyredfish.com/previous-works/, but I have little or no z80 experience. However, having learned many languages over the years I am sure Z80 is going to be a breeze.

https://luckyredfish.com/coding-for-the-spectrum-next-emulator-cspect/

Getting a sprite up on a Spectrum Next

Well during my step into exploring the Spectrum next I came across quite a few sources that had good code, but they were a little difficult to read and it took some time to strip out some of the basics to do what I needed.

https://luckyredfish.com/getting-a-sprite-up-on-a-spectrum-next/

How To Write ZX Spectrum Games, lots of useful information and code on this page

https://chuntey.wordpress.com/category/z80-assembly/page/2/

The Registers And MemoryRegisters are sections of very expensive RAM inside the CPU that are used to store numbers and rapidly operate on them. At this point, you only need to concern yourself with these 8-bit registers: A, B, C, D, E, F, H, and L.The single-letter registers are 8 bits in size, so they can store any number from 0 to 255. Since this is oftentimes inadequate, they can be combined into four register pairs: AF BC DE HL. These, along with IX and IY, are 16-bit, and can store a number in the range 0 to 65535.Although for the most part register use is interchangeable, it is common coding practice to use them in this particular manner:

http://z80-heaven.wikidot.com/the-registers-and-memory

Flags and Conditions

Where would we be without If/Then statements? They’re called conditions in asm. There is no If command in asm. Don’t worry though. We have what are called ‘flags’. Remember when I was telling you about the register pairs? Do you remember that a didn’t have a partner? It does, and it’s f. Af is the registered pair. The z80 has six flags on it total, which are represented in the f register as being either set (1) or reset (0). Remember that the f register contains the flags as bits. The most commonly used flags are the ‘zero flag’ and the ‘carry flag’, we will learn about the others later on.

http://jgmalcolm.com/z80/beginner/flag

Signed arithmetics – this includes compare – uses the Overflow flag (P/V) to signal any over/underflow. To decode it has to be seen in relation with the sign flag. This is a two step process:
Step 1: Test for equal.

• If Z flag is set then V (value compared) is equal to A
• If Z flag is reset then Vr is not equal to A

Step Two: Test for less or greater

• If S and P/V are the same then V is greater (*) an A
• If S and P/V are different then V is less than A

S and P/V are as well the same if the number is equal to A, so without the first test comparing S an P/V can be used to catch a number greater or equal to A.

https://retrocomputing.stackexchange.com/questions/9163/comparing-signed-numbers-on-z80-8080-in-assembly

Conditional Jumps

Branching and looping is fundamental to computing, and the Z80 has a comprehensive set of instructions to support this.

You can:

Perform relative and absolute jumps.
Perform conditional jumps.
Jump to a direct address, or to the contents of a register.
Call and return from subroutines.

http://www.breakintoprogram.co.uk/programming/assembly-language/primer/part-3

https://z80journal.wordpress.com/2015/04/15/z80-interrupts/

The four add, sub, adc and sbc instructions

The Z80 processor is able to directly add or subtract both 8 and 16-bit numbers. These operations are performed by four simple instructions: add, sub, adc and sbc, this page also includes a simple bubble sort in Z80 assembly.

http://www.massmind.org/techref/zilog/z80/part3.htm

z80 Floating Point numbers and math

z80float is a floating point library targeting the Z80 processor. While this project is tested on a TI-84+, the code should be generic enough to run on any Z80 CPU with very little modification (mostly defining scrap RAM locations).

https://github.com/Zeda/z80float

Z80 Family CPU User Manual (Z80 CPU Instruction Description)

Presents the User’s Manual instruction types, addressing modes and instruction Op Codes. Z80 Instruction Set Presents an overview of the User’s Manual assembly language, status indicator flags and the Z80 instructions.

https://retrocdn.net/images/c/c1/Zilog_Z80_Programmer%27s_Reference_Manual.pdf

Extended Next instruction set

https://wiki.specnext.dev/Extended_Z80_instruction_set

Multiplications, divisions and shifts

Even though there is an mul instruction in the next extended set, it’s ‘only’ an unsigned 8×8 multiplication, as the 8 bit registers D and E will be multiplied and the 16 bit result stored in DE, however this link contains 8bit, 16bit and 32bit multiplications, fast division and square root should you need it.

http://map.grauw.nl/articles/mult_div_shifts.php

16-bit Shifts on Z80The Spectrum Next extended instruction set contains barrel shift instructions: BSLA DE,B BSRA DE,B BSRL DE,B BSRF DE,B & BRLC DE,BThe Spectrum Next extended instruction set contains barrel shift instructions, which takes a value to be shifted or rotated, an amount to shift or rotate by and the type of shift or rotate. This can be used by various classes of NEXT instructions to perform comparatively complex operations in a single instruction.

Shift instructions use only bits 4..0 of B, BSLA shifts DE left, BSRA/BSRL/BSRF shifts DE right in arithmetic/logical/fill-one way. BRLC rotates DE left by B places, uses only bits 3..0 of B (to rotate right, use B=16-places).

16-bit Shifts on Z80

Which are nice but for those who need 16-bit, unsigned, binary shifts on a Z80 microprocessor, here’s a quick guide

https://www.chilliant.com/z80shift.html

If you want to make games, you will likely need math routines, if you are making a math program, you need math, and if you are making a utility, you will need math. You will need math in a good number of programs, so here are some routines that might prove useful.

http://z80-heaven.wikidot.com/math

Index, Shadow, and Other Registers

in programming z80, sometimes you probably run out of registers to use but there are several others you can work with too but they have their limits.

Index Registers
Shadow Registers
Other Registers

http://jgmalcolm.com/z80/advanced/inde

Interrupts on the ZX Spectrum

Interrupts, as the name suggests, are when the normal running of a computer program are interrupted so something else can happen. On modern computers there can be various interrupts, but on the ZX Spectrum there were very few, most times you will hear of only 3 different interrupt modes 0, 1 and 2. While the main focus of this document is interrupt mode 2, we will quickly cover modes 0 and 1.

The original document has been copied to my site as facebook would not let me share the original URL.

https://luckyredfish.com/interrupts-on-the-zx-spectrum/

and

The Z80 microprocessor supports three interrupts modes; 0, 1, and 2. In interrupt mode 0 the Z80 gets an instruction from the data bus given by the peripheral and executes it. This instruction is normally RST0 -> RST7 which resets the Z80 to a specific location given by that instruction. In interrupt mode 1 the Z80 jumps to address 0038h where it runs a routine that the programmer implements. In interrupt mode 2 the Z80 gets a byte from the data bus and jumps to the 16-bit address formed by combining the ‘I’ (interrupt vector) register and the supplied byte from the peripheral.

https://z80journal.wordpress.com/2015/04/15/z80-interrupts/

General z80 Optimization

After you’ve worked the bugs out, you may if you wish make your program smaller and run faster. This section is dedicated to just that purpose. Although there are a lot of things you can do, here are some general things that can help

http://z80-heaven.wikidot.com/optimization

Steve Monks Next Machine Code Guides

A collection of short examples, each showing how to use a particular feature of the ZX Spectrum Next’s hardware from Z80 assembler. The emphasis is on keeping the examples short, simple and hopefully easy to understand. All code is heavily annotated to explain what’s going on at any point.

https://github.com/stevemonks/ZXSpectrumNextMachineCodeGuides