Fixed screen flipping for devices where xres_virtual > xres

Change-Id: I3efc10e2c9759a358ded5b46f6125958e6d6bd66
diff --git a/minuitwrp/graphics.c b/minuitwrp/graphics.c
index 512a957..93123e4 100644
--- a/minuitwrp/graphics.c
+++ b/minuitwrp/graphics.c
@@ -351,20 +351,18 @@
         /* flip buffer 180 degrees for devices with physicaly inverted screens */
         unsigned int i;
         unsigned int j;
-        uint8_t tmp;
-        for (i = 0; i < ((vi.xres_virtual * vi.yres)/2); i++) {
-            for (j = 0; j < PIXEL_SIZE; j++) {
-                tmp = gr_mem_surface.data[i * PIXEL_SIZE + j];
-                gr_mem_surface.data[i * PIXEL_SIZE + j] = gr_mem_surface.data[(vi.xres_virtual * vi.yres * PIXEL_SIZE) - ((i+1) * PIXEL_SIZE) + j];
-                gr_mem_surface.data[(vi.xres_virtual * vi.yres * PIXEL_SIZE) - ((i+1) * PIXEL_SIZE) + j] = tmp;
+        for (i = 0; i < vi.yres; i++) {
+            for (j = 0; j < vi.xres; j++) {
+                memcpy(gr_framebuffer[gr_active_fb].data + (i * vi.xres_virtual + j) * PIXEL_SIZE,
+                       gr_mem_surface.data + ((vi.yres - i - 1) * vi.xres_virtual + vi.xres - j - 1) * PIXEL_SIZE, PIXEL_SIZE);
             }
         }
-#endif
-
+#else
         /* copy data from the in-memory surface to the buffer we're about
          * to make active. */
         memcpy(gr_framebuffer[gr_active_fb].data, gr_mem_surface.data,
                vi.xres_virtual * vi.yres * PIXEL_SIZE);
+#endif
 
         /* inform the display driver */
         set_active_framebuffer(gr_active_fb);