changeset 154:1b2cbf3ab441

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 16 Aug 2018 13:00:03 +0300
parents 9f4e6f888120
children b9ad669fb025
files Interface.pde draw_outputs.pde events.pde exporters.pde multipaint.pde
diffstat 5 files changed, 375 insertions(+), 349 deletions(-) [+]
line wrap: on
line diff
--- a/Interface.pde	Wed Aug 15 15:55:14 2018 +0300
+++ b/Interface.pde	Thu Aug 16 13:00:03 2018 +0300
@@ -256,55 +256,44 @@
 {
     // transparent rectangle
     // fixed tp, for grid drawing
-
     //the updatepixels rigmarole has to be handled elsewhere
-    int r, g, b, s, fout;
     int ad = x1 + y1 * width;
 
     if (g_gridmode == NEW)
     {
         for (int yy = 0; yy < h; yy++)
         {
-            for (int xx = 0; xx < w; xx++) {
-                s = pixels[ad + xx];
-                fout = 0;
+            for (int xx = 0; xx < w; xx++)
+            {
+                int s = pixels[ad + xx],
+                    fout = 0;
 
-                if (g_rgb[0] == s) fout = g_grids[0];
-                if (g_rgb[1] == s) fout = g_grids[1];
-                if (g_rgb[2] == s) fout = g_grids[2];
-                if (g_rgb[3] == s) fout = g_grids[3];
-                if (g_rgb[4] == s) fout = g_grids[4];
-                if (g_rgb[5] == s) fout = g_grids[5];
-                if (g_rgb[6] == s) fout = g_grids[6];
-                if (g_rgb[7] == s) fout = g_grids[7];
-                if (g_rgb[8] == s) fout = g_grids[8];
-                if (g_rgb[9] == s) fout = g_grids[9];
-                if (g_rgb[10] == s) fout = g_grids[10];
-                if (g_rgb[11] == s) fout = g_grids[11];
-                if (g_rgb[12] == s) fout = g_grids[12];
-                if (g_rgb[13] == s) fout = g_grids[13];
-                if (g_rgb[14] == s) fout = g_grids[14];
-                if (g_rgb[15] == s) fout = g_grids[15];
+                for (int qn = 0; qn < 16; qn++)
+                {
+                    if (g_rgb[qn] == s)
+                    {
+                        fout = g_grids[qn];
+                        break;
+                    }
+                }
 
                 pixels[ad + xx] = fout;
             }
-            ad = ad + width;
+            ad += width;
         }
     }
     else
     {
-
         for (int yy = 0; yy < h; yy++)
         {
             for (int xx = 0; xx < w; xx++)
             {
-                s = pixels[ad + xx];
+                int s = pixels[ad + xx],
+                    r = (s >> 16) & 0xff,
+                    g = (s >> 8) & 0xff,
+                    b = (s) & 0xff;
 
-                r = (s >> 16) & 0xff;
-                g = (s >> 8) & 0xff;
-                b = (s) & 0xff;
-
-                g = g + 64;
+                g += 64;
 
                 r = int((r * 2) / 3);
                 g = int((g * 2) / 3);
@@ -312,7 +301,7 @@
 
                 pixels[ad + xx] = 0xff000000 + r * 0x10000 + g * 0x100 + b;
             }
-            ad = ad + width;
+            ad += width;
         }
     }
 }
@@ -348,7 +337,7 @@
 void drawicon(int xo, int yo, int t, int mm)
 {
     //draw one icon
-    int ad, cad, xx, yy, pop, far;
+    int cad, xx, yy, pop, far;
     int metal;
 
     yy = int(t / 16);
@@ -357,7 +346,7 @@
     xx *= 2;
     yy *= 2;
 
-    ad = 1024 + xx * 8 + yy * 2048;
+    int ad = 1024 + xx * 8 + yy * 2048;
 
     for (int y = 0; y < 16; y++)
     {
@@ -365,22 +354,26 @@
         {
             metal = 0xffa0a0a0;
             far = 0xff000000;
-            if (t == 18 || (t == 19 && g_backmode == 1)) {
+
+            if (t == 18 || (t == 19 && g_backmode == 1))
+            {
                 if (x < 15 && y < 15) far = int(g_rgb[g_farge]);
             }
+
             if (g_depressed[t] > 0) metal = 0xff606060;
 
-            if (x == 0 || y == 0) {
+            if (x == 0 || y == 0)
+            {
                 metal = 0xffe0e0e0;
                 if (g_depressed[t] > 0) metal = 0xff303030;
                 if (t == 56 || t == 9) metal = 0xffa0a0a0;
             }
 
             cad = 65536 + (xx + int(x / 8)) + yy * 256 + y * 32;
-
             pop = (int(g_icons[cad]) == 0) ? 0 : 1;
 
-            if (int(g_icons[ad + x]) == pop) {
+            if (int(g_icons[ad + x]) == pop)
+            {
                 far = metal;
                 if (mm == 1) far = 0xffffff80;
             }
@@ -395,7 +388,7 @@
 
             e_rect(xo + x * g_uizoom, yo + y * g_uizoom, g_uizoom, g_uizoom, far);
         }
-        ad = ad + 256;
+        ad += 256;
     }
 }
 
@@ -774,7 +767,7 @@
 void icontable(int xx, int yy, int tabletype, int realdraw)
 {
     String pan = "";
-    int x = 0, y = 0, ad;
+    int x = 0, y = 0;
 
     g_data[int('9')] = (g_btype == 9) ? 1 : 0;
 
@@ -846,24 +839,27 @@
                     command(128 + ii + jj * 4);
             }
         }
+
         if (tabletype == 0)
         {
-            x = x + 16 * g_uizoom;
+            x += 16 * g_uizoom;
             if (ad == '.') x = x - 8 * g_uizoom;
             if (x > 16 * g_uizoom)
             {
                 x = 0;
-                y = y + 16 * g_uizoom;
-                if (ad == ':') y = y - 14 * g_uizoom;
+                y += 16 * g_uizoom;
+                if (ad == ':')
+                    y -= 14 * g_uizoom;
             }
         }
+        else
         if (tabletype == 1 || tabletype == 2)
         {
-            y = y + 16 * g_uizoom;
+            y += 16 * g_uizoom;
             if (y > 16 * g_uizoom)
             {
                 y = 0;
-                x = x + 16 * g_uizoom;
+                x += 16 * g_uizoom;
             }
         }
     }
@@ -1022,6 +1018,7 @@
         e_rect(int(x0 + expand * i), y0 + 10 * g_uizoom, g_uizoom, 2 * g_uizoom, g_rgb[257]);
         e_rect(int(x0 + expand * i), y0 + 20 * g_uizoom, g_uizoom, 2 * g_uizoom, g_rgb[257]);
     }
+
     e_rect(int(x0 + expand * g_r[g_farge] / divs), y0, int(expand), 7 * g_uizoom, g_rgb[260]);
     e_rect(int(x0 + expand * g_g[g_farge] / divs), y0 + 10 * g_uizoom, int(expand), 7 * g_uizoom, g_rgb[261]);
     e_rect(int(x0 + expand * g_b[g_farge] / divs), y0 + 20 * g_uizoom, int(expand), 7 * g_uizoom, g_rgb[262]);
@@ -1100,8 +1097,11 @@
                 yloc = yo + yhei * 0 + yfat * 14;
             }
         }
-        if (doicon_drag(xloc, yloc, xonko, yhei)) {
-            if (mouseButton == LEFT || mouseButton == CENTER) {
+
+        if (doicon_drag(xloc, yloc, xonko, yhei))
+        {
+            if (mouseButton == LEFT || mouseButton == CENTER)
+            {
                 selectcolor(0, x);
             }
             if (mouseButton == RIGHT) {
@@ -1110,9 +1110,9 @@
             }
         }
 
-        if (g_repanel <= 0) {
-            int index;
-            index = x;
+        if (g_repanel <= 0)
+        {
+            int index = x;
             if (machine == MSX && x == 0) index = g_map[1];
             e_rect(xloc, yloc, xonko, yhei, g_rgb[index]); // the colour blocks
             far = 0xff000000;
@@ -1168,7 +1168,8 @@
     for (int xx = 0; xx < 12; xx++)
     for (int yy = 0; yy < 4; yy++)
     {
-        if (g_chaup[xx + yy * 16] == 1) {
+        if (g_chaup[xx + yy * 16] == 1)
+        {
             g_chaup[xx + yy * 16] = 0;
             drawchar(ox + xx * cz, oy + yy * cz, g_data[256 + xx + yy * 12]);
         }
@@ -1211,13 +1212,6 @@
 
 void update_ui(boolean forced)
 {
-    if (g_iconmode == 1)
-    {
-        for (int i = 0; i <= 80000; i++) {
-            g_icons[i] = g_map[i];
-        }
-    }
-
     if (g_repanel <= 0)
         g_repanel++;
 
@@ -1225,7 +1219,6 @@
 
     // when tooltipping, the panels are not really
     // drawn but used for easy coordinate reference
-
     if (g_repanel > 0 && !forced)
     {
         icontable(width - 32 * g_uizoom, 0, 0, 0);
@@ -1262,7 +1255,8 @@
 }
 
 
-void viewport() {
+void viewport()
+{
     // formerly void redo()
     // main machine screen redraw
     // and dirty char update
@@ -1273,6 +1267,7 @@
     raddr = 0;
     winsux = 0;
     winsuy = 0;
+
     if (g_backmode == 0) g_map[1] = 0; //some computers have overall background
 
     mmode = magmode();
@@ -1326,6 +1321,7 @@
         winsuy = g_windowy;
         mag = 16;
     } //mini
+    else
     if (mmode == 0) {
         g_ofx = 0;
         g_ofy = 0;
@@ -1335,6 +1331,7 @@
         winsuy = g_windowy;
         mag = 24;
     } //normal
+    else
     if (mmode == 20) {
         g_ofx = 0;
         g_ofy = 0;
@@ -1356,8 +1353,8 @@
     }
 
     for (ywin = 0; ywin <= mayy; ywin++)
-    for (xwin = 0; xwin <= maxx; xwin++) {
-
+    for (xwin = 0; xwin <= maxx; xwin++)
+    {
         // source coords: is 0,0 if not magged
         xx = g_ofx + xwin;
         yy = g_ofy + ywin;
@@ -1428,11 +1425,11 @@
                         if (fylli() == 1) {
                             if (xx * 8 + rubx == g_rx || xx * 8 + rubx == g_rx2) {
                                 if (yy * 8 + y >= g_ry && yy * 8 + y <= g_ry2) fari = 256;
-                                if (yy * 8 + y >= g_ry && yy * 8 + y <= g_ry2) fari = 256;
+//                                if (yy * 8 + y >= g_ry && yy * 8 + y <= g_ry2) fari = 256;
                             }
                             if (yy * 8 + y == g_ry || yy * 8 + y == g_ry2) {
                                 if (xx * 8 + x >= g_rx && xx * 8 + x <= g_rx2) fari = 256;
-                                if (xx * 8 + x >= g_rx && xx * 8 + x <= g_rx2) fari = 256;
+//                                if (xx * 8 + x >= g_rx && xx * 8 + x <= g_rx2) fari = 256;
                             }
                         }
                     }
@@ -1625,7 +1622,7 @@
             //draw grid
             //can in principle be non-square
             if (int(g_data[int('g')]) == 1) {
-                int lapx = int((xx * 8) / g_gridx) * g_gridx;
+                int lapx = chopv(xx * 8, g_gridx);
                 if (lapx == (xx * 8)) {
                     t_rect(xo * mag + winsux, yo * mag + winsuy, 1, mag, g_rgb[257]);
                     if (g_gridx == 4) {
@@ -1633,7 +1630,7 @@
                         t_rect(xo * mag + winsux + 4 * psize, yo * mag + winsuy + mag - int(mag / 2) + 2, 1, int(mag / 2) - 2, g_rgb[257]);
                     }
                 }
-                lapx = int((yy * 8) / g_gridy) * g_gridy;
+                lapx = chopv(yy * 8, g_gridy);
 
                 if (lapx == (yy * 8)) {
                     t_rect(xo * mag + winsux + 1, yo * mag + winsuy, mag - 1, 1, g_rgb[257]);
--- a/draw_outputs.pde	Wed Aug 15 15:55:14 2018 +0300
+++ b/draw_outputs.pde	Thu Aug 16 13:00:03 2018 +0300
@@ -1,6 +1,11 @@
 // Collect all that "writes" the virtual image in some way or other
 // plus other active manipulations
 
+int clipv(int v, int vmin, int vmax)
+{
+    return (v < vmin) ? vmin : (v > vmax ? vmax : v);
+}
+
 int chop2(int v)
 {
   return int(v / 2) * 2;
--- a/events.pde	Wed Aug 15 15:55:14 2018 +0300
+++ b/events.pde	Thu Aug 16 13:00:03 2018 +0300
@@ -839,21 +839,30 @@
     }
 
     if (machine == SPECTRUM) {
-        if (g_data[int('i')] == 1) {
+        if (g_data[int('i')] == 1)
+        {
             g_data[int('i')] = 0;
-            if (g_iconmode == 0) {
+            if (g_iconmode)
+            {
                 message("Icons|not loaded!");
-            } else {
+            }
+            else
+            {
                 message("Store|icons");
                 mpSaveNativeImage("icons.bin");
             }
         }
-        if (g_data[int('I')] == 1) {
+        if (g_data[int('I')] == 1)
+        {
             g_data[int('I')] = 0;
             message("Restore|icons");
             mpLoadNativeImage("icons.bin", true);
             refresh();
-            g_iconmode = 1;
+
+            for (int i = 0; i <= 80000; i++)
+                g_icons[i] = g_map[i];
+
+            g_iconmode = true;
         }
     }
 
--- a/exporters.pde	Wed Aug 15 15:55:14 2018 +0300
+++ b/exporters.pde	Thu Aug 16 13:00:03 2018 +0300
@@ -1071,34 +1071,30 @@
         vertti = 1;
         erkki = 8;
     }
-    if (g_multic == 1) {
+    if (g_multic == 1)
         limitter = 4;
-    } //because zero color can be anywhere?
-    if (g_multic == 2) {
+    else
+    //because zero color can be anywhere?
+    if (g_multic == 2)
         limitter = 16;
-    }
 
     command(int('O')); //special clear screen
 
     balx = int(image.width / X) * g_pixelw;
     baly = int(image.height / Y);
-    if (balx < 1) {
+    if (balx < 1)
         balx = 1;
-    }
-    if (baly < 1) {
+    if (baly < 1)
         baly = 1;
-    }
 
     if (g_palsteps > 0)
     {
-        for (i = 0; i < g_maxcolors; i++) {
-            makecolor(i, 0, 0, 0);
-        }
+        int psteps = int(g_palsteps - 1),
+            maxhis = 0,
+            palls = int(255 / psteps);
 
-        int maxhis, palls, psteps;
-        psteps = int(g_palsteps - 1);
-        maxhis = 0;
-        palls = int(255 / psteps);
+        for (i = 0; i < g_maxcolors; i++)
+            makecolor(i, 0, 0, 0);
 
         for (cy = 0; cy < MY * erkki; cy++)
         for (cx = 0; cx < MX; cx++)
@@ -1112,28 +1108,23 @@
             bb = 0;
             avg = 0;
 
-            for (avy = 0; avy < baly; avy++) {
-                for (avx = 0; avx < balx; avx++) {
-                    c = image.get(x2 + avx, y2 + avy);
-                    rr = rr + int(red(c));
-                    gg = gg + int(green(c));
-                    bb = bb + int(blue(c));
-                    avg++;
-                }
+            for (avy = 0; avy < baly; avy++)
+            for (avx = 0; avx < balx; avx++)
+            {
+                c = image.get(x2 + avx, y2 + avy);
+                rr = rr + int(red(c));
+                gg = gg + int(green(c));
+                bb = bb + int(blue(c));
+                avg++;
             }
 
-            rh = rr / (avg);
-            gh = gg / (avg);
-            bh = bb / (avg);
+            rh = int(int(rr / avg) / palls);
+            gh = int(int(gg / avg) / palls);
+            bh = int(int(bb / avg) / palls);
 
-            rh = int(rh) / palls;
-            gh = int(gh) / palls;
-            bh = int(bh) / palls;
-            histog[int(rh * (g_palsteps * g_palsteps) + gh * (g_palsteps) + bh)]++;
-
-            if (histog[int(rh * (g_palsteps * g_palsteps) + gh * (g_palsteps) + bh)] > maxhis) {
-                maxhis = histog[int(rh * (g_palsteps * g_palsteps) + gh * (g_palsteps) + bh)];
-            }
+            int hindex = int(rh * (g_palsteps * g_palsteps) + gh * (g_palsteps) + bh);
+            if (++histog[hindex] > maxhis)
+                maxhis = histog[hindex];
         }
 
         int step = 0;
@@ -1150,7 +1141,8 @@
                 rh = rh * int(palls);
                 gh = gh * int(palls);
                 bh = bh * int(palls);
-                if (step < g_maxcolors) {
+                if (step < g_maxcolors)
+                {
                     makecolor(step, rh, gh, bh);
                     step++;
                 }
@@ -1159,8 +1151,10 @@
     }
 
     for (cy = 0; cy < MY * erkki; cy++)
-    for (cx = 0; cx < MX; cx++) {
-        for (i = 0; i < xcolors; i++) {
+    for (cx = 0; cx < MX; cx++)
+    {
+        for (i = 0; i < xcolors; i++)
+        {
             pixut[i] = 0;
             idx[i] = i;
         }
@@ -1172,24 +1166,28 @@
                 gg = 0;
                 bb = 0;
                 avg = 0;
-                for (avy = 0; avy < baly; avy++) {
-                    for (avx = 0; avx < balx; avx++) {
-                        c = image.get(x2 + avx, y2 + avy);
-                        rr = rr + int(red(c));
-                        gg = gg + int(green(c));
-                        bb = bb + int(blue(c));
-                        avg++;
-                    }
+
+                for (avy = 0; avy < baly; avy++)
+                for (avx = 0; avx < balx; avx++)
+                {
+                    c = image.get(x2 + avx, y2 + avy);
+                    rr += int(red(c));
+                    gg += int(green(c));
+                    bb += int(blue(c));
+                    avg++;
                 }
-                rr = rr / (avg);
-                gg = gg / (avg);
-                bb = bb / (avg);
+
+                rr = int(rr / avg);
+                gg = int(gg / avg);
+                bb = int(bb / avg);
                 g_farge = 0;
                 target = -1;
                 compa = 9999;
-                for (i = 0; i < xcolors; i++) {
+                for (i = 0; i < xcolors; i++)
+                {
                     fld = dist(rr, gg, bb, g_r[i], g_g[i], g_b[i]);
-                    if (fld < compa) {
+                    if (fld < compa)
+                    {
                         compa = fld;
                         target = i;
                     }
@@ -1218,43 +1216,41 @@
         {
             i = idx[idefix];
             for (yy = cy * vertti; yy <= cy * vertti + vertti - 1; yy++)
+            for (xx = cx * 8; xx <= cx * 8 + 7; xx = xx + g_pixelw)
             {
-                for (xx = cx * 8; xx <= cx * 8 + 7; xx = xx + g_pixelw)
-                {
-                    x2 = int(image.width / X) * xx;
-                    y2 = int(image.height / Y) * yy;
+                x2 = int(image.width / X) * xx;
+                y2 = int(image.height / Y) * yy;
 
-                    rr = 0;
-                    gg = 0;
-                    bb = 0;
-                    avg = 0;
-                    for (avy = 0; avy < baly; avy++) {
-                        for (avx = 0; avx < balx; avx++) {
-                            c = image.get(x2 + avx, y2 + avy);
-                            rr = rr + int(red(c));
-                            gg = gg + int(green(c));
-                            bb = bb + int(blue(c));
-                            avg++;
-                        }
+                rr = 0;
+                gg = 0;
+                bb = 0;
+                avg = 0;
+                for (avy = 0; avy < baly; avy++) {
+                    for (avx = 0; avx < balx; avx++) {
+                        c = image.get(x2 + avx, y2 + avy);
+                        rr = rr + int(red(c));
+                        gg = gg + int(green(c));
+                        bb = bb + int(blue(c));
+                        avg++;
                     }
-                    rr = rr / (avg);
-                    gg = gg / (avg);
-                    bb = bb / (avg);
-                    g_farge = 0;
-                    target = -1;
-                    compa = 9999;
-                    for (j = 0; j < limitter; j++) {
-                        fld = dist(rr, gg, bb, g_r[idx[j]], g_g[idx[j]], g_b[idx[j]]);
-                        if (fld < compa) {
-                            compa = fld;
-                            target = idx[j];
-                        }
+                }
+                rr = rr / (avg);
+                gg = gg / (avg);
+                bb = bb / (avg);
+                g_farge = 0;
+                target = -1;
+                compa = 9999;
+                for (j = 0; j < limitter; j++) {
+                    fld = dist(rr, gg, bb, g_r[idx[j]], g_g[idx[j]], g_b[idx[j]]);
+                    if (fld < compa) {
+                        compa = fld;
+                        target = idx[j];
                     }
-                    if (i == target) {
+                }
+                if (i == target) {
 
-                        g_farge = target;
-                        makepoint(xx, yy);
-                    }
+                    g_farge = target;
+                    makepoint(xx, yy);
                 }
             }
 
@@ -1333,191 +1329,200 @@
 }
 
 
-void make_c64_palette() {
+void make_c64_palette()
+{
     // Pepto's murky C64 palette: http://www.pepto.de/projects/colorvic
-    int rgb[] = {
-        0xff000000,
-        0xffFFFFFF,
-        0xff68372B,
-        0xff70A4B2,
-        0xff6F3D86,
-        0xff588D43,
-        0xff352879,
-        0xffB8C76F,
-        0xff6F4F25,
-        0xff433900,
-        0xff9A6759,
-        0xff444444,
-        0xff6C6C6C,
-        0xff9AD284,
-        0xff6C5EB5,
-        0xff959595
+    int rgb[] =
+    {
+        0x000000,
+        0xFFFFFF,
+        0x68372B,
+        0x70A4B2,
+        0x6F3D86,
+        0x588D43,
+        0x352879,
+        0xB8C76F,
+        0x6F4F25,
+        0x433900,
+        0x9A6759,
+        0x444444,
+        0x6C6C6C,
+        0x9AD284,
+        0x6C5EB5,
+        0x959595
     };
-    for (int i = 0; i < g_maxcolors; i++) {
-        rgb[i] = rgb[i] & 0xffffff;
-        g_grids[i] = rgb[i] + 0xff282828;
-        makecolor(i, rgb[i] >> 16, (rgb[i] & 0xff00FF00) >> 8, rgb[i] & 0xff0000FF);
+    for (int i = 0; i < g_maxcolors; i++)
+    {
+        g_grids[i] = (rgb[i] + 0x282828) | 0xff000000;
+        makecolor(i, (rgb[i] >> 16) & 0xff, (rgb[i] >> 8) & 0xff, rgb[i] & 0xff);
     }
     g_grids[1] = 0xffd0d0d0;
     g_gridmode = NEW;
     g_map[13] = byte(C64);
 }
 
-void make_plus4_palette() {
-    int rgb[] = {
-        0xff000000,
-        0xff2C2C2C,
-        0xff621307,
-        0xff00424C,
-        0xff510378,
-        0xff004E00,
-        0xff27188E,
-        0xff303E00,
-        0xff582100,
-        0xff463000,
-        0xff244400,
-        0xff630448,
-        0xff004E0C,
-        0xff0E2784,
-        0xff33118E,
-        0xff184800,
-        0xff3B3B3B,
-        0xff702419,
-        0xff00505A,
-        0xff601685,
-        0xff125D00,
-        0xff36289B,
-        0xff3F4C00,
-        0xff663100,
-        0xff553F00,
-        0xff345200,
-        0xff711656,
-        0xff005C1D,
-        0xff1F3691,
-        0xff42229B,
-        0xff285700,
-        0xff424242,
-        0xff772C21,
-        0xff055861,
-        0xff661E8C,
-        0xff1B6400,
-        0xff3E30A2,
-        0xff475400,
-        0xff6D3900,
-        0xff5C4700,
-        0xff3B5900,
-        0xff771F5D,
-        0xff046325,
-        0xff273E98,
-        0xff492AA1,
-        0xff305E00,
-        0xff515151,
-        0xff843B31,
-        0xff17656F,
-        0xff742E99,
-        0xff2B7100,
-        0xff4C3FAF,
-        0xff556200,
-        0xff7A4709,
-        0xff6A5500,
-        0xff4A6700,
-        0xff852F6B,
-        0xff177135,
-        0xff364CA5,
-        0xff5739AE,
-        0xff3F6B00,
-        0xff7A7A7A,
-        0xffAC665C,
-        0xff468E97,
-        0xff9C5AC0,
-        0xff57992E,
-        0xff766AD5,
-        0xff7E8A13,
-        0xffA2713A,
-        0xff927E20,
-        0xff748F14,
-        0xffAC5A93,
-        0xff459960,
-        0xff6276CB,
-        0xff8064D4,
-        0xff6A9419,
-        0xff959595,
-        0xffC58178,
-        0xff62A8B1,
-        0xffB675D9,
-        0xff73B34C,
-        0xff9185ED,
-        0xff99A433,
-        0xffBB8C57,
-        0xffAC993E,
-        0xff8FAA34,
-        0xffC676AD,
-        0xff62B37B,
-        0xff7D91E4,
-        0xff9B80ED,
-        0xff85AE38,
-        0xffAFAFAF,
-        0xffDE9B93,
-        0xff7DC2CA,
-        0xffCF90F2,
-        0xff8DCD68,
-        0xffAB9FFF,
-        0xffB3BE51,
-        0xffD5A673,
-        0xffC6B35B,
-        0xffA9C351,
-        0xffDF91C7,
-        0xff7DCC96,
-        0xff97ABFD,
-        0xffB59AFF,
-        0xff9FC755,
-        0xffE1E1E1,
-        0xffFFCFC6,
-        0xffB2F4FC,
-        0xffFFC4FF,
-        0xffC1FE9D,
-        0xffDDD2FF,
-        0xffE5F088,
-        0xffFFD9A8,
-        0xffF7E591,
-        0xffDBF588,
-        0xffFFC4F9,
-        0xffB1FEC9,
-        0xffCBDDFF,
-        0xffE7CDFF,
-        0xffD2F98C
+
+void make_plus4_palette()
+{
+    int rgb[] =
+    {
+        0x000000,
+        0x2C2C2C,
+        0x621307,
+        0x00424C,
+        0x510378,
+        0x004E00,
+        0x27188E,
+        0x303E00,
+        0x582100,
+        0x463000,
+        0x244400,
+        0x630448,
+        0x004E0C,
+        0x0E2784,
+        0x33118E,
+        0x184800,
+        0x3B3B3B,
+        0x702419,
+        0x00505A,
+        0x601685,
+        0x125D00,
+        0x36289B,
+        0x3F4C00,
+        0x663100,
+        0x553F00,
+        0x345200,
+        0x711656,
+        0x005C1D,
+        0x1F3691,
+        0x42229B,
+        0x285700,
+        0x424242,
+        0x772C21,
+        0x055861,
+        0x661E8C,
+        0x1B6400,
+        0x3E30A2,
+        0x475400,
+        0x6D3900,
+        0x5C4700,
+        0x3B5900,
+        0x771F5D,
+        0x046325,
+        0x273E98,
+        0x492AA1,
+        0x305E00,
+        0x515151,
+        0x843B31,
+        0x17656F,
+        0x742E99,
+        0x2B7100,
+        0x4C3FAF,
+        0x556200,
+        0x7A4709,
+        0x6A5500,
+        0x4A6700,
+        0x852F6B,
+        0x177135,
+        0x364CA5,
+        0x5739AE,
+        0x3F6B00,
+        0x7A7A7A,
+        0xAC665C,
+        0x468E97,
+        0x9C5AC0,
+        0x57992E,
+        0x766AD5,
+        0x7E8A13,
+        0xA2713A,
+        0x927E20,
+        0x748F14,
+        0xAC5A93,
+        0x459960,
+        0x6276CB,
+        0x8064D4,
+        0x6A9419,
+        0x959595,
+        0xC58178,
+        0x62A8B1,
+        0xB675D9,
+        0x73B34C,
+        0x9185ED,
+        0x99A433,
+        0xBB8C57,
+        0xAC993E,
+        0x8FAA34,
+        0xC676AD,
+        0x62B37B,
+        0x7D91E4,
+        0x9B80ED,
+        0x85AE38,
+        0xAFAFAF,
+        0xDE9B93,
+        0x7DC2CA,
+        0xCF90F2,
+        0x8DCD68,
+        0xAB9FFF,
+        0xB3BE51,
+        0xD5A673,
+        0xC6B35B,
+        0xA9C351,
+        0xDF91C7,
+        0x7DCC96,
+        0x97ABFD,
+        0xB59AFF,
+        0x9FC755,
+        0xE1E1E1,
+        0xFFCFC6,
+        0xB2F4FC,
+        0xFFC4FF,
+        0xC1FE9D,
+        0xDDD2FF,
+        0xE5F088,
+        0xFFD9A8,
+        0xF7E591,
+        0xDBF588,
+        0xFFC4F9,
+        0xB1FEC9,
+        0xCBDDFF,
+        0xE7CDFF,
+        0xD2F98C
     };
-    for (int i = 0; i < g_maxcolors; i++) {
-        rgb[i] = rgb[i] & 0xffffff;
-        makecolor(i, rgb[i] >> 16, (rgb[i] & 0xff00FF00) >> 8, rgb[i] & 0xff0000FF);
+    for (int i = 0; i < g_maxcolors; i++)
+    {
+        makecolor(i, (rgb[i] >> 16) & 0xff, (rgb[i] >> 8) & 0xff, rgb[i] & 0xff);
     }
 }
 
-void make_msx_palette() {
-    int rgb[] = {
-        0xff000000,
-        0xff000000,
-        0xff3EB849,
-        0xff74D07D,
-        0xff5955E0,
-        0xff8076F1,
-        0xffB95E51,
-        0xff65DBEF,
-        0xffDB6559,
-        0xffFF897D,
-        0xffCCC35E,
-        0xffDED087,
-        0xff3AA241,
-        0xffB766B5,
-        0xffCCCCCC,
-        0xffFFFFFF
+
+void make_msx_palette()
+{
+    int rgb[] =
+    {
+        0x000000,
+        0x000000,
+        0x3EB849,
+        0x74D07D,
+        0x5955E0,
+        0x8076F1,
+        0xB95E51,
+        0x65DBEF,
+        0xDB6559,
+        0xFF897D,
+        0xCCC35E,
+        0xDED087,
+        0x3AA241,
+        0xB766B5,
+        0xCCCCCC,
+        0xFFFFFF
     };
 
-    for (int i = 0; i < g_maxcolors; i++) {
-        rgb[i] = rgb[i] & 0xffffff;
-        g_grids[i] = rgb[i] + 0xff1f1f1f;
-        makecolor(i, (rgb[i] >> 16), (rgb[i] & 0xff00FF00) >> 8, rgb[i] & 0xff0000FF);
+    for (int i = 0; i < g_maxcolors; i++)
+    {
+        g_grids[i] = (rgb[i] + 0x1f1f1f) | 0xff000000;
+        makecolor(i, (rgb[i] >> 16) & 0xff, (rgb[i] >> 8) & 0xff, rgb[i] & 0xff);
     }
+
     g_grids[5] = 0xff9f95Ff;
     g_grids[7] = 0xff84faEF;
     g_grids[9] = 0xffffa99d;
@@ -1525,24 +1530,27 @@
     g_gridmode = NEW;
 }
 
-void make_spectrum_palette() {
-    int rgb[] = {
-        0xff000000,
-        0xff0000C0,
-        0xffC00000,
-        0xffC000C0,
-        0xff00C000,
-        0xff00C0C0,
-        0xffC0C000,
-        0xffC0C0C0,
-        0xff000000,
-        0xff0000FF,
-        0xffFF0000,
-        0xffFF00FF,
-        0xff00FF00,
-        0xff00FFFF,
-        0xffFFFF00,
-        0xffFFFFFF
+
+void make_spectrum_palette()
+{
+    int rgb[] =
+    {
+        0x000000,
+        0x0000C0,
+        0xC00000,
+        0xC000C0,
+        0x00C000,
+        0x00C0C0,
+        0xC0C000,
+        0xC0C0C0,
+        0x000000,
+        0x0000FF,
+        0xFF0000,
+        0xFF00FF,
+        0x00FF00,
+        0x00FFFF,
+        0xFFFF00,
+        0xFFFFFF
     };
 
     g_grids[9] = 0xff0000d8;
@@ -1552,12 +1560,13 @@
     g_grids[13] = 0xff00d8d8;
     g_grids[14] = 0xffd8d800;
     g_grids[15] = 0xffd8d8d8;
-    for (int i = 0; i < g_maxcolors; i++) {
-        rgb[i] = rgb[i] & 0xffffff;
-        if (i <= 8) {
-            g_grids[i] = rgb[i] + 0xff282828;
-        }
-        makecolor(i, (rgb[i] >> 16), (rgb[i] & 0xff00FF00) >> 8, rgb[i] & 0xff0000FF);
+
+    for (int i = 0; i < g_maxcolors; i++)
+    {
+        if (i <= 8)
+            g_grids[i] = (rgb[i] + 0x282828) | 0xff000000;
+
+        makecolor(i, (rgb[i] >> 16) & 0xff, (rgb[i] >> 8) & 0xff, rgb[i] & 0xff);
     }
     g_gridmode = NEW;
 }
@@ -1566,7 +1575,15 @@
 void mpSetupMachine(int m)
 {
     machine = m;
+
+    g_name = "ERROR";
     g_exportext = "none";
+    g_exportname = "";
+    g_formatname = "";
+    g_formatext = "";
+    g_formatname = "";
+    g_formatext = "";
+
     g_map[3] = byte(machine);
     g_map[13] = byte(machine);
     g_palsteps = 0;
@@ -1576,8 +1593,6 @@
     g_charlimit = 0;
     g_hzoomer = 1;
     g_backmode = 0;
-    g_formatname = "";
-    g_formatext = "";
     g_maxcolors = 16;
     X = 320;
     Y = 200;
--- a/multipaint.pde	Wed Aug 15 15:55:14 2018 +0300
+++ b/multipaint.pde	Thu Aug 16 13:00:03 2018 +0300
@@ -81,7 +81,7 @@
 //dimensions
 int X, Y, MX, MY;
 //generic mouse
-boolean g_klikkeri;
+boolean g_klikkeri, g_iconmode = false;
 int g_ofx, g_ofy, g_button, g_realbutton, g_mx, g_my, g_orx, g_ory, g_msx, g_msy;
 //rubberband,mouse
 int g_phase, g_rx, g_ry, g_rx2, g_ry2, g_rubbermode;
@@ -90,7 +90,7 @@
 int g_windowx, g_windowy, g_maglocx, g_maglocy;
 int g_hedge, g_vedge, g_uizoom, g_wzoom;
 //icons & gui stuff
-int g_iconx, g_icony, g_piconx, g_picony, g_iconmode;
+int g_iconx, g_icony, g_piconx, g_picony;
 int g_gridx, g_gridy, g_spare;
 int g_farge, g_backg, g_ofarge, g_repanel, g_msgctr;
 //machine related color properties