remove some dead code
[picodrive.git] / pico / draw.c
index 5094e5c..ca9a140 100644 (file)
@@ -1,11 +1,11 @@
-// This is part of Pico Library\r
-\r
-// (c) Copyright 2004 Dave, All rights reserved.\r
-// (c) Copyright 2006-2008 notaz, All rights reserved.\r
-// Free for non-commercial use.\r
-\r
-// For commercial use, separate licencing terms must be obtained.\r
-\r
+/*\r
+ * line renderer\r
+ * (c) Copyright Dave, 2004\r
+ * (C) notaz, 2006-2010\r
+ *\r
+ * This work is licensed under the terms of MAME license.\r
+ * See COPYING file in the top-level directory.\r
+ */\r
 /*\r
  * The renderer has 4 modes now:\r
  * - normal\r
@@ -19,7 +19,7 @@
  *\r
  * since renderer always draws line in 8bit mode, there are 2 spare bits:\r
  * b \ mode: s/h             as        sonic\r
- * 00        normal          -         -\r
+ * 00        normal          -         pal index\r
  * 01        shadow          -         pal index\r
  * 10        hilight+op spr  spr       pal index\r
  * 11        shadow +op spr  -         pal index\r
@@ -1162,78 +1162,41 @@ unsigned short HighPal[0x100];
 void PicoDoHighPal555(int sh)\r
 {\r
   unsigned int *spal, *dpal;\r
-  unsigned short *pal=HighPal;\r
-  int i, t;\r
+  unsigned int t, i;\r
 \r
   Pico.m.dirtyPal = 0;\r
 \r
   spal = (void *)Pico.cram;\r
   dpal = (void *)HighPal;\r
 \r
-  for (i = 0; i < 0x40; i++) {\r
-    unsigned int t = spal[i];\r
+  for (i = 0; i < 0x40 / 2; i++) {\r
+    t = spal[i];\r
 #ifdef USE_BGR555\r
     t = ((t & 0x000e000e)<< 1) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)<<4);\r
 #else\r
     t = ((t & 0x000e000e)<<12) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)>>7);\r
 #endif\r
-    t |= (t >> 3) & 0x18e318e3;\r
+    // treat it like it was 4-bit per channel, since in s/h mode it somewhat is that.\r
+    // otherwise intensity difference between this and s/h will be wrong\r
+    t |= (t >> 4) & 0x08610861; // 0x18e318e3\r
     dpal[i] = t;\r
   }\r
 \r
+  // norm: xxx0, sh: 0xxx, hi: 0xxx + 7\r
   if (sh)\r
   {\r
     // shadowed pixels\r
-    for (i = 0x3f; i >= 0; i--)\r
-      pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x738e);\r
+    for (i = 0; i < 0x40 / 2; i++)\r
+      dpal[0x40/2 | i] = dpal[0xc0/2 | i] = (dpal[i] >> 1) & 0x738e738e;\r
     // hilighted pixels\r
-    for (i = 0x3f; i >= 0; i--) {\r
-      t=pal[i]&0xe71c;t+=0x4208;if(t&0x20)t|=0x1c;if(t&0x800)t|=0x700;if(t&0x10000)t|=0xe000;t&=0xe71c;\r
-      pal[0x80|i]=(unsigned short)t;\r
+    for (i = 0; i < 0x40 / 2; i++) {\r
+      t = ((dpal[i] >> 1) & 0x738e738e) + 0x738e738e; // 0x7bef7bef;\r
+      t |= (t >> 4) & 0x08610861;\r
+      dpal[0x80/2 | i] = t;\r
     }\r
   }\r
 }\r
 \r
-#if 0\r
-static void FinalizeLineBGR444(int sh, int line)\r
-{\r
-  unsigned short *pd=DrawLineDest;\r
-  unsigned char  *ps=HighCol+8;\r
-  unsigned short *pal=Pico.cram;\r
-  int len, i, t, mask=0xff;\r
-\r
-  if (Pico.video.reg[12]&1) {\r
-    len = 320;\r
-  } else {\r
-    if(!(PicoOpt&POPT_DIS_32C_BORDER)) pd+=32;\r
-    len = 256;\r
-  }\r
-\r
-  if(sh) {\r
-    pal=HighPal;\r
-    if(Pico.m.dirtyPal) {\r
-      blockcpy(pal, Pico.cram, 0x40*2);\r
-      // shadowed pixels\r
-      for(i = 0x3f; i >= 0; i--)\r
-        pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x0777);\r
-      // hilighted pixels\r
-      for(i = 0x3f; i >= 0; i--) {\r
-        t=pal[i]&0xeee;t+=0x444;if(t&0x10)t|=0xe;if(t&0x100)t|=0xe0;if(t&0x1000)t|=0xe00;t&=0xeee;\r
-        pal[0x80|i]=(unsigned short)t;\r
-      }\r
-      Pico.m.dirtyPal = 0;\r
-    }\r
-  }\r
-\r
-  if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI))\r
-    mask=0x3f; // accurate sprites\r
-\r
-  for(i = 0; i < len; i++)\r
-    pd[i] = pal[ps[i] & mask];\r
-}\r
-#endif\r
-\r
-\r
 void FinalizeLine555(int sh, int line)\r
 {\r
   unsigned short *pd=DrawLineDest;\r
@@ -1421,11 +1384,6 @@ PICO_INTERNAL void PicoFrameStart(void)
     lines = 240;\r
   }\r
 \r
-  HighCol = HighColBase + offs * HighColIncrement;\r
-  DrawLineDest = (char *)DrawLineDestBase + offs * DrawLineDestIncrement;\r
-  DrawScanline = 0;\r
-  skip_next_line = 0;\r
-\r
   if (rendstatus != rendstatus_old || lines != rendlines) {\r
     rendlines = lines;\r
     // mode_change() might reset rendstatus_old by calling SetColorFormat\r
@@ -1434,6 +1392,11 @@ PICO_INTERNAL void PicoFrameStart(void)
     rendstatus_old = rendstatus;\r
   }\r
 \r
+  HighCol = HighColBase + offs * HighColIncrement;\r
+  DrawLineDest = (char *)DrawLineDestBase + offs * DrawLineDestIncrement;\r
+  DrawScanline = 0;\r
+  skip_next_line = 0;\r
+\r
   if (PicoOpt & POPT_ALT_RENDERER)\r
     return;\r
 \r
@@ -1454,6 +1417,9 @@ static void DrawBlankedLine(int line, int offs, int sh, int bgc)
 \r
   if (PicoScanEnd != NULL)\r
     PicoScanEnd(line + offs);\r
+\r
+  HighCol += HighColIncrement;\r
+  DrawLineDest = (char *)DrawLineDest + DrawLineDestIncrement;\r
 }\r
 \r
 static void PicoLine(int line, int offs, int sh, int bgc)\r
@@ -1502,19 +1468,9 @@ void PicoDrawSync(int to, int blank_last_line)
 \r
   for (line = DrawScanline; line < to; line++)\r
   {\r
-#if !CAN_HANDLE_240_LINES\r
-    if (line >= 224) break;\r
-#endif\r
     PicoLine(line, offs, sh, bgc);\r
   }\r
 \r
-#if !CAN_HANDLE_240_LINES\r
-  if (line >= 224) {\r
-    DrawScanline = 240;\r
-    return;\r
-  }\r
-#endif\r
-\r
   // last line\r
   if (line <= to)\r
   {\r
@@ -1543,7 +1499,7 @@ void PicoDrawUpdateHighPal(void)
   }\r
 }\r
 \r
-void PicoDrawSetOutFormat(pdso_t which, int allow_32x)\r
+void PicoDrawSetOutFormat(pdso_t which, int use_32x_line_mode)\r
 {\r
   switch (which)\r
   {\r
@@ -1552,7 +1508,7 @@ void PicoDrawSetOutFormat(pdso_t which, int allow_32x)
       break;\r
 \r
     case PDF_RGB555:\r
-      if ((PicoAHW & PAHW_32X) && allow_32x)\r
+      if ((PicoAHW & PAHW_32X) && use_32x_line_mode)\r
         FinalizeLine = FinalizeLine32xRGB555;\r
       else\r
         FinalizeLine = FinalizeLine555;\r
@@ -1562,6 +1518,7 @@ void PicoDrawSetOutFormat(pdso_t which, int allow_32x)
       FinalizeLine = NULL;\r
       break;\r
   }\r
+  PicoDrawSetOutFormat32x(which, use_32x_line_mode);\r
   PicoDrawSetOutputMode4(which);\r
   rendstatus_old = -1;\r
 }\r
@@ -1587,3 +1544,19 @@ void PicoDrawSetInternalBuf(void *dest, int increment)
   }\r
 }\r
 \r
+void PicoDrawSetCallbacks(int (*begin)(unsigned int num), int (*end)(unsigned int num))\r
+{\r
+  PicoScanBegin = NULL;\r
+  PicoScanEnd = NULL;\r
+  PicoScan32xBegin = NULL;\r
+  PicoScan32xEnd = NULL;\r
+\r
+  if ((PicoAHW & PAHW_32X) && FinalizeLine != FinalizeLine32xRGB555) {\r
+    PicoScan32xBegin = begin;\r
+    PicoScan32xEnd = end;\r
+  }\r
+  else {\r
+    PicoScanBegin = begin;\r
+    PicoScanEnd = end;\r
+  }\r
+}\r