Skip to content

Commit e1bb00c

Browse files
erysdrensharkwouter
authored andcommitted
Add a basic ShowMessageBox implementation for PSP (#9932)
1 parent 6da5242 commit e1bb00c

File tree

3 files changed

+160
-1
lines changed

3 files changed

+160
-1
lines changed

src/video/psp/SDL_pspmessagebox.c

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
22+
#include "../../SDL_internal.h"
23+
24+
#ifdef SDL_VIDEO_DRIVER_PSP
25+
26+
#include "SDL_pspvideo.h"
27+
#include "SDL_pspmessagebox.h"
28+
#include <psputility.h>
29+
#include <pspgu.h>
30+
#include <pspdisplay.h>
31+
#include <pspthreadman.h>
32+
#include <pspkernel.h>
33+
34+
static void configure_dialog(pspUtilityMsgDialogParams *dialog, size_t dialog_size)
35+
{
36+
/* clear structure and setup size */
37+
SDL_memset(dialog, 0, dialog_size);
38+
dialog->base.size = dialog_size;
39+
40+
/* set language */
41+
sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, &dialog->base.language);
42+
43+
/* set X/O swap */
44+
sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &dialog->base.buttonSwap);
45+
46+
/* set thread priorities */
47+
/* TODO: understand how these work */
48+
dialog->base.soundThread = 0x10;
49+
dialog->base.graphicsThread = 0x11;
50+
dialog->base.fontThread = 0x12;
51+
dialog->base.accessThread = 0x13;
52+
}
53+
54+
int PSP_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
55+
{
56+
unsigned char list[0x20000] __attribute__((aligned(64)));
57+
pspUtilityMsgDialogParams dialog;
58+
int status;
59+
60+
/* check if it's possible to do a messagebox now */
61+
if (SDL_GetFocusWindow() == NULL)
62+
return SDL_SetError("No video context is available");
63+
64+
/* configure dialog */
65+
configure_dialog(&dialog, sizeof(dialog));
66+
67+
/* setup dialog options for text */
68+
dialog.mode = PSP_UTILITY_MSGDIALOG_MODE_TEXT;
69+
dialog.options = PSP_UTILITY_MSGDIALOG_OPTION_TEXT;
70+
71+
/* copy the message in, 512 bytes max */
72+
SDL_snprintf(dialog.message, sizeof(dialog.message), "%s\r\n\r\n%s", messageboxdata->title, messageboxdata->message);
73+
74+
/* too many buttons */
75+
if (messageboxdata->numbuttons > 2)
76+
return SDL_SetError("messageboxdata->numbuttons valid values are 0, 1, 2");
77+
78+
/* we only have two options, "yes/no" or "ok" */
79+
if (messageboxdata->numbuttons == 2)
80+
dialog.options |= PSP_UTILITY_MSGDIALOG_OPTION_YESNO_BUTTONS | PSP_UTILITY_MSGDIALOG_OPTION_DEFAULT_NO;
81+
82+
/* start dialog */
83+
if (sceUtilityMsgDialogInitStart(&dialog) != 0)
84+
return SDL_SetError("sceUtilityMsgDialogInitStart() failed for some reason");
85+
86+
/* loop while the dialog is active */
87+
status = PSP_UTILITY_DIALOG_NONE;
88+
do
89+
{
90+
sceGuStart(GU_DIRECT, list);
91+
sceGuClearColor(0);
92+
sceGuClearDepth(0);
93+
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
94+
sceGuFinish();
95+
sceGuSync(0,0);
96+
97+
status = sceUtilityMsgDialogGetStatus();
98+
99+
switch (status)
100+
{
101+
case PSP_UTILITY_DIALOG_VISIBLE:
102+
sceUtilityMsgDialogUpdate(1);
103+
break;
104+
105+
case PSP_UTILITY_DIALOG_QUIT:
106+
sceUtilityMsgDialogShutdownStart();
107+
break;
108+
}
109+
110+
sceDisplayWaitVblankStart();
111+
sceGuSwapBuffers();
112+
113+
} while (status != PSP_UTILITY_DIALOG_NONE);
114+
115+
/* success */
116+
if (dialog.buttonPressed == PSP_UTILITY_MSGDIALOG_RESULT_YES)
117+
*buttonid = messageboxdata->buttons[0].buttonid;
118+
else if (dialog.buttonPressed == PSP_UTILITY_MSGDIALOG_RESULT_NO)
119+
*buttonid = messageboxdata->buttons[1].buttonid;
120+
else
121+
*buttonid = messageboxdata->buttons[0].buttonid;
122+
123+
return 0;
124+
}
125+
126+
#endif /* SDL_VIDEO_DRIVER_PSP */

src/video/psp/SDL_pspmessagebox.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
22+
#ifndef SDL_pspmessagebox_h_
23+
#define SDL_pspmessagebox_h_
24+
25+
#if SDL_VIDEO_DRIVER_PSP
26+
27+
int PSP_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
28+
29+
#endif /* SDL_VIDEO_DRIVER_PSP */
30+
31+
#endif /* SDL_pspmessagebox_h_ */

src/video/psp/SDL_pspvideo.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include "SDL_pspvideo.h"
4040
#include "SDL_pspevents_c.h"
4141
#include "SDL_pspgl_c.h"
42+
#include "SDL_pspmessagebox.h"
43+
4244
#include <psputility.h>
4345
#include <pspgu.h>
4446
#include <pspdisplay.h>
@@ -259,7 +261,7 @@ VideoBootStrap PSP_bootstrap = {
259261
"PSP",
260262
"PSP Video Driver",
261263
PSP_Create,
262-
NULL /* no ShowMessageBox implementation */
264+
PSP_ShowMessageBox
263265
};
264266

265267
/*****************************************************************************/

0 commit comments

Comments
 (0)