diff draw_inputs.pde @ 7:c848a6133cfc

Fix many calculations (divisions) that assume integer variable division semantics by truncating to int(). Also add two helper functions chop2(v) and chop8(v) and use them where appropriate.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 03 Jul 2018 22:17:48 +0300
parents a1261cd4c676
children 72407a4d9539
line wrap: on
line diff
--- a/draw_inputs.pde	Tue Jul 03 21:27:18 2018 +0300
+++ b/draw_inputs.pde	Tue Jul 03 22:17:48 2018 +0300
@@ -28,11 +28,11 @@
 //the "slow" call to mark "dirty block"
 void updatepoint(int xx, int yy) {
     if (yy < 0 || xx < 0 || xx >= X || yy >= Y) return;
-    xx = xx / 8;
-    yy = yy / 8;
-    xx = xx + yy * MX;
-    g_redo[xx] = byte(0); //block update
-    g_remdo[xx] = byte(1); //block update
+    xx = int(xx / 8);
+    yy = int(yy / 8);
+    int ad = xx + yy * MX;
+    g_redo[ad] = byte(0); //block update
+    g_remdo[ad] = byte(1); //block update
 }
 
 int getmultibrush(int x1, int y1) {
@@ -43,7 +43,7 @@
     if (g_multic == 2) return g_brush[1024 + x1 + y1 * X];
 
     ad = 1024 + x1 + y1 * X;
-    looks = 65536 + (x1 / 8) + (y1 / 8) * MX;
+    looks = 65536 + int(x1 / 8) + int(y1 / 8) * MX;
     mmc = g_brush[ad] + g_brush[ad + 1] * 2;
     switch (mmc) {
         case 0:
@@ -71,12 +71,11 @@
         if (mode == 0) return g_map[looks];
         if (mode == 1) return g_brush[looks];
     }
-    x1 = x1 / 2;
-    x1 = x1 * 2;
+    x1 = chop2(x1);
     ad = 1024 + x1 + y1 * X;
     source1 = 0;
     source2 = 0;
-    looks = 65536 + (x1 / 8) + (y1 / 8) * MX;
+    looks = 65536 + int(x1 / 8) + int(y1 / 8) * MX;
     if (mode == 0) {
         source1 = g_map[ad];
         source2 = g_map[ad + 1];
@@ -134,8 +133,8 @@
         if (mode == 0) return getmultic(xx, yy, 0);
         return g_map[1]; // was 0?
     }
-    xx = xx / 8;
-    yv = yy / 8;
+    xx = int(xx / 8);
+    yv = int(yy / 8);
     int ad = 65536 + xx + yy * MX;
     if (mode == 0) {
         val = g_map[ad];
@@ -155,8 +154,7 @@
     int chek;
     val = 0;
     sad = 1024 + xx + yy * X;
-    xx = xx / 8;
-    ad = 65536 + xx + yy * MX;
+    ad = 65536 + int(xx / 8) + yy * MX;
     chek = int(g_map[sad]);
     if (chek == 100 || chek == 200) return chek;
 
@@ -270,10 +268,10 @@
     int horisize;
     int molox = 1;
     if (g_multic == 1) molox = 2;
-    horisize = X / g_animx;
+    horisize = int(X / g_animx);
     g_animno = g_animno + 1;
     if (g_animno > g_animframes) g_animno = 1;
-    by = g_animno / horisize;
+    by = int(g_animno / horisize);
     bx = g_animno - (by * horisize);
     g_bsourcex = bx * g_animx;
     g_bsourcey = by * g_animy;
@@ -293,12 +291,10 @@
     xx = xx + g_raster_offset_x * molox;
     yy = yy + g_raster_offset_y;
     if (g_multic == 1 || g_hzoomer == 2) {
-        xx = xx / 2;
+        xx = int(xx / 2);
     }
-    int mx = xx / 8;
-    int my = yy / 8;
-    mx = mx * 8;
-    my = my * 8;
+    int mx = chop8(xx);
+    int my = chop8(yy);
     xx = xx - mx;
     yy = yy - my;
     return g_fixedraster[xx + yy * 8];