diff Discovery/Src/gfx_engine.c @ 110:cc8e24374b83 FlipDisplay

Added option to handled mirrored display to existing functions
author Ideenmodellierer
date Tue, 01 Jan 2019 21:02:17 +0100
parents e97deb6e2705
children 79b19d56ab08
line wrap: on
line diff
--- a/Discovery/Src/gfx_engine.c	Tue Jan 01 21:00:55 2019 +0100
+++ b/Discovery/Src/gfx_engine.c	Tue Jan 01 21:02:17 2019 +0100
@@ -904,18 +904,31 @@
 
 static inline void gfx_brush(uint8_t thickness, GFX_DrawCfgScreen *hgfx, uint16_t x0, uint16_t y0, uint8_t color)
 {
-	uint32_t pDestination;
+	uint16_t* pDestination;
 	uint8_t offset = thickness/2;
-
-	pDestination = hgfx->FBStartAdress + 2*(x0 - offset)*hgfx->ImageHeight + 2*(y0-offset);
+	int16_t stepdir;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(pSettings->FlipDisplay)
+	{
+		pDestination = hgfx->FBStartAdress + (2*hgfx->ImageHeight * (hgfx->ImageWidth - x0 + offset)) + 2*(480 - y0+offset);
+		stepdir = -1;
+	}
+	else
+	{
+		pDestination = hgfx->FBStartAdress + 2*(x0 - offset)*hgfx->ImageHeight + 2*(y0-offset);
+		stepdir = 1;
+	}
 	for(int x=thickness;x>0;x--)
 	{
 		for(int y=thickness;y>0;y--)
 		{
 			*(__IO uint16_t*)pDestination = 0xFF00 + color;
-			pDestination +=2;
+			pDestination += stepdir;
 		}
-		pDestination += 2*(hgfx->ImageHeight - thickness);
+		pDestination += stepdir * (hgfx->ImageHeight - thickness);
 	}
 }
 
