C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Zitat von Auraomega Surely Code: if(pad.Buttons & (PSP_CTRL_CIRCLE & PSP_CTRL_CROSS)) will only work if both buttons are pressed, which makes ...
-
12-22-2007, 02:06 PM #7201QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
No, that will never evaluate to true, because PSP_CTRL_CIRCLE and PSP_CTRL_CROSS have distinct bits set, so the logical AND of both will evaluate to 0 and any value AND 0 is 0 = FALSE.
Zitat von Auraomega
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.
-
12-22-2007, 02:14 PM #7202I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
*Looks in pspctrl.h*
PSP_CTRL_CROSS = 0100000000000000
PSP_CTRL_CIRCLE = 0010000000000000
Surely if they were AND'ed together they would become 0110000000000000? Would that still not work? Bit 14 and bit 15 are both set, so surely that would be correct, even if only in this case? (I think my electronics is conflicting here).
-Aura
-
12-22-2007, 02:24 PM #7203QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
You're confusing logical AND with logical OR. That's why I used OR in my code snippet.
Zitat von Auraomega
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.
-
12-22-2007, 02:54 PM #7204
&
Zitat von Auraomega
0 & 0 = 0
1 & 0 = 0
0 & 1 = 0
1 & 1 = 1
|
0 | 0 = 0
0 | 1 = 1
1 | 0 = 1
1 | 1 = 1
hope that helps:)
-
12-22-2007, 03:11 PM #7205I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Hmm, is there an XOR function, or would I have to do something like:
if ( (!( a & b )) & ( a | b ) );
I think thats right... lord help me I have an exam on this sort of thing very soon and I'm getting mighty confused
-Aura
-
12-22-2007, 03:11 PM #7206Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
hi i was just wondering i know of the
sceKernelLoadExec(); command
i just wanted to know how i would use this to load an eboot from inside another eboot
- if it is not the right command to do this could you please direct me to somewhere i could lean how to do this please or just tell me i dont mind as long as i find out------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
12-22-2007, 03:17 PM #7207I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
If you mean 2 seperate EBOOT files, and are running in 1.50 kernel:
for 3.XX:Code:struct SceKernelLoadExecParam param; memset(¶m, 0, sizeof(param)); param.size = sizeof(param); param.key = "game"; sceKernelLoadExec(FILEPATH, ¶m);
for loading an EBOOT that is hard coded into another EBOOT:Code:struct SceKernelLoadExecVSHParam param; memset(¶m, 0, sizeof(param)); param.size = sizeof(param); param.key = "game"; sctrlKernelLoadExecVSHMs2(FILEPATH, ¶m);
In any case, unless you are making a loader, you are best to load .prx files. Loading EBOOTs is best left for something like a shell, where as an app that requires plugins is best suited to .prx files.Code:struct SceKernelLoadExecParam param; memset(¶m, 0, sizeof(param)); param.size = sizeof(param); param.key = "game"; sceKernelLoadExecBufferPlain(sizeof(BUFFER), BUFFER, ¶m); //might need to be strlen(BUFFER) depending on your storage type. //Not sure if the above will work as I've never actually loaded from a buffer before.
-Aura
-
12-22-2007, 03:19 PM #7208Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
thanks man great response
- did you get them from the samples ?????------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
12-22-2007, 03:20 PM #7209I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Nope, just dragged them out of the Project4 source code (except the buffer one which I pulled from thin air and a header file
)
-Aura
-
12-22-2007, 03:31 PM #7210
exclusive or ^
Zitat von Auraomega
^
0 ^ 0 = 0
1 ^ 0 = 1
0 ^ 1 = 1
1 ^ 1 = 0
there you go:)
-
12-22-2007, 05:11 PM #7211I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Well that certainly explains a lot, tried doing power with ^ the other day and my code went all weird, now I know why... incidently, is there a function for powers in c?
You know what, I think I'm gonna use Google and see what operators there are, its something I've neglected so nows a good time to check I guess.
-Aura
-
12-23-2007, 05:19 AM #7212QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
pow/powf
There are no other operators in C for mathematical functions.
arithmetic:
+, -, *, /, %
boolean:
binary: &&, ||, !
logical: &, |, ~, ^
In C++ you can overload those operators so you can do power with ^ for example.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.
-
12-23-2007, 06:03 AM #7213Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
hi relating to what i asked yesterday and what aura replied with i added it into the code and set the variable but i get this error
error: 'memset' was not declared in this scope
do i have to include a certain lib or do i have to set that as an int or something sorry im new to coding in c for the psp------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
12-23-2007, 06:43 AM #7214
you need to include the proper header files
#include <string.h>
next time ask google, as it will give you the answer within milliseconds :Probot mafia
-
12-23-2007, 06:49 AM #7215Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
thanks man - i didn't realize because in my other source that is already included so i haven't actually checked the commands
thanks again
THE RESULT OF YOUR HELPGeändert von FaT3oYCG (12-23-2007 um 08:46 AM Uhr)
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
12-23-2007, 09:59 AM #7216It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You forgot the ternary operator, which is perfect for obfuscating code.
Zitat von Raphael
boolean ? value-if-true : value-if-false
e.g.:
Code:printf("%s",0?"true":"false"); //prints false printf("%s",1?"true":"false"); //prints truepəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
12-23-2007, 10:17 AM #7217QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Well, I don't consider that an operator in the same category as the above, as as you said it's a ternary operator (meaning it has three operands) :P But oh well... if you so insist, yeah, that one exists too ;)
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.
-
12-23-2007, 10:26 AM #7218It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You're right, it is different from the other operators, but I always see it listed alongside the other operators, whether they're binary or unary.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
12-23-2007, 11:24 AM #7219QJ Gamer Blue
- Registriert seit
- Jan 2007
- Ort
- somewhere
- Beiträge
- 119
- Points
- 4.239
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Can someone link me too the pre-complied toolchain thanx :)
-
12-23-2007, 12:00 PM #7220Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
on my guide
it is the pspdev folder
PSPDEV FOLDER - (precompiled by me) - THE PSPTOOLCHAIN
EDIT 1:
hi sorry for double posting but i have a problem
i have added umd functions into lua player but i am struggling adding the command to activate the umd as disc0: it all compiles fine but whenever i use the command in luaplayer it says a nil value ???? anyone know why
it is probably something with the code but i dont know what
i tried multiple different ways but none seem to work
here is the current code at the moment i just put the example code in to see if that worked but no luck
here it is
EDIT 2:Code:static int lua_UmdActivate(lua_State *L) { if (lua_gettop(L) != 0) return luaL_error(L, "no arguments expected"); sceUmdWaitDriveStat(UMD_WAITFORDISC); int i; i = sceUmdCheckMedium(0); if(i == 0) { sceUmdWaitDriveStat(UMD_WAITFORDISC); } sceUmdActivate(1, "disc0:"); sceUmdWaitDriveStat(UMD_WAITFORINIT); return 0; }
ok nevermind i figured out why it wasnt working now what i want to know is if i wanted to load the umd and play the game
how would i do that because i tried loading the boot.bin and the eboot.bin and then both and neither worked so could i have some help please
thanks
EDIT 3:
ok it has come to my attention that i will need to use
sceKernelLoadModule and sceKernelStartModule
but i cant seem to get it to work
if a specific lib is needed could you please tell me which one and give me a short example of just loading and starting a module i looked at the sample in the svn but i had no luck and just found that it confused me more
here is the code that i am using
thanksCode:static int lua_ExecModule(lua_State *L) { if (lua_gettop(L) != 1) return luaL_error(L, "one argument expected"); struct SceKernelLMOption option; memset(&option, 0, sizeof(option)); option.size = sizeof(option); option.position = 0; option.access = 1; const char *FILEPATH = ""; FILEPATH = luaL_checkstring(L, 1); int moduleid = sceKernelLoadModule(FILEPATH, 0, &option); sceKernelStartModule(moduleid, 0, NULL, 0, NULL); return 0; }Geändert von FaT3oYCG (12-23-2007 um 06:16 PM Uhr) Grund: Automerged Doublepost
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
12-23-2007, 06:53 PM #7221QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Hey, i was just wondering how i would go about storing a bmp image in an array for access later. Thanks
-
12-23-2007, 07:15 PM #7222Developer

- Registriert seit
- Feb 2006
- Ort
- Norway
- Beiträge
- 384
- Points
- 5.359
- Level
- 47
- Downloads
- 0
- Uploads
- 0
How about << and >>? Those seem pretty mathematical to me, and they also seem like operators.
Zitat von Raphael
@Xsjado, here's a class for bmp loading I wrote a while back. If you want to understand it I'd recommend you to use google, there's plenty of sites there regarding bmps.
loadBMP() allocates the necessary memory and makes data point to the bmp, and stores the bmp's size in the width and height variables.
Code:class Image { public: Image(){} ~Image(); bool loadBMP( const char *path ); unsigned char *data; unsigned int width; unsigned int height; }; Image::~Image() { free( data ); } unsigned int getUINT( const unsigned char *p ) { return p[0] + (p[1]<<8) + (p[2]<<16) + (p[3]<<24); } bool Image::loadBMP( const char *path ) { FILE *fp = fopen( path, "r" ); if( fp == NULL ) return false; unsigned char header[54]; fread( header, 54, 1, fp ); // BM if( *(short*)header != 19778 ) { fclose( fp ); return false; } width = getUINT( &header[18] ); height = getUINT( &header[22] ); data = (unsigned char*)malloc( width*height*3 ); fseek( fp, getUINT( &header[10] ), SEEK_SET ); fread( data, width, height*3, fp ); fclose( fp ); // Convert from BGR to RGB for( UINT i = 0; i < width*height*3; i += 3 ) { data[i] ^= data[i+2]; data[i+2] ^= data[i]; data[i] ^= data[i+2]; } return true; }
-
12-23-2007, 11:43 PM #7223QJ Gamer Silver
- Registriert seit
- Feb 2007
- Ort
- Melbourne, Australia
- Beiträge
- 1.773
- Points
- 8.717
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Gar!!! I was trying to make a basic sfx program but it keeps looping, any idea why?
Spoiler for code:WHA!?
-
12-24-2007, 01:16 AM #7224Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
simpel it will only check once or the mp3 has stoped or notCode:int main() { pspDebugScreenInit(); SetupCallbacks(); pspAudioInit(); SceCtrlData pad; printf("Press [O] to play/pause the music\nPress [X] to exit the program\n"); while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CROSS) { MP3_Init(1); MP3_Load("./sounds/sound26.mp3"); MP3_Play(); break; } } while(!MP3_EndOfStream()) { //do nothing } MP3_Stop(); MP3_FreeTune(); sceKernelSleepThread(); return 0; }
-
12-24-2007, 01:43 AM #7225QJ Gamer Silver
- Registriert seit
- Feb 2007
- Ort
- Melbourne, Australia
- Beiträge
- 1.773
- Points
- 8.717
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
that didn't work, still continues
WHA!?
-
12-24-2007, 02:26 AM #7226QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
is your problem that it plays a few times when you press tyhe button for the sound? If so, just add a waitvblank to it. One thing you should change is where your sound is loaded and where you initialize the channel. Do:
Load them before the loop. The way you were doing it if the user kept pressing it would load the sound a million times and kill the psp. That code also includes the waitvblankCode:int main() { pspDebugScreenInit(); SetupCallbacks(); pspAudioInit(); SceCtrlData pad; MP3_Init(1); MP3_Load("./sounds/sound26.mp3"); printf("Press [O] to play/pause the music\nPress [X] to exit the program\n"); while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CROSS) { MP3_Play(); sceDisplayWaitVBlankStart(); } if (MP3_EndOfStream() == 1) break; } MP3_Stop(); MP3_FreeTune(); sceKernelSleepThread(); return 0; }
-
12-24-2007, 04:22 AM #7227Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
ok i have a problem while using the
sceKernelLoadModule command in my code it throws out an error and says something to do with memory not being able to be allocated
does anyone know how to solve this problem thanks
videoGeändert von FaT3oYCG (12-24-2007 um 06:29 AM Uhr)
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
12-24-2007, 10:07 AM #7228It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Surely I'm not the only person who sees problems with this class? Even assuming that the loader works fine (which it won't--it'll crash if it's given a BMP with a malformed header. Also, a bitmap that's too big will cause problems, too). If an Image falls out of scope or if an Image* is deleted before it's loaded, instant crash.
Zitat von Waterbottle
Here's a fixed version. Of course, it assumed UINT and NULL are defined in the scope of the class.
Code:class Image { public: Image(){ data = NULL; } ~Image(); bool loadBMP( const char *path ); unsigned char *data; unsigned int width; unsigned int height; }; Image::~Image() { if( data != NULL ) free( data ); } unsigned int getUINT( const unsigned char *p ) { return p[0] + (p[1]<<8) + (p[2]<<16) + (p[3]<<24); } bool Image::loadBMP( const char *path ) { if( data != NULL ) free( data ); FILE *fp = fopen( path, "r" ); if( fp == NULL ) return false; unsigned char header[54]; if( ( fread( header, 54, 1, fp ) != 54 ) || ( *(short*)header != 19778 ) ) { fclose( fp ); return false; } width = getUINT( &header[18] ); height = getUINT( &header[22] ); data = (unsigned char*)malloc( width*height*3 ); if( data == NULL ) { fclose( fp ); return false; } fseek( fp, getUINT( &header[10] ), SEEK_SET ); fread( data, width, height*3, fp ); fclose( fp ); // Convert from BGR to RGB for( UINT i = 0; i < width*height*3; i += 3 ) { data[i] ^= data[i+2]; data[i+2] ^= data[i]; data[i] ^= data[i+2]; } return true; }pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
12-24-2007, 11:17 AM #7229QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
That still will have problems with <= 8bit BMP files as well as with bmp files who's width(*3) is NOT a multiple of four. Rows in a BMP are always padded to have a multiple of four number of bytes. It works for power of two sized images though, so probably that's why it never came to the OP's attention.
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.
-
12-24-2007, 11:24 AM #7230It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
*doesn't know anything about the Windows bitmap format, hence I just corrected the mistakes I could identify*
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ


LinkBack URL
About LinkBacks
Mit Zitat antworten


Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum