changeset 91:892a06169bb5

Refactor machine program and source exporting.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Jul 2018 00:42:06 +0300
parents dffafe05d520
children 4161d798cb64
files exporters.pde
diffstat 1 files changed, 245 insertions(+), 231 deletions(-) [+]
line wrap: on
line diff
--- a/exporters.pde	Fri Jul 06 00:39:41 2018 +0300
+++ b/exporters.pde	Fri Jul 06 00:42:06 2018 +0300
@@ -388,37 +388,23 @@
 }
 
 
-void machine_export(String fname, int sorsa) {
-    int yy, xx, x, y2, y, checksum;
-    int xp, yp;
-    int valu, valu2;
-    int val1, val2, val3;
-    int ad, by;
-    int bri, skyp;
-    g_sorsaa = sorsa; //aargh another global
-
-    if (sorsa == 1) {
-        exwriter = createWriter(fname);
-    }
-
+byte[] mpExportMachinePRG(bool sorsa)
+{
     // any common text headers
-    by = 0;
-    skyp = 0;
-    outputter(";machine=" + str(machine) + " (" + g_name + ")", true);
+    String src = ";machine=" + str(machine) + " (" + g_name + ")\n";
 
     if (machine == C64) { //C64 HIRES
 
         mpLoadTemplate("c64show.prg");
-        mpSetDataOffs(0X0227);
-        mpExportBitmapData(40, 25);
-        mpSetDataOffs(0X2167);
+        mpSetDataOffs(0x0227);
+        src += mpExportBitmapData(40, 25);
+        mpSetDataOffs(0x2167);
         mpWriteByte(g_map[0]); //=border
-        mpSetDataOffs(0X2168);
+        mpSetDataOffs(0x2168);
         mpWriteByte(g_map[1]); //=background mutta ei tarvita
-        mpSetDataOffs(0X2169);
-        outputter("; The following two first values are border and background", true);
+        mpSetDataOffs(0x2169);
+        src += "; The following two first values are border and background\n";
         mpExportColorData(40, 25, 65536, 0);
-        export_program(fname);
 
         //c64show.prg
         //offsets
@@ -426,12 +412,12 @@
         //0x2167:borderi väri
         //0x2169->värikartta (40x25 bytee, nyppelit foreg/backg)
     }
-
+    else
     if (machine == C64M) { //C64 MULTICOLOR
 
         mpLoadTemplate("c64mshow.prg");
         mpSetDataOffs(0x0239);
-        mpExportBitmapData(40, 25);
+        src += mpExportBitmapData(40, 25);
 
         // first color information
         mpSetDataOffs(0x2179);
@@ -439,14 +425,13 @@
         mpSetDataOffs(0x217A);
         mpWriteByte(g_map[1]);
         mpSetDataOffs(0x217B);
-        outputter("; The following two first values are border and background", true);
+        src += "; The following two first values are border and background\n";
         mpExportColorData(40, 25, 65536, 1);
 
         // second color information
         mpSetDataOffs(0x2563);
-        outputter("; The following goes to $D800 onwards", true);
+        src += "; The following goes to $D800 onwards\n";
         mpExportColorData(40, 25, 65536 + 2000, 2);
-        export_program(fname);
 
         //c64 multicolor
         //offsets
@@ -456,46 +441,45 @@
         //0x217B->värikartta 1 (40x25 bytee, nyppelit foreg/backg ilmeisesti)
         //0x2563->värikartta 2 (40x25 bytee, nyppeli 3-väri nepan osoitteessa $d800-)
     }
-
+    else
     if (machine == PLUS4M) { //PLUS4 MULTICOLOR
         mpLoadTemplate("showpfourm.prg");
-        outputter("  .global _bitmap", true);
-        outputter("  .global _color1", true);
-        outputter("  .global _color2", true);
-        outputter("  .global _border", true);
-        outputter("  .global _back1", true);
-        outputter("  .global _back2", true);
-        outputter("_bitmap:", true);
+        src += "  .global _bitmap\n";
+        src += "  .global _color1\n";
+        src += "  .global _color2\n";
+        src += "  .global _border\n";
+        src += "  .global _back1\n";
+        src += "  .global _back2\n";
+        src += "_bitmap:\n";
         mpSetDataOffs(0x013e);
-        mpExportBitmapData(40, 25);
-        outputter("_border:", true);
+        src += mpExportBitmapData(40, 25);
+        src += "_border:\n";
         val1 = getpluscolor(int(g_map[0]));
         val2 = getplusluminance(int(g_map[0]));
         val3 = val2 * 16 + val1;
         mpSetDataOffs(0x207e);
         mpWriteByte(val3);
-        outputter("  .byte " + val3, true);
-        outputter("_back1:", true);
+        src += "  .byte " + val3 +"\n";
+        src += "_back1:\n";
         val1 = getpluscolor(int(g_map[1]));
         val2 = getplusluminance(int(g_map[1]));
         val3 = val2 * 16 + val1;
         mpSetDataOffs(0x207f);
         mpWriteByte(val3);
-        outputter("  .byte " + val3, true);
-        outputter("_back2:", true);
+        src += "  .byte " + val3 +"\n";
+        src += "_back2:\n";
         val1 = getpluscolor(int(g_map[2]));
         val2 = getplusluminance(int(g_map[2]));
         val3 = val2 * 16 + val1;
         mpSetDataOffs(0x2080);
         mpWriteByte(val3);
-        outputter("  .byte " + val3, true);
-        outputter("_color1:", true);
+        src += "  .byte " + val3 +"\n";
+        src += "_color1:\n";
         mpSetDataOffs(0x2081);
         mpExportColorData(40, 25, 65536, 6);
-        outputter("_color2:", true);
+        src += "_color2:\n";
         mpSetDataOffs(0x2469);
         mpExportColorData(40, 25, 65536, 7);
-        export_program(fname);
         //plus4 multic
         //0x013e bitmap (40 x 25 x 8)
         //0x207e border
@@ -504,16 +488,16 @@
         //0x2081 colors (40 x 25)
         //0x2469 luminance (40 x 25)
     }
-
+    else
     if (machine == PLUS4) { // Plus 4 hires
         mpLoadTemplate("showpfour.prg");
-        outputter("  .global _bitmap", true);
-        outputter("  .global _color", true);
-        outputter("  .global _lumi", true);
-        outputter("  .global _border", true);
-        outputter("_bitmap:", true);
+        src += "  .global _bitmap\n";
+        src += "  .global _color\n";
+        src += "  .global _lumi\n";
+        src += "  .global _border\n";
+        src += "_bitmap:\n";
         mpSetDataOffs(0x0137);
-        mpExportBitmapData(40, 25);
+        src += mpExportBitmapData(40, 25);
         val1 = getpluscolor(int(g_map[0]));
         val2 = getplusluminance(int(g_map[0]));
         val3 = val2 * 16 + val1;
@@ -524,87 +508,86 @@
         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)
         //0x2077   borderi
         //0x2078   colors (40 x 25)
         //0x2460   luminance (40 x 25)
     }
-
+    else
     if (machine == MSX) { // MSX
         mpLoadTemplate("msxshow.com");
         mpSetDataOffs(0x00f9);
-        outputter(char(9) + ".globl _nimi1,_nimi2", true);
-        outputter(char(9) + ".area _CODE", true);
-        outputter("_nimi1:", true);
-        mpExportBitmapData(32, 24);
+        src += "\t.globl _nimi1,_nimi2\n";
+        src += "\t.area _CODE\n";
+        src += "_nimi1:\n";
+        src += mpExportBitmapData(32, 24);
         mpSetDataOffs(0x18f9);
         //mpWriteByte(g_map[1]); //backg
-        //outputter("; The first following value is background", true);
-        outputter("_nimi2:", true);
-        mpExportColorData(32, 24, 65536, 3); //there's an exception for msx-style
-        export_program(fname);
+        //src += "; The first following value is background\n";
+        src += "_nimi2:\n";
+        src += mpExportColorData(32, 24, 65536, 3); //there's an exception for msx-style
         //msx comm
         //0x00f9 bitmap (32x24 x 8 bytes)
         //0x18f9 background color
         //0x18fa colors (32*24 bytes)
     }
-
+    else
     if (machine == SPECTRUM) { // ZX Spectrum
 
         //would need some cleaning up
 
-        //  outputter("  .area  _DATA",true);
-        //  outputter("  .globl _taustakuva",true);
-        //  outputter("",true);
-        //  outputter("_taustakuva:",true);
+        //  src += "  .area  _DATA\n";
+        //  src += "  .globl _taustakuva\n\n";
+        //  src += "_taustakuva:\n";
         mpLoadTemplate("specshow.tap");
-        int stad;
 
-        checksum = 0xc9;
+        int checksum = 0xc9;
         for (y = 0x1d24; y <= 0x1d3d; y++) { //1d3e
             checksum = checksum ^ int(g_template[y]);
         }
+
         //TAP requires fiddling with the checksum
         //println("Checksum:"+hex(checksum,2));
         mpSetDataOffs(0x0223);
-        outputter(".byte " + (str(g_map[0])) + " ;border", true);
-        mpWriteByte(int(g_map[0]));
+        src += ".byte " + (str(g_map[0])) + " ;border\n";
+        mpWriteByte(g_map[0]);
         checksum = checksum ^ int(g_map[0]);
-        for (y = 0; y <= 2; y++)
-        for (y2 = 0; y2 <= 7; y2++)
-        for (yy = 0; yy <= 7; yy++)
+
+        for (int y = 0; y <= 2; y++)
+        for (int y2 = 0; y2 <= 7; y2++)
+        for (int yy = 0; yy <= 7; yy++)
         {
-            outputter(".byte ", false);
-            for (x = 0; x <= 31; x++)
+            src += ".byte ";
+            for (int x = 0; x <= 31; x++)
             {
-                yp = y * 64 + yy * 8 + y2;
-                xp = x;
-                ad = 1024 + yp * 256 + x * 8;
-                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++;
-                mpWriteByte(int(valu));
+                int yp = y * 64 + yy * 8 + y2,
+                    ad = 1024 + yp * 256 + x * 8,
+                    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;
+
+                src += str(valu);
+                mpWriteByte(valu);
                 checksum = checksum ^ int(valu);
                 if (x <= 30) {
-                    outputter(",", false);
+                    src += ",";
                 }
             }
-            outputter("", true);
+            src += "\n";
         }
 
-        outputter("; attributes", true);
-        for (y = 0; y <= 24; y++)
+        src += "; attributes\n";
+        for (int y = 0; y < 24; y++)
         {
-            outputter(".byte ", false);
-            for (x = 0; x <= 31; x++)
+            src += ".byte ";
+            for (int x = 0; x < 32; x++)
             {
-                ad = 65536 + x + y * 256;
-                valu = int(g_map[ad]);
-                valu2 = int(g_map[ad + MX * MY * 8]);
-                bri = 0;
-                if (valu >= 8) {
+                int ad = 65536 + x + y * 256,
+                    valu = int(g_map[ad]),
+                    valu2 = int(g_map[ad + MX * MY * 8]),
+                    bri = 0;
+
+                if (valu >= 8)
+                {
                     bri = 1;
                     valu = valu - 8;
                     valu2 = valu2 - 8;
@@ -615,79 +598,86 @@
                 if (bri == 1) {
                     valu = valu + 64;
                 }
-                outputter(str(valu + valu2 * 8), false);
-                by++;
-                mpWriteByte(int(valu + valu2 * 8));
+
+                src += str(valu + valu2 * 8);
+                mpWriteByte(valu + valu2 * 8);
                 checksum = checksum ^ int(valu + valu2 * 8);
                 if (x <= 30) {
-                    outputter(",", false);
+                    src += ",";
                 }
             }
-            outputter("", true);
+            src += "\n";
         }
         //println("checksum:"+hex(checksum,2));
         mpSetDataOffs(0x1d3e);
         mpWriteByte(int(checksum));
-        export_program(fname);
     }
-
+    else
     if (machine == CPC) {
+        int val1, val2, val3, valu;
         mpLoadTemplate("cpc-mode0.bin");
 
         mpSetDataOffs(69); //bitmap offset
-        mpExportBitmapData_CPC(160, 200);
+        src += mpExportBitmapData_CPC(160, 200);
         mpSetDataOffs(16453);
-        outputter(";palette", true);
-        outputter(".byte ", false);
+        src += ";palette\n";
+        src += ".byte ";
+
         //fixed # of palette entries, just trying to be generic
         for (int i = 0; i < g_maxcolors; i++)
         {
             val1 = int(g_g[i] / (256 / g_palsteps));
             val2 = int(g_r[i] / (256 / g_palsteps));
             val3 = int(g_b[i] / (256 / g_palsteps));
+
             mpWriteByte(val1 * 9 + val2 * 3 + val3);
-            outputter(str(val1 * 9 + val2 * 3 + val3), false);
+            src += str(val1 * 9 + val2 * 3 + val3);
             if (i < g_maxcolors - 1) {
-                outputter(",", false);
+                src += ",";
             }
         }
-        outputter("", true);
-        outputter(";border", true);
-        outputter(".byte ", false);
-        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));
+
+        src += "\n";
+        src += ";border\n";
+        src += ".byte ";
+
+        mpSetDataOffs(16469);
+
         mpWriteByte(val1 * 9 + val2 * 3 + val3);
-        outputter(str(val1 * 9 + val2 * 3 + val3), false);
+        src += str(val1 * 9 + val2 * 3 + val3);
         //cpc
         //69    bitmap 16384 bytes
         //16453 palette 16 bytes (0..26)
         //16469 border color (0..26)
-        export_program(fname);
     }
+    else
+        return null;
 
     // any common lead-outs
-
-    if (sorsa == 1) {
-        exwriter.flush();
-        exwriter.close();
-    }
+    if (sorsa)
+        return src;
+    else
+        return g_template;
 }
 
 
-void mpExportBitmapData_CPC(int xwid, int yy)
+String mpExportBitmapData_CPC(int xwid, int yy)
 {
     int x, y, ad, val1, val2, y2;
     int pix0b0, pix0b1, pix0b2, pix0b3;
     int pix1b0, pix1b1, pix1b2, pix1b3;
-    int pp;
-    pp = 0;
-    outputter(";bitmap", true);
-    for (y2 = 0; y2 <= 7; y2++) {
-        for (y = 0; y < 25; y++) {
-            outputter("  .byte ", false);
+    String src = ";bitmap\n";
+
+    for (y2 = 0; y2 < 8; y2++)
+    {
+        for (y = 0; y < 25; y++)
+        {
+            src += "  .byte ";
             for (x = 0; x < int(xwid / 2); x++) {
                 ad = 1024 + (y * 8) * X + (y2 * X) + x * 4;
 
@@ -713,64 +703,82 @@
                 if ((val1 & 8) != 0) pix1b3 = 1;
 
                 val2 = pix1b3 + pix0b3 * 2 + pix1b1 * 4 + pix0b1 * 8 + pix1b2 * 16 + pix0b2 * 32 + pix1b0 * 64 + pix0b0 * 128;
-                outputter(str(int(val2)), false);
+
+                src += str(int(val2));
                 mpWriteByte(val2);
-                pp++;
+
                 if (x < int(xwid / 2) - 1) {
-                    outputter(",", false);
+                    src += ",";
                 }
             }
-            outputter("", true);
+            src += "\n";
         }
-        outputter("  .byte ", false);
-        for (int j = 0; j <= 47; j++) {
+        src += "  .byte ";
+
+        for (int j = 0; j <= 47; j++)
+        {
             mpWriteByte(0);
-            outputter(str(int(0)), false);
-            pp++;
+            src += str(int(0));
             if (j < 47) {
-                outputter(",", false);
+                src += ",";
             }
         }
-        outputter("", true);
+        src += "\n";
     }
-    outputter("", true);
+    src += "\n";
+    return src;
 }
 
 
-void mpExportBitmapData(int xx, int yy)
+String mpExportBitmapData(int xx, int yy)
 {
-    int xwid, ywid, x, y, y2, value, ad, linep;
-    linep = 0;
-    xwid = xx * 8;
-    ywid = yy * 8;
-    //outputter("unsigned char img[]={",false);
+    String src = "";
+    //String src = "unsigned char img[]={";
+
+    int linep = 0,
+        xwid  = xx * 8,
+        ywid = yy * 8;
 
-    for (y = 0; y < yy; y++) {
-        for (x = 0; x < xx; x++) {
-            //            outputter("  .byte ", false);
-            outputter(char(9) + ".db ", false);
-            for (y2 = 0; y2 <= 7; y2++) {
-                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);
-                mpWriteByte(int(value));
-                if (y2 <= 6) {
-                    outputter(",", false);
-                }
-            }
-            outputter("", true);
-            linep++;
-            if (linep == xx) {
-                linep = 0;
-                outputter("", true);
+    for (int y = 0; y < yy; y++)
+    for (int x = 0; x < xx; x++)
+    {
+        // src += "  .byte ";
+        src += "\t.db ";
+        for (int y2 = 0; y2 < 8; y2++)
+        {
+            int ad = 1024 + y * (xwid * 8) + (y2 * xwid) + x * 8;
+            int 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;
+
+            src += str(int(value));
+            mpWriteByte(int(value));
+
+            if (y2 <= 6) {
+                src += ",";
             }
         }
+        src += "\n";
+        if (++linep == xx)
+        {
+            linep = 0;
+            src += "\n";
+        }
     }
-    outputter("", true);
+    src += "\n";
+
+    return src;
 }
 
 
-int convertlumi(int l, int f) {
+int convertluminance(int l, int f)
+{
     int res = 0;
     if (f == 0) return 0;
     if (l == 0) res = 0 + f;
@@ -784,7 +792,9 @@
     return res;
 }
 
-int getplusluminance(int c) {
+
+int getplusluminance(int c)
+{
     int res = 0;
     if (c == 0) res = 0;
     if (c >= 1 && c <= 15) res = 0;
@@ -798,7 +808,9 @@
     return res;
 }
 
-int getpluscolor(int c) {
+
+int getpluscolor(int c)
+{
     int res = 0;
     if (c == 0) res = 0;
     if (c >= 1 && c <= 15) res = c;
@@ -812,14 +824,18 @@
     return res;
 }
 
-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;
+
+String mpExportColorData(int xx, int yy, int source, int param)
+{
+    int valu, valu2, kalu, muista, ad, linep, xwid, ywid, xoor, yline, myrpsi;
+    String src = "";
+
     xwid = xx * 8;
     ywid = yy * 8;
-    valu = 0;
-    valu2 = 0;
+
     myrpsi = 0;
     xoor = xx;
+
     if (param == 0 || param == 4 || param == 5) {
         xoor = xx * 8;
     }
@@ -827,104 +843,102 @@
         myrpsi = 7;
     }
     if (param < 2) {
-        outputter("colora:", true);
+        src += "colora:\n";
     }
     if (param == 2) {
-        outputter("colorb:", true);
+        src += "colorb:\n";
     }
     if (param < 2) {
-        outputter("  .byte " + int(g_map[0]) + "," + int(g_map[1]), true);
+        src += "  .byte " + int(g_map[0]) + "," + int(g_map[1]) +"\n";
     }
     if (param == 3) {
-        //   outputter("color:", true);
-        //   outputter("  .byte ", false);
-        //  outputter(g_map[0]+" ", true);
+        //   src += "color:\n";
+        //   src += "  .byte ";
+        //  src += g_map[0]+" \n";
         xoor = xx * 8;
     }
     if (param == 4) {
-        outputter("_border:", true);
-        outputter("  .byte ", false);
+        src += "_border:\n";
+        src += "  .byte ";
         kalu = getpluscolor(int(g_map[0]));
         valu2 = getplusluminance(int(g_map[0]));
         valu = valu2 * 16 + kalu;
-        outputter(valu + " ", true);
-        outputter("_color:", true);
+        src += valu + " \n";
+        src += "_color:\n";
     }
     if (param == 5) {
-        outputter("_lumi:", true);
+        src += "_lumi:\n";
     }
-    for (y = 0; y < yy; y++) {
-        //outputter("  .byte ", false);
-        outputter(char(9) + ".db ", false);
-        for (x = 0; x < xx; x++) {
-            for (yline = 0; yline <= myrpsi; yline++) {
-                ad = source + x + y * xoor + yline * xx;
-                if (param == 0) {
+
+    for (int y = 0; y < yy; y++)
+    {
+        //src += "  .byte ";
+        src += "\t.db ";
+        for (int x = 0; x < xx; x++)
+        for (yline = 0; yline <= myrpsi; yline++)
+        {
+            ad = source + x + y * xoor + yline * xx;
+
+            switch (param)
+            {
+                case 0:
                     valu = int(g_map[ad]);
                     valu2 = int(g_map[ad + MX * MY * 8]);
-                }
-                if (param == 1) {
+                    break;
+
+                case 1:
                     valu2 = int(g_map[ad]);
                     valu = int(g_map[ad + 1000]);
-                }
-                if (param == 2) {
+                    break;
+
+                case 2:
                     valu2 = int(g_map[ad]);
                     valu = 0;
-                }
-                if (param == 3) {
+                    break;
+
+                case 3:
                     valu = int(g_map[ad]);
                     valu2 = int(g_map[ad + MX * MY * 8]);
-                }
+                    break;
 
-                if (param == 4) { //plus4 colortable
-                    kalu = int(g_map[ad]);
-                    valu = getpluscolor(kalu);
-                    kalu = int(g_map[ad + MX * MY * 8]);
-                    valu2 = getpluscolor(kalu);
-                }
+                case 4:
+                    //plus4 colortable
+                    valu = getpluscolor(int(g_map[ad]));
+                    valu2 = getpluscolor(int(g_map[ad + MX * MY * 8]));
+                    break;
 
-                if (param == 5) { //plus4 lumitable
-                    kalu = int(g_map[ad]);
-                    valu2 = getplusluminance(kalu);
-                    kalu = int(g_map[ad + MX * MY * 8]);
-                    valu = getplusluminance(kalu);
-                }
+                case 5:
+                    //plus4 lumitable
+                    valu = getplusluminance(int(g_map[ad + MX * MY * 8]));
+                    valu2 = getplusluminance(int(g_map[ad]));
+                    break;
 
-                if (param == 6) { //plus4 multic1
+                case 6:
+                    //plus4 multic1
                     valu2 = getpluscolor(int(g_map[ad]));
                     valu = getpluscolor(int(g_map[ad + 1000]));
-                }
+                    break;
 
-                if (param == 7) { //plus4 multic2
+                case 7:
+                    //plus4 multic2
                     valu = getplusluminance(int(g_map[ad]));
                     valu2 = getplusluminance(int(g_map[ad + 1000]));
-                }
+                    break;
+
+                default:
+                    return null;
+            }
 
-                outputter(str(valu * 16 + valu2), false);
-                mpWriteByte(int(valu * 16 + valu2));
-                if (x < (xx - 1) || yline < myrpsi) {
-                    outputter(",", false);
-                }
+            src += str(valu * 16 + valu2);
+            mpWriteByte(valu * 16 + valu2);
+            if (x < (xx - 1) || yline < myrpsi)
+            {
+                src += ",";
             }
         }
-        outputter("", true);
+        src += "\n";
     }
-    outputter("", true);
-}
-
-void import_program(String fname) {
-    g_template = mpLoadBinaryFile(fname);
-}
-
-void export_program(String fname) {
-    if (g_sorsaa != 1)
-        mpSaveBinaryFile(fname, g_template);
-}
-
-void outputter(String oput, boolean eol) {
-    if (g_sorsaa == 0) return;
-    if (eol == false) exwriter.print(oput);
-    if (eol == true) exwriter.println(oput);
+    src += "\n";
 }