What is the C equivalent function to the Spectrum basic IN and OUT:?

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
Dodger
New member
Posts: 3
Joined: Wed Jan 22, 2020 1:50 pm

What is the C equivalent function to the Spectrum basic IN and OUT:?

Post by Dodger »

Hi All,

What is the C equivalent function to the Spectrum basic IN and OUT:?

Regards

Dodger
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

The best way to do it it to use the __sfr syntax, for 8 bit ports this is:

Code: Select all

__sfr __at 0x1f IO8;

int x = IO8;   // Reads port 0x1f

... 

IO8 = 2;  // Writes 2 to port IO8
And for 16 bit io:

Code: Select all

__sfr __banked __at 0xfff3 IO16;

...

int x = IO16;   // Reads port 0xfff3

IO16 = 2;  // Writes 2 to port IO16
The syntax is supported by both compilers and the IO access is inlined.
Dodger
New member
Posts: 3
Joined: Wed Jan 22, 2020 1:50 pm

Post by Dodger »

Thanks for this

So my code is using for example OUT 3, 1 and OUT 11, 170. What would this be in the syntax example that you gave above?
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

in the example above, IO8=2 equals to OUT($1F),2
Dodger
New member
Posts: 3
Joined: Wed Jan 22, 2020 1:50 pm

Post by Dodger »

I get it now, many thanks!!!
Post Reply