QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Fibonacci Sequence Source Code Help

This is a discussion on Fibonacci Sequence Source Code Help within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Ok I just have finished my Fibonacci sequence program, however I am trying to learn more about the meens of ...

Reply
 
LinkBack Thread Tools
Old 01-15-2007, 06:34 AM   #1
 
Join Date: Jul 2005
Posts: 21
Trader Feedback: 0
Default Fibonacci Sequence Source Code Help

Ok I just have finished my Fibonacci sequence program, however I am trying to learn more about the meens of input for the psp.(I am ridiculously new to this).
Without the if statement:
Quote:
if(pad.Buttons & PSP_CTRL_CROSS) {
printf("%3d %6d\n", i, fib[i]);
}
The Program works fine. But with it it does not work...
Here is my source code, can anyone help me?
Quote:
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
PSP_MODULE_INFO("Hello World", 0, 1, 1);
#define printf pspDebugScreenPrintf
SceCtrlData pad;

int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}


int CallbackThread(SceSize args, void *argp) {
int cbid;

cbid = sceKernelCreateCallback(" Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCall back(cbid);

sceKernelSleepThreadCB();

return 0;
}


int SetupCallbacks(void) {
int thid = 0;

thid = sceKernelCreateThread("up date_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid , 0, 0);
}

return thid;
}
int main() {
pspDebugScreenInit();
SetupCallbacks();

int fib[24];
int i;
int loopVar = 1;
fib[0] = 0;
fib[1] = 1;

for(i = 2; i < 24; i++)
fib[i] = fib[i-1] + fib[i-2];
for (i = 0; i < 24; i++)
while(loopVar == 1){
if(pad.Buttons & PSP_CTRL_CROSS) {
printf("%3d %6d\n", i, fib[i]);
}
}
sceKernelSleepThread();
return 0;
}
sahil927 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-15-2007, 07:36 AM   #2


Developer
 
Join Date: Sep 2005
Posts: 480
Trader Feedback: 0
Default

Quote:
Originally Posted by sahil927
Ok I just have finished my Fibonacci sequence program, however I am trying to learn more about the meens of input for the psp.(I am ridiculously new to this).
Without the if statement:
The Program works fine. But with it it does not work...
Here is my source code, can anyone help me?
you need to put sceCtrlPeekBufferPositive or sceCtrlReadBufferPositive to fill the pad structure with the pressed buttons
weltall is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-15-2007, 11:58 AM   #3

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

As weltall said, add
Code:
sceCtrlReadBuffer(&pad,1);

// or

sceCtrlPeekBuffer(&pad,1);
Right after you start the while(loopVar == 1).

P.S. You don't need to put the == 1 there, or anywhere in a comparitive statement for that matter, as all conditions in a comparitive statement are compared to 'true' (1) default. Hence why:
Code:
while(1) { }
works just dandy.
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-15-2007, 12:59 PM   #4
 
Join Date: Nov 2005
Posts: 70
Trader Feedback: 0
Default

This app sounds AWESOME! Are you going to release it soon?!
snmbondagefreak is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-15-2007, 01:22 PM   #5

Developer
 
Raphael's Avatar
 
Join Date: Jan 2006
Location: Germany
Posts: 919
Trader Feedback: 0
Default

Uh... he just did by posting the complete source? Apart from that, it does nothing else then calculate the fibonacci sequence from 0 to 24. Nothing seriously complicated or usefull.

... That's what I call hyping
__________________
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
Raphael is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-15-2007, 04:25 PM   #6
 
Join Date: Jul 2005
Posts: 21
Trader Feedback: 0
Default thanks

Quote:
Originally Posted by Raphael
Uh... he just did by posting the complete source? Apart from that, it does nothing else then calculate the fibonacci sequence from 0 to 24. Nothing seriously complicated or usefull.

... That's what I call hyping
haha completely true...
i would like to thank everyone for there help!
sahil927 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-16-2007, 06:27 AM   #7

Muppet Magnet
 
Fanjita's Avatar
 
Join Date: Sep 2005
Location: Edinburgh, UK
Posts: 2,388
Trader Feedback: 0
Default

I'd be surprised if it works with just that change. Looks to me like the while loop will never exit, and so you'll just print the first number in the sequence, and nothing more.

Assuming that you're trying to display the next item in the sequence when X is pressed, it would be better to do something like:

Code:
for (i = 0; i < 24; i++)
{
  loopVar = 1;
  while(loopVar == 1)
  {
    sceCtrlReadBuffer(&pad,1);
    if(pad.Buttons & PSP_CTRL_CROSS) 
    { 
      printf("%3d %6d\n", i, fib[i]);
      loopVar = 0;

      // the following fragment also helps to avoid lots of numbers with one press, and shows an alternative way to do the loop above.
      while (pad.Buttons & PSP_CTRL_CROSS)
      {
         sceCtrlReadBuffer(&pad, 1);
      }
    }
  }
}
P.S. Indentation fixed for better readability
Fanjita is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-16-2007, 06:31 AM   #8
 
PSP-Maniac's Avatar
 
Join Date: May 2006
Posts: 457
Trader Feedback: 0
Default

i once made a prog for calculating this but i never released it because it only goes to 3000 or sumthing like that because of the size of integers
PSP-Maniac is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-16-2007, 07:46 AM   #9


Developer
 
Join Date: Sep 2005
Posts: 480
Trader Feedback: 0
Default

yes sure but that was what he requested: how to get controller input :P
weltall is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-18-2007, 01:18 PM   #10
 
Join Date: Jul 2005
Posts: 21
Trader Feedback: 0
Default still something wrong

My code currentley:
Quote:
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
PSP_MODULE_INFO("Hello World", 0, 1, 1);
#define printf pspDebugScreenPrintf
SceCtrlData pad;

int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}


