home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-11-17 | 29.5 KB | 1,430 lines |
- Article 82 of comp.sources.misc:
- Path: tut!osu-cis!cbosgd!mandrill!hal!ncoast!allbery
- From: nwd@j.cc.purdue.edu (Daniel Lawrence)
- Newsgroups: comp.sources.misc
- Subject: MicroEmacs 3.9 (Part 6 of 16)
- Message-ID: <5653@ncoast.UUCP>
- Date: 14 Nov 87 21:09:27 GMT
- Sender: allbery@ncoast.UUCP
- Lines: 1415
- Approved: allbery@ncoast.UUCP
- X-Archive: comp.sources.misc/microemacs-3.9/5
-
- # This is a shar archive.
- # Remove everything above this line.
- # Run the file through sh, not csh.
- # (type `sh mes.6')
- # If you do not see the message
- # `mes.6 completed!'
- # then the file was incomplete.
- echo extracting - fileio.c
- sed 's/^X//' > fileio.c << 'FRIDAY_NIGHT'
- X/*
- X * The routines in this file read and write ASCII files from the disk. All of
- X * the knowledge about files are here.
- X */
- X
- X#include <stdio.h>
- X#include "estruct.h"
- X#include "edef.h"
- X
- XFILE *ffp; /* File pointer, all functions. */
- Xint eofflag; /* end-of-file flag */
- X
- X/*
- X * Open a file for reading.
- X */
- Xffropen(fn)
- Xchar *fn;
- X{
- X if ((ffp=fopen(fn, "r")) == NULL)
- X return (FIOFNF);
- X eofflag = FALSE;
- X return (FIOSUC);
- X}
- X
- X/*
- X * Open a file for writing. Return TRUE if all is well, and FALSE on error
- X * (cannot create).
- X */
- Xffwopen(fn)
- Xchar *fn;
- X{
- X#if VMS
- X register int fd;
- X
- X if ((fd=creat(fn, 0666, "rfm=var", "rat=cr")) < 0
- X || (ffp=fdopen(fd, "w")) == NULL) {
- X#else
- X if ((ffp=fopen(fn, "w")) == NULL) {
- X#endif
- X mlwrite("Cannot open file for writing");
- X return (FIOERR);
- X }
- X return (FIOSUC);
- X}
- X
- X/*
- X * Close a file. Should look at the status in all systems.
- X */
- Xffclose()
- X{
- X /* free this since we do not need it anymore */
- X if (fline) {
- X free(fline);
- X fline = NULL;
- X }
- X
- X#if MSDOS & CTRLZ
- X fputc(26, ffp); /* add a ^Z at the end of the file */
- X#endif
- X
- X#if V7 | USG | BSD | (MSDOS & (LATTICE | MSC | TURBO)) | (ST520 & MWC)
- X if (fclose(ffp) != FALSE) {
- X mlwrite("Error closing file");
- X return(FIOERR);
- X }
- X return(FIOSUC);
- X#else
- X fclose(ffp);
- X return (FIOSUC);
- X#endif
- X}
- X
- X/*
- X * Write a line to the already opened file. The "buf" points to the buffer,
- X * and the "nbuf" is its length, less the free newline. Return the status.
- X * Check only at the newline.
- X */
- Xffputline(buf, nbuf)
- Xchar buf[];
- X{
- X register int i;
- X#if CRYPT
- X char c; /* character to translate */
- X
- X if (cryptflag) {
- X for (i = 0; i < nbuf; ++i) {
- X c = buf[i] & 0xff;
- X crypt(&c, 1);
- X fputc(c, ffp);
- X }
- X } else
- X for (i = 0; i < nbuf; ++i)
- X fputc(buf[i]&0xFF, ffp);
- X#else
- X for (i = 0; i < nbuf; ++i)
- X fputc(buf[i]&0xFF, ffp);
- X#endif
- X
- X#if ST520 & ADDCR
- X fputc('\r', ffp);
- X#endif
- X fputc('\n', ffp);
- X
- X if (ferror(ffp)) {
- X mlwrite("Write I/O error");
- X return (FIOERR);
- X }
- X
- X return (FIOSUC);
- X}
- X
- X/*
- X * Read a line from a file, and store the bytes in the supplied buffer. The
- X * "nbuf" is the length of the buffer. Complain about long lines and lines
- X * at the end of the file that don't have a newline present. Check for I/O
- X * errors too. Return status.
- X */
- Xffgetline()
- X
- X{
- X register int c; /* current character read */
- X register int i; /* current index into fline */
- X register char *tmpline; /* temp storage for expanding line */
- X
- X /* if we are at the end...return it */
- X if (eofflag)
- X return(FIOEOF);
- X
- X /* dump fline if it ended up too big */
- X if (flen > NSTRING) {
- X free(fline);
- X fline = NULL;
- X }
- X
- X /* if we don't have an fline, allocate one */
- X if (fline == NULL)
- X if ((fline = malloc(flen = NSTRING)) == NULL)
- X return(FIOMEM);
- X
- X /* read the line in */
- X i = 0;
- X while ((c = fgetc(ffp)) != EOF && c != '\n') {
- X fline[i++] = c;
- X /* if it's longer, get more room */
- X if (i >= flen) {
- X if ((tmpline = malloc(flen+NSTRING)) == NULL)
- X return(FIOMEM);
- X strncpy(tmpline, fline, flen);
- X flen += NSTRING;
- X free(fline);
- X fline = tmpline;
- X }
- X }
- X
- X#if ST520
- X if(fline[i-1] == '\r')
- X i--;
- X#endif
- X
- X /* test for any errors that may have occured */
- X if (c == EOF) {
- X if (ferror(ffp)) {
- X mlwrite("File read error");
- X return(FIOERR);
- X }
- X
- X if (i != 0)
- X eofflag = TRUE;
- X else
- X return(FIOEOF);
- X }
- X
- X /* terminate and decrypt the string */
- X fline[i] = 0;
- X#if CRYPT
- X if (cryptflag)
- X crypt(fline, strlen(fline));
- X#endif
- X return(FIOSUC);
- X}
- X
- Xint fexist(fname) /* does <fname> exist on disk? */
- X
- Xchar *fname; /* file to check for existance */
- X
- X{
- X FILE *fp;
- X
- X /* try to open the file for reading */
- X fp = fopen(fname, "r");
- X
- X /* if it fails, just return false! */
- X if (fp == NULL)
- X return(FALSE);
- X
- X /* otherwise, close it and report true */
- X fclose(fp);
- X return(TRUE);
- X}
- X
- X#if AZTEC & MSDOS
- X#undef fgetc
- X/* a1getc: Get an ascii char from the file input stream
- X but DO NOT strip the high bit
- X*/
- X
- Xint a1getc(fp)
- X
- XFILE *fp;
- X
- X{
- X int c; /* translated character */
- X
- X c = getc(fp); /* get the character */
- X
- X /* if its a <LF> char, throw it out */
- X while (c == 10)
- X c = getc(fp);
- X
- X /* if its a <RETURN> char, change it to a LF */
- X if (c == '\r')
- X c = '\n';
- X
- X /* if its a ^Z, its an EOF */
- X if (c == 26)
- X c = EOF;
- X
- X return(c);
- X}
- X#endif
- FRIDAY_NIGHT
- echo extracting - hp110.c
- sed 's/^X//' > hp110.c << 'FRIDAY_NIGHT'
- X/*
- X * HP110: Hewlett Packard 110 Screen Driver
- X */
- X
- X#define termdef 1 /* don't define "term" external */
- X
- X#include <stdio.h>
- X#include "estruct.h"
- X#include "edef.h"
- X
- X#if HP110
- X
- X#define NROW 16 /* Screen size. */
- X#define NCOL 80 /* Edit if you want to. */
- X#define NPAUSE 100 /* # times thru update to pause */
- X#define MARGIN 8 /* size of minimim margin and */
- X#define SCRSIZ 64 /* scroll size for extended lines */
- X#define BEL 0x07 /* BEL character. */
- X#define ESC 0x1B /* ESC character. */
- X
- Xextern int ttopen(); /* Forward references. */
- Xextern int ttgetc();
- Xextern int ttputc();
- Xextern int ttflush();
- Xextern int ttclose();
- Xextern int h110move();
- Xextern int h110eeol();
- Xextern int h110eeop();
- Xextern int h110beep();
- Xextern int h110open();
- Xextern int h110rev();
- Xextern int h110cres();
- Xextern int h110close();
- Xextern int h110kopen();
- Xextern int h110kclose();
- X
- X#if COLOR
- Xextern int h110fcol();
- Xextern int h110bcol();
- X
- Xint cfcolor = -1; /* current forground color */
- Xint cbcolor = -1; /* current background color */
- X#endif
- X
- X/*
- X * Standard terminal interface dispatch table. Most of the fields point into
- X * "termio" code.
- X */
- XTERM term = {
- X NROW-1,
- X NROW-1,
- X NCOL,
- X NCOL,
- X MARGIN,
- X SCRSIZ,
- X NPAUSE,
- X h110open,
- X h110close,
- X h110kopen,
- X h110kclose,
- X ttgetc,
- X ttputc,
- X ttflush,
- X h110move,
- X h110eeol,
- X h110eeop,
- X h110beep,
- X h110rev,
- X h110cres
- X#if COLOR
- X , h110fcol,
- X h110bcol
- X#endif
- X};
- X
- X#if COLOR
- Xh110fcol(color) /* set the current output color */
- X
- Xint color; /* color to set */
- X
- X{
- X if (color == cfcolor)
- X return;
- X ttputc(ESC);
- X ttputc('[');
- X h110parm(color+30);
- X ttputc('m');
- X cfcolor = color;
- X}
- X
- Xh110bcol(color) /* set the current background color */
- X
- Xint color; /* color to set */
- X
- X{
- X if (color == cbcolor)
- X return;
- X ttputc(ESC);
- X ttputc('[');
- X h110parm(color+40);
- X ttputc('m');
- X cbcolor = color;
- X}
- X#endif
- X
- Xh110move(row, col)
- X{
- X ttputc(ESC);
- X ttputc('[');
- X h110parm(row+1);
- X ttputc(';');
- X h110parm(col+1);
- X ttputc('H');
- X}
- X
- Xh110eeol()
- X{
- X ttputc(ESC);
- X ttputc('[');
- X ttputc('0');
- X ttputc('K');
- X}
- X
- Xh110eeop()
- X{
- X#if COLOR
- X h110fcol(gfcolor);
- X h110bcol(gbcolor);
- X#endif
- X ttputc(ESC);
- X ttputc('[');
- X ttputc('0');
- X ttputc('J');
- X}
- X
- Xh110rev(state) /* change reverse video state */
- X
- Xint state; /* TRUE = reverse, FALSE = normal */
- X
- X{
- X#if COLOR
- X int ftmp, btmp; /* temporaries for colors */
- X#endif
- X
- X ttputc(ESC);
- X ttputc('[');
- X ttputc(state ? '7': '0');
- X ttputc('m');
- X#if COLOR
- X if (state == FALSE) {
- X ftmp = cfcolor;
- X btmp = cbcolor;
- X cfcolor = -1;
- X cbcolor = -1;
- X h110fcol(ftmp);
- X h110bcol(btmp);
- X }
- X#endif
- X}
- X
- Xh110cres() /* change screen resolution */
- X
- X{
- X return(TRUE);
- X}
- X
- Xspal() /* change pallette register */
- X
- X{
- X /* not here */
- X}
- X
- Xh110beep()
- X{
- X ttputc(BEL);
- X ttflush();
- X}
- X
- Xh110parm(n)
- Xregister int n;
- X{
- X register int q,r;
- X
- X q = n/10;
- X if (q != 0) {
- X r = q/10;
- X if (r != 0) {
- X ttputc((r%10)+'0');
- X }
- X ttputc((q%10) + '0');
- X }
- X ttputc((n%10) + '0');
- X}
- X
- Xh110open()
- X{
- X strcpy(sres, "15LINE");
- X revexist = TRUE;
- X ttopen();
- X}
- X
- Xh110close()
- X
- X{
- X#if COLOR
- X h110fcol(7);
- X h110bcol(0);
- X#endif
- X ttclose();
- X}
- X
- Xh110kopen()
- X
- X{
- X}
- X
- Xh110kclose()
- X
- X{
- X}
- X
- X#if FLABEL
- Xfnclabel(f, n) /* label a function key */
- X
- Xint f,n; /* default flag, numeric argument [unused] */
- X
- X{
- X /* on machines with no function keys...don't bother */
- X return(TRUE);
- X}
- X#endif
- X#else
- Xh110hello()
- X{
- X}
- X#endif
- FRIDAY_NIGHT
- echo extracting - hp150.c
- sed 's/^X//' > hp150.c << 'FRIDAY_NIGHT'
- X/*
- X * The routines in this file provide support for HP150 screens
- X * and routines to access the Keyboard through KEYCODE mode.
- X * It compiles into nothing if not an HP150 screen device.
- X * added by Daniel Lawrence
- X */
- X
- X#define termdef 1 /* don't define "term" external */
- X
- X#include <stdio.h>
- X#include "estruct.h"
- X#include "edef.h"
- X
- X#if HP150
- X
- X#define NROW 24 /* Screen size. */
- X#define NCOL 80 /* Edit if you want to. */
- X#define MARGIN 8 /* size of minimim margin and */
- X#define SCRSIZ 64 /* scroll size for extended lines */
- X#define NPAUSE 15 /* # times thru update to pause */
- X#define BEL 0x07 /* BEL character. */
- X#define ESC 0x1B /* ESC character. */
- X
- Xextern int openhp(); /* Forward references. */
- Xextern int ttgetc();
- Xextern int ttputc();
- Xextern int ttflush();
- Xextern int hpflush();
- Xextern int closehp();
- Xextern int hp15kopen();
- Xextern int hp15kclose();
- Xextern int hp15move();
- Xextern int hp15eeol();
- Xextern int hp15eeop();
- Xextern int hp15beep();
- Xextern int gethpkey();
- Xextern int hp15rev();
- Xextern int hp15cres();
- X#if COLOR
- Xextern int hp15fcol();
- Xextern int hp15bcol();
- X#endif
- X
- X/* weird to ascii translation table */
- X
- Xchar trans[][2] = {
- X 0x24, 9, /* tab */
- X 0x25, 13, /* ret */
- X 0x27, 8, /* backspace */
- X 0x30, 48, /* zero */
- X 0x31, 49, /* one */
- X 0x32, 50, /* two */
- X 0x33, 51, /* three */
- X 0x34, 52, /* four */
- X 0x35, 53, /* five */
- X 0x36, 54, /* six */
- X 0x37, 55, /* seven */
- X 0x38, 56, /* eight */
- X 0x39, 57, /* nine */
- X 0x50, 13, /* enter */
- X 0x54, 27, /* break -> ESC */
- X 0x55, 27, /* esc */
- X 0x58, 24, /* stop -> ^X */
- X 0x70, 45, /* N-minus */
- X 0x71, 42, /* N-asterisk */
- X 0x72, 43, /* N-plus */
- X 0x73, 47, /* N-slash */
- X 0x74, 44, /* N-comma */
- X 0x75, 13, /* N-enter */
- X 0x76, 9, /* N-tab */
- X 0x77, 46 /* N-period */
- X};
- X
- X#define NTRANS sizeof(trans) / 2
- X
- Xunion REGS r; /* register set for bios and dos (AGIOS) calls */
- Xint capslock = 0; /* caps lock flag */
- X
- X/*
- X * Standard terminal interface dispatch table. Most of the fields point into
- X * "termio" code.
- X */
- XTERM term = {
- X NROW-1,
- X NROW-1,
- X NCOL,
- X NCOL,
- X MARGIN,
- X SCRSIZ,
- X NPAUSE,
- X openhp,
- X closehp,
- X hp15kopen,
- X hp15kclose,
- X gethpkey,
- X ttputc,
- X hpflush,
- X hp15move,
- X hp15eeol,
- X hp15eeop,
- X hp15beep,
- X hp15rev,
- X hp15cres
- X#if COLOR
- X , hp15fcol,
- X hp15bcol
- X#endif
- X};
- X
- Xhp15move(row, col)
- X{
- X ttputc(ESC);
- X ttputc('&');
- X ttputc('a');
- X hp15parm(col);
- X ttputc('c');
- X hp15parm(row);
- X ttputc('R');
- X}
- X
- Xhpflush()
- X
- X{
- X
- X}
- X
- Xhp15eeol()
- X{
- X ttputc(ESC);
- X ttputc('K');
- X}
- X
- Xhp15eeop()
- X{
- X ttputc(ESC);
- X ttputc('J');
- X}
- X
- Xhp15rev(status) /* change the reverse video status */
- X
- Xint status; /* TRUE = on, FALSE = off */
- X
- X{
- X ttputc(ESC);
- X ttputc('&');
- X ttputc('d');
- X ttputc((status != FALSE) ? 'B': '@');
- X}
- X
- Xhp15cres() /* change screen resolution */
- X
- X{
- X return(TRUE);
- X}
- X
- Xspal() /* change pallette register */
- X
- X{
- X /* not here */
- X}
- X
- Xhp15beep()
- X{
- X ttputc(BEL);
- X ttflush();
- X}
- X
- Xhp15parm(n)
- Xregister int n;
- X{
- X register int q;
- X
- X q = n/10;
- X if (q != 0)
- X hp15parm(q);
- X ttputc((n%10) + '0');
- X}
- X
- X#if COLOR
- Xhp15fcol() /* we really can't do colors here, so just ignore it */
- X{
- X}
- X
- Xhp15bcol() /* we really can't do colors here, so just ignore it */
- X{
- X}
- X#endif
- X
- Xgethpkey() /* get a key from the HP keyboard while in keycode mode */
- X
- X{
- X static int keepflag = 0; /* kept ahead char flag */
- X static int keepchar = 0; /* kept ehead flag */
- X int c;
- X int devid; /* device ID */
- X int ctype; /* type of character gotten */
- X int shiftb; /* state of shift keys */
- X int i;
- X
- X /* if we are in an extended char sequence, finish it */
- X if (keepflag != 0) {
- X keepflag = 0;
- X return(keepchar);
- X }
- X
- X /* grab the next 4 char sequence */
- Xnext: shiftb = ttgetc();
- X devid = ttgetc();
- X c = ttgetc();
- X ttgetc(); /* skip null byte */
- X
- X /* make sure we are from the keyboard */
- X if (devid != 192)
- X goto next;
- X
- X /* if normal ascii, return it */
- X if ((shiftb & 0x80) == 0) {
- X if (capslock && c >= 'a' && c <= 'z')
- X c -= 32;
- X return(c);
- X }
- X
- X /* check specifically for the caps lock key */
- X if (c == 0x56) {
- X capslock = ~capslock;
- X goto next;
- X }
- X
- X /* check to see if it needs translation */
- X for (i=0; i < NTRANS; i++)
- X if (trans[i][0] == c)
- X return((int)trans[i][1]);
- X
- X /* other wise, shove it in the keep char and return the leadin code */
- X keepchar = c;
- X keepflag = 1;
- X return(0);
- X}
- X
- Xopenhp() /* open the HP150 screen for input */
- X
- X{
- X strcpy(sres, "NORMAL");
- X revexist = TRUE;
- X}
- X
- Xclosehp() /* close the HP150 screen for input */
- X
- X{
- X}
- X
- Xhp15kopen() /* open the HP150 keyboard for input */
- X
- X{
- X /* define key charectoristics with AGIOS call (0, 40) */
- X defkey();
- X
- X /* Turn on RAW mode with MSDOS call 44h */
- X rawon();
- X
- X /* Turn off Control-C checking MS-DOS 33h */
- X ckeyoff();
- X
- X /* Turn on keycode mode with AGIOS call (0,43) */
- X keycon();
- X
- X /* display the application softkey labels */
- X dsplbls();
- X}
- X
- Xhp15kclose() /* close the HP150 keyboard for input */
- X
- X{
- X /* define key charectoristics with AGIOS call (0, 40) */
- X undefkey();
- X
- X /* Turn off RAW mode with MSDOS call 44h */
- X rawoff();
- X
- X /* Turn on Control-C checking MS-DOS 33h */
- X ckeyon();
- X
- X /* Turn off keycode mode with AGIOS call (0,43) */
- X keycoff();
- X}
- X
- Xrawon() /* put the HP150 keyboard into RAW mode */
- X
- X{
- X /* get the IO control info */
- X
- X r.x.ax = 0x4400; /* IO ctrl get device information */
- X r.x.bx = 0x0001; /* File handle; 1 for console */
- X intdos(&r, &r); /* go fer it */
- X
- X r.h.dh = 0; /* clear high byte for put */
- X r.h.dl |= 0x20; /* set raw bit */
- X
- X /* and put it back */
- X
- X r.x.ax = 0x4401; /* IO ctrl put device information */
- X r.x.bx = 0x0001; /* File handle; 1 for console */
- X intdos(&r, &r); /* go fer it */
- X}
- X
- Xrawoff() /* put the HP150 keyboard into COOKED mode */
- X
- X{
- X /* get the IO control info */
- X
- X r.x.ax = 0x4400; /* IO ctrl get device information */
- X r.x.bx = 0x0001; /* File handle; 1 for console */
- X intdos(&r, &r); /* go fer it */
- X
- X r.h.dh = 0; /* clear high byte for put */
- X r.h.dl &= 0xdf; /* set raw bit */
- X
- X /* and put it back */
- X
- X r.x.ax = 0x4401; /* IO ctrl put device information */
- X r.x.bx = 0x0001; /* File handle; 1 for console */
- X intdos(&r, &r); /* go fer it */
- X}
- X
- X
- Xckeyoff() /* turn control-C trapping off */
- X
- X{
- X r.h.ah = 0x33; /* ctrl-break check */
- X r.h.al = 1; /* set the state of the ctrl-break check */
- X r.h.dl = 0; /* turn it off */
- X intdos(&r, &r);
- X}
- X
- Xckeyon() /* turn control-C trapping on */
- X
- X{
- X r.h.ah = 0x33; /* ctrl-break check */
- X r.h.al = 1; /* set the state of the ctrl-break check */
- X r.h.dl = 1; /* turn it on */
- X intdos(&r, &r);
- X}
- X
- X#ifdef unsigned
- X#undef unsigned
- X#endif
- X
- Xagios(buf, len) /* perform an AGIOS call */
- X
- Xchar *buf; /* sequence of bytes in command */
- Xint len; /* length of command in bytes */
- X
- X{
- X r.x.ax = 0x4403; /* I/O ctrl write */
- X r.x.bx = 1; /* console handle */
- X r.x.cx = len; /* buffer length */
- X r.x.dx = (unsigned)buf; /* buffer address */
- X return(intdos(&r, &r)); /* do it */
- X}
- X
- Xkeycon() /* turn keycode mode on */
- X
- X{
- X static char cmd[] = {43, 0, 1};
- X
- X return(agios(&cmd[0], 3));
- X}
- X
- Xkeycoff() /* turn keycode mode off */
- X
- X{
- X static char cmd[] = {43, 0, 0};
- X
- X return(agios(&cmd[0], 3));
- X}
- X
- Xdefkey() /* change all special keys to intercept mode */
- X
- X{
- X static char cmd[] = {40, 0, 2, 0, 0xfe, 0};
- X
- X return(agios(&cmd[0], 6));
- X}
- X
- Xundefkey() /* change all special keys to intercept mode */
- X
- X{
- X static char cmd[] = {40, 0, 0, 0, 0xfe, 0};
- X
- X return(agios(&cmd[0], 6));
- X}
- X
- Xdsplbls() /* display the application softkey labels on the screen */
- X
- X{
- X static char cmd[] = {11, 0};
- X
- X return(agios(&cmd[0], 2));
- X}
- X
- X#if FLABEL
- Xfnclabel(f, n) /* label a function key */
- X
- Xint f,n; /* default flag, numeric argument */
- X
- X{
- X register int status; /* return status */
- X register int i; /* loop index */
- X char lbl[17]; /* returned label contents */
- X /* AGIOS command buffer */
- X static char cmd[] = {8, 0, 1, 0, 7, 7, 7, 7, 10, 0, 10, 0};
- X /* code key# ptr to top bottom
- X label string attribute */
- X union { /* union to cast ptr into AGIOS arg string */
- X char *ptr; /* pointer to arg string */
- X char cstr[4];
- X } ptru;
- X
- X /* must have a numeric argument */
- X if (f == FALSE) {
- X mlwrite("%Need function key number");
- X return(FALSE);
- X }
- X
- X /* and it must be a legal key number */
- X if (n < 1 || n > 8) {
- X mlwrite("%Function key number out of range");
- X return(FALSE);
- X }
- X
- X /* get the string to send */
- X status = mlreply("Label contents: ", &lbl[0], 17);
- X if (status != TRUE)
- X return(status);
- X
- X /* pad the label out */
- X for (i=0; i < 17; i++) {
- X if (lbl[i] == 0)
- X break;
- X }
- X for (; i < 16; i++)
- X lbl[i] = ' ';
- X lbl[16] = 0;
- X
- X /* set up the parameters */
- X cmd[2] = n; /* function key number */
- X ptru.ptr = &lbl[0]; /* set up pointer to label string */
- Xforce: cmd[4] = ptru.cstr[0];
- X cmd[5] = ptru.cstr[1];
- X cmd[6] = ptru.cstr[2];
- X cmd[7] = ptru.cstr[3];
- X
- X /* and send it out */
- X agios(&cmd[0], 12);
- X return(TRUE);
- X}
- X#endif
- X#else
- X
- Xh15hello()
- X
- X{
- X}
- X#endif
- FRIDAY_NIGHT
- echo extracting - ibmpc.c
- sed 's/^X//' > ibmpc.c << 'FRIDAY_NIGHT'
- X/*
- X * The routines in this file provide support for the IBM-PC and other
- X * compatible terminals. It goes directly to the graphics RAM to do
- X * screen output. It compiles into nothing if not an IBM-PC driver
- X * Supported monitor cards include CGA, MONO and EGA.
- X */
- X
- X#define termdef 1 /* don't define "term" external */
- X
- X#include <stdio.h>
- X#include "estruct.h"
- X#include "edef.h"
- X
- X#if IBMPC
- X#define NROW 43 /* Max Screen size. */
- X#define NCOL 80 /* Edit if you want to. */
- X#define MARGIN 8 /* size of minimim margin and */
- X#define SCRSIZ 64 /* scroll size for extended lines */
- X#define NPAUSE 200 /* # times thru update to pause */
- X#define BEL 0x07 /* BEL character. */
- X#define ESC 0x1B /* ESC character. */
- X#define SPACE 32 /* space character */
- X
- X#define SCADC 0xb8000000L /* CGA address of screen RAM */
- X#define SCADM 0xb0000000L /* MONO address of screen RAM */
- X#define SCADE 0xb8000000L /* EGA address of screen RAM */
- X
- X#define MONOCRSR 0x0B0D /* monochrome cursor */
- X#define CGACRSR 0x0607 /* CGA cursor */
- X#define EGACRSR 0x0709 /* EGA cursor */
- X
- X#define CDCGA 0 /* color graphics card */
- X#define CDMONO 1 /* monochrome text card */
- X#define CDEGA 2 /* EGA color adapter */
- X#define CDSENSE 9 /* detect the card type */
- X
- X#define NDRIVE 3 /* number of screen drivers */
- X
- Xint dtype = -1; /* current display type */
- Xchar drvname[][8] = { /* screen resolution names */
- X "CGA", "MONO", "EGA"
- X};
- Xlong scadd; /* address of screen ram */
- Xint *scptr[NROW]; /* pointer to screen lines */
- Xunsigned int sline[NCOL]; /* screen line image */
- Xint egaexist = FALSE; /* is an EGA card available? */
- Xextern union REGS rg; /* cpu register for use of DOS calls */
- X
- Xextern int ttopen(); /* Forward references. */
- Xextern int ttgetc();
- Xextern int ttputc();
- Xextern int ttflush();
- Xextern int ttclose();
- Xextern int ibmmove();
- Xextern int ibmeeol();
- Xextern int ibmeeop();
- Xextern int ibmbeep();
- Xextern int ibmopen();
- Xextern int ibmrev();
- Xextern int ibmcres();
- Xextern int ibmclose();
- Xextern int ibmputc();
- Xextern int ibmkopen();
- Xextern int ibmkclose();
- X
- X#if COLOR
- Xextern int ibmfcol();
- Xextern int ibmbcol();
- X
- Xint cfcolor = -1; /* current forground color */
- Xint cbcolor = -1; /* current background color */
- Xint ctrans[] = /* ansi to ibm color translation table */
- X {0, 4, 2, 6, 1, 5, 3, 7};
- X#endif
- X
- X/*
- X * Standard terminal interface dispatch table. Most of the fields point into
- X * "termio" code.
- X */
- XTERM term = {
- X NROW-1,
- X NROW-1,
- X NCOL,
- X NCOL,
- X MARGIN,
- X SCRSIZ,
- X NPAUSE,
- X ibmopen,
- X ibmclose,
- X ibmkopen,
- X ibmkclose,
- X ttgetc,
- X ibmputc,
- X ttflush,
- X ibmmove,
- X ibmeeol,
- X ibmeeop,
- X ibmbeep,
- X ibmrev,
- X ibmcres
- X#if COLOR
- X , ibmfcol,
- X ibmbcol
- X#endif
- X};
- X
- X#if COLOR
- Xibmfcol(color) /* set the current output color */
- X
- Xint color; /* color to set */
- X
- X{
- X cfcolor = ctrans[color];
- X}
- X
- Xibmbcol(color) /* set the current background color */
- X
- Xint color; /* color to set */
- X
- X{
- X cbcolor = ctrans[color];
- X}
- X#endif
- X
- Xibmmove(row, col)
- X{
- X rg.h.ah = 2; /* set cursor position function code */
- X rg.h.dl = col;
- X rg.h.dh = row;
- X rg.h.bh = 0; /* set screen page number */
- X int86(0x10, &rg, &rg);
- X}
- X
- Xibmeeol() /* erase to the end of the line */
- X
- X{
- X unsigned int attr; /* attribute byte mask to place in RAM */
- X unsigned int *lnptr; /* pointer to the destination line */
- X int i;
- X int ccol; /* current column cursor lives */
- X int crow; /* row */
- X
- X /* find the current cursor position */
- X rg.h.ah = 3; /* read cursor position function code */
- X rg.h.bh = 0; /* current video page */
- X int86(0x10, &rg, &rg);
- X ccol = rg.h.dl; /* record current column */
- X crow = rg.h.dh; /* and row */
- X
- X /* build the attribute byte and setup the screen pointer */
- X#if COLOR
- X if (dtype != CDMONO)
- X attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
- X else
- X attr = 0x0700;
- X#else
- X attr = 0x0700;
- X#endif
- X lnptr = &sline[0];
- X for (i=0; i < term.t_ncol; i++)
- X *lnptr++ = SPACE | attr;
- X
- X if (flickcode && (dtype == CDCGA)) {
- X /* wait for vertical retrace to be off */
- X while ((inp(0x3da) & 8))
- X ;
- X
- X /* and to be back on */
- X while ((inp(0x3da) & 8) == 0)
- X ;
- X }
- X
- X /* and send the string out */
- X movmem(&sline[0], scptr[crow]+ccol, (term.t_ncol-ccol)*2);
- X
- X}
- X
- Xibmputc(ch) /* put a character at the current position in the
- X current colors */
- X
- Xint ch;
- X
- X{
- X rg.h.ah = 14; /* write char to screen with current attrs */
- X rg.h.al = ch;
- X#if COLOR
- X if (dtype != CDMONO)
- X rg.h.bl = cfcolor;
- X else
- X rg.h.bl = 0x07;
- X#else
- X rg.h.bl = 0x07;
- X#endif
- X int86(0x10, &rg, &rg);
- X}
- X
- Xibmeeop()
- X{
- X int attr; /* attribute to fill screen with */
- X
- X rg.h.ah = 6; /* scroll page up function code */
- X rg.h.al = 0; /* # lines to scroll (clear it) */
- X rg.x.cx = 0; /* upper left corner of scroll */
- X rg.x.dx = (term.t_nrow << 8) | (term.t_ncol - 1);
- X /* lower right corner of scroll */
- X#if COLOR
- X if (dtype != CDMONO)
- X attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
- X else
- X attr = 0;
- X#else
- X attr = 0;
- X#endif
- X rg.h.bh = attr;
- X int86(0x10, &rg, &rg);
- X}
- X
- Xibmrev(state) /* change reverse video state */
- X
- Xint state; /* TRUE = reverse, FALSE = normal */
- X
- X{
- X /* This never gets used under the IBM-PC driver */
- X}
- X
- Xibmcres(res) /* change screen resolution */
- X
- Xchar *res; /* resolution to change to */
- X
- X{
- X int i; /* index */
- X
- X for (i = 0; i < NDRIVE; i++)
- X if (strcmp(res, drvname[i]) == 0) {
- X scinit(i);
- X return(TRUE);
- X }
- X return(FALSE);
- X}
- X
- Xspal() /* reset the pallette registers */
- X
- X{
- X /* nothin here now..... */
- X}
- X
- Xibmbeep()
- X{
- X#if MWC86
- X putcnb(BEL);
- X#else
- X bdos(6, BEL, 0);
- X#endif
- X}
- X
- Xibmopen()
- X{
- X scinit(CDSENSE);
- X revexist = TRUE;
- X ttopen();
- X}
- X
- Xibmclose()
- X
- X{
- X#if COLOR
- X ibmfcol(7);
- X ibmbcol(0);
- X#endif
- X /* if we had the EGA open... close it */
- X if (dtype == CDEGA)
- X egaclose();
- X
- X ttclose();
- X}
- X
- Xibmkopen() /* open the keyboard */
- X
- X{
- X}
- X
- Xibmkclose() /* close the keyboard */
- X
- X{
- X}
- X
- Xscinit(type) /* initialize the screen head pointers */
- X
- Xint type; /* type of adapter to init for */
- X
- X{
- X union {
- X long laddr; /* long form of address */
- X int *paddr; /* pointer form of address */
- X } addr;
- X int i;
- X
- X /* if asked...find out what display is connected */
- X if (type == CDSENSE)
- X type = getboard();
- X
- X /* if we have nothing to do....don't do it */
- X if (dtype == type)
- X return(TRUE);
- X
- X /* if we try to switch to EGA and there is none, don't */
- X if (type == CDEGA && egaexist != TRUE)
- X return(FALSE);
- X
- X /* if we had the EGA open... close it */
- X if (dtype == CDEGA)
- X egaclose();
- X
- X /* and set up the various parameters as needed */
- X switch (type) {
- X case CDMONO: /* Monochrome adapter */
- X scadd = SCADM;
- X newsize(TRUE, 25);
- X break;
- X
- X case CDCGA: /* Color graphics adapter */
- X scadd = SCADC;
- X newsize(TRUE, 25);
- X break;
- X
- X case CDEGA: /* Enhanced graphics adapter */
- X scadd = SCADE;
- X egaopen();
- X newsize(TRUE, 43);
- X break;
- X }
- X
- X /* reset the $sres environment variable */
- X strcpy(sres, drvname[type]);
- X dtype = type;
- X
- X /* initialize the screen pointer array */
- X for (i = 0; i < NROW; i++) {
- X addr.laddr = scadd + (long)(NCOL * i * 2);
- X scptr[i] = addr.paddr;
- X }
- X return(TRUE);
- X}
- X
- X/* getboard: Determine which type of display board is attached.
- X Current known types include:
- X
- X CDMONO Monochrome graphics adapter
- X CDCGA Color Graphics Adapter
- X CDEGA Extended graphics Adapter
- X*/
- X
- X/* getboard: Detect the current display adapter
- X if MONO set to MONO
- X CGA set to CGA EGAexist = FALSE
- X EGA set to CGA EGAexist = TRUE
- X*/
- X
- Xint getboard()
- X
- X{
- X int type; /* board type to return */
- X
- X type = CDCGA;
- X int86(0x11, &rg, &rg);
- X if ((((rg.x.ax >> 4) & 3) == 3))
- X type = CDMONO;
- X
- X /* test if EGA present */
- X rg.x.ax = 0x1200;
- X rg.x.bx = 0xff10;
- X int86(0x10,&rg, &rg); /* If EGA, bh=0-1 and bl=0-3 */
- X egaexist = !(rg.x.bx & 0xfefc); /* Yes, it's EGA */
- X return(type);
- X}
- X
- Xegaopen() /* init the computer to work with the EGA */
- X
- X{
- X /* put the beast into EGA 43 row mode */
- X rg.x.ax = 3;
- X int86(16, &rg, &rg);
- X
- X rg.h.ah = 17; /* set char. generator function code */
- X rg.h.al = 18; /* to 8 by 8 double dot ROM */
- X rg.h.bl = 0; /* block 0 */
- X int86(16, &rg, &rg);
- X
- X rg.h.ah = 18; /* alternate select function code */
- X rg.h.al = 0; /* clear AL for no good reason */
- X rg.h.bl = 32; /* alt. print screen routine */
- X int86(16, &rg, &rg);
- X
- X rg.h.ah = 1; /* set cursor size function code */
- X rg.x.cx = 0x0607; /* turn cursor on code */
- X int86(0x10, &rg, &rg);
- X
- X outp(0x3d4, 10); /* video bios bug patch */
- X outp(0x3d5, 6);
- X}
- X
- Xegaclose()
- X
- X{
- X /* put the beast into 80 column mode */
- X rg.x.ax = 3;
- X int86(16, &rg, &rg);
- X}
- X
- Xscwrite(row, outstr, forg, bacg) /* write a line out*/
- X
- Xint row; /* row of screen to place outstr on */
- Xchar *outstr; /* string to write out (must be term.t_ncol long) */
- Xint forg; /* forground color of string to write */
- Xint bacg; /* background color */
- X
- X{
- X unsigned int attr; /* attribute byte mask to place in RAM */
- X unsigned int *lnptr; /* pointer to the destination line */
- X int i;
- X
- X /* build the attribute byte and setup the screen pointer */
- X#if COLOR
- X if (dtype != CDMONO)
- X attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8;
- X else
- X attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
- X#else
- X attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
- X#endif
- X lnptr = &sline[0];
- X for (i=0; i<term.t_ncol; i++)
- X *lnptr++ = (outstr[i] & 255) | attr;
- X
- X if (flickcode && (dtype == CDCGA)) {
- X /* wait for vertical retrace to be off */
- X while ((inp(0x3da) & 8))
- X ;
- X
- X /* and to be back on */
- X while ((inp(0x3da) & 8) == 0)
- X ;
- X }
- X
- X /* and send the string out */
- X movmem(&sline[0], scptr[row],term.t_ncol*2);
- X}
- X
- X#if FLABEL
- Xfnclabel(f, n) /* label a function key */
- X
- Xint f,n; /* default flag, numeric argument [unused] */
- X
- X{
- X /* on machines with no function keys...don't bother */
- X return(TRUE);
- X}
- X#endif
- X#else
- Xibmhello()
- X{
- X}
- X#endif
- X
- FRIDAY_NIGHT
- echo mes.6 completed!
- # That's all folks!
-
-
-