Need help with reading data off of a file

BIOS, Controllers, Memory Cards, Serial I/O, Parallel I/O, etc.
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 reading data off of a file

Post by LameGuy64 » May 30th, 2013, 1:58 am

I'm currently working on a 24-bit bitmap loader to play around with the unused 24-bit color mode of the PlayStation. The problem is, I can't seem to read the 54 byte header off of a file for some reason.

The code:

Code: Select all

// Includes
#include <sys/types.h>
#include <libapi.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)   


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


// Bitmap header structure
typedef struct 
{

	// Entry header
	char 	id[2];
	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);


int main(void)
{

	int 	handle;
	u_char	cdresult;

	// Init everything
	Init();


	// Read some of the bitmap header
	CdReadFile("cdrom:\\bm24test.bmp;1", (u_long*)&bmpheader, sizeof(bmpheader));
	CdReadSync(0, &cdresult);

	
	while (1)
	{

		PrepDisplay();

		FntPrint("\nTest...\n");
		FntPrint("cdresult=%d\n", cdresult);

		FntPrint("\nHeader results:\n");
		FntPrint("hchar=%d\n", bmpheader.id[0]);
		FntPrint("width=%d\n", bmpheader.width);
		FntPrint("height=%d\n", bmpheader.height);

		Display();

	}

}


void Init(void)
{

	// Initialize the graphics
	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]);

}
I've also attached a zip file which contains the makefile, system.cnf file, and the test 640x480 24-bit bitmap drawn by a friend that this snippet uses.
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.

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_ » May 30th, 2013, 7:14 am

Reading the CdReadFile function documentation in "LIBREF46.PDF", tells you that this function reads by chunk of 2048 bytes (one cd sector)
so if you are asking only 54 bytes, it will read 2048 bytes, and corrupt some data in memory.
also, I don't think "cdrom:" is mandaroty, "\\" will work too.
Retro game development on Playstation and other consoles http://orionsoft.free.fr/

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests