c programming

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

c programming

Post by Squall333 »

when programming for the psp can you do like

char a;

a="a";

pgPrint4(1,4,0xffff,a);
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Re: c programming

Post by Agoln »

Squall333 wrote:a="a";
^^ is wrong. It should be:

a='a';

Single quotes for characters, double quotes for strings... which are just character array's.

As far as the other code, I don't know.
Lego of my Ago!
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

thanks for your help but for some reason when i run that code my psp turns off and when i use pspe the program closes
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

put it in a loop, or ask for input after it. Make sure that you have to do something before you exit, otherwise it will just exit after excuting and you will not see anything.
Lego of my Ago!
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

Its in a while(1) loop but i looked at the parameters for pgPrint and i think the last thing has to be a string and cant be a variable

EDIT: i just decided to add my code its pretty short

Code: Select all

// Hello World for PSP


#include "pg.h"


#define CTRL_SQUARE     0x8000 
#define CTRL_TRIANGLE   0x1000 
#define CTRL_CIRCLE     0x2000 
#define CTRL_CROSS      0x4000 
#define CTRL_UP         0x0010 
#define CTRL_DOWN       0x0040 
#define CTRL_LEFT       0x0080 
#define CTRL_RIGHT      0x0020 
#define CTRL_START      0x0008 
#define CTRL_SELECT     0x0001 
#define CTRL_LTRIGGER   0x0100 
#define CTRL_RTRIGGER   0x0200
int n,x,y;
char a;



typedef struct _ctrl_data 
{ 
	int frame; 
	int buttons; 
	unsigned char analog[4]; 
	int unused; 
} ctrl_data_t; 

void keyboardControl()
{
	ctrl_data_t ctrl;
	sceCtrlReadBufferPositive(&ctrl, 1); 
	if (ctrl.buttons & CTRL_UP) { 
		n = n+1;
	} else if (ctrl.buttons & CTRL_DOWN) { 
		n = n+1;
	} else if (ctrl.buttons & CTRL_LEFT) { 
		n = n+1;
	} else if (ctrl.buttons & CTRL_RIGHT) { 
		n = n+1;
	} else if (ctrl.buttons & CTRL_SQUARE) { 
		n = n+1;
	} else if (ctrl.buttons & CTRL_CIRCLE) { 
		n = n+1;
	} else if (ctrl.buttons & CTRL_TRIANGLE) { 
		n = n+1;
	} else if (ctrl.buttons & CTRL_CROSS) { 
		n = n+1;
	} else if (ctrl.buttons & CTRL_RTRIGGER) { 
		n = n+1;
	} else if (ctrl.buttons & CTRL_LTRIGGER) { 
		n = n+1;
	}
}

int xmain(void)
{

	unsigned long fc;
	unsigned long r,g,b,rgb;
	
	pgInit();
	pgScreenFrame(2,0);
	while (1) {
    keyboardControl();
    
       a='a' ;

	pgFillvram(0);
	pgPrint4(1,4,0xffff,a);
	pgScreenFlipV();
}
	
	return 0;
}
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

try making it a character pointer.

like:

char[2] a="a"; //yes, double quotes for strings, which is what this is.

pgprint(/*some x value*/,
/*some y value*/,
/*some color*/,
a);
Lego of my Ago!
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

the compiler doesnt like the code like that so i tried
char a[2];
strcopy ( a, "a" );

but theres come kind of error

it says parse error before string constant
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

char[2] a;

not char a[2];

edit:
If you want, you can try

char* a = "a";

...now that I think of it... i think that's the real way instead of how I said before....
Lego of my Ago!
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

when i do it that way it says parse error before '[' token
parse error before string constant
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

thank you, you are a god the second version worked the char* a="a";
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Squall333 wrote:Its in a while(1) loop but i looked at the parameters for pgPrint and i think the last thing has to be a string and cant be a variable
yes, you are right. Please read some C learning book or website, then try to program on PC and then on Playstation. For your problem: if you want just one char, then call pgPutChar (or whatever it is called in Nem's lib). If the function expects a char*, don't pass a char.
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

actually i was wrong you can use chars in pgprint but my next question is can you use arrays like

char* a[3] = {"a","b","c"};

pgPrint4(1,4,0xfff,a[3]);

EDIT: Yes you can
D0gg
Posts: 1
Joined: Sun May 22, 2005 12:26 pm

Post by D0gg »

Agoln wrote:char[2] a;

not char a[2];
that is incorrect. you should use char a[2] or char* a. array brackets go after the variable name.
Squall333 wrote:actually i was wrong you can use chars in pgprint but my next question is can you use arrays like

char* a[3] = {"a","b","c"};
ya, you could do that but doesn't it look like it'll get annoying? that's an array of pointers to "a\0", "b\0" and "c\0" (\0 is the NULL termination of a string). i recommend doing as you did before with a char array (char a[3] = "abc";)

Code: Select all

void pgPrint4(unsigned long x,unsigned long y,unsigned long color,const char *str)
the prototype for pgPrint4 requires a char array or pointer to the beginning of a NULL terminated string.

if had a 1.5 PSP to code on, i'd be able to test what you have there and possibly fix it but sadly i don't so i can't be much help on what will actually happen
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

You can use pspe as an emulator if you want. you can get it from www.dcemu.co.uk and then go to the psp news section then on the left under psp emulator

i have 2 more problems my program works in pspe but not on my psp. any ideas?

and two when i press a button and hold it down it makes code like x=x+1 going so isntead of making 1 increase to 2 it makes 1 go to like 3 or 4 because i cant press a key fast enough to make count as one press anyone understand what im saying?
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

Sorry for posting so much pgWaitVn(7); works pretty well in between key spaces.
Post Reply