Today i made a simple wrapper for the Message Dialog.
You can use it if you want to. It should work on every psp with firmware 2.00 and higher.
NOTE:
You may use it if you want to but a little credit would be nice.
orginal+downloadeasymessage.h
/*
* File: easymessage.h
* Author: joris
*
* Created on 18 augustus 2009, 19:39
*/
#ifndef _EASYMESSAGE_H
#define _EASYMESSAGE_H
#include <pspdisplay.h>
#include <pspgu.h>
#include <pspkernel.h>
#include <psputility.h>
#include <string.h>
class EasyMessage {
public:
EasyMessage();
virtual ~EasyMessage();
/**
* Shows A message.
*
* @param message - Message which will be displayed to the user
* @param yesno - boolean wchich enables the yes/no user choice
*
* @return 1 of user pressed yes (only when yesno is set to TRUE, otherwise 0
*/
int ShowMessage(const char * message, bool yesno);
/**
* Shows a psp error.
*
* NOTE:
* Not all error codes shows a message.
*
* @param error - Error code
*/
void ShowError(unsigned int error);
/**
* Sets the background color of the dialog.
*
* @param color - the background collor
*/
void SetBGColor(unsigned int color);
/** Inits the GU with the recommanded settings. Should be usable for most
* applications. (compatible with intrafont)
*/
void InitGU();
/**
* Terminates the GU.
*/
void TermGU();
private:
void _RunDialog();
pspUtilityMsgDialogParams params;
unsigned int bgcolor;
};
#endif /* _EASYMESSAGE_H */
easymessage.
cpp/*
* File: easymessage.cpp
* Author: joris
*
* Created on 18 augustus 2009, 19:39
*/
#include "easymessage.h"
static unsigned int __attribute__((aligned(16))) list[262144];
EasyMessage::EasyMessage() {
bgcolor = 0;
memset(¶ms, 0, sizeof (params));
params.base.size = sizeof (params);
sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, ¶ms.base.language); // Prompt language
sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, ¶ms.base.buttonSwap); // X/O button swap
params.base.graphicsThread = 0x11;
params.base.accessThread = 0x13;
params.base.fontThread = 0x12;
params.base.soundThread = 0x10;
}
EasyMessage::~EasyMessage() {
}
void EasyMessage::InitGU() {
sceGuInit();
sceGuStart(GU_DIRECT, list);
sceGuDrawBuffer(GU_PSM_8888, (void*) 0, 512);
sceGuDispBuffer(480, 272, (void*) 0x88000, 512);
sceGuDepthBuffer((void*) 0x110000, 512);
sceGuOffset(2048 - (480 / 2), 2048 - (272 / 2));
sceGuViewport(2048, 2048, 480, 272);
sceGuDepthRange(0xc350, 0x2710);
sceGuScissor(0, 0, 480, 272);
sceGuEnable(GU_SCISSOR_TEST);
sceGuDepthFunc(GU_GEQUAL);
sceGuEnable(GU_DEPTH_TEST);
sceGuFrontFace(GU_CW);
sceGuShadeModel(GU_SMOOTH);
sceGuEnable(GU_CULL_FACE);
sceGuEnable(GU_CLIP_PLANES);
sceGuEnable(GU_BLEND);
sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
sceGuFinish();
sceGuSync(0, 0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
}
void EasyMessage::TermGU() {
sceGuTerm();
}
void EasyMessage::SetBGColor(unsigned int color) {
bgcolor = color;
}
int EasyMessage::ShowMessage(const char* message, bool yesno) {
params.mode = PSP_UTILITY_MSGDIALOG_MODE_TEXT;
params.options = PSP_UTILITY_MSGDIALOG_OPTION_TEXT;
if (yesno)
params.options |= PSP_UTILITY_MSGDIALOG_OPTION_YESNO_BUTTONS | PSP_UTILITY_MSGDIALOG_OPTION_DEFAULT_NO;
strcpy(params.message, message);
_RunDialog();
if (params.buttonPressed == PSP_UTILITY_MSGDIALOG_RESULT_YES) return 1;
else return 0;
}
void EasyMessage::ShowError(unsigned int error) {
params.mode = PSP_UTILITY_MSGDIALOG_MODE_ERROR;
params.options = PSP_UTILITY_MSGDIALOG_OPTION_ERROR;
params.errorValue = error;
_RunDialog();
}
void EasyMessage::_RunDialog() {
sceUtilityMsgDialogInitStart(¶ms);
for (;;) {
sceGuStart(GU_DIRECT, list);
sceGuClearColor(bgcolor);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
sceGuFinish();
sceGuSync(0, 0);
switch (sceUtilityMsgDialogGetStatus()) {
case PSP_UTILITY_DIALOG_VISIBLE:
sceUtilityMsgDialogUpdate(1);
break;
case PSP_UTILITY_DIALOG_QUIT:
sceUtilityMsgDialogShutdownStart();
break;
case PSP_UTILITY_DIALOG_NONE:
return;
}
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
}
}
And because some people need a sample...
main.
cpp#include <pspkernel.h>
#include <pspdebug.h>
#include "easymessage.h"
PSP_MODULE_INFO("Inet Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
int main() {
EasyMessage msg;
msg.InitGU();
if (msg.ShowMessage("This is a utility message dialog.\nAfter you acknowledge it, this program will\nshow an error message dialog.", 1))
msg.ShowMessage("You answered YES.", 0);
else msg.ShowMessage("You answered NO.", 0);
msg.ShowError(0x80020001);
msg.ShowMessage("Did you got scared?\n\nThis application will shut down.",0);
sceKernelExitGame();
return 0;
}
Makefile
TARGET = app
OBJS = main.o easymessage.o
INCDIR =
CFLAGS = -G0 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS= -lstdc++ -lpspgu
BUILD_PRX=1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = EasyMessage Sample
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak