davidsen@steinmetz.UUCP (William E. Davidsen Jr) (06/15/87)
: #!/bin/sh # shar+ created from directory /usr2/davidsen/emacs38i # 13:42 on Thu Jun 11, 1987 by davidsen echo 'x - st520.c (text)' sed << 'E!O!F' 's/^X//' > st520.c X/* X XThe routines in this file provide support for the Atari 520 or 1040ST Xusing VT52 emulation. The I/O services are provided here as well. It Xcompiles into nothing if not a 520ST style device. X 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 MEGAMAX Xoverlay "st520" X#endif X X#if ATARI & ST520 & MEGAMAX X#include <osbind.h> X#include <ctype.h> X X#define LINEA_INIT 0xA000 X#define V_CEL_WR -0x28 X#define V_CEL_MY -0x2a X#define V_CEL_HT -0x2e X#define V_FNT_AD -0x16 X#define V_OFF_AD -0x0a X#define V_DISAB -346 X X#define NROW 25 /* 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 25 /* # times thru update to pause */ X#define BIAS 0x20 /* Origin 0 coordinate bias. */ X#define ESC 0x1B /* ESC character. */ X#define BEL 0x07 /* ascii bell character */ X Xextern int ttopen(); /* Forward references. */ Xextern int ttgetc(); Xextern int ttputc(); Xextern int ttflush(); Xextern int ttclose(); Xextern int st520move(); Xextern int st520eeol(); Xextern int st520eeop(); Xextern int st520beep(); Xextern int st520open(); Xextern int st520close(); Xextern int st520rev(); Xextern int st520kopen(); Xextern int st520kclose(); Xextern int st520chgrez(); X X#if COLOR Xextern int st520fcol(); Xextern int st520bcol(); X Xint cfcolor = -1; /* current fg (character) color */ Xint cbcolor = -1; /* current bg color */ Xint oldpal[8]; /* pallette when emacs was invoked */ Xint newpal[8] = { /* default emacs pallette */ X 0x000, 0x700, 0x070, 0x770, 0x007, 0x707, 0x077, 0x777}; X#endif X Xint STncolors = 0; /* number of colors */ Xint STrez; /* physical screen resolution */ X X/* X * Dispatch table. All the X * hard fields just point into the X * terminal I/O code. X */ XTERM term = { X NROW-1, X NCOL, X MARGIN, X MARGIN, X SCRSIZ, X NPAUSE, X &st520open, X &st520close, X &st520kopen, X &st520kclose, X &ttgetc, X &ttputc, X &ttflush, X &st520move, X &st520eeol, X &st520eeop, X &st520beep, X &st520rev X#if MULTREZ X , &st520chgrez X#endif X#if COLOR X , &st520fcol, X &st520bcol X#endif X}; X struct KBDvecs { X int (*midivec) (); X int (*vkbderr) (); X int (*vmiderr) (); X int (*statvec) (); X int (*mousevec) (); X int (*clockvec) (); X int (*joyvec) (); X int (*midisys) (); X int (*ikbdsys) (); X }; X struct Param { X char topmode; X char buttons; X char xparam; X char yparam; X int xmax,ymax; X int xinitial,yinitial; X }; X struct KBDvecs *kbdvecs; X struct Param *paramp; X char kbdcmds[25]; X Xst520move(row, col) X{ X ttputc(ESC); X ttputc('Y'); X ttputc(row+BIAS); X ttputc(col+BIAS); X} X Xst520eeol() X{ X ttputc(ESC); X ttputc('K'); X} X Xst520eeop() X{ X X#if COLOR X st520fcol(gfcolor); X st520bcol(gbcolor); X#endif X ttputc(ESC); X ttputc('J'); X} X Xst520rev(status) /* set the reverse video state */ X Xint status; /* TRUE = reverse video, FALSE = normal video */ X X{ X X if(status) { X ttputc(ESC); X ttputc('p'); X } X else { X ttputc(ESC); X ttputc('q'); X } X} X X#if COLOR Xst520fcol(color) Xint color; X{ X if(color == cfcolor || !STncolors) X return; X else { X X ttputc(ESC); X ttputc('b'); X ttputc(color & 0x0f); X cfcolor = color; X } X} X Xst520bcol(color) Xint color; X{ X if(color == cbcolor || !STncolors) X return; X else { X ttputc(ESC); X ttputc('c'); X ttputc(color & 0x0f); X cbcolor = color; X } X X} X#endif X Xst520beep() X{ X#ifdef BEL X ttputc(BEL); X ttflush(); X#endif X} X Xst520open() X{ X int i,j,k; X long phys, log; /* screen bases */ X X/* IMPORTANT: it is ABSOLUTELY necessary that the default resolution be the X * largest possible so that display will allocate (malloc) the maximum X * size for the VIDEO arrray X */ X STrez = Getrez(); X switch(STrez) { X case 0: /* low res 25x40 16 colors */ X phys = Physbase(); X log = Logbase(); X Setscreen(log, phys, 1); X STrez = 1; X /* fall thru to med res */ X X case 1: /* med res 25x80 4 colors */ X term.t_nrow = 25 - 1; X term.t_ncol = 80; X grez = 1; X#if COLOR X STncolors = 4; X for(i=0;i<8;i++) { X oldpal[i] = Setcolor(i,newpal[i]); X } X#endif X break; X case 2: /* high res 25x80 no colors */ X term.t_nrow = 40 - 1; X term.t_ncol = 80; X grez = 2; X make_8x10(); /* create a smaller font */ X set_40(); /* and go to 40 line mode */ X#if COLOR X STncolors = 0; X#endif X break; X } X X revexist = TRUE; X eolexist = TRUE; X paramp = (struct Param *)malloc(sizeof(struct Param)); X kbdvecs = (struct KBDvecs *)Kbdvbase(); X paramp -> topmode = 0; X paramp -> buttons = 4; X paramp -> xparam = 8; X paramp -> yparam = 10; X paramp -> xmax = 79; X paramp -> ymax = 23; X paramp -> xinitial = 0; X paramp -> yinitial = 0; X Initmous(1,paramp,kbdvecs -> mousevec); X X i = 0; X kbdcmds[i++] = 0x0a; /*set mouse keycode mode */ X kbdcmds[i++] = 0x08; X kbdcmds[i++] = 0x0a; X Ikbdws(i-1,&kbdcmds[0]); X Cursconf(1,0); X Cursconf(3,0); X Cconout(27);Cconout('E'); X ttopen(); X} X Xst520close() X X{ X int i,j,k; X X i = 0; X kbdcmds[i++] = 0x80; /*reset mouse keycode mode */ X kbdcmds[i++] = 0x01; X Ikbdws(i-1,&kbdcmds[0]); X if(grez == 2 && STrez == 2) /* b/w monitor in 40 row mode */ X restore(); X X#if COLOR X for(i=0;i<STncolors;i++) X Setcolor(i,oldpal[i]); X#endif X Cconout(27);Cconout('E'); X paramp -> buttons = 0; X Initmous(2,paramp,kbdvecs -> mousevec); X i = 0; X kbdcmds[i++] = 0x80; /*reset the keyboard*/ X kbdcmds[i++] = 0x01; X Ikbdws(i-1,&kbdcmds[0]); X Cursconf(1,0); X ttclose(); X} Xst520kopen() X{ X X} Xst520kclose() X{ X X} X Xst520chgrez(nurez) Xint nurez; X{ X int ierr, i, j ,k; X long phys, log; /* screen bases */ X char dum[80]; /* for debugging only */ X X if(grez == nurez) X return(TRUE); X X if(STrez == 2) { /* b/w monitor-only allow hi | med rez */ X switch(nurez) { X case 2: /* high res */ X term.t_nrow = 40 - 1; X term.t_ncol = 80; X make_8x10(); /* create a smaller font */ X set_40(); /* and go to 40 line mode */ X grez = 2; X sgarbf = TRUE; X onlywind(1,1); X break; X case 1: /* med res */ X term.t_nrow = 25 - 1; X term.t_ncol = 80; X restore(); X grez = 1; X sgarbf = TRUE; X onlywind(1,1); X break; X default: X mlwrite("Invalid resolution"); X return(FALSE); X break; X } X } X else { /* color monitor-only allow low | medium resolution */ X phys = Physbase(); X log = Logbase(); X switch(nurez) { X case 1: X term.t_nrow = 25 - 1; X term.t_ncol = 80; X Setscreen(log, phys, 1); X STncolors = 4; X grez = 1; X sgarbf = TRUE; X onlywind(1,1); X break; X case 0: X term.t_nrow = 25 - 1; X term.t_ncol = 40; X Setscreen(log, phys, 0); X STncolors = 8; X grez = 0; X sgarbf = TRUE; X onlywind(1,1); X break; X default: X mlwrite("%Invalid resolution"); X return(FALSE); X break; X } X } X} X XSTcurblink(onoff) Xint onoff; X{ X if(onoff) X Cursconf(2,0); X else X Cursconf(3,0); X} X X Xchar parm_save[28]; Xlong fnt_8x10[640]; X Xmake_8x10() X{ X int i,j,k; X long savea23[2]; X X for(i=0;i<640;i++) X fnt_8x10[i] = 0; X X asm { X movem.l A2-A3,savea23(A6) X X dc.w LINEA_INIT ;A1 -> array of font headers X X lea parm_save(A4),A2 ;A2 -> parameters savearea X move.l V_OFF_AD(A0),(A2)+ X move.l V_FNT_AD(A0),(A2)+ X move.w V_CEL_HT(A0),(A2)+ X move.w V_CEL_MY(A0),(A2)+ X move.w V_CEL_WR(A0),(A2)+ X X X move.l 04(A1),A1 ; A1 -> 8x8 font header X move.l 76(A1),A2 ; A2 -> 8x8 font data X lea fnt_8x10+0x100(A4),A3 ; A3 -> 2nd line of font buffer X move.w #0x200-1,D0 ; D0 <- longword counter for font xfer X Xfnt_loop: X X move.l (A2)+,(A3)+ X dbf D0,fnt_loop X X movem.l savea23(A6),A2-A3 X } X X} X Xset_40() X{ X long savea23[2]; X X asm { X X; X; use the 8x10 character set: 40 line mode X; X X movem.l A2-A3,savea23(A6) X X dc.w LINEA_INIT X X move.l 04(A1),A1 ; A1 -> 8x8 font header X move.l 72(A1),V_OFF_AD(A0) ; v_off_ad <- 8x8 offset table addr X lea fnt_8x10(A4),A2 X move.l A2,V_FNT_AD(A0) ; v_fnt_ad <- 8x10 font data addr X X move.w #10,V_CEL_HT(A0) ; v_cel_ht <- 10 8x10 cell height X move.w #39,V_CEL_MY(A0) ; v_cel_my <- 39 maximum cell "Y" X move.w #800,V_CEL_WR(A0) ; v_cel_wr <- 800 offset to cell Y+1 X X movem.l savea23,A2-A3 X } X} X Xset_20() X{ X long savea23[2]; X X asm { X X; X; use the 8x10 character set: 20 line mode X; X X movem.l A2-A3,savea23(A6) X X dc.w LINEA_INIT ; A0 -> line A variables X X move.l 04(A1),A1 ; A1 -> 8x8 font header X move.l 72(A1),V_OFF_AD(A0) ; v_off_ad <- 8x8 offset table addr X lea fnt_8x10(A4),A2 X move.l A2,V_FNT_AD(A0) ; v_fnt_ad <- 8x10 font data addr X X move.w #10,V_CEL_HT(A0) ; v_cel_ht <- 10 8x10 cell height X move.w #19,V_CEL_MY(A0) ; v_cel_my <- 19 maximum cell "Y" X move.w #1600,V_CEL_WR(A0) ; v_cel_wr <- 800 offset to cell Y+1 X X movem.l savea23,A2-A3 X } X} X X Xrestore() X{ X long savea23[2]; X X asm { X X; return what was saved in parameter save zone X X movem.l A2-A3,savea23(A6) X X dc.w LINEA_INIT ; a0 -> line A variables X X lea parm_save(A4),A2 ; a2 -> parameter save area X move.l (A2)+,V_OFF_AD(A0) X move.l (A2)+,V_FNT_AD(A0) X move.w (A2)+,V_CEL_HT(A0) X move.w (A2)+,V_CEL_MY(A0) X move.w (A2)+,V_CEL_WR(A0) X X movem.l savea23(A6),A2-A3 X } X} XGetCurStat(onoff) Xint onoff; X{ X long savea23[2]; X X asm { X movem.l A2-A3,savea23(A6) X X dc.w LINEA_INIT ; a0 -> line A variables X move.w V_DISAB(A0),onoff(A6) ; 0 = cursor visible X moveq #0,D0 X move.w V_DISAB(A0),D0 X movem.l savea23(A6),A2-A3 X } X} X#else X#if ATARI & ST520 & LATTICE X X/* X These routines provide support for the ATARI 1040ST using Xthe LATTICE compiler using the virtual VT52 Emulator X X*/ X X#define NROW 40 /* 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 300 /* # times thru update to pause */ X#define BIAS 0x20 /* Origin 0 coordinate bias. */ X#define ESC 0x1B /* ESC character. */ X#define BEL 0x07 /* ASCII bell character */ X X/**** ST Internals definitions *****/ X X/* BIOS calls */ X X#define BCONSTAT 1 /* return input device status */ X#define CONIN 2 /* read character from device */ X#define BCONOUT 3 /* write character to device */ X X/* XBIOS calls */ X X#define INITMOUS 0 /* initialize the mouse */ X#define GETREZ 4 /* get current resolution */ X#define SETSCREEN 5 /* set screen resolution */ X#define SETPALETTE 6 /* set the color pallette */ X#define SETCOLOR 7 /* set or read a color */ X#define CURSCONF 21 /* set cursor configuration */ X#define IKBDWS 25 /* intelligent keyboard send command */ X#define KBDVBASE 34 /* get keyboard table base */ X X/* GEMDOS calls */ X X#define EXEC 0x4b /* Exec off a process */ X X#define CON 2 /* CON: Keyboard and screen device */ X X/* LINE A variables */ X X#define LINEA_INIT 0xA000 X#define V_CEL_WR -0x28 X#define V_CEL_MY -0x2a X#define V_CEL_HT -0x2e X#define V_FNT_AD -0x16 X#define V_OFF_AD -0x0a X#define V_DISAB -346 X X/* Palette color definitions */ X X#define LOWPAL "000700070770007707077777" X#define MEDPAL "000700007777" X#define HIGHPAL "000111" X X/* ST Global definitions */ X X/* keyboard vector table */ Xstruct KVT { X long midivec; /* midi input */ X long vkbderr; /* keyboard error */ X long vmiderr; /* MIDI error */ X long statvec; /* IKBD status */ X int (*mousevec)(); /* mouse vector */ X long clockvec; /* clock vector */ X long joyvec; /* joystict vector */ X} *ktable; X Xint (*sysmint)(); /* system mouse interupt handler */ X X/* mouse parameter table */ Xstruct Param { X char topmode; X char buttons; X char xparam; X char yparam; X int xmax,ymax; X int xinitial,yinitial; X} mparam; X Xint currez; /* current screen resolution */ Xchar resname[][8] = { /* screen resolution names */ X "LOW", "MEDIUM", "HIGH", "DENSE" X}; Xshort spalette[16]; /* original color palette settings */ Xshort palette[16]; /* current palette settings */ X Xextern int ttopen(); /* Forward references. */ Xextern int ttgetc(); Xextern int ttputc(); Xextern int ttflush(); Xextern int ttclose(); Xextern int stmove(); Xextern int steeol(); Xextern int steeop(); Xextern int stbeep(); Xextern int stopen(); Xextern int stclose(); Xextern int stgetc(); Xextern int stputc(); Xextern int strev(); Xextern int strez(); Xextern int stkopen(); Xextern int stkclose(); X X#if COLOR Xextern int stfcol(); Xextern int stbcol(); X#endif X X/* X * Dispatch table. All the X * hard fields just point into the X * terminal I/O code. X */ XTERM term = { X NROW-1, X NROW-1, X NCOL, X NCOL, X MARGIN, X SCRSIZ, X NPAUSE, X &stopen, X &stclose, X &stkopen, X &stkclose, X &stgetc, X &stputc, X &ttflush, X &stmove, X &steeol, X &steeop, X &stbeep, X &strev, X &strez X#if COLOR X , &stfcol, X &stbcol X#endif X}; X Xstmove(row, col) X{ X stputc(ESC); X stputc('Y'); X stputc(row+BIAS); X stputc(col+BIAS); X} X Xsteeol() X{ X stputc(ESC); X stputc('K'); X} X Xsteeop() X{ X#if COLOR X stfcol(gfcolor); X stbcol(gbcolor); X#endif X stputc(ESC); X stputc('J'); X} X Xstrev(status) /* set the reverse video state */ X Xint status; /* TRUE = reverse video, FALSE = normal video */ X X{ X if (currez > 1) { X stputc(ESC); X stputc(status ? 'p' : 'q'); X } X} X X#if COLOR Xmapcol(clr) /* medium rez color translation */ X Xint clr; /* emacs color number to translate */ X X{ X static int mctable[] = {0, 1, 2, 3, 2, 1, 2, 3}; X X if (currez != 1) X return(clr); X else X return(mctable[clr]); X} X Xstfcol(color) /* set the forground color */ X Xint color; /* color to set forground to */ X X{ X if (currez < 2) { X stputc(ESC); X stputc('b'); X stputc(mapcol(color)); X } X} X Xstbcol(color) /* set the background color */ X Xint color; /* color to set background to */ X X{ X if (currez < 2) { X stputc(ESC); X stputc('c'); X stputc(mapcol(color)); X } X} X#endif X Xstbeep() X{ X stputc(BEL); X ttflush(); X} X Xdomouse() /* mouse interupt handler */ X X{ X return((*sysmint)()); X} X Xstkopen() /* open the keyboard (and mouse) */ X X{ X /* grab the keyboard vector table */ X ktable = (struct KVT *)xbios(KBDVBASE); X sysmint = ktable->mousevec; /* save mouse vector */ X X /* initialize the mouse */ X mparam.topmode = 0; X mparam.buttons = 4; X mparam.xparam = 8; X mparam.yparam = 10; X mparam.xmax = 79; X mparam.ymax = 23; X mparam.xinitial = 0; X mparam.yinitial = 0; X xbios(INITMOUS, 4, &mparam, &domouse); X} X Xstopen() /* open the screen */ X X{ X int i; X X ttopen(); X eolexist = TRUE; X X /* switch to a steady cursor */ X xbios(CURSCONF, 3); X X /* save the current color palette */ X for (i=0; i<16; i++) X spalette[i] = xbios(SETCOLOR, i, -1); X X /* and find the current resolution */ X currez = xbios(GETREZ); X strcpy(sres, resname[currez]); X X /* set up the screen size and palette */ X switch (currez) { X case 0: term.t_mrow = 25 - 1; X term.t_nrow = 25 - 1; X term.t_ncol = 40 - 1; X strcpy(palstr, LOWPAL); X break; X X case 1: term.t_mrow = 25 - 1; X term.t_nrow = 25 - 1; X strcpy(palstr, MEDPAL); X break; X X case 2: term.t_mrow = 40 - 1; X term.t_nrow = 25 - 1; X strcpy(palstr, HIGHPAL); X } X X /* and set up the default palette */ X spal(palstr); X X stputc(ESC); /* automatic overflow off */ X stputc('w'); X stputc(ESC); /* turn cursor on */ X stputc('e'); X} X Xstkclose() /* close the keyboard (and mouse) */ X X{ X static char resetcmd[] = {0x80, 0x01}; /* keyboard reset command */ X X /* restore the mouse interupt routines */ X xbios(INITMOUS, 2, &mparam, (long)sysmint); X X /* and reset the keyboard controller */ X xbios(IKBDWS, 1, &resetcmd[0]); X} X Xstclose() X X{ X stputc(ESC); /* auto overflow on */ X stputc('v'); X X /* switch to a flashing cursor */ X xbios(CURSCONF, 2); X X /* restore the original palette settings */ X xbios(SETPALETTE, spalette); X X ttclose(); X} X X/* spal(pstr): reset the current palette according to a X "palette string" of the form X X 000111222333444555666777 X X which contains the octal values for the palette registers X*/ X Xspal(pstr) X Xchar *pstr; /* palette string */ X X{ X int pal; /* current palette position */ X int clr; /* current color value */ X int i; X X for (pal = 0; pal < 16; pal++) { X if (*pstr== 0) X break; X X /* parse off a color */ X clr = 0; X for (i = 0; i < 3; i++) X if (*pstr) X clr = clr * 16 + (*pstr++ - '0'); X palette[pal] = clr; X }; X X /* and now set it */ X xbios(SETPALETTE, palette); X} X Xstgetc() /* get a char from the keyboard */ X X{ X int rval; /* return value from BIOS call */ X static int funkey = 0; /* held fuction key scan code */ X X /* if there is a pending function key, return it */ X if (funkey) { X rval = funkey; X funkey = 0; X } else { X /* waiting... flash the cursor */ X xbios(CURSCONF, 2); X X /* get the character */ X rval = bios(CONIN, CON); X if ((rval & 255) == 0) { X funkey = (rval >> 16) & 255; X rval = 0; X } X X /* and switch to a steady cursor */ X xbios(CURSCONF, 3); X } X X return(rval & 255); X} X Xstputc(c) /* output char c to the screen */ X Xchar c; /* character to print out */ X X{ X bios(BCONOUT, CON, c); X} X Xstrez(newrez) /* change screen resolution */ X Xchar *newrez; /* requested resolution */ X X{ X int nrez; /* requested new resolution */ X X /* first, decode the resolution name */ X for (nrez = 0; nrez < 4; nrez++) X if (strcmp(newrez, resname[nrez]) == 0) X break; X if (nrez == 4) { X mlwrite("%%No such resolution"); X return(FALSE); X } X X /* next, make sure this resolution is legal for this monitor */ X if ((currez < 2 && nrez > 1) || (currez > 1 && nrez < 2)) { X mlwrite("%%Resolution illegal for this monitor"); X return(FALSE); X } X X /* eliminate non-changes */ X if (currez == nrez) X return(TRUE); X X /* finally, make the change */ X switch (nrez) { X case 0: /* low resolution - 16 colors */ X newwidth(TRUE, 40); X strcpy(palstr, LOWPAL); X xbios(SETSCREEN, -1, -1, 0); X break; X X case 1: /* medium resolution - 4 colors */ X newwidth(TRUE, 80); X strcpy(palstr, MEDPAL); X xbios(SETSCREEN, -1, -1, 1); X break; X X case 2: /* High resolution - 2 colors - 25 lines */ X newsize(TRUE, 25); X strcpy(palstr, HIGHPAL); X /* change char set back to normal */ X break; X X case 3: /* Dense resolution - 2 colors - 40 lines */ X /* newsize(TRUE, 40); */ X strcpy(palstr, HIGHPAL); X /*change char set size */ X break; X } X X /* and set up the default palette */ X spal(palstr); X currez = nrez; X strcpy(sres, resname[currez]); X X stputc(ESC); /* automatic overflow off */ X stputc('w'); X stputc(ESC); /* turn cursor on */ X stputc('e'); X X return(TRUE); X} X Xsystem(cmd) /* call the system to execute a new program */ X Xchar *cmd; /* command to execute */ X X{ X char *pptr; /* pointer into program name */ X char pname[NSTRING]; /* name of program to execute */ X char tail[NSTRING]; /* command tail */ X X /* scan off program name.... */ X pptr = pname; X while (*cmd && (*cmd != ' ' && *cmd != '\t')) X *pptr++ = *cmd++; X *pptr = 0; X X /* create program name length/string */ X tail[0] = strlen(cmd); X strcpy(&tail[1], cmd); X X /* go do it! */ X return(gemdos( (int)EXEC, X (int)0, X (char *)pname, X (char *)tail, X (char *)NULL)); X} X X#if TYPEAH Xtypahead() X X{ X int rval; /* return value from BIOS call */ X X /* get the status of the console */ X rval = bios(BCONSTAT, CON); X X /* end return the results */ X if (rval == 0) X return(FALSE); X else X return(TRUE); X} X#endif 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 Xsthello() X{ X} X#endif X#endif E!O!F newsize=`wc -c < st520.c` if [ $newsize -ne 19838 ] then echo "File st520.c was $newsize bytes, 19838 expected" fi echo 'x - tcap.c (text)' sed << 'E!O!F' 's/^X//' > tcap.c X/* tcap: Unix V5, V7 and BS4.2 Termcap video driver X for MicroEMACS 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 TERMCAP X X#define MARGIN 8 X#define SCRSIZ 48 /* scroll for long lines */ X#define NPAUSE 10 /* # times thru update to pause */ X#define BEL 0x07 X#define ESC 0x1B X Xextern int ttopen(); Xextern int ttgetc(); Xextern int ttputc(); Xextern int tgetnum(); Xextern int ttflush(); Xextern int ttclose(); Xextern int tcapkopen(); Xextern int tcapkclose(); Xextern int tcapmove(); Xextern int tcapeeol(); Xextern int tcapeeop(); Xextern int tcapbeep(); Xextern int tcaprev(); Xextern int tcapcres(); Xextern int tcapopen(); Xextern int tput(); Xextern char *tgoto(); X#if COLOR Xextern int tcapfcol(); Xextern int tcapbcol(); X#endif X X#define TCAPSLEN 315 Xchar tcapbuf[TCAPSLEN]; Xchar *UP, PC, *CM, *CE, *CL, *SO, *SE; X XTERM term = { X NULL, /* these four values are set dynamically at open time */ X NULL, X NULL, X NULL, X MARGIN, X SCRSIZ, X NPAUSE, X tcapopen, X ttclose, X tcapkopen, X tcapkclose, X ttgetc, X ttputc, X ttflush, X tcapmove, X tcapeeol, X tcapeeop, X tcapbeep, X tcaprev, X tcapcres X#if COLOR X , tcapfcol, X tcapbcol X#endif X}; X Xtcapopen() X X{ X char *getenv(); X char *t, *p, *tgetstr(); X char tcbuf[1024]; X char *tv_stype; X char err_str[72]; X X if ((tv_stype = getenv("TERM")) == NULL) X { X puts("Environment variable TERM not defined!"); X exit(1); X } X X if ((tgetent(tcbuf, tv_stype)) != 1) X { X sprintf(err_str, "Unknown terminal type %s!", tv_stype); X puts(err_str); X exit(1); X } X X X if ((term.t_nrow=(short)tgetnum("li")-1) == -1){ X puts("termcap entry incomplete (lines)"); X exit(1); X } X term.t_mrow = term.t_nrow; X X if ((term.t_ncol=(short)tgetnum("co")) == -1){ X puts("Termcap entry incomplete (columns)"); X exit(1); X } X term.t_mcol = term.t_ncol; X X p = tcapbuf; X t = tgetstr("pc", &p); X if(t) X PC = *t; X X CL = tgetstr("cl", &p); X CM = tgetstr("cm", &p); X CE = tgetstr("ce", &p); X UP = tgetstr("up", &p); X SE = tgetstr("se", &p); X SO = tgetstr("so", &p); X if (SO != NULL) X revexist = TRUE; X X if(CL == NULL || CM == NULL || UP == NULL) X { X puts("Incomplete termcap entry\n"); X exit(1); X } X X if (CE == NULL) /* will we be able to use clear to EOL? */ X eolexist = FALSE; X X if (p >= &tcapbuf[TCAPSLEN]) X { X puts("Terminal description too big!\n"); X exit(1); X } X ttopen(); X} X Xtcapkopen() X X{ X strcpy(sres, "NORMAL"); X} X Xtcapkclose() X X{ X} X Xtcapmove(row, col) Xregister int row, col; X{ X putpad(tgoto(CM, col, row)); X} X Xtcapeeol() X{ X putpad(CE); X} X Xtcapeeop() X{ X putpad(CL); X} X Xtcaprev(state) /* change reverse video status */ X Xint state; /* FALSE = normal video, TRUE = reverse video */ X X{ X static int revstate = FALSE; X if (state) { X if (SO != NULL) X putpad(SO); X } else X if (SE != NULL) X putpad(SE); X} X Xtcapcres() /* change screen resolution */ X X{ X return(TRUE); X} X Xspal(dummy) /* change palette string */ X X{ X /* Does nothing here */ X} X X#if COLOR Xtcapfcol() /* no colors here, ignore this */ X{ X} X Xtcapbcol() /* no colors here, ignore this */ X{ X} X#endif X Xtcapbeep() X{ X ttputc(BEL); X} X Xputpad(str) Xchar *str; X{ X tputs(str, 1, ttputc); X} X Xputnpad(str, n) Xchar *str; X{ X tputs(str, n, ttputc); 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 X Xhello() X{ X} X X#endif TERMCAP E!O!F newsize=`wc -c < tcap.c` if [ $newsize -ne 3990 ] then echo "File tcap.c was $newsize bytes, 3990 expected" fi echo 'x - termio.c (text)' sed << 'E!O!F' 's/^X//' > termio.c X/* X * The functions in this file negotiate with the operating system for X * characters, and write characters in a barely buffered fashion on the display. X * All operating systems. X */ X#include <stdio.h> X#include "estruct.h" X#include "edef.h" X X#if MEGAMAX & ST520 Xoverlay "termio" X#endif X X#if AMIGA X#define NEW 1006 X#define AMG_MAXBUF 1024L Xstatic long terminal; Xstatic char scrn_tmp[AMG_MAXBUF+1]; Xstatic long scrn_tmp_p = 0; X#endif X X#if ST520 & MEGAMAX X#include <osbind.h> X int STscancode = 0; X#endif X X#if VMS X#include <stsdef.h> X#include <ssdef.h> X#include <descrip.h> X#include <iodef.h> X#include <ttdef.h> X#include <tt2def.h> X X#define NIBUF 128 /* Input buffer size */ X#define NOBUF 1024 /* MM says bug buffers win! */ X#define EFN 0 /* Event flag */ X Xchar obuf[NOBUF]; /* Output buffer */ Xint nobuf; /* # of bytes in above */ Xchar ibuf[NIBUF]; /* Input buffer */ Xint nibuf; /* # of bytes in above */ Xint ibufi; /* Read index */ Xint oldmode[3]; /* Old TTY mode bits */ Xint newmode[3]; /* New TTY mode bits */ Xshort iochan; /* TTY I/O channel */ X#endif X X#if CPM X#include <bdos.h> X#endif X X#if MSDOS & (LATTICE | MSC | AZTEC | MWC86) Xunion REGS rg; /* cpu register for use of DOS calls */ Xint nxtchar = -1; /* character held from type ahead */ X#endif X X#if RAINBOW X#include "rainbow.h" X#endif X X#if USG /* System V */ X#include <signal.h> X#include <termio.h> Xstruct termio otermio; /* original terminal characteristics */ Xstruct termio ntermio; /* charactoristics to use inside */ X#endif X X#if V7 | BSD X#undef CTRL X#include <sgtty.h> /* for stty/gtty functions */ X#include <signal.h> Xstruct sgttyb ostate; /* saved tty state */ Xstruct sgttyb nstate; /* values for editor mode */ Xstruct tchars otchars; /* Saved terminal special character set */ Xstruct tchars ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; X /* A lot of nothing */ X#if BSD X#include <sys/ioctl.h> /* to get at the typeahead */ Xextern int rtfrmshell(); /* return from suspended shell */ X#define TBUFSIZ 128 Xchar tobuf[TBUFSIZ]; /* terminal output buffer */ X#endif X#endif X X/* X * This function is called once to set up the terminal device streams. X * On VMS, it translates TT until it finds the terminal, then assigns X * a channel to it and sets it raw. On CPM it is a no-op. X */ Xttopen() X{ X#if AMIGA X terminal = Open("RAW:0/0/640/200/MicroEMACS 3.8i/Amiga", NEW); X#endif X#if VMS X struct dsc$descriptor idsc; X struct dsc$descriptor odsc; X char oname[40]; X int iosb[2]; X int status; X X odsc.dsc$a_pointer = "TT"; X odsc.dsc$w_length = strlen(odsc.dsc$a_pointer); X odsc.dsc$b_dtype = DSC$K_DTYPE_T; X odsc.dsc$b_class = DSC$K_CLASS_S; X idsc.dsc$b_dtype = DSC$K_DTYPE_T; X idsc.dsc$b_class = DSC$K_CLASS_S; X do { X idsc.dsc$a_pointer = odsc.dsc$a_pointer; X idsc.dsc$w_length = odsc.dsc$w_length; X odsc.dsc$a_pointer = &oname[0]; X odsc.dsc$w_length = sizeof(oname); X status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc); X if (status!=SS$_NORMAL && status!=SS$_NOTRAN) X exit(status); X if (oname[0] == 0x1B) { X odsc.dsc$a_pointer += 4; X odsc.dsc$w_length -= 4; X } X } while (status == SS$_NORMAL); X status = SYS$ASSIGN(&odsc, &iochan, 0, 0); X if (status != SS$_NORMAL) X exit(status); X status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0, X oldmode, sizeof(oldmode), 0, 0, 0, 0); X if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) X exit(status); X newmode[0] = oldmode[0]; X newmode[1] = oldmode[1] | TT$M_NOECHO; X newmode[1] &= ~(TT$M_TTSYNC|TT$M_HOSTSYNC); X newmode[2] = oldmode[2] | TT2$M_PASTHRU; X status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, X newmode, sizeof(newmode), 0, 0, 0, 0); X if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) X exit(status); X term.t_nrow = (newmode[1]>>24) - 1; X term.t_ncol = newmode[0]>>16; X X#endif X#if CPM X#endif X X#if MSDOS & (HP150 == 0) & LATTICE X /* kill the ctrl-break interupt */ X rg.h.ah = 0x33; /* control-break check dos call */ X rg.h.al = 1; /* set the current state */ X rg.h.dl = 0; /* set it OFF */ X intdos(&rg, &rg); /* go for it! */ X#endif X X#if USG X ioctl(0, TCGETA, &otermio); /* save old settings */ X ntermio.c_iflag = 0; /* setup new settings */ X ntermio.c_oflag = 0; X ntermio.c_cflag = otermio.c_cflag; X ntermio.c_lflag = 0; X ntermio.c_line = otermio.c_line; X ntermio.c_cc[VMIN] = 1; X ntermio.c_cc[VTIME] = 0; X ioctl(0, TCSETA, &ntermio); /* and activate them */ X#endif X X#if V7 | BSD X gtty(0, &ostate); /* save old state */ X gtty(0, &nstate); /* get base of new state */ X nstate.sg_flags |= RAW; X nstate.sg_flags &= ~(ECHO|CRMOD); /* no echo for now... */ X stty(0, &nstate); /* set mode */ X ioctl(0, TIOCGETC, &otchars); /* Save old characters */ X ioctl(0, TIOCSETC, &ntchars); /* Place new character into K */ X#if BSD X /* provide a smaller terminal output buffer so that X the type ahead detection works better (more often) */ X setbuffer(stdout, &tobuf[0], TBUFSIZ); X signal(SIGTSTP,SIG_DFL); /* set signals so that we can */ X signal(SIGCONT,rtfrmshell); /* suspend & restart emacs */ X#endif X#endif X /* on all screens we are not sure of the initial position X of the cursor */ X ttrow = 999; X ttcol = 999; X} X X/* X * This function gets called just before we go back home to the command X * interpreter. On VMS it puts the terminal back in a reasonable state. X * Another no-operation on CPM. X */ Xttclose() X{ X#if AMIGA X amg_flush(); X Close(terminal); X#endif X#if VMS X int status; X int iosb[1]; X X ttflush(); X status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, X oldmode, sizeof(oldmode), 0, 0, 0, 0); X if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) X exit(status); X status = SYS$DASSGN(iochan); X if (status != SS$_NORMAL) X exit(status); X#endif X#if CPM X#endif X#if MSDOS & (HP150 == 0) & LATTICE X /* restore the ctrl-break interupt */ X rg.h.ah = 0x33; /* control-break check dos call */ X rg.h.al = 1; /* set the current state */ X rg.h.dl = 1; /* set it ON */ X intdos(&rg, &rg); /* go for it! */ X#endif X X#if USG X ioctl(0, TCSETA, &otermio); /* restore terminal settings */ X#endif X X#if V7 | BSD X stty(0, &ostate); X ioctl(0, TIOCSETC, &otchars); /* Place old character into K */ X#endif X} X X/* X * Write a character to the display. On VMS, terminal output is buffered, and X * we just put the characters in the big array, after checking for overflow. X * On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on X * MS-DOS (use the very very raw console output routine). X */ Xttputc(c) X#if AMIGA | (ST520 & MEGAMAX) X char c; X#endif X{ X#if AMIGA X scrn_tmp[scrn_tmp_p++] = c; X if(scrn_tmp_p>=AMG_MAXBUF) X amg_flush(); X#endif X#if ST520 & MEGAMAX X Bconout(2,c); X#endif X#if VMS X if (nobuf >= NOBUF) X ttflush(); X obuf[nobuf++] = c; X#endif X X#if CPM X bios(BCONOUT, c, 0); X#endif X X#if MSDOS & MWC86 X putcnb(c); X#endif X X#if MSDOS & (LATTICE | AZTEC) & ~IBMPC X bdos(6, c, 0); X#endif X X#if RAINBOW X Put_Char(c); /* fast video */ X#endif X X X#if V7 | USG | BSD X fputc(c, stdout); X#endif X} X X#if AMIGA Xamg_flush() X{ X if(scrn_tmp_p) X Write(terminal,scrn_tmp,scrn_tmp_p); X scrn_tmp_p = 0; X} X#endif X X/* X * Flush terminal buffer. Does real work where the terminal output is buffered X * up. A no-operation on systems where byte at a time terminal I/O is done. X */ Xttflush() X{ X#if AMIGA X amg_flush(); X#endif X#if VMS X int status; X int iosb[2]; X X status = SS$_NORMAL; X if (nobuf != 0) { X status = SYS$QIOW(EFN, iochan, IO$_WRITELBLK|IO$M_NOFORMAT, X iosb, 0, 0, obuf, nobuf, 0, 0, 0, 0); X if (status == SS$_NORMAL) X status = iosb[0] & 0xFFFF; X nobuf = 0; X } X return (status); X#endif X X#if CPM X#endif X X#if MSDOS X#endif X X#if V7 | USG | BSD X fflush(stdout); X#endif X} X X/* X * Read a character from the terminal, performing no editing and doing no echo X * at all. More complex in VMS that almost anyplace else, which figures. Very X * simple on CPM, because the system can do exactly what you want. X */ Xttgetc() X{ X#if AMIGA X char ch; X amg_flush(); X Read(terminal, &ch, 1L); X return(255 & (int)ch); X#endif X#if ST520 & MEGAMAX X long ch; X/* X * blink the cursor only if nothing is happening, this keeps the X * cursor on steadily during movement making it easier to track X */ X STcurblink(TRUE); /* the cursor blinks while we wait */ X ch = Bconin(2); X STcurblink(FALSE); /* the cursor is steady while we work */ X STscancode = (ch >> 16) & 0xff; X return(255 & (int)ch); X#endif X#if VMS X int status; X int iosb[2]; X int term[2]; X X while (ibufi >= nibuf) { X ibufi = 0; X term[0] = 0; X term[1] = 0; X status = SYS$QIOW(EFN, iochan, IO$_READLBLK|IO$M_TIMED, X iosb, 0, 0, ibuf, NIBUF, 0, term, 0, 0); X if (status != SS$_NORMAL) X exit(status); X status = iosb[0] & 0xFFFF; X if (status!=SS$_NORMAL && status!=SS$_TIMEOUT) X exit(status); X nibuf = (iosb[0]>>16) + (iosb[1]>>16); X if (nibuf == 0) { X status = SYS$QIOW(EFN, iochan, IO$_READLBLK, X iosb, 0, 0, ibuf, 1, 0, term, 0, 0); X if (status != SS$_NORMAL X || (status = (iosb[0]&0xFFFF)) != SS$_NORMAL) X exit(status); X nibuf = (iosb[0]>>16) + (iosb[1]>>16); X } X } X return (ibuf[ibufi++] & 0xFF); /* Allow multinational */ X#endif X X#if CPM X return (biosb(BCONIN, 0, 0)); X#endif X X#if RAINBOW X int Ch; X X while ((Ch = Read_Keyboard()) < 0); X X if ((Ch & Function_Key) == 0) X if (!((Ch & 0xFF) == 015 || (Ch & 0xFF) == 0177)) X Ch &= 0xFF; X X return Ch; X#endif X X#if MSDOS & MWC86 X return (getcnb()); X#endif X X#if MSDOS & (LATTICE | MSC | AZTEC) X int c; /* character read */ X X /* if a char already is ready, return it */ X if (nxtchar >= 0) { X c = nxtchar; X nxtchar = -1; X return(c); X } X X /* call the dos to get a char */ X rg.h.ah = 7; /* dos Direct Console Input call */ X intdos(&rg, &rg); X c = rg.h.al; /* grab the char */ X return(c & 255); X#endif X X#if V7 | USG | BSD X return(127 & fgetc(stdin)); X#endif X} X X#if TYPEAH & (~ST520 | ~LATTICE) X/* typahead: Check to see if any characters are already in the X keyboard buffer X*/ X Xtypahead() X X{ X#if MSDOS & (LATTICE | AZTEC | MWC86) X int c; /* character read */ X int flags; /* cpu flags from dos call */ X X#if MSC X if (kbhit() != 0) X return(TRUE); X else X return(FALSE); X#endif X X if (nxtchar >= 0) X return(TRUE); X X rg.h.ah = 6; /* Direct Console I/O call */ X rg.h.dl = 255; /* does console input */ X#if LATTICE | AZTEC X flags = intdos(&rg, &rg); X#else X intcall(&rg, &rg, 0x21); X flags = rg.x.flags; X#endif X c = rg.h.al; /* grab the character */ X X /* no character pending */ X if ((flags & 64) != 0) X return(FALSE); X X /* save the character and return true */ X nxtchar = c; X return(TRUE); X#endif X X#if BSD X int x; /* holds # of pending chars */ X X return((ioctl(0,FIONREAD,&x) < 0) ? 0 : x); X#else X return(FALSE); X#endif X} X#endif X E!O!F newsize=`wc -c < termio.c` if [ $newsize -ne 12610 ] then echo "File termio.c was $newsize bytes, 12610 expected" fi echo 'x - tipc.c (text)' sed << 'E!O!F' 's/^X//' > tipc.c X/* X * The routines in this file provide support for the TI-PC and other X * compatible terminals. It goes directly to the graphics RAM to do X * screen output. It compiles into nothing if not a TI-PC 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 TIPC X X#define NROW 25 /* 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#define SCADD 0xDE000L /* address of screen RAM */ X X#define CHAR_ENABLE 0x08 /* TI attribute to show char */ X#define TI_REVERSE 0x10 /* TI attribute to reverse char */ X#define BLACK 0+CHAR_ENABLE /* TI attribute for Black */ X#define BLUE 1+CHAR_ENABLE /* TI attribute for Blue */ X#define RED 2+CHAR_ENABLE /* TI attribute for Red */ X#define MAGENTA 3+CHAR_ENABLE /* TI attribute for Magenta */ X#define GREEN 4+CHAR_ENABLE /* TI attribute for Green */ X#define CYAN 5+CHAR_ENABLE /* TI attribute for Cyan */ X#define YELLOW 6+CHAR_ENABLE /* TI attribute for Yellow */ X#define WHITE 7+CHAR_ENABLE /* TI attribute for White */ X X Xextern int ttopen(); /* Forward references. */ Xextern int ttgetc(); Xextern int ttputc(); Xextern int ttflush(); Xextern int ttclose(); Xextern int timove(); Xextern int tieeol(); Xextern int tieeop(); Xextern int tibeep(); Xextern int tiopen(); Xextern int tirev(); Xextern int ticres(); Xextern int ticlose(); Xextern int tiputc(); X X#if COLOR Xextern int tifcol(); Xextern int tibcol(); X Xint cfcolor = -1; /* current forground color */ Xint cbcolor = -1; /* current background color */ Xint ctrans[] = /* ansi to ti color translation table */ X {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE}; 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 tiopen, X ticlose, X ttgetc, X tiputc, X ttflush, X timove, X tieeol, X tieeop, X tibeep, X tirev, X ticres X#if COLOR X , tifcol, X tibcol X#endif X}; X Xextern union REGS rg; X X#if COLOR Xsetatt( attr ) Xint attr; X{ X rg.h.ah = 0x16; /* set the forground character attribute */ X rg.h.bl = attr; X int86( 0x49, &rg, &rg ); X} X Xtifcol(color) /* set the current output color */ X Xint color; /* color to set */ X X{ X cfcolor = ctrans[color]; X setatt ( cfcolor ); X} X Xtibcol(color) /* set the current background color */ X Xint color; /* color to set */ X X{ X cbcolor = ctrans[color]; X} X#endif X Xtimove(row, col) X{ X rg.h.ah = 2; /* set cursor position function code */ X rg.h.dh = col; X rg.h.dl = row; X int86(0x49, &rg, &rg); X} X Xtieeol() /* erase to the end of the line */ X X{ 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 int86(0x49, &rg, &rg); X ccol = rg.h.dh; /* record current column */ X crow = rg.h.dl; /* and row */ X X rg.h.ah = 0x09; /* Write character at cursor position */ X rg.h.al = ' '; /* Space */ X rg.h.bl = cfcolor; X rg.x.cx = NCOL-ccol; /* Number of characters to write */ X int86(0x49, &rg, &rg); X X} X Xtiputc(ch) /* put a character at the current position in the X current colors */ X Xint ch; X X{ X rg.h.ah = 0x0E; /* write char to screen with current attrs */ X rg.h.al = ch; X int86(0x49, &rg, &rg); X} X Xtieeop() /* Actually a clear screen */ X{ X X rg.h.ah = 0x13; /* Clear Text Screen and Home Cursor */ X int86(0x49, &rg, &rg); X} X Xtirev(state) /* change reverse video state */ X Xint state; /* TRUE = reverse, FALSE = normal */ X X{ X setatt( state ? cbcolor : cfcolor ); X} X Xticres() /* change screen resolution */ X X{ X return(TRUE); X} X Xspal() /* change palette string */ X X{ X /* Does nothing here */ X} X Xtibeep() X{ X bdos(6, BEL, 0); X} X Xtiopen() X{ X strcpy(sres, "NORMAL"); X revexist = TRUE; X ttopen(); X} X Xticlose() X X{ X#if COLOR X tifcol(7); X tibcol(0); X#endif X ttclose(); X} X#else Xtihello() X{ X} X#endif X E!O!F newsize=`wc -c < tipc.c` if [ $newsize -ne 5308 ] then echo "File tipc.c was $newsize bytes, 5308 expected" fi echo 'x - vmsvt.c (text)' sed << 'E!O!F' 's/^X//' > vmsvt.c X/* X * VMS terminal handling routines X * X * Known types are: X * VT52, VT100, and UNKNOWN (which is defined to be an ADM3a) X * written by Curtis Smith X */ X X#include <stdio.h> X#include "estruct.h" X#include "edef.h" X X#if VMSVT X X#define termdef 1 /* don't define "term" external */ X X#include <ssdef.h> /* Status code definitions */ X#include <descrip.h> /* Descriptor structures */ X#include <iodef.h> /* IO commands */ X#include <ttdef.h> /* tty commands */ X Xextern int ttopen(); /* Forward references. */ Xextern int ttgetc(); Xextern int ttputc(); Xextern int ttflush(); Xextern int ttclose(); Xextern int vmsopen(); Xextern int vmskopen(); Xextern int vmskclose(); Xextern int vmseeol(); Xextern int vmseeop(); Xextern int vmsbeep(); Xextern int vmsmove(); Xextern int vmsrev(); Xextern int vmscres(); Xextern int eolexist; X#if COLOR Xextern int vmsfcol(); Xextern int vmsbcol(); X#endif X X#define NROWS 24 /* # of screen rolls */ X#define NCOLS 80 /* # of screen columns */ X#define MARGIN 8 /* size of minimim margin and */ X#define SCRSIZ 64 /* scroll size for extended lines */ X#define NPAUSE 100 /* # times thru update to pause */ X X/* X * Dispatch table. All the X * hard fields just point into the X * terminal I/O code. X */ XTERM term = { X NROWS - 1, X NROWS - 1, X NCOLS, X NCOLS, X MARGIN, X SCRSIZ, X NPAUSE, X &vmsopen, X &ttclose, X &vmskopen, X &vmskclose, X &ttgetc, X &ttputc, X &ttflush, X &vmsmove, X &vmseeol, X &vmseeop, X &vmsbeep, X &vmsrev, X &vmscres X#if COLOR X , &vmsfcol, X &vmsbcol X#endif X}; X Xchar * termeop; /* Erase to end of page string */ Xint eoppad; /* Number of pad characters after eop */ Xchar * termeol; /* Erase to end of line string */ Xint eolpad; /* Number of pad characters after eol */ Xchar termtype; /* Terminal type identifier */ X X X/******* X * ttputs - Send a string to ttputc X *******/ X Xttputs(string) Xchar * string; X{ X while (*string != '\0') X ttputc(*string++); X} X X X/******* X * vmspad - Pad the output after an escape sequence X *******/ X Xvmspad(count) Xint count; X{ X while (count-- > 0) X ttputc('\0'); X} X X X/******* X * vmsmove - Move the cursor X *******/ X Xvmsmove(row, col) X{ X switch (termtype) { X case TT$_UNKNOWN: X ttputc('\033'); X ttputc('='); X ttputc(row+' '); X ttputc(col+' '); X break; X case TT$_VT52: X ttputc('\033'); X ttputc('Y'); X ttputc(row+' '); X ttputc(col+' '); X break; X case TT$_VT100: /* I'm assuming that all these */ X case TT$_VT101: /* are a super set of the VT100 */ X case TT$_VT102: /* If I'm wrong, just remove */ X case TT$_VT105: /* those entries that aren't. */ X case TT$_VT125: X case TT$_VT131: X case TT$_VT132: X case TT$_VT200_SERIES: X { X char buffer[24]; X X sprintf(buffer, "\033[%d;%dH", row+1, col+1); X ttputs(buffer); X vmspad(50); X } X } X} X X/******* X * vmsrev - set the reverse video status X *******/ X Xvmsrev(status) X Xint status; /* TRUE = reverse video, FALSE = normal video */ X{ X switch (termtype) { X case TT$_UNKNOWN: X break; X case TT$_VT52: X break; X case TT$_VT100: X if (status) { X ttputc('\033'); X ttputc('['); X ttputc('7'); X ttputc('m'); X } else { X ttputc('\033'); X ttputc('['); X ttputc('m'); X } X break; X } X} X X/******* X * vmscres - Change screen resolution (which it doesn't) X *******/ X Xvmscres() X X{ X return(TRUE); X} X Xspal() /* change palette string */ X X{ X /* Does nothing here */ X} X X#if COLOR X/******* X * vmsfcol - Set the forground color (not implimented) X *******/ X Xvmsfcol() X{ X} X X/******* X * vmsbcol - Set the background color (not implimented) X *******/ X Xvmsbcol() X{ X} X#endif X X/******* X * vmseeol - Erase to end of line X *******/ X Xvmseeol() X{ X ttputs(termeol); X vmspad(eolpad); X} X X X/******* X * vmseeop - Erase to end of page (clear screen) X *******/ X Xvmseeop() X{ X ttputs(termeop); X vmspad(eoppad); X} X X X/******* X * vmsbeep - Ring the bell X *******/ X Xvmsbeep() X{ X ttputc('\007'); X} X X X/******* X * vmsopen - Get terminal type and open terminal X *******/ X Xvmsopen() X{ X termtype = vmsgtty(); X switch (termtype) { X case TT$_UNKNOWN: /* Assume ADM3a */ X eolexist = FALSE; X termeop = "\032"; X eoppad = 0; X break; X case TT$_VT52: X termeol = "\033K"; X eolpad = 0; X termeop = "\033H\033J"; X eoppad = 0; X break; X case TT$_VT100: X revexist = TRUE; X termeol = "\033[K"; X eolpad = 3; X termeop = "\033[;H\033[2J"; X eoppad = 50; X break; X default: X puts("Terminal type not supported"); X exit (SS$_NORMAL); X } X strcpy(sres, "NORMAL"); X ttopen(); X} X X Xstruct iosb { /* I/O status block */ X short i_cond; /* Condition value */ X short i_xfer; /* Transfer count */ X long i_info; /* Device information */ X}; X Xstruct termchar { /* Terminal characteristics */ X char t_class; /* Terminal class */ X char t_type; /* Terminal type */ X short t_width; /* Terminal width in characters */ X long t_mandl; /* Terminal's mode and length */ X long t_extend; /* Extended terminal characteristics */ X}; X X/******* X * vmsgtty - Get terminal type from system control block X *******/ X Xvmsgtty() X{ X short fd; X int status; X struct iosb iostatus; X struct termchar tc; X $DESCRIPTOR(devnam, "SYS$INPUT"); X X status = sys$assign(&devnam, &fd, 0, 0); X if (status != SS$_NORMAL) X exit (status); X X status = sys$qiow( /* Queue and wait */ X 0, /* Wait on event flag zero */ X fd, /* Channel to input terminal */ X IO$_SENSEMODE, /* Get current characteristic */ X &iostatus, /* Status after operation */ X 0, 0, /* No AST service */ X &tc, /* Terminal characteristics buf */ X sizeof(tc), /* Size of the buffer */ X 0, 0, 0, 0); /* P3-P6 unused */ X X /* De-assign the input device */ X if (sys$dassgn(fd) != SS$_NORMAL) X exit(status); X X if (status != SS$_NORMAL) /* Jump out if bad status */ X exit(status); X if (iostatus.i_cond != SS$_NORMAL) X exit(iostatus.i_cond); X X return tc.t_type; /* Return terminal type */ X} X Xvmskopen() X X{ X} X Xvmskclose() 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 X Xhellovms() X X{ X} X X#endif VMSVT E!O!F newsize=`wc -c < vmsvt.c` if [ $newsize -ne 6398 ] then echo "File vmsvt.c was $newsize bytes, 6398 expected" fi echo 'x - vt52.c (text)' sed << 'E!O!F' 's/^X//' > vt52.c X/* X * The routines in this file X * provide support for VT52 style terminals X * over a serial line. The serial I/O services are X * provided by routines in "termio.c". It compiles X * into nothing if not a VT52 style device. The X * bell on the VT52 is terrible, so the "beep" X * routine is conditionalized on defining BEL. 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 VT52 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 100 /* # times thru update to pause */ X#define BIAS 0x20 /* Origin 0 coordinate bias. */ X#define ESC 0x1B /* ESC character. */ X#define BEL 0x07 /* ascii bell character */ X Xextern int ttopen(); /* Forward references. */ Xextern int ttgetc(); Xextern int ttputc(); Xextern int ttflush(); Xextern int ttclose(); Xextern int vt52move(); Xextern int vt52eeol(); Xextern int vt52eeop(); Xextern int vt52beep(); Xextern int vt52open(); Xextern int vt52rev(); Xextern int vt52cres(); Xextern int vt52kopen(); Xextern int vt52kclose(); X X#if COLOR Xextern int vt52fcol(); Xextern int vt52bcol(); X#endif X X/* X * Dispatch table. All the X * hard fields just point into the X * terminal I/O code. X */ XTERM term = { X NROW-1, X NROW-1, X NCOL, X NCOL, X MARGIN, X SCRSIZ, X NPAUSE, X &vt52open, X &ttclose, X &vt52kopen, X &vt52kclose, X &ttgetc, X &ttputc, X &ttflush, X &vt52move, X &vt52eeol, X &vt52eeop, X &vt52beep, X &vt52rev, X &vt52cres X#if COLOR X , &vt52fcol, X &vt52bcol X#endif X}; X Xvt52move(row, col) X{ X ttputc(ESC); X ttputc('Y'); X ttputc(row+BIAS); X ttputc(col+BIAS); X} X Xvt52eeol() X{ X ttputc(ESC); X ttputc('K'); X} X Xvt52eeop() X{ X ttputc(ESC); X ttputc('J'); X} X Xvt52rev(status) /* set the reverse video state */ X Xint status; /* TRUE = reverse video, FALSE = normal video */ X X{ X /* can't do this here, so we won't */ X} X Xvt52cres() /* change screen resolution - (not here though) */ X X{ X return(TRUE); X} X Xspal() /* change palette string */ X X{ X /* Does nothing here */ X} X X#if COLOR Xvt52fcol() /* set the forground color [NOT IMPLIMENTED] */ X{ X} X Xvt52bcol() /* set the background color [NOT IMPLIMENTED] */ X{ X} X#endif X Xvt52beep() X{ X#ifdef BEL X ttputc(BEL); X ttflush(); X#endif X} X Xvt52open() X{ X#if V7 | BSD X register char *cp; X char *getenv(); X X if ((cp = getenv("TERM")) == NULL) { X puts("Shell variable TERM not defined!"); X exit(1); X } X if (strcmp(cp, "vt52") != 0 && strcmp(cp, "z19") != 0) { X puts("Terminal type not 'vt52'or 'z19' !"); X exit(1); X } X#endif X ttopen(); X} X Xvt52kopen() X X{ X} X Xvt52kclose() X 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 X Xvt52hello() X X{ X} X X#endif E!O!F newsize=`wc -c < vt52.c` if [ $newsize -ne 3386 ] then echo "File vt52.c was $newsize bytes, 3386 expected" fi bill davidsen (wedu@ge-crd.arpa) {chinet | philabs | sesimo}!steinmetz!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me