for 4180 final project

Fork of 4DGL-uLCD-SE by jim hamblen

Revision:
3:9ba47197d94f
Parent:
1:8b656995301f
Child:
4:74df7fc26fef
--- a/uLCD_4DGL_Graphics.cpp	Sun Nov 17 04:36:12 2013 +0000
+++ b/uLCD_4DGL_Graphics.cpp	Mon Nov 18 03:05:40 2013 +0000
@@ -22,7 +22,8 @@
 #define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0])
 
 //****************************************************************************************************
-void uLCD_4DGL :: circle(int x, int y , int radius, int color) {   // draw a circle in (x,y)
+void uLCD_4DGL :: circle(int x, int y , int radius, int color)     // draw a circle in (x,y)
+{
     char command[9]= "";
 
     command[0] = CIRCLE;
@@ -47,7 +48,8 @@
 }
 
 //****************************************************************************************************
-void uLCD_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) {   // draw a traingle
+void uLCD_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color)     // draw a traingle
+{
     char command[15]= "";
 
     command[0] = TRIANGLE;
@@ -81,7 +83,8 @@
 }
 
 //****************************************************************************************************
-void uLCD_4DGL :: line(int x1, int y1 , int x2, int y2, int color) {   // draw a line
+void uLCD_4DGL :: line(int x1, int y1 , int x2, int y2, int color)     // draw a line
+{
     char command[11]= "";
 
     command[0] = LINE;
@@ -109,7 +112,8 @@
 }
 
 //****************************************************************************************************
-void uLCD_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) {   // draw a rectangle
+void uLCD_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color)     // draw a rectangle
+{
     char command[11]= "";
 
     command[0] = RECTANGLE;
@@ -137,7 +141,8 @@
 }
 
 //****************************************************************************************************
-void uLCD_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) {   // draw an ellipse
+void uLCD_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color)     // draw an ellipse
+{
     char command[11]= "";
 
     command[0] = ELLIPSE;
@@ -165,7 +170,8 @@
 }
 
 //****************************************************************************************************
-void uLCD_4DGL :: pixel(int x, int y, int color) {   // draw a pixel
+void uLCD_4DGL :: pixel(int x, int y, int color)     // draw a pixel
+{
     char command[7]= "";
 
     command[0] = PIXEL;
@@ -185,9 +191,49 @@
 
     writeCOMMAND(command, 7);
 }
+//****************************************************************************************************
+void uLCD_4DGL :: BLIT(int x, int y, int w, int h, int *colors)     // draw a block of pixels
+{
+    int red5, green6, blue5;
+    writeBYTE('\x00');
+    writeBYTE(BLITCOM);
+    writeBYTE((x >> 8) & 0xFF);
+    writeBYTE(x & 0xFF);
+    writeBYTE((y >> 8) & 0xFF);
+    writeBYTE(y & 0xFF);
+    writeBYTE((w >> 8) & 0xFF);
+    writeBYTE(w & 0xFF);
+    writeBYTE((h >> 8) & 0xFF);
+    writeBYTE(h & 0xFF);
+    for (int i=0; i<w*h; i++) {
+        red5   = (colors[i] >> (16 + 3)) & 0x1F;              // get red on 5 bits
+        green6 = (colors[i] >> (8 + 2))  & 0x3F;              // get green on 6 bits
+        blue5  = (colors[i] >> (0 + 3))  & 0x1F;              // get blue on 5 bits
+        writeBYTE(((red5 << 3)   + (green6 >> 3)) & 0xFF);  // first part of 16 bits color
+        writeBYTE(((green6 << 5) + (blue5 >> 0)) & 0xFF);  // second part of 16 bits color
+    }
+    int resp=0;
+    while (!_cmd.readable()) wait_ms(TEMPO);              // wait for screen answer
+    if (_cmd.readable()) resp = _cmd.getc();           // read response if any
+    switch (resp) {
+        case ACK :                                     // if OK return   1
+            resp =  1;
+            break;
+        case NAK :                                     // if NOK return -1
+            resp = -1;
+            break;
+        default :
+            resp =  0;                                 // else return   0
+            break;
+    }
+#if DEBUGMODE
+    pc.printf("   Answer received : %d\n",resp);
+#endif
 
+}
 //******************************************************************************************************
-int uLCD_4DGL :: read_pixel(int x, int y) { // read screen info and populate data
+int uLCD_4DGL :: read_pixel(int x, int y)   // read screen info and populate data
+{
 
     char command[6]= "";
     command[0] = 0xFF;
@@ -221,7 +267,8 @@
 }
 
 //******************************************************************************************************
-void uLCD_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) {
+void uLCD_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height)
+{
 
     char command[13]= "";
 
@@ -249,7 +296,8 @@
 }
 
 //****************************************************************************************************
-void uLCD_4DGL :: pen_size(char mode) {   // set pen to SOLID or WIREFRAME
+void uLCD_4DGL :: pen_size(char mode)     // set pen to SOLID or WIREFRAME
+{
     char command[2]= "";
 
     command[0] = PENSIZE;