#include "ded.h" #include "char.h" #include "ter.h" /************************************************************************ * * * copyright Richard Bornat 1981 * * * ************************************************************************/ /************************************************************************ * * * procedures to redisplay the screen * * * ************************************************************************/ extern getline(), getfline(); scrdown(n, saveit) register int n, saveit; { if (n<0 || n>NINROWS) editerror("too far to scroll down (%d)",n); else if (topl<=0) { topl=0; complain(); return; } else if (n>topl) n=topl; reshow_screen(topl-n, getline, saveit); } scrup(n, saveit) register int n, saveit; { if (n<0 || n>NINROWS) editerror("too far to scroll up (%d)",n); else if (topl+LASTINROW >=maxl) { complain(); return; } reshow_screen(topl+n, getline, saveit); } set_topl(n, saveit) int n; { reshow_screen(n, (saveit ? getline : getfline), saveit); } onscreen(fline) register int fline; { return (topl<=fline && fline <= topl+LASTINROW); } /************************************************************************ * * * A procedure to redisplay a screenful of text with minimum effort. * * * * Careful when calling this function - you should only call it with * * a mapfn argument which is getline or getfline or which doesn't refer * * to rowmap - this permits a clearscreen in the final 'else' below. * * * ************************************************************************/ reshow_screen(sline, mapfn, saveit) register int sline; int (*mapfn)(); int saveit; { char linebuf[ENOUGH]; int first, last; register int i; first=0; last=LASTINROW; if (saveit) saveedit(); if (sline<0) sline=0; else if (sline+LASTINROW > maxl) sline = maxl-LASTINROW; /* make the cursor keep position */ if (mode==INMODE) adj_virt_c(topl-sline, 0); if (onscreen(sline)) /* roll up */ while (toplsline) { if (saveit) saverow(LASTINROW); (*mapfn)(topl-1, linebuf); scrolldown(0, LASTINROW, linebuf); dec_topl(); first++; } else /* do it by rewriting the whole screen */ { if (saveit) savescreen(); clearscreen(); topl=sline; if (mapfn==getline) mapfn = getfline; } /* now redraw the extra bits */ for (i=first; i<=last; i++) { (*mapfn)(sline+i, linebuf); redraw(i, 0, linebuf); } showedit(); /* ttyflush(); */ } up_one(str, saveit) register char *str; register int saveit; { /* a fast way of rolling up the lines except the edit line */ if (saveit) saverow(0); if (HARDSCROLL) scrollup(0, LASTINROW, str); else { rollup(); redraw(LASTINROW, 0, str); } inc_topl(); } /************************************************************************ * * * procedures to scroll up * * and down sections of the * * screen. ded tries to use * * the hardware functions * * of the terminal as thoroughly * * as possible. * * * ************************************************************************/ rollup() { /* everybody must have this operation */ sendat(FOOTROW, real_c.col, ter.scrseq.rollup); shufmap(0, FOOTROW, -1); } /************************************************************************ * * * Scrolling routines to scroll with minimum effort. The two scrolling * * procedures are mutually recursive, so scrollup uses all the 'up' * * primitives, scrolldown uses the 'down' primitives. * * * * Each scrolling procedure calculates the cheapest strategy for * * scrolling (a guess at best): if the 'line' parameter is zero then * * it merely returns this cost as its result, otherwise it goes ahead * * and follows the strategy. * * * ************************************************************************/ min(a,b) register int a,b; { return(ar2) return(0); else /* calculate some cost */ { /* default strategy - rewrite every line (r1:r2) */ if (mca = charsin(r1, r2)) mcb = (*ter.scrollup)(r1, r2, (char *)0); } if (line!=0) { if (mcar2) return(0); else /* calculate scrolldown cost */ { if (mca = charsin(r1, r2)) mcb = (*ter.scrolldown)(r1,r2,(char *)0); } /* do it unless just browsing */ if (line!=0) { if (mcar1) { redraw(r2, 0, rowmap[r2-1]); r2--; } redraw(r1, 0, line); } else (*ter.scrolldown)(r1, r2, line); } return(min(mca,mcb)); }