The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

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; i'm not doing this with the psp, at least not at first anyways...

 Tweet
1. i'm not doing this with the psp, at least not at first anyways

2. Code:
```while (something) { /*nothing here*/ };
someother statement;```
I donot exactly understand the purpose of empty semicolon ended while loop

3. quick question on drawing an circle...which i think i may have realized a faster way as i write this.....anyways

currently the way i'm drawing a circle is:
Code:
```#include <oslib/oslib.h>
#include <math.h>
#define PI (first several digits go here)

void DrawPixel(float x, float y, osl_color color){

oslDrawFillRect(x, y , x+1, y+1, color);
}

void DrawCircle(int x, int y, int radius, osl_color){
for(int i=0;i<360;i++){
float tx = x + sinf(i*(PI/180))*radius);
float ty = y - cosf(i*(PI/180))*radius);
DrawPixel(tx, ty, color)
}
}```
^^now than for one or two circles not bad however a multitude of circles and u see a huge slowdown

i've changed the function

Code:
```void DrawCircle(int x, int y, int radius, osl_color){
for(int i=0;i<360;i++){
float tx = x + sinf(i*(PI/180))*radius);
float ty = y - cosf(i*(PI/180))*radius);
DrawPixel(tx, ty, color)
}
}```
to

Code:
```void DrawCircle(int x, int y, int radius, osl_color){
for(int i=0;i<360;i+=30){
float tx = x + sinf(i*(PI/180))*radius);
float ty = y - cosf(i*(PI/180))*radius);
DrawPixel(tx, ty, color)
}
}```
so that does show a major increase in speed but not the best

would it be faster and this is the idea i just thought of to:

draw the circle to an empty image than just displaying the image?

thanks every1

4. Originally Posted by Mr305
Code:
```while (something) { /*nothing here*/ };
someother statement;```
I donot exactly understand the purpose of empty semicolon ended while loop
They're doing it wrong.
Code:
`while (something_that_affects_state);`
Perfectly valid, even if kinda hard to read at times.

5. OK this is not for PSP, I am learning C++ still but have hit a problem with random numbers. I am using Dev C++, with begining ++ Game Programming (this uses Dev C++). The program is meant to be like a dice when rolled, a random number is produced and then modulised by 6 to make it a dice number. However when I run this I only get 6 everytime I run the program. Here is the code.

Code:
```#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int randomnumber = rand(); //generates a random number
int die = (randomnumber % 6) + 1; //get a number between 1 and 6

int main()
{
srand(time(0)); //seed a random number based on current time
cout << "You got a " << die << endl;
cin.get();
return 0;
}```

Anyways, ya something like hwat you said might be better considering your slow down is due to those 2 calculations * 360 times * number of circles to draw. This will only run those 2 calculations once then just scale the image to the radius specified.

Example:
Code:
```OSL_IMAGE *pEllipse = NULL; // internally used, don't directly use this anywhere

// run this function anywhere just once before drawing hte circle (usually the loading resources part of a game)
void Initialize()
{
if (pEllipse != NULL)
oslDeleteImage(pEllipse);

// create image
pEllipse = oslCreateImage (512, 512, OSL_IN_VRAM, OSL_PF_8888)
oslAssert(pEllipse);

// clear to alpha
oslClearImage(pEllipse, RGBA(0, 0, 0, 255));

// set the draw buffer to the new image
oslSetDrawBuffer(pEllipse);

// draw the circle on it, radius = 1/2 dimensions
for (int i = 0; i < 360; i++)
{
int tmpX = oslCosi(i, 256) + 256; // why you don't use OSlib's math functions i dont know...
int tmpY = oslSini(i, 256) + 256; // these use the VFPU, takes the angle as a degree and multiplies it by the magnitude and returns an integer
// does all the stuff you were doing but faster and more readable ;)
oslDrawFillRect(tmpX, tmpY, tmpX + 1, tmpY + 1, RGB(255,255,255)); // draw it white
}

// set the draw buffer back to the default
oslSetDrawBuffer(OSL_DEFAULT_BUFFER);
}

{
pEllipse->x = x - radiusX; // set the position of the image
pEllipse->y = y - radiusY; // "
pEllipse->stretchX = radiusX * 2; // set the width of the ellipsoid
pEllipse->stretchY = radiusY * 2; // set the height "

// store the current params
OSL_ALPHA_PARAMS *currentParameters = NULL;

oslGetAlphaEx(currentParameters);

// now we set a filter to convert the white part of the ellipsoid image
// (the circle part) to the color passed
oslSetAlpha(OSL_FX_ALPHA | OSL_FX_COLOR, color);

oslDrawImage(pEllipse); // draw it

// back to normal
oslSetAlphaEx(currentParameters);
}```
Haven't tested it however it should work. If it doesn't tell me the outcome, i have a few other filtering techniques to color it to the desired color....

Also, take a look here:
http://www.psp-hacks.com/forums/viewtopic.php?id=140324

leejames - It should always return 6 (well any value at that, just the same each time). Your initializing 'randomnumber' to a random number before setting a random seed. Try something like this (btw format your code or i'll have your head ;))
Code:
```#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int randomnumber = 0;
int die = 0;

int main()
{
srand(time(0));

randomnumber = rand();
die = (randomnumber % 6) + 1;

cout << "You got a " << die << endl;
cin.get();

return 0;
}```
That'll work. However I recommend you avoid global variables where possible, not initialize variables to desired values, assign them later to desired values (that was your main problem here) and format your code (a lot of people don't like having to take the time and format your code then look for a problem so format before hand).

7. Originally Posted by leejames04
OK this is not for PSP, I am learning C++ still but have hit a problem with random numbers. I am using Dev C++, with begining ++ Game Programming (this uses Dev C++). The program is meant to be like a dice when rolled, a random number is produced and then modulised by 6 to make it a dice number. However when I run this I only get 6 everytime I run the program. Here is the code.

Code:
```#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int randomnumber = rand(); //generates a random number
int die = (randomnumber % 6) + 1; //get a number between 1 and 6

int main()
{
srand(time(0)); //seed a random number based on current time
cout << "You got a " << die << endl;
cin.get();
return 0;
}```
Try this:

Code:
```#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int main()
{
srand((unsigned)time(0)); //seed a random number based on current time

int randomnumber = rand(); //generates a random number
int die = (randomnumber % 6) + 1; //get a number between 1 and 6

cout << "You got a " << die << endl;
cin.get();
return 0;
}```
Try not to use globals unless absolutely neccessary, and seed before you randomize.

8. Originally Posted by Slasher
How come no matter what I do, I can't seem to get the psp slim tv-out working?

I've included the stub "pspDveManager.S" and have created a 'dummy' function within my main.cpp "int pspDveMgrSetVideoOut(int, int, int, int, int, int, int);", just like the sample did.

It compiles the code fine, but once it hits the finalization of the compiling I get, 'Undefined Reference to pspDveMgrSetVideoOut(int, int, int, int, int, int, int)' @ line 330 which is the line where I declared that function.

What else do I do? I don't understand how the sample works but my code doesn't?

(The sample is at http://dl.qj.net/Fullscreen-TV-out-f...4864/catid/151)
Re-post.
Anyone successfully get this working? How can I get it working?

EDIT: nvm I figured it out
Code:
```#ifdef __cplusplus
extern "C" {
#endif

int pspDveMgrCheckVideoOut();
int pspDveMgrSetVideoOut(int u, int mode, int width, int height, int x, int y, int z);

#ifdef __cplusplus
}
#endif```

9. sry sg57 i'm so used to hitting tab to increase by a few spaces that when trying to type formated code here....well anyways, thanks that'll defiantly give me speed up i think i'm ganna re-write pixel attack anyways since my coding style has changed so much since the time that i wrote it anyways thanks a million this well rly help me=-)

plus i wanna try a few physic's tricks that i've learned to make it look far better

also i didn't use the oslcos and sin commands because they've given back undesired results before so i find going with sinf and cosf to give me the results i'm looking for

10. What do you mean undesired results lol

They take an angle in degrees and the radius size/magnitude. Returns the integer value of the sin/cos of that angle * the radius size/magnitude. It uses the vfpu for the calculations as well so a lot of calls to it should make a significant difference between math.h sinf/cosf and oslib's oslCos and oslSin...

11. yes i fully understand what the function does, however i have experianced problems with the two commands which were remedied when i replaced them with cos and sin, also at this point such a small increase in speed isn't really necessary, especially with such a speed up that the command above gives me

12. Post your old usage of oslCos/Sin and I can almost guarantee a flaw in your usage of it, And hey if it's possible to optimize readability-wise and performance wise, why not? ;)

13. your just an optimization whore=-) not a bad thing of course

i'll see if i can find the project but idk if i still have it on my computer, if i remeber correctly it was in my celestial cunning projects however they've gone through so many updates that idk if i have the original problem any longer but i'll look to see if i can find it

14. i need some help, this is my first post (yay) and i dont know how to get the time off the psp's internal clock, a n00b problem i know. i try to use time.h but cygwin doesnt like it... yay first post.
hmm... since its so late over ther (im in aus) i'll log back in tomorrow after school and see if anything has happened

15. I'm having a problem using a function to load a pbp file as a module. I've been given the stub for the function and got everything work up to the point where I actually try and load the file, at which point I get 0x800200D9, which after searching on Google, I've found to be an error with the file I'm loading.

The functions I'm using are in an exported file which is loading fine by the looks of things, but seeing as the application I'm trying to load (BookR) is working fine normally, I'm more than a tad confused about what is causing the error to pop up?

Any assistance what so ever is welcome, this really has me stumped.

-Aura

16. Originally Posted by Auraomega
I'm having a problem using a function to load a pbp file as a module. I've been given the stub for the function and got everything work up to the point where I actually try and load the file, at which point I get 0x800200D9, which after searching on Google, I've found to be an error with the file I'm loading.

The functions I'm using are in an exported file which is loading fine by the looks of things, but seeing as the application I'm trying to load (BookR) is working fine normally, I'm more than a tad confused about what is causing the error to pop up?

Any assistance what so ever is welcome, this really has me stumped.

-Aura
Hopefully this helps. It loads an elf (the eboot.pbp in the non % folder for kxploited apps).
There's alot of unneeded stuff such as the unloading of the prx loader (which is meant to load this prx), and patching the sceKernelExitGame function, and a few other things.
int run_elf(char * elfPath) is what you should be looking at.

I think your problem lies in that you can't load actual eboots as a module, you need to load the elf. (I may be wrong on this, I'm just assuming)

Furthermore, if you're trying to load BookR such as the way irshell does it(Uses BookR to look at txt files, etc), then it's something entirely different. You must pass arguments onto the eboot. I'm not 100% sure this is how irshell does it, but I'm pretty sure.
Ex)
Code:
```int	runPBP(char * fileName)
{

char args[256];

execParam.size = sizeof(execParam);
execParam.argp = args;
execParam.args = strlen(args) + 1;
execParam.key = NULL;

return -1;

return 1;
}```
The program that is loaded, 'fileName'; can then recieve the arg that you passed onto it, "ms0:/PSP/GAME/test.txt",
through argv.
Code:
```int main(int argc, char** argv)
{```
Anyways, let me know if this helps

17. Well, 7-Points sent me the stubs for a sceKernelLoadModuleForLoa dExecVSHMs2 which is the function I've been trying to get working.

Stub for the functions:
Code:
```	.set noreorder

#include "pspstub.s"

STUB_START "ModuleMgrForKernel",0x40090000,0x00030005
STUB_END```
My kernel module seems to be fine until I attempt to use the above function, which is when it breaks down.

-Aura

18. Might I add that 0x800200D9, an error I know well, means that the PSP ran out of memory? Check the size of your heap and stack to make sure there's enough room for the ELF.

19. Well, I made sure that all memory was free, I reduced my heaps down to the default (32 or 64kb, can't remember) and tried, same error. Plus, according to the link I posted above, it refers to not being able to load due to an error if the file, not just that I'm out of free space?

-Aura

20. http://psp.jim.sh/pspsdk-doc/pspkerror_8h.html
SCE_KERNEL_ERROR_MEMBLOCK _ALLOC_FAILED = 0x800200d9
So I guess it's not strictly running out of memory, so much as that it can't allocate the memory for one reason or another.

21. Could it be because I'm loading from a kernel module? I doubt that would be the cause seeing as it won't run in user mode, but best to ask.

-Aura

22. Hey I was wondering if anyone knew how to find all files in a folder? I'm thinking of making an app that will need this and wonder if there are functions already out there like this for the psp..

23. research up on dirent.h library that's helped me in the past, their may be a library specific to the psp however i've not needed it if their is, someone correct me please, durka, if your still confused after some research on it hit me with a pm=-)

24. Using dirents, namely sceIoDopen (I think, havn't actually got my code on me to refer to). If you need a bit of help drop me a PM and I'll knock you up some code when I get a chance.

-Aura

25. You can also check out the filebrowser example @ my site, http://slasher.team-duck.com . That might help.

26. Wow man great example, this will help me loads.

Exactly what is needed (what headers) to use this? I don't want to include stuff I don't need.

27. dirent.h for the POSIX version, pspiofilemgr.h for the PSP version (it's included by some files, so it might already be included)

28. Alright thanks.

One more question. What size (px by px) is a single character on the standard PSP font? I'm making a simple textbox class that will be able to print according to how many characters wide you want it to be, so I need their sizes.

29. see your pm for my response=-)

30. ## Load an eboot with a prx without exit the first

Hello everyone,
I want to know how I can do if I load an eboot with a prx to not quit the first eboot loaded before.
It is posible because Irshell can do this ^^

Here the code to load an eboot:

Code:
```void execEboot(char *target)
{
u8 vshmain_args[0x400];
memset(vshmain_args, 0, sizeof(vshmain_args));
vshmain_args[0x40] = 1;
vshmain_args[0x280] = 1;
vshmain_args[0x284] = 3;
vshmain_args[0x286] = 5;
memset(&param, 0, sizeof(param));
param.size = sizeof(param);
param.args = strlen(target) + 1;
param.argp = target;
param.key = "game";
param.vshmain_args_size = sizeof(vshmain_args);
param.vshmain_args = vshmain_args;
}```
I thanks everyone who help me^^

I apologize for my bad english because I am french^^

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 05:51 AM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY