32x: packed pixel mode (works over 68k)
[picodrive.git] / pico / draw.c
index 8647a36..180045d 100644 (file)
@@ -78,7 +78,7 @@ void DrawAllSprites(unsigned char *sprited, int prio, int sh);
 void DrawTilesFromCache(int *hc, int sh, int rlim);\r
 void DrawSpritesSHi(unsigned char *sprited);\r
 void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells);\r
-void FinalizeLineBGR444(int sh);\r
+void FinalizeLineBGR444(int sh, int line);\r
 void *blockcpy(void *dst, const void *src, size_t n);\r
 void blockcpy_or(void *dst, void *src, size_t n, int pat);\r
 #else\r
@@ -1192,7 +1192,7 @@ void PicoDoHighPal555(int sh)
   }\r
 }\r
 \r
-static void FinalizeLineBGR444(int sh)\r
+static void FinalizeLineBGR444(int sh, int line)\r
 {\r
   unsigned short *pd=DrawLineDest;\r
   unsigned char  *ps=HighCol+8;\r
@@ -1230,7 +1230,7 @@ static void FinalizeLineBGR444(int sh)
 }\r
 \r
 \r
-void FinalizeLineRGB555(int sh)\r
+void FinalizeLineRGB555(int sh, int line)\r
 {\r
   unsigned short *pd=DrawLineDest;\r
   unsigned char  *ps=HighCol+8;\r
@@ -1266,7 +1266,7 @@ void FinalizeLineRGB555(int sh)
 }\r
 #endif\r
 \r
-static void FinalizeLine8bit(int sh)\r
+static void FinalizeLine8bit(int sh, int line)\r
 {\r
   unsigned char *pd = DrawLineDest;\r
   int len, rs = rendstatus;\r
@@ -1306,7 +1306,7 @@ static void FinalizeLine8bit(int sh)
   }\r
 }\r
 \r
-static void (*FinalizeLine)(int sh);\r
+static void (*FinalizeLine)(int sh, int line);\r
 \r
 // --------------------------------------------\r
 \r
@@ -1429,43 +1429,38 @@ PICO_INTERNAL void PicoFrameStart(void)
   PrepareSprites(1);\r
 }\r
 \r
-static void DrawBlankedLine(int line, int offs)\r
+static void DrawBlankedLine(int line, int offs, int sh, int bgc)\r
 {\r
-  int sh = (Pico.video.reg[0xC]&8)>>3; // shadow/hilight?\r
-\r
   if (PicoScanBegin != NULL)\r
     PicoScanBegin(line + offs);\r
 \r
-  BackFill(Pico.video.reg[7], sh);\r
+  BackFill(bgc, sh);\r
 \r
   if (FinalizeLine != NULL)\r
-    FinalizeLine(sh);\r
+    FinalizeLine(sh, line);\r
 \r
   if (PicoScanEnd != NULL)\r
     PicoScanEnd(line + offs);\r
 }\r
 \r
-static void PicoLine(int line, int offs)\r
+static void PicoLine(int line, int offs, int sh, int bgc)\r
 {\r
-  int sh;\r
   if (skip_next_line > 0) {\r
     skip_next_line--;\r
     return;\r
   }\r
 \r
-  sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight?\r
-\r
   DrawScanline = line;\r
   if (PicoScanBegin != NULL)\r
     skip_next_line = PicoScanBegin(line + offs);\r
 \r
   // Draw screen:\r
-  BackFill(Pico.video.reg[7], sh);\r
+  BackFill(bgc, sh);\r
   if (Pico.video.reg[1]&0x40)\r
     DrawDisplay(sh);\r
 \r
   if (FinalizeLine != NULL)\r
-    FinalizeLine(sh);\r
+    FinalizeLine(sh, line);\r
 \r
   if (PicoScanEnd != NULL)\r
     skip_next_line = PicoScanEnd(line + offs);\r
@@ -1474,16 +1469,22 @@ static void PicoLine(int line, int offs)
 void PicoDrawSync(int to, int blank_last_line)\r
 {\r
   int line, offs = 0;\r
+  int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight?\r
+  int bgc = Pico.video.reg[7];\r
 \r
   if (!(rendstatus & PDRAW_240LINES))\r
     offs = 8;\r
 \r
+  // need to know which pixels are bg for 32x\r
+  if (PicoAHW & PAHW_32X)\r
+    bgc = 0;\r
+\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);\r
+    PicoLine(line, offs, sh, bgc);\r
   }\r
 \r
 #if !CAN_HANDLE_240_LINES\r
@@ -1497,8 +1498,8 @@ void PicoDrawSync(int to, int blank_last_line)
   if (line <= to)\r
   {\r
     if (blank_last_line)\r
-         DrawBlankedLine(line, offs);\r
-    else PicoLine(line, offs);\r
+         DrawBlankedLine(line, offs, sh, bgc);\r
+    else PicoLine(line, offs, sh, bgc);\r
     line++;\r
   }\r
   DrawScanline = line;\r
@@ -1509,7 +1510,7 @@ void PicoDrawSetColorFormat(int which)
   switch (which)\r
   {\r
     case 2: FinalizeLine = FinalizeLine8bit;   break;\r
-    case 1: FinalizeLine = FinalizeLineRGB555; break;\r
+    case 1: FinalizeLine = (PicoAHW & PAHW_32X) ? FinalizeLine32xRGB555 : FinalizeLineRGB555; break;\r
     case 0: FinalizeLine = FinalizeLineBGR444; break;\r
     default:FinalizeLine = NULL; break;\r
   }\r