z88dk SP1 software sprite library
z88dk SP1 software sprite library
Over the years I have had a go with z88dk. I have a basic grasp of C and have been able to write simple text based routines.
I thought I would have a go with graphics and found the sprite library, but can't find any tutorials or documentation (apart from information as to what it is) online:
https://www.z88dk.org/wiki/doku.php?id= ... prites:sp1
I also found the Spectrum specific functions here:
https://www.z88dk.org/wiki/doku.php?id= ... zxspectrum
Would anybody be willing to share some simple examples? (Especially of the uint zx_attr(uchar row, uchar col) and uint zx_screenstr(uchar row, uchar col) functions)
Thanks in advance.
I thought I would have a go with graphics and found the sprite library, but can't find any tutorials or documentation (apart from information as to what it is) online:
https://www.z88dk.org/wiki/doku.php?id= ... prites:sp1
I also found the Spectrum specific functions here:
https://www.z88dk.org/wiki/doku.php?id= ... zxspectrum
Would anybody be willing to share some simple examples? (Especially of the uint zx_attr(uchar row, uchar col) and uint zx_screenstr(uchar row, uchar col) functions)
Thanks in advance.
- bob_fossil
- Manic Miner
- Posts: 654
- Joined: Mon Nov 13, 2017 6:09 pm
Re: z88dk SP1 software sprite library
Hi Peter,
I haven't used the SP1 library so far but it is used here, I think:
https://github.com/z88dk/z88dk/tree/mas ... /BlackStar
Can't vouch for the game itself but the source was useful in getting my head around some of the compiler quirks that can arise when using z88dk and assembly code with the sdcc compiler instead of sccz80.
Bob Fossil
I haven't used the SP1 library so far but it is used here, I think:
https://github.com/z88dk/z88dk/tree/mas ... /BlackStar
Can't vouch for the game itself but the source was useful in getting my head around some of the compiler quirks that can arise when using z88dk and assembly code with the sdcc compiler instead of sccz80.
Bob Fossil
Re: z88dk SP1 software sprite library
I wrote a series of getting started articles for Z88DK earlier this year, but stopped before doing SP1. It's a rather intimidating library which is poorly documented. The docs which are there appear to be a bit out of date.
The examples and Blackstar source are probably your best bet, but learning a library by reading source code isn't easy.
The examples and Blackstar source are probably your best bet, but learning a library by reading source code isn't easy.
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Re: z88dk SP1 software sprite library
Would you be able to post a link to your tutorials? Thanks
Re: z88dk SP1 software sprite library
This is the first one:
https://github.com/z88dk/z88dk/blob/mas ... Started.md
Currently 7 in the series.
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Re: z88dk SP1 software sprite library
This really is a fantastic piece of work. Thank you.
Re: z88dk SP1 software sprite library
Thank you! It's my only contribution to the Speccy scene so I'm grateful for the appreciation.
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Re: z88dk SP1 software sprite library
Do you know FASE ?
It allows coding in z88dk's C and Boriel Basic. It's said to manage many sprites at 50Hz.
Andy Dansby is writing a game making-of on his blog : http://andyspeccysite.simplesite.com
It allows coding in z88dk's C and Boriel Basic. It's said to manage many sprites at 50Hz.
Andy Dansby is writing a game making-of on his blog : http://andyspeccysite.simplesite.com
-
- Microbot
- Posts: 147
- Joined: Fri Nov 24, 2017 5:09 pm
- Location: Syracuse, NY, USA
- Contact:
Re: z88dk SP1 software sprite library
I do have a link for SPLib2 which is older than SP1, but the concepts I believe are the same.
Check out http://www.mojontwins.com/warehouse/splib2-tutorial.pdf
You should be able to carry the concepts of splib to SP1, written by the same person.
I am starting to mess around with FASE, but it always seems to be 1 step forward and 2 steps back. Trying to clear my brain before I start attacking FASE again.
Andy Dansby
Check out http://www.mojontwins.com/warehouse/splib2-tutorial.pdf
You should be able to carry the concepts of splib to SP1, written by the same person.
I am starting to mess around with FASE, but it always seems to be 1 step forward and 2 steps back. Trying to clear my brain before I start attacking FASE again.
Andy Dansby
Re: z88dk SP1 software sprite library
[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:
and the graphics.asm file for those following along:
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:
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:
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:
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?
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;
}
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
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
The 2 in the call to create the sprite:
Code: Select all
s = sp1_CreateSpr(SP1_DRAW_LOAD1LB, SP1_TYPE_1BYTE, 2, 0, 0);
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);
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?
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
- bob_fossil
- Manic Miner
- Posts: 654
- Joined: Mon Nov 13, 2017 6:09 pm
Re: z88dk SP1 software sprite library
I think the stack pointer is important as SP1 uses dynamic memory. The source for the Blackstar example has the following comment in it's zpragma.inc:
Digging into the include file sp1.h, SP1_DRAW_LOAD and so on appear to be function pointers:
So it looks like when you call sp1_AddColSpr you specify a drawing method in the parameters. Don't know if this makes it any clearer? I've found that poorly updated documentation is the curse of the z88dk. Your best bet would be to get into contact with Alvin as he is the font of all z88dk knowledge - or even better, somehow get him to register on this forum. I think he's busy with development on the ZX Spectrum Next these days but I've learnt more about using the z88dk in forum posts with him than I have from anywhere else.
I'm using R-Tape's posted beginners sprite code to write myself a basic sprite handling routine from C that I can understand.
Code: Select all
#pragma output REGISTER_SP = 0xd000 // typical stack location when using sp1
Code: Select all
extern void SP1_DRAW_LOAD1(void); // load sprite 1-byte definition graph only no mask; sw rotation will use LOAD1_NR if no rotation necessary
extern void SP1_DRAW_LOAD1NR(void); // load sprite 1-byte definition graph only no mask; no rotation applied, always drawn at exact tile boundary
extern void SP1_DRAW_LOAD1LB(void); // load sprite 1-byte definition graph only no mask; sw rotation as LOAD1 but for left boundary of sprite only
extern void SP1_DRAW_LOAD1RB(void); // load sprite 1-byte definition graph only no mask; sw rotation as LOAD1 but for right boundary of sprite only
I'm using R-Tape's posted beginners sprite code to write myself a basic sprite handling routine from C that I can understand.