pouët.net

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.
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.

BB Image
(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?
added on the 2015-09-29 14:13:30 by sol_hsa sol_hsa
What do you mean, "the result doesn't.. quite work". This looks awesome! Ship it!
added on the 2015-09-29 14:19:18 by kusma kusma
what kusma said!
added on the 2015-09-29 14:26:59 by psenough psenough
while I tend to agree, I'd still like to get this to work =)
added on the 2015-09-29 14:31:12 by sol_hsa sol_hsa
nice glitch
added on the 2015-09-29 14:40:39 by g0blinish g0blinish
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:
BB Image
added on the 2015-09-29 17:18:03 by sol_hsa sol_hsa
nooooooooo
added on the 2015-09-29 17:24:47 by psenough psenough
i love the glitch version much more than a planned version)
added on the 2015-09-29 18:06:57 by sq sq
aaanyhoo, I dumped all the crap to github if someone wants something to play with.
added on the 2015-09-29 19:17:18 by sol_hsa sol_hsa
that glitch looks like my planar graphics coding on OCS Amiga.
added on the 2015-09-29 19:19:19 by visy visy
Hmmm... regarding performance... wasn't there a trick on Z80 using the stack pointer to do faster copy instead of ldir?
added on the 2015-10-08 16:13:38 by EvilOne EvilOne
http://stackoverflow.com/a/388442/1520521
added on the 2015-10-08 20:16:33 by yzi yzi

login