Sega Genesis Dev Kit (SGDK)

SGDK only sub forum

Moderator: Stef

User avatar
Stef
Very interested
Posts: 2780
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Aug 07, 2014 11:35 am

KanedaFr wrote:ah ah!
About GCC crash, it seems it related to what is already launched when you call it...
I found some details over the net, but since I'm not in GCC source code, I didn't understand everything ;)

with your edit, you deleted the
what about the warning on strcmp ?
which is indeed resolved including "-fno-builtin"
This warning shouldn't occur if you use SGDK included makefile but since I use my own, I had some update to do

It took me 1hour to update to last SGDK, because of lot of refactoring ...
anyway, it's now done ;)
Well i think the GCC bug is resolved on latter version but they just sucks in term of code generation so i won't use them.
The warning on strcmp is normal if you don't use the -fno-builtin... there is nothing to do about it, i don't use the standard library and so i did my own strcmp function :)

Moving to newer SGDK version can take a bit of time, specially if you didn't changed since a long time. I try to avoid refactoring and sometime i keep methods as deprecated as much i can but sometime i have to do changes to improve things.

User avatar
Stef
Very interested
Posts: 2780
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Aug 07, 2014 11:52 am

Hi alko,

It looks like you used Genres from your source file and the first thing i can say is that i don't see where you load the tile from your sprite in the VDP memory so i think that is the reason why your sprite is not displayed.

I would like to warn you that now SGDK has 2 types resource tools and i know it can be confusing :
- genres
- rescomp

Genres was the first one (developed by Kaneda) but i developed rescomp as i wanted something more flexible and cross platform (genres was using DLL files). The wiki tutorial describes Genres but samples provided in SGDK are using the new rescomp :

https://code.google.com/p/sgdk/source/b ... src/main.c

The advantage of the new rescomp : it has more integrated with SGDK, you have many advanced methods to draw image and display sprite easily.

alko
Very interested
Posts: 149
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Post by alko » Fri Aug 08, 2014 3:31 pm

I finally managed to display the sprite with grief in half.
But .... it is creepy curve.
Tile is not correct.

ImageImage

By the way, how can specify the color that would be a video controller is perceived as an alpha channel? (in my case, black color is seen for alpha)

Code:

Code: Select all

#include <genesis.h>


struct genresTiles
{
		u16 *pal; 		//pointer to pal data
		u32 *tiles;		//pointer to tiles data
		u16 width;		//width in tiles
		u16 height;		//height in tiles
		u16 compressedSize; //0 in this demo, more coming soon
};
extern struct genresTiles title;

struct genresSprites
{
		u16 *pal; 		//pointer to pal data
		u32 *tiles;			//pointer to sprites data
		u16 width;		//width of each sprite in pixels
		u16 height;		//height of each sprite in pixels
		u16 size; 		//since we use width/height in pixel, useful info on sprite size
						//TODO : size is not SGDK compliant, you need to use size>>8
						//		will be fixed in coming release
};
extern struct genresSprites bat1;


#define TILE1	1
#define SPRITE1	1

int main( )
{
SpriteDef mySprite;
	
	u8 frame = 0;
	VDP_resetSprites();

	VDP_setPalette(PAL1, title.pal);
VDP_setPalette(PAL2, bat1.pal);
	// load tiles in VRAM
	//  arg0 = tiles data
	//  arg1 = index for first destination tile
	//  arg2 = number of tiles to load
	//  arg3 = use DMA (1) or not (0)
	VDP_loadTileData(title.tiles, TILE1, title.width*title.height, 0);
	VDP_loadTileData(bat1.tiles, SPRITE1, bat1.width*bat1.height, 0);
	VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 0, 0, title.width, title.height);
	
	VDP_setSprite(0, 0, 0, bat1.size, TILE_ATTR_FULL(PAL2,1,0,0,TILE1), 1 /* 0 */);

        
        // define the sprite (using a _spritedef to easily make Sonic move later)
   // define the sprite (using a _spritedef to easily make Sonic move later)
        mySprite.posx = 100;
        mySprite.posy = 100;
      //  mySprite.size = bat1.size>>8;
        mySprite.tile_attr = TILE_ATTR_FULL(PAL2,1,0,0,1);
        mySprite.link  = 0;
   //     VDP_setSpriteP(0, &mySprite);
	while(1)
	{
	 mySprite.posx++;
	 if( mySprite.posx>250) mySprite.posx=0;
	       VDP_setSpriteP(0, &mySprite);
	  VDP_updateSprites();
	VDP_waitVSync();
	}
	return 0;
}
Stef wrote: The advantage of the new rescomp : it has more integrated with SGDK, you have many advanced methods to draw image and display sprite easily.
the fact that in the examples as a sample used multiple sprites in one bmp-file.
It is quite difficult. Firstly, work with pointers to the display area of ​​bmp-file. Secondly, the complex process of constructing such a texture (so accurately position each sprite in a single file).
Much easier it would be (for a beginner like me), if for each sprite was a separate bmp-file

