sdcc zx spectrum problems
category: code [glöplog]
For the fun of it I started looking at compiling c stuff to the zx spectrum, and ran into trouble.
I started off with z88dk, and while that "worked" without problems, eg.
..the result was rather slow. I looked at the generated assembly and it's full of weird function calls even for a simple for loop.
So I grabbed sdcc and tried to find some simple tutorial on how to make stuff for the speccy with it. Lots of stuff about cpc micro, also stuff about gba, but fairly little about zx spectrum itself.
I managed to cobble together stuff that compiles and runs, but the result doesn't.. quite work.
(disregard the "living" horizontal lines, I had variables mapped over the table data; fixing that didn't fix the rest though).
The C code is quite simple: (in a gist here). The tables I've precalculated worked fine with z88dk - ypos is offsets to the screen scanlines (as they're a bit wonky in the speccy), s_png is a 2-screen tall bitmap which you can see rather distorted above, and sinofs is an offset table that will make the bitmap scroll up and down on a sine path.
All pretty basic stuff.
My build script is:
where makezxbin is from here and crt0.s is from here. Appmake is from z88dk, as suggested here.
And no, I'm not going to go 100% assembly (..yet).
Any ideas?
I started off with z88dk, and while that "worked" without problems, eg.
Code:
zcc +zx -O3 -lndos -create-app test.c
..the result was rather slow. I looked at the generated assembly and it's full of weird function calls even for a simple for loop.
So I grabbed sdcc and tried to find some simple tutorial on how to make stuff for the speccy with it. Lots of stuff about cpc micro, also stuff about gba, but fairly little about zx spectrum itself.
I managed to cobble together stuff that compiles and runs, but the result doesn't.. quite work.
(disregard the "living" horizontal lines, I had variables mapped over the table data; fixing that didn't fix the rest though).
The C code is quite simple: (in a gist here). The tables I've precalculated worked fine with z88dk - ypos is offsets to the screen scanlines (as they're a bit wonky in the speccy), s_png is a 2-screen tall bitmap which you can see rather distorted above, and sinofs is an offset table that will make the bitmap scroll up and down on a sine path.
All pretty basic stuff.
My build script is:
Code:
sdasz80 -xlos -g crt0.rel crt0.s
sdcc -c -o app.rel test.c -mz80 --no-std-crt0 --opt-code-speed
sdcc -mz80 --no-std-crt0 --opt-code-speed --nostdlib --code-loc 0x8032 --data-loc 0xc000 -Wl -b_HEADER=0x8000 crt0.rel app.rel
makezxbin <crt0.ihx > test.bin
appmake +zx --binfile test.bin --org 32768
speccy test.tap
where makezxbin is from here and crt0.s is from here. Appmake is from z88dk, as suggested here.
And no, I'm not going to go 100% assembly (..yet).
Any ideas?
What do you mean, "the result doesn't.. quite work". This looks awesome! Ship it!
what kusma said!
while I tend to agree, I'd still like to get this to work =)
nice glitch
Condolences to everyone, the glitch is gone.
The makezxbin (that converts intel hex file to raw binary) was broken. It was written for unix so naturally it borked when run in windows. That explains the random missing bytes in the bitmap.
Here's z88dk and sdcc compiles side by side:
The makezxbin (that converts intel hex file to raw binary) was broken. It was written for unix so naturally it borked when run in windows. That explains the random missing bytes in the bitmap.
Here's z88dk and sdcc compiles side by side:
nooooooooo
i love the glitch version much more than a planned version)
aaanyhoo, I dumped all the crap to github if someone wants something to play with.
that glitch looks like my planar graphics coding on OCS Amiga.
Hmmm... regarding performance... wasn't there a trick on Z80 using the stack pointer to do faster copy instead of ldir?
http://stackoverflow.com/a/388442/1520521