[mention]PeterJ[/mention], did you get any further with SP1? I've been looking at it for a few hours now and all I'm getting is bl**dy frustrated!
I was trying to write a simple program which would print a single sprite on the screen. Working forwards (i.e. starting with a blank editor) I just hit crashes, smudges and squiggles.
So I started again with one of the demos and started taking stuff out which didn't seem relevant. I achieved my aim, but have no idea how it works!
My code:
Code: Select all
/*
* zcc +zx -vn -m -startup=31 -clib=sdcc_iy -O3 --max-allocs-per-node200000 one.c graphics.asm -o one -create-app
*/
#pragma output STACKPTR=53248 // place stack at $d000 at startup
#include <arch/zx.h>
#include <arch/zx/sp1.h>
struct sp1_Rect cr = {0, 0, 32, 24}; // rectangle covering the full screen
extern unsigned char ball[];
int main()
{
static struct sp1_ss *s;
zx_border(INK_BLACK);
sp1_Initialize( SP1_IFLAG_MAKE_ROTTBL | SP1_IFLAG_OVERWRITE_TILES | SP1_IFLAG_OVERWRITE_DFILE, INK_BLACK | PAPER_WHITE, ' ' );
sp1_Invalidate(&cr);
s = sp1_CreateSpr(SP1_DRAW_LOAD1LB, SP1_TYPE_1BYTE, 2, 0, 0);
sp1_AddColSpr(s, SP1_DRAW_LOAD1, 0, 8, 0);
sp1_AddColSpr(s, SP1_DRAW_LOAD1RB, 0, 0, 0);
sp1_MoveSprAbs(s, &cr, ball, 10, 14, 0, 4);
sp1_UpdateNow();
return 0;
}
and the graphics.asm file for those following along:
Code: Select all
SECTION rodata_user
PUBLIC _ball
._ball
defb @00111100
defb @01000010
defb @10000001
defb @10000001
defb @10000001
defb @10000001
defb @01000010
defb @00111100
defb 0, 0, 0, 0
defb 0, 0, 0, 0
My original code didn't have the pragma to move the stack pointer. Why is that necessary I wonder? The program just locks up without it.
I tried taking out those flags to the SP1 init routine:
Code: Select all
SP1_IFLAG_MAKE_ROTTBL | SP1_IFLAG_OVERWRITE_TILES | SP1_IFLAG_OVERWRITE_DFILE
and replacing them with a zero. I don't know what any of those do, and there's no documentation for them, so what use could they possibly be?
Turns out that without them the program prints a squiggle on the left side of the screen, but I've no idea why.
The 2 in the call to create the sprite:
Code: Select all
s = sp1_CreateSpr(SP1_DRAW_LOAD1LB, SP1_TYPE_1BYTE, 2, 0, 0);
looks like it should be a 1. I think it means 1 character cell high, which is what my little ball graphic is. Only if I make it a 1 nothing gets shown. So I made it a 2 but I don't understand why.
What do these calls do, I wonder:
Code: Select all
sp1_AddColSpr(s, SP1_DRAW_LOAD1, 0, 8, 0);
sp1_AddColSpr(s, SP1_DRAW_LOAD1RB, 0, 0, 0);
I think this is building the sprite in memory, column by column. But what's the LOAD1 and LOAD1RB mean? And why the 8? Weird things happen if I take these lines out of change them.
In the graphics file the 8 zero bytes after the sprite data are required. A smudge appears next to the graphic if I leave them out. The old spritepack doc suggests they're required for mask data, or maybe rotation data. It's not really clear.
Anyway, enough of my honking. It's just frustration really. Has anyone learnt how to use SP1? If so, how did you go about it?