Tutorial & Lib for TIM Image/Sprite and BS Image

Graphic based area of development (Graphics Processing Unit), including the Geometry Transform Engine (GTE), TIM, STR (MDEC), etc.
Post Reply
Orion_
Verified
Legendary Programmer
Legendary Programmer
Posts: 240
Joined: Aug 13, 2012
I am a: Programmer
PlayStation Model: Net Yaroze
Location: France
Contact:

Tutorial & Lib for TIM Image/Sprite and BS Image

Post by Orion_ » June 13th, 2013, 3:10 am

I updated my Playstation coding tutorial with VRAM and TIM Image tutorial.
Also my library was updated with some additional samples for using Sprites, Sound and BS Image.
Enjoy :)

Full Tutorial: http://onorisoft.free.fr/psx/tutorial/tuto.htm
My lib: http://onorisoft.free.fr/psx/tutorial/psxlib.zip

With my lib, Loading and drawing a sprite is as simple as that:

Code: Select all

DataManager_Files	game_datas[] =
{
	{"sprite.tim", 0},
	{NULL, 0}
};

#define	SPRITE_TIM	0

int			main(void)
{
	GsOT	*ot;
	int		cputime, gputime;

	System_Init(MODE_PAL, VMODE_16BITS, 320, 240, GsNONINTER, 0);

	DataManager_Init();
	DataManager_LoadDatas("DATA", game_datas);

	Tim_Load(&TIMimage, game_datas[SPRITE_TIM].address);
	Sprite_Init(&Sprite, &TIMimage, SPRITE_NORMAL, 0, 0, 26, 26);
	Sprite_SetPosition(&Sprite, (320-26)/2, (240-26)/2);

	while (!IsPadPress(Pad1Start))
	{
		ot = System_InitFrame();
		Sprite_DrawFast(&Sprite, ot);
		System_DrawFrame(ot, &cputime, &gputime);
	}

	System_Exit();
}
Also loading and drawing a BS Image:

Code: Select all

u_char		bsdata[32*1024];		// BS encoded Image
u_char		imgdata[320*240*3];		// Raw 24 bits decoded Image
u_char		rle_buffer[BS_RLE_BUFFER_SIZE];	// Decode Buffer

int			main(void)
{
	int		i, j = 0;
	GsOT	*ot;
	int		cputime, gputime;

	// Set 24bits mode
	System_Init(MODE_PAL, VMODE_24BITS, 320, 240, GsNONINTER, 0);

	DataManager_Init();
	DataManager_Load("DATA\\EL1_3.BS", bsdata);

	BS_SetClipping(320, 240);
	BS_Decode((u_long *)bsdata, (u_long *)rle_buffer, (u_long *)imgdata, 320, 240, BS_OUTPUT_24BITS);
	BS_Display((u_long *)imgdata, 0, 0, 320, 240, BS_OUTPUT_24BITS, false);

	while (!IsPadPress(Pad1Start))
	{
	}

	System_Exit();
	return (0);
}
Retro game development on Playstation and other consoles http://orionsoft.free.fr/

jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: Aug 13, 2013

Post by jman » October 20th, 2013, 10:33 am

Hello Orion_,

thanks for your library.

There's a an issue however that I cannot quite explain. At first I thought it was somewhere in my code, but then I realized the problem is how I compile your library.

No problem arise if I compile directly everything like you show in your .BAT files, ex:

Code: Select all

set prog=testobj
set address=$80100000
set param=-DCDROM_RELEASE
set lib=%PSXLIB_HEADERS%
ccpsx -I%lib%\. %param% -O2 -Xo%address% %prog%.c %lib%\DataManager.c %lib%\System.c %lib%\Sprite.c -o%prog%.cpe
While if I first compile your library as objects and then link them against my test, ex:

Code: Select all

ccpsx -I%lib%\. -O2 %lib%\System.c -c -o System.o
ccpsx -I%lib%\. -O2 %lib%\Sprite.c -c -o Sprite.o
ccpsx -I%lib%\. -O2 %lib%\DataManager.c -c -o DataManager.o
ccpsx -I%lib%\. %param% -O2 -Xo%address% DataManager.o System.o Sprite.o %prog%.c -o %prog%.cpe
the .PSX file than I put into the CD does not run in the emulator.

What could it be the problem?

Thanks

jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: Aug 13, 2013

Post by jman » October 24th, 2013, 8:34 am

A quick follow-up to provide more details of the issue.
I've tried running a test source in no$psx to take advantage of its command line debug printing.

Compiling all the source files together (see my first example), produces the following output when run in no$psx:

Code: Select all

Nocash PSX Kernel (c) 2008-2013 Martin Korth.
KERNEL SETUP!
Configuration : EvCB=10h TCB=04h
Read Path Table

