[fpc-devel] FPC and Z80

nickysn at gmail.com nickysn at gmail.com
Mon Apr 27 15:57:57 CEST 2020

On Mon, 2020-04-27 at 15:40 +0200, Michael Van Canneyt wrote:
> On Mon, 27 Apr 2020, nickysn--- via fpc-devel wrote:
> > Last night, I got the full system unit to compile, including
> > console
> > output, so now you can use standard write/writeln. Unfortunately if
> > you
> > include both read/readln and write/writeln in your program, the
> > program
> > becomes too big to fit in the memory of the 48k ZX Spectrum, so
> > there's
> > lots of optimizations left to do... :) However, the fact that the
> > system unit compiles fully, means that the code generator is
> > starting
> > to become stable and, therefore, you should have little trouble
> > porting
> > FPC to other Z80 platforms, such as the MSX - it's a matter of
> > writing
> > the platform-specific RTL functions, and implementing the specific
> > things (linking and postprocessing the binary), required to produce
> > a
> > program, in a format, suitable to run on the MSX.
> Well, I'm surprised and impressed you got it to work at all... 
> Quite an achievement.

To be honest, I was also surprised how quickly I reached this point of
code generator stability. The i8086 port was much more painful and took
a lot of time to get it that stable. But now, things are different,

1. I'm much more familiar with the compiler internals, so the learning
curve isn't that steep
2. The compiler already has been ported to 16-bit and 8-bit platforms,
so there's less work needed in the generic parts of the code generator.
3. There are no special pointer types (near, far) and memory models.
It's just 16-bit flat address space.

On the other hand, this time:

1. I knew nothing about Z80 assembly when I started.
2. I knew nothing about the ZX Spectrum.

So, this time, I had to learn about these things from scratch. I also
had to implement the asm backend entirely, almost from scratch
(actually Florian had already started it, but it wasn't as complete as
the x86 family, which just borrows everything from i386, since i8086 is
just a subset of the i386 instructions).

> I suppose FPC is now probably the compiler working for the biggest
> number of
> CPUs/OSes - if it wasn't already. (C excepted, probably)

Yeah, after this port, I'm convinced that FPC can be ported to anything
:) I guess, now 6502 becomes the next challenge. :) Btw, I'm also
considering the PIC microcontroller family, because I use them in some
of my hardware projects - AVR is cool, but sometimes there's a PIC that
just has the right peripherals integrated for your project. :) But
first, the Z80 target still needs a lot of optimizations, because it
produces too many unnecessary moves and the code becomes quite bloated,
at least compared to SDCC.


More information about the fpc-devel mailing list