N5110 library

Fork of N5110 by Craig Evans

Revision:
42:596c207519de
Parent:
36:00ebd449b6f3
Child:
43:c2598020fcac
--- a/N5110.cpp	Wed Mar 08 16:13:08 2017 +0000
+++ b/N5110.cpp	Tue Mar 21 10:43:19 2017 +0000
@@ -191,11 +191,13 @@
 // Pixels are addressed in the range of 0 to 47 (y) and 0 to 83 (x).  The refresh()
 // function must be called after set and clear in order to update the display
 void N5110::setPixel(unsigned int const x,
-                     unsigned int const y)
+                     unsigned int const y,
+                     bool const         state)
 {
     if (x<WIDTH && y<HEIGHT) {  // check within range
         // calculate bank and shift 1 to required position in the data byte
-        buffer[x][y/8] |= (1 << y%8);
+        if(state) buffer[x][y/8] |= (1 << y%8);
+        else      buffer[x][y/8] &= ~(1 << y%8);
     }
 }
 
@@ -389,10 +391,9 @@
             // do linear interpolation
             int y = y0 + (y1-y0)*(x-x0)/(x1-x0);
 
-            if (type == 0)   // if 'white' line, turn off pixel
-                clearPixel(x,y);
-            else
-                setPixel(x,y);  // else if 'black' or 'dotted' turn on pixel
+            // If the line type is '0', this will clear the pixel
+            // If it is '1' or '2', the pixel will be set
+            setPixel(x,y, type);
         }
     } else {
 
@@ -404,11 +405,9 @@
             // do linear interpolation
             int x = x0 + (x1-x0)*(y-y0)/(y1-y0);
 
-            if (type == 0)   // if 'white' line, turn off pixel
-                clearPixel(x,y);
-            else
-                setPixel(x,y);  // else if 'black' or 'dotted' turn on pixel
-
+            // If the line type is '0', this will clear the pixel
+            // If it is '1' or '2', the pixel will be set
+            setPixel(x,y, type);
         }
     }
 
@@ -434,23 +433,16 @@
 }
 
 void N5110::drawSprite(int x0,
-                      int y0,
-                      int nrows,
-                      int ncols,
-                      int *sprite)
+                       int y0,
+                       int nrows,
+                       int ncols,
+                       int *sprite)
 { 
     for (int i = 0; i < nrows; i++) {
         for (int j = 0 ; j < ncols ; j++) {
 
             int pixel = *((sprite+i*ncols)+j);
-
-            if (pixel) {
-                setPixel(x0+j,y0+i);
-            }
-            else {
-                clearPixel(x0+j,y0+i);    
-            }
-
+            setPixel(x0+j,y0+i, pixel);
         }
     }
 }
\ No newline at end of file