Z88DK C+Z80 Development Tools

Discuss ZX Spectrum Next Games, Tools and more.
Alcoholics Anonymous
Posts: 740
Joined: Mon May 29, 2017 7:00 pm

Z88DK C+Z80 Development Tools

Postby Alcoholics Anonymous » Tue May 30, 2017 1:57 am

Z88DK is a complete z80 development environment for windows, macos x and linux.

It features:

* Two C compilers: sccz80 and zsdcc (a customized & improved sdcc).
* Assembler / Linker / Librarian
* M4 as macro preprocessor
* Appmake to build output files for target machines (tape, rom, disk, etc)
* The internet's largest repository of z80 code

The tools allow any mixture of C and asm projects to be built, including all-C or all-asm. The assembler is among the most sophisticated z80 assemblers available for the PC, allowing bankswitched programs to be easily produced and code to be easily shared through libraries.

The Spectrum is one of the primary targets in z88dk and it enjoys significant support through library code including float/integer math, abstract data types (like queues, linked lists), various memory allocators, proportional fonts, music, sound effects, streamed i/o, software sprites and so on. The entire library is written in assembly language and can be used from either assembly or C.

The Next will be getting its own target and will also inherit z88dk's existing spectrum codebase. For the Next, we will be looking to support all video modes, porting the SP1 sprite engine to the Timex video modes (this is a software sprite engine that has been used in close to 50 spectrum games in recent years), adding streamed disk i/o, adding a sockets api, and of course we will be looking at how value can be added to new Next features like the hardware sprites. Contributions are also welcome :)

Main portal on github: https://github.com/z88dk/z88dk

Binary packages are built every night for windows and macosx: http://nightly.z88dk.org/
Download, unzip to your home directory, and set the PATH and ZCCCFG variables according to instructions here.

Linux users can following these instructions to install z88dk and then these instructions to build one of the C compilers zsdcc.

Some Examples:

Pietro Bros for the plain 128 spectrum using Nirvana+ (version before flicker was eliminated).

Sgt. Helmet Zero using a predecessor of sp1 in character movement only.

Ninjajar using a predecessor of sp1.

A somewhat technical and brief overview.
https://github.com/z88dk/z88dk/blob/mas ... verview.md

A technical introduction to compiling for a generic embedded z80 system:
https://www.z88dk.org/wiki/doku.php?id= ... t_embedded
The generic z80 embedded system is the base target for z88dk's new c library. Other targets like the zx are built on top of this so this page gives a solid introduction to the tools and environment. A simpler introduction can come from looking at some examples for the zx ( https://github.com/z88dk/z88dk/tree/mas ... XAMPLES/zx ).

(BB software cannot inline some links in case someone else is having trouble posting)
Last edited by Alcoholics Anonymous on Wed May 31, 2017 6:40 am, edited 2 times in total.

User avatar
Posts: 13
Joined: Tue May 30, 2017 1:22 am

Re: Z88DK C+Z80 Development Tools

Postby z80asm » Tue May 30, 2017 3:51 am

Great info., will definitely check this out, thanks for posting!

Posts: 50
Joined: Tue May 30, 2017 8:24 am

Re: Z88DK C+Z80 Development Tools

Postby stephenvalente » Tue May 30, 2017 8:32 am

Thank heavens it's available for the Mac.

Will have to install it on my MacBook Pro and Mac Pro, and somehow keep them in sync.

User avatar
Posts: 9
Joined: Tue May 30, 2017 10:47 am
Location: Cambridgeshire, England

Re: Z88DK C+Z80 Development Tools

Postby paulland » Tue May 30, 2017 11:49 am

Could I ask what the advantages of using C would be? Is it just that it would be a higher level language but slower running code than using compiled Assembly code? I had used C a while back and more recently C# (yes I know they are different) so I am wondering the pros and cons from a laymans point of view.

Posts: 4
Joined: Tue May 30, 2017 6:45 pm

Re: Z88DK C+Z80 Development Tools

Postby js1 » Tue May 30, 2017 7:16 pm

C is much easier to program in than assembler. Even though I would assume optimizer in Z88DK is pretty good, of course there is lot of additional overhead to hand-coded assembly.

I intend to use Z88DK for my projects, but without C, only the assembler parts.

