[NOOB] what is * after datatype

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Locked
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

[NOOB] what is * after datatype

Post by the underminer »

I am very new to C for PSP, but have quite some experience with lua.

In the image tutorial on psp-programming this datatype was used:

Code: Select all

Image* ourImage;
What's that * doing there?
Also, these forums don't seem to have any structure. (all C related stuff goes in the same place). Is there a subsection for noob stuff like this?[/code][/i]
Behold! The Underminer got hold of a PSP
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

Google "C pointer tutorial". I strongly encourage you to find a good tutorial on C before programming it. C is kinda a high level assembler in some aspects. The pointer through "*" is one of those aspects.

Any variables or functions has an address and they can be accessed through a pointer :

int count1; <--- defines an integer variable

count1 = 10; <--- set the value of this variable to 10

int *count2; <--- defines a pointer on an integer value

count2 = &count1; <--- set the pointer to the address of count1 where 10 was set

*count2 = 20; <--- set the new value of count1 through the pointer count2 to 20

printf("%d", count1); <--- displays teh value of count1, that is, 20 !

Now you should really find a good C tutorial to continue.
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

ok, I will

Post by the underminer »

Good advise. I will do that after this is de-mystified:

I thought I'd edit the timer program to use a proper timer instead of Vblanks to set the value of the counter (now timer)
I looked through the source and found pspsystimer.h in the kernel dir.
I used the functions inside that file.
This is the code:

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspsystimer.h>
PSP_MODULE_INFO&#40;"timer",0,1,1&#41;;

#define printf pspDebugScreenPrintf

// callbacks omitted

int main&#40;&#41;&#123;
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;
	int timerId = sceSTimerAlloc&#40;&#41;;
	int timerValue;
	int i;
	SceCtrlData pad;
	if&#40;timerId<0&#41;&#123;
		printf&#40;"timer not initialized"&#41;;
	&#125;else&#123;
		
		printf&#40;"Press &#91;X&#93; To Start the Timer"&#41;;
		while&#40;1&#41;&#123;
			 sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
			if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;&#123;
				break;
			&#125;
		&#125;
		sceSTimerStartCount&#40;timerId&#41;;
		while&#40;1&#41; &#123;
	   	    sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
	          if&#40;pad.Buttons & PSP_CTRL_CIRCLE&#41; &#123;
	                break;
	          &#125;
			pspDebugScreenClear&#40;&#41;;
			sceSTimerGetCount&#40;timerId, &timerValue&#41;;
	    	  printf&#40;"Press &#91;O&#93; To Stop the Timer\n"&#41;;
	          printf&#40;"timer&#58; %i", timerValue&#41;;
			 for&#40;i=0; i<5; i++&#41; &#123;
	                    sceDisplayWaitVblankStart&#40;&#41;;
	          	&#125;
		&#125;
			pspDebugScreenClear&#40;&#41;;
			sceSTimerGetCount&#40;timerId, &timerValue&#41;;
			printf&#40;"timer Finished."&#41;;
			printf&#40;"Final Count&#58; %i", timerValue&#41;;
	&#125;
	sceKernelSleepThread&#40;&#41;;

	return 0;
&#125;
The compiler didn't complain but when running the eboot from irShell I got a 8002013C error. Google says that's a 'library not found' error. Supposedly caused by the pspsystimer.h.
But the file is in the same directory as pspkernel.h so why shouldn't it be able to find it?
Behold! The Underminer got hold of a PSP
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

the other of your LIBS in your Makefile can be wrong
Image
Upgrade your PSP
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Unfortunately SysTimer is only for kernel application, you cannot use it in this fashion. What you probably want is the RTC stuff (psprtc.h) and use something like sceRtcGetCurrentTick to get a high resolution timer (you can find how many ticks per second are used with sceRtcGetTickResolution).

Of course that being said you really should know how to code C before doing anything as complex as this :)
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

I never understood why can a library in wrong order can have the same error type :|

Everytime I get that error I need to searh my whole code for a kernel-only function and then I need to check the makefile too :/
Image
Upgrade your PSP
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

The issue is if it is a user application those libraries don't exist to be linked to, hence the error. The real issue is with the SDK and in part to the way it developed. Really we need a user only flag (we already have a kernel only flag) which ensures that you can only link in user mode libraries and this issue would go away :)
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

oh I got it now, thanks
Image
Upgrade your PSP
Locked