BOOTSTRAP LOADER Type C Ver 2.1   03-JUL-1994
Read Directory 1
setup file    : cdrom:SYSTEM.CNF;1
TCB     00000004h
EVENT   00000010h
STACK   801FFF00h
BOOT =  cdrom:\MAIN.PSX;1
argument =      
KERNEL SETUP!
Configuration : EvCB=10h TCB=04h
boot file     : cdrom:\MAIN.PSX;1
EXEC:PC0(80108464h) T_ADDR(80100000h) T_SIZE(0000F000h)
boot address  : 80108464h 801FFF00h
Execute !

                S_ADDR(801FFF00h) S_SIZE(00000000h)


PlayStation Lib by Orion_ [2006-2013]
System, DataManager, Sprite, Prim2D, Dialog, BG, Obj3D, Sound, Movie, BSdec.

*** Simulated known Patch: suppress pad_card_auto_ack (even if enabled) (with nops)
*** Simulated known Patch: suppress_pad_error_handling (and get pad_enable) (nops)
PS-X Control PAD Driver  Ver 3.0
Outdated PAD Stuff: TYPE 6 free button or flying-V form (ok)
ResetGraph:jtb=8010d104,env=8010d14c
*** Simulated known Patch: missing_cop0r13 (6-opcode variant)
CD_init:addr=8010e780
while compiling my source against PSXLIB objects (see my second example) produces the following:

Code: Select all

Nocash PSX Kernel (c) 2008-2013 Martin Korth.
KERNEL SETUP!
Configuration : EvCB=10h TCB=04h
Read Path Table

BOOTSTRAP LOADER Type C Ver 2.1   03-JUL-1994
Read Directory 1
setup file    : cdrom:SYSTEM.CNF;1
TCB     00000004h
EVENT   00000010h
STACK   801FFF00h
BOOT =  cdrom:\MAIN.PSX;1
argument =      
KERNEL SETUP!
Configuration : EvCB=10h TCB=04h
boot file     : cdrom:\MAIN.PSX;1
EXEC:PC0(80108134h) T_ADDR(80100000h) T_SIZE(0000D000h)
boot address  : 80108134h 801FFF00h
Execute !

                S_ADDR(801FFF00h) S_SIZE(00000000h)


PlayStation Lib by Orion_ [2006-2013]
System, DataManager, Sprite, Prim2D, Dialog, BG, Obj3D, Sound, Movie, BSdec.

*** Simulated known Patch: suppress pad_card_auto_ack (even if enabled) (with nops)
*** Simulated known Patch: suppress_pad_error_handling (and get pad_enable) (nops)
PS-X Control PAD Driver  Ver 3.0
Outdated PAD Stuff: TYPE 6 free button or flying-V form (ok)
ResetGraph:jtb=8010b15c,env=8010b1a4
*** Simulated known Patch: missing_cop0r13 (6-opcode variant)
CD_init:addr=8010c7c8
DataManager: Loading 'DATA\avatar.tim' at 80010000
*** System Error - Unresolved Exception
*** Excode=00000009h, Epc=801080E8h, ra=80100F64h
Notice the error while trying to retrieve the TIM file.

Also notice that when I create the PS-EXE file the address specified during compiling ($8010000) is correctly returned:

Code: Select all

> cpe2x sprite.cpe
CPE2X Ver1.5
Copyright (C) 1994,1995 by Sony Computer Entertainment Inc.
convert from sprite.cpe to sprite.EXE for Japan area
pc0:80108134 t_addr:80100000  t_size:0000d000
Hope this helps to investigate the issue.

Thanks.

jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: Aug 13, 2013

Post by jman » January 19th, 2014, 10:25 am

I forgot to update this thread with the solution to the issue (it was my fault).
The objects must be compiled with the same flags as of the main executable, example:

Code: Select all

ccpsx -I%lib%\. %param% -O2 %lib%\System.c -c -o System.o
ccpsx -I%lib%\. %param% -O2 %lib%\Sprite.c -c -o Sprite.o
ccpsx -I%lib%\. %param% -O2 %lib%\DataManager.c -c -o DataManager.o
ccpsx -I%lib%\. %param% -O2 -Xo%address% DataManager.o System.o Sprite.o %prog%.c -o %prog%.cpe

User avatar
Greg
Verified
Serious PSXDEV User
Serious PSXDEV User
Posts: 101
Joined: Sep 09, 2013
PlayStation Model: SCPH-7501
Location: Port-au-Prince, HAITI

Post by Greg » September 18th, 2015, 7:57 pm

To compile the bsimage.c exemple from the the lib. add the libpress.lib in the compile.

ccpsx -I%lib%\. %param% -O2 -Xo%address% %prog%.c %lib%\DataManager.c %lib%\System.c %lib%\BSDec.c %lib%\Sprite.c -o%prog%.cpe,,%prog%.map -llibpress.lib
1 x SCPH-7501, 2 x SCPH-7001, 2 x SCPH-5501
1 x Pro Action Replay with "Dual Rom Mod", ROM 1: Caetla, ROM 2: UNIROM
1 x Xplorer V2 with Caetla
1 x GameShark V2.1
1 x GameShark Pro V3.0
1 x CommLinkUSB
1 x XLinkUSB

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests