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 didn't know about the \r, which was one of the problems, the other which was noticed by someone else ...
-
02-13-2009, 05:58 PM #9691I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I didn't know about the \r, which was one of the problems, the other which was noticed by someone else is that I was incrementing loop every time, even if nothing was added to the buffer.
Fixed code is:
Thanks though, the \r I would never have known.Code:c = fgetc(fp); for(int loop = 0; c != EOF;) { if((c != '\n') && (c != '\\') && (c != '\r')) { buffer[loop++] = c; } c = fgetc(fp); }
-Aura
-
02-13-2009, 07:44 PM #9692QJ Gamer Bronze
- Registriert seit
- Aug 2007
- Ort
- Everywhere
- Beiträge
- 206
- Points
- 5.826
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Hi. I was wonder if there was a way to manipulate the screen display, and to turn off the screen in user mode?
I know it's possible in kernel mode.Geändert von chrisp6825 (02-13-2009 um 08:01 PM Uhr)
-
02-14-2009, 06:51 AM #9693I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I can't even find a function to turn the screen off (other than lowering the brightness to 0). I doubt theres any other way, but just to make sure, you know how to wrap a kernel function and call it from a user mode application right?
-Aura
-
02-14-2009, 07:50 AM #9694QJ Gamer Bronze
- Registriert seit
- Aug 2007
- Ort
- Everywhere
- Beiträge
- 206
- Points
- 5.826
- Level
- 49
- Downloads
- 0
- Uploads
- 0
No, but I'd really appreciate an example. :)
-
02-14-2009, 08:34 AM #9695I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
The best example I can offer is in the 4.01M33 SDK. The example is with the shell, the rDriver is a kernel wrapper which you link (using a stub file) and then load the functions in user mode. Take a look at that and if that doesn't help much, I'll see if I can fish out some of my old Project4 code... but its not very tidy as it was a one-man program

