2 Commits 9759ec395d ... 4c5d7950e0

Autore SHA1 Messaggio Data
  Legimet 4c5d7950e0 Temporarily use OLD_SCREEN_API before adding HW-W compatibility 8 anni fa
  Legimet 21cc49ef3f Indentation change 9 anni fa
9 ha cambiato i file con 1290 aggiunte e 1290 eliminazioni
  1. 1 1
      Makefile
  2. 77 77
      floodfill.h
  3. 250 250
      framebuffer.h
  4. 263 263
      fs.c
  5. 83 83
      main.c
  6. 37 37
      module.c
  7. 5 5
      module.h
  8. 170 170
      nsp_keys.c
  9. 404 404
      nsp_texture.c

+ 1 - 1
Makefile

@@ -7,7 +7,7 @@ GENZEHN = genzehn
 BUILD_DATE = $(shell date '+%Y-%m-%d')
 VERSION = $(shell git describe --always --dirty 2> /dev/null || echo $(VERSION_SHORT))
 GCCFLAGS = -std=gnu11 -Wall -W -marm -fstrict-aliasing -fomit-frame-pointer -ffunction-sections -fdata-sections \
-	   -DBUILD_DATE=\"$(BUILD_DATE)\" -DVERSION=\"$(VERSION)\"
+	   -DBUILD_DATE=\"$(BUILD_DATE)\" -DVERSION=\"$(VERSION)\" -DOLD_SCREEN_API
 LDFLAGS = -Wl,--gc-sections,--nspireio
 ZEHNFLAGS = --name "Duktape-nspire" --author "Legimet" --notice "JavaScript (ECMAScript) interpreter using Duktape"
 

+ 77 - 77
floodfill.h

@@ -21,85 +21,85 @@
 
 
 
- /***************************************
+/***************************************
  * Flood fill : non recursive algorithm *
  ***************************************/
 
-  // later look at : http://www.codeproject.com/Articles/6017/QuickFill-An-efficient-flood-fill-algorithm
-
-	typedef struct ffnode_ { void* next; int x, y; } ffnode_t;
-  typedef struct queue_ { ffnode_t* head; ffnode_t* last; } queue_t;
-
-  bool _isEmpty(queue_t* queue) {
-  	return queue->head == NULL;
-  }
-  
-  void _add(queue_t* queue, ffnode_t* node) {
-  	if ( queue->head == NULL ) { queue->head = node; }
-  	if ( queue->last != NULL ) { queue->last->next = node; }
-  	queue->last = node;
-  }
-  
-  ffnode_t* _remove(queue_t* queue) {
-  	if ( queue->head == NULL ) { return NULL; }
-  	ffnode_t* rem = queue->head;
-  	queue->head = queue->head->next;
-  	return rem;
-  }
-
-
-  queue_t* new_queue() {
-	    queue_t *queue = (queue_t*)malloc(sizeof(queue_t));
-	    queue->head = NULL;
-	    queue->last = NULL;
-	    return queue;
-	}
-	
-	ffnode_t* new_ffnode(int x, int y) {
-	    ffnode_t *node = (ffnode_t*)malloc(sizeof(ffnode_t));
-	    node->x = x; node->y = y;
-	    node->next = NULL;
-	    return node;
-	}
-	
-	// beware w/ memeroy hole
-	void flood_fill(uint16_t* image, int imageWidth, int imageHeight, int startx, int starty, uint16_t color) {
-	    ffnode_t *node = NULL;
-	    ffnode_t *w = NULL;
-	    ffnode_t *e = NULL;
-	    ffnode_t *n = NULL;
-	    ffnode_t *s = NULL;
-	
-	    queue_t* q = new_queue();
-	
-	    node = new_ffnode(startx, starty);
-	    _add(q,node);
-	    
-	    while ( !_isEmpty(q) ) {
-	    	node = _remove(q);
-	    	 if ( node->x >= 0 && node->x < imageWidth && node->y >= 0 && node->y < imageHeight ) {
-	        if (image[ (node->y*imageWidth)+node->x ] != color) {
-	
-	            image[ (node->y*imageWidth)+node->x ] = color;
-
-	            e=new_ffnode( node->x+1, node->y );
-	            _add(q,e);
-	            
-							w=new_ffnode( node->x-1, node->y );
-							_add(q,w);
-							
-							s=new_ffnode( node->x, node->y+1 );
-							_add(q,s);
-							
-							n=new_ffnode( node->x, node->y-1 );
-              _add(q,n);
-	        }
-	      }
-	      //node = NULL;
-	      free(node);
-	    }
-	    //q = NULL;
-	    free(q);
+// later look at : http://www.codeproject.com/Articles/6017/QuickFill-An-efficient-flood-fill-algorithm
+
+typedef struct ffnode_ { void* next; int x, y; } ffnode_t;
+typedef struct queue_ { ffnode_t* head; ffnode_t* last; } queue_t;
+
+bool _isEmpty(queue_t* queue) {
+	return queue->head == NULL;
+}
+
+void _add(queue_t* queue, ffnode_t* node) {
+	if ( queue->head == NULL ) { queue->head = node; }
+	if ( queue->last != NULL ) { queue->last->next = node; }
+	queue->last = node;
+}
+
+ffnode_t* _remove(queue_t* queue) {
+	if ( queue->head == NULL ) { return NULL; }
+	ffnode_t* rem = queue->head;
+	queue->head = queue->head->next;
+	return rem;
+}
+
+
+queue_t* new_queue() {
+	queue_t *queue = (queue_t*)malloc(sizeof(queue_t));
+	queue->head = NULL;
+	queue->last = NULL;
+	return queue;
+}
+
+ffnode_t* new_ffnode(int x, int y) {
+	ffnode_t *node = (ffnode_t*)malloc(sizeof(ffnode_t));
+	node->x = x; node->y = y;
+	node->next = NULL;
+	return node;
+}
+
+// beware w/ memeroy hole
+void flood_fill(uint16_t* image, int imageWidth, int imageHeight, int startx, int starty, uint16_t color) {
+	ffnode_t *node = NULL;
+	ffnode_t *w = NULL;
+	ffnode_t *e = NULL;
+	ffnode_t *n = NULL;
+	ffnode_t *s = NULL;
+
+	queue_t* q = new_queue();
+
+	node = new_ffnode(startx, starty);
+	_add(q,node);
+
+	while ( !_isEmpty(q) ) {
+		node = _remove(q);
+		if ( node->x >= 0 && node->x < imageWidth && node->y >= 0 && node->y < imageHeight ) {
+			if (image[ (node->y*imageWidth)+node->x ] != color) {
+
+				image[ (node->y*imageWidth)+node->x ] = color;
+
+				e=new_ffnode( node->x+1, node->y );
+				_add(q,e);
+
+				w=new_ffnode( node->x-1, node->y );
+				_add(q,w);
+
+				s=new_ffnode( node->x, node->y+1 );
+				_add(q,s);
+
+				n=new_ffnode( node->x, node->y-1 );
+				_add(q,n);
+			}
+		}
+		//node = NULL;
+		free(node);
 	}
+	//q = NULL;
+	free(q);
+}
 
-#endif
+#endif

+ 250 - 250
framebuffer.h

@@ -49,302 +49,302 @@ typedef struct FbDev {
 #include "floodfill.h"
 
 
-	void __floodFill(int x, int y, Color_t color, FbDev* fb) {
-		/* -makes a stack overflow -
-		 if ( x >= 0 && x < fb->width && y >= 0 && y < fb->height && _getPixel(x,y,fb) != color) {
-			 _setPixel(x,y,color,fb);
-			 __floodFill(x - 1, y, color, fb);
-			 __floodFill(x, y - 1, color, fb);
-			 __floodFill(x, y + 1, color, fb);
-			 __floodFill(x + 1, y, color, fb);
-		 }
-		 */ 
-		 flood_fill(fb->fb, fb->width, fb->height, x, y, color);
-	}
+void __floodFill(int x, int y, Color_t color, FbDev* fb) {
+	/* -makes a stack overflow -
+	   if ( x >= 0 && x < fb->width && y >= 0 && y < fb->height && _getPixel(x,y,fb) != color) {
+	   _setPixel(x,y,color,fb);
+	   __floodFill(x - 1, y, color, fb);
+	   __floodFill(x, y - 1, color, fb);
+	   __floodFill(x, y + 1, color, fb);
+	   __floodFill(x + 1, y, color, fb);
+	   }
+	   */ 
+	flood_fill(fb->fb, fb->width, fb->height, x, y, color);
+}
+
+// not the real scan lines impl.
+// yes it's a dirty impl. ;(
+void __scanFill(int xMin, int yMin, int xMax, int yMax, int* xys, int nbPts, Color_t color, FbDev* fb) {
+	//int xpts[20]; // max 20 sommets par lignes
+	int xptsCnt = 0;
+
+	int insideX = -999;
+	int insideY = -999;
+
+	for (int y = yMin; y <= yMax; y++) {
+		xptsCnt = 0;
+		for (int i = 0; i < nbPts; i++) {
+			if (xys[(i * 2) + 1] == y) {
+				//xpts[xptsCnt++] = (i * 2) + 0;
+				xptsCnt++;
+			}
+		}
 
-	// not the real scan lines impl.
-	// yes it's a dirty impl. ;(
-	void __scanFill(int xMin, int yMin, int xMax, int yMax, int* xys, int nbPts, Color_t color, FbDev* fb) {
-		//int xpts[20]; // max 20 sommets par lignes
-		int xptsCnt = 0;
-
-		int insideX = -999;
-		int insideY = -999;
-
-		for (int y = yMin; y <= yMax; y++) {
-			xptsCnt = 0;
-			for (int i = 0; i < nbPts; i++) {
-				if (xys[(i * 2) + 1] == y) {
-					//xpts[xptsCnt++] = (i * 2) + 0;
-					xptsCnt++;
+		bool inside = false;
+		int startX = -999, stopX = -999;
+		for (int x = xMin; x <= xMax; x++) {
+			if (xptsCnt > 0) {
+				// noting
+				break;
+			} else {
+				if (_getPixel(x, y, fb) == color) {
+					inside = !inside;
+				}
+				if (inside && startX == -999) {
+					startX = x;
 				}
-			}
 
-			bool inside = false;
-			int startX = -999, stopX = -999;
-			for (int x = xMin; x <= xMax; x++) {
-				if (xptsCnt > 0) {
-					// noting
+				if (!inside && x == startX + 1) {
 					break;
-				} else {
-					if (_getPixel(x, y, fb) == color) {
-						inside = !inside;
-					}
-					if (inside && startX == -999) {
-						startX = x;
-					}
-
-					if (!inside && x == startX + 1) {
-						break;
-					}
-
-					if (!inside && startX > -999 && x > startX + 1) {
-						stopX = x;
-					}
-
-					if (startX > -999 && stopX > -999 && stopX - startX > 2) {
-						insideX = startX + 1;
-						break;
-					}
+				}
 
+				if (!inside && startX > -999 && x > startX + 1) {
+					stopX = x;
 				}
-			}
-			if (insideX > -999) {
-				insideY = y;
-				break;
+
+				if (startX > -999 && stopX > -999 && stopX - startX > 2) {
+					insideX = startX + 1;
+					break;
+				}
+
 			}
 		}
-
-		if (insideX > -999 && insideY > -999) {
-			__floodFill(insideX, insideY, color, fb);
+		if (insideX > -999) {
+			insideY = y;
+			break;
 		}
-
 	}
 
-  // just a Color for during the fill Op
-  // const Color_t TEMP_FILL_COLOR = (15 << 11 | 15 << 5 | 15);
-  const Color_t TEMP_FILL_COLOR = (1 << 11 | 1 << 5 | 1);
-
-	void __replaceByFillColor(int startAddr, int endAddr, Color_t color, FbDev* fb) {
-			if (startAddr < 0) {
-				startAddr = 0;
-			}
-			if (endAddr >= fb->fb_size) {
-				endAddr = fb->fb_size - 1;
-			}
-			for (int i = startAddr; i <= endAddr; i++) {
-				if (fb->fb[i] == TEMP_FILL_COLOR)
-					fb->fb[i] = color;
-			}
+	if (insideX > -999 && insideY > -999) {
+		__floodFill(insideX, insideY, color, fb);
 	}
-	
-	// ========================================
-
-		void setPixel(int x, int y, Color_t color, FbDev* fb) {
-			if (x < 0) {
-				return;
-			} else if (x >= fb->width) {
-				return;
-			}
 
-			if (y < 0) {
-				return;
-			} else if (y >= fb->height) {
-				return;
-			}
+}
 
-			_setPixel(x,y,color,fb);
-		}
+// just a Color for during the fill Op
+// const Color_t TEMP_FILL_COLOR = (15 << 11 | 15 << 5 | 15);
+const Color_t TEMP_FILL_COLOR = (1 << 11 | 1 << 5 | 1);
 
-		int getPixel(int x, int y, FbDev* fb) {
-			return _getPixel(x,y,fb);
-		}
+void __replaceByFillColor(int startAddr, int endAddr, Color_t color, FbDev* fb) {
+	if (startAddr < 0) {
+		startAddr = 0;
+	}
+	if (endAddr >= fb->fb_size) {
+		endAddr = fb->fb_size - 1;
+	}
+	for (int i = startAddr; i <= endAddr; i++) {
+		if (fb->fb[i] == TEMP_FILL_COLOR)
+			fb->fb[i] = color;
+	}
+}
 
-		// ====================
-		// where a is float
-		#define __round(a) ( (int) (a + 0.5F) )
-		// where a is int
-		#define __fabs(a) ( a >= 0 ? a : -a )
-
-		void drawHorizLine(int x1, int x2, int y, Color_t rgb, FbDev* fb) {
-			if (x2 < x1) {
-				int tmp = x1;
-				x1 = x2;
-				x2 = tmp;
-			}
-			// int row = (y * SCREEN_WIDTH);
-			for (int i = x1; i <= x2; i++) {
-				setPixel(i, y, rgb, fb);
-				// fb[row + i] = rgb;
-			}
-		}
+// ========================================
 
-		void drawVertLine(int y1, int y2, int x, Color_t rgb, FbDev* fb) {
-			if (y2 < y1) {
-				int tmp = y1;
-				y1 = y2;
-				y2 = tmp;
-			}
-			for (int i = y1; i <= y2; i++) {
-				setPixel(x, i, rgb, fb);
-			}
-		}
+void setPixel(int x, int y, Color_t color, FbDev* fb) {
+	if (x < 0) {
+		return;
+	} else if (x >= fb->width) {
+		return;
+	}
 
-		void drawLine(int x1, int y1, int x2, int y2, Color_t rgb, FbDev* fb) {
-			if (y1 == y2) {
-				drawHorizLine(x1, x2, y1, rgb, fb);
-			} else if (x1 == x2) {
-				drawVertLine(y1, y2, x1, rgb, fb);
-			} else {
-				int dx = x2 - x1, dy = y2 - y1, steps, k;
-				float xIncrement, yIncrement, x = x1, y = y1;
+	if (y < 0) {
+		return;
+	} else if (y >= fb->height) {
+		return;
+	}
 
-				if (__fabs(dx) > __fabs(dy)) {
-					steps = __fabs(dx);
-				} else {
-					steps = __fabs(dy);
-				}
-				xIncrement = (float) dx / (float) steps;
-				yIncrement = (float) dy / (float) steps;
-				setPixel(__round(x), __round(y), rgb, fb);
-				for (k = 0; k < steps; k++) {
-					x += xIncrement;
-					y += yIncrement;
-					setPixel(__round(x), __round(y), rgb, fb);
-				}
-			}
-		}
+	_setPixel(x,y,color,fb);
+}
 
+int getPixel(int x, int y, FbDev* fb) {
+	return _getPixel(x,y,fb);
+}
 
-	  // ============
+// ====================
+// where a is float
+#define __round(a) ( (int) (a + 0.5F) )
+// where a is int
+#define __fabs(a) ( a >= 0 ? a : -a )
 
+void drawHorizLine(int x1, int x2, int y, Color_t rgb, FbDev* fb) {
+	if (x2 < x1) {
+		int tmp = x1;
+		x1 = x2;
+		x2 = tmp;
+	}
+	// int row = (y * SCREEN_WIDTH);
+	for (int i = x1; i <= x2; i++) {
+		setPixel(i, y, rgb, fb);
+		// fb[row + i] = rgb;
+	}
+}
 
-		void drawRect(int x, int y, int w, int h, Color_t color, FbDev* fb) {
-			drawHorizLine(x, x + w, y, color, fb);
-			drawHorizLine(x, x + w, y + h, color, fb);
-			drawVertLine(y, y + h, x, color, fb);
-			drawVertLine(y, y + h, x + w, color, fb);
+void drawVertLine(int y1, int y2, int x, Color_t rgb, FbDev* fb) {
+	if (y2 < y1) {
+		int tmp = y1;
+		y1 = y2;
+		y2 = tmp;
+	}
+	for (int i = y1; i <= y2; i++) {
+		setPixel(x, i, rgb, fb);
+	}
+}
+
+void drawLine(int x1, int y1, int x2, int y2, Color_t rgb, FbDev* fb) {
+	if (y1 == y2) {
+		drawHorizLine(x1, x2, y1, rgb, fb);
+	} else if (x1 == x2) {
+		drawVertLine(y1, y2, x1, rgb, fb);
+	} else {
+		int dx = x2 - x1, dy = y2 - y1, steps, k;
+		float xIncrement, yIncrement, x = x1, y = y1;
+
+		if (__fabs(dx) > __fabs(dy)) {
+			steps = __fabs(dx);
+		} else {
+			steps = __fabs(dy);
 		}
-
-		void fillRect(int x, int y, int w, int h, Color_t color, FbDev* fb) {
-			drawRect(x, y, w, h, TEMP_FILL_COLOR, fb);
-			__floodFill(x + (w >> 1), y + (h >> 1), TEMP_FILL_COLOR, fb);
-			// /!\ let () around (y+h) Cf defined macro & args
-			__replaceByFillColor(_getAddr(x, y, fb), _getAddr( (x + w), (y + h), fb), color, fb);
+		xIncrement = (float) dx / (float) steps;
+		yIncrement = (float) dy / (float) steps;
+		setPixel(__round(x), __round(y), rgb, fb);
+		for (k = 0; k < steps; k++) {
+			x += xIncrement;
+			y += yIncrement;
+			setPixel(__round(x), __round(y), rgb, fb);
 		}
+	}
+}
 
 
-		// ========================================
+// ============
 
-		void drawPolyLines(int* xys, int nbPts, Color_t color, FbDev* fb) {
-			for (int i = 0; i < nbPts - 1; i++) {
-				drawLine(xys[(2 * i) + 0], xys[(2 * i) + 1], xys[(2 * i) + 2], xys[(2 * i) + 3], color, fb);
-			}
-		}
 
-		void fillPolygon(int* xys, int nbPts, Color_t color, FbDev* fb) {
-			int x1, x2, y1, y2, xMin = SCREEN_WIDTH + 10, xMax = -10, yMin = SCREEN_HEIGHT + 10, yMax = -10;
+void drawRect(int x, int y, int w, int h, Color_t color, FbDev* fb) {
+	drawHorizLine(x, x + w, y, color, fb);
+	drawHorizLine(x, x + w, y + h, color, fb);
+	drawVertLine(y, y + h, x, color, fb);
+	drawVertLine(y, y + h, x + w, color, fb);
+}
 
-			// drawPolyLines(xys, nbPts, TEMP_FILL_COLOR);
-			for (int i = 0; i < nbPts - 1; i++) {
-				x1 = xys[(2 * i) + 0];
-				y1 = xys[(2 * i) + 1];
-				x2 = xys[(2 * i) + 2];
-				y2 = xys[(2 * i) + 3];
+void fillRect(int x, int y, int w, int h, Color_t color, FbDev* fb) {
+	drawRect(x, y, w, h, TEMP_FILL_COLOR, fb);
+	__floodFill(x + (w >> 1), y + (h >> 1), TEMP_FILL_COLOR, fb);
+	// /!\ let () around (y+h) Cf defined macro & args
+	__replaceByFillColor(_getAddr(x, y, fb), _getAddr( (x + w), (y + h), fb), color, fb);
+}
 
-				if (x1 < xMin) {
-					xMin = x1;
-				}
-				if (x1 > xMax) {
-					xMax = x1;
-				}
 
-				if (x2 < xMin) {
-					xMin = x2;
-				}
-				if (x2 > xMax) {
-					xMax = x2;
-				}
+// ========================================
 
-				if (y1 < yMin) {
-					yMin = y1;
-				}
-				if (y1 > yMax) {
-					yMax = y1;
-				}
+void drawPolyLines(int* xys, int nbPts, Color_t color, FbDev* fb) {
+	for (int i = 0; i < nbPts - 1; i++) {
+		drawLine(xys[(2 * i) + 0], xys[(2 * i) + 1], xys[(2 * i) + 2], xys[(2 * i) + 3], color, fb);
+	}
+}
 
-				if (y2 < yMin) {
-					yMin = y2;
-				}
-				if (y2 > yMax) {
-					yMax = y2;
-				}
+void fillPolygon(int* xys, int nbPts, Color_t color, FbDev* fb) {
+	int x1, x2, y1, y2, xMin = SCREEN_WIDTH + 10, xMax = -10, yMin = SCREEN_HEIGHT + 10, yMax = -10;
 
-				drawLine(x1, y1, x2, y2, TEMP_FILL_COLOR, fb);
-			}
+	// drawPolyLines(xys, nbPts, TEMP_FILL_COLOR);
+	for (int i = 0; i < nbPts - 1; i++) {
+		x1 = xys[(2 * i) + 0];
+		y1 = xys[(2 * i) + 1];
+		x2 = xys[(2 * i) + 2];
+		y2 = xys[(2 * i) + 3];
 
-			// if polygon isn't closed : close it
-			if (!(xys[0] == xys[(nbPts * 2) - 2] && xys[1] == xys[(nbPts * 2) - 1])) {
-				x1 = xys[0];
-				y1 = xys[1];
-				x2 = xys[(nbPts * 2) - 2];
-				y2 = xys[(nbPts * 2) - 1];
+		if (x1 < xMin) {
+			xMin = x1;
+		}
+		if (x1 > xMax) {
+			xMax = x1;
+		}
 
-				if (x1 < xMin) {
-					xMin = x1;
-				}
-				if (x1 > xMax) {
-					xMax = x1;
-				}
+		if (x2 < xMin) {
+			xMin = x2;
+		}
+		if (x2 > xMax) {
+			xMax = x2;
+		}
 
-				if (x2 < xMin) {
-					xMin = x2;
-				}
-				if (x2 > xMax) {
-					xMax = x2;
-				}
+		if (y1 < yMin) {
+			yMin = y1;
+		}
+		if (y1 > yMax) {
+			yMax = y1;
+		}
 
-				if (y1 < yMin) {
-					yMin = y1;
-				}
-				if (y1 > yMax) {
-					yMax = y1;
-				}
+		if (y2 < yMin) {
+			yMin = y2;
+		}
+		if (y2 > yMax) {
+			yMax = y2;
+		}
 
-				if (y2 < yMin) {
-					yMin = y2;
-				}
-				if (y2 > yMax) {
-					yMax = y2;
-				}
+		drawLine(x1, y1, x2, y2, TEMP_FILL_COLOR, fb);
+	}
 
-				drawLine(x1, y1, x2, y2, TEMP_FILL_COLOR, fb);
-			}
+	// if polygon isn't closed : close it
+	if (!(xys[0] == xys[(nbPts * 2) - 2] && xys[1] == xys[(nbPts * 2) - 1])) {
+		x1 = xys[0];
+		y1 = xys[1];
+		x2 = xys[(nbPts * 2) - 2];
+		y2 = xys[(nbPts * 2) - 1];
 
-			__scanFill(xMin, yMin, xMax, yMax, xys, nbPts, TEMP_FILL_COLOR, fb);
-			__replaceByFillColor(_getAddr(xMin, yMin, fb), _getAddr(xMax, yMax, fb), color, fb);
+		if (x1 < xMin) {
+			xMin = x1;
+		}
+		if (x1 > xMax) {
+			xMax = x1;
 		}
 
+		if (x2 < xMin) {
+			xMin = x2;
+		}
+		if (x2 > xMax) {
+			xMax = x2;
+		}
 
-		// ============
-
-		void drawCircle(int x, int y, int radius, Color_t color, FbDev* fb) {
-			int startAngle = 0, stopAngle = 90;
-			float fradius = (float) radius;
-			for (int a = startAngle; a <= stopAngle; a++) {
-				int xc = (int) (fradius * __cos[a]);
-				int ys = (int) (fradius * __sin[a]);
-				setPixel(x + xc, y + ys, color, fb);
-				setPixel(x - xc, y + ys, color, fb);
-				setPixel(x + xc, y - ys, color, fb);
-				setPixel(x - xc, y - ys, color, fb);
-			}
+		if (y1 < yMin) {
+			yMin = y1;
+		}
+		if (y1 > yMax) {
+			yMax = y1;
 		}
 
-		void fillCircle(int x, int y, int radius, Color_t color, FbDev* fb) {
-			drawCircle(x, y, radius, TEMP_FILL_COLOR, fb);
-			__floodFill(x, y, TEMP_FILL_COLOR, fb);
-			__replaceByFillColor(_getAddr( (x - radius), (y - radius), fb), _getAddr( (x + radius), (y + radius), fb), color, fb);
+		if (y2 < yMin) {
+			yMin = y2;
+		}
+		if (y2 > yMax) {
+			yMax = y2;
 		}
 
-#endif
+		drawLine(x1, y1, x2, y2, TEMP_FILL_COLOR, fb);
+	}
+
+	__scanFill(xMin, yMin, xMax, yMax, xys, nbPts, TEMP_FILL_COLOR, fb);
+	__replaceByFillColor(_getAddr(xMin, yMin, fb), _getAddr(xMax, yMax, fb), color, fb);
+}
+
+
+// ============
+
+void drawCircle(int x, int y, int radius, Color_t color, FbDev* fb) {
+	int startAngle = 0, stopAngle = 90;
+	float fradius = (float) radius;
+	for (int a = startAngle; a <= stopAngle; a++) {
+		int xc = (int) (fradius * __cos[a]);
+		int ys = (int) (fradius * __sin[a]);
+		setPixel(x + xc, y + ys, color, fb);
+		setPixel(x - xc, y + ys, color, fb);
+		setPixel(x + xc, y - ys, color, fb);
+		setPixel(x - xc, y - ys, color, fb);
+	}
+}
+
+void fillCircle(int x, int y, int radius, Color_t color, FbDev* fb) {
+	drawCircle(x, y, radius, TEMP_FILL_COLOR, fb);
+	__floodFill(x, y, TEMP_FILL_COLOR, fb);
+	__replaceByFillColor(_getAddr( (x - radius), (y - radius), fb), _getAddr( (x + radius), (y + radius), fb), color, fb);
+}
+
+#endif

+ 263 - 263
fs.c

@@ -28,356 +28,356 @@
 #include <fcntl.h>
 
 #define FS_SET_STATS_INT_PROP(ctx, buf, idx, prop) \
-do { \
-    duk_push_int((ctx), (buf)->st_##prop); \
-    duk_put_prop_string((ctx), (idx), #prop); \
-} while (0)
+	do { \
+		duk_push_int((ctx), (buf)->st_##prop); \
+		duk_put_prop_string((ctx), (idx), #prop); \
+	} while (0)
 
 #define FS_SET_STATS_DATE_PROP(ctx, buf, idx1, idx2, prop) \
-do { \
-    duk_get_prop_string((ctx), (idx1), "Date"); \
-    duk_push_int((ctx), buf->st_##prop); \
-    duk_new((ctx), 1); \
-    duk_put_prop_string((ctx), (idx2), #prop); \
-} while (0)
+	do { \
+		duk_get_prop_string((ctx), (idx1), "Date"); \
+		duk_push_int((ctx), buf->st_##prop); \
+		duk_new((ctx), 1); \
+		duk_put_prop_string((ctx), (idx2), #prop); \
+	} while (0)
 
 static duk_ret_t fs_err(duk_context *ctx, bool success, duk_idx_t callback, int callback_args) {
-    if (duk_is_function(ctx, callback)) {
-	duk_dup(ctx, callback);
-	duk_insert(ctx, -callback_args);
-    }
-    if (!success) {
-	duk_push_error_object(ctx, DUK_ERR_ERROR, "%s", strerror(errno));
 	if (duk_is_function(ctx, callback)) {
-	    duk_insert(ctx, -callback_args);
-	}
-    }
-    if (duk_is_function(ctx, callback)) {
-	if (success) {
-	    duk_push_null(ctx);
-	    if (duk_is_function(ctx, callback)) {
+		duk_dup(ctx, callback);
 		duk_insert(ctx, -callback_args);
-	    }
 	}
-	duk_call(ctx, callback_args);
-    } else if (!success) {
-	duk_throw(ctx);
-    }
-    if (callback_args) {
-	return 0;
-    } else {
-	return 1;
-    }
+	if (!success) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "%s", strerror(errno));
+		if (duk_is_function(ctx, callback)) {
+			duk_insert(ctx, -callback_args);
+		}
+	}
+	if (duk_is_function(ctx, callback)) {
+		if (success) {
+			duk_push_null(ctx);
+			if (duk_is_function(ctx, callback)) {
+				duk_insert(ctx, -callback_args);
+			}
+		}
+		duk_call(ctx, callback_args);
+	} else if (!success) {
+		duk_throw(ctx);
+	}
+	if (callback_args) {
+		return 0;
+	} else {
+		return 1;
+	}
 }
 
 static duk_ret_t fs_rename(duk_context *ctx) {
-    bool success = !rename(duk_require_string(ctx, 0), duk_require_string(ctx, 1));
-    return fs_err(ctx, success, 2, 1);
+	bool success = !rename(duk_require_string(ctx, 0), duk_require_string(ctx, 1));
+	return fs_err(ctx, success, 2, 1);
 }
 
 static void fs_init_stats_obj(duk_context *ctx, struct stat *buf) {
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "Stats");
-    duk_new(ctx, 0);
-    FS_SET_STATS_INT_PROP(ctx, buf, -2, dev);
-    FS_SET_STATS_INT_PROP(ctx, buf, -2, ino);
-    FS_SET_STATS_INT_PROP(ctx, buf, -2, mode);
-    FS_SET_STATS_INT_PROP(ctx, buf, -2, nlink);
-    FS_SET_STATS_INT_PROP(ctx, buf, -2, uid);
-    FS_SET_STATS_INT_PROP(ctx, buf, -2, gid);
-    FS_SET_STATS_INT_PROP(ctx, buf, -2, rdev);
-    FS_SET_STATS_INT_PROP(ctx, buf, -2, size);
-    FS_SET_STATS_INT_PROP(ctx, buf, -2, blksize);
-    FS_SET_STATS_INT_PROP(ctx, buf, -2, blocks);
-    duk_push_global_object(ctx);
-    FS_SET_STATS_DATE_PROP(ctx, buf, -1, -3, atime);
-    FS_SET_STATS_DATE_PROP(ctx, buf, -1, -3, mtime);
-    FS_SET_STATS_DATE_PROP(ctx, buf, -1, -3, ctime);
-    duk_swap(ctx, -2, -3);
-    duk_pop_2(ctx);
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "Stats");
+	duk_new(ctx, 0);
+	FS_SET_STATS_INT_PROP(ctx, buf, -2, dev);
+	FS_SET_STATS_INT_PROP(ctx, buf, -2, ino);
+	FS_SET_STATS_INT_PROP(ctx, buf, -2, mode);
+	FS_SET_STATS_INT_PROP(ctx, buf, -2, nlink);
+	FS_SET_STATS_INT_PROP(ctx, buf, -2, uid);
+	FS_SET_STATS_INT_PROP(ctx, buf, -2, gid);
+	FS_SET_STATS_INT_PROP(ctx, buf, -2, rdev);
+	FS_SET_STATS_INT_PROP(ctx, buf, -2, size);
+	FS_SET_STATS_INT_PROP(ctx, buf, -2, blksize);
+	FS_SET_STATS_INT_PROP(ctx, buf, -2, blocks);
+	duk_push_global_object(ctx);
+	FS_SET_STATS_DATE_PROP(ctx, buf, -1, -3, atime);
+	FS_SET_STATS_DATE_PROP(ctx, buf, -1, -3, mtime);
+	FS_SET_STATS_DATE_PROP(ctx, buf, -1, -3, ctime);
+	duk_swap(ctx, -2, -3);
+	duk_pop_2(ctx);
 }
 
 static duk_ret_t fs_stat(duk_context *ctx) {
-    struct stat buf;
-    bool success = !stat(duk_require_string(ctx, 0), &buf);
-    if (success) {
-	fs_init_stats_obj(ctx, &buf);
-    } else {
-	duk_push_undefined(ctx);
-    }
-    return fs_err(ctx, success, 1, 2);
+	struct stat buf;
+	bool success = !stat(duk_require_string(ctx, 0), &buf);
+	if (success) {
+		fs_init_stats_obj(ctx, &buf);
+	} else {
+		duk_push_undefined(ctx);
+	}
+	return fs_err(ctx, success, 1, 2);
 }
 
 static duk_ret_t fs_stat_sync(duk_context *ctx) {
-    struct stat buf;
-    bool success = !stat(duk_require_string(ctx, 0), &buf);
-    if (success) {
-	fs_init_stats_obj(ctx, &buf);
-    }
-    return fs_err(ctx, success, DUK_INVALID_INDEX, 0);
+	struct stat buf;
+	bool success = !stat(duk_require_string(ctx, 0), &buf);
+	if (success) {
+		fs_init_stats_obj(ctx, &buf);
+	}
+	return fs_err(ctx, success, DUK_INVALID_INDEX, 0);
 }
 
 static duk_ret_t fs_unlink(duk_context *ctx) {
-    bool success = !unlink(duk_require_string(ctx, 0));
-    return fs_err(ctx, success, 1, 1);
+	bool success = !unlink(duk_require_string(ctx, 0));
+	return fs_err(ctx, success, 1, 1);
 }
 
 static duk_ret_t fs_rmdir(duk_context *ctx) {
-    bool success = !rmdir(duk_require_string(ctx, 0));
-    return fs_err(ctx, success, 1, 1);
+	bool success = !rmdir(duk_require_string(ctx, 0));
+	return fs_err(ctx, success, 1, 1);
 }
 
 static duk_ret_t fs_mkdir(duk_context *ctx) {
-    bool success;
-    if (duk_is_number(ctx, 1)) {
-	success = !mkdir(duk_require_string(ctx, 0), duk_require_int(ctx, 1));
-	return fs_err(ctx, success, 2, 1);
-    } else {
-	success = !mkdir(duk_require_string(ctx, 0), 0777);
-	return fs_err(ctx, success, 1, 1);
-    }
+	bool success;
+	if (duk_is_number(ctx, 1)) {
+		success = !mkdir(duk_require_string(ctx, 0), duk_require_int(ctx, 1));
+		return fs_err(ctx, success, 2, 1);
+	} else {
+		success = !mkdir(duk_require_string(ctx, 0), 0777);
+		return fs_err(ctx, success, 1, 1);
+	}
 }
 
 static bool fs_init_readdir_arr(duk_context *ctx) {
-    DIR *pdir;
-    struct dirent *pdirent;
-    bool success;
-
-    pdir = opendir(duk_require_string(ctx, 0));
-    if (pdir) {
-	duk_idx_t obj_idx = duk_push_array(ctx);
-	duk_uarridx_t idx = 0;
-	errno = 0;
-	do {
-	    errno = 0;
-	    if ((pdirent = readdir(pdir)) && strcmp(pdirent->d_name, ".") && strcmp(pdirent->d_name, "..")) {
-		duk_push_string(ctx, pdirent->d_name);
-		duk_put_prop_index(ctx, obj_idx, idx);
-	    }
-	    idx++;
-	} while (pdirent != NULL);
-	if (errno) {
-	    int e = errno;
-	    closedir(pdir);
-	    errno = e;
-	    success = false;
-	    duk_pop(ctx);
+	DIR *pdir;
+	struct dirent *pdirent;
+	bool success;
+
+	pdir = opendir(duk_require_string(ctx, 0));
+	if (pdir) {
+		duk_idx_t obj_idx = duk_push_array(ctx);
+		duk_uarridx_t idx = 0;
+		errno = 0;
+		do {
+			errno = 0;
+			if ((pdirent = readdir(pdir)) && strcmp(pdirent->d_name, ".") && strcmp(pdirent->d_name, "..")) {
+				duk_push_string(ctx, pdirent->d_name);
+				duk_put_prop_index(ctx, obj_idx, idx);
+			}
+			idx++;
+		} while (pdirent != NULL);
+		if (errno) {
+			int e = errno;
+			closedir(pdir);
+			errno = e;
+			success = false;
+			duk_pop(ctx);
+		} else {
+			closedir(pdir);
+			success = true;
+		}
 	} else {
-	    closedir(pdir);
-	    success = true;
+		success = false;
 	}
-    } else {
-	success = false;
-    }
-    return success;
+	return success;
 }
 
 static duk_ret_t fs_readdir(duk_context *ctx) {
-    return fs_err(ctx, fs_init_readdir_arr(ctx), 1, 2);
+	return fs_err(ctx, fs_init_readdir_arr(ctx), 1, 2);
 }
 
 static duk_ret_t fs_readdir_sync(duk_context *ctx) {
-    return fs_err(ctx, fs_init_readdir_arr(ctx), DUK_INVALID_INDEX, 0);
+	return fs_err(ctx, fs_init_readdir_arr(ctx), DUK_INVALID_INDEX, 0);
 }
 
 static duk_ret_t fs_close(duk_context *ctx) {
-    bool success = !close(duk_require_int(ctx, 0));
-    return fs_err(ctx, success, 1, 1);
+	bool success = !close(duk_require_int(ctx, 0));
+	return fs_err(ctx, success, 1, 1);
 }
 
 static bool fs_open_get_flags(const char *s, int *flag) {
-    int flag1 = 0;
-    int flag2 = 0;
-
-    switch (s[0]) {
-	case 'r':
-	    flag1 = O_RDONLY;
-	    break;
-	case 'w':
-	    flag1 = O_WRONLY;
-	    flag2 = O_CREAT | O_TRUNC;
-	    break;
-	case 'a':
-	    flag1 = O_WRONLY;
-	    flag2 = O_APPEND | O_TRUNC;
-	    break;
-	default:
-	    return false;
-    }
-
-    switch (s[1]) {
-	case '\0':
-	    break;
-	case '+':
-	    if (s[2])
-		return false;
-	    flag1 = O_RDWR;
-	    break;
-	case 's':
-	    if (flag1 != O_RDONLY || (s[2] != '\0' && s[2] != '+') ||
-		(s[2] == '+' && s[3]))
-		return false;
-	    if (s[2] == '+')
-		flag1 = O_RDWR;
-	    break;
-	case 'x':
-	    if (flag1 != O_WRONLY || (s[2] != '\0' && s[2] != '+') ||
-		(s[2] == '+' && s[3]))
-		return false;
-	    flag2 |= O_EXCL;
-	    if (s[2] == '+')
-		flag1 = O_RDWR;
-	    break;
-	default:
-	    return false;
-    }
-
-    *flag = flag1 | flag2;
-
-    return true;
+	int flag1 = 0;
+	int flag2 = 0;
+
+	switch (s[0]) {
+		case 'r':
+			flag1 = O_RDONLY;
+			break;
+		case 'w':
+			flag1 = O_WRONLY;
+			flag2 = O_CREAT | O_TRUNC;
+			break;
+		case 'a':
+			flag1 = O_WRONLY;
+			flag2 = O_APPEND | O_TRUNC;
+			break;
+		default:
+			return false;
+	}
+
+	switch (s[1]) {
+		case '\0':
+			break;
+		case '+':
+			if (s[2])
+				return false;
+			flag1 = O_RDWR;
+			break;
+		case 's':
+			if (flag1 != O_RDONLY || (s[2] != '\0' && s[2] != '+') ||
+					(s[2] == '+' && s[3]))
+				return false;
+			if (s[2] == '+')
+				flag1 = O_RDWR;
+			break;
+		case 'x':
+			if (flag1 != O_WRONLY || (s[2] != '\0' && s[2] != '+') ||
+					(s[2] == '+' && s[3]))
+				return false;
+			flag2 |= O_EXCL;
+			if (s[2] == '+')
+				flag1 = O_RDWR;
+			break;
+		default:
+			return false;
+	}
+
+	*flag = flag1 | flag2;
+
+	return true;
 }
 
 static duk_ret_t fs_open(duk_context *ctx) {
-    int fd;
-    const char *path = duk_require_string(ctx, 0);
-    const char *flags_str = duk_require_string(ctx, 1);
-    int flags;
-
-    if (!fs_open_get_flags(flags_str, &flags)) {
-	duk_push_error_object(ctx, DUK_ERR_ERROR, "Unknown file open flag: %s", flags_str);
-	duk_throw(ctx);
-    }
-
-    mode_t mode;
-    duk_idx_t callback;
-    if (duk_is_number(ctx, 2)) {
-	mode = duk_get_int(ctx, 2);
-	callback = 3;
-    } else {
-	mode = 0666;
-	callback = 2;
-    }
-    fd = open(path, flags, mode);
-    if (fd != -1) {
-	duk_push_int(ctx, fd);
-    } else {
-	duk_push_undefined(ctx);
-    }
-    return fs_err(ctx, fd != -1, callback, 2);
+	int fd;
+	const char *path = duk_require_string(ctx, 0);
+	const char *flags_str = duk_require_string(ctx, 1);
+	int flags;
+
+	if (!fs_open_get_flags(flags_str, &flags)) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "Unknown file open flag: %s", flags_str);
+		duk_throw(ctx);
+	}
+
+	mode_t mode;
+	duk_idx_t callback;
+	if (duk_is_number(ctx, 2)) {
+		mode = duk_get_int(ctx, 2);
+		callback = 3;
+	} else {
+		mode = 0666;
+		callback = 2;
+	}
+	fd = open(path, flags, mode);
+	if (fd != -1) {
+		duk_push_int(ctx, fd);
+	} else {
+		duk_push_undefined(ctx);
+	}
+	return fs_err(ctx, fd != -1, callback, 2);
 }
 
 static duk_ret_t fs_open_sync(duk_context *ctx) {
-    int fd;
-    const char *path = duk_require_string(ctx, 0);
-    const char *flags_str = duk_require_string(ctx, 1);
-    int flags;
-
-    if (!fs_open_get_flags(flags_str, &flags)) {
-	duk_push_error_object(ctx, DUK_ERR_ERROR, "Unknown file open flag: %s", flags_str);
-	duk_throw(ctx);
-    }
-
-    mode_t mode;
-    if (duk_is_number(ctx, 2)) {
-	mode = duk_get_int(ctx, 2);
-    } else {
-	mode = 0666;
-    }
-    fd = open(path, flags, mode);
-    if (fd != -1) {
-	duk_push_int(ctx, fd);
-    }
-
-    return fs_err(ctx, fd != -1, DUK_INVALID_INDEX, 0);
+	int fd;
+	const char *path = duk_require_string(ctx, 0);
+	const char *flags_str = duk_require_string(ctx, 1);
+	int flags;
+
+	if (!fs_open_get_flags(flags_str, &flags)) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "Unknown file open flag: %s", flags_str);
+		duk_throw(ctx);
+	}
+
+	mode_t mode;
+	if (duk_is_number(ctx, 2)) {
+		mode = duk_get_int(ctx, 2);
+	} else {
+		mode = 0666;
+	}
+	fd = open(path, flags, mode);
+	if (fd != -1) {
+		duk_push_int(ctx, fd);
+	}
+
+	return fs_err(ctx, fd != -1, DUK_INVALID_INDEX, 0);
 }
 
 static duk_ret_t fs_stats_check_mode(duk_context *ctx, mode_t mask) {
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "mode");
-    if (duk_is_undefined(ctx, -1)) {
-	duk_push_false(ctx);
-    } else {
-	if ((duk_get_int(ctx, -1) & S_IFMT) == mask) {
-	    duk_push_true(ctx);
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "mode");
+	if (duk_is_undefined(ctx, -1)) {
+		duk_push_false(ctx);
 	} else {
-	    duk_push_false(ctx);
+		if ((duk_get_int(ctx, -1) & S_IFMT) == mask) {
+			duk_push_true(ctx);
+		} else {
+			duk_push_false(ctx);
+		}
 	}
-    }
-    return 1;
+	return 1;
 }
 
 static duk_ret_t fs_stats_is_file(duk_context *ctx) {
-    return fs_stats_check_mode(ctx, S_IFREG);
+	return fs_stats_check_mode(ctx, S_IFREG);
 }
 
 static duk_ret_t fs_stats_is_dir(duk_context *ctx) {
-    return fs_stats_check_mode(ctx, S_IFDIR);
+	return fs_stats_check_mode(ctx, S_IFDIR);
 }
 
 static duk_ret_t fs_stats_is_blkdev(duk_context *ctx) {
-    return fs_stats_check_mode(ctx, S_IFBLK);
+	return fs_stats_check_mode(ctx, S_IFBLK);
 }
 
 static duk_ret_t fs_stats_is_chardev(duk_context *ctx) {
-    return fs_stats_check_mode(ctx, S_IFCHR);
+	return fs_stats_check_mode(ctx, S_IFCHR);
 }
 
 static duk_ret_t fs_stats_is_symlink(duk_context *ctx) {
-    return fs_stats_check_mode(ctx, S_IFLNK);
+	return fs_stats_check_mode(ctx, S_IFLNK);
 }
 
 static duk_ret_t fs_stats_isfifo(duk_context *ctx) {
-    return fs_stats_check_mode(ctx, S_IFIFO);
+	return fs_stats_check_mode(ctx, S_IFIFO);
 }
 
 static duk_ret_t fs_stats_issocket(duk_context *ctx) {
-    return fs_stats_check_mode(ctx, S_IFSOCK);
+	return fs_stats_check_mode(ctx, S_IFSOCK);
 }
 
 static const duk_function_list_entry fs_stats_methods[] = {
-    {"isFile", fs_stats_is_file, 0},
-    {"isDirectory", fs_stats_is_dir, 0},
-    {"isBlockDevice", fs_stats_is_blkdev, 0},
-    {"isCharacterDevice", fs_stats_is_chardev, 0},
-    {"isSymbolicLink", fs_stats_is_symlink, 0},
-    {"isFIFO", fs_stats_isfifo, 0},
-    {"isSocket", fs_stats_issocket, 0},
-    {NULL, NULL, 0}
+	{"isFile", fs_stats_is_file, 0},
+	{"isDirectory", fs_stats_is_dir, 0},
+	{"isBlockDevice", fs_stats_is_blkdev, 0},
+	{"isCharacterDevice", fs_stats_is_chardev, 0},
+	{"isSymbolicLink", fs_stats_is_symlink, 0},
+	{"isFIFO", fs_stats_isfifo, 0},
+	{"isSocket", fs_stats_issocket, 0},
+	{NULL, NULL, 0}
 };
 
 static duk_ret_t fs_stats_constructor(__attribute__((unused)) duk_context *ctx) {
-    return 0;
+	return 0;
 }
 
 static const duk_function_list_entry fs_funcs[] = {
-    {"rename", fs_rename, 3},
-    {"renameSync", fs_rename, 2},
-    {"stat", fs_stat, 2},
-    {"lstat", fs_stat, 2},
-    {"statSync", fs_stat_sync, 1},
-    {"lstatSync", fs_stat_sync, 1},
-    {"unlink", fs_unlink, 2},
-    {"unlinkSync", fs_unlink, 1},
-    {"rmdir", fs_rmdir, 2},
-    {"rmdirSync", fs_rmdir, 1},
-    {"mkdir", fs_mkdir, DUK_VARARGS},
-    {"mkdirSync", fs_mkdir, DUK_VARARGS},
-    {"readdir", fs_readdir, 2},
-    {"readdirSync", fs_readdir_sync, 1},
-    {"close", fs_close, 2},
-    {"closeSync", fs_close, 1},
-    {"open", fs_open, DUK_VARARGS},
-    {"openSync", fs_open_sync, DUK_VARARGS},
-    {NULL, NULL, 0}
+	{"rename", fs_rename, 3},
+	{"renameSync", fs_rename, 2},
+	{"stat", fs_stat, 2},
+	{"lstat", fs_stat, 2},
+	{"statSync", fs_stat_sync, 1},
+	{"lstatSync", fs_stat_sync, 1},
+	{"unlink", fs_unlink, 2},
+	{"unlinkSync", fs_unlink, 1},
+	{"rmdir", fs_rmdir, 2},
+	{"rmdirSync", fs_rmdir, 1},
+	{"mkdir", fs_mkdir, DUK_VARARGS},
+	{"mkdirSync", fs_mkdir, DUK_VARARGS},
+	{"readdir", fs_readdir, 2},
+	{"readdirSync", fs_readdir_sync, 1},
+	{"close", fs_close, 2},
+	{"closeSync", fs_close, 1},
+	{"open", fs_open, DUK_VARARGS},
+	{"openSync", fs_open_sync, DUK_VARARGS},
+	{NULL, NULL, 0}
 };
 
 duk_ret_t dukopen_fs(duk_context *ctx) {
-    duk_idx_t idx = duk_push_object(ctx);
-    duk_put_function_list(ctx, idx, fs_funcs);
-    duk_idx_t stats_constr = duk_push_c_function(ctx, fs_stats_constructor, 0);
-    duk_idx_t stats_prot = duk_push_object(ctx);
-    duk_put_function_list(ctx, stats_prot, fs_stats_methods);
-    duk_put_prop_string(ctx, stats_constr, "prototype");
-    duk_put_prop_string(ctx, idx, "Stats");
-    return 1;
+	duk_idx_t idx = duk_push_object(ctx);
+	duk_put_function_list(ctx, idx, fs_funcs);
+	duk_idx_t stats_constr = duk_push_c_function(ctx, fs_stats_constructor, 0);
+	duk_idx_t stats_prot = duk_push_object(ctx);
+	duk_put_function_list(ctx, stats_prot, fs_stats_methods);
+	duk_put_prop_string(ctx, stats_constr, "prototype");
+	duk_put_prop_string(ctx, idx, "Stats");
+	return 1;
 }

+ 83 - 83
main.c

@@ -27,116 +27,116 @@ duk_context *ctx;
 
 // Push stack of Error object at -1, remove the Error object
 duk_ret_t get_error_stack(duk_context *ctx) {
-    if (duk_is_error(ctx, -1) && duk_has_prop_string(ctx, -1, "stack")) {
-	duk_get_prop_string(ctx, -1, "stack");
-	duk_remove(ctx, -2);
-    }
-    return 1;
+	if (duk_is_error(ctx, -1) && duk_has_prop_string(ctx, -1, "stack")) {
+		duk_get_prop_string(ctx, -1, "stack");
+		duk_remove(ctx, -2);
+	}
+	return 1;
 }
 
 // Print stack of Error, remove the Error object
 void print_pop_error(void) {
-    duk_safe_call(ctx, get_error_stack, 1, 1);
-    fprintf(stderr, "%s\n", duk_safe_to_string(ctx, -1));
-    duk_pop(ctx);
+	duk_safe_call(ctx, get_error_stack, 1, 1);
+	fprintf(stderr, "%s\n", duk_safe_to_string(ctx, -1));
+	duk_pop(ctx);
 }
 
 // Run JS file
 int handle_file(char *path) {
-    if (duk_pcompile_file(ctx, 0, path)) {
-	return 1;
-    }
-    duk_push_global_object(ctx);
-    if (duk_pcall_method(ctx, 0)) {
-	return 1;
-    }
-    return 0;
+	if (duk_pcompile_file(ctx, 0, path)) {
+		return 1;
+	}
+	duk_push_global_object(ctx);
+	if (duk_pcall_method(ctx, 0)) {
+		return 1;
+	}
+	return 0;
 }
 
 // REPL
 int handle_repl(void) {
-    char input[256];
+	char input[256];
 
-    puts("Duktape-nspire " VERSION "\nBuilt on " BUILD_DATE ", using Duktape " DUK_GIT_DESCRIBE);
+	puts("Duktape-nspire " VERSION "\nBuilt on " BUILD_DATE ", using Duktape " DUK_GIT_DESCRIBE);
 
-    while (true) {
-	printf("> ");
-	fflush(stdout);
-	if (!fgets(input, 256, stdin)) {
-	    if (ferror(stdin)) {
-		fprintf(stderr, "unable to read input\n");
-		return 1;
-	    } else {
-		return 0;
-	    }
+	while (true) {
+		printf("> ");
+		fflush(stdout);
+		if (!fgets(input, 256, stdin)) {
+			if (ferror(stdin)) {
+				fprintf(stderr, "unable to read input\n");
+				return 1;
+			} else {
+				return 0;
+			}
+		}
+		if (!strcmp(input, ".exit\n")) {
+			return 0;
+		}
+		if (duk_pcompile_string(ctx, 0, input)) {
+			print_pop_error();
+			continue;
+		}
+		duk_push_global_object(ctx);
+		if (duk_pcall_method(ctx, 0)) {
+			print_pop_error();
+			continue;
+		}
+		puts(duk_safe_to_string(ctx, -1));
 	}
-	if (!strcmp(input, ".exit\n")) {
-	    return 0;
-	}
-	if (duk_pcompile_string(ctx, 0, input)) {
-	    print_pop_error();
-	    continue;
-	}
-	duk_push_global_object(ctx);
-	if (duk_pcall_method(ctx, 0)) {
-	    print_pop_error();
-	    continue;
-	}
-	puts(duk_safe_to_string(ctx, -1));
-    }
-    return 0;
+	return 0;
 }
 
 // Cleanup at end
 void cleanup(void) {
-    duk_destroy_heap(ctx);
+	duk_destroy_heap(ctx);
 }
 
 int main(int argc, char **argv) {
-    enable_relative_paths(argv); // Enable relative paths
+	enable_relative_paths(argv); // Enable relative paths
 
-    // Register .js file extension
-    if (argc > 0) {
-	char *ptr = strrchr(argv[0], '/');
-	if (ptr++) {
-	    char *dot = strrchr(ptr, '.');
-	    if (dot && dot != ptr && !strcmp(dot, ".tns")) {
-		*dot = '\0';
-		cfg_register_fileext("js", ptr);
-		*dot = '.';
-	    }
+	// Register .js file extension
+	if (argc > 0) {
+		char *ptr = strrchr(argv[0], '/');
+		if (ptr++) {
+			char *dot = strrchr(ptr, '.');
+			if (dot && dot != ptr && !strcmp(dot, ".tns")) {
+				*dot = '\0';
+				cfg_register_fileext("js", ptr);
+				*dot = '.';
+			}
+		}
 	}
-    }
 
-    // Initialize Duktape heap and register cleanup with atexit
-    ctx = duk_create_heap_default();
-    if (atexit(cleanup)) {
-	cleanup();
-	return EXIT_FAILURE;
-    }
+	// Initialize Duktape heap and register cleanup with atexit
+	ctx = duk_create_heap_default();
+	if (atexit(cleanup)) {
+		cleanup();
+		return EXIT_FAILURE;
+	}
 
-    // Add modSearch function for module loading support
-    duk_push_global_object(ctx);
-    duk_get_prop_string(ctx, -1, "Duktape");
-    duk_push_c_function(ctx, module_search, 4);
-    duk_put_prop_string(ctx, -2, "modSearch");
-    duk_pop_2(ctx);
+	// Add modSearch function for module loading support
+	duk_push_global_object(ctx);
+	duk_get_prop_string(ctx, -1, "Duktape");
+	duk_push_c_function(ctx, module_search, 4);
+	duk_put_prop_string(ctx, -2, "modSearch");
+	duk_pop_2(ctx);
 
-    if (argc <= 1) {
-	if (handle_repl()) {
-	    wait_key_pressed();
-	    return EXIT_FAILURE;
-	}
-    } else {
-	for (int i = 1; i < argc; i++) {
-	    duk_push_string(ctx, argv[i]);
-	    if (handle_file(argv[i])) {
-		print_pop_error();
-		wait_key_pressed();
-		return EXIT_FAILURE;
-	    }
+	if (argc <= 1) {
+		if (handle_repl()) {
+			wait_key_pressed();
+			return EXIT_FAILURE;
+		}
+	} else {
+		for (int i = 1; i < argc; i++) {
+			duk_push_string(ctx, argv[i]);
+			if (handle_file(argv[i])) {
+				print_pop_error();
+				wait_key_pressed();
+				return EXIT_FAILURE;
+			}
+		}
 	}
-    }
 
-    return 0;
+	return 0;
 }

+ 37 - 37
module.c

@@ -24,47 +24,47 @@
 
 // Duktape.modSearch function, needed for loading modules with require()
 duk_ret_t module_search(duk_context *ctx) {
-    const char *id = duk_require_string(ctx, 0);
+	const char *id = duk_require_string(ctx, 0);
 
-    // C modules: add functions to exports variable (3rd argument) and return undefined
-    for (int i = 0; i < c_module_count; i++) {
-	if (!strcmp(c_module_list[i].name, id)) {
-	    duk_push_c_function(ctx, c_module_list[i].init_func, 0);
-	    duk_call(ctx, 0);
-	    duk_enum(ctx, -1, 0);
-	    while(duk_next(ctx, -1, 1)) {
-		duk_put_prop(ctx, 2);
-	    }
-	    duk_pop_2(ctx);
-	    return 0;
+	// C modules: add functions to exports variable (3rd argument) and return undefined
+	for (int i = 0; i < c_module_count; i++) {
+		if (!strcmp(c_module_list[i].name, id)) {
+			duk_push_c_function(ctx, c_module_list[i].init_func, 0);
+			duk_call(ctx, 0);
+			duk_enum(ctx, -1, 0);
+			while(duk_next(ctx, -1, 1)) {
+				duk_put_prop(ctx, 2);
+			}
+			duk_pop_2(ctx);
+			return 0;
+		}
 	}
-    }
 
-    // JS modules: return source code as a string
-    // Read from file "modname.js.tns"
-    int module_filename_len = strlen(id) + strlen(".js.tns") + 1;
-    char *module_filename = malloc(module_filename_len);
-    if (!module_filename) goto error;
-    snprintf(module_filename, module_filename_len, "%s.js.tns", id);
-    FILE *module_file = fopen(module_filename, "r");
-    free(module_filename);
-    if (!module_file) goto error;
-    if (fseek(module_file, 0, SEEK_END) != 0) goto error;
-    long module_file_size = ftell(module_file);
-    if (module_file_size == -1) goto error;
-    rewind(module_file);
-    char *src = malloc(module_file_size);
-    if (!src) goto error;
-    fread(src, 1, module_file_size, module_file);
-    if (ferror(module_file)) goto error;
-    fclose(module_file);
+	// JS modules: return source code as a string
+	// Read from file "modname.js.tns"
+	int module_filename_len = strlen(id) + strlen(".js.tns") + 1;
+	char *module_filename = malloc(module_filename_len);
+	if (!module_filename) goto error;
+	snprintf(module_filename, module_filename_len, "%s.js.tns", id);
+	FILE *module_file = fopen(module_filename, "r");
+	free(module_filename);
+	if (!module_file) goto error;
+	if (fseek(module_file, 0, SEEK_END) != 0) goto error;
+	long module_file_size = ftell(module_file);
+	if (module_file_size == -1) goto error;
+	rewind(module_file);
+	char *src = malloc(module_file_size);
+	if (!src) goto error;
+	fread(src, 1, module_file_size, module_file);
+	if (ferror(module_file)) goto error;
+	fclose(module_file);
 
-    duk_push_lstring(ctx, src, module_file_size);
-    free(src);
+	duk_push_lstring(ctx, src, module_file_size);
+	free(src);
+
+	return 1;
 
-    return 1;
-    
 error:
-    duk_push_error_object(ctx, DUK_ERR_ERROR, "module %s not found: %s", id, strerror(errno));
-    duk_throw(ctx);
+	duk_push_error_object(ctx, DUK_ERR_ERROR, "module %s not found: %s", id, strerror(errno));
+	duk_throw(ctx);
 }

+ 5 - 5
module.h

@@ -25,14 +25,14 @@
 #include "nsp_texture.h"
 
 struct c_module {
-    const char *name;
-    duk_ret_t (*init_func)(duk_context*);
+	const char *name;
+	duk_ret_t (*init_func)(duk_context*);
 };
 
 static const struct c_module c_module_list[] = {
-    {"fs", dukopen_fs},
-    {"nsp/keys", dukopen_nsp_keys},
-    {"nsp/texture", dukopen_nsp_texture}
+	{"fs", dukopen_fs},
+	{"nsp/keys", dukopen_nsp_keys},
+	{"nsp/texture", dukopen_nsp_texture}
 };
 
 static const int c_module_count = (sizeof(c_module_list) / sizeof(c_module_list[0]));

+ 170 - 170
nsp_keys.c

@@ -20,200 +20,200 @@
 #include <libndls.h>
 
 struct nsp_key {
-    const char *key_name;
-    const t_key *key_val;
+	const char *key_name;
+	const t_key *key_val;
 };
 
 #define KEY(a) {#a, &a}
 
 static const struct nsp_key nsp_key_consts[] = {
-    KEY(KEY_NSPIRE_RET),
-    KEY(KEY_NSPIRE_ENTER),
-    KEY(KEY_NSPIRE_SPACE),
-    KEY(KEY_NSPIRE_NEGATIVE),
-    KEY(KEY_NSPIRE_Z),
-    KEY(KEY_NSPIRE_PERIOD),
-    KEY(KEY_NSPIRE_Y),
-    KEY(KEY_NSPIRE_0),
-    KEY(KEY_NSPIRE_X),
-    KEY(KEY_NSPIRE_THETA),
-    KEY(KEY_NSPIRE_COMMA),
-    KEY(KEY_NSPIRE_PLUS),
-    KEY(KEY_NSPIRE_W),
-    KEY(KEY_NSPIRE_3),
-    KEY(KEY_NSPIRE_V),
-    KEY(KEY_NSPIRE_2),
-    KEY(KEY_NSPIRE_U),
-    KEY(KEY_NSPIRE_1),
-    KEY(KEY_NSPIRE_T),
-    KEY(KEY_NSPIRE_eEXP),
-    KEY(KEY_NSPIRE_PI),
-    KEY(KEY_NSPIRE_QUES),
-    KEY(KEY_NSPIRE_QUESEXCL),
-    KEY(KEY_NSPIRE_MINUS),
-    KEY(KEY_NSPIRE_S),
-    KEY(KEY_NSPIRE_6),
-    KEY(KEY_NSPIRE_R),
-    KEY(KEY_NSPIRE_5),
-    KEY(KEY_NSPIRE_Q),
-    KEY(KEY_NSPIRE_4),
-    KEY(KEY_NSPIRE_P),
-    KEY(KEY_NSPIRE_TENX),
-    KEY(KEY_NSPIRE_EE),
-    KEY(KEY_NSPIRE_COLON),
-    KEY(KEY_NSPIRE_MULTIPLY),
-    KEY(KEY_NSPIRE_O),
-    KEY(KEY_NSPIRE_9),
-    KEY(KEY_NSPIRE_N),
-    KEY(KEY_NSPIRE_8),
-    KEY(KEY_NSPIRE_M),
-    KEY(KEY_NSPIRE_7),
-    KEY(KEY_NSPIRE_L),
-    KEY(KEY_NSPIRE_SQU),
-    KEY(KEY_NSPIRE_II),
-    KEY(KEY_NSPIRE_QUOTE),
-    KEY(KEY_NSPIRE_DIVIDE),
-    KEY(KEY_NSPIRE_K),
-    KEY(KEY_NSPIRE_TAN),
-    KEY(KEY_NSPIRE_J),
-    KEY(KEY_NSPIRE_COS),
-    KEY(KEY_NSPIRE_I),
-    KEY(KEY_NSPIRE_SIN),
-    KEY(KEY_NSPIRE_H),
-    KEY(KEY_NSPIRE_EXP),
-    KEY(KEY_NSPIRE_GTHAN),
-    KEY(KEY_NSPIRE_APOSTROPHE),
-    KEY(KEY_NSPIRE_CAT),
-    KEY(KEY_NSPIRE_FRAC),
-    KEY(KEY_NSPIRE_G),
-    KEY(KEY_NSPIRE_RP),
-    KEY(KEY_NSPIRE_F),
-    KEY(KEY_NSPIRE_LP),
-    KEY(KEY_NSPIRE_E),
-    KEY(KEY_NSPIRE_VAR),
-    KEY(KEY_NSPIRE_D),
-    KEY(KEY_NSPIRE_DEL),
-    KEY(KEY_NSPIRE_LTHAN),
-    KEY(KEY_NSPIRE_FLAG),
-    KEY(KEY_NSPIRE_CLICK),
-    KEY(KEY_NSPIRE_C),
-    KEY(KEY_NSPIRE_HOME),
-    KEY(KEY_NSPIRE_B),
-    KEY(KEY_NSPIRE_MENU),
-    KEY(KEY_NSPIRE_A),
-    KEY(KEY_NSPIRE_ESC),
-    KEY(KEY_NSPIRE_BAR),
-    KEY(KEY_NSPIRE_TAB),
-    KEY(KEY_NSPIRE_EQU),
-    KEY(KEY_NSPIRE_UP),
-    KEY(KEY_NSPIRE_UPRIGHT),
-    KEY(KEY_NSPIRE_RIGHT),
-    KEY(KEY_NSPIRE_RIGHTDOWN),
-    KEY(KEY_NSPIRE_DOWN),
-    KEY(KEY_NSPIRE_DOWNLEFT),
-    KEY(KEY_NSPIRE_LEFT),
-    KEY(KEY_NSPIRE_LEFTUP),
-    KEY(KEY_NSPIRE_SHIFT),
-    KEY(KEY_NSPIRE_CTRL),
-    KEY(KEY_NSPIRE_DOC),
-    KEY(KEY_NSPIRE_TRIG),
-    KEY(KEY_NSPIRE_SCRATCHPAD),
-    KEY(KEY_84_DOWN),
-    KEY(KEY_84_LEFT),
-    KEY(KEY_84_RIGHT),
-    KEY(KEY_84_UP),
-    KEY(KEY_84_ENTER),
-    KEY(KEY_84_PLUS),
-    KEY(KEY_84_MINUS),
-    KEY(KEY_84_MULTIPLY),
-    KEY(KEY_84_DIVIDE),
-    KEY(KEY_84_EXP),
-    KEY(KEY_84_CLEAR),
-    KEY(KEY_84_NEGATIVE),
-    KEY(KEY_84_3),
-    KEY(KEY_84_6),
-    KEY(KEY_84_9),
-    KEY(KEY_84_RP),
-    KEY(KEY_84_TAN),
-    KEY(KEY_84_VARS),
-    KEY(KEY_84_PERIOD),
-    KEY(KEY_84_2),
-    KEY(KEY_84_5),
-    KEY(KEY_84_8),
-    KEY(KEY_84_LP),
-    KEY(KEY_84_COS),
-    KEY(KEY_84_PRGM),
-    KEY(KEY_84_STAT),
-    KEY(KEY_84_0),
-    KEY(KEY_84_1),
-    KEY(KEY_84_4),
-    KEY(KEY_84_7),
-    KEY(KEY_84_COMMA),
-    KEY(KEY_84_SIN),
-    KEY(KEY_84_APPS),
-    KEY(KEY_84_X),
-    KEY(KEY_84_STO),
-    KEY(KEY_84_LN),
-    KEY(KEY_84_LOG),
-    KEY(KEY_84_SQU),
-    KEY(KEY_84_INV),
-    KEY(KEY_84_MATH),
-    KEY(KEY_84_ALPHA),
-    KEY(KEY_84_GRAPH),
-    KEY(KEY_84_TRACE),
-    KEY(KEY_84_ZOOM),
-    KEY(KEY_84_WIND),
-    KEY(KEY_84_YEQU),
-    KEY(KEY_84_2ND),
-    KEY(KEY_84_MODE),
-    KEY(KEY_84_DEL)
+	KEY(KEY_NSPIRE_RET),
+	KEY(KEY_NSPIRE_ENTER),
+	KEY(KEY_NSPIRE_SPACE),
+	KEY(KEY_NSPIRE_NEGATIVE),
+	KEY(KEY_NSPIRE_Z),
+	KEY(KEY_NSPIRE_PERIOD),
+	KEY(KEY_NSPIRE_Y),
+	KEY(KEY_NSPIRE_0),
+	KEY(KEY_NSPIRE_X),
+	KEY(KEY_NSPIRE_THETA),
+	KEY(KEY_NSPIRE_COMMA),
+	KEY(KEY_NSPIRE_PLUS),
+	KEY(KEY_NSPIRE_W),
+	KEY(KEY_NSPIRE_3),
+	KEY(KEY_NSPIRE_V),
+	KEY(KEY_NSPIRE_2),
+	KEY(KEY_NSPIRE_U),
+	KEY(KEY_NSPIRE_1),
+	KEY(KEY_NSPIRE_T),
+	KEY(KEY_NSPIRE_eEXP),
+	KEY(KEY_NSPIRE_PI),
+	KEY(KEY_NSPIRE_QUES),
+	KEY(KEY_NSPIRE_QUESEXCL),
+	KEY(KEY_NSPIRE_MINUS),
+	KEY(KEY_NSPIRE_S),
+	KEY(KEY_NSPIRE_6),
+	KEY(KEY_NSPIRE_R),
+	KEY(KEY_NSPIRE_5),
+	KEY(KEY_NSPIRE_Q),
+	KEY(KEY_NSPIRE_4),
+	KEY(KEY_NSPIRE_P),
+	KEY(KEY_NSPIRE_TENX),
+	KEY(KEY_NSPIRE_EE),
+	KEY(KEY_NSPIRE_COLON),
+	KEY(KEY_NSPIRE_MULTIPLY),
+	KEY(KEY_NSPIRE_O),
+	KEY(KEY_NSPIRE_9),
+	KEY(KEY_NSPIRE_N),
+	KEY(KEY_NSPIRE_8),
+	KEY(KEY_NSPIRE_M),
+	KEY(KEY_NSPIRE_7),
+	KEY(KEY_NSPIRE_L),
+	KEY(KEY_NSPIRE_SQU),
+	KEY(KEY_NSPIRE_II),
+	KEY(KEY_NSPIRE_QUOTE),
+	KEY(KEY_NSPIRE_DIVIDE),
+	KEY(KEY_NSPIRE_K),
+	KEY(KEY_NSPIRE_TAN),
+	KEY(KEY_NSPIRE_J),
+	KEY(KEY_NSPIRE_COS),
+	KEY(KEY_NSPIRE_I),
+	KEY(KEY_NSPIRE_SIN),
+	KEY(KEY_NSPIRE_H),
+	KEY(KEY_NSPIRE_EXP),
+	KEY(KEY_NSPIRE_GTHAN),
+	KEY(KEY_NSPIRE_APOSTROPHE),
+	KEY(KEY_NSPIRE_CAT),
+	KEY(KEY_NSPIRE_FRAC),
+	KEY(KEY_NSPIRE_G),
+	KEY(KEY_NSPIRE_RP),
+	KEY(KEY_NSPIRE_F),
+	KEY(KEY_NSPIRE_LP),
+	KEY(KEY_NSPIRE_E),
+	KEY(KEY_NSPIRE_VAR),
+	KEY(KEY_NSPIRE_D),
+	KEY(KEY_NSPIRE_DEL),
+	KEY(KEY_NSPIRE_LTHAN),
+	KEY(KEY_NSPIRE_FLAG),
+	KEY(KEY_NSPIRE_CLICK),
+	KEY(KEY_NSPIRE_C),
+	KEY(KEY_NSPIRE_HOME),
+	KEY(KEY_NSPIRE_B),
+	KEY(KEY_NSPIRE_MENU),
+	KEY(KEY_NSPIRE_A),
+	KEY(KEY_NSPIRE_ESC),
+	KEY(KEY_NSPIRE_BAR),
+	KEY(KEY_NSPIRE_TAB),
+	KEY(KEY_NSPIRE_EQU),
+	KEY(KEY_NSPIRE_UP),
+	KEY(KEY_NSPIRE_UPRIGHT),
+	KEY(KEY_NSPIRE_RIGHT),
+	KEY(KEY_NSPIRE_RIGHTDOWN),
+	KEY(KEY_NSPIRE_DOWN),
+	KEY(KEY_NSPIRE_DOWNLEFT),
+	KEY(KEY_NSPIRE_LEFT),
+	KEY(KEY_NSPIRE_LEFTUP),
+	KEY(KEY_NSPIRE_SHIFT),
+	KEY(KEY_NSPIRE_CTRL),
+	KEY(KEY_NSPIRE_DOC),
+	KEY(KEY_NSPIRE_TRIG),
+	KEY(KEY_NSPIRE_SCRATCHPAD),
+	KEY(KEY_84_DOWN),
+	KEY(KEY_84_LEFT),
+	KEY(KEY_84_RIGHT),
+	KEY(KEY_84_UP),
+	KEY(KEY_84_ENTER),
+	KEY(KEY_84_PLUS),
+	KEY(KEY_84_MINUS),
+	KEY(KEY_84_MULTIPLY),
+	KEY(KEY_84_DIVIDE),
+	KEY(KEY_84_EXP),
+	KEY(KEY_84_CLEAR),
+	KEY(KEY_84_NEGATIVE),
+	KEY(KEY_84_3),
+	KEY(KEY_84_6),
+	KEY(KEY_84_9),
+	KEY(KEY_84_RP),
+	KEY(KEY_84_TAN),
+	KEY(KEY_84_VARS),
+	KEY(KEY_84_PERIOD),
+	KEY(KEY_84_2),
+	KEY(KEY_84_5),
+	KEY(KEY_84_8),
+	KEY(KEY_84_LP),
+	KEY(KEY_84_COS),
+	KEY(KEY_84_PRGM),
+	KEY(KEY_84_STAT),
+	KEY(KEY_84_0),
+	KEY(KEY_84_1),
+	KEY(KEY_84_4),
+	KEY(KEY_84_7),
+	KEY(KEY_84_COMMA),
+	KEY(KEY_84_SIN),
+	KEY(KEY_84_APPS),
+	KEY(KEY_84_X),
+	KEY(KEY_84_STO),
+	KEY(KEY_84_LN),
+	KEY(KEY_84_LOG),
+	KEY(KEY_84_SQU),
+	KEY(KEY_84_INV),
+	KEY(KEY_84_MATH),
+	KEY(KEY_84_ALPHA),
+	KEY(KEY_84_GRAPH),
+	KEY(KEY_84_TRACE),
+	KEY(KEY_84_ZOOM),
+	KEY(KEY_84_WIND),
+	KEY(KEY_84_YEQU),
+	KEY(KEY_84_2ND),
+	KEY(KEY_84_MODE),
+	KEY(KEY_84_DEL)
 };
 
 static duk_ret_t nsp_keys_any_key_pressed(__attribute__((unused)) duk_context *ctx) {
-    duk_push_boolean(ctx, any_key_pressed());
-    return 1;
+	duk_push_boolean(ctx, any_key_pressed());
+	return 1;
 }
 
 static duk_ret_t nsp_keys_is_key_pressed(duk_context *ctx) {
-    int k = duk_require_int(ctx, 0);
-    if (k < 0 || (unsigned int)k >= sizeof(nsp_key_consts) / sizeof(struct nsp_key)) {
-	duk_push_error_object(ctx, DUK_ERR_ERROR, "invalid key: %d", k);
-	duk_throw(ctx);
-    }
-    duk_push_boolean(ctx, isKeyPressed(*(nsp_key_consts[k].key_val)));
-    return 1;
+	int k = duk_require_int(ctx, 0);
+	if (k < 0 || (unsigned int)k >= sizeof(nsp_key_consts) / sizeof(struct nsp_key)) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "invalid key: %d", k);
+		duk_throw(ctx);
+	}
+	duk_push_boolean(ctx, isKeyPressed(*(nsp_key_consts[k].key_val)));
+	return 1;
 }
 
 static duk_ret_t nsp_keys_on_key_pressed(__attribute__((unused)) duk_context *ctx) {
-    duk_push_boolean(ctx, on_key_pressed());
-    return 1;
+	duk_push_boolean(ctx, on_key_pressed());
+	return 1;
 }
 
 static duk_ret_t nsp_keys_wait_key_pressed(__attribute__((unused)) duk_context *ctx) {
-    wait_key_pressed();
-    return 0;
+	wait_key_pressed();
+	return 0;
 }
 
 static duk_ret_t nsp_keys_wait_no_key_pressed(__attribute__((unused)) duk_context *ctx) {
-    wait_no_key_pressed();
-    return 0;
+	wait_no_key_pressed();
+	return 0;
 }
 
 static const duk_function_list_entry nsp_keys_funcs[] = {
-    {"anyKeyPressed", nsp_keys_any_key_pressed, 0},
-    {"isKeyPressed", nsp_keys_is_key_pressed, 1},
-    {"onKeyPressed", nsp_keys_on_key_pressed, 0},
-    {"waitKeyPressed", nsp_keys_wait_key_pressed, 0},
-    {"waitNoKeyPressed", nsp_keys_wait_no_key_pressed, 0},
-    {NULL, NULL, 0 }
+	{"anyKeyPressed", nsp_keys_any_key_pressed, 0},
+	{"isKeyPressed", nsp_keys_is_key_pressed, 1},
+	{"onKeyPressed", nsp_keys_on_key_pressed, 0},
+	{"waitKeyPressed", nsp_keys_wait_key_pressed, 0},
+	{"waitNoKeyPressed", nsp_keys_wait_no_key_pressed, 0},
+	{NULL, NULL, 0 }
 };
 
 duk_ret_t dukopen_nsp_keys(duk_context *ctx) {
-    duk_idx_t idx = duk_push_object(ctx);
-    duk_put_function_list(ctx, idx, nsp_keys_funcs);
-    for (unsigned int i = 0; i < sizeof(nsp_key_consts) / sizeof(struct nsp_key); i++) {
-	duk_push_int(ctx, i);
-	duk_put_prop_string(ctx, idx, nsp_key_consts[i].key_name);
-    }
-    return 1;
+	duk_idx_t idx = duk_push_object(ctx);
+	duk_put_function_list(ctx, idx, nsp_keys_funcs);
+	for (unsigned int i = 0; i < sizeof(nsp_key_consts) / sizeof(struct nsp_key); i++) {
+		duk_push_int(ctx, i);
+		duk_put_prop_string(ctx, idx, nsp_key_consts[i].key_name);
+	}
+	return 1;
 }

+ 404 - 404
nsp_texture.c

@@ -28,494 +28,494 @@
 
 
 static duk_ret_t nsp_texture_constructor(duk_context *ctx) {
-    int width = duk_require_int(ctx, 0);
-    int height = duk_require_int(ctx, 1);
-    if (width < 1 || height < 1) {
-	duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "Width and height must be positive");
-	duk_throw(ctx);
-    }
-    bool has_transparency;
-    uint16_t transparent_color;
-    if ((has_transparency = duk_is_number(ctx, 2))) {
-	transparent_color = (uint16_t)duk_get_int(ctx, 2);
-    }
-    duk_push_this(ctx);
-    duk_push_fixed_buffer(ctx, width * height * 2);
-    duk_put_prop_string(ctx, -2, "bitmap");
-    duk_push_int(ctx, width);
-    duk_put_prop_string(ctx, -2, "width");
-    duk_push_int(ctx, height);
-    duk_put_prop_string(ctx, -2, "height");
-    if (has_transparency) {
-	duk_push_int(ctx, transparent_color);
-    } else {
-	duk_push_null(ctx);
-    }
-    duk_put_prop_string(ctx, -2, "transparentColor");
-    return 0;
+	int width = duk_require_int(ctx, 0);
+	int height = duk_require_int(ctx, 1);
+	if (width < 1 || height < 1) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "Width and height must be positive");
+		duk_throw(ctx);
+	}
+	bool has_transparency;
+	uint16_t transparent_color;
+	if ((has_transparency = duk_is_number(ctx, 2))) {
+		transparent_color = (uint16_t)duk_get_int(ctx, 2);
+	}
+	duk_push_this(ctx);
+	duk_push_fixed_buffer(ctx, width * height * 2);
+	duk_put_prop_string(ctx, -2, "bitmap");
+	duk_push_int(ctx, width);
+	duk_put_prop_string(ctx, -2, "width");
+	duk_push_int(ctx, height);
+	duk_put_prop_string(ctx, -2, "height");
+	if (has_transparency) {
+		duk_push_int(ctx, transparent_color);
+	} else {
+		duk_push_null(ctx);
+	}
+	duk_put_prop_string(ctx, -2, "transparentColor");
+	return 0;
 }
 
 duk_ret_t nsp_texture_display(duk_context *ctx) {
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "width");
-    int width = duk_get_int(ctx, -1);
-    duk_pop(ctx);
-    duk_get_prop_string(ctx, -1, "height");
-    int height = duk_get_int(ctx, -1);
-    duk_pop(ctx);
-    duk_get_prop_string(ctx, -1, "transparentColor");
-    if (width != 320 || height != 240 || !duk_is_null(ctx, -1)) {
-	duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "must have dimensions 230x240 without transparency");
-	duk_throw(ctx);
-    }
-    duk_pop(ctx);
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap;
-    bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL || size != 320 * 240 * 2) {
-	duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap buffer does not match with dimensions");
-	duk_throw(ctx);
-    }
-    memcpy(SCREEN_BASE_ADDRESS, bitmap, 320 * 240 * 2);
-    return 0;
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "width");
+	int width = duk_get_int(ctx, -1);
+	duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "height");
+	int height = duk_get_int(ctx, -1);
+	duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "transparentColor");
+	if (width != 320 || height != 240 || !duk_is_null(ctx, -1)) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "must have dimensions 230x240 without transparency");
+		duk_throw(ctx);
+	}
+	duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap;
+	bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL || size != 320 * 240 * 2) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap buffer does not match with dimensions");
+		duk_throw(ctx);
+	}
+	memcpy(SCREEN_BASE_ADDRESS, bitmap, 320 * 240 * 2);
+	return 0;
 }
 
 duk_ret_t nsp_texture_fill(duk_context *ctx) {
-    uint16_t color = duk_require_int(ctx, 0);
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL) {
-	duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
-	duk_throw(ctx);
-    }
-    for (size_t i = 0; i < size / 2; i++) {
-	bitmap[i] = (uint16_t)color;
-    }
-
-    return 0;
+	uint16_t color = duk_require_int(ctx, 0);
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
+		duk_throw(ctx);
+	}
+	for (size_t i = 0; i < size / 2; i++) {
+		bitmap[i] = (uint16_t)color;
+	}
+
+	return 0;
 }
 
 duk_ret_t nsp_texture_get_pixel(duk_context *ctx) {
-    int x = duk_require_int(ctx, 0);
-    int y = duk_require_int(ctx, 1);
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "width");
-    int w = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-    duk_get_prop_string(ctx, -1, "height");
-    int h = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-
-    if (w <= 0 || h <= 0) {
-	duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
-	duk_throw(ctx);
-    }
-
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL) {
-	duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
-	duk_throw(ctx);
-    }
-
-    if (0 <= x && x < w && 0 <= y && y < h && size >= (size_t)(w * h * 2)) {
-	duk_push_int(ctx, bitmap[w * y + x]);
-	return 1;
-    } else {
-	duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "coordinates out of range");
-	duk_throw(ctx);
-    }
+	int x = duk_require_int(ctx, 0);
+	int y = duk_require_int(ctx, 1);
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "width");
+	int w = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "height");
+	int h = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+
+	if (w <= 0 || h <= 0) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
+		duk_throw(ctx);
+	}
+
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
+		duk_throw(ctx);
+	}
+
+	if (0 <= x && x < w && 0 <= y && y < h && size >= (size_t)(w * h * 2)) {
+		duk_push_int(ctx, bitmap[w * y + x]);
+		return 1;
+	} else {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "coordinates out of range");
+		duk_throw(ctx);
+	}
 }
 
 duk_ret_t nsp_texture_set_pixel(duk_context *ctx) {
-    int x = duk_require_int(ctx, 0);
-    int y = duk_require_int(ctx, 1);
-    uint16_t color = duk_require_int(ctx, 2);
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "width");
-    int w = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-    duk_get_prop_string(ctx, -1, "height");
-    int h = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-
-    if (w <= 0 || h <= 0) {
-	duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
-	duk_throw(ctx);
-    }
-
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL) {
-	duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
-	duk_throw(ctx);
-    }
-
-    if (0 <= x && x < w && 0 <= y && y < h && size >= (size_t)(w * h * 2)) {
-	bitmap[w * y + x] = (uint16_t)color;
-	return 0;
-    } else {
-	duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "coordinates out of range");
-	duk_throw(ctx);
-    }
+	int x = duk_require_int(ctx, 0);
+	int y = duk_require_int(ctx, 1);
+	uint16_t color = duk_require_int(ctx, 2);
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "width");
+	int w = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "height");
+	int h = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+
+	if (w <= 0 || h <= 0) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
+		duk_throw(ctx);
+	}
+
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
+		duk_throw(ctx);
+	}
+
+	if (0 <= x && x < w && 0 <= y && y < h && size >= (size_t)(w * h * 2)) {
+		bitmap[w * y + x] = (uint16_t)color;
+		return 0;
+	} else {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "coordinates out of range");
+		duk_throw(ctx);
+	}
 }
 
 // ====== Xtase drawing routines ======
 duk_ret_t nsp_texture_draw_line(duk_context *ctx) {
-    int x1 = duk_require_int(ctx, 0);
-    int y1 = duk_require_int(ctx, 1);
-
-    int x2 = duk_require_int(ctx, 2);
-    int y2 = duk_require_int(ctx, 3);
-
-    uint16_t color = duk_require_int(ctx, 4);
-
-
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "width");
-    int w = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-    duk_get_prop_string(ctx, -1, "height");
-    int h = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-
-    if (w <= 0 || h <= 0) {
-			duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
-			duk_throw(ctx);
-    }
-
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL) {
-			duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
-			duk_throw(ctx);
-    }
-
-		FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
-		  fb->width = w;
-		  fb->height = h;
-		  fb->fb_size = w * h;
-		  fb->fb = bitmap;
-		  drawLine(x1,y1,x2,y2,color,fb);
-		free(fb);
-    return 0;
+	int x1 = duk_require_int(ctx, 0);
+	int y1 = duk_require_int(ctx, 1);
+
+	int x2 = duk_require_int(ctx, 2);
+	int y2 = duk_require_int(ctx, 3);
+
+	uint16_t color = duk_require_int(ctx, 4);
+
+
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "width");
+	int w = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "height");
+	int h = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+
+	if (w <= 0 || h <= 0) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
+		duk_throw(ctx);
+	}
+
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
+		duk_throw(ctx);
+	}
+
+	FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
+	fb->width = w;
+	fb->height = h;
+	fb->fb_size = w * h;
+	fb->fb = bitmap;
+	drawLine(x1,y1,x2,y2,color,fb);
+	free(fb);
+	return 0;
 }
 
 
 
 duk_ret_t nsp_texture_draw_rect(duk_context *ctx) {
-    int x = duk_require_int(ctx, 0);
-    int y = duk_require_int(ctx, 1);
-
-    int w_ = duk_require_int(ctx, 2);
-    int h_ = duk_require_int(ctx, 3);
-
-    uint16_t color = duk_require_int(ctx, 4);
-
-
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "width");
-    int w = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-    duk_get_prop_string(ctx, -1, "height");
-    int h = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-
-    if (w <= 0 || h <= 0) {
-			duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
-			duk_throw(ctx);
-    }
-
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL) {
-			duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
-			duk_throw(ctx);
-    }
-
-		FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
-		  fb->width = w;
-		  fb->height = h;
-		  fb->fb_size = w * h;
-		  fb->fb = bitmap;
-		  drawRect(x,y,w_,h_,color,fb);
-		free(fb);
-    return 0;
+	int x = duk_require_int(ctx, 0);
+	int y = duk_require_int(ctx, 1);
+
+	int w_ = duk_require_int(ctx, 2);
+	int h_ = duk_require_int(ctx, 3);
+
+	uint16_t color = duk_require_int(ctx, 4);
+
+
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "width");
+	int w = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "height");
+	int h = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+
+	if (w <= 0 || h <= 0) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
+		duk_throw(ctx);
+	}
+
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
+		duk_throw(ctx);
+	}
+
+	FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
+	fb->width = w;
+	fb->height = h;
+	fb->fb_size = w * h;
+	fb->fb = bitmap;
+	drawRect(x,y,w_,h_,color,fb);
+	free(fb);
+	return 0;
 }
 
 duk_ret_t nsp_texture_fill_rect(duk_context *ctx) {
-    int x = duk_require_int(ctx, 0);
-    int y = duk_require_int(ctx, 1);
-
-    int w_ = duk_require_int(ctx, 2);
-    int h_ = duk_require_int(ctx, 3);
-
-    uint16_t color = duk_require_int(ctx, 4);
-
-
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "width");
-    int w = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-    duk_get_prop_string(ctx, -1, "height");
-    int h = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-
-    if (w <= 0 || h <= 0) {
-			duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
-			duk_throw(ctx);
-    }
-
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL) {
-			duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
-			duk_throw(ctx);
-    }
-
-		FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
-		  fb->width = w;
-		  fb->height = h;
-		  fb->fb_size = w * h;
-		  fb->fb = bitmap;
-		  fillRect(x,y,w_,h_,color,fb);
-		free(fb);
-    return 0;
+	int x = duk_require_int(ctx, 0);
+	int y = duk_require_int(ctx, 1);
+
+	int w_ = duk_require_int(ctx, 2);
+	int h_ = duk_require_int(ctx, 3);
+
+	uint16_t color = duk_require_int(ctx, 4);
+
+
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "width");
+	int w = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "height");
+	int h = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+
+	if (w <= 0 || h <= 0) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
+		duk_throw(ctx);
+	}
+
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
+		duk_throw(ctx);
+	}
+
+	FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
+	fb->width = w;
+	fb->height = h;
+	fb->fb_size = w * h;
+	fb->fb = bitmap;
+	fillRect(x,y,w_,h_,color,fb);
+	free(fb);
+	return 0;
 }
 
 int* getIntArray(duk_context *ctx, int stackIndex) {
 	static int* result = NULL;
 
 	if(duk_is_array(ctx, stackIndex)) {
-    int resultLen = duk_get_length(ctx, stackIndex);
+		int resultLen = duk_get_length(ctx, stackIndex);
 
-    result = (int*)malloc( resultLen * sizeof(int) );
-    memset(result,0,resultLen);
+		result = (int*)malloc( resultLen * sizeof(int) );
+		memset(result,0,resultLen);
 
-    duk_enum(ctx, stackIndex, DUK_ENUM_ARRAY_INDICES_ONLY);
+		duk_enum(ctx, stackIndex, DUK_ENUM_ARRAY_INDICES_ONLY);
 
 
 		// NOT stackIndex because waits enumIndex that is -1
 		int idx=0;
 		while (duk_next(ctx, -1, 1)) {
-			 // in JS/duktape toto[1] <=> toto["1"]
-			 // that's why keys are strings
-			 const char* k = duk_to_string(ctx, -2);
-			 int v = duk_to_int(ctx, -1);
-		   //printf("key=%s, value=%d\n", k, v);
-			 result[idx++] = v;
-		   duk_pop_2(ctx);
+			// in JS/duktape toto[1] <=> toto["1"]
+			// that's why keys are strings
+			const char* k = duk_to_string(ctx, -2);
+			int v = duk_to_int(ctx, -1);
+			//printf("key=%s, value=%d\n", k, v);
+			result[idx++] = v;
+			duk_pop_2(ctx);
 		}
 		duk_pop(ctx); // duk_enum
 
-  } else {
-  	printf("Found NO array\n");
-  }
+	} else {
+		printf("Found NO array\n");
+	}
 
-  return result;
+	return result;
 }
 
 
 
 duk_ret_t nsp_texture_draw_polyLines(duk_context *ctx) {
 
-    duk_require_object_coercible(ctx, 0);
-    int* xys = getIntArray(ctx,0);
+	duk_require_object_coercible(ctx, 0);
+	int* xys = getIntArray(ctx,0);
 
-    int nbPts = duk_require_int(ctx, 1);
+	int nbPts = duk_require_int(ctx, 1);
 
-    uint16_t color = duk_require_int(ctx, 2);
+	uint16_t color = duk_require_int(ctx, 2);
 
 
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "width");
-    int w = duk_require_int(ctx, -1);
-    duk_pop(ctx);
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "width");
+	int w = duk_require_int(ctx, -1);
+	duk_pop(ctx);
 
-    duk_get_prop_string(ctx, -1, "height");
-    int h = duk_require_int(ctx, -1);
-    duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "height");
+	int h = duk_require_int(ctx, -1);
+	duk_pop(ctx);
 
-    if (w <= 0 || h <= 0) {
-			duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
-			duk_throw(ctx);
-    }
+	if (w <= 0 || h <= 0) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
+		duk_throw(ctx);
+	}
 
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL) {
-			duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
-			duk_throw(ctx);
-    }
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
+		duk_throw(ctx);
+	}
 
-		FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
-		  fb->width = w;
-		  fb->height = h;
-		  fb->fb_size = w * h;
-		  fb->fb = bitmap;
-		  drawPolyLines( xys, nbPts, color, fb );
-		free(fb);
-    return 0;
+	FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
+	fb->width = w;
+	fb->height = h;
+	fb->fb_size = w * h;
+	fb->fb = bitmap;
+	drawPolyLines( xys, nbPts, color, fb );
+	free(fb);
+	return 0;
 }
 
 duk_ret_t nsp_texture_fill_polygon(duk_context *ctx) {
 
-    duk_require_object_coercible(ctx, 0);
-    int* xys = getIntArray(ctx,0);
+	duk_require_object_coercible(ctx, 0);
+	int* xys = getIntArray(ctx,0);
 
-    int nbPts = duk_require_int(ctx, 1);
+	int nbPts = duk_require_int(ctx, 1);
 
-    uint16_t color = duk_require_int(ctx, 2);
+	uint16_t color = duk_require_int(ctx, 2);
 
 
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "width");
-    int w = duk_require_int(ctx, -1);
-    duk_pop(ctx);
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "width");
+	int w = duk_require_int(ctx, -1);
+	duk_pop(ctx);
 
-    duk_get_prop_string(ctx, -1, "height");
-    int h = duk_require_int(ctx, -1);
-    duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "height");
+	int h = duk_require_int(ctx, -1);
+	duk_pop(ctx);
 
-    if (w <= 0 || h <= 0) {
-			duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
-			duk_throw(ctx);
-    }
+	if (w <= 0 || h <= 0) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
+		duk_throw(ctx);
+	}
 
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL) {
-			duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
-			duk_throw(ctx);
-    }
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
+		duk_throw(ctx);
+	}
 
-		FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
-		  fb->width = w;
-		  fb->height = h;
-		  fb->fb_size = w * h;
-		  fb->fb = bitmap;
-		  fillPolygon( xys, nbPts, color, fb );
-		free(fb);
-    return 0;
+	FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
+	fb->width = w;
+	fb->height = h;
+	fb->fb_size = w * h;
+	fb->fb = bitmap;
+	fillPolygon( xys, nbPts, color, fb );
+	free(fb);
+	return 0;
 }
 
 duk_ret_t nsp_texture_draw_circle(duk_context *ctx) {
-    int x = duk_require_int(ctx, 0);
-    int y = duk_require_int(ctx, 1);
-
-    int radius = duk_require_int(ctx, 2);
-    uint16_t color = duk_require_int(ctx, 3);
-
-
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "width");
-    int w = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-    duk_get_prop_string(ctx, -1, "height");
-    int h = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-
-    if (w <= 0 || h <= 0) {
-			duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
-			duk_throw(ctx);
-    }
-
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL) {
-			duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
-			duk_throw(ctx);
-    }
-
-		FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
-		  fb->width = w;
-		  fb->height = h;
-		  fb->fb_size = w * h;
-		  fb->fb = bitmap;
-		  drawCircle(x,y,radius,color,fb);
-		free(fb);
-    return 0;
+	int x = duk_require_int(ctx, 0);
+	int y = duk_require_int(ctx, 1);
+
+	int radius = duk_require_int(ctx, 2);
+	uint16_t color = duk_require_int(ctx, 3);
+
+
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "width");
+	int w = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "height");
+	int h = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+
+	if (w <= 0 || h <= 0) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
+		duk_throw(ctx);
+	}
+
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
+		duk_throw(ctx);
+	}
+
+	FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
+	fb->width = w;
+	fb->height = h;
+	fb->fb_size = w * h;
+	fb->fb = bitmap;
+	drawCircle(x,y,radius,color,fb);
+	free(fb);
+	return 0;
 }
 
 duk_ret_t nsp_texture_fill_circle(duk_context *ctx) {
-    int x = duk_require_int(ctx, 0);
-    int y = duk_require_int(ctx, 1);
-
-    int radius = duk_require_int(ctx, 2);
-    uint16_t color = duk_require_int(ctx, 3);
-
-
-    duk_push_this(ctx);
-    duk_get_prop_string(ctx, -1, "width");
-    int w = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-    duk_get_prop_string(ctx, -1, "height");
-    int h = duk_require_int(ctx, -1);
-    duk_pop(ctx);
-
-    if (w <= 0 || h <= 0) {
-			duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
-			duk_throw(ctx);
-    }
-
-    duk_get_prop_string(ctx, -1, "bitmap");
-    size_t size;
-    uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
-    if (bitmap == NULL) {
-			duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
-			duk_throw(ctx);
-    }
-
-		FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
-		  fb->width = w;
-		  fb->height = h;
-		  fb->fb_size = w * h;
-		  fb->fb = bitmap;
-		  fillCircle(x,y,radius,color,fb);
-		free(fb);
-    return 0;
+	int x = duk_require_int(ctx, 0);
+	int y = duk_require_int(ctx, 1);
+
+	int radius = duk_require_int(ctx, 2);
+	uint16_t color = duk_require_int(ctx, 3);
+
+
+	duk_push_this(ctx);
+	duk_get_prop_string(ctx, -1, "width");
+	int w = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+	duk_get_prop_string(ctx, -1, "height");
+	int h = duk_require_int(ctx, -1);
+	duk_pop(ctx);
+
+	if (w <= 0 || h <= 0) {
+		duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "width and height must be positive");
+		duk_throw(ctx);
+	}
+
+	duk_get_prop_string(ctx, -1, "bitmap");
+	size_t size;
+	uint16_t *bitmap = duk_get_buffer(ctx, -1, &size);
+	if (bitmap == NULL) {
+		duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap pointer is NULL");
+		duk_throw(ctx);
+	}
+
+	FbDev* fb = (FbDev*)malloc( 1 * sizeof(FbDev) );
+	fb->width = w;
+	fb->height = h;
+	fb->fb_size = w * h;
+	fb->fb = bitmap;
+	fillCircle(x,y,radius,color,fb);
+	free(fb);
+	return 0;
 }
 
 // ======/Xtase drawing routines/======
 
 
 static const duk_function_list_entry nsp_texture_methods[] = {
-    {"display", nsp_texture_display, 0},
-    {"fill", nsp_texture_fill, 1},
-    {"getPx", nsp_texture_get_pixel, 2},
-    {"setPx", nsp_texture_set_pixel, 3},
+	{"display", nsp_texture_display, 0},
+	{"fill", nsp_texture_fill, 1},
+	{"getPx", nsp_texture_get_pixel, 2},
+	{"setPx", nsp_texture_set_pixel, 3},
 
-    // Xtase drawing routines
-    {"drawLine", nsp_texture_draw_line, 5},
-    {"drawRect", nsp_texture_draw_rect, 5},
-    {"fillRect", nsp_texture_fill_rect, 5},
+	// Xtase drawing routines
+	{"drawLine", nsp_texture_draw_line, 5},
+	{"drawRect", nsp_texture_draw_rect, 5},
+	{"fillRect", nsp_texture_fill_rect, 5},
 
-    {"drawPolyLines", nsp_texture_draw_polyLines, 3},
-    {"fillPolygon", nsp_texture_fill_polygon, 3},
+	{"drawPolyLines", nsp_texture_draw_polyLines, 3},
+	{"fillPolygon", nsp_texture_fill_polygon, 3},
 
-    {"drawCircle", nsp_texture_draw_circle, 4},
-    {"fillCircle", nsp_texture_fill_circle, 4},
+	{"drawCircle", nsp_texture_draw_circle, 4},
+	{"fillCircle", nsp_texture_fill_circle, 4},
 
-    {NULL, NULL, 0}
+	{NULL, NULL, 0}
 };
 
 duk_ret_t dukopen_nsp_texture(duk_context *ctx) {
-    duk_idx_t idx = duk_push_object(ctx);
-    duk_idx_t stats_constr = duk_push_c_function(ctx, nsp_texture_constructor, DUK_VARARGS);
-    duk_idx_t stats_prot = duk_push_object(ctx);
-    duk_put_function_list(ctx, stats_prot, nsp_texture_methods);
-    duk_put_prop_string(ctx, stats_constr, "prototype");
-    duk_put_prop_string(ctx, idx, "Texture");
-    return 1;
+	duk_idx_t idx = duk_push_object(ctx);
+	duk_idx_t stats_constr = duk_push_c_function(ctx, nsp_texture_constructor, DUK_VARARGS);
+	duk_idx_t stats_prot = duk_push_object(ctx);
+	duk_put_function_list(ctx, stats_prot, nsp_texture_methods);
+	duk_put_prop_string(ctx, stats_constr, "prototype");
+	duk_put_prop_string(ctx, idx, "Texture");
+	return 1;
 }