Trying to read the TIM file.

General PSX CD Troubleshooting, PSX CD-ROM Mastering and Disc Creation
Post Reply
User avatar
MihaiGamerXD
Active PSXDEV User
Active PSXDEV User
Posts: 38
Joined: Mar 09, 2019
I am a: Programmer
PlayStation Model: SCPH-1001

Trying to read the TIM file.

Post by MihaiGamerXD » August 25th, 2019, 1:54 am

Hi!
I got another serious problem! I'm trying to read the TIM file using this code:

Code: Select all

if (CdSearchFile(&file,"\\LOGO.TIM;1") {
	CdReadFile("\\LOGO.TIM;1",TIMLogo,nbyte)
	CdReadSync(0,0);
}
But it crashes! Any ideas?

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » August 29th, 2019, 8:21 am

Turn on compiler warnings. You're missing a closing bracket at the end of the first statement.

TIMLogo should be hopefully defined as an unsigned long pointer (you should use malloc for better memory management but that can be worked in later if need be).

Don't use nbyte. Use &fp.size (but it must be a multiple of 2048 so it's probably safer to just set nbyte to 0).
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
MihaiGamerXD
Active PSXDEV User
Active PSXDEV User
Posts: 38
Joined: Mar 09, 2019
I am a: Programmer
PlayStation Model: SCPH-1001

Post by MihaiGamerXD » August 30th, 2019, 2:19 am

Shadow wrote: August 29th, 2019, 8:21 am Turn on compiler warnings. You're missing a closing bracket at the end of the first statement.

TIMLogo should be hopefully defined as an unsigned long pointer (you should use malloc for better memory management but that can be worked in later if need be).

Don't use nbyte. Use &fp.size (but it must be a multiple of 2048 so it's probably safer to just set nbyte to 0).
Ok... I replaced:

Code: Select all

u_long *TIMLogo;
to:

Code: Select all

unsigned long TIMLogo[16384];
And then I deleted nbyte so I used:

Code: Select all

CdReadFile("\\LOGO.TIM;1",TIMLogo[0],&file.size);
I used "&file.size" Because "file" was used from:

Code: Select all

CdlFILE file;
So you were wrong, and it also shows me a warning like this:

Code: Select all

passing arg 3 of "CdReadFile" makes integer from pointer...
Or maybe I was wrong and I need to use something like:

Code: Select all

(int)&file.size
?

I also replaced:

Code: Select all

&file.size
to:

Code: Select all

16384
That was used from "TIMLogo", but it now displays, but the FPS display is glitchy:
FPS Glitch.png
See? What is going on?

The FPS display was used from the previous step, and the next step is to read the TIM file from the CD, and I still need some help, I'm very very new to do that.

And here's the source code, so you can help me.
source.zip
You do not have the required permissions to view the files attached to this post.

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » August 30th, 2019, 4:13 pm

No, you can't use an unsigned long like that. You'd have to use a char. You can use u_long *TIMLogo; but point it to an empty place in memory by doing u_long TIMLogo = 0x80010000; (correct that address if need be). You'll have to make your own malloc routines to assist with dynamic memory management later.

Yes, you will have to cast it, but like I mentioned you can just use an argument of 0 to get the full filesize.

Sounds like the FPS timer is glitchy because you're trashing memory so use the step I mentioned above.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

Yagotzirck
Verified
Extreme PSXDEV User
Extreme PSXDEV User
Posts: 131
Joined: Jul 17, 2013

Post by Yagotzirck » August 30th, 2019, 10:13 pm

Judging from the source you posted, you're trying to read a TIM image by merely compiling the code without creating any disc image whatsoever... If you aren't that familiar with creating psx disc images you're better off embedding the TIM file inside the exe.
Also I don't understand why you're allocating 2048 * 4 = 8 KB for the TIMLogo buffer when the tim image itself is 600 KB? :?

Seriously dude, you look like a hunter who randomly shoots in the air hoping to hit some ducks - stop blindly modifying examples hoping for them to work, read the docs/do some research/strengthen your C knowledge instead of randomly adding stuff and asking for help here for every single thing that doesn't work.
You could keep doing this, but you wouldn't be doing yourself any favour since you aren't learning to approach and solve problems on you own, you're merely delegating the problem's solution to someone else every single time.

Now keep in mind that I'm not telling you to stop asking for help, I'm telling you to at least put some effort on things before immediately making a new thread here, since most of the issues you're having would be solved easily if you only bothered to read Sony's documentation first; then again that's your call.

User avatar
MihaiGamerXD
Active PSXDEV User
Active PSXDEV User
Posts: 38
Joined: Mar 09, 2019
I am a: Programmer
PlayStation Model: SCPH-1001

Post by MihaiGamerXD » August 30th, 2019, 11:48 pm

Yagotzirck wrote: August 30th, 2019, 10:13 pm Judging from the source you posted, you're trying to read a TIM image by merely compiling the code without creating any disc image whatsoever... If you aren't that familiar with creating psx disc images you're better off embedding the TIM file inside the exe.
Also I don't understand why you're allocating 2048 * 4 = 8 KB for the TIMLogo buffer when the tim image itself is 600 KB? :?

Seriously dude, you look like a hunter who randomly shoots in the air hoping to hit some ducks - stop blindly modifying examples hoping for them to work, read the docs/do some research/strengthen your C knowledge instead of randomly adding stuff and asking for help here for every single thing that doesn't work.
You could keep doing this, but you wouldn't be doing yourself any favour since you aren't learning to approach and solve problems on you own, you're merely delegating the problem's solution to someone else every single time.

Now keep in mind that I'm not telling you to stop asking for help, I'm telling you to at least put some effort on things before immediately making a new thread here, since most of the issues you're having would be solved easily if you only bothered to read Sony's documentation first; then again that's your call.
Ok fine, I'll stop asking for help, if you don't! This is it! I'll go myself, no one believe me I'm new!

Yagotzirck
Verified
Extreme PSXDEV User
Extreme PSXDEV User
Posts: 131
Joined: Jul 17, 2013

Post by Yagotzirck » August 31st, 2019, 1:05 am

MihaiGamerXD wrote: August 30th, 2019, 11:48 pm Ok fine, I'll stop asking for help, if you don't! This is it! I'll go myself, no one believe me I'm new!
...Yeah, you totally understood the point of my post :roll:

There's "being new to PSX programming" and "being new to programming in general", and judging by the look of your posts you seem to belong to the latter category; I even asked you how much experience do you have in C a while ago to adapt explanations to your knowledge level, but you diligently dodged the question claiming you "already know programming", so I kept answering your questions assuming you have a decent level of C knowledge but seeing how you keep struggling with relatively simple programming tasks it's quite obvious it's not the case.

The bottom line is you must learn to walk before you can run; PSX programming isn't the kind of stuff you should even think to attempt before having some decent C/low level programming foundations first, unless of course you enjoy stumbling at every single trivial obstacle like you're doing right now.

TL;DR: Don't take the reality check I'm giving you personally, discipline yourself to learn C properly instead, and come back :)

User avatar
MihaiGamerXD
Active PSXDEV User
Active PSXDEV User
Posts: 38
Joined: Mar 09, 2019
I am a: Programmer
PlayStation Model: SCPH-1001

Post by MihaiGamerXD » December 20th, 2019, 2:50 am

Already found out, how to load a TIM file from the CD.
This is the code, on loading a TIM file from the CD:

Code: Select all

//...
#include <libcd.h>
char filebuffer[614424]; //I'll have to use this char for reading file from the CD, but still works.
CdlFILE fp;
//...
int main()
{
	GsIMAGE tim;
	RECT rect;
	
	CdInit();
	
	//...
	if (CdSearchFile(&fp, "\\MY_IMAGE.TIM;1"))
	{
		CdReadFile("\\MY_IMAGE.TIM;1",filebuffer,0);
		CdReadSync(0,0);
	}
	
	GsGetTimInfo((u_long*)(filebuffer+4),&tim);
	
	setRECT(&rect,tim.px,tim.py,tim.pw,tim.ph);
	LoadImage(&rect,tim.pixel);
	setRECT(&rect,tim.cx,tim.cy,tim.cw,tim.ch);
	LoadImage(&rect,tim.pixel);
	
	DrawSync(0);
	
	return 0;
}
Thanks for helping me.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests