| View previous topic :: View next topic |
| Author |
Message |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Sat Jun 14, 2008 6:50 pm Post subject: [NOOB] what is * after datatype |
|
|
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:
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 |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Sat Jun 14, 2008 7:14 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Sat Jun 14, 2008 7:34 pm Post subject: ok, I will |
|
|
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: |
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspsystimer.h>
PSP_MODULE_INFO("timer",0,1,1);
#define printf pspDebugScreenPrintf
// callbacks omitted
int main(){
pspDebugScreenInit();
SetupCallbacks();
int timerId = sceSTimerAlloc();
int timerValue;
int i;
SceCtrlData pad;
if(timerId<0){
printf("timer not initialized");
}else{
printf("Press [X] To Start the Timer");
while(1){
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CROSS){
break;
}
}
sceSTimerStartCount(timerId);
while(1) {
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CIRCLE) {
break;
}
pspDebugScreenClear();
sceSTimerGetCount(timerId, &timerValue);
printf("Press [O] To Stop the Timer\n");
printf("timer: %i", timerValue);
for(i=0; i<5; i++) {
sceDisplayWaitVblankStart();
}
}
pspDebugScreenClear();
sceSTimerGetCount(timerId, &timerValue);
printf("timer Finished.");
printf("Final Count: %i", timerValue);
}
sceKernelSleepThread();
return 0;
}
|
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 |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Sat Jun 14, 2008 9:31 pm Post subject: |
|
|
the other of your LIBS in your Makefile can be wrong _________________
Upgrade your PSP |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Sat Jun 14, 2008 9:44 pm Post subject: |
|
|
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 :) |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Sat Jun 14, 2008 10:17 pm Post subject: |
|
|
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 :/ _________________
Upgrade your PSP |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Sat Jun 14, 2008 11:43 pm Post subject: |
|
|
| 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 :) |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Sun Jun 15, 2008 8:00 am Post subject: |
|
|
oh I got it now, thanks _________________
Upgrade your PSP |
|
| Back to top |
|
 |
|