| View previous topic :: View next topic |
| Author |
Message |
Squall333
Joined: 28 Apr 2005 Posts: 91
|
Posted: Sat Jul 02, 2005 12:37 am Post subject: c programming |
|
|
when programming for the psp can you do like
char a;
a="a";
pgPrint4(1,4,0xffff,a); |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Sat Jul 02, 2005 12:39 am Post subject: Re: c programming |
|
|
^^ 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! |
|
| Back to top |
|
 |
Squall333
Joined: 28 Apr 2005 Posts: 91
|
Posted: Sat Jul 02, 2005 12:52 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Sat Jul 02, 2005 1:00 am Post subject: |
|
|
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! |
|
| Back to top |
|
 |
Squall333
Joined: 28 Apr 2005 Posts: 91
|
Posted: Sat Jul 02, 2005 1:03 am Post subject: |
|
|
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: |
// 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;
}
|
|
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Sat Jul 02, 2005 1:11 am Post subject: |
|
|
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! |
|
| Back to top |
|
 |
Squall333
Joined: 28 Apr 2005 Posts: 91
|
Posted: Sat Jul 02, 2005 1:19 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Sat Jul 02, 2005 1:20 am Post subject: |
|
|
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! |
|
| Back to top |
|
 |
Squall333
Joined: 28 Apr 2005 Posts: 91
|
Posted: Sat Jul 02, 2005 1:22 am Post subject: |
|
|
when i do it that way it says parse error before '[' token
parse error before string constant |
|
| Back to top |
|
 |
Squall333
Joined: 28 Apr 2005 Posts: 91
|
Posted: Sat Jul 02, 2005 1:23 am Post subject: |
|
|
| thank you, you are a god the second version worked the char* a="a"; |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sat Jul 02, 2005 1:39 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Squall333
Joined: 28 Apr 2005 Posts: 91
|
Posted: Sat Jul 02, 2005 12:01 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
D0gg
Joined: 22 May 2005 Posts: 1
|
Posted: Sun Jul 03, 2005 9:01 am Post subject: |
|
|
| 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: | | 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 |
|
| Back to top |
|
 |
Squall333
Joined: 28 Apr 2005 Posts: 91
|
Posted: Mon Jul 04, 2005 2:15 am Post subject: |
|
|
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? |
|
| Back to top |
|
 |
Squall333
Joined: 28 Apr 2005 Posts: 91
|
Posted: Tue Jul 05, 2005 2:41 pm Post subject: |
|
|
| Sorry for posting so much pgWaitVn(7); works pretty well in between key spaces. |
|
| Back to top |
|
 |
|