Reinhart's Animation

slinga

Member
Reinhart's Animation

Hey Reinhart,

I've been trying for a while to display 2d sprites on the saturn. Your code seems to be the easiest to follow. Can you explain the following segments of code:

Code:
/*----------------------------------------------------------------------*/

static void set_sprite(PICTURE *pcptr , Uint32 NbPicture)

{

	TEXTURE *txptr;

	for(; NbPicture-- > 0; pcptr++){

 txptr = tex_spr + pcptr->texno;

 slDMACopy((void *)pcptr->pcsrc,

 	(void *)(SpriteVRAM + ((txptr->CGadr) << 3)),

 	(Uint32)((txptr->Hsize * txptr->Vsize * 4) >> (pcptr->cmode)));

	}

}
and

Code:
/*----------------------------------------------------------------------*/

static void disp_sprite(int SpriteNo)

{

	

	slDispSprite((FIXED *)stat[SpriteNo], (SPR_ATTR *)(&attr[SpriteNo].texno), DEGtoANG(0));

	

}

[quote]

/*----------------------------------------------------------------------*/
Also, can you give me some insights into how you converted your picture into a c array? toss? Thanks in advance, and excellent work on your animation. It would also help to have a very basic PDF, or doc, as a tutorial for newbs, similiar to Takashi's original document, but focusing only on displaying a single image.
 

Reinhart

New Member
Reinhart's Animation

That 2 function are copy-paste from the sgl samples.

Basically, set_sprite load sprite into Saturn Memory ans disp_sprite is used to dispay the sprite. The most important is the sprite data located in in anotherfile (where are set size, orientation ...).

I'm using ssconv to convert sprites (toss only for background).

I will try to write a little toturial ...
 

slinga

Member
Reinhart's Animation

Can you explain what PICTURE *pcptr and Uint32 NbPicture are? I think I got everything else.
 

Reinhart

New Member
Reinhart's Animation

Here is a little tutorial

I hope it will answer your question.

It focus on displaying a single sprite (more to come)

Feedbacks, corrections, rewiews are welcome (my engrish may be bad)

I also hope it is good enough to be put in the SatDev section.
 

Reinhart

New Member
Reinhart's Animation

:thumbs-up:

Thanks for the correction.

Let's see how everybody like this before the 'howto display 23 sprites' tutorial.
 

RockinB

Staff member
Reinhart's Animation

Now that this is going to become a tutorial....

...SGL sprites are 16 bits, so why creating them with 24 bit color depth? May be confusing.

...the sprite dimensions don't strictly need to be a multiple of 8, when I remember correctly. Only one dimension must be multiple of 8, but I don't know exactly which of both. You'll have to take a brief look into VDP1 users manual.

... sprite conversion: for completeness, there is the possibility to use the SEGA Converter for Windows. Taken from MineSweeper's README.TXT:

A little more about the SEGA Converter:

Don't give up if it says that the color format is not supported.

Create a new file in Converter, select proper resolution and 32K colors.

Then open the sprite as BMP file, select all, copy and paste into the new file.

Deselect the pasted image and saving will be possible. Save as SGL .c .

Finished!

...maybe you should mention something about bitmap/palette:

The SGL uses 16bits bitmap sprites/textures because of color calculations that are made when displaying 3D objects. This tutorial is not about textures, but sprites. And for sprites it would be much better to use paletted images, because of memory usage. I remember Reinhards stating on his site that he tried to get more sprites managed. Paletted sprites is the solution. But no one did this. What I read is that the used pallete is the same that is registered inside VDP2. But there seems to be another way to place multiple palettes of 16 colors into VDP1 RAM.

Bye,

The Rockin'-B
 

antime

Extra Hard Mid Boss
Reinhart's Animation

Originally posted by Rockin'-B@Sep 16, 2003 @ 08:46 PM

...the sprite dimensions don't strictly need to be a multiple of 8, when I remember correctly. Only one dimension must be multiple of 8, but I don't know exactly which of both.
The width must be a multiple of eight pixels (max 504 pixels) while the height can be given in one-pixel precision (max 255 pixels).

