_dysfunctional, PLEASE write a tutorial on Wifi!
Printable View
_dysfunctional, PLEASE write a tutorial on Wifi!
Zitat:
Zitat von Judas
You could do that, too.Code:int myNum;
FILE* pFile = fopen("file.txt", "r");
/* Error Checking */
/* Get an variable amount of (formatted) values from a file. Similar to scanf. */
fscanf(pFile, "%d", &myNum);
I'll write a tutorial probably tomorrow if I have time. I have a school project due Monday.
Still having Troubles with reading the high score, and saving the new one, here is what i have so far,
and i call it with, scorecmp(Score);Code:void scorecmp(int current_score)
{
int high_score;
FILE* fd = fopen("HI.txt","rb");
u32 filesize = fsize(fd);
char* buffer = (char*)malloc(filesize + 1);
fread(&buffer,1,filesize,fd);
high_score = atoi(buffer);
if(high_score > current_score) { // do nothing
}else if(current_score > high_score) {
sprintf(nhscore, "%s with %d points!",lname, Score);
FILE * pFile;
pFile = fopen ("SCORE.txt" , "w");
fwrite (nhscore , 1 , 29 , pFile);
fclose (pFile);
FILE * hsFile;
hsFile = fopen ("HI.txt" , "w");
fwrite (Score , 1 , 29 , hsFile);
fclose (hsFile);
}else{ // They are equal. DO whatever you want.
free(buffer);
}
}
Sure you can.Zitat:
Zitat von hallo007
Doesn't mean that you should, but you can.Code:int a = 0;
int main(void)
{
printf("%d\n",a);
if(!a++)
main();
return 0;
}
-= Double Post =-
You might wanna be careful with what you did in that program.Zitat:
Zitat von BlackShark
It can lead to memory leaks since you allocate memory but you don't free the memory you allocated after you exit the function. The memory is still allocated but inaccessible because the function has ended. That is why I didn't put return; after theCode:else{ // They are equal. DO whatever you want.
free(buffer);
}
"if(high_score > current_score) " because if the case is true, it will branch to the free(buffer); and still return control to the calling sub routine.
Anyway, this should work.
Code:void scorecmp(int current_score)
{
int high_score;
u32 filesize;
FILE* fd;
if(!fd = fopen("HI.txt","rb"))
freopen("HI.txt","wb",fd); // Create the file if it doesn't exist.
if(filesize = fsize(fd)) // If the file size is greater than 0.
{
char* buffer = (char*)malloc(filesize + 1);
fread(&buffer,1,filesize,fd);
high_score = atoi(buffer);
if(high_score > current_score)
;
else if(current_score > high_score)
{
FILE * pFile = fopen ("SCORE.txt" , "wb");
fprintf(pFile,"%s with %d points!",lname,current_score);
fclose(pFile);
freopen("HI.txt","wb",fd); // reopen the file in write mode.
fprintf(fd,"%d",current_score); // Save the high score
}
else // They are equal. DO whatever you want.
;
free(buffer);
}
else // if the file size is 0, then there is no high score. Save the current score as the high.
fprintf(fd,"%d",current_score);
fclose(fd);
}
I've Found my "i don't see any text" problem :)
i forgot the "flipscreen();" command:Argh:
it will work , but u know what I meanZitat:
Zitat von Moca
Is it possible to use printf functions on top of an image?
And I'm getting 0x800200D9 when trying to load a .elf with pspSdkLoadStartModule... is it because I'm trying to load a .elf, or is it another reason?
-Aura
To use the printf function on top of an image, I believe you have to set the background transparent by adjusting the alpha value.
I'm using the graphics.c stuff, so would I need to lower the alpha on the .png I'm blitting? Or would I be better off trying to change the way it loads?Zitat:
Zitat von Judas
While I'm here... what needs to be changed to convert an app to the 3.XX kernel?
-Aura
0x800200D9 means memory block allocation failed, presumably because there wasn't enough space to load it.Zitat:
Zitat von Auraomega
Yeah, I looked it up, the reason I asked is because it doesn't make sense... the file is only 300kb big, and there should be a lot more space than that free...Zitat:
Zitat von Archaemic
@Judas:
I just tried increased the alpha value, but no luck, still no text appears.
-Aura
You need to DECREASE an alpha value to make it transparent.Zitat:
Zitat von Auraomega
Sorry, I meant to say I increased the transparency... but yeah, even with a lower alpha level I still don't see text.Zitat:
Zitat von JaSo PsP
-Aura
Thanks, but theres a problem, after adding a few { and } were needed, i only have 1 problem left,Zitat:
Anyway, this should work.
Code:void scorecmp(int current_score)
{
int high_score;
u32 filesize;
FILE* fd;
if(!fd = fopen("HI.txt","rb"))
freopen("HI.txt","wb",fd); // Create the file if it doesn't exist.
if(filesize = fsize(fd)) // If the file size is greater than 0.
{
char* buffer = (char*)malloc(filesize + 1);
fread(&buffer,1,filesize,fd);
high_score = atoi(buffer);
if(high_score > current_score)
;
else if(current_score > high_score)
{
FILE * pFile = fopen ("SCORE.txt" , "wb");
fprintf(pFile,"%s with %d points!",lname,current_score);
fclose(pFile);
freopen("HI.txt","wb",fd); // reopen the file in write mode.
fprintf(fd,"%d",current_score); // Save the high score
}
else // They are equal. DO whatever you want.
;
free(buffer);
}
else // if the file size is 0, then there is no high score. Save the current score as the high.
fprintf(fd,"%d",current_score);
fclose(fd);
}
Here is line 166, any ideas? (also, thank you for all your help so far, not just moca, but every body)Code:space_game.c(166) : error: invalid lvalue in assignment
Code:if(!fd = fopen("HI.txt","rb")){
if( ( fd = fopen("HI.txt","rb") ) < 0 )
fopen returns NULL, not necessarily a negative number.
Try:
Code:fd = fopen("hi.txt", "rb");
if(!fd)
{
/* Error */
}
I've made a function that edits a string, but I can't seem to return it to the calling function...
This doesn't do anything, and gives me a warning upon compilation, I have tried changing toCode:void keyboard(char* string)
{
string = "text\0";
}
int main()
{
char string[256];
keyboard(&string);
}
but that gives me an lvalue error,Code:*string = "text\0";
but this only removes the warning.Code:keyboard(string);
Can anyone tell me what I'm doing wrong?
-Aura
Strings don't work with the 'equals' operator like integers do.
Try this.
Code:void keyboard(char* string)
{
memset(string, '\0', strlen(string));
strcpy(string, "text");
}
Ok, I was trying to cut back on my code... its a bit more complex than that...Zitat:
Zitat von _dysfunctional
I'm editing each letter individually, and then adding a \0 to the next byte each time, so my code looks more like...
and I'm doing this a lot of times, the string is meant to be variable length and variable text, and as you may have guessed its to be a keyboard, using strncat would be tedious, and hard to reverse when going back a character, using this method should work... I also get an output when I use printf, so I know the string is getting written correctly, its simply getting it back to the calling function I'm having problems with.Code:string[number] = 'a';
string[number+1] = '\0';
-Aura
<_<
nvm, junkie answered you <_<Code:void keyboard(char** string)
{
*string = "text";
}
int main()
{
char *string;
keyboard(&string);
}
Ok, sorted it... the strcpy worked, but didn't give enough flexabilty, so I made a new string in my keyboard function, messed around with that string, then used strcpy at the very end to copy it back to the pointed string :tup:
-Aura
Is it possible for a plugin to call another prx?
I tried sceKernelLoadExec() and sceKernelLoadModule()/sceKernelStartModule() but had no success.
Can I have some code snippet?
A snippet from my XMBE...Zitat:
Zitat von petervaz
I did run into some problems myself when making XMBE-S, I had to load up the plugin, and start a new thread, which may or may not seem obvious...Code:SceUID mod = sceKernelLoadModule(file, 0, NULL);
if(mod>0) mod = sceKernelStartModule(mod, args, argp, NULL, NULL);
That sorted everything out, of course, if it still refuses to load you could put some debug into it, and see if you are getting an error code when loading, just use PSPLink for that.Code:int main(SceSize args, void* argp)
{
SceUID startthread = sceKernelCreateThread("Screen_Saver", __main, 0x30, 0x10000, 0, NULL);
sceKernelStartThread(startthread, args, argp);
sceKernelExitDeleteThread(0);
}
-Aura
Thanks Aura.
Are you passing arguments on args and argp?
The exemple I found was using zeros.
Not that I know of, I just never tried putting 0s into a new thread, so I had to start the function with args and argp, guess using 0s should be fine.Zitat:
Zitat von petervaz
I'm having a problem with my code, its not copying correctly, I either get too much data copied or to little data, just wondering if anyone can point out my error.
-AuraCode:while(1)
{
fgets(byte, 1024*200, org);
//byte[(1024*200)+1] = '\0';
fputs(byte, nwf);
pspDebugScreenSetXY(x, y);
data+=(sizeof(byte)); //incorrect, edit!
_printf("%u bytes", data);
if(feof(org)) break;
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CROSS) break;
}
Hey folks! :)
When I make a .PRX that has exports, how do I get the function IDs (the hashes) used to import them into another program?
:)
alright, im getting close, it works once, but then it just stops working, when i look at HI.txt on my computer, it sais its currupted... here is the function again,Zitat:
Zitat von Moca
Code:void scorecmp(int current_score)
{
int high_score;
u32 filesize;
FILE* fd = fopen("HI.txt","rb");
if(!fd) {
pspDebugScreenPrintf(" Please create the HI.txt\n");
pspDebugScreenPrintf(" file in the game folder...exiting");
wait(500);
sceKernelExitGame();
}
if(filesize = fsize(fd)) // If the file size is greater than 0.
{
char* buffer = (char*)malloc(filesize + 1);
fread(&buffer,1,filesize,fd);
high_score = atoi(buffer);
if(high_score > current_score) {
}else if(current_score > high_score)
{
FILE * pFile = fopen ("SCORE.txt" , "wb");
fprintf(pFile,"%s with %d points!",lname,current_score);
fclose(pFile);
freopen("HI.txt","wb",fd); // reopen the file in write mode.
fprintf(fd,"%d",current_score); // Save the high score
}else{ // They are equal. DO whatever you want.
free(buffer);
}
}else{ // if the file size is 0, then there is no high score. Save the current score as the high.
fprintf(fd,"%d",current_score);
fclose(fd);
}
}
is this the best way to convert a decimal to binair?Code:* #include <stdio.h> /* pour printf */
* #include <conio.h> /* pour getch */
*
* /*
* Nouveau type de char, il prend exactement la meme place en
* memoire qu'un vrai char.
* C'est une union donc chaque membre de la structure occupera
* la meme place en memoire.
* */
*
* typedef union NEWCHAR
* {
* unsigned char dec; /* decimal */
* struct
* {
* bool bit8:1; /* binaire, le :1 */
* bool bit7:1; /* signifie que la */
* bool bit6:1; /* variable n'intervient */
* bool bit5:1; /* que sur un seul bit */
* bool bit4:1; /* de la structure */
* bool bit3:1;
* bool bit2:1;
* bool bit1:1;
* };
* struct
* {
* unsigned int hexa2:4; /* hexadecimal, le :4 */
* unsigned int hexa1:4; /* pour seulement 4 bits */
* };
* };
*
* /*
* les sous-structure de NEWCHAR ne porte pas de nom, ça permet d'acceder
* a leurs variables comme ci elles appartenaient directement a NEWCHAR
* et que en meme temps toutes leurs variables n'en valent qu'une seule
* dans l'union
* */
*
* int main()
* {
* NEWCHAR octet;
*
* octet.dec=173; /* octet = 173 */
*
* /* binaire */
* printf("binaire : %d%d%d%d%d%d%d%d\n",octet.bit1,octet.bit2,octet.bit3,octet.bit4,octet.bit5,octet.bit6,octet.bit7,octet.bit8);
*
* /* hexadecimal */
* printf("hexadecimal : ");
* if (octet.hexa1>9) printf("%c",octet.hexa1+55);
* else printf("%d",octet.hexa1);
* if (octet.hexa2>9) printf("%c\n",octet.hexa2+55);
* else printf("%d\n",octet.hexa2);
*
* /* decimal */
* printf("decimal : %d",octet.dec);
*
* getch();
*
* return 0;
* }
...
...Code:char single_byte = 0x24 /*any number here*/;
for(char i = number; i; i<<=1) printf("%u",i&80);
also, why would anyone ever use getch() for anything?
I REALLY need to know how to use printf functions without the stupid background highlight, I've tried learning how to hook functions in order to do it, but I've had next to no help, so can someone either please explain what I need to do, or hand it to me on a silver platter. This is one of the only things stopping my project from being released, and I would be exceptionally pleased if someone would help.
-Aura
This is the meat of the text rendering function (for a 32-bit display mode):
If you take outCode:static void debug_put_char_32(int x, int y, u32 color, u32 bgc, u8 ch)
{
int i,j, l;
u8 *font;
u32 pixel;
u32 *vram_ptr;
u32 *vram;
if(!init)
{
return;
}
vram = g_vram_base;
vram += (g_vram_offset >> 2) + x;
vram += (y * PSP_LINE_SIZE);
font = &msx[ (int)ch * 8];
for (i=l=0; i < 8; i++, l+= 8, font++)
{
vram_ptr = vram;
for (j=0; j < 8; j++)
{
if ((*font & (128 >> j)))
pixel = color;
else
pixel = bgc;
*vram_ptr++ = pixel;
}
vram += PSP_LINE_SIZE;
}
}
It will stop drawing the background. Of course, you'll need to not build against -lpspdebug if you feel like redefining the entirety of scr_printf.c in one of your files, or rename all of the functions in scr_printf.c and use those names (with a properly adjusted header file, of course). You'll also need msx.c, as that contains the font, so it's probably better to build against -lpspdebug with a scr_printf.c with all the functions renamedCode:else
pixel = bgc;
*Note that I haven't actually tried, this, I'm just assuming. It also won't give the shadow effect seen in JoySens. But you really should be able to figure out how to implement that.
Ok, thanks, I think I can go from here, the only problem is I don't have any of those c files (probably why I struggled so much in the first place) as I have a pre-compiled toolchain, could you link me, or upload all the files I'm going to need?
Thanks.
-Aura
Alrighty,
I have a structure,
and I wan't to make it so that ALL of the 6 enemies of the structure do the same thing if there mode is "RIGHT" or "LEFT" etc. heres an example, i have,Code:typedef struct {
int state, health, fTimer, xMove, yMove, firing, bx, by, bh, bw;
float x, y, w, h, speed;
} ENEMY;
ENEMY cruzer[6];
This makes it so that if enemy 1(0) and enemy 2(1) is == right, then there ships move right, now would there be a way to write,Code:if(cruzer[0].xMove == RIGHT) {
cruzer[0].x++;
}else if(cruzer[0].xMove == LEFT) {
cruzer[0].x--;
}
if(cruzer[1].xMove == RIGHT) {
cruzer[1].x++;
}else if(cruzer[1].xMove == LEFT) {
cruzer[1].x--;
}
as in, have all of the ships Act the same way, with out having to write it all out? or am i just Hoping for too much?Code:if(cruzer[ALL].xMove == RIGHT) {
cruzer[ALL].x++;
}else if(cruzer[ALL].xMove == LEFT) {
cruzer[ALL].x--;
}
for(int i = 0; i < 6; ++i)
Also, it's faster to write it all out because it doesn't have to run through the loop. If you have optimizations set, it should unroll the loop so you don't have to write out the whole thing.
Thanks for that, just wondering how to compile it now... make doesn't work, neither does make install (which is obvious as theres nothing to install). I'm not sure what other commands are available with Cygwin, and whats the one I need to use.Zitat:
Zitat von Archaemic
-Aura
Ok, I've sorted it in a different way, works amazingly well :tup:
Just for future reference, you need to do a tad more to the scr_printf.c, but you definatly got me going on the right lines :Jump:
Now my only question is, is it possible to omit libpspdebug when compiling? It adds itself automatically, but if I can remove it it would be awesome, if not I'll overwrite the library with my current one, just might want to use the original for a later purpose.
-Aura
Go to X:/cygwin/usr/local/pspdev/psp/sdk/lib
There you'll find build.mak, just take out the libraries you don't want.
Ah thanks, thats sorted it :tup:Zitat:
Zitat von Judas
-Aura
I'm getting an odd bug that I can't work out...
This should continually print the time, date and battery charge, but for some reason it stops printing after a while, the time is random I've seen it go for a matter of seconds, and other times for a matter of minutes, it worked fine originally with the dsx library, but I've decided to use the clear printf functions I've made, to test how it works in the vsh... since doing so I've had this problem, and it occurs even with the normal pspdebug library, so I'm just wondering if anyone can see what I've done wrong?Code:int __main()
{
char day [15];
char month [15];
char extention [4];
char milisec [20];
int batlife;
long colour = 0;
int colournum = 0;
//outermod();
pspDebugScreenInit();
//buttoncheck(1);
for(;;)
{
sceRtcGetCurrentClockLocalTime(&pt);
batlife = scePowerGetBatteryLifePercent();
getdate(day, month, extention);
sprintf(milisec, "%i", pt.microseconds);
pspDebugScreenSetXY(50, 0);
if(pt.hour>12) _printf("%2i:%2i:%2i:%2.2sPM", (pt.hour - 12), pt.minutes, pt.seconds, milisec);
else _printf("%2i:%2i:%2i:%2.2sAM", pt.hour, pt.minutes, pt.seconds, milisec);
pspDebugScreenSetXY(0, 32);
_printf("%s the %i%s %s %i", day, pt.day, extention, month, pt.year);
pspDebugScreenSetXY(50, 32);
if(batlife>=0) _printf("%i%% battery life", batlife);
else _printf("No battery");
//buttoncheck(0);
sceKernelDelayThread(10*1000);
colournum++;
if(colournum==50)
{
colour = rand()%0xFFFFFFFF+1;
pspDebugScreenSetTextColor(colour);
colournum=0;
}
}
sceKernelExitDeleteThread(0);
return 0;
}
-Aura