phillip@cbmvax.UUCP (07/18/87)
Since I received so many requests I decided to post the MicroEMACS 38i
enhancements for the AMIGA.
Whoops! One important note. Modify constants "NROW" and "NCOL" in ANSI.C
to 50 and 80 respectively. This will set-up the MAX screen size...I set
up the current screen size in ttopen().
-phil
-----------------------cut here
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# amymakefile
# amytermio.c
# amyconsole.c
# This archive created: Sat Jul 11 15:26:37 1987
export PATH; PATH=/bin:$PATH
echo shar: extracting "'amymakefile'" '(1408 characters)'
if test -f 'amymakefile'
then
echo shar: will not over-write existing file "'amymakefile'"
else
sed 's/^ X//' << \SHAR_EOF > 'amymakefile'
X# Makefile for Amiga MicroEMACS V38i
X# Added some flexability to the dependency of the header files. P. LINDSAY
X
X# need these flags so Aztec will be happy
XCFLAGS= +l -Z12000
X
XHFILES = estruct.h edef.h
XHBINDFUNC = efunc.h ebind.h
XHEPATH = epath.h
XHEVAR = evar.h
X
XOEPATH = bind.o
XOEBINDEFUNC = main.o
XOEVAR = eval.o
X
XOFILES= ansi.o basic.o $(OEPATH) buffer.o crypt.o dg10.o \
X display.o $(OEVAR) exec.o file.o fileio.o \
X hp110.o hp150.o ibmpc.o input.o isearch.o line.o \
X lock.o $(OEBINDEFUNC) random.o region.o search.o spawn.o \
X st520.o tcap.o termio.o console.o tipc.o vmsvt.o vt52.o \
X window.o word.o z309.o
X
XOFILES1= ansi.o basic.o buffer.o crypt.o dg10.o \
X display.o exec.o file.o fileio.o \
X hp110.o hp150.o ibmpc.o input.o isearch.o line.o \
X lock.o random.o region.o search.o spawn.o \
X st520.o tcap.o termio.o console.o tipc.o vmsvt.o vt52.o \
X window.o word.o z309.o
X
XCFILES= ansi.c basic.c bind.c buffer.c crypt.c dg10.c \
X display.c eval.c exec.c file.c fileio.c \
X hp110.c hp150.c ibmpc.c input.c isearch.c line.c \
X lock.c main.c random.c region.c search.c spawn.c \
X st520.c tcap.c termio.c console.c tipc.c vmsvt.c vt52.c \
X window.c word.c z309.c
X
Xemacs: $(OFILES)
X ln $(OFILES) -o emacs -lc32
X
X$(OEPATH): $(HFILES) $(HEPATH)
X
X$(OEBINDEFUNC): $(HFILES) $(HBINDFUNC)
X
X$(OEVAR): $(HFILES) $(HEVAR)
X
X$(OFILES1): $(HFILES)
X
SHAR_EOF
echo shar: a missing newline was added to "'amymakefile'"
if test 1408 -ne "`wc -c < 'amymakefile'`"
then
echo shar: error transmitting "'amymakefile'" '(should have been 1408 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'amytermio.c'" '(16896 characters)'
if test -f 'amytermio.c'
then
echo shar: will not over-write existing file "'amytermio.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'amytermio.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#undef TRUE
X#undef FALSE
X#include <exec/types.h>
X#include <exec/nodes.h>
X#include <exec/lists.h>
X#include <exec/tasks.h>
X#include <exec/ports.h>
X#include <exec/io.h>
X#include <devices/console.h>
X#include <devices/conunit.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X#include <graphics/clip.h>
X#include <graphics/view.h>
X#include <graphics/rastport.h>
X#include <graphics/layers.h>
X#include <graphics/text.h>
X#include <intuition/intuition.h>
X
X#define CSI 0x9b
X#define AMG_MAXBUF 4608L /* worst case size */
X
Xextern struct IntuitionBase *IntuitionBase; /* library bases */
Xextern struct GfxBase *GfxBase;
Xextern struct Window *EmacsWindow; /* Our window */
Xextern struct MsgPort *consoleport; /* I/O port */
Xextern struct IOStdReq *consoleWriteMsg; /* I/O messages */
Xextern struct IOStdReq *consoleReadMsg;
Xextern struct Window *savewindow;
X
Xextern char *itoa(); /* we decide the */
Xextern LONG newsize(); /* the screen size */
Xextern LONG newwidth(); /* a startup */
Xextern VOID CursorOn(), /* these guys help */
X CursorOff(); /* speed up screen */
X /* writes */
X
Xextern VOID *OpenLibrary();
Xextern LONG OpenConsole();
Xextern struct Task *FindTask();
Xextern struct Window *InitWindow();
Xextern struct MsgPort *CreatePort();
Xextern struct IOStdReq *CreateStdIO();
Xextern UWORD getrows(); /* determine number */
Xextern UWORD getcols(); /* of rows and cols */
X /* available */
X
Xextern LONG Enable_Abort; /* Do NOT allow abort! */
Xextern VOID cleanup();
X
X/*
X storage for pernament real estate...
X*/
X
Xstatic char scrtitle[81];
Xstatic char scrn_tmp[AMG_MAXBUF+1];
Xstatic LONG scrn_tmp_p = 0L;
X
X#endif
X
X#if ST520
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
X register struct ConUnit *conunit;
X register UWORD count;
X struct Process *myproc;
X UWORD rows,cols;
X
X Enable_Abort = 0L; /* Disable ^C */
X
X GfxBase = (struct GfxBase *)
X OpenLibrary("graphics.library", (LONG) 0);
X if (!GfxBase) /* Graphics lib */
X cleanup();
X
X IntuitionBase = (struct IntuitionBase *) /* Intuition */
X OpenLibrary("intuition.library", (LONG) 0);
X
X if (!IntuitionBase)
X cleanup();
X
X strcpy(scrtitle,"MicroEMACS ");
X strcat(scrtitle,VERSION);
X
X EmacsWindow = InitWindow(-1,0,0,0,scrtitle);
X if (!EmacsWindow)
X cleanup();
X
X /* Port for reading and writing */
X consoleport = CreatePort("emacs.con.port",0L);
X if (!consoleport)
X cleanup();
X
X consoleWriteMsg = CreateStdIO(consoleport);
X if (!consoleWriteMsg)
X cleanup();
X
X consoleReadMsg = CreateStdIO(consoleport);
X if (!consoleReadMsg)
X cleanup();
X
X /* attach the console device to our window */
X if ((OpenConsole(consoleWriteMsg,consoleReadMsg,EmacsWindow)))
X cleanup();
X
X /* Make AmigaDOS requesters appear in our screen */
X /* "cleanup()" will restore previous value */
X
X myproc = (struct Process *) FindTask(0L);
X Forbid();
X savewindow = (struct Window *) myproc->pr_WindowPtr;
X myproc->pr_WindowPtr = (APTR) EmacsWindow;
X Permit();
X
X /* Set-up window size for EMACS and console.device... */
X
X conunit = (struct ConUnit *) consoleReadMsg->io_Unit;
X
X rows = getrows(conunit->cu_Window,conunit->cu_Font);
X cols = getcols(conunit->cu_Window,conunit->cu_Font);
X
X term.t_mrow = term.t_nrow = rows-1;
X term.t_mcol = term.t_ncol = cols;
X
X newsize(TRUE, rows );
X newwidth(TRUE, cols );
X
X /* set top offset */
X ttputc(CSI);
X ttputc('0');
X ttputc('y');
X
X /* set page length */
X ttputc(CSI);
X ttputstr(itoa( rows ));
X ttputc('t');
X
X /* set left offset */
X ttputc(CSI);
X ttputc('0');
X ttputc('x');
X
X /* set line length */
X ttputc(CSI);
X ttputstr(itoa( cols ));
X ttputc('u');
X
X /* clear screen */
X ttputc(0x0c);
X
X /* flush output buffer */
X ttflush();
X
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 cleanup();
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
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
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 /* speed up screen writes by turning off the cursor */
X
X if(scrn_tmp_p)
X {
X CursorOff(consoleWriteMsg);
X ConWrite(consoleWriteMsg,scrn_tmp,scrn_tmp_p);
X CursorOn(consoleWriteMsg);
X }
X scrn_tmp_p = 0L;
X}
X
X
Xttputstr(a_str)
Xchar *a_str;
X{
X while(*a_str) ttputc(*a_str++);
X}
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 GetChar(consoleReadMsg,&ch);
X return( 255 & (int) ch);
X#endif
X#if ST520
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
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#endif
X return(FALSE);
X}
X#endif
X
X
SHAR_EOF
echo shar: a missing newline was added to "'amytermio.c'"
if test 16896 -ne "`wc -c < 'amytermio.c'`"
then
echo shar: error transmitting "'amytermio.c'" '(should have been 16896 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'amyconsole.c'" '(9088 characters)'
if test -f 'amyconsole.c'
then
echo shar: will not over-write existing file "'amyconsole.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'amyconsole.c'
X/*
X * Misc. console.device/window functions
X *
X * Feel free to use this code anywhere you please...Just keep
X * "this" information in the source.
X * Phillip Lindsay
X */
X
X#include <stdio.h>
X#include "estruct.h"
X#include "edef.h"
X
X#if AMIGA
X#undef TRUE
X#undef FALSE
X#include <exec/types.h>
X#include <exec/nodes.h>
X#include <exec/lists.h>
X#include <exec/tasks.h>
X#include <exec/ports.h>
X#include <exec/io.h>
X#include <devices/console.h>
X#include <devices/conunit.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X#include <graphics/clip.h>
X#include <graphics/view.h>
X#include <graphics/rastport.h>
X#include <graphics/layers.h>
X#include <graphics/text.h>
X#include <intuition/intuition.h>
X
XLONG OpenConsole();
XVOID cleanup();
Xextern struct Screen *OpenScreen();
Xextern struct Window *OpenWindow();
Xextern struct MsgPort *CreatePort();
Xextern struct IOStdReq *CreateStdIO();
Xextern LONG OpenDevice();
Xextern struct Task *FindTask();
Xextern LONG DoIO();
X
X#define CONSOLENAME "console.device"
X
X#define WINFLAGS1 WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH
X#define WINFLAGS2 SMART_REFRESH | ACTIVATE | NOCAREREFRESH
X#define WINFLAGS (WINFLAGS1 | WINFLAGS2)
X
X#define SCRWINFLAGS1 BORDERLESS | BACKDROP | NOCAREREFRESH | ACTIVATE
X#define SCRWINFLAGS SCRWINFLAGS1 | SMART_REFRESH
X
X/*
X * Intuition global variables
X */
X
Xstruct TextAttr SafeFont =
X {
X (UBYTE *)"topaz.font",
X TOPAZ_EIGHTY,
X 0,
X FS_NORMAL
X };
X
Xstruct IntuitionBase *IntuitionBase=NULL; /* library bases */
Xstruct GfxBase *GfxBase=NULL;
X/* struct DiskfontBase *DiskfontBase=NULL; */
Xstruct Window *EmacsWindow=NULL; /* Our window */
Xstruct MsgPort *consoleport=NULL; /* I/O port */
Xstruct IOStdReq *consoleWriteMsg=NULL; /* I/O messages */
Xstruct IOStdReq *consoleReadMsg=NULL;
Xstruct Window *savewindow=-1L;
X
Xchar screenkey[] = "EmacsScreen";
X
X/*
X * Open a console device, given a read request
X * and a write request message.
X */
X
XLONG OpenConsole(writerequest,readrequest,window)
Xstruct IOStdReq *writerequest;
Xstruct IOStdReq *readrequest;
Xstruct Window *window;
X{
X LONG error;
X writerequest->io_Data = (APTR) window;
X writerequest->io_Length = (ULONG) sizeof(*window);
X error = OpenDevice(CONSOLENAME, 0L, writerequest, 0L);
X
X /* clone required parts of the request */
X readrequest->io_Device = writerequest->io_Device;
X readrequest->io_Unit = writerequest->io_Unit;
X return( (LONG) error);
X}
X
X/*
X * Output a single character
X * to a specified console
X */
X
XLONG ConPutChar(request,character)
Xstruct IOStdReq *request;
Xchar character;
X{
X request->io_Command = CMD_WRITE;
X request->io_Data = (APTR)&character;
X request->io_Length = (ULONG)1;
X return( (LONG) DoIO(request) );
X}
X
X/*
X * Output a NULL-terminated string of
X * characters to a console
X */
X
XLONG ConPutStr(request,string)
Xstruct IOStdReq *request;
Xchar *string;
X{
X request->io_Command = CMD_WRITE;
X request->io_Data = (APTR)string;
X request->io_Length = (LONG)-1;
X return( (LONG) DoIO(request) );
X}
X
X/*
X * Write out a string of predetermined
X * length to the console
X */
X
XLONG ConWrite(request,string,len)
Xstruct IOStdReq *request;
Xchar *string;
XLONG len;
X{
X request->io_Command = CMD_WRITE;
X request->io_Data = (APTR)string;
X request->io_Length = (ULONG)len;
X return( (LONG) DoIO(request) );
X}
X
X/*
X * read a character.
X */
X
XLONG GetChar(request,whereto)
Xstruct IOStdReq *request;
Xchar *whereto;
X{
X request->io_Command = CMD_READ;
X request->io_Data = (APTR)whereto;
X request->io_Length = (LONG)1;
X return((LONG)DoIO(request));
X}
X
XVOID CursorOff(request)
Xstruct IOStdReq *request;
X{
X register struct IOStdReq *req=request;
X
X req->io_Command = CMD_WRITE;
X req->io_Data = (APTR) "\X9B0 p";
X req->io_Length = -1L;
X DoIO(req);
X}
X
XVOID CursorOn(request)
Xstruct IOStdReq *request;
X{
X register struct IOStdReq *req=request;
X
X req->io_Command = CMD_WRITE;
X req->io_Data = (APTR) "\X9B p";
X req->io_Length = -1L;
X DoIO(req);
X}
X
X/*
X * memfill() - fill memory with supplied byte value for "size" bytes
X */
Xvoid memfill(source,size,value)
XUBYTE *source;
XULONG size;
XUBYTE value;
X{
X register UBYTE *msource=source,
X mvalue=value,
X *mend = &source[size];
X
X while( msource < mend ) *msource++ = mvalue;
X
X}
X
XLONG screendefaults(width,height,modes)
XSHORT *width, *height;
XUWORD *modes;
X{
X struct Screen wbscreen;
X
X if(!(GetScreenData(&wbscreen,(ULONG)sizeof(struct Screen),WBENCHSCREEN,0L)))
X return( (LONG) FALSE);
X
X *width = wbscreen.Width;
X *height = wbscreen.Height;
X *modes = wbscreen.ViewPort.Modes;
X
X return( (LONG) TRUE);
X}
X
Xstruct Screen *InitScreen(title,width,height,modes)
XUBYTE *title;
XSHORT width,height;
XUWORD modes;
X{
X struct NewScreen newscreen;
X
X memfill(&newscreen,(ULONG)sizeof(struct NewScreen),0L);
X
X#ifdef DEBUG
X kprintf("Opening Screen..w:%d h:%d m:%d\n",width,height,modes);
X#endif
X
X newscreen.Width = width;
X newscreen.Height = height;
X newscreen.Depth = 1;
X newscreen.BlockPen = 1;
X newscreen.ViewModes = modes;
X newscreen.Type = CUSTOMSCREEN;
X newscreen.Font = &SafeFont;
X newscreen.DefaultTitle = title;
X
X return((struct Screen *)OpenScreen(&newscreen));
X}
X
X/*
X Basically this function opens a window, but depending on what is
X passed as arguments a window will be opened in their own screen.
X winx = -1, opens a window on a workbench size/mode screen
X winx = -1, winy = -1
X opens a window on a interlace screen based on workbench screen
X*/
Xstruct Window *InitWindow(winx,winy,wwidth,wheight,title)
XWORD winx,winy,wwidth,wheight;
XUBYTE *title;
X{
X struct NewWindow newwindow;
X SHORT width,height;
X UWORD modes;
X
X if(!(screendefaults(&width,&height,&modes)))
X return( (struct Window *) 0L);
X
X#ifdef DEBUG
Xkprintf("InitWindow: x=%d,y=%d,wx=%d,wy=%d,title=%s\n",
X winx,winy,wwidth,wheight,title);
X#endif
X
X memfill(&newwindow,(ULONG)sizeof(struct NewWindow),0L);
X if(winx == -1)
X {
X if(winy == -1 && !(modes & LACE))
X {
X modes |= LACE; /* here we make a magic assumption */
X height *= 2;
X }
X if(!(newwindow.Screen = InitScreen(title,width,height,modes)))
X return( (struct Window *) 0L);
X
X ShowTitle(newwindow.Screen,(LONG) FALSE);
X newwindow.Screen->UserData = (UBYTE *) screenkey;
X winx = 0;
X winy = (SHORT) newwindow.Screen->BarHeight;
X wwidth = width;
X wheight = height - newwindow.Screen->BarHeight;
X newwindow.Type = CUSTOMSCREEN;
X newwindow.Flags = SCRWINFLAGS;
X title = NULL; /* so we don't get a title in window */
X }
X
X newwindow.LeftEdge = winx;
X newwindow.TopEdge = winy;
X newwindow.Width = (!wwidth ? width : wwidth);
X newwindow.Height = (!wheight ? height : wheight);
X newwindow.DetailPen = -1L;
X newwindow.BlockPen = -1L;
X
X if(newwindow.Type != CUSTOMSCREEN)
X {
X newwindow.Title = title;
X newwindow.Flags = WINFLAGS;
X newwindow.MinWidth = 71L;
X newwindow.MinHeight = 22L;
X newwindow.MaxWidth = -1L;
X newwindow.MaxHeight = -1L;
X newwindow.Type = WBENCHSCREEN;
X }
X
X return((struct Window *)OpenWindow(&newwindow));
X
X}
X
X/*
X this function close a window and if the window is attached to a
X screen "we opened" that screen will also be closed
X*/
X
Xvoid CloseScrWin(win)
Xstruct Window *win;
X{
X struct Screen *scr;
X
X scr = win->WScreen;
X
X CloseWindow(win);
X
X/* make sure this is OUR screen */
X if(((scr->Flags & SCREENTYPE) != WBENCHSCREEN) &&
X !(strcmp(scr->UserData,screenkey)))
X CloseScreen(scr);
X}
X
X/*
X This function determines the number of rows/cols available on a given
X window. If the window type becomes more complicated these routines
X might need some additional logic. (ie. worry about borders and such )
X*/
X
XUWORD getrows(Win,Font)
Xstruct Window *Win;
Xstruct TextFont *Font;
X{
X register struct TextFont *font=Font;
X register struct Window *win=Win;
X
X return( (UWORD) win->Height/font->tf_YSize);
X}
X
XUWORD getcols(Win,Font)
Xstruct Window *Win;
Xstruct TextFont *Font;
X{
X register struct TextFont *font=Font;
X register struct Window *win=Win;
X
X return( (UWORD) win->Width/font->tf_XSize);
X}
X
X/*
X here is the Amiga specific cleanup code for MicroEMACS.
X*/
X
Xvoid cleanup()
X{
X struct Process *myproc;
X
X if(savewindow != -1L)
X {
X myproc = (struct Process *) FindTask(0L);
X Forbid();
X myproc->pr_WindowPtr = (APTR) savewindow;
X Permit();
X }
X if(consoleReadMsg)
X {
X if(consoleReadMsg->io_Device)
X CloseDevice(consoleReadMsg);
X DeleteStdIO(consoleReadMsg);
X }
X if(consoleWriteMsg) DeleteStdIO(consoleWriteMsg);
X if(consoleport) DeletePort(consoleport);
X if(EmacsWindow) CloseScrWin(EmacsWindow);
X if(GfxBase) CloseLibrary(GfxBase);
X if(IntuitionBase) CloseLibrary(IntuitionBase);
X
X}
X
X/* end of console.c */
X#endif
X
SHAR_EOF
echo shar: a missing newline was added to "'amyconsole.c'"
if test 9088 -ne "`wc -c < 'amyconsole.c'`"
then
echo shar: error transmitting "'amyconsole.c'" '(should have been 9088 characters)'
fi
fi # end of overwriting check
# End of shell archive
exit 0