GsBG Problem

Programming examples for the Psy-Q SDK
Post Reply
Zentek
What is PSXDEV?
What is PSXDEV?
Posts: 3
Joined: Aug 08, 2020

GsBG Problem

Post by Zentek » July 16th, 2021, 10:17 pm

Hello to all of you!

So I want to develop some tests and would like to understand how the GsCELLs are initialized. All tests on real hardware tend to crash so I would like what I do wrong?

I want to use GsSortBg because of Background rotation (and I know it's stupid but I don't want to build my own). But How to I init the GsMAP and GsCELL right so that special Tiles are composed to get a background?

Greetings and I hope that I will get some help.

User avatar
mzxtuelkl
Curious PSXDEV User
Curious PSXDEV User
Posts: 20
Joined: Jul 26, 2021
PlayStation Model: SCPH-5501
Location: United States
Contact:

Post by mzxtuelkl » July 26th, 2021, 6:38 pm

Set the "base" member of your GsMAP to point to wherever you stored your CEL file in memory, then set all the other members of the GsMAP accordingly from a BGD file. It's best to check the associated sample in psyq because I've only glanced over it. The sample is called "BGSAMPLE" and is located in C:\psyq\PSX\SAMPLE\GRAPHICS\BG\BGSAMPLE.

Here's the initBG function:

Code: Select all

/*
 *  initialize BG */
void initBG()
{
        u_char *cel;
        u_char *bgd;
	u_char celflag;
	int ncell;
	u_char bgdflag;

        cel = (u_char *)data_cel;        
	cel += 3;
	celflag = *cel++;
	ncell = *(u_short *)cel;	
	cel += 4;

       	bgd = (u_char *)data_bgd;
	bgd += 3;
	bgdflag = *bgd++;

	/* GsMAP struct */
	BGMap.ncellw = *bgd++;
	BGMap.ncellh = *bgd++;
	BGMap.cellw = *bgd++;
	BGMap.cellh = *bgd++;
	BGMap.base = (GsCELL *)cel;
	BGMap.index = (u_short *)bgd;

	/* GsBG struct */
	BGData.attribute = ((TexInfo.pmode&0x03)<<24); /* TexInfo is a GsIMAGE */
	BGData.x = 0;
	BGData.y = 0;
	BGData.scrollx = BGData.scrolly = 0;
	BGData.r = BGData.g = BGData.b = 128;
	BGData.map = &BGMap;
	BGData.mx = 320/2;
	BGData.my = 224/2;
	BGData.scalex = BGData.scaley = ONE;
	BGData.rotate = 0;
	BGData.w = 320;
	BGData.h = 224;

	cel += ncell*8;
	if(celflag&0xc0 == 0x80) {
		cel += ncell;		/* Skip ATTR (8bit) */
	}
	if(celflag&0xc0 == 0xc0) {
		cel += ncell*2;		/* Skip ATTR (16bit) */
	}

	bgd += BGMap.ncellw*BGMap.ncellh*2;
	if(bgdflag&0xc0 == 0x80) {
		bgd += BGMap.ncellw*BGMap.ncellh;
	}
	if(bgdflag&0xc0 == 0xc0) {
		bgd += BGMap.ncellw*BGMap.ncellh*2;
	}
}

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests