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:
- 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);
- 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; - Download and install SDDC from here;
- Download the file S030217_crt0.s from the Files section in the working directory;
- 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:
- customize the crt0.rel file that contains the initialization code for the target system;
- add to the library the function putchar(char c) to send output to the console;
- add to the library the function getchar() to read from the keyboard.
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
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.