Fix more NXTEXT bugs -- seems to be working now

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3768 42af7a65-404d-4744-a932-0658087f49c3
diff --git a/examples/README.txt b/examples/README.txt
index d3306f3..07d92a7 100644
--- a/examples/README.txt
+++ b/examples/README.txt
@@ -314,10 +314,11 @@
   The text display will continue to update while the pop-up is visible.
 
   NOTE:  This example will *only* work with FB drivers and with LCD
-  drivers that support reading the contents of the internal LCD memory.
-  If you notice garbage on the display or a failure at the point where
-  the display should scroll, it is probably because you have an LCD
-  driver that is write-only.
+  drivers that support reading the contents of the internal LCD memory
+  *unless* you define CONFIG_EXAMPLES_NXTEXT_NOGETRUN.  If you notice
+  garbage on the display or a failure at the point where the display
+  should scroll, it is probably because you have an LCD driver that is
+  write-only.
   
   The following configuration options can be selected:
 
@@ -335,6 +336,9 @@
       background window. Default depends on CONFIG_EXAMPLES_NXTEXT_BPP.
     CONFIG_EXAMPLES_NXTEXT_BPP -- Pixels per pixel to use.  Valid options
       include 2, 4, 8, 16, 24, and 32.  Default is 32.
+    CONFIG_EXAMPLES_NXTEXT_NOGETRUN -- If your display is read-only OR if
+      reading is not reliable, then select this configuration to avoid
+      reading from the display.
     CONFIG_EXAMPLES_NXTEXT_EXTERNINIT - The driver for the graphics device on
       this platform requires some unusual initialization.  This is the
       for, for example, SPI LCD/OLED devices.  If this configuration is