@@ -968,35 +981,63 @@
 
 void GFX_draw_line(GFX_DrawCfgScreen *hgfx, point_t start, point_t stop, uint8_t color)
 {
-	uint32_t pDestination;
+	uint16_t* pDestination;
 	uint32_t j;
-
+	int16_t stepdir;
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+
+	/* horizontal line */
 	if(start.x == stop.x)
 	{
 		if(start.y > stop.y) gfx_flip(&start,&stop);
+
 		pDestination = (uint32_t)hgfx->FBStartAdress;
-		pDestination += start.x * hgfx->ImageHeight * 2;
-		pDestination += start.y * 2;
+		if(pSettings->FlipDisplay)
+		{
+			pDestination += (800 - start.x) * hgfx->ImageHeight;
+			pDestination += (480 - start.y);
+			stepdir = -1;
+		}
+		else
+		{
+			pDestination += start.x * hgfx->ImageHeight;
+			pDestination += start.y;
+			stepdir = 1;
+		}
 		for (j = stop.y - start.y; j > 0; j--)
 		{
-			*(__IO uint16_t*)pDestination = 0xFF00 + color;
-			pDestination += 2;
+				*(__IO uint16_t*)pDestination = 0xFF00 + color;
+				pDestination += stepdir;
 		}
 	}
-	else
+	else /* vertical line ? */
 	if(start.y == stop.y)
 	{
 		if(start.x > stop.x) gfx_flip(&start,&stop);
 		pDestination = (uint32_t)hgfx->FBStartAdress;
-		pDestination += start.x * hgfx->ImageHeight * 2;
-		pDestination += start.y * 2;
+
+		if(pSettings->FlipDisplay)
+		{
+			pDestination += (800 - start.x) * hgfx->ImageHeight;
+			pDestination += (480 - start.y);
+			stepdir = -1;
+		}
+		else
+		{
+			pDestination += start.x * hgfx->ImageHeight;
+			pDestination += start.y;
+			stepdir = 1;
+		}
+
 		for (j = stop.x - start.x; j > 0; j--)
 		{
 			*(__IO uint16_t*)pDestination = 0xFF00 + color;
-			pDestination += hgfx->ImageHeight * 2;
+			pDestination += stepdir * hgfx->ImageHeight;
 		}
 	}
-	else // diagonal
+	else /* diagonal */
 	{
 		int x0 = start.x;
 		int y0 = start.y;
@@ -1008,8 +1049,17 @@
 	 
 		for(;;)
 		{
-			pDestination = (uint32_t)hgfx->FBStartAdress;
-			pDestination += ((x0 * hgfx->ImageHeight) + y0) * 2;
+			pDestination = (uint16_t*)hgfx->FBStartAdress;
+
+			if(pSettings->FlipDisplay)
+			{
+				pDestination += (((800 - x0) * hgfx->ImageHeight) + (480 - y0));
+			}
+			else
+			{
+				pDestination += ((x0 * hgfx->ImageHeight) + y0);
+			}
+
 			*(__IO uint16_t*)pDestination = 0xFF00 + color;
 			if (x0==x1 && y0==y1) break;
 			e2 = err;
@@ -1022,7 +1072,53 @@
 
 void GFX_draw_image_monochrome(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image, uint8_t color)
 {
-	uint32_t pDestination;
+	uint16_t* pDestination;
+	uint32_t j;
+	point_t start, stop;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	start.x = window.left;
+	start.y = (hgfx->ImageHeight - image->height - window.top);
+	stop.y = start.y + image->height;
+	stop.x = start.x + image->width;
+	j = 0;
+
+	if(pSettings->FlipDisplay)
+	{
+		for(int xx = start.x; xx < stop.x; xx++)
+		{
+			pDestination = hgfx->FBStartAdress;
+			pDestination += (hgfx->ImageHeight - start.y) + (stop.x * hgfx->ImageHeight) ;
+			pDestination -= (xx - start.x) * hgfx->ImageHeight;
+
+			for(int yy = start.y; yy < stop.y; yy++)
+			{
+				*(__IO uint16_t*)pDestination-- = image->data[j++] << 8 + color;
+			}
+		}
+	}
+	else
+	{
+		for(int xx = start.x; xx < stop.x; xx++)
+		{
+			pDestination = (uint32_t)hgfx->FBStartAdress;
+			pDestination += xx * hgfx->ImageHeight;
+			pDestination += start.y;
+			for(int yy = start.y; yy < stop.y; yy++)
+			{
+				*(__IO uint16_t*)pDestination++ = image->data[j++] << 8 + color;
+			}
+		}
+	}
+}
+	
+
+void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image)
+{
+	uint16_t* pDestination;
+
 	uint32_t j;
 	point_t start, stop;
 
@@ -1032,47 +1128,37 @@
 	stop.x = start.x + image->width;
 	j = 0;
 	
-	for(int xx = start.x; xx < stop.x; xx++)
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(pSettings->FlipDisplay)
 	{
-		pDestination = (uint32_t)hgfx->FBStartAdress;
-		pDestination += xx * hgfx->ImageHeight * 2;
-		pDestination += start.y * 2;
-		for(int yy = start.y; yy < stop.y; yy++)
+		for(int xx = start.x; xx < stop.x; xx++)
 		{
-			*(__IO uint8_t*)pDestination = color;
-			pDestination += 1;
-			*(__IO uint8_t*)pDestination = image->data[j++];
-			pDestination += 1;
+			pDestination = (uint16_t*)hgfx->FBStartAdress;
+			pDestination += (hgfx->ImageHeight - start.y) + (stop.x * hgfx->ImageHeight);
+			pDestination -= (xx - start.x) * hgfx->ImageHeight;
+
+			for(int yy = start.y; yy < stop.y; yy++)
+			{
+			//	*(__IO uint16_t*)pDestination-- = image->data[j++] << 8 | 0xFF;
+				*(__IO uint16_t*)pDestination-- = 0xFF << 8 | image->data[j++];
+			}
 		}
-	}	
-}
-	
-
-void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image)
-{
-	uint32_t pDestination;
-	uint32_t j;
-	point_t start, stop;
-
-	start.x = window.left;
-	start.y = (hgfx->ImageHeight - image->height - window.top);
-	stop.y = start.y + image->height;
-	stop.x = start.x + image->width;
-	j = 0;
-	
-	for(int xx = start.x; xx < stop.x; xx++)
+	}
+	else
 	{
-		pDestination = (uint32_t)hgfx->FBStartAdress;
-		pDestination += xx * hgfx->ImageHeight * 2;
-		pDestination += start.y * 2;
-		for(int yy = start.y; yy < stop.y; yy++)
+		for(int xx = start.x; xx < stop.x; xx++)
 		{
-			*(__IO uint8_t*)pDestination = image->data[j++];
-			pDestination += 1;
-			*(__IO uint8_t*)pDestination = 0xFF;
-			pDestination += 1;
+			pDestination = (uint32_t)hgfx->FBStartAdress;
+			pDestination += xx * hgfx->ImageHeight;
+			pDestination += start.y;
+			for(int yy = start.y; yy < stop.y; yy++)
+			{
+				*(__IO uint16_t*)pDestination++ = 0xFF << 8 | image->data[j++];
+			}
 		}
-	}	
+	}
 }
 
 
@@ -1120,15 +1206,23 @@
 /* this is NOT fast nor optimized */
 void GFX_draw_pixel(GFX_DrawCfgScreen *hgfx, int16_t x, int16_t y, uint8_t color)
 {
-	uint32_t pDestination;
-	
-	pDestination = (uint32_t)hgfx->FBStartAdress;
-	pDestination += x * hgfx->ImageHeight * 2;
-	pDestination += y * 2;
-	
-	*(__IO uint8_t*)pDestination = color;
-	pDestination += 1;
-	*(__IO uint8_t*)pDestination = 0xFF;
+	uint16_t* pDestination;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	pDestination = (uint16_t*)hgfx->FBStartAdress;
+	if(pSettings->FlipDisplay)
+	{
+		pDestination += (800 - x) * hgfx->ImageHeight;
+		pDestination += (480 - y);
+	}
+	else
+	{
+		pDestination += x * hgfx->ImageHeight;
+		pDestination += y;
+	}
+	*(__IO uint16_t*)pDestination = 0xFF << 8 | color;
 }
 
 
@@ -1271,7 +1365,8 @@
 		{
             p1.x = window.left + (int)(i * deltaline + 0.5f);
             p2.x = p1.x ;
-            GFX_draw_colorline(hgfx, p1,p2, color );
+            //GFX_draw_colorline(hgfx, p1,p2, color );
+            GFX_draw_line(hgfx, p1,p2, color );
 		}
     }
     if(vdeltaline > 0)
@@ -1282,7 +1377,8 @@
 		{
             p1.x = window.left + (int)(i * vdeltaline + 0.5f);
             p2.x = p1.x ;
-            GFX_draw_colorline(hgfx, p1,p2, color );
+          //  GFX_draw_colorline(hgfx, p1,p2, color );
+            GFX_draw_line(hgfx, p1,p2, color );
 		}
     }
     if(hlines > 0)
@@ -1294,7 +1390,8 @@
 		{
             p1.y = 479 - window.top - (int)(i * deltaline + 0.5f);
             p2.y = p1.y;
-            GFX_draw_colorline(hgfx, p1,p2, color );
+           // GFX_draw_colorline(hgfx, p1,p2, color );
+            GFX_draw_line(hgfx, p1,p2, color );
 		}
     }
 }
@@ -1406,10 +1503,14 @@
 //  ===============================================================================
 
 
-void GFX_graph_print(GFX_DrawCfgScreen *hgfx, const  SWindowGimpStyle *window, int16_t drawVeilUntil, uint8_t Xdivide, uint16_t dataMin, uint16_t dataMax,  uint16_t *data, uint16_t datalength, uint8_t color, uint8_t *colour_data)
+void GFX_graph_print(GFX_DrawCfgScreen *hgfx, const  SWindowGimpStyle *window, const int16_t drawVeilUntil, uint8_t Xdivide, uint16_t dataMin, uint16_t dataMax,  uint16_t *data, uint16_t datalength, uint8_t color, uint8_t *colour_data)
 {
-  //uint32_t pDestination,pDestination_old,
-	uint32_t pDestination_tmp,pDestination_end, pDestination_start, pDestination_zero_veil;
+	uint16_t* pDestination_tmp;
+	uint16_t* pDestination_start;
+	uint16_t* pDestination_end;
+	uint16_t* pDestination_zero_veil;
+
+	SSettings* pSettings;
 
 	uint32_t max = 0;
 	int windowheight = -1;
@@ -1429,6 +1530,9 @@
 	uint8_t colorDataTemp;
 	uint8_t	colormask = 0;
 
+	pSettings = settingsGetPointer();
+	pDestination_zero_veil = 0;
+
 	if(dataMin > dataMax)
 	{
 		uint16_t dataFlip;
@@ -1441,7 +1545,8 @@
 		invert = 0;
 
 	colormask = color;
-	
+
+	pSettings = settingsGetPointer();
 		
 	if(window->bottom > 479)
 		return;
@@ -1522,15 +1627,32 @@
 		if(h_ulong > (window->bottom - window->top))
 			h_ulong = (window->bottom - window->top);
 
-		if(drawVeilUntil > 0)
+		if(!pSettings->FlipDisplay)
 		{
-				pDestination_zero_veil = hgfx->FBStartAdress + 2 * (  (479 - (drawVeilUntil - 2) ) + ( (w1 + window->left) * hgfx->ImageHeight) );
+			if(drawVeilUntil > 0)
+			{
+					pDestination_zero_veil = (uint16_t*)hgfx->FBStartAdress;
+					pDestination_zero_veil += ((479 - (drawVeilUntil - 2) ) + ((w1 + window->left) * hgfx->ImageHeight) );
+			}
+			else if(drawVeilUntil < 0 )
+			{
+					pDestination_zero_veil = hgfx->FBStartAdress;
+					pDestination_zero_veil += ((479 + (drawVeilUntil)) + ((w1 + window->left) * hgfx->ImageHeight) );
+			}
 		}
-		else if(drawVeilUntil < 0 )
+		else
 		{
-				pDestination_zero_veil = hgfx->FBStartAdress + 2 * (  (479 + (drawVeilUntil) ) + ( (w1 + window->left) * hgfx->ImageHeight) );
+			if(drawVeilUntil > 0)
+			{
+				pDestination_zero_veil = hgfx->FBStartAdress;
+				pDestination_zero_veil += (((drawVeilUntil) ) + ( (window->right - w1) * hgfx->ImageHeight) );
+							}
+			else if(drawVeilUntil < 0 )
+			{
+				pDestination_zero_veil = hgfx->FBStartAdress;
+				pDestination_zero_veil += 479 -  drawVeilUntil + ( (window->right - w1 -1) * hgfx->ImageHeight);
+			}
 		}
-
 		if(h_ulong + window->top > max)
 		{
 			max = h_ulong + window->top;
@@ -1543,29 +1665,65 @@
 			//output_mask[pointer] = true;
 			if(w1 > 0)
 			{
-				pDestination_start = hgfx->FBStartAdress +  (2 * ((479 - (window->top)) + ((w1 + window->left) * hgfx->ImageHeight)));
-				pDestination_end = pDestination_start;
-				if(h_ulong >= h_ulong_old)
+				pDestination_start = hgfx->FBStartAdress;
+				if(!pSettings->FlipDisplay)
 				{
-					pDestination_start -= 2 * h_ulong_old;
-					pDestination_end -= 2 * h_ulong;
+					pDestination_start += (((479 - (window->top)) + ((w1 + window->left) * hgfx->ImageHeight)));
 				}
 				else
 				{
-					pDestination_start -= 2 * h_ulong;
-					pDestination_end -= 2 * h_ulong_old;
+					pDestination_start += (((window->top) + ((window->right - w1) * hgfx->ImageHeight)));
 				}
+				pDestination_end = pDestination_start;
+
+				if(!pSettings->FlipDisplay)
+				{
+					if(h_ulong >= h_ulong_old)
+					{
+						pDestination_start -= h_ulong_old;
+						pDestination_end -= h_ulong;
+					}
+					else
+					{
+						pDestination_start -= h_ulong;
+						pDestination_end -= h_ulong_old;
+					}
+				}
+				else
+				{
+					if(h_ulong < h_ulong_old)
+					{
+						pDestination_start += h_ulong_old;
+						pDestination_end += h_ulong;
+					}
+					else
+					{
+						pDestination_start += h_ulong;
+						pDestination_end += h_ulong_old;
+					}
+				}
+
 				
 				// deco stops
 				if(drawVeilUntil < 0)
 				{
-					pDestination_tmp = pDestination_end;
-					while(pDestination_tmp <= pDestination_zero_veil)
+					if(!pSettings->FlipDisplay)
 					{
-							*(__IO uint8_t*)pDestination_tmp = colormask;
-											pDestination_tmp -= 1;
-											*(__IO uint8_t*)pDestination_tmp = 0x80;
-											pDestination_tmp += 3;
+						pDestination_tmp = pDestination_end;
+						while(pDestination_tmp <= pDestination_zero_veil)
+						{
+							*(__IO uint16_t*)pDestination_tmp = (0x80 << 8) | colormask;
+							pDestination_tmp++;
+						}
+					}
+					else
+					{
+						pDestination_tmp = pDestination_zero_veil;
+						while(pDestination_tmp <=  pDestination_end)
+						{
+							*(__IO uint16_t*)pDestination_tmp = (0x80 << 8) | colormask;
+							pDestination_tmp++;
+						}
 					}
 				}
 				else
@@ -1573,20 +1731,31 @@
 					// regular graph with veil underneath if requested
 					// von oben nach unten
 					// von grossen pDestination Werten zu kleinen pDestination Werten
-					pDestination_tmp = pDestination_start;
-					while(pDestination_tmp >= pDestination_end)
+					{
+						pDestination_tmp = pDestination_start;
+						while(pDestination_tmp >= pDestination_end)
+						{
+							*(__IO uint16_t*)pDestination_tmp = (0xFF << 8) | colormask ;
+							pDestination_tmp--;
+						}
+					}
+
+					if(!pSettings->FlipDisplay)
 					{
-							*(__IO uint8_t*)pDestination_tmp = colormask;
-											pDestination_tmp += 1;
-											*(__IO uint8_t*)pDestination_tmp = 0xFF;
-											pDestination_tmp -= 3;
+						while((drawVeilUntil > 0) && (pDestination_tmp >= pDestination_zero_veil))
+						{
+							*(__IO uint16_t*)pDestination_tmp = (0x20 << 8) | colormask ;
+							pDestination_tmp--;
+						}
 					}
-					while((drawVeilUntil > 0) && (pDestination_tmp >= pDestination_zero_veil))
+					else
 					{
-							*(__IO uint8_t*)pDestination_tmp = colormask;
-											pDestination_tmp += 1;
-											*(__IO uint8_t*)pDestination_tmp = 0x20;
-											pDestination_tmp -= 3;
+						pDestination_tmp = pDestination_start;
+						while((drawVeilUntil > 0) && (pDestination_tmp <=  pDestination_zero_veil))
+						{
+							*(__IO uint16_t*)pDestination_tmp = (0x20 << 8) | colormask ;
+							pDestination_tmp++;
+						}
 					}
 				}
 			}
@@ -1671,11 +1840,13 @@
 
 void GFX_draw_box(GFX_DrawCfgScreen *hgfx, point_t LeftLow, point_t WidthHeight, uint8_t Style, uint8_t color)
 {
-	uint32_t pDestination, pStart;
+	uint16_t* pDestination;
+	uint16_t* pStart;
 	uint32_t j;
 	uint32_t lineWidth, lineHeight;
 	int x, y;
 	uint8_t intensity;
+	int stepdir;
 
 	typedef struct {
 			int x;
@@ -1701,66 +1872,86 @@
 		{4,3,110}
 	};
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
 	lineWidth = WidthHeight.x;
 	lineHeight = WidthHeight.y;
-
 	pStart = (uint32_t)hgfx->FBStartAdress;
-	pStart += LeftLow.x * hgfx->ImageHeight * 2;
-	pStart += LeftLow.y * 2;
+
+	if(!pSettings->FlipDisplay)
+	{
+		pStart += LeftLow.x * hgfx->ImageHeight;
+		pStart += LeftLow.y;
+		stepdir = 1;
+	}
+	else
+	{
+		pStart += (800 - LeftLow.x - 1) * hgfx->ImageHeight;
+		pStart += (480 - LeftLow.y);
+		stepdir = -1;
+	}
+	pStart = pStart;
 
 	// Untere Linie
 	pDestination = pStart;
 	if(Style)
 	{
-		pDestination += 2 * 10 * hgfx->ImageHeight;
+		pDestination += stepdir * 10 * hgfx->ImageHeight;
 		lineWidth -= 18;
 	}
 	for (j = lineWidth; j > 0; j--)
 	{
+
 		*(__IO uint16_t*)pDestination = 0xFF00 + color;
-		pDestination += hgfx->ImageHeight * 2;
+		pDestination += stepdir * hgfx->ImageHeight;
 	}
 
 	// Obere Linie
-	pDestination = pStart + 2 * WidthHeight.y;
+
+	pDestination = pStart + stepdir * WidthHeight.y;
 	if(Style)
 	{
-		pDestination += 2 * 10 * hgfx->ImageHeight;
+		pDestination += stepdir * 10 * hgfx->ImageHeight;
 	}
 
 	for (j = lineWidth; j > 0; j--)
 	{
 		*(__IO uint16_t*)pDestination = 0xFF00 + color;
-		pDestination += hgfx->ImageHeight * 2;
+		pDestination += stepdir * hgfx->ImageHeight;
 	}
 
 	// Linke Linie
 	pDestination = pStart;
+
 	if(Style)
 	{
-		pDestination += 2 * 10;
+		pDestination += stepdir * 10;
 		lineHeight -= 18;
 	}
 
 	for (j = lineHeight; j > 0; j--)
 	{
 		*(__IO uint16_t*)pDestination = 0xFF00 + color;
-		pDestination += 2;
+		pDestination += stepdir;
 	}
 
+
 	// Rechte Linie
-	pDestination = pStart + 2 * WidthHeight.x * hgfx->ImageHeight;
+
+	pDestination = pStart + stepdir * WidthHeight.x * hgfx->ImageHeight;
 	if(Style)
 	{
-		pDestination += 2 * 10;
+		pDestination += stepdir * 10;
 	}
 
 	for (j = lineHeight; j > 0; j--)
 	{
 		*(__IO uint16_t*)pDestination = 0xFF00 + color;
-		pDestination += 2;
+		pDestination += stepdir;
 	}
 
+
 	// Ecken wenn notwendig == Style
 	if(Style)
 	{
@@ -1769,60 +1960,61 @@
 		x = corner[0].x;
 		y = corner[0].y;
 		intensity = corner[0].intensity;
-    *(__IO uint16_t*)(pDestination  + 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+
+    *(__IO uint16_t*)(pDestination  + stepdir * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
 
 		for(j = 15; j > 0; j--)
 		{
 			x = corner[j].x;
 			y = corner[j].y;
 			intensity = corner[j].intensity;
-			*(__IO uint16_t*)(pDestination + 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
-			*(__IO uint16_t*)(pDestination + 2	* (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir	* (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
 		}
 		// links oben
-		pDestination = pStart + 2 * WidthHeight.y;
+		pDestination = pStart + stepdir * WidthHeight.y;
 		x = corner[0].x;
 		y = corner[0].y;
 		intensity = corner[0].intensity;
-    *(__IO uint16_t*)(pDestination + 2 * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+    *(__IO uint16_t*)(pDestination + stepdir * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
 
 		for(j = 15; j > 0; j--)
 		{
 			x = corner[j].x;
 			y = corner[j].y;
 			intensity = corner[j].intensity;
-			*(__IO uint16_t*)(pDestination + 2 * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
-			*(__IO uint16_t*)(pDestination + 2 * (-x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * (-x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
 		}
 		// rechts unten
-		pDestination = pStart + 2 * WidthHeight.x * hgfx->ImageHeight;
+		pDestination = pStart + stepdir * WidthHeight.x * hgfx->ImageHeight;
 		x = corner[0].x;
 		y = corner[0].y;
 		intensity = corner[0].intensity;
-    *(__IO uint16_t*)(pDestination + 2 * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+    *(__IO uint16_t*)(pDestination + stepdir * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
 
 		for(j = 15; j > 0; j--)
 		{
 			x = corner[j].x;
 			y = corner[j].y;
 			intensity = corner[j].intensity;
-			*(__IO uint16_t*)(pDestination + 2 * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
-			*(__IO uint16_t*)(pDestination + 2 * (x - (y * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * (x - (y * hgfx->ImageHeight))) = (intensity << 8) + color;
 		}
 		// rechts oben
-		pDestination = pStart + 2 * WidthHeight.y + 2 * WidthHeight.x * hgfx->ImageHeight;
+		pDestination = pStart + stepdir * WidthHeight.y + stepdir * WidthHeight.x * hgfx->ImageHeight;
 		x = corner[0].x;
 		y = corner[0].y;
 		intensity = corner[0].intensity;
-    *(__IO uint16_t*)(pDestination - 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+    *(__IO uint16_t*)(pDestination + stepdir * -1 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
 
 		for(j = 15; j > 0; j--)
 		{
 			x = corner[j].x;
 			y = corner[j].y;
 			intensity = corner[j].intensity;
-			*(__IO uint16_t*)(pDestination - 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
-			*(__IO uint16_t*)(pDestination - 2 * (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * -1 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * -1 * (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
 		}
 	}
 }
@@ -1871,6 +2063,11 @@
 
     GFX_DrawCfgWindow	hgfx;
 
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+
 	if(XrightGimpStyle > 799)
 		XrightGimpStyle = 799;
 	if(XleftGimpStyle >= XrightGimpStyle)
@@ -1881,14 +2078,27 @@
 	hgfx.WindowNumberOfTextLines = 1;
 	hgfx.WindowLineSpacing = 0;
 	hgfx.WindowTab = 0;
-	hgfx.WindowX0 = XleftGimpStyle;
-	hgfx.WindowX1 = XrightGimpStyle;
-	hgfx.WindowY1 = 479 - YtopGimpStyle;
-	if(hgfx.WindowY1 < Font->height)
-		hgfx.WindowY0 = 0;
+
+	if(!pSettings->FlipDisplay)
+	{
+		hgfx.WindowX0 = XleftGimpStyle;
+		hgfx.WindowX1 = XrightGimpStyle;
+		hgfx.WindowY1 = 479 - YtopGimpStyle;
+		if(hgfx.WindowY1 < Font->height)
+			hgfx.WindowY0 = 0;
+		else
+			hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+	}
 	else
-		hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-
+	{
+		hgfx.WindowX0 = 800 - XrightGimpStyle;
+		hgfx.WindowX1 = 800 - XleftGimpStyle;
+		hgfx.WindowY0 = YtopGimpStyle;
+		if(hgfx.WindowY0 + Font->height > 480)
+			hgfx.WindowY1 = 480;
+		else
+			hgfx.WindowY1 = hgfx.WindowY0 + Font->height;
+	}
 	GFX_write_label(Font, &hgfx, text, color);
 }
 
@@ -2374,7 +2584,7 @@
 	uint32_t i, j;
 	uint32_t width, height;
 	uint32_t found;
-	uint32_t pDestination;
+	uint16_t* pDestination;
 	uint32_t pDestinationColor;
 	uint32_t pSource;
 	uint32_t OffsetDestination;
@@ -2385,7 +2595,20 @@
 	uint8_t fill;
 	uint32_t widthFont, heightFont;
 	uint32_t nextLine;
-	
+	int32_t stepdir;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(pSettings->FlipDisplay)
+	{
+		stepdir = -1;	/* decrement address while putting pixels */
+	}
+	else
+	{
+		stepdir = 1;
+	}
+
 
 	if(hgfx->Image->ImageWidth <= (hgfx->WindowX0 + cfg->Xdelta))
 		return 0x0000FFFF;
@@ -2411,16 +2634,25 @@
 
 	height = heightFont*2;
 	width = widthFont*2;
-	
-	OffsetDestination = 2 * (hgfx->Image->ImageHeight - height);
-
-	pDestination += (hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight * 2;
-	pDestination += (hgfx->WindowY0 + cfg->Ydelta) * 2;
-	nextLine = hgfx->Image->ImageHeight * 2;
+
+
+	if(pSettings->FlipDisplay)
+	{
+		pDestination += (uint32_t)(hgfx->WindowX1 - cfg->Xdelta) * hgfx->Image->ImageHeight; /* set pointer to delta row */
+		pDestination += (hgfx->WindowY1 - cfg->Ydelta);							   /* set pointer to delta colum */
+	}
+	else
+	{
+		pDestination += (uint32_t)(hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight;  /* set pointer to delta row */
+		pDestination += (hgfx->WindowY0 + cfg->Ydelta);							   /* set pointer to delta colum */
+	}
+	OffsetDestination = (hgfx->Image->ImageHeight - height);
+	nextLine = hgfx->Image->ImageHeight;
 
 // -----------------------------
 	char_truncated_WidthFlag = 0;
 	width_left = hgfx->Image->ImageWidth - (hgfx->WindowX0 + cfg->Xdelta);
+
 	if(width_left < width)
 	{
 		char_truncated_WidthFlag = 1;
@@ -2428,6 +2660,7 @@
 		widthFont = width/2;
 	}
 // -----------------------------
+
 	char_truncated_Height = 0;
 	height_left = hgfx->Image->ImageHeight - (hgfx->WindowY0 + cfg->Ydelta);
 	if(height_left < height)
@@ -2441,26 +2674,12 @@
 		height = height_left;
 		heightFont = height/2;
 	}
-	OffsetDestination += 2 * char_truncated_Height;
+
+	OffsetDestination += char_truncated_Height;
 // -----------------------------
 	if(height == 0)
 		return 0x0000FFFF;
 // -----------------------------
-	
-	if((cfg->color > 0) )
-	{
-		pDestinationColor = pDestination - 1;
-
-		for(i = width; i > 0; i--)
-		{
-			for (j = height; j > 0; j--)
-			{
-				*(__IO uint32_t*)pDestinationColor =  cfg->color;
-				pDestinationColor += 2;
-			}
-			pDestinationColor += OffsetDestination;
-		}
-	}
 
 	if(cfg->singleSpaceWithSizeOfNextChar)
 	{
@@ -2476,12 +2695,12 @@
 		{
 			for (j = height; j > 0; j--)
 			{
-				*(__IO uint8_t*)pDestination = fill;
-				pDestination += 2;
-				*(__IO uint8_t*)pDestination = fill;
-				pDestination += 2;
+				*(__IO uint16_t*)pDestination =  cfg->color << 8 | fill;
+				pDestination += stepdir;
+				*(__IO uint16_t*)pDestination =  cfg->color << 8 | fill;
+				pDestination += stepdir;
 			}
-			pDestination += OffsetDestination;
+			pDestination += stepdir * OffsetDestination;
 		}
 	}
 	else
@@ -2496,37 +2715,37 @@
 				{
 					for (j = heightFont; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
 					}
 					pSource += char_truncated_Height;
 				}
@@ -2535,33 +2754,33 @@
 					pSource++;
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 |0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
 					}
 				}
-				pDestination += OffsetDestination + nextLine;
+				pDestination += (OffsetDestination + nextLine) * stepdir;
 			}
 		}
 		else
@@ -2573,21 +2792,21 @@
 				{
 					for (j = heightFont; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
 					}
 					pSource += char_truncated_Height;
 				}
@@ -2596,24 +2815,24 @@
 					pSource++;
 					for (j = heightFont; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
 					}
 				}
-				pDestination += OffsetDestination + nextLine;
+				pDestination += (OffsetDestination + nextLine) * stepdir;
 			}
 		}
-	}
+	} /* inverted */
 	else
 	{
 		if((heightFont & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
@@ -2625,46 +2844,46 @@
 				{
 					for (j = heightFont; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
 					}
 					pSource += char_truncated_Height;
 				}
 				else
 				{
 					pSource++;
-					pDestination +=  2 * height;
+					pDestination +=  stepdir * height;
 				}
-				pDestination += OffsetDestination + nextLine;
+				pDestination += stepdir * (OffsetDestination + nextLine);
 			}
 		}
 		else
@@ -2676,30 +2895,30 @@
 				{
 					for (j = heightFont; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
 					}
 					pSource += char_truncated_Height;
 				}
 				else
 				{
 					pSource++;
-					pDestination +=  2 * height;
+					pDestination +=  stepdir * height;
 				}
-				pDestination += OffsetDestination + nextLine;
+				pDestination += stepdir * (OffsetDestination + nextLine);
 			}
 		}
 	}
@@ -2747,7 +2966,7 @@
 	uint32_t i, j;
 	uint32_t width, height;
 	uint32_t found;
-	uint32_t pDestination;
+	uint16_t* pDestination;
 	uint32_t pDestinationColor;
 	uint32_t pSource;
 	uint32_t OffsetDestination;
@@ -2756,6 +2975,19 @@
 	uint32_t char_truncated_WidthFlag;
 	uint32_t char_truncated_Height;
 	uint8_t fill;
+	int16_t stepdir;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(pSettings->FlipDisplay)
+	{
+		stepdir = -1;	/* decrement address while putting pixels */
+	}
+	else
+	{
+		stepdir = 1;
+	}
 
 	if(hgfx->Image->ImageWidth <= (hgfx->WindowX0 + cfg->Xdelta))
 		return 0x0000FFFF;
@@ -2784,16 +3016,28 @@
 
 
 	pSource = ((uint32_t)Font->chars[i].image->data);
-	pDestination = 1 + (uint32_t)hgfx->Image->FBStartAdress;
+	pDestination = (uint32_t)hgfx->Image->FBStartAdress + 1;
 
 	height = Font->chars[i].image->height;
 	width = Font->chars[i].image->width;
 
-	OffsetDestination = 2 * (hgfx->Image->ImageHeight - height);
-
-	pDestination += (hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight * 2;
-	pDestination += (hgfx->WindowY0 + cfg->Ydelta) * 2;
-
+	OffsetDestination = hgfx->Image->ImageHeight - height;
+
+
+	/* Xyyyyy   y= height */
+	/* Xyyyyy   x= width  */
+	/* Xyyyyy             */
+
+	if(pSettings->FlipDisplay)
+	{
+		pDestination += (hgfx->WindowX1 - cfg->Xdelta) * hgfx->Image->ImageHeight; /* set pointer to delta row */
+		pDestination += (hgfx->WindowY1 - cfg->Ydelta);							   /* set pointer to delta colum */
+	}
+	else
+	{
+		pDestination += (hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight; /* set pointer to delta row */
+		pDestination += (hgfx->WindowY0 + cfg->Ydelta);							   /* set pointer to delta colum */
+	}
 
 
 // -----------------------------
@@ -2817,27 +3061,12 @@
 		}
 		height = height_left;
 	}
-	OffsetDestination += 2 * char_truncated_Height;
+	OffsetDestination += char_truncated_Height;
 // -----------------------------
 	if(height == 0)
 		return 0x0000FFFF;
 // -----------------------------
 	
-	if((cfg->color > 0) )//&& (cfg->color < 6))
-	{
-		pDestinationColor = pDestination - 1;
-
-		for(i = width; i > 0; i--)
-		{
-			for (j = height; j > 0; j--)
-			{
-				*(__IO uint32_t*)pDestinationColor =  cfg->color;//ColorLUT[cfg->color - 1];
-				pDestinationColor += 2;
-			}
-			pDestinationColor += OffsetDestination;
-		}
-	}
-
 	if(cfg->singleSpaceWithSizeOfNextChar)
 	{
 		cfg->singleSpaceWithSizeOfNextChar = 0;
@@ -2852,12 +3081,12 @@
 		{
 			for (j = height; j > 0; j--)
 			{
-				*(__IO uint8_t*)pDestination = fill;
-				pDestination += 2;
-				*(__IO uint8_t*)pDestination = fill;
-				pDestination += 2;
+				*(__IO uint16_t*)pDestination =  cfg->color << 8 | fill;
+				pDestination += stepdir;
+				*(__IO uint16_t*)pDestination =  cfg->color << 8 | fill;
+				pDestination += stepdir;
 			}
-			pDestination += OffsetDestination;
+			pDestination += stepdir * OffsetDestination;
 		}
 	}
 	else
@@ -2870,39 +3099,36 @@
 			{
 				if(*(uint8_t*)pSource != 0x01)
 				{
+
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
 					}
 					pSource += char_truncated_Height;
 				}
-				else
+				else /* empty line => fast fill */
 				{
 					pSource++;
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
 					}
 				}
-				pDestination += OffsetDestination;
+				pDestination += stepdir * OffsetDestination;
 			}
 		}
 		else
@@ -2914,12 +3140,10 @@
 				{
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
 					}
 					pSource += char_truncated_Height;
 				}
@@ -2928,50 +3152,49 @@
 					pSource++;
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
 					}
 				}
-				pDestination += OffsetDestination;
+				pDestination += stepdir * OffsetDestination;
 			}
 		}
 	}
-	else
+	else  /* not inverted */
 	{
 		if((height & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
 		{
+
 			height /= 4;
+
 			for(i = width; i > 0; i--)
 			{
 				if(*(uint8_t*)pSource != 0x01)
 				{
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
+							*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+							pDestination += stepdir;
+							*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+							pDestination += stepdir;
+							*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+							pDestination += stepdir;
+							*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+							pDestination += stepdir;
 					}
 					pSource += char_truncated_Height;
 				}
 				else
 				{
 					pSource++;
-					pDestination +=  2 * height * 4;
+					pDestination += stepdir * height * 4;
 				}
-				pDestination += OffsetDestination;
+				pDestination += stepdir * OffsetDestination;
 			}
 		}
+
 		else
 		{
 			height /= 2;
@@ -2981,21 +3204,19 @@
 				{
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+						pDestination += stepdir;
 					}
 					pSource += char_truncated_Height;
 				}
 				else
 				{
 					pSource++;
-					pDestination +=  2 * height * 2;
+					pDestination += stepdir * height * 2;
 				}
-				pDestination += OffsetDestination;
+				pDestination += stepdir * OffsetDestination;
 			}
 		}
 	}
@@ -3831,24 +4052,43 @@
 {
 	GFX_DrawCfgWindow	hgfx;
 
-	if(XrightGimpStyle > 799)
-		XrightGimpStyle = 799;
-	if(XleftGimpStyle >= XrightGimpStyle)
-		XleftGimpStyle = 0;
-	if(YtopGimpStyle > 479)
-		YtopGimpStyle = 479;
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(!pSettings->FlipDisplay)
+	{
+		if(XrightGimpStyle > 799)
+			XrightGimpStyle = 799;
+		if(XleftGimpStyle >= XrightGimpStyle)
+			XleftGimpStyle = 0;
+		if(YtopGimpStyle > 479)
+			YtopGimpStyle = 479;
+	}
 	hgfx.Image = tMscreen;
 	hgfx.WindowNumberOfTextLines = 1;
 	hgfx.WindowLineSpacing = 0;
 	hgfx.WindowTab = 0;
-	hgfx.WindowX0 = XleftGimpStyle;
-	hgfx.WindowX1 = XrightGimpStyle;
-	hgfx.WindowY1 = 479 - YtopGimpStyle;
-	if(hgfx.WindowY1 < Font->height)
-		hgfx.WindowY0 = 0;
+
+	if(!pSettings->FlipDisplay)
+	{
+		hgfx.WindowX0 = XleftGimpStyle;
+		hgfx.WindowX1 = XrightGimpStyle;
+		hgfx.WindowY1 = 479 - YtopGimpStyle;
+		if(hgfx.WindowY1 < Font->height)
+			hgfx.WindowY0 = 0;
+		else
+			hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+	}
 	else
-		hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-
+	{
+		hgfx.WindowX0 = 800 - XrightGimpStyle;
+		hgfx.WindowX1 = 800 - XleftGimpStyle;
+		hgfx.WindowY0 = YtopGimpStyle;
+		if(hgfx.WindowY0 + Font->height >= 479)
+			hgfx.WindowY1 = 479;
+		else
+			hgfx.WindowY1 = hgfx.WindowY0 + Font->height;
+	}
 	GFX_write_string_color(Font, &hgfx, text, 0, color);
 }
 
@@ -3861,14 +4101,25 @@
 	hgfx.Image = tMscreen;
 	hgfx.WindowNumberOfTextLines = 1;
 	hgfx.WindowLineSpacing = 0;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
 	hgfx.WindowTab = 0;
 	hgfx.WindowX0 = 20;
 	hgfx.WindowX1 = 779;
-	hgfx.WindowY1 = 479;
-	hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-	
+
+	if(!pSettings->FlipDisplay)
+	{
+		hgfx.WindowY1 = 479;
+		hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+	}
+	else
+	{
+		hgfx.WindowY0 = 0;
+		hgfx.WindowY1 = Font->height;
+	}
 	GFX_write_label(Font, &hgfx, text, color);
-	
 }
 
 
@@ -3878,16 +4129,29 @@
 	const tFont *Font = &FontT48;
 	char text[7];
 	uint8_t i, secondDigitPage, secondDigitTotal;
-	
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
 	hgfx.Image = tMscreen;
 	hgfx.WindowNumberOfTextLines = 1;
 	hgfx.WindowLineSpacing = 0;
 	hgfx.WindowTab = 0;
-	hgfx.WindowX1 = 779;
-	hgfx.WindowX0 = hgfx.WindowX1 - (25*5);
-	hgfx.WindowY1 = 479;
-	hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-	
+
+	if(!pSettings->FlipDisplay)
+	{
+		hgfx.WindowX1 = 779;
+		hgfx.WindowX0 = hgfx.WindowX1 - (25*5);
+		hgfx.WindowY1 = 479;
+		hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+	}
+	else
+	{
+		hgfx.WindowX1 = 25*5;
+		hgfx.WindowX0 = 0;
+		hgfx.WindowY1 = Font->height;;
+		hgfx.WindowY0 = 0;
+	}
 	if(page > 99)
 		page = 99;
 	if(total > 99)