Need help with pointers

General Programming help in C, C++ or ASM, Compiling / Debugging, and R3000A Central Processing Unit (CPU) information
Post Reply
User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Need help with pointers

Post by LameGuy64 » May 31st, 2013, 7:40 pm

I'm currently working on a 24-bit bitmap loader for experimental purposes and I was able to get it to work but there's something wrong with my CdEasyFileRead function that has something to do with how I treat the pointers (which I'm pretty sure is incorrect).

Attached in this post is a ZIP file that contains the source code, the makefile, and the test picture in RGB24 RAW format that this snipped uses.

Image

Code:

Code: Select all

// Includes
#include <sys/types.h>
#include <memory.h>
#include <libetc.h>
#include <libgte.h>
#include <libgpu.h>
#include <libgs.h>
#include <libcd.h>
#include <stdio.h>


// Some defines
#define OT_LENGTH 8
#define PACKETMAX (2048)      
#define PACKETMAX2 (PACKETMAX*24)   

#define CDBUFFLEN 8192	// CD data buffer length


// Setup the ordering tables
GsOT myOT[2];
GsOT_TAG myOT_TAG[2][1<<OT_LENGTH];
PACKET GPUPacketArea[2][PACKETMAX2];
int ActiveOT;


// For the easy CD reading function
u_char 	CdBuff[CDBUFFLEN];	// Data buffer for easy CD loading
int	CdBufferOffs;		// Offset of the next byte to read within the buffer
int	CdBytesRead;		// The number of bytes read from the buffer


u_char RowBuff[7680];	// 640x4 24-bit chunk

// Bitmap header structure (failed)
/*
typedef struct 
{

	// Entry header
	//char 	id[2];
	short	id;
	int	size;
	short	res1;
	short	res2;
	int	offset;

	// Bitmap header
	int	hsize;
	int	width;
	int	height;
	short	planes;
	short	bpp;
	int	compression;
	int	imagebytes;
	int	xres;
	int	yres;
	int	numcolors;
	int	sigcolors;
	
} bmpheader_struct;

bmpheader_struct bmpheader;
*/


// Prototypes
int main(void);
void Init(void);
void Display(void);
void PrepDisplay(void);
void CdEasyReadFile(char *filename, u_long *destptr, u_long NumBytes);


int main(void)
{

	RECT	RowRect = { 0, 0, 640*3/2, 4 };
	u_char	cdresult=0;

	int vy;

	// Init everything
	Init();


	// Read the first 4 rows of the bitmap
	//CdReadFile("\\bm24test.raw;1", (u_long*)&CdBuff[0], 8192);
	//CdReadSync(0, result);

	CdEasyReadFile("\\bm24test.raw;1", (u_long*)&RowBuff[0], 7680);

	for (vy=0; vy<479; vy=vy+4)
	{

		// Load the chunk into the framebuffer
		RowRect.y = vy;
		LoadImage(&RowRect, (u_long*)&RowBuff[0]);
		DrawSync(0);

		// Load more chunks
		CdEasyReadFile(0, (u_long*)&RowBuff[0], 7680);

	};

}


void Init(void)
{

	DISPENV disp;

	// Initialize the graphics
	ResetGraph(0);
	SetGraphDebug(0);

	SetDefDispEnv(&disp, 0, 0, 640, 480);
	disp.isrgb24 = 1;
	PutDispEnv(&disp);
	SetDispMask(1);

	/*
	GsInitGraph(320, 240, GsNONINTER|GsOFSGPU, 1, 0);
	GsDefDispBuff(0, 0, 0, 240);

	myOT[0].length = OT_LENGTH;
	myOT[1].length = OT_LENGTH;
	myOT[0].org = myOT_TAG[0];
	myOT[1].org = myOT_TAG[1];

	GsClearOt(0, 0, &myOT[0]);
	GsClearOt(0, 0, &myOT[1]);

	ResetGraph(0);
	SetVideoMode(MODE_NTSC);
	SetGraphDebug(0);

	// Clear the screens
	GsSortClear(0, 0, 0, &myOT[0]);
	GsSortClear(0, 0, 0, &myOT[1]);

	// Initialize debug font
	FntLoad(960, 256);
	FntOpen(0, 0, 320, 240, 0, 512);
	*/


	// Initialize the CD drive
	CdInit();

}


void Display(void)
{

	FntFlush(-1);
	DrawSync(0);

	VSync(0);
	GsSwapDispBuff();
	GsSortClear(0, 0, 0, &myOT[ActiveOT]);
	GsDrawOt(&myOT[ActiveOT]);

}


void PrepDisplay(void)
{

	ActiveOT = GsGetActiveBuff();
	GsSetWorkBase((PACKET*)GPUPacketArea[ActiveOT]);
	GsClearOt(0, 0, &myOT[ActiveOT]);

}


void CdEasyReadFile(char *filename, u_long *destptr, u_long NumBytes)
{

	int 	CdDestOffs=0;
	int 	CdCopyBytes=0;
	u_char	CdResult=0;

	/*
	if (filename > 0)
	{
		CdBytesRead = 0;
		CdBufferOffs = 0;
	};
	*/

	while (1)
	{

		if (CdBytesRead <= 0)
		{
			CdReadFile(filename, (u_long*)&CdBuff[0], CDBUFFLEN);
			CdReadSync(0, &CdResult);

			CdBytesRead = CDBUFFLEN;
			CdBufferOffs = 0;
		};


		CdCopyBytes = (NumBytes - CdDestOffs);

		if ((CdDestOffs + CdCopyBytes) > CdBytesRead)	CdCopyBytes = CdBytesRead;
		if ((CdDestOffs + CdCopyBytes) > NumBytes) 	CdCopyBytes = NumBytes - CdDestOffs;

		memcpy(destptr + CdDestOffs, &CdBuff[CdBufferOffs], CdCopyBytes);


		CdBufferOffs = CdBufferOffs + CdCopyBytes;
		CdDestOffs = CdDestOffs + CdCopyBytes;

		CdBytesRead = CdBytesRead - CdCopyBytes;

		if (CdDestOffs >= NumBytes)	break;

	};

}
You do not have the required permissions to view the files attached to this post.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 139
Joined: Dec 19, 2012
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Post by t0rxe » May 31st, 2013, 10:56 pm

There may be a problem in your CD reading routine -> buffer storage. I will load this over my Xplorer soon and see if the problem persists and check out the code more.
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

User avatar
bizarro2011
Serious PSXDEV User
Serious PSXDEV User
Posts: 118
Joined: Mar 27, 2012
Location: Brazil

Post by bizarro2011 » June 1st, 2013, 12:20 am

someone has an editor with image file extension Bs?

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » June 1st, 2013, 2:00 am

bizarro2011 wrote:someone has an editor with image file extension Bs?
Unfortunately, you can't edit those files but you can convert a bitmap image into a BS image using MC32 in your bin folder. BS files are like JPEG images except its MDEC compatible and the file format is most likely similar to STR video files only supporting one frame. The downside is, its as lossy as JPEG and loading such files on the PlayStation might be tricky as it involves using the MDEC processor.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

Orion_
Verified
Legendary Programmer
Legendary Programmer
Posts: 240
Joined: Aug 13, 2012
I am a: Programmer
PlayStation Model: Net Yaroze
Location: France
Contact:

Post by Orion_ » June 1st, 2013, 4:59 am

I have a BS image loader in my library, you can check the code in BSdec.c
Retro game development on Playstation and other consoles http://orionsoft.free.fr/

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 139
Joined: Dec 19, 2012
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Post by t0rxe » June 1st, 2013, 1:48 pm

Awesome. Thanks for the post guys! I will take a look at it.
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » June 1st, 2013, 6:20 pm

Did you guys forget about helping me with this pointer problem? No one seems to cooperate about it at all! Oh well, time to scrap this little project.

I don't really know if this is the proper way to manipulate a pointer:

Code: Select all

memcpy(destptr + CdDestOffs, &CdBuff[CdBufferOffs], CdCopyBytes);
Or no one gives a crap about it...
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 139
Joined: Dec 19, 2012
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Post by t0rxe » June 1st, 2013, 7:47 pm

Looks alight to me. On another note, I tried loading your example over my xplorer, and it failed to display correctly.
Anyway, I got Sony's example working, so I'll remove all the garbage from it and share it soon.
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » June 1st, 2013, 8:39 pm

Have you tried burning the raw image file included in the attached zip file into a CD to get my code to work?

EDIT: Never mind. I managed to fix the problem myself (I used an incorrect pointer type for destptr)...I'll release the fixed code once I add a file selector.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 139
Joined: Dec 19, 2012
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Post by t0rxe » June 1st, 2013, 9:28 pm

No, I didn't burn it to a disc because I am low on them at the moment...

Anyway, here RGB24 all working
http://www.psxdev.net/forum/viewtopic.p ... 2283#p2307
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests