Correctly render all-white screen (explosion flickering)
[mercenary-reloaded.git] / src / libvideo / video.c
index c48742f..55d4059 100644 (file)
@@ -27,6 +27,7 @@
 
 static void planar2chunky(uint8_t *rgb, uint8_t *bitplanes[], uint16_t palette[], int planes, int width, int y_start, int y_end)
 {
+       uint8_t red, green, blue;
        int x, y, p, b, i;
        uint8_t word[planes], chunk;
        uint16_t rgb4;
@@ -46,9 +47,15 @@ static void planar2chunky(uint8_t *rgb, uint8_t *bitplanes[], uint16_t palette[]
                                        word[p] <<= 1;
                                }
                                rgb4 = palette[chunk];
-                               *rgb++ = (rgb4 >> 4) & 0xf0;
-                               *rgb++ = rgb4 & 0xf0;
-                               *rgb++ = rgb4 << 4;
+                               red = (rgb4 >> 4) & 0xf0;
+                               green = rgb4 & 0xf0;
+                               blue = rgb4 << 4;
+                               red = red | (red >> 4);
+                               green = green | (green >> 4);
+                               blue = blue | (blue >> 4);
+                               *rgb++ = red;
+                               *rgb++ = green;
+                               *rgb++ = blue;
                        }
                        i++;
                }
@@ -83,6 +90,9 @@ static void planar2chunky2(uint8_t *rgb1, uint8_t *bitplanes[], uint16_t palette
                                red = (rgb4 >> 4) & 0xf0;
                                green = rgb4 & 0xf0;
                                blue = rgb4 << 4;
+                               red = red | (red >> 4);
+                               green = green | (green >> 4);
+                               blue = blue | (blue >> 4);
                                *rgb1++ = red;
                                *rgb1++ = green;
                                *rgb1++ = blue;
@@ -110,7 +120,7 @@ static void planar2chunky2(uint8_t *rgb1, uint8_t *bitplanes[], uint16_t palette
 #define BPL1PTH                0x0e0
 #define COLOR00                0x180
 
-void emul_video(uint8_t *rgb, uint8_t *memory, uint16_t render_palette[], int width, int height, int diwstart, uint16_t *io, int start, int stop, int double_size)
+int emul_video(uint8_t *rgb, uint8_t *memory, uint16_t render_palette[], int width, int height, int diwstart, uint16_t *io, int start, int stop, int double_size)
 {
        uint32_t bitplane[8] = {0, 0, 0, 0, 0, 0, 0, 0};
        uint8_t *bitmem[8];
@@ -122,9 +132,9 @@ void emul_video(uint8_t *rgb, uint8_t *memory, uint16_t render_palette[], int wi
        int i;
        int all_white;
 
-       /* special case where all palette entries are white. (unknown reason, maybe due to teleporter travel) */
+       /* special case where all palette entries are white, except for color 0 that is always black. (this happens during explosion) */
        all_white = 1;
-       for (i = 0; i < 16; i++) {
+       for (i = 1; i < 16; i++) {
                if (io[i * 2 + 0x180] != 0xfff)
                        all_white = 0;
        }
@@ -149,7 +159,7 @@ void emul_video(uint8_t *rgb, uint8_t *memory, uint16_t render_palette[], int wi
        copperlist = (io[COP1LCH] << 16) | io[COP1LCL];
        if (!copperlist) {
                print_error("Copper list pointer not initialized, please fix!\n");
-               return;
+               return all_white;
        }
 
 #ifdef DEBUG_COPPERLIST
@@ -163,7 +173,7 @@ void emul_video(uint8_t *rgb, uint8_t *memory, uint16_t render_palette[], int wi
        while (42) {
                if (++count == 100) {
                        print_error("Copper list does not seem to terminate, please fix!\n");
-                       return;
+                       return all_white;
                }
                c1 = m68k_read_memory_16(copperlist);
                c2 = m68k_read_memory_16(copperlist + 2);
@@ -239,7 +249,7 @@ void emul_video(uint8_t *rgb, uint8_t *memory, uint16_t render_palette[], int wi
                                        printf("\n");
 #endif
                                        print_error("Bitplane %d in copper list not set or out of range, please fix!\n", i);
-                                       return;
+                                       return all_white;
                                }
                                bitmem[i] = memory + bitplane[i];
                        }
@@ -279,4 +289,5 @@ void emul_video(uint8_t *rgb, uint8_t *memory, uint16_t render_palette[], int wi
                }
        }
 
+       return all_white;
 }