-Aura
-
02-14-2009, 08:40 AM #9696QJ Gamer Bronze
- Registriert seit
- Aug 2007
- Ort
- Everywhere
- Beiträge
- 206
- Points
- 5.826
- Level
- 49
- Downloads
- 0
- Uploads
- 0
What do you mean 4.01 M33 SDK?
-
02-14-2009, 09:25 AM #9697I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Download the 4.01M33 installer, inside theres a folder called SDK, thats got some libraries M33 created which allows for some kernel functions to be called in user mode (the kernel wrappers are loaded by default in the flash). Theres also a folder with the headers, and finally one with the source code in for compiling the shell. Its basic, but does the job teaching what needs to be done.
-Aura
-
02-14-2009, 09:32 AM #9698QJ Gamer Bronze
- Registriert seit
- Aug 2007
- Ort
- Everywhere
- Beiträge
- 206
- Points
- 5.826
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Oh wow. Thanks, I'll check this out right now.
So kubridge.h is what I'm looking for.
SceUID kuKernelLoadModule()
I'm not sure how to use it though.
I need to load a module with it, so do I write my plugin with kernel functions, then load it with this?Geändert von chrisp6825 (02-14-2009 um 09:56 AM Uhr)
-
02-14-2009, 10:36 AM #9699I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Basically, you write 2 modules:
Module 1:
Kernel - 0x1000
Contains all kernel functions
Compile a stub (.s) file with all functions to link to in the main application.
Create a header file to link functions to main application.
Module 2:
User/update - 0x0000/0x0800
Contains all user functions, and kernel wrappers from module 1
Link the stub file into the makefile like any other C/++ file.
Link the header into the source that calls on those functions.
Load the module at the start (checking for errors).
Run the wrapped functions in place of the kernel ones.
A word of advice, create a checkFunc function, just to make sure linking has worked correctly:
then when you load the module, run checkFunc, and see if it returns 0x5034, if it returns <0 then an error has occured, it if returns 0x5034 then linking has worked correctly.Code:int checkFunc() { return 0x5034; }
...0x5034 only has value to me, you can use whatever you like above 0. (0x5034 = P4 in ascii).
-Aura
Is there any way I can create a temp file that exists only in RAM? I looked at tmpnam function, but I'm wondering if it creates a copy on the device. I'm trying to create an OTP system before I move on to something else and specifically need no data to be written before the encryption or after the decryption, but I want to be able to launch the decrypted file in whatever application it should be launched from.Geändert von Auraomega (02-14-2009 um 06:06 PM Uhr)
-
02-15-2009, 11:20 AM #9700QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- Perth, Scotland
- Beiträge
- 1.094
- Points
- 8.475
- Level
- 62
- Downloads
- 0
- Uploads
- 0
-
02-15-2009, 12:13 PM #9701I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
The late binding goes in the exports file correct? Just to make sure, it goes something like this:
or does it go with syslib?Code:PSP_EXPORT_START(STUBNAME, 0, 0x4009)
-Aura
Edit:
Just wrote a test to confirm what I previously thought about tmpnam. Ran the program, paused, remove my SD card, continued the application and it gave me errors that the volume doesn't exist. I need a method that means the plain text files only exists in RAM and never get written to the drive.
I did have the thought though that it might just have to believe that its writing to the SD card to exist, so if anyone could confirm this I'd be happy, if not is there any cross platform libraries that do supply this ability?Geändert von Auraomega (02-15-2009 um 12:46 PM Uhr)
-
02-15-2009, 05:05 PM #9702QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Just keep a buffer in ram, modify it to your liking, then when you need to save it, just write the whole thing to the memory card.
-
02-15-2009, 05:12 PM #9703QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- Perth, Scotland
- Beiträge
- 1.094
- Points
- 8.475
- Level
- 62
- Downloads
- 0
- Uploads
- 0
-
02-16-2009, 01:37 AM #9704QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- Netherlands
- Beiträge
- 148
- Points
- 5.672
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Hi I followed: http://www.psp-programming.com/code/...heport-lesson1
But it doesn't seem to work :Cry:
http://pastebin.com/m4741ad73[SIZE="1"][color=#D1D1FF]______________________________________________________________[/color]
[i]Last edited by basfreak; 01-01-1990 at [color=#666686]12:00 PM[/color][/i].[/SIZE]
-
02-16-2009, 06:03 AM #9705I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
@_dysfunctional:
I want to be able to open the document in other programs though, such as a text editor or image viewer, something like that so a temp file seemed best. Either way I found a method using ramfs on Linux.
@basfreak:
Two problems I noticed, one, your makefile is building an elf, you want a prx, use BUILD_PRX = 1. The second is building a prx gives you 32kb of heap, not enough to run a program like this. The HEAP_SIZE_KB macro will fix this, just give yourself a few mb and you should be good to go.
-Aura
-
02-16-2009, 06:14 AM #9706QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- Netherlands
- Beiträge
- 148
- Points
- 5.672
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Still only displays:
FPS: 1578
till
FPS: 1580

Code:#include "main.h" PSP_MODULE_INFO("Lesson1", 0, 1, 1); PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER); PSP_HEAP_SIZE_KB(20480); void *dList; // display List, used by sceGUStart void *fbp0; // frame buffer int fps = 0; // for calculating the frames per second char fpsDisplay[100]; u32 tickResolution; u64 fpsTickNow; u64 fpsTickLast; Vertex __attribute__((aligned(16))) triangle[3] = { { GU_COLOR( 1.0f, 1.0f, 1.0f, 0.0f ), 0.0f, 1.0f, 0.0f }, // top point { GU_COLOR( 1.0f, 1.0f, 1.0f, 0.0f ), 1.0f,-1.0f, 0.0f }, // left point { GU_COLOR( 1.0f, 1.0f, 1.0f, 0.0f ),-1.0f,-1.0f, 0.0f } // right point }; Vertex __attribute__((aligned(16))) quad[4] = { { GU_COLOR( 1.0f, 1.0f, 1.0f, 0.0f ),-1.0f, 1.0f, 0.0f }, // top-left point { GU_COLOR( 1.0f, 1.0f, 1.0f, 0.0f ), 1.0f, 1.0f, 0.0f }, // top-right point { GU_COLOR( 1.0f, 1.0f, 1.0f, 0.0f ),-1.0f,-1.0f, 0.0f }, // bottom-left point { GU_COLOR( 1.0f, 1.0f, 1.0f, 0.0f ), 1.0f,-1.0f, 0.0f } // bottom-right point }; void FPS( void ) { fps++; sceRtcGetCurrentTick( &fpsTickNow ); if( ((fpsTickNow - fpsTickLast)/((float)tickResolution)) >= 1.0f ) { fpsTickLast = fpsTickNow; sprintf( fpsDisplay, "FPS: %d", fps ); fps = 0; } pspDebugScreenSetOffset( (int)fbp0 ); pspDebugScreenSetXY( 0, 0 ); pspDebugScreenPrintf( fpsDisplay ); } void InitGU( void ) { // Init GU sceGuInit(); sceGuStart( GU_DIRECT, dList ); // Set Buffers sceGuDrawBuffer( GU_PSM_8888, fbp0, BUF_WIDTH ); sceGuDispBuffer( SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH); sceGuDepthBuffer( (void*)0x110000, BUF_WIDTH); sceGuOffset( 2048 - (SCR_WIDTH/2), 2048 - (SCR_HEIGHT/2)); sceGuViewport( 2048, 2048, SCR_WIDTH, SCR_HEIGHT); sceGuDepthRange( 65535, 0); // Set Render States sceGuScissor( 0, 0, SCR_WIDTH, SCR_HEIGHT); sceGuEnable( GU_SCISSOR_TEST ); sceGuDepthFunc( GU_GEQUAL ); sceGuEnable( GU_DEPTH_TEST ); sceGuFrontFace( GU_CW ); sceGuShadeModel( GU_SMOOTH ); sceGuEnable( GU_CULL_FACE ); sceGuEnable( GU_CLIP_PLANES ); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); // finish } void SetupProjection( void ) { // setup matrices for the triangle sceGumMatrixMode(GU_PROJECTION); sceGumLoadIdentity(); sceGumPerspective( 75.0f, 16.0f/9.0f, 0.5f, 1000.0f); sceGumMatrixMode(GU_VIEW); sceGumLoadIdentity(); sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f ) ); sceGuClearDepth(0); } void DrawScene( void ) { sceGuStart( GU_DIRECT, dList ); // clear screen sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); sceGumMatrixMode(GU_MODEL); sceGumLoadIdentity(); { ScePspFVector3 move = { 3.0f, 0.0f, 0.0f }; sceGumTranslate( &move ); } // Draw Triangle sceGumDrawArray( GU_TRIANGLES, GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 3, 0, triangle ); sceGuFinish(); sceGuSync(0,0); } int main(int argc, char **argv) { pspDebugScreenInit(); SetupCallbacks(); sceRtcGetCurrentTick( &fpsTickLast ); tickResolution = sceRtcGetTickResolution(); dList = memalign( 16, 640 ); fbp0 = 0; InitGU(); SetupProjection(); while( 1 ) { DrawScene(); FPS(); //sceDisplayWaitVblankStart(); fbp0 = sceGuSwapBuffers(); } sceGuTerm(); // Terminating the Graphics System // Free Memory free( dList ); free( fbp0 ); sceKernelExitGame(); return 0; }Oh, this part:Code:TARGET = LessonOne OBJS = ./main.o INCDIR = LIBDIR = LDFLAGS = LIBS = -lpspgum -lpspgu -lpsprtc -lstdc++ -lm CFLAGS = -O2 -G0 -Wall CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) BUILD_PRX = 1 EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = Lesson1 PSPSDK = $(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak ./main.o: ./main.cpp $(CXX) $(CXXFLAGS) -c ./main.cpp -o ./main.o
What does the brackets around the move variables do?Code:sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); sceGumMatrixMode(GU_MODEL); sceGumLoadIdentity(); { ScePspFVector3 move = { 3.0f, 0.0f, 0.0f }; sceGumTranslate( &move ); } // Draw Triangle
Ty:Punk:[SIZE="1"][color=#D1D1FF]______________________________________________________________[/color]
[i]Last edited by basfreak; 01-01-1990 at [color=#666686]12:00 PM[/color][/i].[/SIZE]
-
02-16-2009, 08:10 AM #9707I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Off the top of my head I can't see any mistakes, it sounds like the image is being drawn off screen, if being drawn at all. Try changing:
to:Code:ScePspFVector3 move = { 3.0f, 0.0f, 0.0f };
to keep it centered(ish, can't remember exactly how it works).Code:ScePspFVector3 move = { 0.0f, 0.0f, 0.0f };
As for what the { } means, move is an array and you're initialising it with 3 values, its then being fed into sceGumTranslate which moves it on the drawing position on the screen by {X, Y, Z}, similar to glTranslatef(X, Y, Z).
Have you done any OGL stuff on the PC? If not I'd suggest playing around with it first and get a feel for 3D developing, then move to GU once you have an understanding of how things work; DirectX/OGL/GU is harder than most 2D libraries to learn so it'd be worth your time learning on the PC where mistakes are easier to rectify.
-Aura
-
02-16-2009, 09:10 AM #9708QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- Netherlands
- Beiträge
- 148
- Points
- 5.672
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Hmm, okay.
But I actually meant the { after loadIdentity.[SIZE="1"][color=#D1D1FF]______________________________________________________________[/color]
[i]Last edited by basfreak; 01-01-1990 at [color=#666686]12:00 PM[/color][/i].[/SIZE]
-
02-16-2009, 09:20 AM #9709QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
The curly-brackets that separate the two lines you are talking about simply put them in a new scope.
Also, ScePspFVector3 is not an array, it's a structure.
Additionally, a PRX has 64kb of heap by default.
As for your actual problem, try moving the polygon back by translating it a bit on the z axis.
Like:
PHP-Code:ScePspFVector3 move;
move.x = 3.0f;
move.y = 0.0f;
move.z = 3.0f; // Or -3.0f, I can't remember which direction is positive on the z axis on the PSP.
sceGumTranslate(&move);
-
02-16-2009, 09:26 AM #9710I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Haha, sorry I didn't realise.
Its a scope; any variable declared in a scope is removed from the stack at the end of that scope, for example:
Its handy if you need to work with a large string or a set of variables, but only want to use it for a small period of time.Code:int intA; int newFunc() { //this function can access intA as its a global } int main() { int intB = 1; //we can access intA and intB here { int intC; //this scope can access intA, intB and intC { int intD; //here we can access intA, intB, intC } //when we've reached this intD is no longer availabe } //we can access intA and intB here, but not intC as it no longer exists { int intC; //we can reuse the variable here as it was removed at the end of the scope } if(intB == 1) { char string[256]; //string is available in this scope } //string is no longer available here }
I think _dysfunctional is right as well, I hadn't thought about the Z axis. Negative is closer towards us and positive is futher away though, so the possitive is correct... and yeah, ignore my dumb comment on the array, an array would be something like char string[256];
-Aura
-
02-18-2009, 06:56 PM #9711I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I want to create a basic file transfer and chat client in C/++, but I'm not sure where to start from. I believe I need to use sockets, but I can't find a good guide as they all seem to be totally different from each other. Are sockets cross platform? If so do any of you know a good tutorial on sockets?
-Aura
-
02-18-2009, 08:53 PM #9712xMod.
- Registriert seit
- Oct 2008
- Ort
- Melbourne, Australia
- Beiträge
- 675
- Points
- 4.576
- Level
- 43
- My Mood
-
- Downloads
- 0
- Uploads
- 0
im pretty sure that theres a sample in the sdk that sends a string over adhoc to a second psp
-
02-19-2009, 12:53 AM #9713QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- Netherlands
- Beiträge
- 148
- Points
- 5.672
- Level
- 48
- Downloads
- 0
- Uploads
- 0
I think he meant from PC to PC, although this is in the PSP Development Forum:o
[SIZE="1"][color=#D1D1FF]______________________________________________________________[/color]
[i]Last edited by basfreak; 01-01-1990 at [color=#666686]12:00 PM[/color][/i].[/SIZE]
-
02-19-2009, 06:16 AM #9714I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Yeah I meant for PC-PC transfers... its a PSP development forum but a C/++ thread, and hey, saves me signing up to some other website for 1 question... plus I've come to trust the opinions of quite a few devs on here, even if their method seems awkward at first.
-Aura
-
02-19-2009, 03:50 PM #9715QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Auraomega, http://beej.us/guide/bgnet/
Try to finish most of the tutorial and memorize some basic functions and structures. If you can do that, then you will find network programming a piece of cake ;) . If you can't, there's always the .NET framework.[CODE]Random Facts:
irc://irc.malloc.us #wtf #**********
[/CODE]
[SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]
-
02-19-2009, 04:52 PM #9716QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Gah, my head hurts so bad. I think I see aComa coming.
-
02-19-2009, 07:00 PM #9717QJ Gamer Blue
Achievements:
- Registriert seit
- Feb 2009
- Beiträge
- 9
- Points
- 1.997
- Level
- 26
- Downloads
- 0
- Uploads
- 0
Ok, so I have this square. That rotates in a circle when I press R. It rotates fine, but I am trying to use oslibprintf to print the current angle as it rotates. (to help me debug)
It's rotating fine with this
But this is how I am trying to print it. I really don't know exactly what to write. I thought %i displays the variable (read something like that in a tut,)Code:if (osl_keys->held.R) { square_t->angle++; }
My compiler gives me an error on this line saying : warning: format '%i' expects type 'int', but argument 3 has type 'double'Code:oslPrintf_xy(20,20, " Rotation Degree: %i",square_t->angle);
-
02-19-2009, 07:07 PM #9718Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Use %f.
See http://www.cplusplus.com/reference/c...io/printf.html for more information, including what %i is actually for.
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
-
02-19-2009, 07:14 PM #9719QJ Gamer Blue
Achievements:
- Registriert seit
- Feb 2009
- Beiträge
- 9
- Points
- 1.997
- Level
- 26
- Downloads
- 0
- Uploads
- 0
Ok, well, I used f%, and it still doesn't work. So I'm thinking there might be another problem. Maybe my print command is in the wrong place?
and what are all the initializations that i need before it?
edit:
aha. yeah. it was in the wrong place. it's working now. thanks
-=Double Post Merge =-
Ok, This is probably and easy one.
I'm trying to change the position on my sprite when the value of my function is between 1 and 22
if (square_t->angle = >1 && <22 ) sprite_position = URIGHT;
All I really wanna know is how I should write the bolded part?Geändert von Jmaxx (02-19-2009 um 08:22 PM Uhr) Grund: Automerged Doublepost
-
02-19-2009, 08:25 PM #9720OMFG

- Registriert seit
- Jul 2005
- Ort
- Toronto
- Beiträge
- 2.814
- Points
- 19.453
- Level
- 88
- Downloads
- 0
- Uploads
- 0
Code:if ( ( square_t->angle >= 1 ) && ( square_t->angle < 22 ) ) sprite_position = URIGHT;


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