int CallbackThread(SceSize args, void *argp) {
int cbid;

cbid = sceKernelCreateCallback(" Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCall back(cbid);

sceKernelSleepThreadCB();

return 0;
}


int SetupCallbacks(void) {
int thid = 0;

thid = sceKernelCreateThread("up date_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid , 0, 0);
}

return thid;
}
int main() {
pspDebugScreenInit();
SetupCallbacks();

int fib[24];
int i;
int loopVar = 1;
fib[0] = 0;
fib[1] = 1;

for(i = 2; i < 24; i++)
fib[i] = fib[i-1] + fib[i-2];
for (i = 0; i < 24; i++)
{
loopVar = 1;
while(loopVar == 1)
{
sceCtrlReadBuffer(&pad,1) ;
if(pad.Buttons & PSP_CTRL_CROSS)
{
printf("%3d %6d\n", i, fib[i]);
loopVar = 0;

// the following fragment also helps to avoid lots of numbers with one press, and shows an alternative way to do the loop above.
while (pad.Buttons & PSP_CTRL_CROSS)
{
sceCtrlReadBuffer(&pad, 1);
}
}
}
}
return 0;
}
Can anyone help me understand this error...
Quote:
make kxploit
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -c -o main.o main.c
main.c: In function 'CallbackThread':
main.c:18: error: 'sceKernelRegisterExitCal l' undeclared (first use in this function)
main.c:18: error: (Each undeclared identifier is reported only once
main.c:18: error: for each function it appears in.)
main.c:18: error: syntax error before 'back'
main.c: In function 'main':
main.c:53: warning: implicit declaration of function 'sceCtrlReadBuffer'
main.c:68:2: warning: no newline at end of file
make: *** [main.o] Error 1
sahil927 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-18-2007, 02:45 PM   #11

Developer
 
Raphael's Avatar
 
Join Date: Jan 2006
Location: Germany
Posts: 919
Trader Feedback: 0
Default

Code:
sceKernelRegisterExitCall back(cbid);
Look how there is a space in the function name - that's obviously not correct.

Also make sure you link -lpspctrl in your makefile.
__________________
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
Raphael is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-18-2007, 05:59 PM   #12
 
Join Date: Jul 2005
Posts: 21
Trader Feedback: 0
Default a little more h elp for a noob

Quote:
sceCtrlReadBuffer(&pad,1) ;
It says i have an undefined reference to this...how do i reference it
sahil927 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-18-2007, 06:47 PM   #13

Muppet Magnet
 
Fanjita's Avatar
 
Join Date: Sep 2005
Location: Edinburgh, UK
Posts: 2,388
Trader Feedback: 0
Default

You need to make sure the libs line in your makefile includes "-lctrl".
Fanjita is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
code , fibonacci , sequence , source

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 04:07 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us