SC114 SDCC Blinking Leds
Table of Contents
SDCC Example For SC114
Recently I had a lot of fun assembling the SC114 Z80 Kit. I admit it’s pretty much useless for any real contemporary task, but I still recommend it as a soothing hobby activity.
One bump I hit was the lack of ready-to-use C examples for SC114 and other RC2014-like computers. Tips in various forums suggested to relocate the program to SRAM by passing the following options to SDCC:
--code-loc 0x8000 --data-loc 0x9000
But that was not enough to get my program to run. When I checked the SDCC crt0.s source code it became evident that the reset vector is hardcoded at address 0:
.area _HEADER (ABS)
;; Reset vector
.org 0
jp init
I could not find a way to override this from the command line.
The Solution
I copied the crt0.s source and removed the address hard-coding. The custom CRT0 source requires an option to override the default one provided by SDCC:
--code-loc 0x8000 --data-loc 0x9000 --no-std-crt0
To load and run my program from the onboard SRAM I relied on the SCMON monitor, which comes preloaded on SC114’s ROM. SCMON recognizes Intel HEX, so all that is needed to load it is to send the file from the host PC:
cat main.s > /dev/ttyUSB0
Finally, to execute the custom program, run the SCMON command to jump to the loaded address:
g 8000
Getting Help From SCMON
SCMON provides useful functionalities which can be called from user programs. This spares me from writing UART drivers or counting cycles to implement my own delay routines.
Yet again I could not find any C wrappers for SCMON, so I wrote my own. This allowed me to print to the serial console from my SDCC C program:
scmon_putline("....\n");
Or add delays between statements:
scmon_delay_ms(100);
Alternatives
SC114 ROM comes pre-programmed with BASIC interpreter. Unfortunately, in my opinion, BASIC programs quickly get hairy when they grow beyond 10 lines of code.
The Z88DK toolchain has C examples for RC2014-like computers, but it’s not packaged for Debian.
Demo
In the video below you can see SC114 Z80 Motherboard Kit with SC129 Digital I/O Module and SC104 Z80 SIO/2 Module.
The animation is generated by the following C program:
#include <stdint.h>
#include "scmon_api.h"
/* SC129 Digital I/O Module Kit for RC2014 */
__sfr __at 0x00 DIO;
/* On-board single LED. */
__sfr __at 0x08 LEDST;
void main(void)
{
int n=0;
while(1) {
/* Ding-dong pattern on SC129 8-bit parallel output. */
DIO= (n >= 8) ? (1 << (15-n)) : (1 << n);
/* Show that we can also control the SC114 single LED. */
LEDST = !!(n & 0x08);
/* Call SCMON Function. */
scmon_delay_ms(100);
if (++n == 16) {
n = 0;
}
}
}
Full source code can be cloned from https://gitlab.com/dinuxbg/sc114-sdcc-hello