some work on PSP CLUT
authornotaz <notasas@gmail.com>
Sun, 21 Oct 2007 18:41:52 +0000 (18:41 +0000)
committernotaz <notasas@gmail.com>
Sun, 21 Oct 2007 18:41:52 +0000 (18:41 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@277 be3aeb3a-fb24-0410-a615-afba39da0efa

common/menu.c
psp/emu.c
psp/menu.c
psp/port_config.h
psp/psp.c
psp/psp.h

index bb59510..7fc7ba5 100644 (file)
@@ -225,7 +225,6 @@ void menu_init(void)
                                int tmp = parse_hex_color(buff+16);\r
                                if (tmp >= 0) menu_sel_color = tmp;\r
                                else lprintf("skin.txt: parse error for selection_color\n");\r
-                               lprintf("sel color: %04x\n", menu_sel_color);\r
                        }\r
                        else\r
                                lprintf("skin.txt: parse error: %s\n", buff);\r
index 6c1b050..edaf26a 100644 (file)
--- a/psp/emu.c
+++ b/psp/emu.c
@@ -4,6 +4,8 @@
 
 #include <pspthreadman.h>
 #include <pspdisplay.h>
+#include <psputils.h>
+#include <pspgu.h>
 
 #include "psp.h"
 #include "menu.h"
 #define OSD_FPS_X 260
 #endif
 
-// vram usage map:
-// 000000-044000 fb0
-// 044000-088000 fb1
-// 088000-0ae000 texture0
-// 0ae000-0d4000 texture1
-
 char romFileName[PATH_MAX];
-static unsigned char picoD2FB[(8+320)*(8+240+8)];
-unsigned char *PicoDraw2FB = picoD2FB;  // temporary buffer for alt renderer ( (8+320)*(8+240+8) )
+unsigned char *PicoDraw2FB = (unsigned char *)VRAM_CACHED_STUFF + 8; // +8 to be able to skip border with 1 quadword..
 int engineState;
 
 static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos
@@ -139,14 +134,117 @@ void emu_setDefaultConfig(void)
 }
 
 
+static unsigned short __attribute__((aligned(16))) localPal[0x100];
+
+struct Vertex
+{
+       short u,v;
+       short x,y,z;
+};
+
+static void EmuScanPrepare(void)
+{
+       HighCol = VRAM_STUFF;
+
+#if 0
+       sceGuSync(0,0); // sync with prev
+       sceGuStart(GU_DIRECT, guCmdList);
+//     sceGuDispBuffer(480, 272, psp_screen == VRAM_FB0 ? VRAMOFFS_FB1 : VRAMOFFS_FB0, 512);
+       sceGuDrawBuffer(GU_PSM_5650, psp_screen == VRAM_FB0 ? VRAMOFFS_FB0 : VRAMOFFS_FB1, 512); // point to back fb?
+       sceGuFinish();
+#endif
+}
+
 static int EmuScan16(unsigned int num, void *sdata)
 {
+//     struct Vertex* vertices;
+
        if (!(Pico.video.reg[1]&8)) num += 8;
-       DrawLineDest = (unsigned short *) psp_screen + 512*(num+1);
+       //DrawLineDest = (unsigned short *) psp_screen + 512*(num+1);
+       HighCol = (unsigned char *)psp_screen + num*512;
+
+#if 0
+       sceGuSync(0,0); // sync with prev
+       sceGuStart(GU_DIRECT, guCmdList);
+
+       if (Pico.m.dirtyPal) {
+               int i, *dpal = (void *)localPal, *spal = (int *)Pico.cram;
+               Pico.m.dirtyPal = 0;
+               for (i = 0x3f/2; i >= 0; i--)
+                       dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
 
+               sceGuClutLoad((256/8), localPal); // upload 32*8 entries (256)
+       }
+
+       // setup CLUT texture
+
+//     sceGuClutMode(GU_PSM_5650,0,0xff,0);
+//     sceGuClutLoad((256/8), localPal); // upload 32*8 entries (256)
+//     sceGuTexMode(GU_PSM_T8,0,0,0); // 8-bit image
+//     sceGuTexImage(0,512,1/*512*/,512,VRAM_STUFF);
+//     sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
+//     sceGuTexFilter(GU_LINEAR,GU_LINEAR);
+//     sceGuTexScale(1.0f,1.0f);
+//     sceGuTexOffset(0.0f,0.0f);
+//     sceGuAmbientColor(0xffffffff);
+
+       // render sprite
+
+//     sceGuColor(0xffffffff);
+       vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
+       vertices[0].u = 0; vertices[0].v = 0;
+       vertices[0].x = 0; vertices[0].y = num; vertices[0].z = 0;
+       vertices[1].u = 320; vertices[1].v = 512;
+       vertices[1].x = 320; vertices[1].y = num+1; vertices[1].z = 0;
+       //sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);
+
+       sceGuFinish();
+#endif
        return 0;
 }
 
