Skip to content

Commit 3fd0b46

Browse files
authored
[SDL3] [PS2] Framebuffer resolution + 240p/480p + PAL support (#13993)
* Do not override NTSC/PAL * Fix PS2 build instructions * Add PS2 GS hints Allows for switching between NTSC/PAL, progressive/interlaced, etc
1 parent bce2a33 commit 3fd0b46

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

docs/README-ps2.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ Credit to
1111
## Building
1212
To build SDL library for the PS2, make sure you have the latest PS2Dev status and run:
1313
```bash
14-
cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$PS2DEV/ps2sdk/ps2dev.cmake
14+
cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$PS2DEV/share/ps2dev.cmake
1515
cmake --build build
1616
cmake --install build
1717
```
1818

19+
## Hints
20+
- `SDL_HINT_PS2_GS_WIDTH`: Width of the framebuffer. Defaults to 640.
21+
- `SDL_HINT_PS2_GS_HEIGHT`: Height of the framebuffer. Defaults to 448.
22+
- `SDL_HINT_PS2_GS_PROGRESSIVE`: Whether to use progressive, instead of interlaced. Defaults to 0.
23+
- `SDL_HINT_PS2_GS_MODE`: Regional standard of the signal. "NTSC" (60hz), "PAL" (50hz) or "" (the console's region, default).
24+
1925
## Notes
2026
If you trying to debug a SDL app through [ps2client](https://github.com/ps2dev/ps2client) you need to avoid the IOP reset, otherwise you will lose the connection with your computer.
2127
So to avoid the reset of the IOP CPU, you need to call to the macro `SDL_PS2_SKIP_IOP_RESET();`.

include/SDL3/SDL_hints.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,37 @@ extern "C" {
31853185
*/
31863186
#define SDL_HINT_ROG_GAMEPAD_MICE_EXCLUDED "SDL_ROG_GAMEPAD_MICE_EXCLUDED"
31873187

3188+
/**
3189+
* Variable controlling the width of the PS2's framebuffer in pixels
3190+
*
3191+
* By default, this variable is "640"
3192+
*/
3193+
#define SDL_HINT_PS2_GS_WIDTH "SDL_PS2_GS_WIDTH"
3194+
3195+
/**
3196+
* Variable controlling the height of the PS2's framebuffer in pixels
3197+
*
3198+
* By default, this variable is "448"
3199+
*/
3200+
#define SDL_HINT_PS2_GS_HEIGHT "SDL_PS2_GS_HEIGHT"
3201+
3202+
/**
3203+
* Variable controlling whether the signal is interlaced or progressive
3204+
*
3205+
* - "0": Image is interlaced. (default)
3206+
* - "1": Image is progressive
3207+
*/
3208+
#define SDL_HINT_PS2_GS_PROGRESSIVE "SDL_PS2_GS_PROGRESSIVE"
3209+
3210+
/**
3211+
* Variable controlling the video mode of the console
3212+
*
3213+
* - "": Console-native. (default)
3214+
* - "NTSC": 60hz region
3215+
* - "PAL": 50hz region
3216+
*/
3217+
#define SDL_HINT_PS2_GS_MODE "SDL_PS2_GS_MODE"
3218+
31883219
/**
31893220
* A variable controlling which Dispmanx layer to use on a Raspberry PI.
31903221
*

src/render/ps2/SDL_render_ps2.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,42 @@ static bool PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
655655

656656
gsGlobal = gsKit_init_global_custom(RENDER_QUEUE_OS_POOLSIZE, RENDER_QUEUE_PER_POOLSIZE);
657657

658-
gsGlobal->Mode = GS_MODE_NTSC;
659-
gsGlobal->Height = 448;
658+
// GS interlaced/progressive
659+
if (SDL_GetHintBoolean(SDL_HINT_PS2_GS_PROGRESSIVE, false)) {
660+
gsGlobal->Interlace = GS_NONINTERLACED;
661+
} else {
662+
gsGlobal->Interlace = GS_INTERLACED;
663+
}
664+
665+
// GS width/height
666+
gsGlobal->Width = 0;
667+
gsGlobal->Height = 0;
668+
const char *hint = SDL_GetHint(SDL_HINT_PS2_GS_WIDTH);
669+
if (hint) {
670+
gsGlobal->Width = SDL_atoi(hint);
671+
}
672+
hint = SDL_GetHint(SDL_HINT_PS2_GS_HEIGHT);
673+
if (hint) {
674+
gsGlobal->Height = SDL_atoi(hint);
675+
}
676+
if (gsGlobal->Width <= 0) {
677+
gsGlobal->Width = 640;
678+
}
679+
if (gsGlobal->Height <= 0) {
680+
gsGlobal->Height = 448;
681+
}
682+
683+
// GS region
684+
hint = SDL_GetHint(SDL_HINT_PS2_GS_MODE);
685+
if (hint) {
686+
if (SDL_strcasecmp(SDL_GetHint(SDL_HINT_PS2_GS_MODE), "NTSC") == 0) {
687+
gsGlobal->Mode = GS_MODE_NTSC;
688+
}
689+
690+
if (SDL_strcasecmp(SDL_GetHint(SDL_HINT_PS2_GS_MODE), "PAL") == 0) {
691+
gsGlobal->Mode = GS_MODE_PAL;
692+
}
693+
}
660694

661695
gsGlobal->PSM = GS_PSM_CT24;
662696
gsGlobal->PSMZ = GS_PSMZ_16S;

0 commit comments

Comments
 (0)