Difference between revisions of "Z80"
Line 59: | Line 59: | ||
− | === Adding Color === | + | ==== Adding Color ==== |
The ZX Spectrum has a 32x24 colormap located at $5800 where you can write color information for each 8x8 tile. | The ZX Spectrum has a 32x24 colormap located at $5800 where you can write color information for each 8x8 tile. | ||
It has has 8 colors (INK and PAPER) with 2 brightness settings that can be set like this. | It has has 8 colors (INK and PAPER) with 2 brightness settings that can be set like this. | ||
Line 65: | Line 65: | ||
color = brightness(64) | (PAPER<<3) | INK | color = brightness(64) | (PAPER<<3) | INK | ||
+ | |||
+ | ==== Border Color ==== | ||
You can set the border color to any of the 8 colors with: | You can set the border color to any of the 8 colors with: | ||
Line 71: | Line 73: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === Getting something on screen === | + | ==== Getting something on screen ==== |
To be added soon. | To be added soon. | ||
Revision as of 05:30, 6 July 2020
Contents
Introduction
Wanting to start sizecoding on a Z80 platform in this day and age can be tough.
So here is a bit of help to get you started:
Z80 for X86 programmers
Z80 can be seen as the little 8bit brother of X86 chipsets, with many similarities. If you are coming from a X86 background, this might help you get a bit more grip on the Z80.
Registers
These are the register pairs of the Z80, as seen from a X86 programmers perspective.
- AF = AL + Flags
- HL = Can be seen as BX (H=BH,L=BL) or SI in a (HL) setting, like BX also used for adressing.
- BC = Can be seen as CX (B=CH,C=CL), often used for loops
- DE = Can be seen as DX (D=DH,E=DL) or DI in a (DE) setting
- IX = 16 bit Index Register X, can also be accessed with IXH,IXL
- IY = 16 bit Index Register Y, can also be accessed with IYH,IYL
Note: For a lot of operations, you can only use the A(8bit) and HL(16bit) registers. The Sjasmplus assembler doesn't really do proper syntax checking for this so beware.
Instructions
Here is a rough translation for some of the Z80 instructions:
- BIT = TEST
- CP = CMP (although the Z80 has many other handy compare functionality)
- DJNZ = LOOP (decreases B and checks not zero)
- EXE = Exchange all registers with Shadow registers, can be used a bit like PUSHA/POPA
- EX = XCHG
- HALT = HLT
- JP = JMP
- JR = JMP NEAR (Jump Relative)
- LD = MOV
- LDI = MOVSB (tmp=(HL),(DE)=tmp, DE++, HL++)
- LDIR = REP MOVSB (tmp=(HL),(DE)=tmp, DE++, HL++, BC--)
ZX Spectrum
The ZX Spectrum consists of a Z80A @ 3.5 MHz CPU with either 16k, 48k or 128K of RAM.
Setting up
Setting up your development platform for the ZX Spectrum is quite easy, first get the following tools:
- Assembler: SJASMPLUS -This assembler has nice macros for creating Binaries and SNA snapshot files out of the box. You can download it at https://sourceforge.net/projects/sjasmplus/
- Emulator(s): I Found FUSE, UnrealSpeccy and EightyOne to work best for my usecase. Most emulators can read TAP, SNA and TRD files out of the box.
Start values
Upon startup (when called from basic), the following values can assumed:
- The alternate HL register is set to 0x2758
- BC = start address
- A = C
Video display
Video display on the ZX Spectrum is mostly CPU based with little hardware features. No hardware sprites, no specific text or video modes, only a 256x192 byte screenbuffer with 1bit pixeldata located at $4000 in memory. It is ordened a bit strange in 3 sections of 256x64 pixels, then character rows, then subrows.
ScreenPosition = (page<<11) + (character row<<8) + (subrow<<5)
Adding Color
The ZX Spectrum has a 32x24 colormap located at $5800 where you can write color information for each 8x8 tile. It has has 8 colors (INK and PAPER) with 2 brightness settings that can be set like this.
color = brightness(64) | (PAPER<<3) | INK
Border Color
You can set the border color to any of the 8 colors with:
out (254),color
Getting something on screen
To be added soon.
Sound
The original Spectrum has only a 1 bit sound capability (BEEP) through its internal speaker. Later models included the AY-3-8910 Soundchip which provides 3 channels of PSG sound.
Make some noise - Beeper
To be added soon.
Make some noise - AY
You can access the AY soundchip be outputting to the following ports:
ld bc,0xfffd
ld a, ay register number
out (c),a
ld b,0xbf
ld a, data byte
out (c),a
For more information about the soundchip, check out: https://www.atarimagazines.com/v4n7/stsound.html
Additional Resources
I found resources on ZX Spectrum sizecoding to be sparse.
- Blogpost on ZX Spectrum coding from a X86 coder's perspectove on superogue's sizecdoing blog (soon)
- 128byte/256 byte zx spectrum productions by goblinish on pouet.net https://www.pouet.net/groups.php?which=11696&order=platform&reverse=1
- 128byte/256 byte zx spectrum productions by gasman on pouet.net https://www.pouet.net/user.php?who=2260&show=credits
Amstrad CPC
The Amstrad consists of a Z80A @ 3.5 MHz CPU
Setting up
Setting up..
- Assembler: -
- Emulator(s): -
Video Display
No information yet
Sound
No information yet
Additional Resources
No information yet