But there seems to be another way to place multiple palettes of 16 colors into VDP1 RAM.
I don't know how/if SGL exposes this, but the "Color Mode" bits in the CMDPMOD command table field must be set to 001. The address of the color table divided by 8 is stored in the CMDCOLR field. The color table can either hold color bank codes (VDP2 palettes) or RGB data. Set the MSB of the color to 1 for it to be interpreted as RGB. If VDP1 is in 8bpp mode (framebuffer rotation or hires) you can only use color bank codes.

Also note that color number zero is used as transparent, unless the disable bit is set. If you enable end codes, you lose another color (number 15 with 4bpp data).

EDIT: Looking at the SGL docs, it seems you can use paletted data by setting the right face/sprite attribute data. The "Mode" should be CL16Look, the lookup table address (divided by 8, I assume) should be given as "Color" and the "Option" should be UsePalette. I think you have to manage the CLUTs yourself, couldn't see any references in the manual.
 

slinga

Member
Reinhart's Animation

Thanks so much guys!! This is exactly what I was looking for.

One small suggestion, in the section 4 of the pdf can we have comments describing the struct member variables?

Code:
#define SPR_ATTRIBUTE(t,c,g,a,d) \

{t,(a)|(((d)>>24)&0xc0),c,g,(d)&0x0f3f}

typedef struct {

   Uint16 texno; // texture for the sprite

   Uint16 atrb; // attribute???

   Uint16 colno; // color code??

   Uint16 gstb; // no clue??

   Uint16 dir; // no clue??

} SPR_ATTR;

#define TEXDEF(h,v,presize) \

{h,v,(cgaddress+(((presize)*4)>>(pal)))/8,(((h)&0x1f8)<<5 | (v))}

typedef struct {

Uint16 Hsize; // horizontal size of the texture?

Uint16 Vsize; // vertical size of the texture?

Uint16 CGadr; // no clue??

Uint16 HVsize; // no clue??

} TEXTURE;

2

#define PICDEF(texno,cmode,pcsrc) \

{(Uint16)(texno),(Uint16)(cmode),(void *)(pcsrc)}

typedef struct {

Uint16 texno; // ??

Uint16 cmode; // color mode??

void *pcsrc; // no clue??

} PICTURE;
 

slinga

Member
Reinhart's Animation