Alcoholics Anonymous
Posts: 740
Joined: Mon May 29, 2017 7:00 pm

Re: Z88DK C+Z80 Development Tools

Postby Alcoholics Anonymous » Tue May 30, 2017 7:39 pm

paulland wrote:
Tue May 30, 2017 11:49 am
Could I ask what the advantages of using C would be? Is it just that it would be a higher level language but slower running code than using compiled Assembly code?
It's about speeding up development and being able to write more complex programs. In a game, it's usually 10-20% of the code that is speed critical and there is little advantage to writing the rest in asm. In asm you also can't quickly try new algorithms and you probably won't do anything too complex because of the effort involved. For things that are not games, for example if you wanted to write an assembler, text editor, shell, etc you would be making things much harder on yourself by sticking to pure asm with no clear advantage in doing so.

You shouldn't get the wrong impression though. Programming in C on the z80 is not about pure C, it's about a mix of C and asm. The asm, whether provided by you or the library, must make up that min 10-20% of code to make execution speed similar to pure asm. For games that code will include your graphics engine (or one of the z88dk library's graphics engines) and maybe a bit more. The rest - game logic, menus, between level housekeeping, file io, etc - can be perfectly well implemented in C. You may also want to use C to quickly try out a lot of different algorithms, AI, etc and then when satisfied rewrite in asm as (and if) necessary.

On the Next, things like the hardware sprites will mean the amount of asm needed in a program for performance reasons will be much less. To get an idea of this you can have a look at Astroforce for the Sega Master System which also has hardware sprites and scrolling and has much less asm in it than a typical spectrum game written in c and none of it written by the author:
The source code is in the z88dk repository: https://github.com/z88dk/z88dk/tree/mas ... AstroForce

However, it's not just about the C; it's also about the tools. Most z80 cross assemblers are very simple in that they cannot deal with memory spaces greater than 64k in a general manner and they are unable to share code. They were based on native assemblers written for machines like the spectrum in the 1980s which in turn were limited in comparison to the assemblers available in the 1970s due to small memory spaces and lack of standard mass storage. Assemblers used with C compiilers have to be able to separate memory types (ROM from RAM) and accommodate extended memory banks of any size so they can't be simplified.

The linking capability allows people to share code. If you write code or graphics that you would like to share with others, in order to use it, other people will have to manually extract the functions they want to use and all their dependencies. This is only practical in very small library sizes. In the z80 community, it is very common for individuals to build up a personal library of routines that they reuse over and over however sharing is very rare simply because they're not using the right tools to share.

Related to sharing code, there are 1000 functions in z88dk now written in asm that anyone has the option of using. These are not trivial functions that anyone can sit down and write over a few evenings; it would take a dedicated expert more than a year+ to reimplement from scratch in their spare time (and why would one do that?) Things like this save a lot of time and increase the possible complexity of programs for beginners and experts by standing on the work of others. Something not quite what you need? Implement it and share that.

Anyway there you go :)

User avatar
Posts: 9
Joined: Tue May 30, 2017 10:47 am
Location: Cambridgeshire, England

Re: Z88DK C+Z80 Development Tools

Postby paulland » Thu Jun 01, 2017 9:41 am

Thank you js1 for your response and thank you AA. You have completely convinced me to take a look at it. Thank you for taking the time for such a thorough answer. I'll jump in and see how I get on. :D

Posts: 27
Joined: Tue May 30, 2017 8:03 am

Re: Z88DK C+Z80 Development Tools

Postby utz » Tue Jun 06, 2017 9:39 pm

You know what'd be really awesome? Having z88dk running on the rpi0 accelerator board, coupled with a nice IDE. Just imagine: High-level development for the Next, done on the Next!

Alcoholics Anonymous
Posts: 740
Joined: Mon May 29, 2017 7:00 pm

Re: Z88DK C+Z80 Development Tools

Postby Alcoholics Anonymous » Wed Jun 14, 2017 7:26 pm

Original thread : viewtopic.php?f=8&t=349&start=30#p1873
I don't want to suck the oxygen out of that thread so I'll respond here instead.
This BB is broken somehow so inlining links is not possible sorry :(
Spec-chum wrote:
Wed Jun 14, 2017 8:25 am
It seems much has changed since a lot of the wiki was written, which I was following last night, is there a more up to date idiots guide I may have missed?
Which wiki? :) But yes all the documentation is behind, some more than others. The documentation problem exists because z88dk is a rapidly evolving project and it's still evolving. There have been many changes in the last two years and there will be more coming.

