Browse Source

new code to collect/use more stats, some debug tools

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@520 be3aeb3a-fb24-0410-a615-afba39da0efa
notaz 16 years ago
parent
commit
fbc65db755
5 changed files with 239 additions and 112 deletions
  1. 177 73
      Pico/Draw.c
  2. 16 31
      Pico/Draw.s
  3. 1 2
      Pico/Pico.c
  4. 5 2
      Pico/Pico.h
  5. 40 4
      platform/gp2x/menu.c

+ 177 - 73
Pico/Draw.c

@@ -36,19 +36,21 @@ static int  HighCacheA[41+1];   // caches for high layers
 static int  HighCacheB[41+1];
 int  HighPreSpr[80*2+1]; // slightly preprocessed sprites
 
-#define MAX_LINE_SPRITES 30
-unsigned char HighLnSpr[240][2 + MAX_LINE_SPRITES]; // sprite_count, tile_count, [spritep]...
+#define MAX_LINE_SPRITES 29
+#define SPRL_HAVE_HI     0x80 // have hi priority sprites
+#define SPRL_HAVE_LO     0x40 // *lo*
+#define SPRL_MAY_HAVE_OP 0x20 // may have operator sprites on the line
+#define SPRL_LO_ABOVE_HI 0x10 // low priority sprites may be on top of hi
+unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES]; // sprite_count, ^flags, tile_count, [spritep]...
 
 int rendstatus = 0;
 int DrawScanline = 0;
+int PicoDrawMask = -1;
 
 static int skip_next_line=0;
 
 //unsigned short ppt[] = { 0x0f11, 0x0ff1, 0x01f1, 0x011f, 0x01ff, 0x0f1f, 0x0f0e, 0x0e7c };
 
-static void (*DrawAllSpritesLoPri)(int prio, int sh) = NULL;
-static void (*DrawAllSpritesHiPri)(int prio, int sh) = NULL;
-
 struct TileStrip
 {
   int nametab; // Position in VRAM of name table (for this tile line)
@@ -65,7 +67,7 @@ void DrawWindow(int tstart, int tend, int prio, int sh);
 void BackFill(int reg7, int sh);
 void DrawAllSprites(int prio, int sh);
 void DrawTilesFromCache(int *hc, int sh, int rlim);
-void DrawSpritesSHi(int prio, int sh);
+void DrawSpritesSHi(unsigned short *sprited);
 void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells);
 void FinalizeLineBGR444(int sh);
 void FinalizeLineRGB555(int sh);
@@ -772,16 +774,16 @@ static void DrawAllSpritesInterlace(int pri, int sh)
 #ifndef _ASM_DRAW_C
 // Index + 0  :    hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size
 // Index + 4  :    xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
-static void DrawSpritesSHi(int prio, int sh)
+static void DrawSpritesSHi(unsigned char *sprited)
 {
   int (*fTileFunc)(int sx,int addr,int pal);
   unsigned char *p;
   int cnt;
 
-  cnt = HighLnSpr[DrawScanline][0] & 0x7f;
+  cnt = sprited[0] & 0x7f;
   if (cnt == 0) return;
 
-  p = &HighLnSpr[DrawScanline][2];
+  p = &sprited[3];
 
   // Go through sprites backwards:
   for (cnt--; cnt >= 0; cnt--)
@@ -794,7 +796,7 @@ static void DrawSpritesSHi(int prio, int sh)
     code = sprite[1];
     pal = (code>>9)&0x30;
 
-    if (sh && pal == 0x30)
+    if (pal == 0x30)
     {
       if (code & 0x8000) // hi priority
       {
@@ -840,16 +842,16 @@ static void DrawSpritesSHi(int prio, int sh)
 }
 #endif
 
-static void DrawSpritesHiAS(int prio, int sh)
+static void DrawSpritesHiAS(unsigned char *sprited, int sh)
 {
   int (*fTileFunc)(int sx,int addr,int pal);
   unsigned char *p;
   int entry, cnt, sh_cnt = 0;
 
-  cnt = HighLnSpr[DrawScanline][0] & 0x7f;
+  cnt = sprited[0] & 0x7f;
   if (cnt == 0) return;
 
-  p = &HighLnSpr[DrawScanline][2];
+  p = &sprited[3];
 
   // Go through sprites:
   for (entry = 0; entry < cnt; entry++)
@@ -908,7 +910,7 @@ static void DrawSpritesHiAS(int prio, int sh)
     }
   }
 
-  if (!sh) return;
+  if (!sh || !(sprited[1]&SPRL_MAY_HAVE_OP)) return;
 
   /* nasty 1: remove 'sprite' flags */
   {
@@ -920,8 +922,8 @@ static void DrawSpritesHiAS(int prio, int sh)
   }
 
   /* nasty 2: sh operator pass */
-  HighLnSpr[DrawScanline][0] = sh_cnt;
-  DrawSpritesSHi(1, 1);
+  sprited[0] = sh_cnt;
+  DrawSpritesSHi(sprited);
 }
 
 
@@ -934,7 +936,7 @@ static void DrawSpritesHiAS(int prio, int sh)
 void PrepareSprites(int full)
 {
   struct PicoVideo *pvid=&Pico.video;
-  int u,link=0;
+  int u,link=0,sh;
   int table=0;
   int *pd = HighPreSpr;
   int max_lines = 224, max_sprites = 80, max_width = 328;
@@ -946,6 +948,7 @@ void PrepareSprites(int full)
     max_line_sprites = MAX_LINE_SPRITES;
 
   if (pvid->reg[1]&8) max_lines = 240;
+  sh = Pico.video.reg[0xC]&8; // shadow/hilight?
 
   table=pvid->reg[5]&0x7f;
   if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
@@ -981,15 +984,15 @@ void PrepareSprites(int full)
           if (cnt >= max_line_sprites) continue;              // sprite limit?
 
           for (i = 0; i < cnt; i++)
-            if (((HighLnSpr[y][2+i] ^ entry) & 0x7f) == 0) goto found;
+            if (((HighLnSpr[y][3+i] ^ entry) & 0x7f) == 0) goto found;
 
           // this sprite was previously missing
-          HighLnSpr[y][2+cnt] = entry;
+          HighLnSpr[y][3+cnt] = entry;
           HighLnSpr[y][0] = cnt + 1;
 found:;
           if (entry & 0x80)
-               rendstatus |= PDRAW_HAVE_HI_SPR;
-          else rendstatus |= PDRAW_HAVE_LO_SPR;
+               HighLnSpr[y][1] |= SPRL_HAVE_HI;
+          else HighLnSpr[y][1] |= SPRL_HAVE_LO;
         }
       }
 
@@ -1004,6 +1007,8 @@ found:;
   }
   else
   {
+    int old_prio = 0x8000, lo_above_hi = 0;
+
     for (u = 0; u < max_lines; u++)
       *((int *)&HighLnSpr[u][0]) = 0;
 
@@ -1011,7 +1016,6 @@ found:;
     {
       unsigned int *sprite;
       int code, code2, sx, sy, hv, height, width;
-      int sx_min;
 
       sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
 
@@ -1025,22 +1029,32 @@ found:;
       code2 = sprite[1];
       sx = (code2>>16)&0x1ff;
       sx -= 0x78; // Get X coordinate + 8
-      sx_min = 8-(width<<3);
 
       if (sy < max_lines && sy + (height<<3) > DrawScanline) // sprite onscreen (y)?
       {
-        int y = (sy >= DrawScanline) ? sy : DrawScanline;
-        int entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);
+        int entry, y, sx_min, onscr_x, maybe_op = 0;
+
+        sx_min = 8-(width<<3);
+        onscr_x = sx_min < sx && sx < max_width;
+        if (sh && (code2 & 0x6000) == 0x6000)
+          maybe_op = SPRL_MAY_HAVE_OP;
+
+        if (onscr_x && !old_prio && (code2 & 0x8000))
+          lo_above_hi = SPRL_LO_ABOVE_HI;
+        old_prio = code2 & 0x8000;
+
+        entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);
+        y = (sy >= DrawScanline) ? sy : DrawScanline;
         for (; y < sy + (height<<3) && y < max_lines; y++)
         {
           int cnt = HighLnSpr[y][0];
           if (cnt >= max_line_sprites) continue;              // sprite limit?
 
-          if (HighLnSpr[y][1] >= max_line_sprites*2) {        // tile limit?
+          if (HighLnSpr[y][2] >= max_line_sprites*2) {        // tile limit?
             HighLnSpr[y][0] |= 0x80;
             continue;
           }
-          HighLnSpr[y][1] += width;
+          HighLnSpr[y][2] += width;
 
           if (sx == -0x78) {
             if (cnt > 0)
@@ -1048,13 +1062,14 @@ found:;
             continue;
           }
           // must keep the first sprite even if it's offscreen, for masking
-          if (cnt > 0 && (sx <= sx_min || sx >= max_width)) continue; // offscreen x
+          if (cnt > 0 && !onscr_x) continue; // offscreen x
 
-          HighLnSpr[y][2+cnt] = entry;
+          HighLnSpr[y][3+cnt] = entry;
           HighLnSpr[y][0] = cnt + 1;
           if (entry & 0x80)
-               rendstatus |= PDRAW_HAVE_HI_SPR;
-          else rendstatus |= PDRAW_HAVE_LO_SPR;
+               HighLnSpr[y][1] |= SPRL_HAVE_HI;
+          else HighLnSpr[y][1] |= SPRL_HAVE_LO;
+          HighLnSpr[y][1] |= maybe_op|lo_above_hi; // there might be op sprites or priority mess on this line
         }
       }
 
@@ -1071,9 +1086,9 @@ found:;
     for (u = 0; u < max_lines; u++)
     {
       int y;
-      printf("c%03i: %2i, %2i: ", u, HighLnSpr[u][0] & 0x7f, HighLnSpr[u][1]);
+      printf("c%03i: %2i, %2i: ", u, HighLnSpr[u][0] & 0x7f, HighLnSpr[u][2]);
       for (y = 0; y < HighLnSpr[u][0] & 0x7f; y++)
-        printf(" %i", HighLnSpr[u][y+2]);
+        printf(" %i", HighLnSpr[u][y+3]);
       printf("\n");
     }
 #endif
@@ -1081,9 +1096,9 @@ found:;
 }
 
 #ifndef _ASM_DRAW_C
-static void DrawAllSprites(int prio, int sh)
+static void DrawAllSprites(unsigned char *sprited, int prio, int sh)
 {
-  int rs = rendstatus, scan = DrawScanline;
+  int rs = rendstatus;
   unsigned char *p;
   int cnt;
 
@@ -1093,10 +1108,10 @@ static void DrawAllSprites(int prio, int sh)
     rendstatus = rs & ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES);
   }
 
-  cnt = HighLnSpr[scan][0] & 0x7f;
+  cnt = sprited[0] & 0x7f;
   if (cnt == 0) return;
 
-  p = &HighLnSpr[scan][2];
+  p = &sprited[3];
 
   // Go through sprites backwards:
   for (cnt--; cnt >= 0; cnt--)
@@ -1289,13 +1304,14 @@ static void DrawBlankedLine(void)
 
 static int DrawDisplay(int sh, int as)
 {
+  unsigned char *sprited = &HighLnSpr[DrawScanline][0];
   struct PicoVideo *pvid=&Pico.video;
   int win=0,edge=0,hvwind=0;
-  int maxw, maxcells;
+  int maxw,maxcells;
 
   rendstatus &= ~(PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO);
 
-  if(pvid->reg[12]&1) {
+  if (pvid->reg[12]&1) {
     maxw = 328; maxcells = 40;
   } else {
     maxw = 264; maxcells = 32;
@@ -1308,7 +1324,8 @@ static int DrawDisplay(int sh, int as)
   if (win&0x80) { if (DrawScanline>=edge) hvwind=1; }
   else          { if (DrawScanline< edge) hvwind=1; }
 
-  if (!hvwind) { // we might have a vertical window here
+  if (!hvwind) // we might have a vertical window here
+  {
     win=pvid->reg[0x11];
     edge=win&0x1f;
     if (win&0x80) {
@@ -1321,28 +1338,48 @@ static int DrawDisplay(int sh, int as)
     }
   }
 
-  DrawLayer(1|((sh|as)<<1), HighCacheB, 0, maxcells);
-  if (hvwind == 1)
-    DrawWindow(0, maxcells>>1, 0, sh|as);
+  /* - layer B low - */
+  if (PicoDrawMask & PDRAW_LAYERB_ON)
+    DrawLayer(1|(sh<<1), HighCacheB, 0, maxcells);
+  /* - layer A low - */
+  if (!(PicoDrawMask & PDRAW_LAYERA_ON));
+  else if (hvwind == 1)
+    DrawWindow(0, maxcells>>1, 0, sh);
   else if (hvwind == 2) {
-    // ahh, we have vertical window
-    DrawLayer(0|((sh|as)<<1), HighCacheA, (win&0x80) ?    0 : edge<<1, (win&0x80) ?     edge<<1 : maxcells);
-    DrawWindow(                           (win&0x80) ? edge :       0, (win&0x80) ? maxcells>>1 : edge, 0, sh|as);
+    DrawLayer(0|(sh<<1), HighCacheA, (win&0x80) ?    0 : edge<<1, (win&0x80) ?     edge<<1 : maxcells);
+    DrawWindow(                      (win&0x80) ? edge :       0, (win&0x80) ? maxcells>>1 : edge, 0, sh);
   } else
-    DrawLayer(0|((sh|as)<<1), HighCacheA, 0, maxcells);
-  if (rendstatus & PDRAW_HAVE_LO_SPR)
-    DrawAllSpritesLoPri(0, sh);
-
-  if (HighCacheB[0]) DrawTilesFromCache(HighCacheB, sh, maxw);
-  if (hvwind == 1)
+    DrawLayer(0|(sh<<1), HighCacheA, 0, maxcells);
+  /* - sprites low - */
+  if (!(PicoDrawMask & PDRAW_SPRITES_LOW_ON));
+  else if (rendstatus & PDRAW_INTERLACE)
+    DrawAllSpritesInterlace(0, sh);
+  else if (sprited[1] & SPRL_HAVE_LO)
+    DrawAllSprites(sprited, 0, sh);
+
+  /* - layer B hi - */
+  if ((PicoDrawMask & PDRAW_LAYERB_ON) && HighCacheB[0])
+    DrawTilesFromCache(HighCacheB, sh, maxw);
+  /* - layer A hi - */
+  if (!(PicoDrawMask & PDRAW_LAYERA_ON));
+  else if (hvwind == 1)
     DrawWindow(0, maxcells>>1, 1, sh);
   else if (hvwind == 2) {
-    if(HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : maxw);
+    if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : maxw);
     DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh);
   } else
     if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, maxw);
-  if ((rendstatus & PDRAW_HAVE_HI_SPR) || sh)
-    DrawAllSpritesHiPri(1, sh);
+  /* - sprites hi - */
+  if (!(PicoDrawMask & PDRAW_SPRITES_HI_ON));
+  else if (rendstatus & PDRAW_INTERLACE)
+    DrawAllSpritesInterlace(1, sh);
+  // AS on and have both lo/hi sprites and lo before hi sprites?
+  else if (as && (sprited[1] & 0xd0) == 0xd0)
+    DrawSpritesHiAS(sprited, sh);
+  else if (sh && (sprited[1] & SPRL_MAY_HAVE_OP))
+    DrawSpritesSHi(sprited);
+  else if (sprited[1] & SPRL_HAVE_HI)
+    DrawAllSprites(sprited, 1, 0);
 
 #if 0
   {
@@ -1360,28 +1397,11 @@ static int DrawDisplay(int sh, int as)
 PICO_INTERNAL void PicoFrameStart(void)
 {
   // prepare to do this frame
-  int sh = Pico.video.reg[0xC] & 8; // shadow/hilight?
   rendstatus = 0;
   if (PicoOpt & POPT_ACC_SPRITES)
     rendstatus |= PDRAW_ACC_SPRITES;
-
-  if (sh)
-  {
-    DrawAllSpritesLoPri = DrawAllSprites;
-    DrawAllSpritesHiPri = DrawSpritesSHi;
-  }
-  else
-  {
-    DrawAllSpritesLoPri =
-    DrawAllSpritesHiPri = DrawAllSprites;
-  }
-  if (rendstatus & PDRAW_ACC_SPRITES)
-    DrawAllSpritesHiPri = DrawSpritesHiAS;
-  if ((Pico.video.reg[12]&6) == 6) {
+  if ((Pico.video.reg[12]&6) == 6)
     rendstatus |= PDRAW_INTERLACE; // interlace mode
-    DrawAllSpritesLoPri =
-    DrawAllSpritesHiPri = DrawAllSpritesInterlace;
-  }
 
   if (Pico.m.dirtyPal) Pico.m.dirtyPal = 2; // reset dirty if needed
 
@@ -1451,3 +1471,87 @@ void PicoDrawSetColorFormat(int which)
 #endif
 }
 
+/* debug and fun */
+static void set16(unsigned short *p, unsigned short d, int cnt)
+{
+  while (cnt-- > 0)
+    *p++ = d;
+}
+
+void PicoDrawShowSpriteStats(unsigned short *screen)
+{
+  int lines, i, u, step;
+  unsigned short *dest;
+  unsigned char *p;
+
+  memset(screen, 0, 320*240*2);
+  step = (320-4*4-1) / MAX_LINE_SPRITES;
+  lines = 240;
+  if (!Pico.m.pal || !(Pico.video.reg[1]&8))
+    lines = 224, screen += 320*8;
+
+  for (i = 0; i < lines; i++)
+  {
+    dest = screen + 320*i;
+    p = &HighLnSpr[i][0];
+
+    // sprite graphs
+    for (u = 0; u < (p[0] & 0x7f); u++) {
+      set16(dest, (p[3+u] & 0x80) ? 0xe700 : 0x0700, step);
+      dest += step;
+    }
+
+    // flags
+    dest = screen + 320*i + 320-4*4;
+    if (p[1] & SPRL_HAVE_LO)     set16(dest+4*0, 0x0700, 4);
+    if (p[1] & SPRL_HAVE_HI)     set16(dest+4*1, 0xe700, 4);
+    if (p[1] & SPRL_MAY_HAVE_OP) set16(dest+4*2, 0x001e, 4);
+    if (p[1] & SPRL_LO_ABOVE_HI) set16(dest+4*3, 0xf000, 4);
+  }
+
+  // draw grid
+  for (i = step*5; i <= 320-4*4-1; i += step*5) {
+    for (u = 0; u < lines; u++)
+      screen[i + u*320] = 0x182;
+  }
+}
+
+void PicoDrawShowPalette(unsigned short *screen)
+{
+  unsigned int *spal=(void *)Pico.cram;
+  unsigned int *dpal=(void *)HighPal;
+  int x, y, i;
+
+  memset(screen, 0, 320*240*2);
+
+  for (i = 0x3f/2; i >= 0; i--)
+#ifdef USE_BGR555
+    dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
+#else
+    dpal[i] = ((spal[i]&0x000f000f)<<12)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)>>7);
+#endif
+  for (i = 0x3f; i >= 0; i--)
+    HighPal[0x40|i] = (unsigned short)((HighPal[i]>>1)&0x738e);
+  for (i = 0x3f; i >= 0; i--) {
+    int t=HighPal[i]&0xe71c;t+=0x4208;if(t&0x20)t|=0x1c;if(t&0x800)t|=0x700;if(t&0x10000)t|=0xe000;t&=0xe71c;
+    HighPal[0x80|i]=(unsigned short)t;
+  }
+
+  screen += 16*320+8;
+  for (y = 0; y < 8*4; y++)
+    for (x = 0; x < 8*16; x++)
+      screen[x + y*320] = HighPal[x/8 + (y/8)*16];
+
+  screen += 160;
+  for (y = 0; y < 8*4; y++)
+    for (x = 0; x < 8*16; x++)
+      screen[x + y*320] = HighPal[(x/8 + (y/8)*16) | 0x40];
+
+  screen += 320*48;
+  for (y = 0; y < 8*4; y++)
+    for (x = 0; x < 8*16; x++)
+      screen[x + y*320] = HighPal[(x/8 + (y/8)*16) | 0x80];
+
+  Pico.m.dirtyPal = 1;
+}
+

+ 16 - 31
Pico/Draw.s

@@ -25,7 +25,6 @@
 .equ PDRAW_DIRTY_SPRITES, (1<<4)
 .equ PDRAW_PLANE_HI_PRIO, (1<<6)
 .equ PDRAW_SHHI_DONE,     (1<<7)
-.equ MAX_LINE_SPRITES,    30
 
 @ helper
 .macro TilePixel pat lsrr offs
@@ -947,26 +946,19 @@ DrawTilesFromCache:
 @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
 
-.global DrawSpritesSHi @ int prio_unused, int sh
+.global DrawSpritesSHi @ unsigned char *sprited
 
 DrawSpritesSHi:
-    ldr     r3, =DrawScanline
-    ldr     r2, =HighLnSpr
-    ldr     r12,[r3]
-    mov     r3, #(MAX_LINE_SPRITES+2)
-    mla     r2, r12, r3, r2
-    ldr     r3, [r2]
+    ldr     r3, [r0]
+    mov     r12,#0xff
     ands    r3, r3, #0x7f
     bxeq    lr
 
     stmfd   sp!, {r4-r11,lr}
-    mov     r12,#0xff
-    strb    r12,[r2,#1]     @ set end marker
-    add     r10,r2, #2
+    strb    r12,[r0,#2]     @ set end marker
+    add     r10,r0, #3      @ r10=HighLnSpr end
     add     r10,r10,r3      @ r10=HighLnSpr end
 
-    str     r1, [sp, #-4]   @ no calls after this point
-
 .if OVERRIDE_HIGHCOL
     ldr     r11,=HighCol
     mov     r12,#0xf
@@ -982,7 +974,7 @@ DrawSpriteSHi:
     @ draw next sprite
     ldrb    r0, [r10,#-1]!
     ldr     r1, =HighPreSpr
-    ldr     r8, [sp, #-4]
+@    ldr     r8, [sp, #-4]
     cmp     r0, #0xff
     ldmeqfd sp!, {r4-r11,pc} @ end of list
     and     r0, r0, #0x7f
@@ -994,12 +986,12 @@ DrawSpriteSHi:
     mov     r9, r9, lsl #16
     mov     r3, r9, lsr #31 @ priority
     mov     r9, r9, lsr #16
-    orr     r9, r9, r8, lsl #31 @ r9=code|sh[31]
+@    orr     r9, r9, r8, lsl #31 @ r9=code|sh[31]   @@ sh is always on here now
     and     r4, r9, #0x6000
     orr     r9, r9, r4, lsl #16
-    orr     r9, r9, #0x10000000 @ r9=scc1 ???? ... <code> (s=shadow/hilight, cc=pal)
+    orr     r9, r9, #0x90000000 @ r9=scc1 ???? ... <code> (s=shadow/hilight, cc=pal)
     cmp     r12,r9, lsr #28 @ sh/hi with pal3?
-    cmpne   r3, #1          @ if not, is hi prio
+    cmpne   r3, #1          @ if not, is ir hi prio?
     bne     DrawSpriteSHi   @ non-operator low sprite, already drawn
 
     ldr     r3, [r0]        @ sprite[0]
@@ -1030,8 +1022,6 @@ DrawSpriteSHi:
     add     r8, r8, r7, lsl #1 @ tile+=(row&7)<<1; // Tile address
 
     mov     r5, r5, lsl #4     @ delta<<=4; // Delta of address
-
-    orrs    r3, r9, r9, lsl #4
     mov     r3, r4, lsr #9     @ r3=pal=((code>>9)&0x30);
 
     add     r6, r6, #1         @ inc now
@@ -1136,36 +1126,31 @@ DrawSpriteSHi:
 
 @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
-.global DrawAllSprites @ int prio, int sh
+.global DrawAllSprites @ unsigned char *sprited, int prio, int sh
 
 DrawAllSprites:
     ldr     r3, =rendstatus
-    orr     r1, r1, r0, lsl #1
+    orr     r1, r2, r1, lsl #1
     ldr     r12,[r3]
     tst     r12,#(PDRAW_ACC_SPRITES|PDRAW_SPRITES_MOVED)
     beq     das_no_prep
-    stmfd   sp!, {r1,lr}
+    stmfd   sp!, {r0,r1,lr}
     and     r0, r12,#PDRAW_DIRTY_SPRITES
     bic     r12,r12,#(PDRAW_ACC_SPRITES|PDRAW_SPRITES_MOVED)
     str     r12,[r3]
     bl      PrepareSprites
-    ldmfd   sp!, {r1,lr}
+    ldmfd   sp!, {r0,r1,lr}
 
 das_no_prep:
-    ldr     r3, =DrawScanline
-    ldr     r2, =HighLnSpr
-    ldr     r12,[r3]
-    mov     r3, #(MAX_LINE_SPRITES+2)
-    mla     r2, r12, r3, r2
-    ldr     r3, [r2]
+    ldr     r3, [r0]
     ands    r3, r3, #0x7f
     bxeq    lr
 
     @ time to do some real work
     stmfd   sp!, {r4-r11,lr}
     mov     r12,#0xff
-    strb    r12,[r2,#1]     @ set end marker
-    add     r10,r2, #2
+    strb    r12,[r0,#2]     @ set end marker
+    add     r10,r0, #3
     add     r10,r10,r3      @ r10=HighLnSpr end
 
     str     r1, [sp, #-4]   @ no calls after this point

+ 1 - 2
Pico/Pico.c

@@ -375,8 +375,7 @@ char *debugString(void)
     else sprites_lo++;
 
   dstrp = dstr;
-  sprintf(dstrp, "mode set 1: %02x       spr lo[%c]: %2i, spr hi[%c]: %2i\n", (r=reg[0]),
-    rendstatus&PDRAW_HAVE_LO_SPR?'y':'n', sprites_lo, rendstatus&PDRAW_HAVE_HI_SPR?'y':'n', sprites_hi);
+  sprintf(dstrp, "mode set 1: %02x       spr lo: %2i, spr hi: %2i\n", (r=reg[0]), sprites_lo, sprites_hi);
   dstrp+=strlen(dstrp);
   sprintf(dstrp, "display_disable: %i, M3: %i, palette: %i, ?, hints: %i\n", bit(r,0), bit(r,1), bit(r,2), bit(r,4));
   dstrp+=strlen(dstrp);

+ 5 - 2
Pico/Pico.h

@@ -157,6 +157,11 @@ extern int (*PicoScanEnd)(unsigned int num);
 #ifdef _ASM_DRAW_C
 void vidConvCpyRGB565(void *to, void *from, int pixels);
 #endif
+extern int PicoDrawMask;
+#define PDRAW_LAYERB_ON      (1<<2)
+#define PDRAW_LAYERA_ON      (1<<3)
+#define PDRAW_SPRITES_LOW_ON (1<<4)
+#define PDRAW_SPRITES_HI_ON  (1<<7)
 // internals
 #define PDRAW_SPRITES_MOVED (1<<0) // (asm)
 #define PDRAW_WND_DIFF_PRIO (1<<1) // not all window tiles use same priority
@@ -166,8 +171,6 @@ void vidConvCpyRGB565(void *to, void *from, int pixels);
 #define PDRAW_SONIC_MODE    (1<<5) // mid-frame palette changes for 8bit renderer
 #define PDRAW_PLANE_HI_PRIO (1<<6) // have layer with all hi prio tiles (mk3)
 #define PDRAW_SHHI_DONE     (1<<7) // layer sh/hi already processed
-#define PDRAW_HAVE_LO_SPR   (1<<8)
-#define PDRAW_HAVE_HI_SPR   (1<<9)
 extern int rendstatus;
 extern unsigned short HighPal[0x100];
 

+ 40 - 4
platform/gp2x/menu.c

@@ -432,8 +432,10 @@ rescan:
 // ------------ debug menu ------------
 
 char *debugString(void);
+void PicoDrawShowSpriteStats(unsigned short *screen);
+void PicoDrawShowPalette(unsigned short *screen);
 
-static void draw_debug(void)
+static void draw_main_debug(void)
 {
 	char *p, *str = debugString();
 	int len, line;
@@ -450,13 +452,47 @@ static void draw_debug(void)
 		if (*p == 0) break;
 		p++; str = p;
 	}
-	menu_flip();
+}
+
+static void draw_frame_debug(void)
+{
+	char layer_str[48] = "layers:             ";
+	if (PicoDrawMask & PDRAW_LAYERB_ON)      memcpy(layer_str +  8, "B", 1);
+	if (PicoDrawMask & PDRAW_LAYERA_ON)      memcpy(layer_str + 10, "A", 1);
+	if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);
+	if (PicoDrawMask & PDRAW_SPRITES_HI_ON)  memcpy(layer_str + 19, "spr_hi", 6);
+
+	memset(gp2x_screen, 0, 320*240*2);
+	emu_forcedFrame();
+	smalltext_out16(4, 232, layer_str, 0xffff);
 }
 
 static void debug_menu_loop(void)
 {
-	draw_debug();
-	wait_for_input(GP2X_B|GP2X_X);
+	int inp, mode = 0;
+
+	while (1)
+	{
+		switch (mode)
+		{
+			case 0: draw_main_debug(); break;
+			case 1: draw_frame_debug(); break;
+			case 2: PicoDrawShowSpriteStats(gp2x_screen); break;
+			case 3: PicoDrawShowPalette(gp2x_screen); break;
+		}
+		menu_flip();
+
+		inp = wait_for_input(GP2X_B|GP2X_X|GP2X_L|GP2X_R|GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT);
+		if (inp & (GP2X_B|GP2X_X)) return;
+		if (inp & GP2X_L) { mode--; if (mode < 0) mode = 3; }
+		if (inp & GP2X_R) { mode++; if (mode > 3) mode = 0; }
+		if (mode == 1) {
+			if (inp & GP2X_LEFT)  PicoDrawMask ^= PDRAW_LAYERB_ON;
+			if (inp & GP2X_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;
+			if (inp & GP2X_DOWN)  PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;
+			if (inp & GP2X_UP)    PicoDrawMask ^= PDRAW_SPRITES_HI_ON;
+		}
+	}
 }
 
 // ------------ patch/gg menu ------------