z88dk and peripherals (SC126)

156 views
Skip to first unread message

Michael Earls

unread,
Nov 20, 2019, 3:54:40 PM11/20/19
to retro-comp
I have my z88dk development environment up and running and I've been writing some sample code and running it on my SC126, but I can't quite figure out how to address the onboard LEDs. As far as I understand it, all I have to do is write to memory location 0x0D a value between 0x00 and 0xFF.

Here's what I've tried:

while(1==1) {
        int volatile * const p_reg = (int *0xD;
        *p_reg = 0xFF;
    }

I also tried this:

    while(1==1) {
        char *= (char*0x0D;
        *= 1;
    }

When I run the program, it flashes the first LED, but then nothing else happens (that's why I put it in an infinite loop).

What am I misunderstanding? Is it possible to write to peripherals using C and the z88dk?

Thanks,

Michael Earls

Marten Feldtmann

unread,
Nov 20, 2019, 4:14:44 PM11/20/19
to retro-comp
You may use:

#include <z80.h> 

// input
z80_inp(portnumber)

// output

z80_outp(portnumber, value);


Marten

Marten Feldtmann

unread,
Nov 20, 2019, 4:15:56 PM11/20/19
to retro-comp
You hve create a pointer to a memory address, but the IO stuff of the Z80 family is located in the IO space ... you need special intrcutions for that.

Marten

Am Mittwoch, 20. November 2019 21:54:40 UTC+1 schrieb Michael Earls:

Michael Earls

unread,
Nov 20, 2019, 4:33:34 PM11/20/19
to retro-comp
Thank you. The only changes I had to make were for the SC126 (z180).

I used z180.h and the z180_outp(port, data) functions.

Thanks again.

Alan Cox

unread,
Nov 20, 2019, 7:10:13 PM11/20/19
to retro-comp

SDCC also supports its own rather odd syntax but inlines code nicely as a result

__sfr __at 0x0D foo;

(or to force a full 16bit banked)

__sfr __banked __at 0x000D foo;

Phillip Stevens

unread,
Nov 20, 2019, 7:34:07 PM11/20/19
to retro...@googlegroups.com
Only to add to Alan’s comments, that the defined ports for the z88dk scz180 target are found here.

The usage for these defined ports in C is described here in Performing I/O.
The __sfr method results in better code for 8-bit z80 style I/O ports, as the clib library functions always use 16-bit code.

For example for usage.

{
    io_system = 0x01;
uint8_t variable = io_system;
}

There could be other ports that should be added.

Phillip

Harald Nagy

unread,
Nov 21, 2019, 11:20:20 AM11/21/19
to retro-comp
A little bit off-topic, but is there any guide to help setup z88dk for the Sc126 and maybe to rc2014 pro?

Michael Earls

unread,
Nov 21, 2019, 1:39:42 PM11/21/19
to retro...@googlegroups.com
I used the installation instructions on the z88dk wiki:


I am using Visual Studio Code on Windows (it also runs on Linux and mac) to do my development with a custom task to do the build.

Here is the shell command that I use for the sc126:

zcc +scz180 -subtype=app -SO3 -v -m -clib=sdcc_iy -llib/scz180/time --math32_z180 --max-allocs-per-node40000 test.c -o test

From this post.
Reply all
Reply to author
Forward
0 new messages