twosixonetwo
Very interested
Posts: 58
Joined: Tue Feb 25, 2014 3:38 pm

Post by twosixonetwo » Sat Aug 09, 2014 7:20 am

IIRC the transparent color on the mega drive is always the first in the palette. Try reordering the colors in the bitmap and it might solve that issue.

alko
Very interested
Posts: 149
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Post by alko » Sun Aug 10, 2014 12:45 pm

what am I doing wrong?

Original picture (56*16 pixels)

ImageImage

Result

ImageImage


main.c

Code: Select all

#include <genesis.h>

struct genresSprites
{
		u16 *pal; 		//pointer to pal data
		u32 **sprites;		//pointer to sprites data
		u16 count;		//nb sprites
		u16 width;		//width of each sprite in pixels
		u16 height;		//height of each sprite in pixels
		u16 size; 		//since we use width/height in pixel, useful info on sprite size
						//TODO : size is not SGDK compliant, you need to use size>>8
						//		will be fixed in coming release
};
extern struct genresSprites bat;


#define TILE1	1

int main( )
{
	SpriteDef mySprite;
	u16 nbTiles = (bat.height) * (bat.width);
	u8 frame = 0;

VDP_loadTileData( bat.sprites[0], TILE1, nbTiles, 0);

	VDP_setPalette(PAL1, bat.pal);

	VDP_resetSprites();
	VDP_setSprite(0, 0, 0, bat.size>>8, TILE_ATTR_FULL(PAL1,1,0,0,TILE1), 1 /* 0 */);
	mySprite.posx = 40;
	mySprite.posy = 40;
	mySprite.size = bat.size>>8;
	mySprite.tile_attr = TILE_ATTR_FULL(PAL1,1,0,0,TILE1+nbTiles);
	mySprite.link  = 0;
	VDP_setSpriteP(2, &mySprite);

	VDP_updateSprites();

	while(1)
	{

		VDP_updateSprites();

		VDP_waitVSync();
		VDP_waitVSync();
		VDP_waitVSync();
	}
	return 0;
}
resource.rc

Code: Select all

SPRITE bat "data/bat.bmp" 56 16 0

Chilly Willy
Very interested
Posts: 2601
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sun Aug 10, 2014 6:03 pm

Your bitmap is too wide. The max width of a sprite is 32. You need to split your bitmap into pieces the correct max width and use multiple sprites to make it.

alko
Very interested
Posts: 149
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Post by alko » Sun Aug 10, 2014 6:55 pm

Thanks.
I should try.

User avatar
KanedaFr
Administrateur
Posts: 1116
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Mon Aug 11, 2014 9:11 pm

It's not a SGDK issue but a Genres one.

I could answer but you should ask on tools section next time.

Code: Select all

SPRITE bat "data/bat.bmp" 56 16 0
isn't valid

only 8/16/24/32 are valid sizes

so for a 56 width sprite, you could use

Code: Select all

SPRITE bat "data/bat.bmp" 32 16 0
this will generate 2 32x16 sprites

next version won't require size so it will generate minimum number of sprites at the best size.

alko
Very interested
Posts: 149
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Post by alko » Tue Aug 12, 2014 11:16 am

Thanks, I already understood.
Now I do not know how to display two or more of the sprite.

I thought to cut my sprite into two parts (32*16 & 24*16 ). And then display both parts. But displayed only the second sprite (SpriteDef b2). In general, something I'm doing wrong again.

Code: Select all

#include <genesis.h> 

struct genresSprites 
{ 
      u16 *pal;       //pointer to pal data 
      u32 **sprites;      //pointer to sprites data 
      u16 count;      //nb sprites 
      u16 width;      //width of each sprite in pixels 
      u16 height;      //height of each sprite in pixels 
      u16 size;       //since we use width/height in pixel, useful info on sprite size 
                  //TODO : size is not SGDK compliant, you need to use size>>8 
                  //      will be fixed in coming release 
}; 
extern struct genresSprites bat1; 
extern struct genresSprites bat2; 


#define TILE1   1 

int main( ) 
{ 
   SpriteDef b1; 
    SpriteDef b2;

	
   u16 nbTiles = (bat1.height) * (bat1.width); 
    u16 nbTiles1 = (bat2.height) * (bat2.width); 
   u8 frame = 0; 

VDP_loadTileData( bat1.sprites[0], TILE1, nbTiles, 0); 
VDP_loadTileData( bat2.sprites[0], TILE1, nbTiles1, 0); 

   VDP_setPalette(PAL1, bat1.pal); 

   VDP_resetSprites(); 
   VDP_setSprite(0, 100, 100, bat1.size>>8, TILE_ATTR_FULL(PAL1,1,0,0,TILE1), 1 /* 0 */); 
   VDP_setSprite(0, 100+32, 100, bat2.size>>8, TILE_ATTR_FULL(PAL1,1,0,0,TILE1), 1 /* 0 */); 
  
   b1.posx = 40; 
   b1.posy = 40; 
   b1.size = bat1.size>>8; 
   b1.tile_attr = TILE_ATTR_FULL(PAL1,1,0,0,TILE1+nbTiles); 
   b1.link  = 0; 
   VDP_setSpriteP(2, &b1);  
   
   b2.posx = 40+32; 
   b2.posy = 40; 
   b2.size = bat1.size>>8; 
   b2.tile_attr = TILE_ATTR_FULL(PAL1,1,0,0,TILE1+nbTiles1); 
   b2.link  = 0; 
   VDP_setSpriteP(2, &b2); 

   while(1) 
   { 
 VDP_setSpriteP(2, &b1);  
    VDP_setSpriteP(2, &b2); 
      VDP_updateSprites(); 
      VDP_waitVSync(); 
   } 
   return 0; 
} 

Zontar
Very interested
Posts: 55
Joined: Fri Oct 21, 2011 8:58 pm

Post by Zontar » Mon Oct 20, 2014 11:11 pm

Is it possible to use the modulo operator (%) in SGDK? I attempt to use it, however, GCC closes with an "undefined reference to `__modsi3'" error.

User avatar
powerofrecall
Very interested
Posts: 237
Joined: Fri Apr 17, 2009 7:35 pm
Location: USA

Post by powerofrecall » Tue Oct 21, 2014 2:59 am

Here's a way around it that that I've used before, for a % b:

Code: Select all

	c = a - b;
	while(c >= b) {
		c = c - b;
	}
modulo is C

It's because in order to be C compliant the 68000 needs some support code for 32 bit divide, modulo, etc. I haven't used SGDK in a while but I think the multiply/divide support code is in there but not the mod

User avatar
Stef
Very interested
Posts: 2780
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Oct 21, 2014 8:01 am

Oh i need to test that, indeed the 32 bits multiply / division are here but maybe the modulo is missing.

User avatar
Stef
Very interested
Posts: 2780
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Oct 21, 2014 7:21 pm

Just tested and the 32 bits modulo does work for me, did you have a special compiler setup ??

Zontar
Very interested
Posts: 55
Joined: Fri Oct 21, 2011 8:58 pm

Post by Zontar » Thu Oct 23, 2014 9:01 pm

Stef wrote:Just tested and the 32 bits modulo does work for me, did you have a special compiler setup ??
I use kubilus' Linux Genesis Dev Setup, so this may be an issue specific to that then.

User avatar
Stef
Very interested
Posts: 2780
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Oct 23, 2014 9:45 pm

Indeed you should probably ask kubilus about it then :)

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests