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; I havn't got access to my codes at the moment, but I was wondering if it was possible to store ...
-
01-01-2008, 03:12 PM #7351I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I havn't got access to my codes at the moment, but I was wondering if it was possible to store the data of the screen display buffer in memory using the graphics.c...
I want to make a function that will read the current thing on screen, and store it away for use later, I thought it would be as simple as just using getVramDisplayBuffer but I realised this only returns a pointer, and that the display buffer constantly changing means the data is changed too, I need to keep that data, I was thinking about using malloc to make the memory, but I'm not sure off the top of my head what arguments to use, so if anyone knows how to do this (or an easier way) I'd love to hear it :)
Sorry if I explained that badly, or just rambled, I just hope I got my question across properly.
Also, has anyone got an code showing how to mount flash2 as read/write as I can't find the arguments required, I assumed flash2 but it returned the nodev error, I also tried assigning it incase it wasn't already assigned, again no luck, so any pointers on this would be aprechiated.
-Aura
-
01-01-2008, 03:51 PM #7352Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
i havent done much about screen buffers, but this would be my guess:
Zitat von Auraomega
Code:1. Get the pointer. 2. malloc(sizeof(*pointer)); // Dont know if this would work exactly // 3. memcpy(from pointer to malloc'd memory);
--------------------------------------------------------------------------------------
-
01-01-2008, 04:00 PM #7353
haven't tested it but this should do it aswell
u32 buffer[512x272] //buffer to store whole screenbuffer
memcpy(buffer,0x04000000, 512*272) //copy framebuffer content to buffer
//donerobot mafia
-
01-01-2008, 04:16 PM #7354
The screen is only 480*272. Any reason why you chose 512 instead of 480?
Zitat von tommydanger
[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]
Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.
-
01-01-2008, 04:20 PM #7355I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I'm back :)
Zitat von Judas
Actually, you are both wrong, it should be 512*272*4...
I'm crashing at the moment using the codes posted above, I'm not sure if its the memory constraint or not, I'll work at it a little more, if it still crashes I'll post the code and see if anyone else can see what I'm doing wrong (if anything).Code:#define FRAMEBUFFER_SIZE (PSP_LINE_SIZE*SCREEN_HEIGHT*4)
-Aura
-
01-01-2008, 04:31 PM #7356QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
No. Tommydanger was right (apart from the memcpy's last parameter). He created an array of u32s, so the size was in fact 512*272*4. Anyway, it crashes, because the buffer is created on stack and the stack is not large enough for that. Either make the declaration static or use malloc.
Zitat von Auraomega
Also, you could get weird results if you're reading back the framebuffer while it is currently being rendered too. So you'd probably be best off mutexing the memcpy or disabling interrupts during the time and make sure it happens after the rendering of the screen has finished (by hooking sceDisplaySetFramebuf or sceGuSync).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.
-
01-01-2008, 09:37 PM #7357QJ Gamer Silver
- Registriert seit
- Feb 2007
- Ort
- Melbourne, Australia
- Beiträge
- 1.773
- Points
- 8.717
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Anyone? It has been five days since I originally posted..
Zitat von BigSanFrey
WHA!?
-
01-02-2008, 02:58 AM #7358QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
What is your code in GetRandomNum? Chances are that the function is not returning correct values.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-02-2008, 10:01 AM #7359I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Argh, brain isn't functioning today. It was the stack, once I allocated more to the thread it stopped crashing, but instead it appears to be reverting to a mix of old images blitted to the screen, I think I've done something wrong with assigning the buffer to the image->data.
Zitat von Raphael
When I then blit screen to the screen it gives me a mix of whats already there, the "PSPLink Bootstrap TyRaNiD (c) 2k7 Version v3.0" but instead of it being white it gives it with the colours of the picture that was on screen the previous time.Code:u32 buffer = (void*)malloc(512*272*4); Image* screen; screen = createImage(480, 272); while(1) { sceCtrlPeekBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_SELECT) { memcpy(buffer, 0x04000000, 512*272*4); screen->data = buffer;
-Aura
-
01-02-2008, 10:37 AM #7360Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Quoted for emphasis.
Zitat von Raphael

Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
-
01-02-2008, 11:00 AM #7361QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
That sounds as if you just draw the image with alpha transparency - however the framebuffers alpha channel is not useable, so you need to disable blending. If that's not the case - refer to my previous posts hint (which IWN quoted).
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.
-
01-02-2008, 12:27 PM #7362I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Yeah I made sure nothing was writing the to buffer while I was doing so (I suspended all the threads doing this).
Zitat von Insert_Witty_Name
Thank you Raphael, for some odd reason I was trying to use alpha, after reviewing the code I have disabled this and it now works fine
-Aura
-
01-02-2008, 07:16 PM #7363QJ Gamer Blue
- Registriert seit
- Jan 2006
- Ort
- CO
- Beiträge
- 150
- Points
- 8.686
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
psp-config help
Ok so I was installing cygwin and then pspdev I made the changes I needed to cygwin.bat ie.
set path=%path%;C:/cygwin/usr/local/pspdev/bin
set PSPSDK=C:/cygwin/usr/local/pspdev
But what I did by accident "so stupid" I typed
set path=%/path%;C:/.......
That dang forward slash some how got saved. So when I compile I get an error that says.
/c/cygwin/usr/local/pspdev/psp/sdk/lib/build.mak: No such file or directory.
I know theres a fix, I found it a long long time ago. All day I've been searching with no results this time. Yes I have done this before :Argh:
I will definitely write it down this time around. If anyone knows the syntax to fix this I would appreciate it. Thats all I can remember about fixing it was typeing something in the command prompt. And just to let you know I have reinstalled cygwin, made both PATH and PSPSDK Environment Variables.
Plus how can you get a clean uninstall of cygwin? That might just be my best bet since I can't find my answer. Hope I made sence I'm a little angry with myself at the moment.
::Edit::
Found out about the cygwin uninstall all through there sites FAQ... duh! Talk about an off day.
...gezz All I had to do is type this into the command prompt.
set PATH=c:/cygwin/usr/local/pspdev/bin;%PATH%
set PSPDEV=c:/cygwin/usr/local/pspdev
Dont know why it wouldn't fix its self through Environmental Varibles Settings..??Geändert von HYde (01-02-2008 um 10:31 PM Uhr)
-
01-02-2008, 11:10 PM #7364QJ Gamer Silver
- Registriert seit
- Feb 2007
- Ort
- Melbourne, Australia
- Beiträge
- 1.773
- Points
- 8.717
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Zitat von yaustar
is my GetRandomNum functionCode:int GetRandomNum(int lo, int hi) { SceKernelUtilsMt19937Context ctx; sceKernelUtilsMt19937Init(&ctx, time(NULL)); //SEED TO TIME u32 rand_val = sceKernelUtilsMt19937UInt(&ctx); rand_val = lo + rand_val % hi; return (int)rand_val; }
WHA!?
-
01-03-2008, 04:37 AM #7365QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
That will give you a random number in range [lo, lo+hi-1].
Zitat von BigSanFrey
What you probably want is return (lo + (rand_val % (hi - lo + 1)));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.
-
01-03-2008, 05:10 AM #7366QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Thought as much, I fixed this 5 days ago:
Zitat von BigSanFrey
http://forums.qj.net/f-psp-developme...4/page732.html
C/C++ Programming Help Thread[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-03-2008, 12:32 PM #7367QJ Gamer Silver
- Registriert seit
- Feb 2007
- Ort
- Melbourne, Australia
- Beiträge
- 1.773
- Points
- 8.717
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
sorry!!
I searched for a random number generator in the earlier parts of this thread and it gave me pretty much that exact code.. weird (and stupid of me!)WHA!?
-
01-03-2008, 03:02 PM #7368QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Ok, i tried that, but i get the error for the static line: "initializer element is not constant".
Zitat von yaustar
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
01-03-2008, 04:44 PM #7369Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
-
01-03-2008, 07:02 PM #7370QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Will this work then:
Edit: Never mind, i was being an idiot. That doesn't work. I found it out. :)Code:int GetRandomNum(int lo, int hi) { static SceKernelUtilsMt19937Context ctx; sceKernelUtilsMt19937Init(&ctx, time(NULL)); int rand_val = (int)sceKernelUtilsMt19937UInt(&ctx); rand_val = lo + ( rand_val % (hi-lo) ); return rand_val; }Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
01-03-2008, 07:56 PM #7371It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Here's a hack-y way to do it.Code:SceKernelUtilsMt19937Context InitialiseMtContext() { SceKernelUtilsMt19937Context ctx; sceKernelUtilsMt19937Init(&ctx, time(NULL)); return ctx; } int GetRandomNum(int lo, int hi) { static int initialized = 0; static SceKernelUtilsMt19937Context ctx; if(!initialized) { ctx = InitialiseMtContext(); initialized = 1; } int rand_val = (int)sceKernelUtilsMt19937UInt(&ctx); rand_val = lo + ( rand_val % (hi-lo) ); return rand_val; } int main() { // get random number GetRandomNum( 0, 100 ); // ctx gets initialised here the first time the function is called GetRandomNum( 0, 100 ); // but not here GetRandomNum( 0, 100 ); // nor here return 0; }pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
01-04-2008, 02:03 AM #7372QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
It is something to do with the array in the struct ctx so copying by value is invalid.
Zitat von TMNT
Code:int GetRandomNum(int lo, int hi) { static int initialized = 0; static SceKernelUtilsMt19937Context ctx; if(!initialized) { sceKernelUtilsMt19937Init(&ctx, time(NULL)); initialized = 1; } int rand_val = (int)sceKernelUtilsMt19937UInt(&ctx); rand_val = lo + ( rand_val % (hi-lo) ); return rand_val; } int main() { // get random number GetRandomNum( 0, 100 ); // ctx gets initialised here the first time the function is called GetRandomNum( 0, 100 ); // but not here GetRandomNum( 0, 100 ); // nor here return 0; }[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-04-2008, 03:06 AM #7373Developer

- Registriert seit
- Aug 2007
- Beiträge
- 74
- Points
- 3.206
- Level
- 35
- Downloads
- 0
- Uploads
- 0
uh...you're passing the whole struct back? You do realise that SceMt19937Context is 625 Bytes in size.
Zitat von TMNT
Also, while Mersenne Twister is good and one of the best prng's there are. It's a lot quicker and more convenient to use the psp's hardware prng. Either via the VFPU's rand registers, or the KIRK crypto engine.
Fortunately, SCE provides a nifty api to access the crypt hw.
int sceDdrdbPrngen(u8 *rand);
You dont have to seed it (KIRK is initialised automatically on boot) and is a pure hw based prng so will be a lot faster (although the exact algo used is unknown - naturally, considering its from the security engine).
It normally returns 20 bytes, but if you only need 0-100 just take a single byte and scale it.PSP PRX LibDoc's Lives On!
http://silverspring.lan.st/
My new home:
http://my.malloc.us/silverspring/
-
01-04-2008, 03:09 AM #7374QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
I was, (it is my original re-done code), since it only happens once throughout the life of the program, it isn't that big of a deal.
Zitat von SilverSpring
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-04-2008, 01:42 PM #7375QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Zitat von yaustar
That's giving me random number outside my max and min values.
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
01-04-2008, 02:15 PM #7376QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
That is impossible. What numbers are you passing in and what are you getting out? Are you sure you are using the right random values ? E.g. Passing in 0 to 480 but setting it to the Y position of an object instead of X?
Zitat von TMNT
Write a test program that is just the random number function being called a 1000 times that spits out an error message if it goes beyond the range of the min and max values.[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-04-2008, 02:44 PM #7377QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
I just finished doing that. I even checked the values and everything. Even then, some of the values are going outside the min and max!

This is the wierdest problem i have ever had. However, this works perfectly:
I'm just going to stick with this...Code:int GetRandomNum(int lo, int hi) { SceKernelUtilsMt19937Context ctx; sceKernelUtilsMt19937Init(&ctx, time(NULL)); int rand_val = (int)sceKernelUtilsMt19937UInt(&ctx); rand_val = lo + ( rand_val % (hi-lo) ); return rand_val; }
My main question is, how do i make a tile system?Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
01-04-2008, 02:57 PM #7378lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Look at all the examples out their....That should give you an idea.
Or you can think about what a tile system does and make one...
-
01-04-2008, 03:50 PM #7379QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Do you have a link to the examples?
Side note:
OMFG!!!! I got my mp3 decoding code to work!!!!!!!!! Yes!!! Now i don't have to worry about all that lagging!!!Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
01-04-2008, 03:52 PM #7380
A tile engine is very easy to make. Search for a Lua version, and get the basic idea. From there, it'll be easy to port to C.
Zitat von TMNT
[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]
Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.


LinkBack URL
About LinkBacks

Mit Zitat antworten
). But number four does not show, it shows if i have the

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