Close

An automated C language toolchain

A project log for A 4$, 4ICs, Z80 homemade computer on breadboard

No iron, no cry! Build a mini 4MHz Z80 64kB RAM system with Basic and Forth interpreters, CP/M 2.2, QP/M 2.71, Assembler and C toolchains

just4funJust4Fun 02/09/2017 at 21:260 Comments

Here how set up a toolchain to program the Z80-MBC using the C language. It is based on SDCC (Small Device C Compiler) and uses the same "process" of the previous Assembler toolchain.
In the following it is assumed the the Assembler toolchain is already set up in a Windows host as described in in the Log: New iLoad boot mode and an automated Assembler toolchain.
So only the SDCC relevant part is explained here.


Here it is a short video with the toolchain in action:

What you need to do:

  1. Create a working directory (or use the previous one) where to store the C sources and the two batch files (C.BAT and L.BAT) in the C_batch.zip file from the File section (if you are using the same assembler working directory overwrite the previous L.BAT);
  2. With a text editor search the line:
    "C:\Program Files\teraterm\ttermpro.exe" /c=3 /BAUD=9600 /w="Z80-MBC Terminal" /m=LoadZ80.ttl
    inside C.BAT and L.BAT and verify that both the path and the COM number (/c=3 means COM3) meet your system;
  3. Download and install SDDC from here;
  4. Download the file S030217_crt0.s from the Files section in the working directory;
  5. Open the DOS command line and give the command: "sdasz80 -o S030217_crt0.s".
    Then rename the generated S030217_crt0.rel as crt0.rel. Copy it in the SDCC directory "C:\Program Files\SDCC\lib\z80" (may be a bit different in your system) overwriting the old one.

All done!

As usual close Tera Term before every new upload.

To check if it is all ok, download from the File section the file C_demo.zip and unzip it in the working directory.
From the DOS command line give the command: "C Blink.c" to check if all the toolchain works as in the video.
Try also the other demo ANSItest.c (taken from here) to check the ANSI capabilities of a different terminal emulator or a physical terminal:

About SDCC

I'm pretty new to SDCC. The SDCC documentation is 8051 "focused", so the given examples can be misleading if used with an other processor in mind.
When "porting" SDCC to a target HW, there are 3 things to prepare:

I found the documentation quite missing about how to modify for a custom system.
In particular in the provided crt0.s example there isn't a needed global declaration of three variables (l__INITIALIZER, s__INITIALIZED and s__INITIALIZER). Without this declaration the code will not compile.
And to make this customization you need to know how the provided assembler works, but the assembler manual is not provided. So you must find it googling...
If you are used to the Arduino IDE, read carefully the SDCC manual. This C compiler is a lot more "rude" about types and syntax... (as C standard is...).

Last minute update

Just found the assembler and linker documentation here!

Discussions