I copy and pasted the code, (I used ring1.c from reinhart's source code). I couldn't get it to compile:

gcc main.c -O2 -m2 -g -c -I../../inc -o main.o

gcc -m2 -L../../lib -Xlinker -T../common/sl.lnk -Xlinker -Map -Xlinker sl.map -X

linker -e -Xlinker ___Start -nostartfiles ../common/cinit.o ../../lib/sglarea.o

main.o -lcd -lsgl -lgfs -o sl.coff

main.o: In function `set_sprite':

main.c:26: undefined reference to `tex_spr'

main.o: In function `disp_sprite':

main.c:33: undefined reference to `attr'

main.o: In function `ss_main':

main.c:46: undefined reference to `tex_spr'

main.c(.text+0xf4): undefined reference to `pic_spr'

make.exe: *** [sl.coff] Error 1

Any ideas as to what I'm doing wrong? :huh

I included scr_data.h, and it compiles fine now. Only thing is I don't see a ring on satourne? Argh I'm going to bed, but good work on the tutorial.

I'll keep trying.
 

vreuzon

New Member
Reinhart's Animation

slinga :

- did you add the file containing your sprites attributes in the OBJECT file ? As the PICTURE, TEXTURE and SPR_ATTR are EXTERN in the main.c, you have to add the relative object file for the link to be successfull.

- parts of the sprites structures are rather unclear to me; someone reading japanese could help by translating the members meaning by translating them from sgl.h (or sl_def, I don't remember)

rockin'b, antime :

thanks for your comments. They've been added to the tutorial.

reinhart : multiple sprites from different arrays, now ? and then paletted sprites ?
 

Attachments

RockinB

Staff member
Reinhart's Animation

Yo slinga,

I think you already know the reason for this compilation error.

No sprite display? I had really, really strange problems like that with the old compiler that you use. Don't want to go into detail, but I very strongly suggest you to take the new kpit compiler. This problem will be eliminated then and you will avoid a lot of wasted time.... .

Good luck,

The Rockin'-B
 

Reinhart

New Member
Reinhart's Animation

Slinga : Check if the initial position of the sprite is not 'outside' of the screen

Vreuzon : I have to make some tries with multiple arrays .

Paleted sprites seems difficult to handle for me ... :(
 

slinga

Member
Reinhart's Animation

*bump*

New compiler. Still no sprite =(

If someone has some free time, please take a look at my files and tell me what I'm doing wrong, I copy and pasted directly from the guide:

Main.c

Code:
/*----------------------------------------------------------------------*/

/* Sprite tutorial 1 */

/*----------------------------------------------------------------------*/

#include "sgl.h"

extern TEXTURE tex_spr[];

extern PICTURE pic_spr[];

extern FIXED stat[][XYZS];

extern SPR_ATTR attr[];

extern ANGLE angz[];

/*----------------------------------------------------------------------*/

/* Set_sprite : register all sprite define in Spr_data.c */

/*----------------------------------------------------------------------*/

static void set_sprite(PICTURE *pcptr , Uint32 NbPicture) {

TEXTURE *txptr;

for(; NbPicture-- > 0; pcptr++){

	txptr = tex_spr + pcptr->texno;

	slDMACopy((void *)pcptr->pcsrc,

	(void *)(SpriteVRAM + ((txptr->CGadr) << 3)),

	(Uint32)((txptr->Hsize * txptr->Vsize * 4) >> (pcptr->cmode)));

	}

}

/*----------------------------------------------------------------------*/

/* disp_sprite : display sprite selected */

/*----------------------------------------------------------------------*/

static void disp_sprite(int SpriteNo) {

slDispSprite((FIXED *)stat[SpriteNo],

(SPR_ATTR *)(&attr[SpriteNo].texno), DEGtoANG(0));

}

/*----------------------------------------------------------------------*/

void ss_main(void)

{

slInitSystem(TV_320x224,tex_spr,1);

//register the sprite, here we only have 1 sprite

set_sprite(pic_spr,1);

while(1) {

//display our sprite (note the first sprite is n\x{00B0} 0)

disp_sprite(0);

slPrint("Hello world", slLocate(5,6));

slSynch();

}

}
spr_data.c

Code:
#include "sgl.h" // library needed

#include "ring1.c" // the sprite you want

SPR_ATTR attr[] =

{

	SPR_ATTRIBUTE(0,No_Palet,No_Gouraud,CL32KRGB|ECdis,sprNoflip),

};

TEXTURE tex_spr[] =

{

//(sprite_width, sprite_height, prev_sprite_width*prev_sprite_height)

	TEXDEF(16,16,0),

};

PICTURE pic_spr[] =

{

//attribute n0, number of color, which sprite to display

	PICDEF(0,COL_32K,ring1),

};

FIXED stat[][XYZS] = {

//Position of ring1 (X_pos, Y_pos, Z_pos(depth), scale)}

{toFIXED(50),toFIXED(-130),toFIXED(169),toFIXED(1.0)}

};

ANGLE angz[] = {

DEGtoANG( 0),

};
ring1.c (taken from Reinhart's contest entry)

Code:
// Source File: ring1.raw

// sprite : 16x16

unsigned short ring1[]	=

{

	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8210, 0x839C, 0x839C, 

	0x839C, 0x839C, 0x839C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x8210, 0x839C, 0x839C, 0x839C, 0x839C, 

	0xF39C, 0xF39C, 0xF39C, 0x839C, 0x839C, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x8108, 0x839C, 0x839C, 0x839C, 0x8108, 0x8108, 

	0x8108, 0x8108, 0x839C, 0xF39C, 0xF39C, 0x839C, 0x0000, 0x0000, 

	0x0000, 0x8108, 0x839C, 0x839C, 0x8210, 0x8210, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x8108, 0x8108, 0x839C, 0xF39C, 0x839C, 0x0000, 

	0x0000, 0x8108, 0x839C, 0x839C, 0x0000, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x0000, 0x8108, 0xF39C, 0x839C, 0x0000, 

	0x8108, 0x839C, 0x839C, 0x8210, 0x0000, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x0000, 0x8108, 0x839C, 0xF39C, 0x839C, 

	0x8108, 0x839C, 0x839C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8108, 0xF39C, 0x839C, 

	0x8108, 0x839C, 0x839C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8108, 0xF39C, 0x839C, 

	0x8108, 0x839C, 0xF39C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8108, 0xF39C, 0x839C, 

	0x8108, 0x839C, 0xF39C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8108, 0x839C, 0x839C, 

	0x8108, 0x8210, 0xF39C, 0x839C, 0x0000, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x0000, 0x8108, 0x8210, 0x839C, 0x8210, 

	0x0000, 0x8108, 0x839C, 0xF39C, 0x0000, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x0000, 0x8210, 0x839C, 0x839C, 0x0000, 

	0x0000, 0x8108, 0x8210, 0x839C, 0xF39C, 0x839C, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x8210, 0x839C, 0x839C, 0x839C, 0x8210, 0x0000, 

	0x0000, 0x0000, 0x8108, 0x8210, 0x839C, 0xF39C, 0xF39C, 0xF39C, 

	0x839C, 0x839C, 0x839C, 0x839C, 0x839C, 0x8108, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x8108, 0x8108, 0x8210, 0x839C, 0x839C, 

	0x839C, 0x839C, 0x8210, 0x8210, 0x8108, 0x0000, 0x0000, 0x0000, 

	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8108, 0x8108, 0x8108, 

	0x8108, 0x8108, 0x8108, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000

};

unsigned long	ring1Size	= 256;
Objects

Code:
# source_program

SRCS = main.c spr_data.c

SYSOBJS = $(CMNDIR)/cinit.o $(SGLLDR)/sglarea.o

OBJS = $(SRCS:.c=.o)

LIBS = -lsgl
And everything compiles without a hitch:

D:\satprog\myProj\SpriteTest>make

sh-coff-gcc main.c -O2 -m2 -g -c -Id:/satprog/sgl/inc -o main.o

main.c:41:2: warning: no newline at end of file

sh-coff-gcc spr_data.c -O2 -m2 -g -c -Id:/satprog/sgl/inc -o spr_data.o

spr_data.c:28:3: warning: no newline at end of file

sh-coff-gcc -m2 -Ld:/satprog/sgl/lib -Xlinker --strip-debug -Xlinker --format=co

ff-sh -Xlinker -T../common/sl.lnk -Xlinker -Map -Xlinker sl.map -Xlinker -e -Xli

nker ___Start -nostartfiles ../common/cinit.o d:/satprog/sgl/lib/sglarea.o main.

o spr_data.o -lsgl -o sl.coff

sh-coff-objcopy -O binary sl.coff sl.bin

I'm guessing I'm missing something in the objects file.
 

mrkotfw

Member
Reinhart's Animation

Code:
{toFIXED(50),toFIXED(-130),toFIXED(169),toFIXED(1.0)}
change it to:

Code:
{toFIXED(0.0),toFIXED(0.0),toFIXED(170.0),toFIXED(1.0)},
and heres mine:

Code:
#include <sgl.h>

#include "monkey1.h"

#include "monkey2.h"

signed long pos_spr[][XYZS]={

{toFIXED(0.0),toFIXED(0.0),toFIXED(170.0),toFIXED(1.0)},

{toFIXED(0.0),toFIXED(0.0),toFIXED(170.0),toFIXED(1.0)}

};

SPR_ATTR atr_spr[]={

SPR_ATTRIBUTE(0,No_Palet,No_Gouraud,CL32KRGB|ECdis,sprNoflip),

SPR_ATTRIBUTE(1,No_Palet,No_Gouraud,CL32KRGB|ECdis,sprNoflip)

};

signed short ang_spr[]={

DEGtoANG(0.0),

DEGtoANG(0.0)

};

TEXTURE tex_spr[]={

TEXDEF(48,48,2304*(0)),

TEXDEF(48,48,2304*(1)) // See, 2304 is the size of the array

                  // Slinga, as you have more sprites you times it.....

};

PICTURE pic_spr[]={

PICDEF(0,COL_32K,monkey1),

PICDEF(1,COL_32K,monkey2)

};
 

slinga

Member
Reinhart's Animation

Hey Piratero,

Thanks for your help. After I made the change you recommended, I see an image in the middle of the screen. It doesn't look correct though, I still think something is wrong. Can I see the source files for your new demo? Thanks in advance.
 
Top