[Solved] About programming a 2d game based on TIM format

Graphic based area of development (Graphics Processing Unit), including the Geometry Transform Engine (GTE), TIM, STR (MDEC), etc.
Post Reply
metalex10
What is PSXDEV?
What is PSXDEV?
Posts: 4
Joined: Apr 26, 2021

[Solved] About programming a 2d game based on TIM format

Post by metalex10 » April 27th, 2021, 8:59 pm

Hi people my name is Miguel Ruiz (Metalex) and I'm developing a visual novel called Alternative Reality that will come out for
Ps1, PS2, PS3, PSP, psvita, PS4, Xbox, Xbox360, Xbox one, Xbox Series S | X, nintendo WiiU, nintendo 3DS, nintendo Switch, Android, PC (Steam and Windows Store), Mac, Linux, web

I am currently developing a special engine for the PS1 version but I have a problem is that I do not know if I am doing it wrong but I load three different TIMs for example
MENU.TIM
AR.TIM
HOWTO.TIM

one goes in main, the other is in an int MTLX (VOID)
the other in int MTLXp (VOID)
even there it works but when I add the four VOID
int MTLXr (VOID)

and SCENE1.TIM is when the problem starts

, the point of programming or visual novel is to pass images and lyrics with music.

Obviously I already have it about the images and the music as well, about the programming is where there are problems because when adding the FOUR TEXTURE, in the emulator an illegal code error appears
"r3000: executed illegal opcode 4f1b4f1b"
or
"translate_address: illegal physical address 02a43350"

Postdata.-I load the information of the images through an .asm file
I attach code

main.c

Code: Select all

#include <sys/types.h>
#include <libetc.h>
#include <libgte.h>
#include <inline_c.h>
#include <gtemac.h>
#include <libgpu.h>

#include <LIBPAD.H>
// #define SCR_Z	507		// distant to screen
// #define PADLeft 0x8000
// #define PADDown 0x4000
// #define PADRight 0x2000
// #define PADUp 0x1000
// #define PADStart 0x800
// #define PADR3 0x400
// #define PADL3 0x200
// #define PADSelect 0x100
// #define PADSquare 0x80
// #define PADCross 0x40
// #define PADCircle 0x20
// #define PADTriangle 0x10
// #define PADRB1 0x8
// #define PADLB1 0x4
// #define PADRB2 0x2
// #define PADLB2 0x1
// u_char padData[34]; // Raw pad data
// u_short padButtons = 0; // Complete 16bit button state from bytes 3 & 4 of padData
// u_char padIsAnalog = 0; // boolean for analog detection
// #define PadButtonDown( b ) ((padButtons & b) == 0)

extern unsigned long TIMaddr[];	// background TIM
extern unsigned long TIMaddr1[];	// background TIM
extern unsigned long TIMaddr2[];
extern unsigned long TIMaddr3[];
static u_long PadData;

static void initTexture(unsigned long *timAddr)
	{
	unsigned long bnum;		// number of bytes
	RECT rect;				// LoadImage rectangle
	timAddr++;
	if (*timAddr & 8)				// check CLUT flag
		{
		timAddr++;					// load CLUT info
		bnum = *timAddr;
		timAddr++;
		rect.x = *timAddr & 0xffff;
		rect.y = *timAddr >> 0x10;
		timAddr++;
		rect.w = *timAddr & 0xffff;
		rect.h = *timAddr >> 0x10;
		timAddr++;
		LoadImage(&rect,timAddr);
		timAddr += (bnum >> 2) - 2;
		}
	else
		timAddr += 2;
	rect.x = *timAddr & 0xffff;		// load pixel info
	rect.y = *timAddr >> 0x10;
	timAddr++;
	rect.w = *timAddr & 0xffff;
	rect.h = *timAddr >> 0x10;
	timAddr++;
	LoadImage(&rect,timAddr);
	DrawSync(0);
	}

static void initTexture1(unsigned long *timAddr1)
	{
	unsigned long bnum;		// number of bytes
	RECT rect;				// LoadImage rectangle
	timAddr1++;
	if (*timAddr1 & 8)				// check CLUT flag
		{
		timAddr1++;					// load CLUT info
		bnum = *timAddr1;
		timAddr1++;
		rect.x = *timAddr1 & 0xffff;
		rect.y = *timAddr1 >> 0x10;
		timAddr1++;
		rect.w = *timAddr1 & 0xffff;
		rect.h = *timAddr1 >> 0x10;
		timAddr1++;
		LoadImage(&rect,timAddr1);
		timAddr1 += (bnum >> 2) - 2;
		}
	else
		timAddr1 += 2;
	rect.x = *timAddr1 & 0xffff;		// load pixel info
	rect.y = *timAddr1 >> 0x10;
	timAddr1++;
	rect.w = *timAddr1 & 0xffff;
	rect.h = *timAddr1 >> 0x10;
	timAddr1++;
	LoadImage(&rect,timAddr1);
	DrawSync(0);
	}
static void initTexture2(unsigned long *timAddr2)
	{
	unsigned long bnum;		// number of bytes
	RECT rect;				// LoadImage rectangle
	timAddr2++;
	if (*timAddr2 & 8)				// check CLUT flag
		{
		timAddr2++;					// load CLUT info
		bnum = *timAddr2;
		timAddr2++;
		rect.x = *timAddr2 & 0xffff;
		rect.y = *timAddr2 >> 0x10;
		timAddr2++;
		rect.w = *timAddr2 & 0xffff;
		rect.h = *timAddr2 >> 0x10;
		timAddr2++;
		LoadImage(&rect,timAddr2);
		timAddr2 += (bnum >> 2) - 2;
		}
	else
		timAddr2 += 2;
	rect.x = *timAddr2 & 0xffff;		// load pixel info
	rect.y = *timAddr2 >> 0x10;
	timAddr2++;
	rect.w = *timAddr2 & 0xffff;
	rect.h = *timAddr2 >> 0x10;
	timAddr2++;
	LoadImage(&rect,timAddr2);
	DrawSync(0);
	}
static void initTexture3(unsigned long *timAddr3)
	{
	unsigned long bnum;		// number of bytes
	RECT rect;				// LoadImage rectangle
	timAddr3++;
	if (*timAddr3 & 8)				// check CLUT flag
		{
		timAddr3++;					// load CLUT info
		bnum = *timAddr3;
		timAddr3++;
		rect.x = *timAddr3 & 0xffff;
		rect.y = *timAddr3 >> 0x10;
		timAddr3++;
		rect.w = *timAddr3 & 0xffff;
		rect.h = *timAddr3 >> 0x10;
		timAddr3++;
		LoadImage(&rect,timAddr3);
		timAddr3 += (bnum >> 2) - 2;
		}
	else
		timAddr3 += 2;
	rect.x = *timAddr3 & 0xffff;		// load pixel info
	rect.y = *timAddr3 >> 0x10;
	timAddr3++;
	rect.w = *timAddr3 & 0xffff;
	rect.h = *timAddr3 >> 0x10;
	timAddr3++;
	LoadImage(&rect,timAddr3);
	DrawSync(0);
	}
int main(void)
	{
	int padStatus;
	
	DRAWENV	drawenv;
	DISPENV	dispenv;


	ResetCallback();
	ResetGraph(0);				// reset graphic subsystem (0:cold,1:warm)
	SetGraphDebug(0);			// set debug mode (0:off, 1:monitor, 2:dump)
	PadInit(0);             	// initialise PAD
	InitGeom();					// initialise geometry subsystem
	SetGeomOffset(320, 240);	// set geometry origin
	SetGeomScreen(SCR_Z);		// distance to viewing-screen
	SetDefDrawEnv(&drawenv, 0, 0, 320, 240);  	// initialise environment
	SetDefDispEnv(&dispenv, 0, 0, 320, 240)
	dispenv.isinter = 1;		// interlaced
	drawenv.isbg = 0;			// don't clear background
	SetDispMask(1);				// enable display (0:inhibit, 1:enable)
	PutDrawEnv(&drawenv); 		// update drawing environment
	PutDispEnv(&dispenv); 		// update display environment
	initTexture(TIMaddr);
			// load TIMs
//	VSyncCallback(0);
//	StopCallback();
	ResetGraph(3);
	padStatus = PadRead(1);
		if (padStatus && PADLright)
		{
		MTLX();
		}
	return 0;
	}

int MTLX(void)
	{
	int padStatus;

	DRAWENV	drawenv;
	DISPENV	dispenv;
	ResetCallback();
	ResetGraph(0);				// reset graphic subsystem (0:cold,1:warm)
	SetGraphDebug(0);			// set debug mode (0:off, 1:monitor, 2:dump)
	PadInit(0);             	// initialise PAD
	InitGeom();					// initialise geometry subsystem
	SetGeomOffset(320, 240);	// set geometry origin
	SetGeomScreen(SCR_Z);		// distance to viewing-screen
	SetDefDrawEnv(&drawenv, 0, 0, 320, 240);  	// initialise environment
	SetDefDispEnv(&dispenv, 0, 0, 320, 240);
	dispenv.isinter = 1;		// interlaced
	drawenv.isbg = 0;			// don't clear background
	SetDispMask(1);				// enable display (0:inhibit, 1:enable)
	PutDrawEnv(&drawenv); 		// update drawing environment
	PutDispEnv(&dispenv); 		// update display environment
	initTexture(TIMaddr1);
	padStatus = PadRead(1);
	if (padStatus & PADLright)
		{
		MTLXp();
		}
	else if (padStatus & PADLleft)
		{
		main();
		}
			// load TIMs
//	VSyncCallback(0);
//	StopCallback();
	ResetGraph(3);
	return(0);
	}
int MTLXp(void)
	{
	int padStatus;

	DRAWENV	drawenv;
	DISPENV	dispenv;
	ResetCallback();
	ResetGraph(0);				// reset graphic subsystem (0:cold,1:warm)
	SetGraphDebug(0);			// set debug mode (0:off, 1:monitor, 2:dump)
	PadInit(0);             	// initialise PAD
	InitGeom();					// initialise geometry subsystem
	SetGeomOffset(320, 240);	// set geometry origin
	SetGeomScreen(SCR_Z);		// distance to viewing-screen
	SetDefDrawEnv(&drawenv, 0, 0, 320, 240);  	// initialise environment
	SetDefDispEnv(&dispenv, 0, 0, 320, 240);
	dispenv.isinter = 1;		// interlaced
	drawenv.isbg = 0;			// don't clear background
	SetDispMask(1);				// enable display (0:inhibit, 1:enable)
	PutDrawEnv(&drawenv); 		// update drawing environment
	PutDispEnv(&dispenv); 		// update display environment
	initTexture(TIMaddr2);
	padStatus = PadRead(1);
	if (padStatus & PADLright)
		{
		if (padStatus & PADLright)
		{
		MTLXr();
		}
		}
	else if (padStatus & PADLleft)
		{
		MTLX();
		}
			// load TIMs
//	VSyncCallback(0);
//	StopCallback();
	ResetGraph(3);
	return(0);
	}
