Page 1 of 1

Trying to read the TIM file.

Posted: August 25th, 2019, 1:54 am
by MihaiGamerXD
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?

Re: Trying to read the TIM file.

Posted: August 29th, 2019, 8:21 am
by Shadow
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).

Re: Trying to read the TIM file.

Posted: August 30th, 2019, 2:19 am
by MihaiGamerXD
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

Re: Trying to read the TIM file.

Posted: August 30th, 2019, 4:13 pm
by Shadow
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.

Re: Trying to read the TIM file.

Posted: August 30th, 2019, 10:13 pm
by Yagotzirck
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.

Re: Trying to read the TIM file.

Posted: August 30th, 2019, 11:48 pm
by MihaiGamerXD
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!

Re: Trying to read the TIM file.

Posted: August 31st, 2019, 1:05 am
by Yagotzirck
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 :)

Re: Trying to read the TIM file.

Posted: December 20th, 2019, 2:50 am
by MihaiGamerXD
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.