boesch@Shasta.STANFORD.EDU (Brian Boesch) (08/19/86)
-------------- This shar file contains updated versions of: estruct.h ibmpc.c display.c These files improve MicroEmacs' performance on slow IBM displays such as the CGA. In addition it includes switches for IBM Mono adapter. The file estruct.h is currently set up for IBM color adapter and for a 4Mhz machine. If your machine is faster than 4Mhz you may wish to change IBM_RETRACEC to 3 or maybe 4. This is the number of lines updated onscreen per vertical retrace. Thus setting of 2 will double performance of origional MicroEmacs and so on. Note: Do not set IBM_RETRACEC to 0 this will inhibit all screen updates if IBMPC is selected. Either IBM_CGA or IBM_MDA must be set to 1 if IBMPC is selected. These changes have only been tried under MSC. --------- cut here -------- #! /bin/sh : This is a shar archive. Extract with sh, not csh. echo x - estruct.h cat > estruct.h << '1089!Funky!Stuff!' /* ESTRUCT: Structure and preprocesser defined for MicroEMACS 3.7 written by Dave G. Conroy modified by Steve Wilhite, George Jones greatly modified by Daniel Lawrence */ #undef LATTICE /* don't use their definitions...use ours */ #undef MSDOS #undef CPM #undef AMIGA /* Machine/OS definitions */ #define AMIGA 0 /* AmigaDOS */ #define ST520 0 /* ST520, TOS */ #define MSDOS 1 /* MS-DOS */ #define V7 0 /* V7 UN*X or Coherent or BSD4.2*/ #define BSD 0 /* UNIX BSD 4.2 and ULTRIX */ #define USG 0 /* UNIX system V */ #define VMS 0 /* VAX/VMS */ #define CPM 0 /* CP/M-86 */ /* Compiler definitions */ #define MWC86 0 /* marc williams compiler */ #define LATTICE 0 /* either lattice compiler */ #define LAT2 0 /* Lattice 2.15 */ #define LAT3 0 /* Lattice 3.0 */ #define AZTEC 0 /* Aztec C 3.20e */ #define MSC 1 /* MicroSoft C compile version 3 */ /* Profiling options */ #define APROF 0 /* turn Aztec C profiling on? */ #define NBUCK 100 /* number of buckets to profile */ /* Special keyboard definitions */ #define WANGPC 0 /* WangPC - mostly escape sequences */ /* Terminal Output definitions */ #define ANSI 0 /* ansi escape sequences */ #define HP150 0 /* HP150 screen driver */ #define VMSVT 0 /* various VMS terminal entries */ #define VT52 0 /* VT52 terminal (Zenith). */ #define VT100 0 /* Handle VT100 style keypad. */ #define LK201 0 /* Handle LK201 style keypad. */ #define RAINBOW 0 /* Use Rainbow fast video. */ #define TERMCAP 0 /* Use TERMCAP */ #define DG10 0 /* Data General system/10 */ #define IBMPC 1 /* IBM-PC specific driver */ /* if IBMPC then the following switches must be set */ #define IBM_MDA 0 /* IBM Monochrome adapter */ #define IBM_CGA 1 /* IBM Color adapter */ #define IBM_WAITRETRACE 1 /* Update display only on retrace */ /* If IBM_WAITRETRACE is set, Set IBM_RETRACEC to the largest value */ /* that doesn't cause snow on the screen. 4Mhz ibmpc -> 2, 8Mhz -> 3 */ /* AT probably larger but I haven't tested it */ #define IBM_RETRACEC 2 /* Number of lines to update per */ /* retrace. */ /* Configuration options */ #define CVMVAS 1 /* arguments to page forward/back in pages */ #define NFWORD 1 /* forward word jumps to begining of word */ #define CLRMSG 0 /* space clears the message line with no insert */ #define TYPEAH 1 /* type ahead causes update to be skipped */ #define FILOCK 0 /* file locking under unix BSD 4.2 */ #define REVSTA 1 /* Status line appears in reverse video */ #define COLOR 1 /* color commands and windows */ #define ACMODE 1 /* auto CMODE on .C and .H files */ #define CFENCE 1 /* fench matching in CMODE */ #define ISRCH 1 /* Incremental searches like ITS EMACS */ #define WORDPRO 1 /* Advanced word processing features */ #define BACKUP 1 /* Backup last copy of file to filename~ */ /* System dependant library redefinitions, structures and includes */ #if MSDOS & AZTEC #undef fputc #undef fgetc #define fputc aputc #define fgetc agetc #define int86 sysint #define inp inportb struct XREG { int ax,bx,cx,dx,si,di; }; struct HREG { char al,ah,bl,bh,cl,ch,dl,dh; }; union REGS { struct XREG x; struct HREG h; }; #endif #if MSDOS & LATTICE #undef CPM #undef LATTICE #include <dos.h> #undef CPM #endif #if MSDOS & MSC #include <dos.h> #endif /* internal constants */ #define NBINDS 200 /* max # of bound keys */ #define NFILEN 80 /* # of bytes, file name */ #define NBUFN 16 /* # of bytes, buffer name */ #define NLINE 256 /* # of bytes, line */ #define NSTRING 256 /* # of bytes, string buffers */ #define NKBDM 256 /* # of strokes, keyboard macro */ #define NPAT 80 /* # of bytes, pattern */ #define HUGE 1000 /* Huge number */ #define NLOCKS 100 /* max # of file locks active */ #define NCOLORS 8 /* number of supported colors */ #define KBLOCK 250 /* sizeof kill buffer chunks */ #define NBLOCK 16 /* line block chunk size */ #define AGRAVE 0x60 /* M- prefix, Grave (LK201) */ #define METACH 0x1B /* M- prefix, Control-[, ESC */ #define CTMECH 0x1C /* C-M- prefix, Control-\ */ #define EXITCH 0x1D /* Exit level, Control-] */ #define CTRLCH 0x1E /* C- prefix, Control-^ */ #define HELPCH 0x1F /* Help key, Control-_ */ #define CTRL 0x0100 /* Control flag, or'ed in */ #define META 0x0200 /* Meta flag, or'ed in */ #define CTLX 0x0400 /* ^X flag, or'ed in */ #define SPEC 0x0800 /* special key (function keys) */ #define FALSE 0 /* False, no, bad, etc. */ #define TRUE 1 /* True, yes, good, etc. */ #define ABORT 2 /* Death, ^G, abort, etc. */ #define FIOSUC 0 /* File I/O, success. */ #define FIOFNF 1 /* File I/O, file not found. */ #define FIOEOF 2 /* File I/O, end of file. */ #define FIOERR 3 /* File I/O, error. */ #define FIOLNG 4 /*line longer than allowed len */ #define CFCPCN 0x0001 /* Last command was C-P, C-N */ #define CFKILL 0x0002 /* Last command was a kill */ #define BELL 0x07 /* a bell character */ #define TAB 0x09 /* a tab character */ /* * There is a window structure allocated for every active display window. The * windows are kept in a big list, in top to bottom screen order, with the * listhead at "wheadp". Each window contains its own values of dot and mark. * The flag field contains some bits that are set by commands to guide * redisplay; although this is a bit of a compromise in terms of decoupling, * the full blown redisplay is just too expensive to run for every input * character. */ typedef struct WINDOW { struct WINDOW *w_wndp; /* Next window */ struct BUFFER *w_bufp; /* Buffer displayed in window */ struct LINE *w_linep; /* Top line in the window */ struct LINE *w_dotp; /* Line containing "." */ short w_doto; /* Byte offset for "." */ struct LINE *w_markp; /* Line containing "mark" */ short w_marko; /* Byte offset for "mark" */ char w_toprow; /* Origin 0 top row of window */ char w_ntrows; /* # of rows of text in window */ char w_force; /* If NZ, forcing row. */ char w_flag; /* Flags. */ #if COLOR char w_fcolor; /* current forground color */ char w_bcolor; /* current background color */ #endif } WINDOW; #define WFFORCE 0x01 /* Window needs forced reframe */ #define WFMOVE 0x02 /* Movement from line to line */ #define WFEDIT 0x04 /* Editing within a line */ #define WFHARD 0x08 /* Better to a full display */ #define WFMODE 0x10 /* Update mode line. */ #define WFCOLR 0x20 /* Needs a color change */ /* * Text is kept in buffers. A buffer header, described below, exists for every * buffer in the system. The buffers are kept in a big list, so that commands * that search for a buffer by name can find the buffer header. There is a * safe store for the dot and mark in the header, but this is only valid if * the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for * the buffer is kept in a circularly linked list of lines, with a pointer to * the header line in "b_linep". * Buffers may be "Inactive" which means the files accosiated with them * have not been read in yet. These get read in at "use buffer" time. */ typedef struct BUFFER { struct BUFFER *b_bufp; /* Link to next BUFFER */ struct LINE *b_dotp; /* Link to "." LINE structure */ short b_doto; /* Offset of "." in above LINE */ struct LINE *b_markp; /* The same as the above two, */ short b_marko; /* but for the "mark" */ struct LINE *b_linep; /* Link to the header LINE */ char b_active; /* window activated flag */ char b_nwnd; /* Count of windows on buffer */ char b_flag; /* Flags */ char b_mode; /* editor mode of this buffer */ char b_fname[NFILEN]; /* File name */ char b_bname[NBUFN]; /* Buffer name */ } BUFFER; #define BFINVS 0x01 /* Internal invisable buffer */ #define BFCHG 0x02 /* Changed since last write */ /* mode flags */ #define NUMMODES 7 /* # of defined modes */ #define MDWRAP 0x0001 /* word wrap */ #define MDCMOD 0x0002 /* C indentation and fence match*/ #define MDSPELL 0x0004 /* spell error parcing */ #define MDEXACT 0x0008 /* Exact matching for searches */ #define MDVIEW 0x0010 /* read-only buffer */ #define MDOVER 0x0020 /* overwrite mode */ #define MDMAGIC 0x0040 /* regular expresions in search */ /* * The starting position of a region, and the size of the region in * characters, is kept in a region structure. Used by the region commands. */ typedef struct { struct LINE *r_linep; /* Origin LINE address. */ short r_offset; /* Origin LINE offset. */ long r_size; /* Length in characters. */ } REGION; /* * All text is kept in circularly linked lists of "LINE" structures. These * begin at the header line (which is the blank line beyond the end of the * buffer). This line is pointed to by the "BUFFER". Each line contains a the * number of bytes in the line (the "used" size), the size of the text array, * and the text. The end of line is not stored as a byte; it's implied. Future * additions will include update hints, and a list of marks into the line. */ typedef struct LINE { struct LINE *l_fp; /* Link to the next line */ struct LINE *l_bp; /* Link to the previous line */ short l_size; /* Allocated size */ short l_used; /* Used size */ char l_text[1]; /* A bunch of characters. */ } LINE; #define lforw(lp) ((lp)->l_fp) #define lback(lp) ((lp)->l_bp) #define lgetc(lp, n) ((lp)->l_text[(n)]&0xFF) #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c)) #define llength(lp) ((lp)->l_used) /* * The editor communicates with the display using a high level interface. A * "TERM" structure holds useful variables, and indirect pointers to routines * that do useful operations. The low level get and put routines are here too. * This lets a terminal, in addition to having non standard commands, have * funny get and put character code too. The calls might get changed to * "termp->t_field" style in the future, to make it possible to run more than * one terminal type. */ typedef struct { short t_nrow; /* Number of rows. */ short t_ncol; /* Number of columns. */ short t_margin; /* min margin for extended lines*/ short t_scrsiz; /* size of scroll region " */ int t_pause; /* # times thru update to pause */ int (*t_open)(); /* Open terminal at the start. */ int (*t_close)(); /* Close terminal at end. */ int (*t_getchar)(); /* Get character from keyboard. */ int (*t_putchar)(); /* Put character to display. */ int (*t_flush)(); /* Flush output buffers. */ int (*t_move)(); /* Move the cursor, origin 0. */ int (*t_eeol)(); /* Erase to end of line. */ int (*t_eeop)(); /* Erase to end of page. */ int (*t_beep)(); /* Beep. */ int (*t_rev)(); /* set reverse video state */ #if COLOR int (*t_setfor)(); /* set forground color */ int (*t_setback)(); /* set background color */ #endif } TERM; /* structure for the table of initial key bindings */ typedef struct { short k_code; /* Key code */ int (*k_fp)(); /* Routine to handle it */ } KEYTAB; /* structure for the name binding table */ typedef struct { char *n_name; /* name of function key */ int (*n_func)(); /* function name is bound to */ } NBIND; /* The editor holds deleted text chunks in the KILL buffer. The kill buffer is logically a stream of ascii characters, however due to its unpredicatable size, it gets implemented as a linked list of chunks. (The d_ prefix is for "deleted" text, as k_ was taken up by the keycode structure */ typedef struct KILL { struct KILL *d_next; /* link to next chunk, NULL if last */ char d_chunk[KBLOCK]; /* deleted text */ } KILL; 1089!Funky!Stuff! echo x - ibmpc.c cat > ibmpc.c << '1089!Funky!Stuff!' /* * The routines in this file provide support for the IBM-PC and other * compatible terminals. It goes directly to the graphics RAM to do * screen output. It compiles into nothing if not an IBM-PC driver */ #define termdef 1 /* don't define "term" external */ #include <stdio.h> #include "estruct.h" #include "edef.h" #if IBMPC #include <memory.h> #define NROW 25 /* Screen size. */ #define NCOL 80 /* Edit if you want to. */ #define MARGIN 8 /* size of minimim margin and */ #define SCRSIZ 64 /* scroll size for extended lines */ #define NPAUSE 200 /* # times thru update to pause */ #define BEL 0x07 /* BEL character. */ #define ESC 0x1B /* ESC character. */ #define SPACE 32 /* space character */ #if IBM_CGA #define SCADD 0xb8000000L /* address of screen RAM */ #endif #if IBM_MDA #define SCADD 0xb0000000L /* address of screen RAM */ #endif int *scptr[NROW]; /* pointer to screen lines */ #define IBM_RETRACEC 3 int *sline_scptr[IBM_RETRACEC]; /* screen row to update */ int *slinep[IBM_RETRACEC]; /* pointer to line buffer */ int sline[IBM_RETRACEC][NCOL]; int slinebusy; /* -1 sline empty, */ extern int ttopen(); /* Forward references. */ extern int ttgetc(); extern int ttputc(); extern int ttflush(); extern int ttclose(); extern int ibmmove(); extern int ibmeeol(); extern int ibmeeop(); extern int ibmbeep(); extern int ibmopen(); extern int ibmrev(); extern int ibmclose(); extern int ibmputc(); #if COLOR extern int ibmfcol(); extern int ibmbcol(); int cfcolor = -1; /* current forground color */ int cbcolor = -1; /* current background color */ int ctrans[] = /* ansi to ibm color translation table */ {0, 4, 2, 6, 1, 5, 3, 7}; #endif /* * Standard terminal interface dispatch table. Most of the fields point into * "termio" code. */ TERM term = { NROW-1, NCOL, MARGIN, SCRSIZ, NPAUSE, ibmopen, ibmclose, ttgetc, ibmputc, ttflush, ibmmove, ibmeeol, ibmeeop, ibmbeep, ibmrev #if COLOR , ibmfcol, ibmbcol #endif }; extern union REGS rg; #if COLOR ibmfcol(color) /* set the current output color */ int color; /* color to set */ { cfcolor = ctrans[color]; } ibmbcol(color) /* set the current background color */ int color; /* color to set */ { cbcolor = ctrans[color]; } #endif ibmmove(row, col) { rg.h.ah = 2; /* set cursor position function code */ rg.h.dl = col; rg.h.dh = row; rg.h.bh = 0; /* set screen page number */ int86(0x10, &rg, &rg); } ibmeeol() /* erase to the end of the line */ { int attr; /* attribute byte mask to place in RAM */ int *lnptr; /* pointer to the destination line */ int i; int ccol; /* current column cursor lives */ int crow; /* row */ /* find the current cursor position */ rg.h.ah = 3; /* read cursor position function code */ rg.h.bh = 0; /* current video page */ int86(0x10, &rg, &rg); ccol = rg.h.dl; /* record current column */ crow = rg.h.dh; /* and row */ /* build the attribute byte and setup the screen pointer */ #if COLOR attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8; #else attr = 0x0700; #endif scwriteu(); lnptr = slinep[0]; for (i=0; i < NCOL; i++) *lnptr++ = SPACE | attr; #if IBM_WAITRETRACE /* wait for vertical retrace to be off */ while ((inp(0x3da) & 8)) ; /* and to be back on */ while ((inp(0x3da) & 8) == 0) ; #endif /* and send the string out */ memcpy(scptr[crow]+ccol, slinep[0], (NCOL-ccol)*2); } ibmputc(ch) /* put a character at the current position in the current colors */ int ch; { rg.h.ah = 14; /* write char to screen with current attrs */ rg.h.al = ch; #if COLOR rg.h.bl = cfcolor; #else rg.h.bl = 0x07; #endif int86(0x10, &rg, &rg); } ibmeeop() { int attr; /* attribute to fill screen with */ rg.h.ah = 6; /* scroll page up function code */ rg.h.al = 0; /* # lines to scroll (clear it) */ rg.x.cx = 0; /* upper left corner of scroll */ rg.x.dx = 0x174f; /* lower right corner of scroll */ #if COLOR attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15); #else attr = 0; #endif rg.h.bh = attr; int86(0x10, &rg, &rg); } ibmrev(state) /* change reverse video state */ int state; /* TRUE = reverse, FALSE = normal */ { /* This never gets used under the IBM-PC driver */ } ibmbeep() { bdos(6, BEL, 0); } ibmopen() { scinit(); revexist = TRUE; ttopen(); } ibmclose() { #if COLOR ibmfcol(7); ibmbcol(0); #endif ttclose(); } scinit() /* initialize the screen head pointers */ { union { long laddr; /* long form of address */ int *paddr; /* pointer form of address */ } addr; int i; /* initialize the screen pointer array */ for (i = 0; i < NROW; i++) { addr.laddr = SCADD + (long)(NCOL * i * 2); scptr[i] = addr.paddr; } for (i=0; i<IBM_RETRACEC; i++) { slinep[i] = &sline[i][0]; } slinebusy = 0; } scwrite(row, outstr, forg, bacg) /* write a line out*/ int row; /* row of screen to place outstr on */ char *outstr; /* string to write out (must be NCOL long) */ int forg; /* forground color of string to write */ int bacg; /* background color */ { int attr; /* attribute byte mask to place in RAM */ int *lnptr; /* pointer to the destination line */ int i; /* build the attribute byte and setup the screen pointer */ #if COLOR attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8; #else attr = (((bacg & 15) << 4) | (forg & 15)) << 8; #endif sline_scptr[slinebusy] = scptr[row]; lnptr = slinep[slinebusy]; slinebusy++; for (i=0; i<NCOL; i++) *lnptr++ = (outstr[i] & 255) | attr; if (slinebusy >= IBM_RETRACEC) scwriteu(); } scwriteu() { int i, charperline; if (slinebusy == 0) return; charperline = NCOL*2; #if IBM_WAITRETRACE /* wait for vertical retrace to be off */ while ((inp(0x3da) & 8)) ; /* and to be back on */ while ((inp(0x3da) & 8) == 0) ; #endif /* and send the string out */ for (i=0; i<slinebusy;i++) { memcpy(sline_scptr[i], slinep[i], charperline); } slinebusy = 0; } #else ibmhello() { } #endif 1089!Funky!Stuff! echo x - display.c cat > display.c << '1089!Funky!Stuff!' /* * The functions in this file handle redisplay. There are two halves, the * ones that update the virtual display screen, and the ones that make the * physical display screen the same as the virtual display screen. These * functions use hints that are left in the windows by the commands. * */ #include <stdio.h> #include "estruct.h" #include "edef.h" #define WFDEBUG 0 /* Window flag debug. */ typedef struct VIDEO { int v_flag; /* Flags */ #if COLOR int v_fcolor; /* current forground color */ int v_bcolor; /* current background color */ int v_rfcolor; /* requested forground color */ int v_rbcolor; /* requested background color */ #endif char v_text[1]; /* Screen data. */ } VIDEO; #define VFCHG 0x0001 /* Changed flag */ #define VFEXT 0x0002 /* extended (beyond column 80) */ #define VFREV 0x0004 /* reverse video status */ #define VFREQ 0x0008 /* reverse video request */ #define VFCOL 0x0010 /* color change requested */ VIDEO **vscreen; /* Virtual screen. */ #if IBMPC == 0 VIDEO **pscreen; /* Physical screen. */ #endif /* * Initialize the data structures used by the display code. The edge vectors * used to access the screens are set up. The operating system's terminal I/O * channel is set up. All the other things get initialized at compile time. * The original window has "WFCHG" set, so that it will get completely * redrawn on the first call to "update". */ vtinit() { register int i; register VIDEO *vp; char *malloc(); (*term.t_open)(); (*term.t_rev)(FALSE); vscreen = (VIDEO **) malloc(term.t_nrow*sizeof(VIDEO *)); if (vscreen == NULL) exit(1); #if IBMPC == 0 pscreen = (VIDEO **) malloc(term.t_nrow*sizeof(VIDEO *)); if (pscreen == NULL) exit(1); #endif for (i = 0; i < term.t_nrow; ++i) { vp = (VIDEO *) malloc(sizeof(VIDEO)+term.t_ncol); if (vp == NULL) exit(1); vp->v_flag = 0; #if COLOR vp->v_rfcolor = 7; vp->v_rbcolor = 0; #endif vscreen[i] = vp; #if IBMPC == 0 vp = (VIDEO *) malloc(sizeof(VIDEO)+term.t_ncol); if (vp == NULL) exit(1); vp->v_flag = 0; pscreen[i] = vp; #endif } } /* * Clean up the virtual terminal system, in anticipation for a return to the * operating system. Move down to the last line and clear it out (the next * system prompt will be written in the line). Shut down the channel to the * terminal. */ vttidy() { mlerase(); movecursor(term.t_nrow, 0); (*term.t_flush)(); (*term.t_close)(); } /* * Set the virtual cursor to the specified row and column on the virtual * screen. There is no checking for nonsense values; this might be a good * idea during the early stages. */ vtmove(row, col) { vtrow = row; vtcol = col; } /* * Write a character to the virtual screen. The virtual row and column are * updated. If the line is too long put a "$" in the last column. This routine * only puts printing characters into the virtual terminal buffers. Only * column overflow is checked. */ vtputc(c) int c; { register VIDEO *vp; vp = vscreen[vtrow]; if (vtcol >= term.t_ncol) { vtcol = (vtcol + 0x07) & ~0x07; vp->v_text[term.t_ncol - 1] = '$'; } else if (c == '\t') { do { vtputc(' '); } while ((vtcol&0x07) != 0); } else if (c < 0x20 || c == 0x7F) { vtputc('^'); vtputc(c ^ 0x40); } else vp->v_text[vtcol++] = c; } /* put a character to the virtual screen in an extended line. If we are not yet on left edge, don't print it yet. check for overflow on the right margin */ vtpute(c) int c; { register VIDEO *vp; vp = vscreen[vtrow]; if (vtcol >= term.t_ncol) { vtcol = (vtcol + 0x07) & ~0x07; vp->v_text[term.t_ncol - 1] = '$'; } else if (c == '\t') { do { vtpute(' '); } while (((vtcol + lbound)&0x07) != 0); } else if (c < 0x20 || c == 0x7F) { vtpute('^'); vtpute(c ^ 0x40); } else { if (vtcol >= 0) vp->v_text[vtcol] = c; ++vtcol; } } /* * Erase from the end of the software cursor to the end of the line on which * the software cursor is located. */ vteeol() { register VIDEO *vp; vp = vscreen[vtrow]; while (vtcol < term.t_ncol) vp->v_text[vtcol++] = ' '; } /* upscreen: user routine to force a screen update always finishes complete update */ upscreen(f, n) { update(TRUE); return(TRUE); } /* * Make sure that the display is right. This is a three part process. First, * scan through all of the windows looking for dirty ones. Check the framing, * and refresh the screen. Second, make sure that "currow" and "curcol" are * correct for the current window. Third, make the virtual and physical * screens the same. */ update(force) int force; /* force update past type ahead? */ { register WINDOW *wp; #if TYPEAH if (force == FALSE && typahead()) return(TRUE); #endif /* update any windows that need refreshing */ wp = wheadp; while (wp != NULL) { if (wp->w_flag) { /* if the window has changed, service it */ reframe(wp); /* check the framing */ if ((wp->w_flag & ~WFMODE) == WFEDIT) updone(wp); /* update EDITed line */ else if (wp->w_flag & ~WFMOVE) updall(wp); /* update all lines */ #if ~WFDEBUG if (wp->w_flag & WFMODE) modeline(wp); /* update modeline */ #endif wp->w_flag = 0; wp->w_force = 0; } #if WFDEBUG modeline(); #endif /* on to the next window */ wp = wp->w_wndp; } /* recalc the current hardware cursor location */ updpos(); #if IBMPC /* update the cursor and flush the buffers */ movecursor(currow, curcol - lbound); #endif /* check for lines to de-extend */ upddex(); /* if screen is garbage, re-plot it */ if (sgarbf != FALSE) updgar(); /* update the virtual screen to the physical screen */ updupd(force); /* update the cursor and flush the buffers */ movecursor(currow, curcol - lbound); (*term.t_flush)(); return(TRUE); } /* reframe: check to see if the cursor is on in the window and re-frame it if needed or wanted */ reframe(wp) WINDOW *wp; { register LINE *lp; register int i; /* if not a requested reframe, check for a needed one */ if ((wp->w_flag & WFFORCE) == 0) { lp = wp->w_linep; for (i = 0; i < wp->w_ntrows; i++) { /* if the line is in the window, no reframe */ if (lp == wp->w_dotp) return(TRUE); /* if we are at the end of the file, reframe */ if (lp == wp->w_bufp->b_linep) break; /* on to the next line */ lp = lforw(lp); } } /* reaching here, we need a window refresh */ i = wp->w_force; /* how far back to reframe? */ if (i > 0) { /* only one screen worth of lines max */ if (--i >= wp->w_ntrows) i = wp->w_ntrows - 1; } else if (i < 0) { /* negative update???? */ i += wp->w_ntrows; if (i < 0) i = 0; } else i = wp->w_ntrows / 2; /* backup to new line at top of window */ lp = wp->w_dotp; while (i != 0 && lback(lp) != wp->w_bufp->b_linep) { --i; lp = lback(lp); } /* and reset the current line at top of window */ wp->w_linep = lp; wp->w_flag |= WFHARD; wp->w_flag &= ~WFFORCE; return(TRUE); } /* updone: update the current line to the virtual screen */ updone(wp) WINDOW *wp; /* window to update current line in */ { register LINE *lp; /* line to update */ register int sline; /* physical screen line to update */ register int i; /* search down the line we want */ lp = wp->w_linep; sline = wp->w_toprow; while (lp != wp->w_dotp) { ++sline; lp = lforw(lp); } /* and update the virtual line */ vscreen[sline]->v_flag |= VFCHG; vscreen[sline]->v_flag &= ~VFREQ; vtmove(sline, 0); for (i=0; i < llength(lp); ++i) vtputc(lgetc(lp, i)); #if COLOR vscreen[sline]->v_rfcolor = wp->w_fcolor; vscreen[sline]->v_rbcolor = wp->w_bcolor; #endif vteeol(); } /* updall: update all the lines in a window on the virtual screen */ updall(wp) WINDOW *wp; /* window to update lines in */ { register LINE *lp; /* line to update */ register int sline; /* physical screen line to update */ register int i; /* search down the lines, updating them */ lp = wp->w_linep; sline = wp->w_toprow; while (sline < wp->w_toprow + wp->w_ntrows) { /* and update the virtual line */ vscreen[sline]->v_flag |= VFCHG; vscreen[sline]->v_flag &= ~VFREQ; vtmove(sline, 0); if (lp != wp->w_bufp->b_linep) { /* if we are not at the end */ for (i=0; i < llength(lp); ++i) vtputc(lgetc(lp, i)); lp = lforw(lp); } /* on to the next one */ #if COLOR vscreen[sline]->v_rfcolor = wp->w_fcolor; vscreen[sline]->v_rbcolor = wp->w_bcolor; #endif vteeol(); ++sline; } } /* updpos: update the position of the hardware cursor and handle extended lines. This is the only update for simple moves. */ updpos() { register LINE *lp; register int c; register int i; /* find the current row */ lp = curwp->w_linep; currow = curwp->w_toprow; while (lp != curwp->w_dotp) { ++currow; lp = lforw(lp); } /* find the current column */ curcol = 0; i = 0; while (i < curwp->w_doto) { c = lgetc(lp, i++); if (c == '\t') curcol |= 0x07; else if (c < 0x20 || c == 0x7f) ++curcol; ++curcol; } /* if extended, flag so and update the virtual line image */ if (curcol >= term.t_ncol - 1) { vscreen[currow]->v_flag |= (VFEXT | VFCHG); updext(); } else lbound = 0; } /* upddex: de-extend any line that derserves it */ upddex() { register WINDOW *wp; register LINE *lp; register int i,j; wp = wheadp; while (wp != NULL) { lp = wp->w_linep; i = wp->w_toprow; while (i < wp->w_toprow + wp->w_ntrows) { if (vscreen[i]->v_flag & VFEXT) { if ((wp != curwp) || (lp != wp->w_dotp) || (curcol < term.t_ncol - 1)) { vtmove(i, 0); for (j = 0; j < llength(lp); ++j) vtputc(lgetc(lp, j)); vteeol(); /* this line no longer is extended */ vscreen[i]->v_flag &= ~VFEXT; vscreen[i]->v_flag |= VFCHG; } } lp = lforw(lp); ++i; } /* and onward to the next window */ wp = wp->w_wndp; } } /* updgar: if the screen is garbage, clear the physical screen and the virtual screen and force a full update */ updgar() { register char *txt; register int i,j; for (i = 0; i < term.t_nrow; ++i) { vscreen[i]->v_flag |= VFCHG; #if REVSTA vscreen[i]->v_flag &= ~VFREV; #endif #if COLOR vscreen[i]->v_fcolor = gfcolor; vscreen[i]->v_bcolor = gbcolor; #endif #if IBMPC == 0 txt = pscreen[i]->v_text; for (j = 0; j < term.t_ncol; ++j) txt[j] = ' '; #endif } movecursor(0, 0); /* Erase the screen. */ (*term.t_eeop)(); sgarbf = FALSE; /* Erase-page clears */ mpresf = FALSE; /* the message area. */ #if COLOR mlerase(); /* needs to be cleared if colored */ #endif } /* updupd: update the physical screen from the virtual screen */ updupd(force) int force; /* forced update flag */ { register VIDEO *vp1; register int i; for (i = 0; i < term.t_nrow; ++i) { vp1 = vscreen[i]; /* for each line that needs to be updated*/ if ((vp1->v_flag & VFCHG) != 0) { #if TYPEAH if (force == FALSE && typahead()) return(TRUE); #endif #if IBMPC updateline(i, vp1); #else updateline(i, vp1, pscreen[i]); #endif } } #if IBMPC scwriteu(); #endif return(TRUE); } /* updext: update the extended line which the cursor is currently on at a column greater than the terminal width. The line will be scrolled right or left to let the user see where the cursor is */ updext() { register int rcursor; /* real cursor location */ register LINE *lp; /* pointer to current line */ register int j; /* index into line */ /* calculate what column the real cursor will end up in */ rcursor = ((curcol - term.t_ncol) % term.t_scrsiz) + term.t_margin; lbound = curcol - rcursor + 1; /* scan through the line outputing characters to the virtual screen */ /* once we reach the left edge */ vtmove(currow, -lbound); /* start scanning offscreen */ lp = curwp->w_dotp; /* line to output */ for (j=0; j<llength(lp); ++j) /* until the end-of-line */ vtpute(lgetc(lp, j)); /* truncate the virtual line */ vteeol(); /* and put a '$' in column 1 */ vscreen[currow]->v_text[0] = '$'; } /* * Update a single line. This does not know how to use insert or delete * character sequences; we are using VT52 functionality. Update the physical * row and column variables. It does try an exploit erase to end of line. The * RAINBOW version of this routine uses fast video. */ #if IBMPC /* UPDATELINE specific code for the IBM-PC and other compatables */ updateline(row, vp1) int row; /* row of screen to update */ struct VIDEO *vp1; /* virtual screen image */ { #if COLOR scwrite(row, vp1->v_text, vp1->v_rfcolor, vp1->v_rbcolor); vp1->v_fcolor = vp1->v_rfcolor; vp1->v_bcolor = vp1->v_rbcolor; #else if (vp1->v_flag & VFREQ) scwrite(row, vp1->v_text, 0, 7); else scwrite(row, vp1->v_text, 7, 0); #endif vp1->v_flag &= ~(VFCHG | VFCOL); /* flag this line as changed */ } #else updateline(row, vp1, vp2) int row; /* row of screen to update */ struct VIDEO *vp1; /* virtual screen image */ struct VIDEO *vp2; /* physical screen image */ { #if RAINBOW /* UPDATELINE specific code for the DEC rainbow 100 micro */ register char *cp1; register char *cp2; register int nch; /* since we don't know how to make the rainbow do this, turn it off */ flags &= (~VFREV & ~VFREQ); cp1 = &vp1->v_text[0]; /* Use fast video. */ cp2 = &vp2->v_text[0]; putline(row+1, 1, cp1); nch = term.t_ncol; do { *cp2 = *cp1; ++cp2; ++cp1; } while (--nch); *flags &= ~VFCHG; #else /* UPDATELINE code for all other versions */ register char *cp1; register char *cp2; register char *cp3; register char *cp4; register char *cp5; register int nbflag; /* non-blanks to the right flag? */ int rev; /* reverse video flag */ int req; /* reverse video request flag */ /* set up pointers to virtual and physical lines */ cp1 = &vp1->v_text[0]; cp2 = &vp2->v_text[0]; #if COLOR (*term.t_setfor)(vp1->v_rfcolor); (*term.t_setback)(vp1->v_rbcolor); #endif #if REVSTA | COLOR /* if we need to change the reverse video status of the current line, we need to re-write the entire line */ rev = (vp1->v_flag & VFREV) == VFREV; req = (vp1->v_flag & VFREQ) == VFREQ; if ((rev != req) #if COLOR || (vp1->v_fcolor != vp1->v_rfcolor) || (vp1->v_bcolor != vp1->v_rbcolor) #endif ) { movecursor(row, 0); /* Go to start of line. */ /* set rev video if needed */ if (rev != req) (*term.t_rev)(req); /* scan through the line and dump it to the screen and the virtual screen array */ cp3 = &vp1->v_text[term.t_ncol]; while (cp1 < cp3) { (*term.t_putchar)(*cp1); ++ttcol; *cp2++ = *cp1++; } /* turn rev video off */ if (rev != req) (*term.t_rev)(FALSE); /* update the needed flags */ vp1->v_flag &= ~VFCHG; if (req) vp1->v_flag |= VFREV; else vp1->v_flag &= ~VFREV; #if COLOR vp1->v_fcolor = vp1->v_rfcolor; vp1->v_bcolor = vp1->v_rbcolor; #endif return(TRUE); } #endif /* advance past any common chars at the left */ while (cp1 != &vp1->v_text[term.t_ncol] && cp1[0] == cp2[0]) { ++cp1; ++cp2; } /* This can still happen, even though we only call this routine on changed * lines. A hard update is always done when a line splits, a massive * change is done, or a buffer is displayed twice. This optimizes out most * of the excess updating. A lot of computes are used, but these tend to * be hard operations that do a lot of update, so I don't really care. */ /* if both lines are the same, no update needs to be done */ if (cp1 == &vp1->v_text[term.t_ncol]) return(TRUE); /* find out if there is a match on the right */ nbflag = FALSE; cp3 = &vp1->v_text[term.t_ncol]; cp4 = &vp2->v_text[term.t_ncol]; while (cp3[-1] == cp4[-1]) { --cp3; --cp4; if (cp3[0] != ' ') /* Note if any nonblank */ nbflag = TRUE; /* in right match. */ } cp5 = cp3; /* Erase to EOL ? */ if (nbflag == FALSE && eolexist == TRUE && (req != TRUE)) { while (cp5!=cp1 && cp5[-1]==' ') --cp5; if (cp3-cp5 <= 3) /* Use only if erase is */ cp5 = cp3; /* fewer characters. */ } movecursor(row, cp1 - &vp1->v_text[0]); /* Go to start of line. */ #if REVSTA (*term.t_rev)((vp1->v_flag & VFREV) == VFREV); #endif while (cp1 != cp5) { /* Ordinary. */ (*term.t_putchar)(*cp1); ++ttcol; *cp2++ = *cp1++; } if (cp5 != cp3) { /* Erase. */ (*term.t_eeol)(); while (cp1 != cp3) *cp2++ = *cp1++; } #if REVSTA (*term.t_rev)(FALSE); #endif vp1->v_flag &= ~VFCHG; /* flag this line is changed */ return(TRUE); #endif } #endif /* * Redisplay the mode line for the window pointed to by the "wp". This is the * only routine that has any idea of how the modeline is formatted. You can * change the modeline format by hacking at this routine. Called by "update" * any time there is a dirty window. */ modeline(wp) WINDOW *wp; { register char *cp; register int c; register int n; /* cursor position count */ register BUFFER *bp; register i; /* loop index */ register lchar; /* character to draw line in buffer with */ register firstm; /* is this the first mode? */ char tline[NLINE]; /* buffer for part of mode line */ n = wp->w_toprow+wp->w_ntrows; /* Location. */ vscreen[n]->v_flag |= VFCHG | VFREQ | VFCOL;/* Redraw next time. */ #if COLOR vscreen[n]->v_rfcolor = 0; /* black on */ vscreen[n]->v_rbcolor = 7; /* white.....*/ #endif vtmove(n, 0); /* Seek to right line. */ if (wp == curwp) /* mark the current buffer */ lchar = '='; else #if REVSTA if (revexist) lchar = ' '; else #endif lchar = '-'; vtputc(lchar); bp = wp->w_bufp; if ((bp->b_flag&BFCHG) != 0) /* "*" if changed. */ vtputc('*'); else vtputc(lchar); n = 2; strcpy(tline, " MicroEMACS 3.7 ("); /* Buffer name. */ /* display the modes */ firstm = TRUE; for (i = 0; i < NUMMODES; i++) /* add in the mode flags */ if (wp->w_bufp->b_mode & (1 << i)) { if (firstm != TRUE) strcat(tline, " "); firstm = FALSE; strcat(tline, modename[i]); } strcat(tline,") "); cp = &tline[0]; while ((c = *cp++) != 0) { vtputc(c); ++n; } #if WFDEBUG vtputc(lchar); vtputc((wp->w_flag&WFCOLR) != 0 ? 'C' : lchar); vtputc((wp->w_flag&WFMODE) != 0 ? 'M' : lchar); vtputc((wp->w_flag&WFHARD) != 0 ? 'H' : lchar); vtputc((wp->w_flag&WFEDIT) != 0 ? 'E' : lchar); vtputc((wp->w_flag&WFMOVE) != 0 ? 'V' : lchar); vtputc((wp->w_flag&WFFORCE) != 0 ? 'F' : lchar); vtputc(lchar); n += 8; #endif vtputc(lchar); vtputc(lchar); vtputc(' '); n += 3; cp = &bp->b_bname[0]; while ((c = *cp++) != 0) { vtputc(c); ++n; } vtputc(' '); vtputc(lchar); vtputc(lchar); n += 3; if (bp->b_fname[0] != 0) /* File name. */ { vtputc(' '); ++n; cp = "File: "; while ((c = *cp++) != 0) { vtputc(c); ++n; } cp = &bp->b_fname[0]; while ((c = *cp++) != 0) { vtputc(c); ++n; } vtputc(' '); ++n; } while (n < term.t_ncol) /* Pad to full width. */ { vtputc(lchar); ++n; } } upmode() /* update all the mode lines */ { register WINDOW *wp; wp = wheadp; while (wp != NULL) { wp->w_flag |= WFMODE; wp = wp->w_wndp; } } /* * Send a command to the terminal to move the hardware cursor to row "row" * and column "col". The row and column arguments are origin 0. Optimize out * random calls. Update "ttrow" and "ttcol". */ movecursor(row, col) { if (row!=ttrow || col!=ttcol) { ttrow = row; ttcol = col; (*term.t_move)(row, col); } } /* * Erase the message line. This is a special routine because the message line * is not considered to be part of the virtual screen. It always works * immediately; the terminal buffer is flushed via a call to the flusher. */ mlerase() { int i; movecursor(term.t_nrow, 0); #if COLOR (*term.t_setfor)(7); (*term.t_setback)(0); #endif if (eolexist == TRUE) (*term.t_eeol)(); else { for (i = 0; i < term.t_ncol - 1; i++) (*term.t_putchar)(' '); movecursor(term.t_nrow, 1); /* force the move! */ movecursor(term.t_nrow, 0); } (*term.t_flush)(); mpresf = FALSE; } /* * Write a message into the message line. Keep track of the physical cursor * position. A small class of printf like format items is handled. Assumes the * stack grows down; this assumption is made by the "++" in the argument scan * loop. Set the "message line" flag TRUE. */ mlwrite(fmt, arg) char *fmt; { register int c; register char *ap; #if COLOR (*term.t_setfor)(7); (*term.t_setback)(0); #endif if (eolexist == FALSE) { mlerase(); (*term.t_flush)(); } movecursor(term.t_nrow, 0); ap = (char *) &arg; while ((c = *fmt++) != 0) { if (c != '%') { (*term.t_putchar)(c); ++ttcol; } else { c = *fmt++; switch (c) { case 'd': mlputi(*(int *)ap, 10); ap += sizeof(int); break; case 'o': mlputi(*(int *)ap, 8); ap += sizeof(int); break; case 'x': mlputi(*(int *)ap, 16); ap += sizeof(int); break; case 'D': mlputli(*(long *)ap, 10); ap += sizeof(long); break; case 's': mlputs(*(char **)ap); ap += sizeof(char *); break; case 'f': mlputf(*(int *)ap); ap += sizeof(int); break; default: (*term.t_putchar)(c); ++ttcol; } } } if (eolexist == TRUE) (*term.t_eeol)(); (*term.t_flush)(); mpresf = TRUE; } /* * Write out a string. Update the physical cursor position. This assumes that * the characters in the string all have width "1"; if this is not the case * things will get screwed up a little. */ mlputs(s) char *s; { register int c; while ((c = *s++) != 0) { (*term.t_putchar)(c); ++ttcol; } } /* * Write out an integer, in the specified radix. Update the physical cursor * position. */ mlputi(i, r) { register int q; static char hexdigits[] = "0123456789ABCDEF"; if (i < 0) { i = -i; (*term.t_putchar)('-'); } q = i/r; if (q != 0) mlputi(q, r); (*term.t_putchar)(hexdigits[i%r]); ++ttcol; } /* * do the same except as a long integer. */ mlputli(l, r) long l; { register long q; if (l < 0) { l = -l; (*term.t_putchar)('-'); } q = l/r; if (q != 0) mlputli(q, r); (*term.t_putchar)((int)(l%r)+'0'); ++ttcol; } /* * write out a scaled integer with two decimal places */ mlputf(s) int s; /* scaled integer to output */ { int i; /* integer portion of number */ int f; /* fractional portion of number */ /* break it up */ i = s / 100; f = s % 100; /* send out the integer portion */ mlputi(i, 10); (*term.t_putchar)('.'); (*term.t_putchar)((f / 10) + '0'); (*term.t_putchar)((f % 10) + '0'); ttcol += 3; } #if RAINBOW putline(row, col, buf) int row, col; char buf[]; { int n; n = strlen(buf); if (col + n - 1 > term.t_ncol) n = term.t_ncol - col + 1; Put_Data(row, col, n, buf); } #endif 1089!Funky!Stuff! exit -------------- This is the end of the archive ----- Brian Boesch Boesch@su-shasta.EDU
boesch@Shasta.STANFORD.EDU (Brian Boesch) (08/21/86)
---------------------------------------------------------------- How often have you said, "But it was only a one line change." In my posing of a modification for faster IBMPC display update on MicroEmacs, I inadvertantly left an extra define in "ibmpc.c". Delete the define of IBM_RETRACEC. This is already defined in "estruct.h". Brian Boesch boesch@su-shasta.EDU