Skip to: Site menu | Main content


Welcome to PSP-Programming.com, a place for developers to get together.

Welcome to the forums. Here you can find other user tutorials as well as homebrew releases and the source code repository. You can also ask for help with your code here and post your own homebrew!

PSP-Programming.com Forums
February 08, 2012, 06:19:56 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

News: Check out the Code Section!
Home Help Search Shop Login Register
Digg This!
Pages: [1]
Print
Author Topic: EasyMessage V0.1 (Message Dialog Wrapper)  (Read 2168 times)
jojojoris
Seabears and Fairy tales are real.
C/C++ Developer
Full Member
*

Karma: +15/-4
Offline Offline

Posts: 169
1820.60 points

View Inventory
Send Money to jojojoris

View Profile
« on: August 18, 2009, 11:18:38 AM »

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+download

easymessage.h
Code:
/*
 * 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
Code:
/*
 * 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(&params, 0, sizeof (params));
    params.base.size = sizeof (params);
    sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, &params.base.language); // Prompt language
    sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &params.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(&params);
    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
Code:
#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
Code:
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
Logged


Arshia001

C/C++ Developer
Sr. Member
*

Karma: +42/-41
Offline Offline

Posts: 268
1224.39 points

View Inventory
Send Money to Arshia001

View Profile
« Reply #1 on: August 18, 2009, 10:32:51 PM »

Yet another useful release...Tell you what though,why don't you make them in C instead of C++?C would benefit many more people.
Anyhow,good work man.If you keep creating these wrappers,we may have a nice collection of them in the near future. Wink
Logged

Check out this audio library:
http://www.psp-programming.com/forums/index.php/topic,4338.0.html

Thanks for all the Karma,you guys!
jojojoris
Seabears and Fairy tales are real.
C/C++ Developer
Full Member
*

Karma: +15/-4
Offline Offline

Posts: 169
1820.60 points

View Inventory
Send Money to jojojoris

View Profile
« Reply #2 on: August 19, 2009, 12:19:34 AM »

If you keep creating these wrappers,we may have a nice collection of them in the near future.
That's what i'm doin' Wink

A C version would not be that hard i suppose.
Logged
Noware
C/C++ Developer
C/C++ Developer
Hero Member
*

Karma: +41/-2
Offline Offline

Posts: 685
37495.68 points

View Inventory
Send Money to Noware

Avatar by: Jason Hise


View Profile
« Reply #3 on: August 19, 2009, 11:42:23 AM »

Nice work, I like your C++ wrapping around here Wink

Two minor thingies

1.) Make the pointer to the display list a member of your class, so you don't have the 1MB static overhead, also you can automatically call the TermGU() in your destructor

Code:
class EasyMessage {
public:
             EasyMessage()          : mDisplayList(NULL) { }
    virtual ~EasyMessage()          { TermGU(); }

    ...

    void    InitGU();
    void    TermGU()
    {
        if (mDisplayList!=NULL)
        {
            ... terminate GU ...

            free(mDisplayList);
            mDisplayList = NULL;
        }
    }

private:
    void*   mDisplayList;
}

2.) Hide the PSP stuff in your header i.e. change pspUtilityMsgDialogParams params; -> void* mParams; and cast it in your implementation.

In my project all headers are multi platform (and most cpp files), if some code relies on the PSP or Windows I postfix the cpp file with PSP or Win32. i.e.
File.h // global multi platform header
File.cpp // Common file implementation
FilePSP.cpp // PSP specific file implementation i.e. calls to sceIoOpen()/sceIORead() etc.
FileWin32.cpp // Windows specific file implementation i.e. calls to FileOpen(), etc

[EDIT]
@Arshia001
Quote
...why don't you make them in C instead of C++?C would benefit many more people.
Let them learn C++ instead and other OO languages, in the end it will give them more benefit Wink

Noware
« Last Edit: August 19, 2009, 11:51:42 AM by Noware » Logged

Reporter - What do you think of western civilization?
Gandhi - I think it would be a good idea!
jojojoris
Seabears and Fairy tales are real.
C/C++ Developer
Full Member
*

Karma: +15/-4
Offline Offline

Posts: 169
1820.60 points

View Inventory
Send Money to jojojoris

View Profile
« Reply #4 on: August 19, 2009, 12:08:06 PM »

@noware It seems like you know a lot about c++ and programming and stuff like that. Are you a teacher or something. (I think you would be a lot better than those at my school)
Logged
Noware
C/C++ Developer
C/C++ Developer
Hero Member
*

Karma: +41/-2
Offline Offline

Posts: 685
37495.68 points

View Inventory
Send Money to Noware

Avatar by: Jason Hise


View Profile
« Reply #5 on: August 19, 2009, 12:25:20 PM »

AlphaDingDong made a comment about me in one of his funny moods, something about a squirrel Wink

http://www.psp-programming.com/forums/index.php/topic,4395.msg33711.html#msg33711

Noware
« Last Edit: August 19, 2009, 12:47:57 PM by Noware » Logged

Reporter - What do you think of western civilization?
Gandhi - I think it would be a good idea!
jojojoris
Seabears and Fairy tales are real.
C/C++ Developer
Full Member
*

Karma: +15/-4
Offline Offline

Posts: 169
1820.60 points

View Inventory
Send Money to jojojoris

View Profile
« Reply #6 on: August 19, 2009, 12:51:09 PM »

AlphaDingDong made a comment about me in one of his funny moods, something about a squirrel Wink

http://www.psp-programming.com/forums/index.php/topic,4395.msg33711.html#msg33711

Noware

Don't get it Confused Are you teacher or a coder (a coder from Sony or another game developer)

I want to become someone like you  Mr. Green
« Last Edit: August 19, 2009, 12:53:17 PM by jojojoris » Logged
Noware
C/C++ Developer
C/C++ Developer
Hero Member
*

Karma: +41/-2
Offline Offline

Posts: 685
37495.68 points

View Inventory
Send Money to Noware

Avatar by: Jason Hise


View Profile
« Reply #7 on: August 19, 2009, 01:09:07 PM »

Quote
Don't get it  Confused Are you teacher or a coder (a coder from Sony or another game developer)

I want to become someone like you Mr. Green
I'm a human just like you

Noware
« Last Edit: August 19, 2009, 01:33:20 PM by Noware » Logged

Reporter - What do you think of western civilization?
Gandhi - I think it would be a good idea!
Arshia001

C/C++ Developer
Sr. Member
*

Karma: +42/-41
Offline Offline

Posts: 268
1224.39 points

View Inventory
Send Money to Arshia001

View Profile
« Reply #8 on: August 19, 2009, 10:00:05 PM »

We already know he's a coder,but as Alpha said,he's a squirrel.Don't try worming info out of him,it won't work. Wink

Quote
Let them learn C++ instead and other OO languages, in the end it will give them more benefit

Maybe you're right...
Logged

Check out this audio library:
http://www.psp-programming.com/forums/index.php/topic,4338.0.html

Thanks for all the Karma,you guys!
Pages: [1]
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.217 seconds with 32 queries.
Sister Sites: Guitar Hero 4   BrokeniTouch.com