+ if (scroll_size >= 0 && !recursive) {
+ newscr = scrtop + lines * (cols+1);
+
+ if (newscr > sbbot && botline == rows-1) {
+ /* We've hit the bottom of memory, so we have to do a
+ * physical scroll. But instead of just 1 line do it
+ * by 10% of the available memory.
+ *
+ * If the scroll region isn't the whole screen then we can't
+ * do this as it stands. We would need to recover the bottom
+ * of the screen from the scroll buffer after being sure that
+ * it doesn't get deleted.
+ */
+
+ i = (rows+savelines)/10;
+
+ /* Make it simple and ensure safe recursion */
+ if ( i<savelines-1) {
+ recursive ++;
+ scroll(topline, botline, i, sb);
+ recursive --;
+
+ newscr = scrtop - i * (cols+1);
+ if (scrtop_is_disptop) disptop = newscr;
+ scrtop = newscr;
+ }
+
+ newscr = scrtop + lines * (cols+1);
+ }
+
+ if (newscr <= sbbot) {
+ if (scrtop_is_disptop) disptop = newscr;
+ scrtop = newscr;
+
+ if (botline == rows-1 )
+ for (i = 0; i < size; i++)
+ scrtop[i+scroll_size] = erase_char;
+
+ update_sbar();
+ fix_cpos;
+
+ if (botline != rows-1) {
+ /* This fastscroll only works for full window scrolls.
+ * If the caller wanted a partial one we have to reverse
+ * scroll the bottom of the screen.
+ */
+ scroll(botline-lines+1, rows-1, -lines, 0);
+ }
+ return ;
+ }
+
+ /* If we can't scroll by memory remapping do it physically.
+ * But rather than expensivly doing the scroll buffer just
+ * scroll the screen. All it means is that sometimes we choose
+ * to not add lines from a scroll region to the scroll buffer.
+ */
+
+ if (savelines <= 400) {
+ sbtop -= lines * (cols+1);
+ if (sbtop < text)
+ sbtop = text;
+ scroll_size += scroll_top - sbtop;
+ scroll_top = sbtop;
+
+ update_sbar();
+ }
+ } else {
+ /* Ho hum, expensive scroll required. */
+
+ sbtop -= lines * (cols+1);
+ if (sbtop < text)
+ sbtop = text;
+ scroll_size += scroll_top - sbtop;
+ scroll_top = sbtop;
+
+ update_sbar();
+ }