changeset 84:025efefd1704

Rename few functions and a variable.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Jul 2018 23:43:28 +0300
parents 6524e83c3ba7
children db97aef4e159
files exporters.pde multipaint.pde
diffstat 2 files changed, 147 insertions(+), 140 deletions(-) [+]
line wrap: on
line diff
--- a/exporters.pde	Thu Jul 05 23:19:14 2018 +0300
+++ b/exporters.pde	Thu Jul 05 23:43:28 2018 +0300
@@ -4,26 +4,46 @@
 // remember hexdump -C !
 
 String g_formatname, g_formatext;
-int g_headpos;
+int g_dataoffs;
 int[] g_grids = new int[16];
 int OLD = 0;
 int NEW = 1;
 int g_gridmode = OLD;
 
 
-void pushbyte(int ad, int head) {
-    g_map[ad    ] = byte((g_template[head] & 128) >> 7);
-    g_map[ad + 1] = byte((g_template[head] & 64) >> 6);
-    g_map[ad + 2] = byte((g_template[head] & 32) >> 5);
-    g_map[ad + 3] = byte((g_template[head] & 16) >> 4);
-    g_map[ad + 4] = byte((g_template[head] & 8) >> 3);
-    g_map[ad + 5] = byte((g_template[head] & 4) >> 2);
-    g_map[ad + 6] = byte((g_template[head] & 2) >> 1);
-    g_map[ad + 7] = byte( g_template[head] & 1);
+void mpSetByte(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);
 }
 
 
-bool format_import(byte[] fhd) {
+void mpSetDataOffs(int offs)
+{
+    g_dataoffs = offs;
+}
+
+
+void mpWriteByte(int bb)
+{
+    g_template[g_dataoffs++] = byte(bb);
+}
+
+
+void mpLoadTemplate(String fname)
+{
+    g_template = mpLoadBinaryFile("templates/" + fname);
+}
+
+
+bool mpImportFormat(byte[] fdata)
+{
     int x, y, x2, y2, y3, head, xx, yy, yp, ad, valu;
     int p1, p2, p3;
     head = 0;
@@ -45,7 +65,7 @@
         {
             yp = y * 64 + yy * 8 + y2;
             ad = 1024 + yp * 256 + x * 8;
-            pushbyte(ad, head);
+            mpSetByte(ad, head);
             head++;
         }
 
@@ -89,7 +109,7 @@
         {
             head = 2 + x * 8 + y * (40 * 8) + y2;
             ad = 1024 + x * 8 + y * (320 * 8) + y2 * 320;
-            pushbyte(ad, head);
+            mpSetByte(ad, head);
             p1 = g_template[0x1f42 + x + y * 40] & 0x0f;
             p2 = g_template[0x1f42 + x + y * 40] & 0xf0;
             p2 = p2 >> 4;
@@ -113,7 +133,7 @@
                 for (y2 = 0; y2 <= 7; y2++) {
                     head = 2050 + x * 8 + y * (40 * 8) + y2;
                     ad = 1024 + x * 8 + y * (320 * 8) + y2 * 320;
-                    pushbyte(ad, head);
+                    mpSetByte(ad, head);
 
                     p1 = g_template[1026 + x + y * 40] & 0x0f;
                     p2 = g_template[1026 + x + y * 40] & 0xf0;
@@ -146,7 +166,7 @@
                 for (y2 = 0; y2 <= 7; y2++) {
                     head = 2050 + x * 8 + y * (40 * 8) + y2;
                     ad = 1024 + x * 8 + y * (320 * 8) + y2 * 320;
-                    pushbyte(ad, head);
+                    mpSetByte(ad, head);
 
                     p1 = g_template[1026 + x + y * 40] & 0x0f;
                     p2 = g_template[1026 + x + y * 40] & 0xf0;
@@ -186,7 +206,7 @@
                     ad = 1024 + x * 8 + y * (320 * 8) + y2 * 320;
 
                     head = 2 + x * 8 + y * (40 * 8) + y2;
-                    pushbyte(ad, head);
+                    mpSetByte(ad, head);
 
                     p1 = g_template[0x1f42 + x + y * 40] & 0x0f;
                     p2 = (g_template[0x1f42 + x + y * 40] >> 4) & 0x0f;
@@ -214,7 +234,7 @@
                 for (y2 = 0; y2 <= 7; y2++) {
                     head = 7 + x * 8 + y * (32 * 8) + y2;
                     ad = 1024 + x * 8 + y * (256 * 8) + y2 * 256;
-                    pushbyte(ad, head);
+                    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;
                     p2 = p2 >> 4;
@@ -249,45 +269,45 @@
     int y, y2, yy, x, yp, xp, ad, valu, valu2, bri;
 
     if (machine == PLUS4) { // botticelli hires
-        load_template("g.hires.prg");
-        set_head(0x02);
-        colorexport(40, 25, 65536, 5); //lumis
-        set_head(1026);
-        colorexport(40, 25, 65536, 4); //colors
-        set_head(2050);
+        mpLoadTemplate("g.hires.prg");
+        mpSetDataOffs(0x02);
+        mpExportColorData(40, 25, 65536, 5); //lumis
+        mpSetDataOffs(1026);
+        mpExportColorData(40, 25, 65536, 4); //colors
+        mpSetDataOffs(2050);
         bitmapexport(40, 25);
         export_program(fname);
     }
     else
     if (machine == PLUS4M) { // multi botticelli multicolor
-        load_template("m.multi.prg");
+        mpLoadTemplate("m.multi.prg");
         val2 = getpluscolor(int(g_map[1]));
         val1 = getplusluminance(int(g_map[1]));
         val3 = val2 * 16 + val1;
-        set_head(1025);
-        write_head(val3);
+        mpSetDataOffs(1025);
+        mpWriteByte(val3);
         val2 = getpluscolor(int(g_map[2]));
         val1 = getplusluminance(int(g_map[2]));
         val3 = val2 * 16 + val1;
-        set_head(1024);
-        write_head(val3);
-        set_head(1026);
-        colorexport(40, 25, 65536, 6); //colors
-        set_head(2);
-        colorexport(40, 25, 65536, 7); //lumis
-        set_head(2050);
+        mpSetDataOffs(1024);
+        mpWriteByte(val3);
+        mpSetDataOffs(1026);
+        mpExportColorData(40, 25, 65536, 6); //colors
+        mpSetDataOffs(2);
+        mpExportColorData(40, 25, 65536, 7); //lumis
+        mpSetDataOffs(2050);
         bitmapexport(40, 25);
         export_program(fname);
     }
     else
     if (machine == C64) {
-        load_template("hires.art");
-        set_head(2);
+        mpLoadTemplate("hires.art");
+        mpSetDataOffs(2);
         bitmapexport(40, 25);
-        set_head(0x1f42);
-        colorexport(40, 25, 65536, 0);
-        set_head(0x232a);
-        write_head(int(g_map[0]));
+        mpSetDataOffs(0x1f42);
+        mpExportColorData(40, 25, 65536, 0);
+        mpSetDataOffs(0x232a);
+        mpWriteByte(int(g_map[0]));
         export_program(fname);
     }
     else
@@ -295,46 +315,46 @@
         if (fname.indexOf(".kla") >= 0)
         {
             // Koala Painter
-            load_template("multic.kla");
-            set_head(2);
+            mpLoadTemplate("multic.kla");
+            mpSetDataOffs(2);
             bitmapexport(40, 25);
-            set_head(0x1f42);
-            colorexport(40, 25, 65536, 1);
-            set_head(0x232a);
-            colorexport(40, 25, 65536 + 2000, 2);
-            set_head(0x2712);
-            write_head(int(g_map[1] & 0x0f));
+            mpSetDataOffs(0x1f42);
+            mpExportColorData(40, 25, 65536, 1);
+            mpSetDataOffs(0x232a);
+            mpExportColorData(40, 25, 65536 + 2000, 2);
+            mpSetDataOffs(0x2712);
+            mpWriteByte(int(g_map[1] & 0x0f));
         }
         else
         {
             // Advanced Art Studio
-            load_template("multic.ocp");
-            set_head(2);
+            mpLoadTemplate("multic.ocp");
+            mpSetDataOffs(2);
             bitmapexport(40, 25);
-            set_head(0x1f42);
-            colorexport(40, 25, 65536, 1);
-            set_head(0x233a);
-            colorexport(40, 25, 65536 + 2000, 2);
-            set_head(0x232a);
-            write_head(int(g_map[0]));
-            set_head(0x232b);
-            write_head(int(g_map[1]));
+            mpSetDataOffs(0x1f42);
+            mpExportColorData(40, 25, 65536, 1);
+            mpSetDataOffs(0x233a);
+            mpExportColorData(40, 25, 65536 + 2000, 2);
+            mpSetDataOffs(0x232a);
+            mpWriteByte(int(g_map[0]));
+            mpSetDataOffs(0x232b);
+            mpWriteByte(int(g_map[1]));
         }
         export_program(fname);
     }
     else
     if (machine == MSX) {
-        load_template("msx-screen2.sc2");
-        set_head(7);
+        mpLoadTemplate("msx-screen2.sc2");
+        mpSetDataOffs(7);
         bitmapexport(32, 24);
-        set_head(7 + (32 * 24 * 8) + 768 + 1280);
-        colorexport(32, 24, 65536, 3); //there's an exception for msx-style
+        mpSetDataOffs(7 + (32 * 24 * 8) + 768 + 1280);
+        mpExportColorData(32, 24, 65536, 3); //there's an exception for msx-style
         export_program(fname);
     }
     else
     if (machine == SPECTRUM) {
-        load_template("zx-screen.scr");
-        set_head(0);
+        mpLoadTemplate("zx-screen.scr");
+        mpSetDataOffs(0);
         for (y = 0; y < 3; y++)
         for (y2 = 0; y2 < 8; y2++)
         for (yy = 0; yy < 8; yy++)
@@ -352,7 +372,7 @@
                    g_map[ad + 6] * 2 +
                    g_map[ad + 7] * 1;
 
-            write_head(int(valu));
+            mpWriteByte(int(valu));
         }
 
         for (y = 0; y < 24; y++)
@@ -372,7 +392,7 @@
             if (bri == 1) {
                 valu += 64;
             }
-            write_head(int(valu + valu2 * 8));
+            mpWriteByte(int(valu + valu2 * 8));
         }
         export_program(fname);
     }
@@ -399,16 +419,16 @@
 
     if (machine == C64) { //C64 HIRES
 
-        load_template("c64show.prg");
-        set_head(0X0227);
+        mpLoadTemplate("c64show.prg");
+        mpSetDataOffs(0X0227);
         bitmapexport(40, 25);
-        set_head(0X2167);
-        write_head(g_map[0]); //=border
-        set_head(0X2168);
-        write_head(g_map[1]); //=background mutta ei tarvita
-        set_head(0X2169);
+        mpSetDataOffs(0X2167);
+        mpWriteByte(g_map[0]); //=border
+        mpSetDataOffs(0X2168);
+        mpWriteByte(g_map[1]); //=background mutta ei tarvita
+        mpSetDataOffs(0X2169);
         outputter("; The following two first values are border and background", true);
-        colorexport(40, 25, 65536, 0);
+        mpExportColorData(40, 25, 65536, 0);
         export_program(fname);
 
         //c64show.prg
@@ -420,23 +440,23 @@
 
     if (machine == C64M) { //C64 MULTICOLOR
 
-        load_template("c64mshow.prg");
-        set_head(0x0239);
+        mpLoadTemplate("c64mshow.prg");
+        mpSetDataOffs(0x0239);
         bitmapexport(40, 25);
 
         // first color information
-        set_head(0x2179);
-        write_head(g_map[0]);
-        set_head(0x217A);
-        write_head(g_map[1]);
-        set_head(0x217B);
+        mpSetDataOffs(0x2179);
+        mpWriteByte(g_map[0]);
+        mpSetDataOffs(0x217A);
+        mpWriteByte(g_map[1]);
+        mpSetDataOffs(0x217B);
         outputter("; The following two first values are border and background", true);
-        colorexport(40, 25, 65536, 1);
+        mpExportColorData(40, 25, 65536, 1);
 
         // second color information
-        set_head(0x2563);
+        mpSetDataOffs(0x2563);
         outputter("; The following goes to $D800 onwards", true);
-        colorexport(40, 25, 65536 + 2000, 2);
+        mpExportColorData(40, 25, 65536 + 2000, 2);
         export_program(fname);
 
         //c64 multicolor
@@ -449,7 +469,7 @@
     }
 
     if (machine == PLUS4M) { //PLUS4 MULTICOLOR
-        load_template("showpfourm.prg");
+        mpLoadTemplate("showpfourm.prg");
         outputter("  .global _bitmap", true);
         outputter("  .global _color1", true);
         outputter("  .global _color2", true);
@@ -457,35 +477,35 @@
         outputter("  .global _back1", true);
         outputter("  .global _back2", true);
         outputter("_bitmap:", true);
-        set_head(0x013e);
+        mpSetDataOffs(0x013e);
         bitmapexport(40, 25);
         outputter("_border:", true);
         val1 = getpluscolor(int(g_map[0]));
         val2 = getplusluminance(int(g_map[0]));
         val3 = val2 * 16 + val1;
-        set_head(0x207e);
-        write_head(val3);
+        mpSetDataOffs(0x207e);
+        mpWriteByte(val3);
         outputter("  .byte " + val3, true);
         outputter("_back1:", true);
         val1 = getpluscolor(int(g_map[1]));
         val2 = getplusluminance(int(g_map[1]));
         val3 = val2 * 16 + val1;
-        set_head(0x207f);
-        write_head(val3);
+        mpSetDataOffs(0x207f);
+        mpWriteByte(val3);
         outputter("  .byte " + val3, true);
         outputter("_back2:", true);
         val1 = getpluscolor(int(g_map[2]));
         val2 = getplusluminance(int(g_map[2]));
         val3 = val2 * 16 + val1;
-        set_head(0x2080);
-        write_head(val3);
+        mpSetDataOffs(0x2080);
+        mpWriteByte(val3);
         outputter("  .byte " + val3, true);
         outputter("_color1:", true);
-        set_head(0x2081);
-        colorexport(40, 25, 65536, 6);
+        mpSetDataOffs(0x2081);
+        mpExportColorData(40, 25, 65536, 6);
         outputter("_color2:", true);
-        set_head(0x2469);
-        colorexport(40, 25, 65536, 7);
+        mpSetDataOffs(0x2469);
+        mpExportColorData(40, 25, 65536, 7);
         export_program(fname);
         //plus4 multic
         //0x013e bitmap (40 x 25 x 8)
@@ -497,24 +517,24 @@
     }
 
     if (machine == PLUS4) { // Plus 4 hires
-        load_template("showpfour.prg");
+        mpLoadTemplate("showpfour.prg");
         outputter("  .global _bitmap", true);
         outputter("  .global _color", true);
         outputter("  .global _lumi", true);
         outputter("  .global _border", true);
         outputter("_bitmap:", true);
-        set_head(0x0137);
+        mpSetDataOffs(0x0137);
         bitmapexport(40, 25);
         val1 = getpluscolor(int(g_map[0]));
         val2 = getplusluminance(int(g_map[0]));
         val3 = val2 * 16 + val1;
-        set_head(0x2077);
-        write_head(val3); //border
+        mpSetDataOffs(0x2077);
+        mpWriteByte(val3); //border
 
-        set_head(0x2078);
-        colorexport(40, 25, 65536, 4); //colors
-        set_head(0x2460);
-        colorexport(40, 25, 65536, 5); //lumis
+        mpSetDataOffs(0x2078);
+        mpExportColorData(40, 25, 65536, 4); //colors
+        mpSetDataOffs(0x2460);
+        mpExportColorData(40, 25, 65536, 5); //lumis
         export_program(fname);
         //plus4 hires
         //0x0137   bitmap (40 x 25 x 8)
@@ -524,17 +544,17 @@
     }
 
     if (machine == MSX) { // MSX
-        load_template("msxshow.com");
-        set_head(0x00f9);
+        mpLoadTemplate("msxshow.com");
+        mpSetDataOffs(0x00f9);
         outputter(char(9) + ".globl _nimi1,_nimi2", true);
         outputter(char(9) + ".area _CODE", true);
         outputter("_nimi1:", true);
         bitmapexport(32, 24);
-        set_head(0x18f9);
-        //write_head(g_map[1]); //backg
+        mpSetDataOffs(0x18f9);
+        //mpWriteByte(g_map[1]); //backg
         //outputter("; The first following value is background", true);
         outputter("_nimi2:", true);
-        colorexport(32, 24, 65536, 3); //there's an exception for msx-style
+        mpExportColorData(32, 24, 65536, 3); //there's an exception for msx-style
         export_program(fname);
         //msx comm
         //0x00f9 bitmap (32x24 x 8 bytes)
@@ -550,7 +570,7 @@
         //  outputter("  .globl _taustakuva",true);
         //  outputter("",true);
         //  outputter("_taustakuva:",true);
-        load_template("specshow.tap");
+        mpLoadTemplate("specshow.tap");
         int stad;
 
         checksum = 0xc9;
@@ -559,9 +579,9 @@
         }
         //TAP requires fiddling with the checksum
         //println("Checksum:"+hex(checksum,2));
-        set_head(0x0223);
+        mpSetDataOffs(0x0223);
         outputter(".byte " + (str(g_map[0])) + " ;border", true);
-        write_head(int(g_map[0]));
+        mpWriteByte(int(g_map[0]));
         checksum = checksum ^ int(g_map[0]);
         for (y = 0; y <= 2; y++) {
             for (y2 = 0; y2 <= 7; y2++) {
@@ -575,7 +595,7 @@
                         valu = g_map[ad + 0] * 128 + g_map[ad + 1] * 64 + g_map[ad + 2] * 32 + g_map[ad + 3] * 16 + g_map[ad + 4] * 8 + g_map[ad + 5] * 4 + g_map[ad + 6] * 2 + g_map[ad + 7] * 1;
                         outputter(str(int(valu)), false);
                         by++;
-                        write_head(int(valu));
+                        mpWriteByte(int(valu));
                         checksum = checksum ^ int(valu);
                         if (x <= 30) {
                             outputter(",", false);
@@ -607,7 +627,7 @@
                 }
                 outputter(str(valu + valu2 * 8), false);
                 by++;
-                write_head(int(valu + valu2 * 8));
+                mpWriteByte(int(valu + valu2 * 8));
                 checksum = checksum ^ int(valu + valu2 * 8);
                 if (x <= 30) {
                     outputter(",", false);
@@ -616,24 +636,24 @@
             outputter("", true);
         }
         //println("checksum:"+hex(checksum,2));
-        set_head(0x1d3e);
-        write_head(int(checksum));
+        mpSetDataOffs(0x1d3e);
+        mpWriteByte(int(checksum));
         export_program(fname);
     }
 
     if (machine == CPC) {
-        load_template("cpc-mode0.bin");
+        mpLoadTemplate("cpc-mode0.bin");
 
-        set_head(69); //bitmap offset
+        mpSetDataOffs(69); //bitmap offset
         bitmapexport_cpc(160, 200);
-        set_head(16453);
+        mpSetDataOffs(16453);
         outputter(";palette", true);
         outputter(".byte ", false);
         for (int i = 0; i < g_maxcolors; i++) { //fixed # of palette entries, just trying to be generic
             val1 = int(g_g[i] / (256 / g_palsteps));
             val2 = int(g_r[i] / (256 / g_palsteps));
             val3 = int(g_b[i] / (256 / g_palsteps));
-            write_head(val1 * 9 + val2 * 3 + val3);
+            mpWriteByte(val1 * 9 + val2 * 3 + val3);
             outputter(str(val1 * 9 + val2 * 3 + val3), false);
             if (i < g_maxcolors - 1) {
                 outputter(",", false);
@@ -642,12 +662,12 @@
         outputter("", true);
         outputter(";border", true);
         outputter(".byte ", false);
-        set_head(16469);
+        mpSetDataOffs(16469);
         valu = int(g_map[0]);
         val1 = int(g_g[valu] / (256 / g_palsteps));
         val2 = int(g_r[valu] / (256 / g_palsteps));
         val3 = int(g_b[valu] / (256 / g_palsteps));
-        write_head(val1 * 9 + val2 * 3 + val3);
+        mpWriteByte(val1 * 9 + val2 * 3 + val3);
         outputter(str(val1 * 9 + val2 * 3 + val3), false);
         //cpc
         //69    bitmap 16384 bytes
@@ -700,7 +720,7 @@
 
                 val2 = pix1b3 + pix0b3 * 2 + pix1b1 * 4 + pix0b1 * 8 + pix1b2 * 16 + pix0b2 * 32 + pix1b0 * 64 + pix0b0 * 128;
                 outputter(str(int(val2)), false);
-                write_head(val2);
+                mpWriteByte(val2);
                 pp++;
                 if (x < int(xwid / 2) - 1) {
                     outputter(",", false);
@@ -710,7 +730,7 @@
         }
         outputter("  .byte ", false);
         for (int j = 0; j <= 47; j++) {
-            write_head(0);
+            mpWriteByte(0);
             outputter(str(int(0)), false);
             pp++;
             if (j < 47) {
@@ -737,7 +757,7 @@
                 ad = 1024 + y * (xwid * 8) + (y2 * xwid) + x * 8;
                 value = g_map[ad + 0] * 128 + g_map[ad + 1] * 64 + g_map[ad + 2] * 32 + g_map[ad + 3] * 16 + g_map[ad + 4] * 8 + g_map[ad + 5] * 4 + g_map[ad + 6] * 2 + g_map[ad + 7] * 1;
                 outputter(str(int(value)), false);
-                write_head(int(value));
+                mpWriteByte(int(value));
                 if (y2 <= 6) {
                     outputter(",", false);
                 }
@@ -795,7 +815,7 @@
     return res;
 }
 
-void colorexport(int xx, int yy, int source, int param) {
+void mpExportColorData(int xx, int yy, int source, int param) {
     int x, y, y2, valu, valu2, kalu, muista, ad, linep, xwid, ywid, xoor, yline, myrpsi;
     xwid = xx * 8;
     ywid = yy * 8;
@@ -884,7 +904,7 @@
                 }
 
                 outputter(str(valu * 16 + valu2), false);
-                write_head(int(valu * 16 + valu2));
+                mpWriteByte(int(valu * 16 + valu2));
                 if (x < (xx - 1) || yline < myrpsi) {
                     outputter(",", false);
                 }
@@ -895,23 +915,10 @@
     outputter("", true);
 }
 
-void load_template(String fname) {
-    g_template = mpLoadBinaryFile("templates/" + fname);
-}
-
 void import_program(String fname) {
     g_template = mpLoadBinaryFile(fname);
 }
 
-void set_head(int pos) {
-    g_headpos = pos;
-}
-
-void write_head(int bb) {
-    g_template[g_headpos] = byte(bb);
-    g_headpos++;
-}
-
 void export_program(String fname) {
     if (g_sorsaa != 1)
         mpSaveBinaryFile(fname, g_template);
--- a/multipaint.pde	Thu Jul 05 23:19:14 2018 +0300
+++ b/multipaint.pde	Thu Jul 05 23:43:28 2018 +0300
@@ -524,7 +524,7 @@
         {
             store_undo();
             filename = fh.name;
-            format_import(fdata);
+            mpImportFormat(fdata);
             refresh();
         });