You have to be aware that there are two c libraries which are not equivalent. Each has stuff that the other does not. The classic library is the original and has a long history. The newlib is the re-write for a subset of c11. Eventually after things have settled down the two will be homogenized.

There are two c compilers. The native one is sccz80 and it has a history going back to the 70s as its origin is Ron Cain's small c ( https://en.wikipedia.org/wiki/Small-C ). However, this is the most advanced version of this compiler and can be called nearly c90 but there are some notable deficiencies (among them cannot pass structs by value, multi-dimensional arrays are not supported, some restrictions on prototyping function pointers). The new one is zsdcc which is a customization of sdcc ( https://sourceforge.net/projects/sdcc/ ), an open optimizing c compiler for several small micros. It has better standards compliance (also no passing of structs by value) and generates faster code (and usually smaller code when the appropriate optimization settings are chosen). zsdcc is very slow when optimization is high however. There are still reasons to use sccz80 instead of zsdcc, one being that sccz80 is fast and can be used as the development compiler.

Bob's example is using the classic library and sccz80.

The wiki you were reading is probably the classic library wiki. The library documentation for the classiclib is under the heading "library documentation" on the main wiki page ( https://www.z88dk.org/wiki/doku.php ). Other information on how things work, setting up and so on, are more up-to-date on this wiki page ( https://www.z88dk.org/wiki/doku.php?id=temp:front ) which was intended as the replacement once it was completed. However now that z88dk has moved to github, the intention is to create a wiki there ( https://github.com/z88dk/z88dk/issues/234 ) so that others can contribute but that effort hasn't really started yet.

Someone has started writing a guide for the zsdcc/newlib ( https://github.com/z88dk/z88dk/blob/mas ... Started.md ) combination though only part one is done. There is a technical overview of the newlib and tools ( https://www.z88dk.org/wiki/doku.php?id= ... t_embedded ) for the embedded-z80 target. However for non-technical people this might be too intimidating. Nevertheless it covers a lot of ground, is mostly up-to-date and the embedded-z80 target is the base that other targets (like the zx spectrum) build on. The functions in newlib itself are not really documented anywhere. To find what is in there, it's probably quickest to look at the header files ( http://github.com/z88dk/z88dk/tree/mast ... PMENT/sdcc ) and maybe the z80 source code if you are comfortable with that ( https://github.com/z88dk/z88dk/tree/mas ... EVELOPMENT ). Anyone familiar with c will recognize a lot of the functions there but there are many extensions too.

Examples are best to get going.

Classic library examples ( https://github.com/z88dk/z88dk/tree/master/examples ).
Newlib examples ( https://github.com/z88dk/z88dk/tree/mas ... T/EXAMPLES ).

The classic library supports about 50 different z80 machines, whereas the newlib supports about 6-7 currently, including the zx. The Next will initially have a target in the newlib only ( https://github.com/z88dk/z88dk/issues/244 , https://github.com/z88dk/z88dk/issues/77 ) unless another dev takes it up for classic. I'm sure a classic target will appear once the newlib is done as code can then just be borrowed as necessary.

The classic can support one disk device in compiles which is selected by linking on the compile line. Choices are +3 and microdrive for the zx which doesn't apply to the Next unless residos as opposed to esxdos becomes a thing. The newlib has an object oriented unix io model but disk io is not complete yet so it cannot currently do disk io.

Posts: 36
Joined: Tue May 30, 2017 11:14 am

Re: Z88DK C+Z80 Development Tools

Postby Spec-chum » Wed Jun 14, 2017 9:35 pm

Awesome! Thanks for that great answer!

I assume you're one of the devs? Great work...

I'm comfortable with C and asm and I was browsing the source last night, very impressed and it's clear a huge amount of work has gone into this.

Last night I was using sccz80 with classic and today I've been using zsdcc with newlib, I've managed to get both to work so we're good.

So, kind of a loaded question, but which compiler and lib would you recommend to use going forward?
I'm not insane; my mother had me tested

Who is online

Users browsing this forum: No registered users and 4 guests