Index: /trunk/include/camera.h
===================================================================
--- /trunk/include/camera.h	(revision 1249)
+++ /trunk/include/camera.h	(revision 1250)
@@ -52,6 +52,12 @@
 #define CAM_EMUL_KEYPRESS_DURATION  5           // Length of keypress emulation
 
-#define CAM_MENU_BORDERWIDTH        30          // Related to screen layout somehow.
-                                                // TODO someone explain what this does, probably doesn't really belong here
+#define CAM_MENU_BORDERWIDTH        30          // Defines the width of the border on each side of the CHDK menu. The CHDK menu will have this
+                                                // many pixels left blank to the on each side. Should not be less than 10 to allow room for the
+                                                // scroll bar on the right.
+
+#undef  CAM_DETECT_SCREEN_ERASE                 // Define this to add 'guard' pixel to the screen bitmap to help detect if the firmware has erase the screen
+                                                // If the guard pixel changes the CHDK ALT menu is forced to redraw.
+                                                // Take care not to place CHDK OSD elements over the guard pixel.
+                                                // The guard pixel is the first pixel of the top row in the screen bitmap.
 
 #undef  CAM_AF_SCAN_DURING_VIDEO_RECORD         // CHDK can make single AF scan during video record
Index: /trunk/core/gui.c
===================================================================
--- /trunk/core/gui.c	(revision 1249)
+++ /trunk/core/gui.c	(revision 1250)
@@ -1913,4 +1913,12 @@
     static int show_md_grid=0;
 
+#ifdef CAM_DETECT_SCREEN_ERASE
+    if (!draw_test_guard())
+    {
+        draw_set_guard();
+        gui_menu_force_redraw();
+    }
+#endif
+
 	gui_handle_splash();
 
@@ -2012,4 +2020,5 @@
     gui_in_redraw = 0;
     if ((gui_mode_old != gui_mode && (gui_mode_old != GUI_MODE_NONE && gui_mode_old != GUI_MODE_ALT) && (gui_mode != GUI_MODE_MBOX && gui_mode != GUI_MODE_MPOPUP)) || gui_restore) {
+        if (gui_restore) gui_menu_force_redraw();
         gui_restore = 0;
         if (gui_mode != GUI_MODE_REVERSI && gui_mode != GUI_MODE_SOKOBAN && gui_mode != GUI_MODE_4WINS && gui_mode != GUI_MODE_MASTERMIND)
Index: /trunk/core/gui_draw.c
===================================================================
--- /trunk/core/gui_draw.c	(revision 1249)
+++ /trunk/core/gui_draw.c	(revision 1250)
@@ -60,4 +60,37 @@
    draw_set_aspect_xcorrection_proc(xcorrection_proc);
    draw_set_aspect_ycorrection_proc(ycorrection_proc);
+}
+
+#endif
+
+//-------------------------------------------------------------------
+#ifdef CAM_DETECT_SCREEN_ERASE
+
+#define GUARD_VAL   SCREEN_COLOR
+
+void draw_set_guard()
+{
+    *((unsigned char*)(frame_buffer[0])) = GUARD_VAL;
+    *((unsigned char*)(frame_buffer[1])) = GUARD_VAL;
+}
+
+int draw_test_guard()
+{
+    if (*((unsigned char*)(frame_buffer[0])) != GUARD_VAL) return 0;
+    if (*((unsigned char*)(frame_buffer[1])) != GUARD_VAL) return 0;
+    return 1;
+}
+
+// Test a pixel value in both frame buffers, returns 0 if either doesn't match or co-ords out of range
+int draw_test_pixel(coord x, coord y, color c)
+{
+    if (x >= screen_width || y >= screen_height) return 0;
+#if CAM_USES_ASPECT_CORRECTION
+    return (frame_buffer[0][y * screen_buffer_width + aspect_xcorrection_proc(x)] == c) &&
+           (frame_buffer[1][y * screen_buffer_width + aspect_xcorrection_proc(x)] == c);
+#else
+    return (frame_buffer[0][y * screen_buffer_width + x] == c) &&
+           (frame_buffer[1][y * screen_buffer_width + x] == c);
+#endif
 }
 
@@ -81,4 +114,8 @@
       draw_set_aspect_ycorrection_proc(NULL);
     #endif
+
+#ifdef CAM_DETECT_SCREEN_ERASE
+    draw_set_guard();
+#endif
 }
 
@@ -377,4 +414,8 @@
 void draw_restore() {
     vid_bitmap_refresh();
+
+#ifdef CAM_DETECT_SCREEN_ERASE
+    draw_set_guard();
+#endif
 }
 
Index: /trunk/core/gui_draw.h
===================================================================
--- /trunk/core/gui_draw.h	(revision 1249)
+++ /trunk/core/gui_draw.h	(revision 1250)
@@ -336,6 +336,12 @@
 
 //-------------------------------------------------------------------
-void draw_init();
-void draw_set_draw_proc(void (*pixel_proc)(unsigned int offset, color cl));
+extern void draw_init();
+extern void draw_set_draw_proc(void (*pixel_proc)(unsigned int offset, color cl));
+
+#ifdef CAM_DETECT_SCREEN_ERASE
+extern void draw_set_guard();
+extern int draw_test_guard();
+extern int draw_test_pixel(coord x, coord y, color c);
+#endif
 
 extern color draw_get_pixel(coord x, coord y);
Index: /trunk/core/gui_menu.c
===================================================================
--- /trunk/core/gui_menu.c	(revision 1249)
+++ /trunk/core/gui_menu.c	(revision 1250)
@@ -68,4 +68,13 @@
     
     gui_menu_redraw=2;
+}
+
+//-------------------------------------------------------------------
+void gui_menu_force_redraw()
+{
+    if (gui_get_mode() == GUI_MODE_MENU)
+    {
+        gui_menu_redraw=2;
+    }
 }
 
Index: /trunk/core/gui_menu.h
===================================================================
--- /trunk/core/gui_menu.h	(revision 1249)
+++ /trunk/core/gui_menu.h	(revision 1250)
@@ -50,5 +50,5 @@
 extern void gui_menu_draw();
 extern void mod_user_menu(CMenuItem curr_menu_item, int* gui_menu_add_item, int mod);
-
+extern void gui_menu_force_redraw();
 //-------------------------------------------------------------------
 #endif
