Add prim video support
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4c9daf3..9f430a7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3040,6 +3040,10 @@ if(APPLE)
target_compile_options(sdl-build-options INTERFACE "-fobjc-arc")
endif()
+if(PS2)
+ target_compile_options(sdl-build-options INTERFACE "-Wno-error=declaration-after-statement")
+endif()
+
if(SDL_SHARED)
add_library(SDL2 SHARED ${SOURCE_FILES} ${VERSION_SOURCES})
add_dependencies(SDL2 sdl_headers_copy)
diff --git a/src/video/ps2/SDL_ps2video.c b/src/video/ps2/SDL_ps2video.c
index 3546d8d..ed666dd 100644
--- a/src/video/ps2/SDL_ps2video.c
+++ b/src/video/ps2/SDL_ps2video.c
@@ -57,6 +57,9 @@ static void PS2_VideoQuit(_THIS);
/* PS2 driver bootstrap functions */
+static GSGLOBAL *gsGlobal = NULL;
+static int vsync_sema_id = 0;
+
static void
PS2_DeleteDevice(SDL_VideoDevice * device)
{
@@ -96,17 +99,112 @@ VideoBootStrap PS2_bootstrap = {
};
+/* PRIVATE METHODS */
+static int vsync_handler()
+{
+ iSignalSema(vsync_sema_id);
+
+ ExitHandler();
+ return 0;
+}
+
+/* Copy of gsKit_sync_flip, but without the 'flip' */
+static void gsKit_sync(GSGLOBAL *gsGlobal)
+{
+ if (!gsGlobal->FirstFrame) WaitSema(vsync_sema_id);
+ while (PollSema(vsync_sema_id) >= 0)
+ ;
+}
+
+/* Copy of gsKit_sync_flip, but without the 'sync' */
+static void gsKit_flip(GSGLOBAL *gsGlobal)
+{
+ if (!gsGlobal->FirstFrame)
+ {
+ if (gsGlobal->DoubleBuffering == GS_SETTING_ON)
+ {
+ GS_SET_DISPFB2( gsGlobal->ScreenBuffer[
+ gsGlobal->ActiveBuffer & 1] / 8192,
+ gsGlobal->Width / 64, gsGlobal->PSM, 0, 0 );
+
+ gsGlobal->ActiveBuffer ^= 1;
+ }
+
+ }
+
+ gsKit_setactive(gsGlobal);
+}
+
int
PS2_VideoInit(_THIS)
{
+ ee_sema_t sema;
+ sema.init_count = 0;
+ sema.max_count = 1;
+ sema.option = 0;
+ vsync_sema_id = CreateSema(&sema);
+
+ gsGlobal = gsKit_init_global();
+
+ gsGlobal->Mode = gsKit_check_rom();
+ if (gsGlobal->Mode == GS_MODE_PAL){
+ gsGlobal->Height = 512;
+ } else {
+ gsGlobal->Height = 448;
+ }
+
+ gsGlobal->PSM = GS_PSM_CT24;
+ gsGlobal->PSMZ = GS_PSMZ_16S;
+ gsGlobal->ZBuffering = GS_SETTING_OFF;
+ gsGlobal->DoubleBuffering = GS_SETTING_ON;
+ gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
+ gsGlobal->Dithering = GS_SETTING_OFF;
+
+ gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
+
+ dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
+ dmaKit_chan_init(DMA_CHANNEL_GIF);
+
+ printf("\nGraphics: created %ix%i video surface\n",
+ gsGlobal->Width, gsGlobal->Height);
+
+ gsKit_set_clamp(gsGlobal, GS_CMODE_REPEAT);
+
+ gsKit_vram_clear(gsGlobal);
+
+ gsKit_init_screen(gsGlobal);
+
+ gsKit_TexManager_init(gsGlobal);
+
+ gsKit_add_vsync_handler(vsync_handler);
+
+ gsKit_mode_switch(gsGlobal, GS_ONESHOT);
+
+ gsKit_clear(gsGlobal, GS_SETREG_RGBAQ(0x80,0x00,0x00,0x80,0x00));
+
+ if (gsGlobal->DoubleBuffering == GS_SETTING_OFF) {
+ gsKit_sync(gsGlobal);
+ gsKit_queue_exec(gsGlobal);
+ } else {
+ gsKit_queue_exec(gsGlobal);
+ gsKit_finish();
+ gsKit_sync(gsGlobal);
+ gsKit_flip(gsGlobal);
+ }
+ gsKit_TexManager_nextFrame(gsGlobal);
+
SDL_DisplayMode mode;
/* Use a fake 32-bpp desktop mode */
SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_RGB888;
- mode.w = 1024;
- mode.h = 768;
- mode.refresh_rate = 0;
+ mode.w = 640;
+ if (gsGlobal->Mode == GS_MODE_PAL){
+ mode.h = 512;
+ } else {
+ mode.h = 448;
+ }
+ mode.refresh_rate = 60;
mode.driverdata = NULL;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
@@ -119,14 +217,58 @@ PS2_VideoInit(_THIS)
}
static int
+SDL_to_PS2_PFM(Uint32 format)
+{
+ switch (format) {
+ case SDL_PIXELFORMAT_RGBA5551:
+ return GS_PSM_CT16S;
+ case SDL_PIXELFORMAT_RGB24:
+ return GS_PSM_CT24;
+ case SDL_PIXELFORMAT_ABGR32:
+ return GS_PSM_CT32;
+ default:
+ return GS_PSM_CT24;
+ }
+}
+
+static int
PS2_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
+ gsGlobal->Mode = GS_MODE_NTSC;
+ gsGlobal->Width = mode->w;
+ if ((gsGlobal->Interlace == GS_INTERLACED) && (gsGlobal->Field == GS_FRAME))
+ gsGlobal->Height = mode->h / 2;
+ else
+ gsGlobal->Height = mode->h;
+
+ gsGlobal->PSM = SDL_to_PS2_PFM(mode->format);
+ gsGlobal->PSMZ = GS_PSMZ_16S;
+
+ gsGlobal->ZBuffering = GS_SETTING_OFF;
+ gsGlobal->DoubleBuffering = GS_SETTING_ON;
+ gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
+ gsGlobal->Dithering = GS_SETTING_OFF;
+
+ gsGlobal->Interlace = GS_INTERLACED;
+ gsGlobal->Field = GS_FIELD;
+
+ gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
+
+ gsKit_set_clamp(gsGlobal, GS_CMODE_REPEAT);
+ gsKit_vram_clear(gsGlobal);
+ gsKit_init_screen(gsGlobal);
+ gsKit_set_display_offset(gsGlobal, -0.5f, -0.5f);
+ gsKit_sync_flip(gsGlobal);
+
+ gsKit_mode_switch(gsGlobal, GS_ONESHOT);
+ gsKit_clear(gsGlobal, GS_SETREG_RGBAQ(0x00,0x00,0x00,0x80,0x00));
return 0;
}
void
PS2_VideoQuit(_THIS)
{
+ gsKit_deinit_global(gsGlobal);
}
#endif /* SDL_VIDEO_DRIVER_PS2 */
diff --git a/src/video/ps2/SDL_ps2video.h b/src/video/ps2/SDL_ps2video.h
index 59fd883..3a380fa 100644
--- a/src/video/ps2/SDL_ps2video.h
+++ b/src/video/ps2/SDL_ps2video.h
@@ -25,6 +25,14 @@
#include "../SDL_sysvideo.h"
+#include <kernel.h>
+
+#include <gsKit.h>
+#include <dmaKit.h>
+
+#include <gsToolkit.h>
+#include <gsInline.h>
+
#endif /* SDL_ps2video_h_ */
/* vi: set ts=4 sw=4 expandtab: */