PDA

View Full Version : PSP Coding Question



KunoNoOni
September 1st, 2008, 01:15
This is going to sound very stupid and noobish. that probably wasn't a good way to open my question but whatever :p

Is there a way when the psp is set in graphics mode to print a variable. I've tried printf but it doesn't display anything. I know about outtextxy but it doesn't print variables. atleast it didn't do it for me...

kamaldeeps
September 1st, 2008, 08:01
I've tried print but it doesn't display anything.

*this is a spambot with links in the sig*

yaustar
September 1st, 2008, 17:38
printf (the actual C library function) will print to the TTY. Whichever graphics library you are using, there is normally a function to print text to the screen. Have a little hunt in the library headers/documentation and you should find one easily enough.

KunoNoOni
September 4th, 2008, 05:37
The only graphics library that I am using is graphics.h, but the problem isn't with printing text to the screen. I understand how to do that. its with printing variables. printf is what I want to use, but when I init the graphics printf ceases to function and outtextxy will not print variables. I'll look again though...

Wally
September 4th, 2008, 09:04
You'd be better off using printf and PSPlink, to keep things neat.

PSPLink will save you bucket loads of time anndd its a TTY interface so woo!

Wally

yaustar
September 4th, 2008, 20:35
Where do you want to print out your variables? On screen? In the TTY?

If on screen and you are using the header graphics.h, if you look in the header, you see a function:

void printTextScreen(int x, int y, const char* text, u32 color)
Which only takes a char string. You will have to use char string functions (snprintf(C), sprintf(C) and stringstreams(C++)) to create your string to print on screen. E.g

int foo = 20;
float bar = 2.2f;
char buffer[128] = "\0";
snprintf( buffer, 127, "blah blah %d, %.2f", foo, bar );
buffer[127] = '\0';
printTextScreen( 0, 0, buffer, 0 );

KunoNoOni
September 4th, 2008, 21:12
Where do you want to print out your variables? On screen? In the TTY?

If on screen and you are using the header graphics.h, if you look in the header, you see a function:

void printTextScreen(int x, int y, const char* text, u32 color)
Which only takes a char string. You will have to use char string functions (snprintf(C), sprintf(C) and stringstreams(C++)) to create your string to print on screen. E.g

int foo = 20;
float bar = 2.2f;
char buffer[128] = "\0";
snprintf( buffer, 127, "blah blah %d, %.2f", foo, bar );
buffer[127] = '\0';
printTextScreen( 0, 0, buffer, 0 );



I think I've tried this too and unless I'm typing the command wrong it didn't work. but your right I didn't use snprintf, sprintf or stringsteams.. I will try it out and let you know. thanks for the info :)

JLF65
September 4th, 2008, 23:22
The way I do it can be found in the latest version of Basilisk II for the PSP. Here's the relevant code as a quote because the code tags don't work on this forum. :mad: It's the show_msg() function in video_psp.cpp.


void show_msg(char *message, uint32 fc, uint32 bc)
{
struct texVertex *vertices;

pspDebugScreenSetOffset(DEBUG_BUF);
pspDebugScreenSetBackColor(bc);
pspDebugScreenSetTextColor(fc);
pspDebugScreenSetXY(0, 0);
pspDebugScreenPrintf("%s", message);

sceGuEnable(GU_TEXTURE_2D);

sceGuTexMode(GU_PSM_8888,0,0,0);
sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
sceGuTexFilter(GU_LINEAR, GU_LINEAR);
sceGuTexImage(0, 512, 8, 512, (void *)(0x40000000 | (uint32)sceGeEdramGetAddr() + DEBUG_BUF));
sceGuTexSync();

vertices = (struct texVertex*)sceGuGetMemory(2 * sizeof(struct texVertex));
vertices[0].u = 0;
vertices[1].u = strlen(message)*7;
vertices[0].v = 0;
vertices[1].v = 8;
vertices[0].x = (SCR_WIDTH-strlen(message)*7)/2;
vertices[1].x = vertices[0].x + strlen(message)*7;
vertices[0].y = SCR_HEIGHT-48;
vertices[1].y = vertices[0].y + 8;
vertices[0].z = 0;
vertices[1].z = 0;

sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERT EX_16BIT|GU_TRANSFORM_2D, 2,0,vertices);
}

That uses pspDebugScreenSetOffset() to make the subsequent pspDebugScreenPrintf() draw to a place designated as the debug text texture buffer. It's just one line worth of space - 512x8x4.

Then that texture buffer is blitted to the screen. Just tack a call to show_msg() to the end of your screen drawing before you call sceGuFinish(); sceGuSync(0,0);

yaustar
September 4th, 2008, 23:45
I think I've tried this too and unless I'm typing the command wrong it didn't work. but your right I didn't use snprintf, sprintf or stringsteams.. I will try it out and let you know. thanks for the info :)
Post up your entire code and we can see where you have gone wrong.

KunoNoOni
September 6th, 2008, 18:47
Thank you yaustar, your idea worked like a charm!!! :D

The problem was that I was only using printTextScreen without first dumping the variable with a sprintf. took me a couple of tries to get it placed correctly in the code. but I got it to work!! Thank you again!! :thumbup: