changeset 120:55b0a77af602

Clean up the format import code a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Jul 2018 17:44:47 +0300
parents ecc0e5148b47
children 25a29d29ee6a
files exporters.pde
diffstat 1 files changed, 46 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/exporters.pde	Mon Jul 09 11:30:01 2018 +0300
+++ b/exporters.pde	Mon Jul 09 17:44:47 2018 +0300
@@ -11,16 +11,16 @@
 int g_gridmode = OLD;
 
 
-void mpSetByte(int moffs, int toffs)
+void mpCopyByte(byte[] fdata, int moffs, int toffs)
 {
-    g_map[moffs    ] = byte((g_template[toffs] & 128) >> 7);
-    g_map[moffs + 1] = byte((g_template[toffs] & 64) >> 6);
-    g_map[moffs + 2] = byte((g_template[toffs] & 32) >> 5);
-    g_map[moffs + 3] = byte((g_template[toffs] & 16) >> 4);
-    g_map[moffs + 4] = byte((g_template[toffs] & 8) >> 3);
-    g_map[moffs + 5] = byte((g_template[toffs] & 4) >> 2);
-    g_map[moffs + 6] = byte((g_template[toffs] & 2) >> 1);
-    g_map[moffs + 7] = byte( g_template[toffs] & 1);
+    g_map[moffs    ] = byte((fdata[toffs] & 128) >> 7);
+    g_map[moffs + 1] = byte((fdata[toffs] & 64) >> 6);
+    g_map[moffs + 2] = byte((fdata[toffs] & 32) >> 5);
+    g_map[moffs + 3] = byte((fdata[toffs] & 16) >> 4);
+    g_map[moffs + 4] = byte((fdata[toffs] & 8) >> 3);
+    g_map[moffs + 5] = byte((fdata[toffs] & 4) >> 2);
+    g_map[moffs + 6] = byte((fdata[toffs] & 2) >> 1);
+    g_map[moffs + 7] = byte( fdata[toffs] & 1);
 }
 
 
@@ -47,14 +47,13 @@
     int x, y, x2, y2, y3, head, xx, yy, yp, ad, valu;
     int p1, p2, p3;
 
-    g_template = fdata;
     head = 0;
 
     if (machine == SPECTRUM) //SCR=SCREEN$
     {
         // 32*24*8 bytes of bitmap
         // 32*24 bytes of attributes
-        if (g_template.length < 6912) {
+        if (fdata.length < 6912) {
             return false;
         }
         for (y = 0; y < 3; y++)
@@ -64,7 +63,7 @@
         {
             yp = y * 64 + yy * 8 + y2;
             ad = 1024 + yp * 256 + x * 8;
-            mpSetByte(ad, head);
+            mpCopyByte(fdata, ad, head);
             head++;
         }
 
@@ -72,7 +71,7 @@
         for (x = 0; x < 32; x++)
         {
             ad = 65536 + x + y * (32 * 8);
-            valu = g_template[head];
+            valu = fdata[head];
             int ink = valu & 7;
             int pap = valu & 56;
             pap = pap >> 3;
@@ -96,11 +95,11 @@
         //0x0002->bitmap
         //0x1f42->colormap
         //0x232a=border (take the lower nybble)
-        if (g_template.length < 9006) {
+        if (fdata.length < 9006) {
             return false;
         }
-        if (g_template.length >= 0x232a) {
-            g_map[0] = byte(g_template[0x232a] & 0x0f);
+        if (fdata.length >= 0x232a) {
+            g_map[0] = byte(fdata[0x232a] & 0x0f);
         }
         for (y = 0; y < 25; y++)
         for (x = 0; x < 40; x++)
@@ -108,9 +107,9 @@
         {
             head = 2 + x * 8 + y * (40 * 8) + y2;
             ad = 1024 + x * 8 + y * (320 * 8) + y2 * 320;
-            mpSetByte(ad, head);
-            p1 = g_template[0x1f42 + x + y * 40] & 0x0f;
-            p2 = g_template[0x1f42 + x + y * 40] & 0xf0;
+            mpCopyByte(fdata, ad, head);
+            p1 = fdata[0x1f42 + x + y * 40] & 0x0f;
+            p2 = fdata[0x1f42 + x + y * 40] & 0xf0;
             p2 = p2 >> 4;
             g_map[65536 + x + y * 40 * 8 + y2 * 40] = byte(p2);
             g_map[65536 + MX * MY * 8 + x + y * 40 * 8 + y2 * 40] = byte(p1);
@@ -122,7 +121,7 @@
         //2 - luminance 40*25
         //1026 - colors 40*25
         //2050 - bitmappi 40*25*8
-        if (g_template.length < 10050) {
+        if (fdata.length < 10050) {
             return false;
         }
         int l1, l2;
@@ -132,13 +131,13 @@
         {
             head = 2050 + x * 8 + y * (40 * 8) + y2;
             ad = 1024 + x * 8 + y * (320 * 8) + y2 * 320;
-            mpSetByte(ad, head);
+            mpCopyByte(fdata, ad, head);
 
-            p1 = g_template[1026 + x + y * 40] & 0x0f;
-            p2 = g_template[1026 + x + y * 40] & 0xf0;
+            p1 = fdata[1026 + x + y * 40] & 0x0f;
+            p2 = fdata[1026 + x + y * 40] & 0xf0;
             p2 = p2 >> 4;
-            l1 = g_template[2 + x + y * 40] & 0x0f;
-            l2 = g_template[2 + x + y * 40] & 0xf0;
+            l1 = fdata[2 + x + y * 40] & 0x0f;
+            l2 = fdata[2 + x + y * 40] & 0xf0;
             l2 = l2 >> 4;
             g_map[65536 + x + y * 40 * 8 + y2 * 40] = byte(convertluminance(l1, p2));
             g_map[65536 + MX * MY * 8 + x + y * 40 * 8 + y2 * 40] = byte(convertluminance(l2, p1));
@@ -152,7 +151,7 @@
         //1025 - bäkki2
         //1026 - colors 40*25
         //2050 - bitmap 40*25*8
-        if (g_template.length < 10050) {
+        if (fdata.length < 10050) {
             return false;
         }
         int l1, l2;
@@ -162,24 +161,24 @@
         {
             head = 2050 + x * 8 + y * (40 * 8) + y2;
             ad = 1024 + x * 8 + y * (320 * 8) + y2 * 320;
-            mpSetByte(ad, head);
+            mpCopyByte(fdata, ad, head);
 
-            p1 = g_template[1026 + x + y * 40] & 0x0f;
-            p2 = g_template[1026 + x + y * 40] & 0xf0;
+            p1 = fdata[1026 + x + y * 40] & 0x0f;
+            p2 = fdata[1026 + x + y * 40] & 0xf0;
             p2 = p2 >> 4;
-            l1 = g_template[2 + x + y * 40] & 0x0f;
-            l2 = g_template[2 + x + y * 40] & 0xf0;
+            l1 = fdata[2 + x + y * 40] & 0x0f;
+            l2 = fdata[2 + x + y * 40] & 0xf0;
             l2 = l2 >> 4;
             g_map[65536 + x + y * 40 + 1000] = byte(convertluminance(l1, p2));
             g_map[65536 + x + y * 40 + 0000] = byte(convertluminance(l2, p1));
         }
 
-        p1 = int(g_template[1025]) & 0xf0;
-        l1 = int(g_template[1025]) & 0x0f;
+        p1 = int(fdata[1025]) & 0xf0;
+        l1 = int(fdata[1025]) & 0x0f;
         p1 = p1 >> 4;
         g_map[1] = byte(convertluminance(l1, p1));
-        p1 = int(g_template[1024]) & 0xf0;
-        l1 = int(g_template[1024]) & 0x0f;
+        p1 = int(fdata[1024]) & 0xf0;
+        l1 = int(fdata[1024]) & 0x0f;
         p1 = p1 >> 4;
         g_map[2] = byte(convertluminance(l1, p1));
     }
@@ -191,7 +190,7 @@
         //0x232a border
         //0x232b background
         //0x233a colors2 (40*25)
-        if (g_template.length < 10018) {
+        if (fdata.length < 10018) {
             return false;
         }
         for (y = 0; y < 25; y++)
@@ -201,24 +200,24 @@
             ad = 1024 + x * 8 + y * (320 * 8) + y2 * 320;
 
             head = 2 + x * 8 + y * (40 * 8) + y2;
-            mpSetByte(ad, head);
+            mpCopyByte(fdata, ad, head);
 
-            p1 = g_template[0x1f42 + x + y * 40] & 0x0f;
-            p2 = (g_template[0x1f42 + x + y * 40] >> 4) & 0x0f;
-            p3 = g_template[0x233a + x + y * 40] & 0x0f;
+            p1 = fdata[0x1f42 + x + y * 40] & 0x0f;
+            p2 = (fdata[0x1f42 + x + y * 40] >> 4) & 0x0f;
+            p3 = fdata[0x233a + x + y * 40] & 0x0f;
 
             g_map[65536 + x + y * 40] = byte(p1);
             g_map[65536 + x + y * 40 + 1000] = byte(p2);
             g_map[65536 + x + y * 40 + 2000] = byte(p3);
         }
-        g_map[0] = byte(g_template[0x232a] & 0x0f); //bord
-        g_map[1] = byte(g_template[0x232b] & 0x0f); //baku
+        g_map[0] = byte(fdata[0x232a] & 0x0f); //bord
+        g_map[1] = byte(fdata[0x232b] & 0x0f); //baku
     }
     else
     if (machine == MSX) { // sc2
         // 7=bitmap 32*24*8
         // 7+(32*24*8)=colormap 32*24
-        if (g_template.length < 14343) {
+        if (fdata.length < 14343) {
             return false;
         }
         for (y = 0; y < 24; y++)
@@ -227,9 +226,9 @@
         {
             head = 7 + x * 8 + y * (32 * 8) + y2;
             ad = 1024 + x * 8 + y * (256 * 8) + y2 * 256;
-            mpSetByte(ad, head);
-            p1 = g_template[(8199) + x * 8 + ((y * 8 * 32) + y2)] & 0x0f;
-            p2 = g_template[(8199) + x * 8 + ((y * 8 * 32) + y2)] & 0xf0;
+            mpCopyByte(fdata, ad, head);
+            p1 = fdata[(8199) + x * 8 + ((y * 8 * 32) + y2)] & 0x0f;
+            p2 = fdata[(8199) + x * 8 + ((y * 8 * 32) + y2)] & 0xf0;
             p2 = p2 >> 4;
             if (p1 == 0) {
                 p1 = 1;
@@ -384,7 +383,7 @@
     else
         return null;
 
-    return g_template;
+    return fdata;
 }