8bit sdl surfaces

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

8bit sdl surfaces

Post by crazyc »

Here's a patch to add support for 8bit software surfaces in SDL.

Code: Select all

--- SDL_pspvideo.c.orig	Fri Aug 26 15:58:10 2005
+++ SDL_pspvideo.c	Fri Aug 26 15:54:56 2005
@@ -35,6 +35,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <malloc.h>
 
 #include "SDL.h"
 #include "SDL_error.h"
@@ -205,7 +206,13 @@
         sceGuInit&#40;&#41;;
         sceGuStart&#40;GU_DIRECT, list&#41;; 
         sceGuDispBuffer&#40;SCREEN_WIDTH, SCREEN_HEIGHT, &#40;void*&#41;0, PSP_LINE_SIZE&#41;;
-        sceGuDrawBuffer&#40;gu_format, &#40;void*&#41;0, PSP_LINE_SIZE&#41;;
+		if&#40;gu_format == GU_PSM_T8&#41;
+		&#123;
+			sceGuDrawBuffer&#40;GU_PSM_8888, &#40;void*&#41;0, PSP_LINE_SIZE&#41;;
+			sceGuClutMode&#40;GU_PSM_8888, 0, 255, 0&#41;;
+		&#125;
+		else
+        	sceGuDrawBuffer&#40;gu_format, &#40;void*&#41;0, PSP_LINE_SIZE&#41;;
         sceGuClear&#40;GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT&#41;;
         sceGuDepthBuffer&#40;&#40;void*&#41; 0x110000, PSP_LINE_SIZE&#41;;
         sceGuOffset&#40;2048 - &#40;SCREEN_WIDTH / 2&#41;, 2048 - &#40;SCREEN_HEIGHT / 2&#41;&#41;;
@@ -236,6 +243,13 @@
         &#125;
 
         switch&#40;bpp&#41; &#123;
+		case 8&#58;
+				Amask = 0;
+				Rmask = 0;
+				Gmask = 0;
+				Bmask = 0;
+				pixel_format = PSP_DISPLAY_PIXEL_FORMAT_8888;
+				gu_format = GU_PSM_T8;
         case 15&#58; /* 5-5-5-1 */
                 pitch = 512 * 2;
                 Amask = 0x00008000;
@@ -301,6 +315,8 @@
 
                 this->hidden->gu_format = gu_format;
                 this->UpdateRects = PSP_GuUpdateRects;
+				if&#40;bpp == 8 && !this->hidden->gu_palette&#41;
+					this->hidden->gu_palette = memalign&#40;16, 4 * 256&#41;; 
     &#125;
 
         this->hidden->pixel_format = pixel_format;
@@ -448,8 +464,20 @@
 
 int PSP_SetColors&#40;_THIS, int firstcolor, int ncolors, SDL_Color *colors&#41;
 &#123;
-        /* do nothing of note. */
-        return&#40;1&#41;;
+	int i, j;
+	unsigned int *palette = this->hidden->gu_palette;
+
+	if &#40;this->hidden->gu_format != GU_PSM_T8&#41; return 0;
+	
+	for &#40;i=firstcolor, j=0; j < ncolors; i++, j++&#41;
+		palette&#91;i&#93; = &#40;colors&#91;j&#93;.b << 16&#41; | &#40;colors&#91;j&#93;.g << 8&#41; | &#40;colors&#91;j&#93;.r&#41;;
+		
+	sceKernelDcacheWritebackAll&#40;&#41;;
+	sceGuStart&#40;GU_DIRECT, list&#41;;
+	sceGuClutLoad&#40;32, this->hidden->gu_palette&#41;;
+	sceGuFinish&#40;&#41;;
+	
+	return 1;
 &#125;
 
 /* Note&#58;  If we are terminated, this could be called in the middle of
Also "unsigned int *gu_palette" should be added to the SDL_PrivateVideoData struct
stefan
Posts: 10
Joined: Sun Nov 14, 2004 4:54 pm

Post by stefan »

Applied with minor changes. Untested.
vtrucco
Posts: 1
Joined: Fri Aug 05, 2005 3:36 am

Post by vtrucco »

Doesn't work for me. I tested with /SDL/test/testsprite.c

"8-bit surfaces are only supported on software surfaces."
urchin
Posts: 121
Joined: Thu Jun 02, 2005 5:41 pm

Post by urchin »

If you specify double buffering when setting the video mode to 8bit, it will be forced into hardware surface mode and fail.
Post Reply