diff --git a/examples/nxtext/nxtext_bkgd.c b/examples/nxtext/nxtext_bkgd.c
index ca8451a..d75dfae 100644
--- a/examples/nxtext/nxtext_bkgd.c
+++ b/examples/nxtext/nxtext_bkgd.c
@@ -197,14 +197,110 @@
 #endif
 
 /****************************************************************************
+ * Name: nxbg_movedisplay
+ *
+ * Description:
+ *   This function implements the data movement for the scroll operation.  If
+ *   we can read the displays framebuffer memory, then the job is pretty
+ *   easy.  However, many displays (such as SPI-based LCDs) are often read-
+ *   only.
+ ****************************************************************************/
+
+#ifdef CONFIG_EXAMPLES_NXTEXT_NOGETRUN
+static inline void nxbg_movedisplay(NXWINDOW hwnd, int bottom, int lineheight)
+{
+  FAR struct nxtext_bitmap_s *bm;
+  struct nxgl_rect_s rect;
+  nxgl_coord_t row;
+  int ret;
+  int i;
+
+  /* Move each row, one at a time.  They could all be moved at once (by calling
+   * nxbg_redrawrect), but the since the region is cleared, then re-written, the
+   * effect would not be good.  Below the region is also cleared and re-written,
+   * however, in much smaller chunks.
+   */
+
+  rect.pt1.x = 0;
+  rect.pt2.x = g_bgstate.wsize.w - 1;
+
+  for (row = LINE_SEPARATION; row < bottom; row += lineheight)
+    {
+      /* Create a bounding box the size of one row of characters */
+
+      rect.pt1.y = row;
+      rect.pt2.y = row + lineheight - 1;
+
+      /* Clear the region */
+
+      ret = nx_fill(hwnd, &rect, g_bgstate.wcolor);
+      if (ret < 0)
+        {
+          message("nxbg_movedisplay: nx_fill failed: %d\n", errno);
+        }
+
+      /* Fill each character that might lie within in the bounding box */
+
+      for (i = 0; i < g_bgstate.nchars; i++)
+        {
+          bm = &g_bgstate.bm[i];
+          if (bm->pos.y <= rect.pt2.y && bm->pos.y + g_bgstate.fheight >= rect.pt1.y)
+            {
+              nxtext_fillchar(hwnd, &rect, &g_bgstate, bm);
+            }
+        }
+    }
+
+  /* Finally, clear the bottom part of the display */
+
+  rect.pt1.y = bottom;
+  rect.pt2.y = g_bgstate.wsize.h- 1;
+
+  ret = nx_fill(hwnd, &rect, g_bgstate.wcolor);
+  if (ret < 0)
+    {
+      message("nxbg_movedisplay: nx_fill failed: %d\n", errno);
+    }
+}
+#else
+static inline void nxbg_movedisplay(NXWINDOW hwnd, int bottom, int lineheight)
+{
+  struct nxgl_rect_s rect;
+  struct nxgl_point_s offset;
+  int ret;
+
+  /* Move the display in the range of 0-height up one lineheight.  The
+   * line at the bottom will be reset to the background color automatically.
+   *
+   * The source rectangle to be moved.
+   */
+
+  rect.pt1.x = 0;
+  rect.pt1.y = lineheight + LINE_SEPARATION;
+  rect.pt2.x = g_bgstate.wsize.w - 1;
+  rect.pt2.y = g_bgstate.wsize.h - 1;
+
+  /* The offset that determines how far to move the source rectangle */
+
+  offset.x   = 0;
+  offset.y   = -lineheight;
+
+  /* Move the source rectangle */
+
+  ret = nx_move(hwnd, &rect, &offset);
+  if (ret < 0)
+    {
+      message("nxbg_redrawrect: nx_move failed: %d\n", errno);
+    }
+}
+#endif
+
+/****************************************************************************
  * Name: nxbg_scroll
  ****************************************************************************/
 
 static inline void nxbg_scroll(NXWINDOW hwnd, int lineheight)
 {
-  struct nxgl_rect_s rect;
-  struct nxgl_point_s offset;
-  int ret;
   int i;
   int j;
 
@@ -216,7 +312,7 @@
 
       /* Has any part of this character scrolled off the screen? */
 
-      if (bm->pos.y < lineheight)
+      if (bm->pos.y < lineheight + LINE_SEPARATION)
         {
           /* Yes... Delete the character by moving all of the data */
 
@@ -250,29 +346,9 @@
 
   g_bgstate.fpos.y -= lineheight;
 
-  /* Move the display in the range of 0-height up one lineheight.  The
-   * line at the bottom will be reset to the background color automatically.
-   *
-   * The source rectangle to be moved.
-   */
+  /* Move the display in the range of 0-height up one lineheight. */
 
-  rect.pt1.x = 0;
-  rect.pt1.y = lineheight;
-  rect.pt2.x = g_bgstate.wsize.w - 1;
-  rect.pt2.y = g_bgstate.wsize.h - 1;
-
-  /* The offset that determines how far to move the source rectangle */
-
-  offset.x   = 0;
-  offset.y   = -lineheight;
-
-  /* Move the source rectangle */
-
-  ret = nx_move(hwnd, &rect, &offset);
-  if (ret < 0)
-    {
-      message("nxbg_redrawrect: nx_move failed: %d\n", errno);
-    }
+  nxbg_movedisplay(hwnd, g_bgstate.fpos.y, lineheight);
 }
 
 /****************************************************************************
diff --git a/examples/nxtext/nxtext_internal.h b/examples/nxtext/nxtext_internal.h
index af0cd03..3bcbb1a 100644
--- a/examples/nxtext/nxtext_internal.h
+++ b/examples/nxtext/nxtext_internal.h
@@ -242,9 +242,9 @@
 
   /* These describe all text already added to the display */
 
-  uint16_t maxchars;                        /* Size of the mb array */
-  uint8_t maxglyphs;                        /* Size of the glyph array */
-  uint8_t nchars;                           /* Number of chars already displayed */
+  uint8_t maxglyphs;                        /* Size of the glyph[] array */
+  uint16_t maxchars;                        /* Size of the bm[] array */
+  uint16_t nchars;                          /* Number of chars in the bm[] array */
 
   FAR struct nxtext_bitmap_s *bm;           /* List of characters on the display */
   FAR struct nxtext_glyph_s  *glyph;        /* Cache of rendered fonts in use */
diff --git a/examples/nxtext/nxtext_main.c b/examples/nxtext/nxtext_main.c
index 9f8f674..a302716 100644
--- a/examples/nxtext/nxtext_main.c
+++ b/examples/nxtext/nxtext_main.c
@@ -99,30 +99,30 @@
 static const uint8_t g_pumsg[] = "Pop-Up!";
 static const char *g_bgmsg[BGMSG_LINES] =
 {
-  "\nJULIET\n",
-  "Wilt thou be gone?\n",
-  "  It is not yet near day:\n",
-  "It was the nightingale,\n",
-  "  and not the lark,\n",
-  "That pierced the fearful hollow\n",
-  "  of thine ear;\n",
-  "Nightly she sings\n",
-  "  on yon pomegranate-tree:\n",
-  "Believe me, love,\n",
-  "  it was the nightingale.\n",
-  "\nROMEO\n",
-  "It was the lark,\n",
-  "  the herald of the morn,\n",
-  "No nightingale:\n",
-  "  look, love, what envious streaks\n",
-  "Do lace the severing clouds\n",
-  "  in yonder east:\n",
-  "Night's candles are burnt out,\n",
-  "  and jocund day\n",
-  "Stands tiptoe\n",
-  "  on the misty mountain tops.\n",
-  "I must be gone and live,\n",
-  "  or stay and die.\n"
+  "\nJULIET\n",                           /* Line 1 */
+  "Wilt thou be gone?\n",                 /* Line 2 */
+  "  It is not yet near day:\n",          /* Line 3 */
+  "It was the nightingale,\n",            /* Line 4 */
+  "  and not the lark,\n",                /* Line 5 */
+  "That pierced the fearful hollow\n",    /* Line 6 */
+  "  of thine ear;\n",                    /* Line 7 */
+  "Nightly she sings\n",                  /* Line 8 */
+  "  on yon pomegranate-tree:\n",         /* Line 9 */
+  "Believe me, love,\n",                  /* Line 10 */
+  "  it was the nightingale.\n",          /* Line 11 */
+  "\nROMEO\n",                            /* Line 12 */
+  "It was the lark,\n",                   /* Line 13 */
+  "  the herald of the morn,\n",          /* Line 14 */
+  "No nightingale:\n",                    /* Line 15 */
+  "  look, love, what envious streaks\n", /* Line 16 */
+  "Do lace the severing clouds\n",        /* Line 17 */
+  "  in yonder east:\n",                  /* Line 18 */
+  "Night's candles are burnt out,\n",     /* Line 19 */
+  "  and jocund day\n",                   /* Line 20 */
+  "Stands tiptoe\n",                      /* Line 21 */
+  "  on the misty mountain tops.\n",      /* Line 22 */
+  "I must be gone and live,\n",           /* Line 23 */
+  "  or stay and die.\n"                  /* Line 24 */
 };
 #endif
 
@@ -440,7 +440,8 @@
         }
 
       /* Give another line of text to the background window.  Force this
-       * text to go the background by calling the kbdin method directly.
+       * text to go the background by calling the background window interfaces
+       * directly.
        */
 
       nxbg_write(g_bgwnd, (FAR const uint8_t *)g_bgmsg[bkgndx], strlen(g_bgmsg[bkgndx]));
diff --git a/examples/nxtext/nxtext_putc.c b/examples/nxtext/nxtext_putc.c
index 81fe3aa..b9c9417 100644
--- a/examples/nxtext/nxtext_putc.c
+++ b/examples/nxtext/nxtext_putc.c
@@ -572,7 +572,7 @@
 
   if (!nxgl_nullrect(&intersection))
     {
-      FAR const void *src = (FAR const void *)glyph->bitmap;
+      FAR const void *src;
 
       /* Find (or create) the glyph that goes with this font */