View Single Post
 
Old 06-28-2008, 09:32 AM
pirata nervo pirata nervo is offline
Moderator
PSP Titan
 
Join Date: Mar 2007
Location: www.consoleworld.net
Posts: 5,008
pirata nervo is on a distinguished road
Default

pspdebug.h functions tutorial
First off, this is a very good place to take a look at the pspdebug.h functions:
http://alek.dark-alex.org/pspsdkdocs/pspdebug_8h.html
the sdk docs.

In this tutorial I will ONLY explain the debug functions and not any other functions I may use.

Here's a simple program which makes use of a lot of debug functions.
main.c
Code:
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <string.h>
#include <pspdebug.h>

PSP_MODULE_INFO("Simple debug tutorial", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

int main(void)
{
	pspDebugScreenInit(); // Initializes the debug screen
    
	pspDebugScreenClear(); // Clears the debug screen

	char mystring[100] = { '\0' };

	strcpy(mystring, "This is a string");

	/*
	 * the X and Y must be multiplied by 10 to find the real coordinate on the screen (works in character units) 
	 * So this means we are placing the text at coordinates 0*10 = 0 X and 1*10 = 10 Y
	*/
	pspDebugScreenSetXY(0,1); 

	// prints text to the screen, usually defined at the top of the program as printf
	pspDebugScreenPrintf("\n***********************************************************");
	sceKernelDelayThread(1000000*1);

	/*
	 * Sets the background color for the text, it's black as default (0xFF000000)
	 * @param 1: u32 color - 0xAABBGGRR (color format: A=Alpha | B=Blue | G=Green | R=Red)
	 * The color I am using below is red. FF = 255 (alpha) | 00 = 0 (blue) | 00 = 0 (green) | FF = 255 (red)
	*/
	pspDebugScreenSetBackColor(0xFF0000FF);
	pspDebugScreenPrintf("\n********************** Debug Sample ***********************");
	sceKernelDelayThread(1000000*1);

	/*
	 * Sets the color for the text, it's white as default (0xFFFFFFFF)
	 * @param 1: u32 color - 0xAABBGGRR (color format: A=Alpha | B=Blue | G=Green | R=Red)
	 * The color I am using below is green. FF = 255 (alpha) | 00 = 0 (blue) | FF = 255 (green) | 00 = 0 (red)
	*/
	pspDebugScreenSetTextColor(0xFF00FF00);
	pspDebugScreenPrintf("\n***********************************************************\n\n");
	sceKernelDelayThread(1000000*1);

	// this functions prints a string to the screen. (you can't have parameters like on printf)
	pspDebugScreenPuts(mystring);
	sceKernelDelayThread(1000000*1);

	pspDebugScreenPrintf("\n\nExiting...(wait 3 seconds)");
	sceKernelDelayThread(1000000*3);

	sceKernelExitGame();
	sceKernelSleepThread();

	return 0;

}
Makefile
Code:
TARGET = main
OBJS = main.o

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS) -c

LIBDIR =
LDFLAGS =
LIBS = -lpspdebug

PSP_FW_VERSION = 390

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = PSP Debug Functions

PSPSDK=$(shell psp-config --pspsdk-path)

include $(PSPSDK)/lib/build.mak
Here are some other explanations about other pspdebug.h functions.
pspDebugScreenKprintf(const char *format,...) __attribute__((format(printf
The printf but for kernel mode ;)

pspDebugScreenGetX();
Used to get the X coordinate (in character units) of current "debug" coordinate.

pspDebugScreenGetY();
Used to get the Y coordinate (in character units) of current "debug" coordinate.

[u]pspDebugScreenPrintData(const char *buff, int size);
This function is used to print a Non-null terminated string.
@param 1: the non-null terminated string to print
@param 2: the size of data (not length of the string)

pspDebugScreenPutChar (int x, int y, u32 color, u8 ch);
Puts a single character on the screen.
@param 1: X coordinate (pixel units)
@param 2: Y coordinate (pixel units)
@param 3: u32 color, 0xAABBGGRR (color format: A=Alpha | B=Blue | G=Green | R=Red)
@param 4: the character to print

There are a lot of more functions in pspdebug.h but some use kernel mode and I won't explain HOW to use kernel mode in your applications/games for now.
__________________

Upgrade your PSP Slim or FAT now!
NervOS Official Forum
Reply With Quote