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 waterbottle if (x>=50) is true if x is larger then or equal to 50. but since you never ...
-
10-08-2006, 10:59 AM #1171Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
haha lol , that was in my programm , but i dindt written it in this thread;)
Zitat von waterbottle
-
10-08-2006, 12:29 PM #1172QJ Gamer Bronze
- Registriert seit
- Jul 2005
- Ort
- USA
- Beiträge
- 496
- Points
- 14.090
- Level
- 77
- Downloads
- 0
- Uploads
- 0
How do I make an If,Then statement satisfy multiple conditions?
I always do stuff in LUA and now want to learn C++. Im using the oslib (Old School Lib) to make a little sample thing to get expierence.Code:if (k->held.cross & sel = 1) //code;
Just help and dont give smartass comments.
-
10-08-2006, 12:32 PM #1173AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Code:Logical AND (what you want) if(statement1 && statement2) Bitwise AND if(statement1 & statement2) Logical OR if(statement1 || statement2) Bitwise OR (not sure about this one :P) if(statement1 | statement2)
-
10-08-2006, 12:35 PM #1174QJ Gamer Bronze
- Registriert seit
- Jul 2005
- Ort
- USA
- Beiträge
- 496
- Points
- 14.090
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Thanks. I'll try figure out all the other problems myself.
-
10-08-2006, 12:54 PM #1175AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Feel free to post here, that's what this thread's supposed to be for you know :Punk:
Zitat von CtrlAltDeleteDie
-
10-08-2006, 12:59 PM #1176words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Homer - You're correct, there's bitwise and logical AND, OR operators. But bitwise can return more than 1 or 0 ;)
Oh and homer - You're good with emulators, per say, right? think you could help me with a little... problem... Ill pm you with details if you want to, id very appreciate it :)
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
10-08-2006, 01:04 PM #1177AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Okay, sure. I might be able to help
Zitat von SG57
-
10-08-2006, 01:15 PM #1178words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Ok sweet, how can i contact you? AIM (recommended), MSN, IRC, PM (not recommened)?
I find it better to give you info in portions then one large PM :o
P.S. Thanks for this
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
10-08-2006, 01:20 PM #1179QJ Gamer Bronze
- Registriert seit
- Jul 2005
- Ort
- USA
- Beiträge
- 496
- Points
- 14.090
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Ok. I decided to post again...
I probably dont need to post all this, but I will anyways.
The main error I got was, "paint was not declared in this scope". As you can tell I have no idea what I am doing, but I am learning from trial and error.Code:int main(int argc, char* argv[]) { //Initialize the different parts of the library oslInit(0); oslInitGfx(OSL_PF_8888, 1); oslSetBkColor(RGBA(0,0,0,0)); oslSetTextColor(RGB(255,255,255)); oslInitConsole(); OSL_CONTROLLER *k; //Main loop while (!osl_quit) { //Display code oslStartDrawing(); paint = oslLoadImageFile("ms0:/img.png", OSL_IN_VRAM, OSL_PF_8888); //Draw oslDrawGradientRect(0, 0, 480, 272, RGB(255,255,255), RGB(255,255,255), RGB(100,100,100), RGB(100,100,100)); oslDrawFillRect(50, 50, 150, 150, RGB(255,0,0)); .........
-
10-08-2006, 01:24 PM #1180AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
You haven't declared paint as a datatype, I have no idea what the image struct is called in oslib. I'm sure it says in the documentation though (if it has any).Code:paint = oslLoadImageFile("ms0:/img.png", OSL_IN_VRAM, OSL_PF_8888);
-
10-08-2006, 01:24 PM #1181words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
It's correct. 'paint' is uninitialized. What data type must 'paint' be? Proably a structure pointer, but... to what? (i dont know OSL)
EDIT
homer beat me to it :Argh:
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
10-08-2006, 01:27 PM #1182sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
The bitwise OR (|) take two numbers like this:
110101101
101011101
------------
111111101
-
10-08-2006, 01:30 PM #1183AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
EDIT (or something).
I think the stuct you want is named OSL_IMAGE.
So the paint line should look like this
However, you probably want to put that outside (before) the main loop or it'll load the image on each loop :PCode:OSL_IMAGE *paint = oslLoadImageFile("ms0:/img.png", OSL_IN_VRAM, OSL_PF_8888);
-
10-08-2006, 02:55 PM #1184QJ Gamer Bronze
- Registriert seit
- Jul 2005
- Ort
- USA
- Beiträge
- 496
- Points
- 14.090
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Thanks again Homer. I dont know why I didn't include that in the code before.
-
10-08-2006, 03:20 PM #1185likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
can you help me?
the problem is, that it compiles but when i load it the screen isnt fully blue and when i useCode:#include <pspdisplay.h> #include <pspgu.h> #include <pspkernel.h> #include <pspctrl.h> #include <pspdebug.h> #include <stdlib.h> #include <stdio.h> #include <math.h> #include <time.h> #include <png.h> #include <string.h> #include "graphics.h" #include "framebuffer.h" #include "flib.h" #define printf pspDebugScreenPrintf #define dprint pspDebugScreenPrintf #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) #define true 1 #define false !true #define bool int #define NULL 0 PSP_MODULE_INFO("OMG HAX!!!!1", 0, 1, 1); /* Standard callbacks */ int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } int rand_nums() { short rn0 = 0; short rn1 = 0; short rn2 = 0; bool win_status = false; SceCtrlData pad; sceCtrlPeekBufferPositive(&pad, 1); srand(sceKernelLibcTime(NULL)); if(pad.Buttons & PSP_CTRL_CROSS) { rn0=rand()%1,3; rn1=rand()%1,3; rn2=rand()%1,3; } if(rn0 == 1 && rn1 == 1 && rn2 == 1) { win_status=true; if(win_status == true) { pspDebugScreenSetXY(0,2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("You won.\n"); pspDebugScreenPrintf("Press '~X~' to restart.\n"); sceKernelSleepThread(); if(pad.Buttons & PSP_CTRL_CROSS) { rand_nums(); } } } if(rn0 == 2 && rn1 == 2 && rn2 == 2) { win_status=true; if(win_status == true) { pspDebugScreenSetXY(0,2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("You won.\n"); pspDebugScreenPrintf("Press '~X~' to restart.\n"); sceKernelSleepThread(); if(pad.Buttons & PSP_CTRL_CROSS) { rand_nums(); } } } if(rn0 == 3 && rn1 == 3 && rn2 ==3) { win_status=true; if(win_status == true) { pspDebugScreenSetXY(0,2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("You won.\n"); pspDebugScreenPrintf("Press '~X~' to restart.\n"); sceKernelSleepThread(); if(pad.Buttons & PSP_CTRL_CROSS) { rand_nums(); } } } if(rn0 == 0 && rn1 == 0 && rn2 == 0) { pspDebugScreenSetXY(0,2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("Press '~X~' to start\n"); sceKernelSleepThread(); if(pad.Buttons & PSP_CTRL_CROSS) { pspDebugScreenSetXY(0,2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); rn0=rand()%1,3; rn1=rand()%1,3; rn2=rand()%1,3; } } } int main(void) { pspDebugScreenInit(); SetupCallbacks(); initGraphics(); void show_errmsg(const char *errmsg); while(true) { rand_nums(); } return 0; }
It makes the screen flicker.Code:flipScreen();
-
10-08-2006, 04:37 PM #1186Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von psphacker12.
its not :
its:Code:while (true) {
Code:while (1) {--------------------------------------------------------------------------------------
-
10-08-2006, 04:50 PM #1187likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
ok ill try that then
Zitat von Grimfate126
edit: that makes absolutley no difference..Geändert von psphacker12. (10-08-2006 um 05:12 PM Uhr)
-
10-08-2006, 05:06 PM #1188words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Technically, if you define true as 1, it works ;)

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
10-08-2006, 05:07 PM #1189sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
duh...
Code:#define true 1
lol
-
10-08-2006, 06:05 PM #1190Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
hey, im not THAT dumb. ;)
Zitat von SG57
psp
, then i dunno whats wrong.. (too lazy to inspect the whole entire code.)
--------------------------------------------------------------------------------------
-
10-08-2006, 06:16 PM #1191QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Egypt
- Beiträge
- 378
- Points
- 5.300
- Level
- 46
- Downloads
- 0
- Uploads
- 0
would anybody be kind enough and help me?
ive read the insomaniacs tutorial and i followed everything written on the screen..the last step claims to change the path to a certain thing
starts with @off
cywin worked before that, but now it doesnt start. does anybody know what the path to cygwin was before chainging it so i can reinstall the toolchain (im guessing thats my problem) although ive installed it already...
Edit://
I got it :) But thanks anybody to anyone willing to help...
-
10-09-2006, 07:53 AM #1192QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Strings
Hi, I'm having troubles with strings recieved via TCP; I'm getting a string "[list of artists]" from a simple TCP echo server (you don't need to view this, all it does is recieve a command (string) from the client and answer "[list of artists]".
Spoiler for server code:
More relevant code; How the client recieves the string from the server:
IMHO seems fine, but look what he does:Code:command = "get_artists"; command_len = strlen(command); if (send(socket, command, command_len, 0) != command_len) { printf("send() sent a different length of bytes than expected!\n"); return; } printf("sending command get_artists...\n"); printf("recieving...\n"); while(rc!=SOCKET_ERROR) { printf("Recieving package %d\n", i); rc = recv(socket,buf,256,0); buf[rc]='\0'; if(rc==0) { printf("Server has closed the connnection\n"); break; } if(rc==SOCKET_ERROR) { printf("Error: recv, error-code: %s\n",strerror(errno)); break; } strcat(recivedMessage, " - "); strcat(recivedMessage, buf); printf("buf: %s\n", buf); printf("recivedMessage: %s\n", recivedMessage); i++; } printf("\n\nget_artists returned: %s\n", recivedMessage);

Could it be that he prints buf, which as an array has the size of 265, completely, the whole 256 chars?
-= Double Post =-
PS: Damn that psp is dirty!Geändert von Lukeson (10-09-2006 um 07:53 AM Uhr) Grund: Automerged Doublepost
-
10-09-2006, 07:59 AM #1193
from the look at your picture:buf[rc]='\0';
if(rc==0)
{
printf("Server has closed the connnection\n");
break;
}
you set a Null terminating character depending on rc (recieved bytes).
In your photo you also see that the psp puts out "Server has closed the connection"
This only happens if rc==0;
so in your case yout set '\0' or 0x00 immediately at the first position of your char buffer.
Furthermore printf only puts out chars till he finds '\0' so it's clear why you don't get anything ;)
-
10-09-2006, 08:01 AM #1194QJ Gamer Bronze
- Registriert seit
- Jul 2005
- Ort
- USA
- Beiträge
- 496
- Points
- 14.090
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Im having trouble compiling a program in CYGWIN. It compiles an .elf file which i can just rename to a .pbp, but I gives an arror when it goes to make a .pbp. Ill post what CYGWIN spits out.
Help?Code:........ -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o Square.elf psp-fixup-imports Square.elf psp-strip Select Square.elf -o Select Square_strip.elf Usage: psp-strip <option(s)> in-file(s) Removes symbols and sections from files The options are: -I --input-target=<bfdname> Assume input file is in format <bfdname> -O --output-target=<bfdname> Create an output file in format <bfdname> -F --target=<bfdname> Set both input and output format to <bfdname> -p --preserve-dates Copy modified/access timestamps to the output -R --remove-section=<name> Remove section <name> from the output -s --strip-all Remove all symbol and relocation information -g -S -d --strip-debug Remove all debugging symbols & sections --strip-unneeded Remove all symbols not needed by relocations --only-keep-debug Strip everything but the debug information -N --strip-symbol=<name> Do not copy symbol <name> -K --keep-symbol=<name> Only copy symbol <name> -w --wildcard Permit wildcard in symbol comparison -x --discard-all Remove all non-global symbols -X --discard-locals Remove any compiler-generated symbols -v --verbose List all object files modified -V --version Display this program's version number -h --help Display this output --info List object formats & architectures supported -o <file> Place stripped output into <file> psp-strip: supported targets: elf32-littlemips elf32-bigmips elf64-bigmips elf64 -littlemips elf64-little elf64-big elf32-little elf32-big srec symbolsrec tekhex binary ihex make: *** [EBOOT.PBP] Error 1
-
10-09-2006, 08:03 AM #1195AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Do you use the sdk makefile or your custom?
-
10-09-2006, 08:07 AM #1196QJ Gamer Bronze
- Registriert seit
- Jul 2005
- Ort
- USA
- Beiträge
- 496
- Points
- 14.090
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Makefile:
Code:TARGET = Select Square OBJS = main.o YOURLIBS= INCDIR = CFLAGS = -G4 -Wall -O2 CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) LIBDIR = LDFLAGS = STDLIBS= -losl -lpng -lz \ -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm LIBS=$(STDLIBS)$(YOURLIBS) EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = SelectPSP PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak
-
10-09-2006, 08:10 AM #1197QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 499
- Points
- 5.848
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Right o Chaps, i got a problem, Cygwin is broke, and i cant delete it to get rid of it to re-install..
It comes up with a Error saying the folder cant be deleted, but that is utter crap since i've tried numerous unlocking programs, and i'm also the owner of the folder according to windows security.
Anyway to delete this pile of steaming **** off my harddrive ?
-
10-09-2006, 08:29 AM #1198QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
So I put "buf[rc]='\0';" after the break, but he still prints those huge spaces instread of a nice and clean
Zitat von tommydanger
sending command get_artists...
recieving...
Recieving package 1
buf: [list of artists]
recivedMessage: [list of artists]
Server has closed the connnection
get_artists returned: [list of artists]
What he prints:
-
10-09-2006, 08:35 AM #1199
no this is due to the linefeeds you added in your printf commands "\n"
last statement:
printf("\n\nget_artists returned: %s\n", recivedMessage);
make 2 linfeeds before writing the string ;)
-
10-09-2006, 09:06 AM #1200QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
such a huge space?
Zitat von tommydanger
What? that'd be even more space!
Zitat von tommydanger
-= Double Post =-
Could it be because 'buf' is a array of the size of 265?
-= Double Post =-
I reduced the size of the array to 56 and still get the same screenCould it be because 'buf' is a array of the size of 265?
(
Geändert von Lukeson (10-09-2006 um 09:06 AM Uhr) Grund: Automerged Doublepost


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