int MTLXr(void)
	{
	int padStatus;

	DRAWENV	drawenv;
	DISPENV	dispenv;
	ResetCallback();
	ResetGraph(0);				// reset graphic subsystem (0:cold,1:warm)
	SetGraphDebug(0);			// set debug mode (0:off, 1:monitor, 2:dump)
	PadInit(0);             	// initialise PAD
	InitGeom();					// initialise geometry subsystem
	SetGeomOffset(320, 240);	// set geometry origin
	SetGeomScreen(SCR_Z);		// distance to viewing-screen
	SetDefDrawEnv(&drawenv, 0, 0, 320, 240);  	// initialise environment
	SetDefDispEnv(&dispenv, 0, 0, 320, 240);
	dispenv.isinter = 1;		// interlaced
	drawenv.isbg = 0;			// don't clear background
	SetDispMask(1);				// enable display (0:inhibit, 1:enable)
	PutDrawEnv(&drawenv); 		// update drawing environment
	PutDispEnv(&dispenv); 		// update display environment
	initTexture(TIMaddr3);
	padStatus = PadRead(1);
	if (padStatus & PADLright)
		{
		return(0);
		}
	else if (padStatus & PADLleft)
		{
		MTLXp();
		}
			// load TIMs
//	VSyncCallback(0);
//	StopCallback();
	ResetGraph(3);
	return(0);
}



DATAFILE.ASM

        opt C+
       	section datasection

        global TIMaddr
        cnop 0,4
		global TIMaddr1
        cnop 0,4
		global TIMaddr2
        cnop 0,4
		global TIMaddr3
        cnop 0,4
TIMaddr:
        incbin "MENU.tim"

        cnop 0,4
TIMaddr1:
        incbin "HOWTO.tim"

        cnop 0,4
TIMaddr2:
        incbin "AR.tim"

        cnop 0,4
TIMaddr3:
        incbin "AR.tim"

        cnop 0,4
        

PD.-i solved the problem thx
Last edited by metalex10 on April 30th, 2021, 4:22 pm, edited 1 time in total.

kernex
Interested PSXDEV User
Interested PSXDEV User
Posts: 7
Joined: Mar 14, 2020
I am a: Software engineer & PSX enthusiast
PlayStation Model: SCPH-101
Location: Brazil

Post by kernex » April 28th, 2021, 5:47 am

First, explain what is your goal. Do you wanna show some images on screen? Move them?
Your code is wrong. Why reset the graphic system each time a new image is displayed? You don't need do that.
Where is your game loop for screen refresh?

metalex10
What is PSXDEV?
What is PSXDEV?
Posts: 4
Joined: Apr 26, 2021

Post by metalex10 » April 29th, 2021, 10:25 pm

ok first of all thank you very much for commenting, second the objective I already included it in the post is basically to make a novel visual with TIM Y XA images and audio

where basically MENU.TIM IS the menu, HOWTO is an explanation of how to play, and then it would go to AR.TIM (SCENARIO 1)
WHERE IS THE BACKGROUND and the character and a rectangle for the text, where in turn the name of the character and what it says would go, pressing the right arrow you move forward and pressing the left arrow you go back, as it was opened above,
to all this and it is not to belittle your comment but you say that what I did is wrong, do you have an example or do you know how that would be good?

metalex10
What is PSXDEV?
What is PSXDEV?
Posts: 4
Joined: Apr 26, 2021

Post by metalex10 » April 30th, 2021, 6:44 am

NEVER MINT I SOLVE THE PROBLEM THX

kernex
Interested PSXDEV User
Interested PSXDEV User
Posts: 7
Joined: Mar 14, 2020
I am a: Software engineer & PSX enthusiast
PlayStation Model: SCPH-101
Location: Brazil

Post by kernex » May 20th, 2021, 12:15 am

metalex10 wrote: April 29th, 2021, 10:25 pm ok first of all thank you very much for commenting, second the objective I already included it in the post is basically to make a novel visual with TIM Y XA images and audio

where basically MENU.TIM IS the menu, HOWTO is an explanation of how to play, and then it would go to AR.TIM (SCENARIO 1)
WHERE IS THE BACKGROUND and the character and a rectangle for the text, where in turn the name of the character and what it says would go, pressing the right arrow you move forward and pressing the left arrow you go back, as it was opened above,
to all this and it is not to belittle your comment but you say that what I did is wrong, do you have an example or do you know how that would be good?
All of that can be done with 2D sprites. 'Each' TIM would be a sprite. Can you please post a image or diagram of what would be this project? So, we can help you better.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests