Developing in C
I am beginning a small project for the ZX Spectrum. I intend to write the thing in C, doing the entire development on PC and then transferring somehow to an emulated ZX Spectrum.
My question is, how best to read and write to the I/O? The operations equivalent to assembly language IN and OUT?
My question is, how best to read and write to the I/O? The operations equivalent to assembly language IN and OUT?
Post edited by wilsonsamm on
Comments
What sort of i/o? There may be functions that do some things for you already.
If you want to do low level i/o as in asm you can:
1. Use inline asm to do the i/o. You may or may not have to do some fiddling to make the C compiler aware of results or to gather the operands for the i/o.
main() { ... #asm ld bc,$xxxx out (c),l ;; where did the value of L come from -- that depends #endasm ... }Related to this is you could make a macro that inlines asm i/o instructions but the operands to the macro must resolve to constants at compile time.
2. The C compiler may have functions that expose z80 i/o. z88dk has the following in the new clib:
The downside is these are functions so the compiler must push params on the stack (sccz80 no if it's one parameter) and call which is much slower than a simple 'out'.
3. sdcc calls the i/o space "special function registers (sfr)" and has special syntax to declare their associate i/o addresses.
__sfr __at 0x78 IoPort; // an 8-bit i/o port at address 0x78 __sfr __banked __at 0x00fe Io_Keys; // a 16-bit i/o port at address main() { ... IoPort = 200; // write 200 to port 0x78 a = Io_Keys; // read port 0x00fe ... }The resulting code is composed of i/o instructions just like you would want.
Write games in C using Z88DK and SP1
just curious