Recent

Author Topic: Z80 ZX Spectrum and System.pp  (Read 2210 times)

Cascade

  • Jr. Member
  • **
  • Posts: 75
Z80 ZX Spectrum and System.pp
« on: February 10, 2026, 03:30:13 pm »
I've been having fun playing with FPC cross-compiling to a Z80 target (specifically the ZX Spectrum).  It's working, and some test programs are loading fine.

The major problem encountered so far is an empty program compiles to around 32KB, even with optimisations and smart-linking enabled.  The target machine only has 48KB of RAM in total, and over 6KB of that is reserved for the screen.  Basically there's - almost - no room left for my program.

Is there a way to trim some features away from the target's system.pp ?  Perhaps some {$defines} to exclude features.  I don't need floating point math or heap memory management.  Exception handling might not be necessary either.  A stack is required, and records would be nice.  But otherwise a fairly bare-bones setup would be fine, as I'll be writing procedures and functions containing assembly language, and calling the built in ROM.  I'm really using Pascal for structure and encapsulation only.

I've spent a few weeks on and off hacking away at system.pp both starting from scratch (via the Wiki) and adding things FPC needs, and also taking the existing ZX Spectrum system.pp and removing things a bit at a time - but unfortunately neither approach has yet yielded a stripped down system.ppu that will compile a simple program.

Maybe I'm going about this wrong.  Does anyone have any tips for using FPC to target the ZX Spectrum in a practical 'bare-bones' way?

d2010

  • Sr. Member
  • ****
  • Posts: 257
Re: Z80 ZX Spectrum and System.pp
« Reply #1 on: March 09, 2026, 07:49:36 pm »
I've been having fun playing with FPC cross-compiling to a Z80 target (specifically the ZX Spectrum).  It's working, and some test programs are loading fine.
Maybe I'm going about this wrong.  Does anyone have any tips for using FPC to target the ZX Spectrum in a practical 'bare-bones' way?
A)Other way, you translate your'Pascal to Z80-Basic.
Please, please, please, you, Believe me, HiSoft'Basic.z80  is very very powerfull compilator of Basic, He contain max -speed of assembler.z80 and tiny'codes-result.

B)You can use HiSoft-Basic.z80 results for develope the system.pas, classes, graph, or crt.pas

« Last Edit: March 09, 2026, 09:52:17 pm by marcov »

Thaddy

  • Hero Member
  • *****
  • Posts: 18797
  • Glad to be alive.
Re: Z80 ZX Spectrum and System.pp
« Reply #2 on: March 09, 2026, 09:04:25 pm »
Well, do not touch system.pas because you probably have the wrong one.
Besides: that is a horribly incorrect and outdated wiki entry.
The target is an embedded target and you should end up with an empty program much smaller than 32K.
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

Cascade

  • Jr. Member
  • **
  • Posts: 75
Re: Z80 ZX Spectrum and System.pp
« Reply #3 on: March 10, 2026, 06:02:06 pm »
I wonder whether I have an outdated build.  FPC has Z80/ZX Spectrum as a target CPU/OS but Z80/Embedded seems not an option.

z80-zxspectrum works (and it is my target machine) but its system.pas compiles too large for the machine's RAM.

z80-embedded sounds more like what I'm after if it's possible.  Is there a particular build I should install to get that combination?

Currently on: FPC 3.3.1 aarch64-darwin-cocoa, built from source in September 2025.

@d2010, I agree HiSoft Basic is a truly excellent compiler - I used it back in the day for non-speed critical coding.  But now I would prefer to develop on a modern system with a more structured and encapsulated approach, and cross-compile to the target.  I think Pascal's encapsulation features such as Records could work really nicely combined with inline assembly in function implementations.

In the meantime I'm having success coding directly for z80 with sjasmplus - but miss the high-level language structure.

Thaddy

  • Hero Member
  • *****
  • Posts: 18797
  • Glad to be alive.
Re: Z80 ZX Spectrum and System.pp
« Reply #4 on: March 10, 2026, 07:37:51 pm »
Well, I seem to have been wrong, but the size you get is definitely way too large.
Did you build with debug info?
Afaik, the z80 target was mainly developed by Florian himself. I can not imagine he would have released it if there would be not enough workspace left.
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

Cascade

  • Jr. Member
  • **
  • Posts: 75
Re: Z80 ZX Spectrum and System.pp
« Reply #5 on: March 10, 2026, 08:22:14 pm »
Some z80 systems have more than 64K, addressed by switching 16K pages in and out of the 0..65535 address space.  ZX Spectrum machines are 16K, 48K and 128K, with the 48K model typically the 'standard' model to target.

Part of that 48K is shared video memory (6912 bytes for the display), plus some system variables.

The FPC Z80 target is impressive (I especially appreciate detail such as auto-generating a .tzx file for Spectrum emulators to load).

I'm compiling without debug information, and with smart-linking enabled, and O1 optimisation.  As you say, chances are I've got something not quite right, though 32K for a complete system.pp is not unexpected.  An option or $define for (almost) no system.pp could work wonders here!
« Last Edit: March 10, 2026, 08:35:58 pm by Cascade »

d2010

  • Sr. Member
  • ****
  • Posts: 257
Re: Z80 ZX Spectrum and System.pp
« Reply #6 on: March 12, 2026, 07:58:28 pm »
Some z80 systems have more than 64K, addressed by switching 16K pages in and out of the 0..65535 address space.  ZX Spectrum machines are 16K, 48K and 128K, with the 48K model typically the 'standard' model to target.

Part of that 48K is shared video memory (6912 bytes for the display), plus some system variables.

The FPC Z80 target is impressive (I especially appreciate detail such as auto-generating a .tzx file for Spectrum emulators to load).

Please, You make a demo Video. , a youtube or demo.mp4, for facebook tictok. with your games.tzx
,but you extend SCREEN$ cu 6912bytes, with "Hardware snapshot"=as Second- "SourceCapture, bas, pas , z80 ", or Z80-Inside Hard -images or ... Pleae you share many demos. for the public.
https://youtu.be/cuBbQ6K45YY

Here is russian-demo-musical.. I can make and others :-\,  if you need a team.
On the screen right+bottom ., you will see snaphot.avi cu books of Z80..Great Lover.
https://youtu.be/a0xAzqtk7g8
 :(
Please please,
, You clone my musical-movie , with FreePascal Fpc,
with Z80-Dos+FreePascal.exe( You capture the sources.pas.for -spectrum)

« Last Edit: March 12, 2026, 08:03:43 pm by d2010 »

 

TinyPortal © 2005-2018