Does a book called "Quick C Programming for the IBM" count? Because that's the only C book I can find in my room.Zitat:
Go and learn C with some books or something..
-= Double Post =-
That book didn't help much.
Printable View
Does a book called "Quick C Programming for the IBM" count? Because that's the only C book I can find in my room.Zitat:
Go and learn C with some books or something..
-= Double Post =-
That book didn't help much.
Well...
Seeing as how no one has helped you and you apparently can't make use of the bountiful resources around you:
PSP Specific:
Code:#include <kernel.h>
...
sceKernelDelayThread ( 4*1000000 /* in micro seconds */ ); // this would delay for 4 seconds
You could also design your app to "delay" and use the time.h or sceRtc functions.
Yea....speaking of timers, yaustar and I tried to figure out a way to successfully use the psprtc to make timers instead of relying on the CPU. I still can't get it to reset everytime i use it.
Zitat:
Zitat von yaustar
Tried reading the PSP SDK documentation yet?Zitat:
Zitat von DJKPSP
What's a sign of a buffer overflow?
My program is acting extremely weird. One day it was working fine - the next, it's completely ****ed and freezes right after the intro. I've tried everything, and it doesn't even make sense.
If I reposition the order of globals(assigned to my Texture struct), some will work, and some won't. Is there some way I can fix this? What do I need to do? I'm desperate here.
Is this the result of a buffer overflow, or something else? It seems to be freezing right when I try to draw the images using the gu.
I have one?Zitat:
Zitat von FreePlay
Then I can't find it.
I found it :) It was a buffer overflow. I was making it loop through 100 slices, when there was only 64 made available!Zitat:
Zitat von Slasher
Wow, I must have spent 2 hours trying to fix it, and it was something as dumb as that...
Don't buffer overflows cause undefined behaviour?Zitat:
Zitat von Slasher
Personally, I'd run it using PSPLink so it can catch the exception - then use addr2line and get a general idea (sometimes more) of what is causing the problem.
Check out triTimer in triEngine.Zitat:
Zitat von TMNT
The overflow must have been leaking into the images memory space, hence causing a freeze up once I tried to render them. I also noticed some funky things going on with some variables when I commented out all the drawing routines.Zitat:
Zitat von SG57
Thanks for that PSPLink tip though! I'll probobly use that next time to pinpoint what's going on.
I'm having a problem...
Ironically, it might have something to do with Slasher's ;)
I've narrowed it down to drawing the scene, not loading. I seem to have gotten it to work 1 time, ever since it's been a failiure.
Here's the info I've gathered:
it's a FPU Exception (yes FPU),
It's in the main_function (more specifically the drawing scene portion).
When tracing the exception back with addr2line and PSPLink i get:
Any ideas?Code:engine::video::BSP_Step2(BspClipVertex*, unsigned short*, engine::video::S3DVert
ex2TCoords const*, unsigned short const*, int, int*, int*)
quick question, how do i suspend/resume user_main thread? due to user_main not actually being defined in the code the compiler comes up with "user_main undeclared .etc". any help would be mad
Are you trying to suspend the user_main in your own program, or in a 3rd party program?
Explain what you're trying to achieve.
If the thread's not from your module, you'll need to know it's UID to be able to do anything.Zitat:
Zitat von Xsjado7
I mean the main thread in my module. The one that handles main()
First of all, here is the code:
When I run the program, no text goes on the screen. (Okay, sometimes the prime numbers between 0 and 200 does) But, I just get a screen saying "primenumbers.exe has encountered an error and needs to close." One of those Windows errors. This was under windows XP. Compiled with MinGW C++ compiler under Code::Blocks IDE.Code://primenumber.cpp
//exercise 2, chapter 3, feb 19, 2008
//Prints out prime numbers with nested for loops
#include <iostream>
using namespace std;
int main()
{
cout << "All prime numbers between 0 and 200.\n\n";
bool primeNumber = false;
for (int i = 0; i < 200; i++)
{
for (int j = 0; j < i; j++)
{
if ( ( i % j ) == 0 )
{
cout << i << " is not a prime a number.";
primeNumber = true;
break;
}
if (!primeNumber)
{
cout << i << " is a prime number." << endl;
}
}
}
cout << "\nThere they are!\n" << endl;
return 0;
}
Don't know if this will fix it (probably won't), but you have to set primeNumber to false at the beginning of each loop, otherwise it will always stay true after the first prime number is encountered.Zitat:
Zitat von michaelp
It didn't, but thanks for pointing that out. :)
This should work, but is untested.Zitat:
Zitat von Xsjado7
Code:SceUID myThread = sceKernelGetThreadId();
sceKernelSuspendThread(myThread);
Thank you! I havent tried it yet but i will when i get access to my source and a compiler. I shoulda thought of something like that :D
-= Double Post =-
Works a treat Insert_Witty_Name, thanks again :)
You can also define another thread, load that and work your main code from there, placing the UID into either a global variable/struct, or sending the UID in the argp args. Just remember to run sceKernelExitDeleteThread (0); when you've gone to the other thread.
Is there any way to free up memory allocated in a function using int, char [], and so on, without returning? Obviously free doesn't work because its not malloc'ed data, but I was wondering if there were any easier ways than malloc'ing the data and then free'ing the data at the end of the function? I want this basically because I have a function that is pretty much a bridging function, but it needs some variables to function correctly, and rather than restructure all the coding or leave a memory leak, I'm trying to explore easier but safe ways of doing getting it back.
Thanks.
-Aura
Use scoping rules:Zitat:
Zitat von Auraomega
Code:void function()
{
int foo;
{
int blah;
char gah;
}
// blah and gah are popped off the stack
}
[email protected] ~/psptoolchain
$ svn update
Skipped '.'
I installed Cygwin, and I try to do svn update and I get this. ?
I didn't do ./toolchain.sh, as yeldarb's tutorial said to do this first.
It will say skipped if its already up to date.
Move on to the next step.
[email protected] ~/psptoolchainZitat:
Zitat von hibbyware
$ ./toolchain.sh
../depends/check-autoconf.sh: line 5: autoconf: command not found
ERROR: Install autoconf before continuing.
../depends/check-autoconf.sh: Failed.
~_~
Wow thanks, I can't believe I never knew that, but thinking about it is a pretty sensible assumption to make, this will come in VERY handy :tup:Zitat:
Zitat von yaustar
-Aura
Go back and setup cygwin with all the packages that are needed.Zitat:
Zitat von PSPduh
autoconf is one of those packages. read the tutorial again.
Stupid question:
What is a float?
Example:
float Gravity = 1.0;
Why not use:
int Gravity = 1.0;
*slaps forehead* A float is a variable that can hold a floating point value (a decimal value, as in 32.45) And you can't use int, because int is for integers, or whole numbers.Zitat:
Zitat von TMNT
*slaps balls*Zitat:
Zitat von Judas
Edit: Shi*...i ruptured my epididymus.
Ok, here is my coding style, how can i improve it? Just don't say indents.
Yes, i am working on SG57's project, Be Thou for the People. If you need my current beta, just ask.
Code:#include <oslib/oslib.h>
#include <psprtc.h>
#define print oslPrintf_xy
#define Load_Sound oslLoadSoundFile
#define Stop_Sound oslStopSound
#define Load_Image oslLoadImageFile
#define Load_Font oslLoadFontFile
#define blit oslDrawImageXY
#define wait sceKernelDelayThread
#define WHITE RGBA(255,255,255,255)
#define BLACK RGBA(0,0,0,255)
#define GREEN RGBA(0,255,0,255)
#define BLUE RGBA(0,0,255,255)
#define RIGHT 2
#define LEFT 1
PSP_MODULE_INFO("Be Thou for the People", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
/*************************************************
Center Text
**************************************************/
void printcenter ( int y, char* text )
{
auto int textLength = strlen(text);
auto int x = 240 - (( textLength * 8 ) / 2 );
print( x , y , text );
}
/***************************************************************************************************
****************************************************************************************************
****************************** ************************************
****************************** Menu ************************************
****************************** ************************************
****************************** ************************************
****************************************************************************************************/
int menu()
{
/****************************
Initialize
*****************************/
oslInit(0);
oslInitGfx(OSL_PF_5650, 1);
oslInitConsole();
oslInitAudio();
oslAudioVSync();
/****************************
Loading
*****************************/
OSL_SOUND *click, *motherland, *music, *kick, *run, *jump;
OSL_IMAGE *background, *credits, *opening, *Ed, *level1;
OSL_FONT *myfont, *myfont2;
//Images
background = Load_Image("./files/Menu/background.png", OSL_IN_RAM, OSL_PF_5650);
credits = Load_Image("./files/Menu/credits.png", OSL_IN_RAM, OSL_PF_5650);
opening = Load_Image("./files/Game/Other/Opening.png", OSL_IN_RAM, OSL_PF_5650);
level1 = Load_Image("./files/Game/Maps/1/background.png", OSL_IN_RAM, OSL_PF_5650);
oslSetTransparentColor(RGB(255,0,255));
Ed = Load_Image("./files/Game/Characters/Ed/Ed.png", OSL_IN_RAM, OSL_PF_5650);
//Sounds
click = Load_Sound("./files/Menu/click.wav", OSL_FMT_NONE);
motherland = Load_Sound("./files/Menu/motherland.wav", OSL_FMT_NONE);
music = Load_Sound("./files/Game/Sounds/Music.wav", OSL_FMT_NONE);
kick = Load_Sound("./files/Game/Sounds/kick.wav", OSL_FMT_NONE);
run = Load_Sound("./files/Game/Sounds/run.wav", OSL_FMT_NONE);
jump = Load_Sound("./files/Game/Sounds/jump.wav", OSL_FMT_NONE);
//Fonts
myfont = Load_Font("./files/Menu/font.oft");
myfont2 = Load_Font("./files/Menu/font2.oft");
/****************************
File Check
*****************************/
//If can't load in RAM, display error
if (!background || !credits || !opening || !Ed || !level1) { oslDebug("Error: Could not load one or more images"); }
if (!click || !motherland || !music || !kick || !run || !jump) { oslDebug("Error: Could not load one or more music files"); }
//if (motherland) { oslSetSoundLoop(motherland, 1); oslPlaySound(motherland, 1);}
//if (music) { oslSetSoundLoop(music, 1); oslPlaySound(music, 1);}
if (!myfont || !myfont2) { oslDebug("Error: Could not load the font files"); }
//Text Color
//oslSetTextColor(RGBA(255,0,0,128));
if (myfont || !myfont2) { oslSetFont(myfont); oslSetBkColor(RGBA(0,0,0,0)); }
/****************************
Variables
*****************************/
//Credits
int ShowCredits = 4; //1 - credits, 0 - menu, 2 - introduction, 3 - animation, 4 - game
int Alpha = 1;
int FadeIn = 1;
//Menu
int MenuStatus = 1;
int SelectionPosition = 6;
int SelectionMove = 0;
//Animation
int AnimationPosition = 109;
//Level Information
int ShowTime = 0;
int PlayerFacing = RIGHT;
int PlayerStatus = 1;
int PlayerPosX = 5;
int PlayerPosY = 196;
int PlayerOffsetX = 0;
int PlayerOffsetY = 0;
int PlayerWidth = 0;
int PlayerHeight = 0;
int StandingTimer = 0;
int RunningTimer = 0;
int KickTimer = 0;
int JumpTimer = 0;
/**************************************************
While Loop
***************************************************/
while (!osl_quit)
{
//Enables
oslStartDrawing();
oslReadKeys();
oslCls();
if (ShowCredits == 1) {
oslSetAlpha(OSL_FX_ALPHA,Alpha);
blit(credits, 0, 0);
if (FadeIn == 1) { Alpha++; }
else if (FadeIn == 0) { Alpha--; }
if (Alpha > 254) { wait(3000000); FadeIn = 0; }
else if (Alpha < 1) { Alpha = 0; ShowCredits = 0; }
}
else if (ShowCredits == 0) {
oslSetAlpha(OSL_FX_ALPHA,Alpha);
blit(background, 0, 0);
if (Alpha < 255) { Alpha++; }
if (MenuStatus == 1) {
if (SelectionMove == 0) { SelectionPosition--; }
if (SelectionMove == 1) { SelectionPosition++; }
if (SelectionPosition < -7) { SelectionMove = 1; }
if (SelectionPosition > 7) { SelectionMove = 0; }
oslSetTextColor(GREEN); oslSetFont(myfont);
print((480/3*0.5-32) + (SelectionPosition), 242, "Continue");
oslSetTextColor(WHITE); oslSetFont(myfont);
print(480/3*1.5-32, 242, "New Game");
oslSetTextColor(WHITE); oslSetFont(myfont);
print(480/3*2.5-16, 242, "Exit");
}
else if (MenuStatus == 2) {
if (SelectionMove == 0) { SelectionPosition--; }
if (SelectionMove == 1) { SelectionPosition++; }
if (SelectionPosition < -7) { SelectionMove = 1; }
if (SelectionPosition > 7) { SelectionMove = 0; }
oslSetTextColor(WHITE); oslSetFont(myfont);
print(480/3*0.5-32, 242, "Continue");
oslSetTextColor(GREEN); oslSetFont(myfont);
print((480/3*1.5-32) + (SelectionPosition), 242, "New Game");
oslSetTextColor(WHITE); oslSetFont(myfont);
print(480/3*2.5-16, 242, "Exit");
}
else if (MenuStatus == 3) {
if (SelectionMove == 0) { SelectionPosition--; }
if (SelectionMove == 1) { SelectionPosition++; }
if (SelectionPosition < -7) { SelectionMove = 1; }
if (SelectionPosition > 7) { SelectionMove = 0; }
oslSetTextColor(WHITE); oslSetFont(myfont);
print(480/3*0.5-32, 242, "Continue");
oslSetTextColor(WHITE); oslSetFont(myfont);
print(480/3*1.5-32, 242, "New Game");
oslSetTextColor(GREEN); oslSetFont(myfont);
print((480/3*2.5-16) + (SelectionPosition), 242, "Exit");
}
/***********************
Controls
************************/
if (osl_pad.pressed.cross)
{
if (MenuStatus == 2)
{
Stop_Sound(motherland);
ShowCredits = 2;
}
if (MenuStatus == 3)
{
oslEndGfx();
oslQuit();
}
}
if ( (osl_pad.pressed.left) && (MenuStatus > 1) )
{
MenuStatus--; oslPlaySound(click, 2);
}
if ( (osl_pad.pressed.right) && (MenuStatus < 3) )
{
MenuStatus++; oslPlaySound(click, 2);
}
}
else if (ShowCredits == 2) {
ShowTime++;
oslSetFont(myfont2); oslSetBkColor(RGBA(0,0,0,0)); oslSetTextColor(GREEN);
printcenter(40, "Level 1");
oslSetTextColor(RGBA(0,255,255,255));
printcenter(65, "Part 1");
oslSetTextColor(RGBA(255,255,0,255));
printcenter(120, "To Challenge the Sun");
oslSetTextColor(WHITE); oslSetFont(myfont);
print(170, 170, "Fight through the onslaught of");
print(170, 190, "attacking lizards to the strange");
print(170, 210, "desert city where Cornello is said");
print(170, 230, "to posess a Philosoper's Stone...");
if (ShowTime > 300) { ShowTime = 0; ShowCredits = 3; }
}
else if (ShowCredits == 3)
{
AnimationPosition -= .1;
oslSetImageTileSize (opening, 0, AnimationPosition, 480, 135);
blit(opening, 0, 68);
oslSetFont(myfont2); oslSetBkColor(RGBA(0,0,0,0)); oslSetTextColor(BLUE);
printcenter(235, "Cornello, here I come...");
if (AnimationPosition < 1) { AnimationPosition = 109; ShowCredits = 4; }
}
/***************************************************************************************************
****************************************************************************************************
****************************** ************************************
****************************** Game ************************************
****************************** ************************************
****************************** ************************************
****************************************************************************************************/
else if (ShowCredits == 4)
{
/*****************************
Standing Timer
******************************/
StandingTimer++;
if (StandingTimer > 0) { PlayerStatus = 1; StandingTimer++; }
if ( (StandingTimer > 40) && (StandingTimer < 80) ) { PlayerStatus = 2; StandingTimer++; }
if ( (StandingTimer > 80) && (StandingTimer < 120) ) { PlayerStatus = 3; StandingTimer++; }
if (StandingTimer > 120) { StandingTimer = 1; StandingTimer++; }
/*****************************
Running Timer
******************************/
if (RunningTimer > 0) { PlayerStatus = 4; }
if ( (RunningTimer > 10) && (RunningTimer < 20) ) { PlayerStatus = 5; oslPlaySound(run, 2); }
if ( (RunningTimer > 20) && (RunningTimer < 30) ) { PlayerStatus = 6; }
if (RunningTimer > 30) { RunningTimer = 1; }
/*****************************
Kicking Timer
******************************/
if (KickTimer > 0) { PlayerStatus = 7; KickTimer++; }
if ( (KickTimer > 10) && (KickTimer < 20) ) { PlayerStatus = 8; KickTimer++; oslPlaySound(kick, 2); }
if ( (KickTimer > 20) && (KickTimer < 40) ) { PlayerStatus = 9; KickTimer++; }
if (KickTimer > 45) { KickTimer = 0; }
/*****************************
Jumping Timer
******************************/
if (JumpTimer > 0) { PlayerStatus = 10; PlayerPosY -= 5; JumpTimer++; }
if ( (JumpTimer > 10) && (JumpTimer < 20) ) { PlayerPosY -= 2; }
if ( (JumpTimer > 20) && (JumpTimer < 30) ) { PlayerPosY += 2; }
if ( (JumpTimer > 30) && (JumpTimer < 40) ) { PlayerPosY += 5; }
if (JumpTimer > 40) { JumpTimer = 0; }
/*****************************
Ed Attributes
******************************/
//Player Standing
if (PlayerStatus == 1) { PlayerOffsetX = 3; PlayerOffsetY = 2; PlayerWidth = 38; PlayerHeight = 55; }
if (PlayerStatus == 2) { PlayerOffsetX = 48; PlayerOffsetY = 2; PlayerWidth = 38; PlayerHeight = 55; }
if (PlayerStatus == 3) { PlayerOffsetX = 92; PlayerOffsetY = 2; PlayerWidth = 37; PlayerHeight = 55; }
//Player Running
if (PlayerStatus == 4) { PlayerOffsetX = 133; PlayerOffsetY = 1; PlayerWidth = 48; PlayerHeight = 56; }
if (PlayerStatus == 5) { PlayerOffsetX = 187; PlayerOffsetY = 1; PlayerWidth = 37; PlayerHeight = 56; }
if (PlayerStatus == 6) { PlayerOffsetX = 224; PlayerOffsetY = 1; PlayerWidth = 47; PlayerHeight = 56; }
//Player Kicking
if (PlayerStatus == 7) { PlayerOffsetX = 286; PlayerOffsetY = 1; PlayerWidth = 37; PlayerHeight = 56; }
if (PlayerStatus == 8) { PlayerOffsetX = 335; PlayerOffsetY = 1; PlayerWidth = 37; PlayerHeight = 56; }
if (PlayerStatus == 9) { if (PlayerFacing == LEFT) { PlayerPosX = PlayerPosX - 1; } PlayerOffsetX = 378; PlayerOffsetY = 1; PlayerWidth = 55; PlayerHeight = 56; }
//Player Jumping
if (PlayerStatus == 10) { PlayerOffsetX = 4; PlayerOffsetY = 63; PlayerWidth = 30; PlayerHeight = 57; }
//Player Hurt
if (PlayerStatus == 11) { PlayerOffsetX = 43; PlayerOffsetY = 67; PlayerWidth = 40; PlayerHeight = 54; }
if (PlayerStatus == 12) { PlayerOffsetX = 85; PlayerOffsetY = 67; PlayerWidth = 41; PlayerHeight = 53; }
if (PlayerStatus == 13) { PlayerOffsetX = 135; PlayerOffsetY = 70; PlayerWidth = 37; PlayerHeight = 51; }
//Player Dead
if (PlayerStatus == 14) { PlayerOffsetX = 187; PlayerOffsetY = 72; PlayerWidth = 37; PlayerHeight = 49; }
if (PlayerStatus == 15) { PlayerOffsetX = 233; PlayerOffsetY = 73; PlayerWidth = 37; PlayerHeight = 47; }
if (PlayerStatus == 16) { PlayerOffsetX = 279; PlayerOffsetY = 75; PlayerWidth = 36; PlayerHeight = 45; }
/*****************************
Controls
******************************/
/*************
Start
**************/
if (osl_pad.pressed.start)
{
oslEndGfx();
oslQuit();
}
/*************
Cross
**************/
if ( (osl_pad.pressed.cross) && (JumpTimer == 0) )
{
oslPlaySound(jump, 2);
JumpTimer++;
}
/*************
Square
**************/
if ( (osl_pad.pressed.square) && (KickTimer == 0) && (!osl_pad.held.right) )
{
KickTimer = 1;
}
/*************
Right
**************/
if ( (osl_pad.held.right) && (KickTimer == 0) )
{
if (PlayerFacing == LEFT) { PlayerFacing = RIGHT; }
PlayerPosX += 2;
StandingTimer = 0;
RunningTimer++;
}
/*************
Left
**************/
if ( (osl_pad.held.left) && (KickTimer == 0) )
{
if (PlayerFacing == RIGHT) { PlayerFacing = LEFT; }
PlayerPosX -= 2;
StandingTimer = 0;
RunningTimer++;
}
if ( (!osl_pad.held.right) && (!osl_pad.held.left) )
{
RunningTimer = 0;
}
/*****************************
Blit Images
******************************/
blit(level1, 0, 0);
oslSetImageTileSize (Ed, PlayerOffsetX, PlayerOffsetY, PlayerWidth, PlayerHeight);
if (PlayerFacing == RIGHT)
{
blit(Ed, PlayerPosX, PlayerPosY);
}
if (PlayerFacing == LEFT)
{
oslMirrorImageH(Ed);
blit(Ed, PlayerPosX, PlayerPosY);
}
/*****************************
End of Game
******************************/
}
/**********************************
End of While Loop
***********************************/
oslEndDrawing();
oslSyncFrame();
}
/**********************************
End of Menu
***********************************/
return 0;
}
/***************************************************************************************************
****************************************************************************************************
****************************** ************************************
****************************** Main ************************************
****************************** ************************************
****************************** ************************************
****************************************************************************************************/
int main()
{
menu(); return 0;
}