forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

c programming

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Squall333



Joined: 28 Apr 2005
Posts: 91

PostPosted: Sat Jul 02, 2005 12:37 am    Post subject: c programming Reply with quote

when programming for the psp can you do like

char a;

a="a";

pgPrint4(1,4,0xffff,a);
Back to top
View user's profile Send private message AIM Address
Agoln



Joined: 08 Jun 2005
Posts: 326
Location: Fort Wayne, IN

PostPosted: Sat Jul 02, 2005 12:39 am    Post subject: Re: c programming Reply with quote

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!
Back to top
View user's profile Send private message AIM Address
Squall333



Joined: 28 Apr 2005
Posts: 91

PostPosted: Sat Jul 02, 2005 12:52 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Agoln



Joined: 08 Jun 2005
Posts: 326
Location: Fort Wayne, IN

PostPosted: Sat Jul 02, 2005 1:00 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Squall333



Joined: 28 Apr 2005
Posts: 91

PostPosted: Sat Jul 02, 2005 1:03 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Agoln



Joined: 08 Jun 2005
Posts: 326
Location: Fort Wayne, IN

PostPosted: Sat Jul 02, 2005 1:11 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Squall333



Joined: 28 Apr 2005
Posts: 91

PostPosted: Sat Jul 02, 2005 1:19 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Agoln



Joined: 08 Jun 2005
Posts: 326
Location: Fort Wayne, IN

PostPosted: Sat Jul 02, 2005 1:20 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Squall333



Joined: 28 Apr 2005
Posts: 91

PostPosted: Sat Jul 02, 2005 1:22 am    Post subject: Reply with quote

when i do it that way it says parse error before '[' token
parse error before string constant
Back to top
View user's profile Send private message AIM Address
Squall333



Joined: 28 Apr 2005
Posts: 91

PostPosted: Sat Jul 02, 2005 1:23 am    Post subject: Reply with quote

thank you, you are a god the second version worked the char* a="a";
Back to top
View user's profile Send private message AIM Address
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sat Jul 02, 2005 1:39 am    Post subject: Reply with quote

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
View user's profile Send private message
Squall333



Joined: 28 Apr 2005
Posts: 91

PostPosted: Sat Jul 02, 2005 12:01 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
D0gg



Joined: 22 May 2005
Posts: 1

PostPosted: Sun Jul 03, 2005 9:01 am    Post subject: Reply with quote

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
View user's profile Send private message
Squall333



Joined: 28 Apr 2005
Posts: 91

PostPosted: Mon Jul 04, 2005 2:15 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Squall333



Joined: 28 Apr 2005
Posts: 91

PostPosted: Tue Jul 05, 2005 2:41 pm    Post subject: Reply with quote

Sorry for posting so much pgWaitVn(7); works pretty well in between key spaces.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group