Atlas - SDL_pspvideo.c

Home / ext / SDL / src / video / psp Lines: 3 | Size: 14435 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 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// SDL internals 27#include "../SDL_sysvideo.h" 28#include "../../events/SDL_mouse_c.h" 29#include "../../events/SDL_keyboard_c.h" 30 31// PSP declarations 32#include "SDL_pspvideo.h" 33#include "SDL_pspevents_c.h" 34#include "SDL_pspgl_c.h" 35#include "../../render/psp/SDL_render_psp_c.h" 36 37#include <psputility.h> 38#include <pspgu.h> 39#include <pspdisplay.h> 40#include <vram.h> 41 42/* unused 43static bool PSP_initialized = false; 44*/ 45 46static void PSP_Destroy(SDL_VideoDevice *device) 47{ 48 SDL_free(device->internal); 49 SDL_free(device); 50} 51 52static SDL_VideoDevice *PSP_Create(void) 53{ 54 SDL_VideoDevice *device; 55 SDL_VideoData *phdata; 56 SDL_GLDriverData *gldata; 57 58 // Initialize SDL_VideoDevice structure 59 device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); 60 if (!device) { 61 return NULL; 62 } 63 64 // Initialize internal PSP specific data 65 phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); 66 if (!phdata) { 67 SDL_free(device); 68 return NULL; 69 } 70 71 gldata = (SDL_GLDriverData *)SDL_calloc(1, sizeof(SDL_GLDriverData)); 72 if (!gldata) { 73 SDL_free(device); 74 SDL_free(phdata); 75 return NULL; 76 } 77 device->gl_data = gldata; 78 79 device->internal = phdata; 80 81 phdata->egl_initialized = true; 82 83 // Setup amount of available displays 84 device->num_displays = 0; 85 86 // Set device free function 87 device->free = PSP_Destroy; 88 89 // Setup all functions which we can handle 90 device->VideoInit = PSP_VideoInit; 91 device->VideoQuit = PSP_VideoQuit; 92 device->GetDisplayModes = PSP_GetDisplayModes; 93 device->SetDisplayMode = PSP_SetDisplayMode; 94 device->CreateSDLWindow = PSP_CreateWindow; 95 device->SetWindowTitle = PSP_SetWindowTitle; 96 device->SetWindowPosition = PSP_SetWindowPosition; 97 device->SetWindowSize = PSP_SetWindowSize; 98 device->ShowWindow = PSP_ShowWindow; 99 device->HideWindow = PSP_HideWindow; 100 device->RaiseWindow = PSP_RaiseWindow; 101 device->MaximizeWindow = PSP_MaximizeWindow; 102 device->MinimizeWindow = PSP_MinimizeWindow; 103 device->RestoreWindow = PSP_RestoreWindow; 104 device->DestroyWindow = PSP_DestroyWindow; 105 device->GL_LoadLibrary = PSP_GL_LoadLibrary; 106 device->GL_GetProcAddress = PSP_GL_GetProcAddress; 107 device->GL_UnloadLibrary = PSP_GL_UnloadLibrary; 108 device->GL_CreateContext = PSP_GL_CreateContext; 109 device->GL_MakeCurrent = PSP_GL_MakeCurrent; 110 device->GL_SetSwapInterval = PSP_GL_SetSwapInterval; 111 device->GL_GetSwapInterval = PSP_GL_GetSwapInterval; 112 device->GL_SwapWindow = PSP_GL_SwapWindow; 113 device->GL_DestroyContext = PSP_GL_DestroyContext; 114 device->HasScreenKeyboardSupport = PSP_HasScreenKeyboardSupport; 115 device->ShowScreenKeyboard = PSP_ShowScreenKeyboard; 116 device->HideScreenKeyboard = PSP_HideScreenKeyboard; 117 118 device->PumpEvents = PSP_PumpEvents; 119 120 device->device_caps = VIDEO_DEVICE_CAPS_FULLSCREEN_ONLY; 121 122 return device; 123} 124 125static void configure_dialog(pspUtilityMsgDialogParams *dialog, size_t dialog_size) 126{ 127 // clear structure and setup size 128 SDL_memset(dialog, 0, dialog_size); 129 dialog->base.size = dialog_size; 130 131 // set language 132 sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, &dialog->base.language); 133 134 // set X/O swap 135 sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &dialog->base.buttonSwap); 136 137 // set thread priorities 138 // TODO: understand how these work 139 dialog->base.soundThread = 0x10; 140 dialog->base.graphicsThread = 0x11; 141 dialog->base.fontThread = 0x12; 142 dialog->base.accessThread = 0x13; 143} 144 145static void *setup_temporal_gu(void *list) 146{ 147 // Using GU_PSM_8888 for the framebuffer 148 int bpp = 4; 149 150 void *doublebuffer = vramalloc(PSP_FRAME_BUFFER_SIZE * bpp * 2); 151 void *backbuffer = doublebuffer; 152 void *frontbuffer = ((uint8_t *)doublebuffer) + PSP_FRAME_BUFFER_SIZE * bpp; 153 154 sceGuInit(); 155 156 sceGuStart(GU_DIRECT,list); 157 sceGuDrawBuffer(GU_PSM_8888, vrelptr(frontbuffer), PSP_FRAME_BUFFER_WIDTH); 158 sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, vrelptr(backbuffer), PSP_FRAME_BUFFER_WIDTH); 159 160 sceGuOffset(2048 - (PSP_SCREEN_WIDTH >> 1), 2048 - (PSP_SCREEN_HEIGHT >> 1)); 161 sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); 162 163 sceGuDisable(GU_DEPTH_TEST); 164 165 // Scissoring 166 sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); 167 sceGuEnable(GU_SCISSOR_TEST); 168 169 sceGuFinish(); 170 sceGuSync(0,0); 171 172 sceDisplayWaitVblankStart(); 173 sceGuDisplay(GU_TRUE); 174 175 return doublebuffer; 176} 177 178static void term_temporal_gu(void *guBuffer) 179{ 180 sceGuTerm(); 181 vfree(guBuffer); 182 sceDisplayWaitVblankStart(); 183} 184 185bool PSP_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) 186{ 187 unsigned char list[64] __attribute__((aligned(64))); 188 pspUtilityMsgDialogParams dialog; 189 int status; 190 void *guBuffer = NULL; 191 192 // check if it's possible to use existing video context 193 if (SDL_GetKeyboardFocus() == NULL) { 194 guBuffer = setup_temporal_gu(list); 195 } 196 197 // configure dialog 198 configure_dialog(&dialog, sizeof(dialog)); 199 200 // setup dialog options for text 201 dialog.mode = PSP_UTILITY_MSGDIALOG_MODE_TEXT; 202 dialog.options = PSP_UTILITY_MSGDIALOG_OPTION_TEXT; 203 204 // copy the message in, 512 bytes max 205 SDL_snprintf(dialog.message, sizeof(dialog.message), "%s\r\n\r\n%s", messageboxdata->title, messageboxdata->message); 206 207 // too many buttons 208 if (messageboxdata->numbuttons > 2) 209 return SDL_SetError("messageboxdata->numbuttons valid values are 0, 1, 2"); 210 211 // we only have two options, "yes/no" or "ok" 212 if (messageboxdata->numbuttons == 2) 213 dialog.options |= PSP_UTILITY_MSGDIALOG_OPTION_YESNO_BUTTONS | PSP_UTILITY_MSGDIALOG_OPTION_DEFAULT_NO; 214 215 // start dialog 216 if (sceUtilityMsgDialogInitStart(&dialog) != 0) 217 return SDL_SetError("sceUtilityMsgDialogInitStart() failed for some reason"); 218 219 // loop while the dialog is active 220 status = PSP_UTILITY_DIALOG_NONE; 221 do 222 { 223 sceGuStart(GU_DIRECT, list); 224 sceGuClearColor(0); 225 sceGuClearDepth(0); 226 sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 227 sceGuFinish(); 228 sceGuSync(0,0); 229 230 status = sceUtilityMsgDialogGetStatus(); 231 232 switch (status) 233 { 234 case PSP_UTILITY_DIALOG_VISIBLE: 235 sceUtilityMsgDialogUpdate(1); 236 break; 237 238 case PSP_UTILITY_DIALOG_QUIT: 239 sceUtilityMsgDialogShutdownStart(); 240 break; 241 } 242 243 sceDisplayWaitVblankStart(); 244 sceGuSwapBuffers(); 245 246 } while (status != PSP_UTILITY_DIALOG_NONE); 247 248 // cleanup 249 if (guBuffer) 250 { 251 term_temporal_gu(guBuffer); 252 } 253 254 // success 255 if (dialog.buttonPressed == PSP_UTILITY_MSGDIALOG_RESULT_YES) 256 *buttonID = messageboxdata->buttons[0].buttonID; 257 else if (dialog.buttonPressed == PSP_UTILITY_MSGDIALOG_RESULT_NO) 258 *buttonID = messageboxdata->buttons[1].buttonID; 259 else 260 *buttonID = messageboxdata->buttons[0].buttonID; 261 262 return true; 263} 264 265VideoBootStrap PSP_bootstrap = { 266 "psp", 267 "PSP Video Driver", 268 PSP_Create, 269 PSP_ShowMessageBox, 270 false 271}; 272 273/*****************************************************************************/ 274// SDL Video and Display initialization/handling functions 275/*****************************************************************************/ 276bool PSP_VideoInit(SDL_VideoDevice *_this) 277{ 278 SDL_DisplayMode mode; 279 280 if (!PSP_EventInit(_this)) { 281 return false; // error string would already be set 282 } 283 284 SDL_zero(mode); 285 mode.w = PSP_SCREEN_WIDTH; 286 mode.h = PSP_SCREEN_HEIGHT; 287 mode.refresh_rate = 60.0f; 288 289 // 32 bpp for default 290 mode.format = SDL_PIXELFORMAT_ABGR8888; 291 292 if (SDL_AddBasicVideoDisplay(&mode) == 0) { 293 return false; 294 } 295 return true; 296} 297 298void PSP_VideoQuit(SDL_VideoDevice *_this) 299{ 300 PSP_EventQuit(_this); 301} 302 303bool PSP_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) 304{ 305 SDL_DisplayMode mode; 306 307 SDL_zero(mode); 308 mode.w = PSP_SCREEN_WIDTH; 309 mode.h = PSP_SCREEN_HEIGHT; 310 mode.refresh_rate = 60.0f; 311 312 // 32 bpp for default 313 mode.format = SDL_PIXELFORMAT_ABGR8888; 314 SDL_AddFullscreenDisplayMode(display, &mode); 315 316 // 16 bpp secondary mode 317 mode.format = SDL_PIXELFORMAT_BGR565; 318 SDL_AddFullscreenDisplayMode(display, &mode); 319 return true; 320} 321 322bool PSP_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) 323{ 324 return true; 325} 326 327#define EGLCHK(stmt) \ 328 do { \ 329 EGLint err; \ 330 \ 331 stmt; \ 332 err = eglGetError(); \ 333 if (err != EGL_SUCCESS) { \ 334 SDL_SetError("EGL error %d", err); \ 335 return true; \ 336 } \ 337 } while (0) 338 339bool PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) 340{ 341 SDL_WindowData *wdata; 342 343 // Allocate window internal data 344 wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); 345 if (!wdata) { 346 return false; 347 } 348 349 // Setup driver data for this window 350 window->internal = wdata; 351 352 SDL_SetKeyboardFocus(window); 353 354 // Window has been successfully created 355 return true; 356} 357 358void PSP_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) 359{ 360} 361bool PSP_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) 362{ 363 return SDL_Unsupported(); 364} 365void PSP_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) 366{ 367} 368void PSP_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window) 369{ 370} 371void PSP_HideWindow(SDL_VideoDevice *_this, SDL_Window *window) 372{ 373} 374void PSP_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window) 375{ 376} 377void PSP_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window) 378{ 379} 380void PSP_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window) 381{ 382} 383void PSP_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window) 384{ 385} 386void PSP_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) 387{ 388} 389 390bool PSP_HasScreenKeyboardSupport(SDL_VideoDevice *_this) 391{ 392 return true; 393} 394 395void PSP_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) 396{ 397 char list[0x20000] __attribute__((aligned(64))); // Needed for sceGuStart to work 398 int i; 399 int done = 0; 400 int input_text_length = 32; // SDL_SendKeyboardText supports up to 32 characters per event 401 unsigned short outtext[input_text_length]; 402 char text_string[input_text_length]; 403 404 SceUtilityOskData data; 405 SceUtilityOskParams params; 406 407 SDL_memset(outtext, 0, input_text_length * sizeof(unsigned short)); 408 409 data.language = PSP_UTILITY_OSK_LANGUAGE_DEFAULT; 410 data.lines = 1; 411 data.unk_24 = 1; 412 switch (SDL_GetTextInputType(props)) { 413 default: 414 case SDL_TEXTINPUT_TYPE_TEXT: 415 data.inputtype = PSP_UTILITY_OSK_INPUTTYPE_ALL; 416 break; 417 case SDL_TEXTINPUT_TYPE_TEXT_NAME: 418 data.inputtype = PSP_UTILITY_OSK_INPUTTYPE_ALL; 419 break; 420 case SDL_TEXTINPUT_TYPE_TEXT_EMAIL: 421 data.inputtype = PSP_UTILITY_OSK_INPUTTYPE_ALL; 422 break; 423 case SDL_TEXTINPUT_TYPE_TEXT_USERNAME: 424 data.inputtype = PSP_UTILITY_OSK_INPUTTYPE_ALL; 425 break; 426 case SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN: 427 data.inputtype = PSP_UTILITY_OSK_INPUTTYPE_ALL; 428 break; 429 case SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_VISIBLE: 430 data.inputtype = PSP_UTILITY_OSK_INPUTTYPE_ALL; 431 break; 432 case SDL_TEXTINPUT_TYPE_NUMBER: 433 data.inputtype = PSP_UTILITY_OSK_INPUTTYPE_LATIN_DIGIT; 434 break; 435 case SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_HIDDEN: 436 data.inputtype = PSP_UTILITY_OSK_INPUTTYPE_LATIN_DIGIT; 437 break; 438 case SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_VISIBLE: 439 data.inputtype = PSP_UTILITY_OSK_INPUTTYPE_LATIN_DIGIT; 440 break; 441 } 442 data.desc = NULL; 443 data.intext = NULL; 444 data.outtextlength = input_text_length; 445 data.outtextlimit = input_text_length; 446 data.outtext = outtext; 447 448 params.base.size = sizeof(params); 449 sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, &params.base.language); 450 sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &params.base.buttonSwap); 451 params.base.graphicsThread = 17; 452 params.base.accessThread = 19; 453 params.base.fontThread = 18; 454 params.base.soundThread = 16; 455 params.datacount = 1; 456 params.data = &data; 457 458 sceUtilityOskInitStart(&params); 459 460 SDL_SendScreenKeyboardShown(); 461 462 while(!done) { 463 sceGuStart(GU_DIRECT, list); 464 sceGuClearColor(0); 465 sceGuClearDepth(0); 466 sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); 467 sceGuFinish(); 468 sceGuSync(0,0); 469 470 switch(sceUtilityOskGetStatus()) 471 { 472 case PSP_UTILITY_DIALOG_VISIBLE: 473 sceUtilityOskUpdate(1); 474 break; 475 case PSP_UTILITY_DIALOG_QUIT: 476 sceUtilityOskShutdownStart(); 477 break; 478 case PSP_UTILITY_DIALOG_NONE: 479 done = 1; 480 break; 481 default : 482 break; 483 } 484 sceDisplayWaitVblankStart(); 485 sceGuSwapBuffers(); 486 } 487 488 // Convert input list to string 489 for (i = 0; i < input_text_length; i++) { 490 text_string[i] = outtext[i]; 491 } 492 SDL_SendKeyboardText((const char *) text_string); 493 494 SDL_SendScreenKeyboardHidden(); 495} 496 497void PSP_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window) 498{ 499} 500 501#endif // SDL_VIDEO_DRIVER_PSP 502
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.