+
+static void draw2_clut(void)
+{
+       struct Vertex* vertices;
+       int x;
+
+       sceKernelDcacheWritebackAll(); // for PicoDraw2FB
+
+       sceGuSync(0,0); // sync with prev
+       sceGuStart(GU_DIRECT, guCmdList);
+//     sceGuDispBuffer(480, 272, psp_screen == VRAM_FB0 ? VRAMOFFS_FB1 : VRAMOFFS_FB0, 512);
+       sceGuDrawBuffer(GU_PSM_5650, psp_screen == VRAM_FB0 ? VRAMOFFS_FB0 : VRAMOFFS_FB1, 512); // point to back fb?
+
+       if (Pico.m.dirtyPal) {
+               int i, *dpal = (void *)localPal, *spal = (int *)Pico.cram;
+               Pico.m.dirtyPal = 0;
+               for (i = 0x3f/2; i >= 0; i--)
+                       dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
+
+               sceGuClutLoad((256/8), localPal); // upload 32*8 entries (256)
+       }
+
+       #define SLICE_WIDTH 32
+
+       for (x = 0; x < 320; x += SLICE_WIDTH)
+       {
+               // render sprite
+               vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
+               vertices[0].u = vertices[0].x = x;
+               vertices[0].v = vertices[0].y = 0;
+               vertices[0].z = 0;
+               vertices[1].u = vertices[1].x = x + SLICE_WIDTH;
+               vertices[1].v = vertices[1].y = 224;
+               vertices[1].z = 0;
+               sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);
+       }
+
+       sceGuFinish();
+}
+
+
+
 static int EmuScan8(unsigned int num, void *sdata)
 {
        // draw like the fast renderer
@@ -187,26 +285,36 @@ static void cd_leds(void)
 }
 
 
-static short localPal[0x100];
-
 static void blit(const char *fps, const char *notice)
 {
        int emu_opt = currentConfig.EmuOpt;
 
-#if 0
        if (PicoOpt&0x10)
        {
-               int lines_flags = 224;
+#if 1
+               draw2_clut();
+#else
+               extern void amips_clut(unsigned short *dst, unsigned char *src, unsigned short *pal, int count);
+               int i; // , lines_flags = 224;
+               unsigned short *pd = psp_screen;
+               unsigned char  *ps = PicoDraw2FB+328*8+8;
                // 8bit fast renderer
                if (Pico.m.dirtyPal) {
+                       int *dpal = (void *)localPal;
+                       int *spal = (int *)Pico.cram;
                        Pico.m.dirtyPal = 0;
-                       vidConvCpyRGB565(localPal, Pico.cram, 0x40);
+                       for (i = 0x3f/2; i >= 0; i--)
+                               dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
                }
-               if (!(Pico.video.reg[12]&1)) lines_flags|=0x10000;
-               if (currentConfig.EmuOpt&0x4000)
-                       lines_flags|=0x40000; // (Pico.m.frame_count&1)?0x20000:0x40000;
-               vidCpy8to16((unsigned short *)giz_screen+321*8, PicoDraw2FB+328*8, localPal, lines_flags);
+               // if (!(Pico.video.reg[12]&1)) lines_flags|=0x10000;
+               // if (currentConfig.EmuOpt&0x4000)
+               //      lines_flags|=0x40000; // (Pico.m.frame_count&1)?0x20000:0x40000;
+               //vidCpy8to16((unsigned short *)giz_screen+321*8, PicoDraw2FB+328*8, localPal, lines_flags);
+               for (i = 224; i > 0; i--, pd+=512, ps+=328)
+                       amips_clut(pd, ps, localPal, 320);
+#endif
        }
+#if 0
        else if (!(emu_opt&0x80))
        {
                int lines_flags;
@@ -245,6 +353,7 @@ static void blit(const char *fps, const char *notice)
        if ((emu_opt & 0x400) && (PicoMCD & 1))
                cd_leds();
 
+       sceGuSync(0,0);
        psp_video_flip(0);
 }
 
@@ -264,10 +373,30 @@ static void clearArea(int full)
 
 static void vidResetMode(void)
 {
+       // setup GU
+       sceGuSync(0,0); // sync with prev
+       sceGuStart(GU_DIRECT, guCmdList);
+
+       sceGuClutMode(GU_PSM_5650,0,0xff,0);
+       //sceGuClutLoad((256/8), localPal); // upload 32*8 entries (256)
+       sceGuTexMode(GU_PSM_T8,0,0,0); // 8-bit image
+       sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
+       sceGuTexFilter(GU_LINEAR,GU_LINEAR);
+       sceGuTexScale(1.0f,1.0f);
+       sceGuTexOffset(0.0f,0.0f);
+       sceGuAmbientColor(0xffffffff);
+       sceGuColor(0xffffffff);
+
+
        if (PicoOpt&0x10) {
+               sceGuTexImage(0,512,512,512,(char *)VRAM_STUFF + 8*512+16);
+
        } else if (currentConfig.EmuOpt&0x80) {
-               PicoDrawSetColorFormat(1);
+               PicoDrawSetColorFormat(/*1*/-1);
                PicoScan = EmuScan16;
+
+               sceGuTexImage(0,512,1/*512*/,512,VRAM_STUFF);
+
        } else {
                PicoDrawSetColorFormat(-1);
                PicoScan = EmuScan8;
@@ -281,16 +410,19 @@ static void vidResetMode(void)
        }
        Pico.m.dirtyPal = 1;
 
+       sceGuFinish();
+       sceGuSync(0,0);
+
        clearArea(1);
 }
-
+/*
 static void updateSound(int len)
 {
        if (PicoOpt&8) len<<=1;
 
        // TODO..
 }
-
+*/
 
 static void SkipFrame(void)
 {
@@ -310,7 +442,7 @@ void emu_forcedFrame(void)
 
        PicoDrawSetColorFormat(1);
        PicoScan = EmuScan16;
-       PicoScan((unsigned) -1, NULL);
+       EmuScanPrepare();
        Pico.m.dirtyPal = 1;
        PicoFrameDrawOnly();
 
@@ -662,7 +794,7 @@ void emu_Loop(void)
                updateKeys();
 
                if (!(PicoOpt&0x10))
-                       PicoScan((unsigned) -1, NULL);
+                       EmuScanPrepare();
 
                PicoFrame();
 
index b2b3fc5..1f3c6ea 100644 (file)
@@ -39,8 +39,6 @@ static const char * const pspKeyNames[] = {
        pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn
 };
 
-unsigned int __attribute__((aligned(16))) guCmdList[1024]; // TODO: adjust, mv
-
 static unsigned char bg_buffer[480*272*2] __attribute__((aligned(16))); // TODO: move to vram?
 #define menu_screen psp_screen
 
@@ -92,10 +90,11 @@ static void menu_draw_begin(void)
        // for (i = 272; i >= 0; i--, dst += 512, src += 480)
        //      memcpy32((int *)dst, (int *)src, 480*2/4);
 
+       sceGuSync(0,0); // sync with prev
        sceGuStart(GU_DIRECT, guCmdList);
        sceGuCopyImage(GU_PSM_5650, 0, 0, 480, 272, 480, bg_buffer, 0, 0, 512, menu_screen);
        sceGuFinish();
-       sceGuSync(0, GU_SYNC_FINISH);
+       sceGuSync(0,0);
 }
 
 
index fe56132..486a877 100644 (file)
@@ -7,11 +7,12 @@
 \r
 // draw.c\r
 #define USE_BGR555 1\r
-#define OVERRIDE_HIGHCOL 0\r
+#define OVERRIDE_HIGHCOL 1\r
 \r
 // draw2.c\r
 #define START_ROW  0 // which row of tiles to start rendering at?\r
 #define END_ROW   28 // ..end\r
+#define DRAW2_OVERRIDE_LINE_WIDTH 512\r
 \r
 // pico.c\r
 #define CAN_HANDLE_240_LINES   1\r
index e740f21..8f811f6 100644 (file)
--- a/psp/psp.c
+++ b/psp/psp.c
@@ -13,7 +13,9 @@
 
 PSP_MODULE_INFO("PicoDrive", 0, 1, 34);
 
-void *psp_screen = PSP_VRAM_BASE0;
+unsigned int __attribute__((aligned(16))) guCmdList[GU_CMDLIST_SIZE];
+
+void *psp_screen = VRAM_FB0;
 static int current_screen = 0; /* front bufer */
 
 static SceUID logfd = -1;
@@ -54,13 +56,49 @@ void psp_init(void)
 
        /* video */
        sceDisplaySetMode(0, 480, 272);
-       sceDisplaySetFrameBuf(PSP_VRAM_BASE1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
+       sceDisplaySetFrameBuf(VRAM_FB1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
        current_screen = 1;
-       psp_screen = PSP_VRAM_BASE0;
+       psp_screen = VRAM_FB0;
 
        /* gu */
        sceGuInit();
 
+       sceGuStart(GU_DIRECT, guCmdList);
+       sceGuDrawBuffer(GU_PSM_5650, VRAMOFFS_FB0, 512); // point to back fb?
+       sceGuDispBuffer(480, 272, VRAMOFFS_FB1, 512);
+       sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
+       sceGuDepthBuffer(VRAMOFFS_DEPTH, 512);
+       sceGuOffset(2048 - (480 / 2), 2048 - (272 / 2));
+       sceGuViewport(2048, 2048, 480, 272);
+       sceGuDepthRange(0xc350, 0x2710);
+       sceGuScissor(0, 0, 480, 272);
+       sceGuEnable(GU_SCISSOR_TEST);
+//     sceGuAlphaFunc(GU_GREATER, 0, 0xff);
+//     sceGuEnable(GU_ALPHA_TEST);
+//     sceGuDepthFunc(GU_ALWAYS); // GU_GEQUAL);
+//     sceGuEnable(GU_DEPTH_TEST);
+
+       sceGuDepthMask(0xffff);
+       sceGuDisable(GU_DEPTH_TEST);
+
+       sceGuFrontFace(GU_CW);
+//     sceGuShadeModel(GU_SMOOTH);
+//     sceGuEnable(GU_CULL_FACE);
+       sceGuEnable(GU_TEXTURE_2D);
+//     sceGuEnable(GU_CLIP_PLANES);
+       sceGuTexMode(GU_PSM_5650, 0, 0, 0);
+       sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
+       sceGuTexFilter(GU_NEAREST, GU_NEAREST);
+//     sceGuAmbientColor(0xffffffff);
+//     sceGuEnable(GU_BLEND);
+//     sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
+       sceGuFinish();
+       sceGuSync(0, 0);
+
+       sceDisplayWaitVblankStart();
+       sceGuDisplay(GU_TRUE);
+
+
        /* input */
        sceCtrlSetSamplingCycle(0);
        sceCtrlSetSamplingMode(0);
@@ -80,17 +118,17 @@ void psp_video_flip(int wait_vsync)
        sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565,
                wait_vsync ? PSP_DISPLAY_SETBUF_IMMEDIATE : PSP_DISPLAY_SETBUF_NEXTFRAME);
        current_screen ^= 1;
-       psp_screen = current_screen ? PSP_VRAM_BASE0 : PSP_VRAM_BASE1;
+       psp_screen = current_screen ? VRAM_FB0 : VRAM_FB1;
 }
 
 void *psp_video_get_active_fb(void)
 {
-       return current_screen ? PSP_VRAM_BASE1 : PSP_VRAM_BASE0;
+       return current_screen ? VRAM_FB1 : VRAM_FB0;
 }
 
 void psp_video_switch_to_single(void)
 {
-       psp_screen = PSP_VRAM_BASE0;
+       psp_screen = VRAM_FB0;
        sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
        current_screen = 0;
 }
index 07d4093..03f9db0 100644 (file)
--- a/psp/psp.h
+++ b/psp/psp.h
@@ -5,8 +5,25 @@ void psp_finish(void);
 
 void psp_msleep(int ms);
 
-#define PSP_VRAM_BASE0 ((void *) 0x44000000)
-#define PSP_VRAM_BASE1 ((void *) 0x44044000)
+// vram usage map:
+// 000000-044000 fb0
+// 044000-088000 fb1
+// 088000-0cc000 depth (?)
+// 0cc000-0??000 stuff
+
+#define VRAMOFFS_FB0    ((void *) 0x00000000)
+#define VRAMOFFS_FB1    ((void *) 0x00044000)
+#define VRAMOFFS_DEPTH  ((void *) 0x00088000)
+
+#define VRAM_FB0        ((void *) 0x44000000)
+#define VRAM_FB1        ((void *) 0x44044000)
+#define VRAM_STUFF      ((void *) 0x440cc000)
+
+#define VRAM_CACHED_STUFF   ((void *) 0x040cc000)
+
+#define GU_CMDLIST_SIZE (16*1024) // TODO: adjust
+
+extern unsigned int guCmdList[GU_CMDLIST_SIZE];
 
 void *psp_video_get_active_fb(void);
 void  psp_video_switch_to_single(void);