Skip to content

Commit 7b28fb2

Browse files
Fierelierslouken
authored andcommitted
[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 (cherry picked from commit 3fd0b46)
1 parent ecb7214 commit 7b28fb2

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

docs/README-ps2.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ Credit to
1111
## Building
1212
To build SDL2 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

1919
## Hints
2020
The PS2 port has a special Hint for having a dynamic VSYNC. The Hint is `SDL_HINT_PS2_DYNAMIC_VSYNC`.
2121
If you enabled the dynamic vsync having as well `SDL_RENDERER_PRESENTVSYNC` enabled, then if the app is not able to run at 60 FPS, automatically the `vsync` will be disabled having a better performance, instead of droping FPS to 30.
22+
- `SDL_HINT_PS2_GS_WIDTH`: Width of the framebuffer. Defaults to 640.
23+
- `SDL_HINT_PS2_GS_HEIGHT`: Height of the framebuffer. Defaults to 448.
24+
- `SDL_HINT_PS2_GS_PROGRESSIVE`: Whether to use progressive, instead of interlaced. Defaults to 0.
25+
- `SDL_HINT_PS2_GS_MODE`: Regional standard of the signal. "NTSC" (60hz), "PAL" (50hz) or "" (the console's region, default).
2226

2327
## Notes
2428
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 conection with your computer.

include/SDL_hints.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,37 @@ extern "C" {
20242024
*/
20252025
#define SDL_HINT_ROG_GAMEPAD_MICE_EXCLUDED "SDL_ROG_GAMEPAD_MICE_EXCLUDED"
20262026

2027+
/**
2028+
* Variable controlling the width of the PS2's framebuffer in pixels
2029+
*
2030+
* By default, this variable is "640"
2031+
*/
2032+
#define SDL_HINT_PS2_GS_WIDTH "SDL_PS2_GS_WIDTH"
2033+
2034+
/**
2035+
* Variable controlling the height of the PS2's framebuffer in pixels
2036+
*
2037+
* By default, this variable is "448"
2038+
*/
2039+
#define SDL_HINT_PS2_GS_HEIGHT "SDL_PS2_GS_HEIGHT"
2040+
2041+
/**
2042+
* Variable controlling whether the signal is interlaced or progressive
2043+
*
2044+
* - "0": Image is interlaced. (default)
2045+
* - "1": Image is progressive
2046+
*/
2047+
#define SDL_HINT_PS2_GS_PROGRESSIVE "SDL_PS2_GS_PROGRESSIVE"
2048+
2049+
/**
2050+
* Variable controlling the video mode of the console
2051+
*
2052+
* - "": Console-native. (default)
2053+
* - "NTSC": 60hz region
2054+
* - "PAL": 50hz region
2055+
*/
2056+
#define SDL_HINT_PS2_GS_MODE "SDL_PS2_GS_MODE"
2057+
20272058
/**
20282059
* A variable controlling if VSYNC is automatically disable if doesn't reach
20292060
* the enough FPS

src/render/ps2/SDL_render_ps2.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,42 @@ static int PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32
624624

625625
gsGlobal = gsKit_init_global_custom(RENDER_QUEUE_OS_POOLSIZE, RENDER_QUEUE_PER_POOLSIZE);
626626

627-
gsGlobal->Mode = GS_MODE_NTSC;
628-
gsGlobal->Height = 448;
627+
// GS interlaced/progressive
628+
if (SDL_GetHintBoolean(SDL_HINT_PS2_GS_PROGRESSIVE, false)) {
629+
gsGlobal->Interlace = GS_NONINTERLACED;
630+
} else {
631+
gsGlobal->Interlace = GS_INTERLACED;
632+
}
633+
634+
// GS width/height
635+
gsGlobal->Width = 0;
636+
gsGlobal->Height = 0;
637+
const char *hint = SDL_GetHint(SDL_HINT_PS2_GS_WIDTH);
638+
if (hint) {
639+
gsGlobal->Width = SDL_atoi(hint);
640+
}
641+
hint = SDL_GetHint(SDL_HINT_PS2_GS_HEIGHT);
642+
if (hint) {
643+
gsGlobal->Height = SDL_atoi(hint);
644+
}
645+
if (gsGlobal->Width <= 0) {
646+
gsGlobal->Width = 640;
647+
}
648+
if (gsGlobal->Height <= 0) {
649+
gsGlobal->Height = 448;
650+
}
651+
652+
// GS region
653+
hint = SDL_GetHint(SDL_HINT_PS2_GS_MODE);
654+
if (hint) {
655+
if (SDL_strcasecmp(SDL_GetHint(SDL_HINT_PS2_GS_MODE), "NTSC") == 0) {
656+
gsGlobal->Mode = GS_MODE_NTSC;
657+
}
658+
659+
if (SDL_strcasecmp(SDL_GetHint(SDL_HINT_PS2_GS_MODE), "PAL") == 0) {
660+
gsGlobal->Mode = GS_MODE_PAL;
661+
}
662+
}
629663

630664
gsGlobal->PSM = GS_PSM_CT24;
631665
gsGlobal->PSMZ = GS_PSMZ_16S;

0 commit comments

Comments
 (0)