diff tools/lib64gfx.c @ 2132:6528a1398e8e

Add char map helper functions and use them.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 28 May 2019 10:32:12 +0300
parents 781b1d63109a
children b8491ee3cf24
line wrap: on
line diff
--- a/tools/lib64gfx.c	Tue May 28 07:25:20 2019 +0300
+++ b/tools/lib64gfx.c	Tue May 28 10:32:12 2019 +0300
@@ -1277,124 +1277,70 @@
 }
 
 
-static int fmtGetGenericSCPixel(Uint8 *col,
-    const DMC64Image *img, const int rasterX, const int rasterY)
+static int fmtGetGenericSCPixel(Uint8 *col, const DMC64Image *img,
+    const int rasterX, const int rasterY)
 {
     DM_C64_GENERIC_SC_PIXEL_DEFS(img)
 
     return dmC64GetGenericSCPixel(
-        col, img, bmoffs, scroffs, vshift, 0, 0);
+        col, img,
+        bmoffs, scroffs,
+        vshift, 0, 0);
 }
 
 
-static int fmtGetGenericMCPixel(Uint8 *col,
-    const DMC64Image *img, const int rasterX, const int rasterY)
+static int fmtGetGenericMCPixel(Uint8 *col, const DMC64Image *img,
+    const int rasterX, const int rasterY)
 {
     DM_C64_GENERIC_MC_PIXEL_DEFS(img)
 
     return dmC64GetGenericMCPixel(
-        col, img, bmoffs, scroffs, vshift, 0, 0, 0, img->bgcolor);
+        col, img,
+        bmoffs, scroffs,
+        vshift, 0,
+        0, 0, img->bgcolor);
 }
 
 
-static int fmtGetGenericCharSCPixel(Uint8 *col,
-    const DMC64Image *img, const int rasterX, const int rasterY)
+static int fmtGetGenericCharSCPixel(Uint8 *col, const DMC64Image *img,
+    const int rasterX, const int rasterY)
 {
-    const int
-        x = rasterX / 8,
-        y = rasterY / 8,
-        scroffs = y * img->fmt->chWidth + x,
-        vshift = 7 - (rasterX & 7),
-        chr = img->screen[0].data[scroffs];
+    DM_C64_GENERIC_CHAR_PIXEL(img)
+    const int chr = img->screen[0].data[scroffs];
 
-    const size_t chroffs = (chr * D64_CHR_SIZE) + (rasterY & 7);
-    if (chroffs >= img->charData[0].size)
-    {
-        return dmError(DMERR_INVALID_DATA,
-            "Character map index #%d out of bounds for char ROM data.\n",
-            chr);
-    }
-
-    if ((img->charData[0].data[chroffs] >> vshift) & 1)
-        *col = img->color[0].data[scroffs];
-    else
-        *col = img->bgcolor;
-
-    return DMERR_OK;
+    return dmC64GetGenericCharSCPixel(
+        col, img,
+        scroffs, rasterX,
+        0, (chr * D64_CHR_SIZE) + (rasterY & 7), chr,
+        0, img->bgcolor);
 }
 
 
-static int fmtGetGenericCharMCPixel(Uint8 *col,
-    const DMC64Image *img, const int rasterX, const int rasterY)
+static int fmtGetGenericCharMCPixel(Uint8 *col, const DMC64Image *img,
+    const int rasterX, const int rasterY)
 {
-    const int
-        y = rasterY / 8,
-        scroffs = y * img->fmt->chWidth + (rasterX / 8),
-        chr = img->screen[0].data[scroffs],
-        ccol = img->color[0].data[scroffs];
-
-    const size_t chroffs = (chr * D64_CHR_SIZE) + (rasterY & 7);
-    if (chroffs >= img->charData[0].size)
-    {
-        return dmError(DMERR_INVALID_DATA,
-            "Character map index #%d out of bounds for char ROM data.\n",
-            chr);
-    }
+    DM_C64_GENERIC_CHAR_PIXEL(img)
+    const int chr = img->screen[0].data[scroffs];
 
-    if (ccol & 8)
-    {
-        const int vshift = 6 - (rasterX & 6);
-        switch ((img->charData[0].data[chroffs] >> vshift) & 3)
-        {
-            case 0: *col = img->bgcolor; break;
-            case 1: *col = img->d022; break;
-            case 2: *col = img->d023; break;
-            case 3: *col = ccol & 15;
-        }
-    }
-    else
-    {
-        const int vshift = 7 - (rasterX & 7);
-        if ((img->charData[0].data[chroffs] >> vshift) & 1)
-            *col = ccol & 7;
-        else
-            *col = img->bgcolor;
-    }
-
-    return DMERR_OK;
+    return dmC64GetGenericCharMCPixel(
+        col, img,
+        scroffs, rasterX,
+        0, (chr * D64_CHR_SIZE) + (rasterY & 7), chr,
+        0, img->bgcolor, img->d022, img->d023);
 }
 
 
-static int fmtGetGenericCharECMPixel(Uint8 *col,
-    const DMC64Image *img, const int rasterX, const int rasterY)
+static int fmtGetGenericCharECMPixel(Uint8 *col, const DMC64Image *img,
+    const int rasterX, const int rasterY)
 {
-    const int
-        x = rasterX / 8,
-        y = rasterY / 8,
-        scroffs = y * img->fmt->chWidth + x,
-        vshift = 7 - (rasterX & 7),
-        chr = img->screen[0].data[scroffs];
+    DM_C64_GENERIC_CHAR_PIXEL(img)
+    const int chr = img->screen[0].data[scroffs];
 
-    const size_t chroffs = ((chr & 0x3f) * D64_CHR_SIZE) + (rasterY & 7);
-    if (chroffs >= img->charData[0].size)
-    {
-        return dmError(DMERR_INVALID_DATA,
-            "Character map index #%d out of bounds for char ROM data.\n",
-            chr);
-    }
-
-    if ((img->charData[0].data[chroffs] >> vshift) & 1)
-        *col = img->color[0].data[scroffs] & 15;
-    else
-    switch ((chr >> 6) & 3)
-    {
-        case 0: *col = img->bgcolor; break;
-        case 1: *col = img->d022; break;
-        case 2: *col = img->d023; break;
-        case 3: *col = img->d024; break;
-    }
-
-    return DMERR_OK;
+    return dmC64GetGenericCharECMPixel(
+        col, img,
+        scroffs, rasterX,
+        0, ((chr & 0x3f) * D64_CHR_SIZE) + (rasterY & 7), chr,
+        0, img->bgcolor, img->d022, img->d023, img->d024);
 }