[libgens/tests] test_VdpPalette_DAC: Added 32X palette tests.
authorDavid Korth <gerbilsoft@gerbilsoft.com>
Sat, 5 Sep 2015 02:54:38 +0000 (22:54 -0400)
committerDavid Korth <gerbilsoft@gerbilsoft.com>
Sat, 5 Sep 2015 02:54:38 +0000 (22:54 -0400)
test_VdpPalette_DAC_generate.c: Added support for generating a
test file for 32X palettes.

src/libgens/tests/CMakeLists.txt
src/libgens/tests/test_VdpPalette_DAC.cpp
src/libgens/tests/test_VdpPalette_DAC.h
src/libgens/tests/test_VdpPalette_DAC_generate.c

index e2e3e85..81e510b 100644 (file)
@@ -57,6 +57,8 @@ ADD_TEST(NAME test_VdpPalette_DAC_generate_SMS
        COMMAND test_VdpPalette_DAC_generate --palmode SMS PalTest_SMS.txt)
 ADD_TEST(NAME test_VdpPalette_DAC_generate_GG
        COMMAND test_VdpPalette_DAC_generate --palmode GG PalTest_GG.txt)
+ADD_TEST(NAME test_VdpPalette_DAC_generate_32X
+       COMMAND test_VdpPalette_DAC_generate --palmode 32X PalTest_32X.txt)
 
 # Test the VDP DAC.
 ADD_TEST(NAME test_VdpPalette_DAC_MD
@@ -65,6 +67,8 @@ ADD_TEST(NAME test_VdpPalette_DAC_GG
        COMMAND test_VdpPalette_DAC PalTest_GG.txt)
 ADD_TEST(NAME test_VdpPalette_DAC_SMS
        COMMAND test_VdpPalette_DAC PalTest_SMS.txt)
+ADD_TEST(NAME test_VdpPalette_DAC_32X
+       COMMAND test_VdpPalette_DAC PalTest_32X.txt)
 
 # Sprite Masking & Overflow Test ROM.
 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
index d512c9b..2ca8224 100644 (file)
@@ -231,21 +231,19 @@ int Test_VdpPalette_DAC::exec(void)
                        // Palette mode.
                        // Format: PalMode:(string)mode
                        token = strtok(NULL, ":");
-                       if (!strcasecmp(token, PALTEST_PALMODE_MD))
+                       if (!strcasecmp(token, PALTEST_PALMODE_MD)) {
                                palMode = VdpPalette::PALMODE_MD;
-                       /* TODO
-                       else if (!strcasecmp(token, PALTEST_PALMODE_32X))
+                       } else if (!strcasecmp(token, PALTEST_PALMODE_32X)) {
                                palMode = VdpPalette::PALMODE_32X;
-                       */
-                       else if (!strcasecmp(token, PALTEST_PALMODE_SMS))
+                       } else if (!strcasecmp(token, PALTEST_PALMODE_SMS)) {
                                palMode = VdpPalette::PALMODE_SMS;
-                       else if (!strcasecmp(token, PALTEST_PALMODE_GG))
+                       } else if (!strcasecmp(token, PALTEST_PALMODE_GG)) {
                                palMode = VdpPalette::PALMODE_GG;
                        /* TODO
-                       else if (!strcasecmp(token, PALTEST_PALMODE_TMS9918))
+                       } else if (!strcasecmp(token, PALTEST_PALMODE_TMS9918)) {
                                palMode = VdpPalette::PALMODE_TMS9918;
                        */
-                       else {
+                       else {
                                PrintFail();
                                fprintf(m_f_out, "Unsupported PalMode: '%s'\n", token);
                                goto fail;
@@ -259,11 +257,10 @@ int Test_VdpPalette_DAC::exec(void)
                                        palMode_str = PALTEST_PALMODE_MD;
                                        m5m4bits = 3;   // Mode 5
                                        break;
-                               /* TODO
                                case VdpPalette::PALMODE_32X:
                                        palMode_str = PALTEST_PALMODE_32X;
+                                       m5m4bits = 3;   // Mode 5
                                        break;
-                               */
                                case VdpPalette::PALMODE_SMS:
                                        palMode_str = PALTEST_PALMODE_SMS;
                                        m5m4bits = 1;   // Mode 4
@@ -347,8 +344,10 @@ int Test_VdpPalette_DAC::exec(void)
                        // rgb15 and rgb16 are both 16-bit.
                        // rgb32 is 32-bit.
 
-                       uint16_t cram, rgb15, rgb16;
-                       uint32_t rgb32;
+                       // NOTE: Initializing values to 0xCC to work around
+                       // gcc compiler warnings.
+                       uint16_t cram = 0xCCCC, rgb15 = 0xCCCC, rgb16 = 0xCCCC;
+                       uint32_t rgb32 = 0xCCCCCCCC;
 
                        // Parse the data.
                        // TODO: Move validation into a common assertion function.
@@ -392,16 +391,25 @@ int Test_VdpPalette_DAC::exec(void)
                                        : 0x01
                                        );
 
-                       if (palMode == VdpPalette::PALMODE_SMS) {
-                               // SMS. Write 8-bit data to CRam.
-                               vdp15->writeCRam_8(0x01, (uint8_t)cram);
-                               vdp16->writeCRam_8(0x01, (uint8_t)cram);
-                               vdp32->writeCRam_8(0x01, (uint8_t)cram);
-                       } else {
-                               // Other system. Write 16-bit data to CRam.
-                               vdp15->writeCRam_16(0x02, cram);
-                               vdp16->writeCRam_16(0x02, cram);
-                               vdp32->writeCRam_16(0x02, cram);
+                       switch (palMode) {
+                               case VdpPalette::PALMODE_SMS:
+                                       // SMS. Write 8-bit data to CRam.
+                                       vdp15->writeCRam_8(0x01, (uint8_t)cram);
+                                       vdp16->writeCRam_8(0x01, (uint8_t)cram);
+                                       vdp32->writeCRam_8(0x01, (uint8_t)cram);
+                                       break;
+                               case VdpPalette::PALMODE_32X:
+                                       // 32X. Write to 32X CRam.
+                                       vdp15->writeCRam32X_16(0x02, cram);
+                                       vdp16->writeCRam32X_16(0x02, cram);
+                                       vdp32->writeCRam32X_16(0x02, cram);
+                                       break;
+                               default:
+                                       // Other system. Write 16-bit data to CRam.
+                                       vdp15->writeCRam_16(0x02, cram);
+                                       vdp16->writeCRam_16(0x02, cram);
+                                       vdp32->writeCRam_16(0x02, cram);
+                                       break;
                        }
 
                        // Update the VdpPalette objects.
@@ -410,9 +418,17 @@ int Test_VdpPalette_DAC::exec(void)
                        vdp32->update();
 
                        // Verify the RGB values.
-                       assertCRam(lineNum, 15, cram, rgb15, vdp15->m_palActive.u16[pal_entry]);
-                       assertCRam(lineNum, 16, cram, rgb16, vdp16->m_palActive.u16[pal_entry]);
-                       assertCRam(lineNum, 32, cram, rgb32, vdp32->m_palActive.u32[pal_entry]);
+                       if (palMode == VdpPalette::PALMODE_32X) {
+                               // 32X palette.
+                               assertCRam(lineNum, 15, cram, rgb15, vdp15->m_palActive32X.u16[pal_entry]);
+                               assertCRam(lineNum, 16, cram, rgb16, vdp16->m_palActive32X.u16[pal_entry]);
+                               assertCRam(lineNum, 32, cram, rgb32, vdp32->m_palActive32X.u32[pal_entry]);
+                       } else {
+                               // Standard palette.
+                               assertCRam(lineNum, 15, cram, rgb15, vdp15->m_palActive.u16[pal_entry]);
+                               assertCRam(lineNum, 16, cram, rgb16, vdp16->m_palActive.u16[pal_entry]);
+                               assertCRam(lineNum, 32, cram, rgb32, vdp32->m_palActive.u32[pal_entry]);
+                       }
                } else {
                        // Ignore this line.
                }
index 75d5426..d855c58 100644 (file)
@@ -4,7 +4,7 @@
  *                                                                         *
  * Copyright (c) 1999-2002 by St├ęphane Dallongeville.                      *
  * Copyright (c) 2003-2004 by St├ęphane Akhoun.                             *
- * Copyright (c) 2008-2011 by David Korth.                                 *
+ * Copyright (c) 2008-2015 by David Korth.                                 *
  *                                                                         *
  * This program is free software; you can redistribute it and/or modify it *
  * under the terms of the GNU General Public License as published by the   *
@@ -49,10 +49,12 @@ extern "C" {
 #define PALTEST_SHMODE_HIGHLIGHT "Highlight"
 
 // Palette modes.
-#define PALTEST_CMD_PALMODE "PalMode"
-#define PALTEST_PALMODE_MD "MD"
-#define PALTEST_PALMODE_SMS "SMS"
-#define PALTEST_PALMODE_GG "GG"
+#define PALTEST_CMD_PALMODE            "PalMode"
+#define PALTEST_PALMODE_MD             "MD"
+#define PALTEST_PALMODE_SMS            "SMS"
+#define PALTEST_PALMODE_GG             "GG"
+#define PALTEST_PALMODE_32X            "32X"
+#define PALTEST_PALMODE_TMS9918A       "TMS9918A"
 
 // Color entry.
 #define PALTEST_CMD_COLORENTRY "C"
index d7359c9..878563c 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.           *
  ***************************************************************************/
 
-/**
- * TODO:
- * - Add 32X and TMS9918 functions.
- */
+/** TODO: Add TMS9918 functions. **/
 
 #include "test_VdpPalette_DAC.h"
 
@@ -63,6 +60,11 @@ typedef enum {
 
 // TODO: Combine these functions together.
 
+/**
+ * Write palette test information for Sega Mega Drive.
+ * This includes shadow and highlight variants.
+ * @param filename Output filename.
+ */
 static int write_paltype_md(const char *filename)
 {
        static const uint8_t PalComponent_MD[16] =
@@ -172,6 +174,10 @@ static int write_paltype_md(const char *filename)
        return 0;
 }
 
+/**
+ * Write palette test information for Sega Master System.
+ * @param filename Output filename.
+ */
 static int write_paltype_sms(const char *filename)
 {
        static const uint8_t PalComponent_SMS[4] = {0x00, 0x55, 0xAA, 0xFF};
@@ -214,6 +220,10 @@ static int write_paltype_sms(const char *filename)
        return 0;
 }
 
+/**
+ * Write palette test information for Sega Game Gear.
+ * @param filename Output filename.
+ */
 static int write_paltype_gg(const char *filename)
 {
        unsigned int i;
@@ -232,6 +242,7 @@ static int write_paltype_gg(const char *filename)
        fprintf(f, "\n");
        for (i = 0x0000; i <= 0xFFFF; i++) {
                // Get the Game Gear color components.
+               // Game Gear uses XBGR4444.
                uint8_t r, g, b;
                uint16_t rgb555, rgb565;
                uint32_t rgb888;
@@ -259,6 +270,56 @@ static int write_paltype_gg(const char *filename)
        return 0;
 }
 
+/**
+ * Write palette test information for Sega 32X.
+ * @param filename Output filename.
+ */
+static int write_paltype_32x(const char *filename)
+{
+       unsigned int i;
+
+       FILE *f = fopen(filename, "w");
+       if (!f) {
+               fprintf(stderr, "Error opening file '%s': %s\n", filename, strerror(errno));
+               return -1;
+       }
+
+       // Write the file header.
+       fprintf(f, "%s:%04X\n", PALTEST_MAGIC, PALTEST_VERSION);
+       fprintf(f, "PalMode:%s\n", PALTEST_PALMODE_32X);
+
+       // Write the palette.
+       fprintf(f, "\n");
+       for (i = 0x0000; i <= 0xFFFF; i++) {
+               // Get the 32X color components.
+               // 32X uses XBGR1555.
+               uint8_t r, g, b;
+               uint16_t rgb555, rgb565;
+               uint32_t rgb888;
+
+               r = ((i << 3) & 0xF8);  r |= (r >> 5);
+               g = ((i >> 2) & 0xF8);  g |= (g >> 5);
+               b = ((i >> 7) & 0xF8);  b |= (b >> 5);
+
+               // Calculate the scaled RGB colors.
+               rgb555 = ((r & 0xF8) << 7) | ((g & 0xF8) << 2) | (b >> 3);
+               rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
+               rgb888 = (r << 16) | (g << 8) | b;
+
+               // Write the palette entry.
+               // Format: C:[CRAM]:[RGB555]:[RGB565]:[RGB888]
+               // - CRAM: Color RAM value. (16-bit for MD)
+               // - RGB555: 15-bit RGB value.
+               // - RGB565: 16-bit RGB value.
+               // - RGB888: 32-bit RGB value.
+               fprintf(f, "C:%04X:%04X:%04X:%06X\n",
+                       i, rgb555, rgb565, rgb888);
+       }
+
+       fclose(f);
+       return 0;
+}
+
 static void print_prg_info(void)
 {
        fprintf(stderr, "LibGens: VdpPalette tests: Data file generator.\n");
@@ -395,15 +456,17 @@ int main(int argc, char *argv[])
                // argument was specified, usage information
                // was printed. This isn't needed, since the
                // user can use the help options.
-               if (!strcasecmp(pal_mode_str, "MD")) {
+               if (!strcasecmp(pal_mode_str, PALTEST_PALMODE_MD)) {
                        palMode = PALMODE_MD;
-               } else if (!strcasecmp(pal_mode_str, "32X")) {
+               } else if (!strcasecmp(pal_mode_str, PALTEST_PALMODE_32X)) {
                        palMode = PALMODE_32X;
-               } else if (!strcasecmp(pal_mode_str, "SMS")) {
+               } else if (!strcasecmp(pal_mode_str, PALTEST_PALMODE_SMS)) {
                        palMode = PALMODE_SMS;
-               } else if (!strcasecmp(pal_mode_str, "GG")) {
+               } else if (!strcasecmp(pal_mode_str, PALTEST_PALMODE_GG)) {
                        palMode = PALMODE_GG;
-               } else if (!strcasecmp(pal_mode_str, "TMS9918")) {
+               } else if (!strcasecmp(pal_mode_str, PALTEST_PALMODE_TMS9918A) ||
+                          !strcasecmp(pal_mode_str, "TMS9918"))
+               {
                        palMode = PALMODE_TMS9918A;
                } else {
                        // Invalid palette mode.
@@ -448,11 +511,12 @@ int main(int argc, char *argv[])
                        ret = write_paltype_gg(out_filename);
                        break;
                case PALMODE_32X:
+                       ret = write_paltype_32x(out_filename);
+                       break;
                case PALMODE_TMS9918A:
                default:
                        // Unsupported right now.
-                       fprintf(stderr, "%s: error: palette mode '%s' isn't supported yet.\n",
-                               argv[0], (palMode == PALMODE_32X ? "32X" : "TMS9918"));
+                       fprintf(stderr, "%s: error: palette mode 'tms9918' isn't supported yet.\n", argv[0]);
                        return EXIT_FAILURE;
        }