I'm new to the forum. But not to the Spectrum. When I was young, I always wanted to go beyond Basic, but Assembler seemed a bit too harsh for me. Much later, I messed with C on Linux, but got better results with Perl and Python. Using the "fuse"-emulator, I wondered, if I could program the Spectrum in C.
Someone pointed me to the compiler "z88dk".
Yesterday, I could do this:
Code: Select all
#include <stdio.h>
/* toscreen.c */
int main() {
int i;
for (i=16384; i<=18384; i++) {
/* printf("%d\n", i); */
bpoke(i, 25);
}
}
Code: Select all
zcc +zx -clib=ansi -lndos -create-app toscreen.c
This creates a file "a.tap", you can run with "fuse a.tap".
It pokes a pattern into the screen-buffer, just like:
Code: Select all
10 FOR i = 16384 TO 18384
20 POKE i, 25
30 NEXT i
Then I thought about writing a PLOT-function in C. Seems, it's quite tricky to poke in the correct value at the correct address, to set a single point at a certain pixel (you know, how the Spectrum-screen builds up).
Seems, there's a library for z88dk for that. So you can plot like this:
Code: Select all
#include <arch/zx.h>
#include <stdlib.h>
/* plot.c */
void plot(unsigned char x, unsigned char y) {
*zx_pxy2saddr(x,y) |= zx_px2bitmask(x);
}
int main(void) {
unsigned char i;
zx_cls(PAPER_WHITE);
for(i=0; i<15; i++) {
plot(rand() % 256, rand() % 192);
}
return 0;
}
Code: Select all
zcc +zx -vn -clib=new -create-app -zorg=32768 plot.c
That's pretty cool. I can write my code in vim on Linux, and execute it on a (virtual for now) Spectrum.
Of course the .tap would work on a hardware-Spectrum too.
Let's see, what else I can do ...