scrollup(
    long	line_count,
    int		byfold UNUSED)	// TRUE: count a closed fold as one line
{
#if defined(FEAT_FOLDING) || defined(FEAT_DIFF)
    linenr_T	lnum;

    if (
# ifdef FEAT_FOLDING
	    (byfold && hasAnyFolding(curwin))
#  ifdef FEAT_DIFF
	    ||
#  endif
# endif
# ifdef FEAT_DIFF
	    curwin->w_p_diff
# endif
	    )
    {
	// count each sequence of folded lines as one logical line
	lnum = curwin->w_topline;
	while (line_count--)
	{
# ifdef FEAT_DIFF
	    if (curwin->w_topfill > 0)
		--curwin->w_topfill;
	    else
# endif
	    {
# ifdef FEAT_FOLDING
		if (byfold)
		    (void)hasFolding(lnum, NULL, &lnum);
# endif
		if (lnum >= curbuf->b_ml.ml_line_count)
		    break;
		++lnum;
# ifdef FEAT_DIFF
		curwin->w_topfill = diff_check_fill(curwin, lnum);
# endif
	    }
	}
	// approximate w_botline
	curwin->w_botline += lnum - curwin->w_topline;
	curwin->w_topline = lnum;
    }
    else
#endif
    {
	curwin->w_topline += line_count;
	curwin->w_botline += line_count;	// approximate w_botline
    }

    if (curwin->w_topline > curbuf->b_ml.ml_line_count)
	curwin->w_topline = curbuf->b_ml.ml_line_count;
    if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1)
	curwin->w_botline = curbuf->b_ml.ml_line_count + 1;

#ifdef FEAT_DIFF
    check_topfill(curwin, FALSE);
#endif

#ifdef FEAT_FOLDING
    if (hasAnyFolding(curwin))
	// Make sure w_topline is at the first of a sequence of folded lines.
	(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
#endif

    curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
    if (curwin->w_cursor.lnum < curwin->w_topline)
    {
	curwin->w_cursor.lnum = curwin->w_topline;
	curwin->w_valid &=
	      ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
	coladvance(curwin->w_curswant);
    }
}
scrollup(
    long	line_count,
    int		byfold UNUSED)	 
{
#if defined(FEAT_FOLDING) || defined(FEAT_DIFF)
    linenr_T	lnum;

    if (
# ifdef FEAT_FOLDING
	    (byfold && hasAnyFolding(curwin))
#  ifdef FEAT_DIFF
	    ||
#  endif
# endif
# ifdef FEAT_DIFF
	    curwin->w_p_diff
# endif
	    )
    {
	 
	lnum = curwin->w_topline;
	while (line_count--)
	{
# ifdef FEAT_DIFF
	    if (curwin->w_topfill > 0)
		--curwin->w_topfill;
	    else
# endif
	    {
# ifdef FEAT_FOLDING
		if (byfold)
		    (void)hasFolding(lnum, NULL, &lnum);
# endif
		if (lnum >= curbuf->b_ml.ml_line_count)
		    break;
		++lnum;
# ifdef FEAT_DIFF
		curwin->w_topfill = diff_check_fill(curwin, lnum);
# endif
	    }
	}
	 
	curwin->w_botline += lnum - curwin->w_topline;
	curwin->w_topline = lnum;
    }
    else
#endif
    {
	curwin->w_topline += line_count;
	curwin->w_botline += line_count;	 
    }

    if (curwin->w_topline > curbuf->b_ml.ml_line_count)
	curwin->w_topline = curbuf->b_ml.ml_line_count;
    if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1)
	curwin->w_botline = curbuf->b_ml.ml_line_count + 1;

#ifdef FEAT_DIFF
    check_topfill(curwin, FALSE);
#endif

#ifdef FEAT_FOLDING
    if (hasAnyFolding(curwin))
	 
	(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
#endif

    curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
    if (curwin->w_cursor.lnum < curwin->w_topline)
    {
	curwin->w_cursor.lnum = curwin->w_topline;
	curwin->w_valid &=
	      ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
	coladvance(curwin->w_curswant);
    }
}