Sign in Join
Wiki copytemporary

Z80: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Z80

OldNewLine
1+## Overview
2+
3+A Z80 port is currently under development in Git "main" branch. To check it out, use:
4+
5+`mkdir fpc-z80`\
6+`cd fpc-z80`\
7+`git clone `[`https://gitlab.com/freepascal.org/fpc/source.git`](https://gitlab.com/freepascal.org/fpc/source.git)` fpc`
8+
9+## Requirements
10+
11+The compiler now includes an internal assembler and linker, so no extra packages are needed. Optionally, the assembler and linker from the SDCC package can be used as well:
12+
13+<http://sdcc.sourceforge.net/>
14+
15+## Targets
16+
17+### Embedded
18+
19+The compiler produces files in the IHX format (Intel HEX Format).
20+
21+### ZX Spectrum
22+
23+The compiler produces ZX Spectrum tape files in the TZX file format. They are suitable for running in emulators. An open-source emulator that works is FBZX:
24+
25+<https://www.rastersoft.com/programas/fbzx.html>
26+
27+ROM images for the emulator are available here:
28+
29+<http://www.chiark.greenend.org.uk/~cjwatson/code/spectrum-roms/>
30+
31+and here:
32+
33+<http://www.shadowmagic.org.uk/spectrum/roms.html>
34+
35+They are copyrighted and are not free (as in freedom), but are legally available for use in emulators (not in real hardware), and are also repackaged and redistributed in Linux repositories such as [RPMFusion - nonfree](https://rpmfusion.org/).
36+
37+Another emulator that works is Fuse:
38+
39+<http://fuse-emulator.sourceforge.net/fuse.php>
40+
41+Producing TZX files requires a tool, called **ihxutil**, which is written in Pascal and is available in the *utils/ihxutil* directory of the compiler.
42+
43+### MSX-DOS
44+
45+The compiler produces flat COM files that can be run from the MSX-DOS environment. Please note that you need to take extreme care that you don't link in too much code especially if you want to also include a heap and a stack. The default size for the heap is 256 and for the stack 1024 and these can be changed using the *\$MEMORY* directive.
46+
47+Generating the COM files requires the **ihxutil** utility which is written in Pascal and is available in the *utils/ihxutil* directory of the Free Pascal sources.
48+
49+More information can be found [[MSX-DOS|here]].
50+
51+## Building
52+
53+Here's the build script I use:
54+
55+``` bash
56+#!/bin/sh
57+
58+set -e
59+
60+FPC_Z80_DIR=/home/nickysn/tralala/fpc-z80
61+STARTPP=fpc
62+BINUTILSPREFIX=
63+
64+CROSSOPT=-O-1
65+export CROSSOPT
66+OPT="-CX -XXs"
67+if [ -n "$EXTRAOPT" ]
68+then
69+ OPT+=" $EXTRAOPT"
70+fi
71+export OPT
72+export CPU_TARGET=z80
73+export OS_TARGET=zxspectrum
74+export OS_SOURCE=`$STARTPP -iSO`
75+export CPU_SOURCE=`$STARTPP -iSP`
76+
77+cd $FPC_Z80_DIR/fpc
78+make -j `nproc` clean PP=$STARTPP BINUTILSPREFIX=$BINUTILSPREFIX
79+make -j `nproc` all PP=$STARTPP BINUTILSPREFIX=$BINUTILSPREFIX
80+make -j `nproc` crossinstall PP=$FPC_Z80_DIR/fpc/compiler/ppcrossz80 INSTALL_PREFIX=$FPC_Z80_DIR/zxspectrum-snapshot BINUTILSPREFIX=$BINUTILSPREFIX
81+```
82+
83+Note that, if you use the SDCC package from the official Fedora repositories, you might need to replace
84+
85+`BINUTILSPREFIX=`
86+
87+with
88+
89+`BINUTILSPREFIX=sdcc-`
90+
91+When compiling programs, you should always enable smartlinking by adding these two options to the compiler:
92+
93+`-CX -XX`
94+
95+## Status
96+
97+As of Apr 27, 2020, the code generator is stable enough to compile the full system unit. Standard output via write/writeln works now. As of May 17, 2020, optimization level 1 also works, so you can try compiling with -O1. Note that there aren't many Z80-specific optimizations implemented yet, but enabling optimization still has some small effect. Here's a simple program that works:
98+
99+``` pascal
100+program Hello;
101+var
102+ b: byte;
103+begin
104+ Write('FPC');
105+ for b := 0 to 255 do
106+ Write(HexStr(b, 2));
107+end.
108+```
109+
110+Here's what this program produces in the FBZX emulator:
111+
112+![](/wiki-images/c/c9/ZX_Spectrum_hello_world_FBZX_emulator_screenshot.png)
113+
114+---
115+*From the Free Pascal wiki, page "Z80", as it stood on 2022-05-24 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history