Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!amdcad!lll-crg!caip!daemon From: BM17@CMCCTD@caip.RUTGERS.EDU Newsgroups: net.micro.amiga Subject: Terminal emulator Message-ID: <1383@caip.RUTGERS.EDU> Date: Tue, 25-Feb-86 23:24:13 EST Article-I.D.: caip.1383 Posted: Tue Feb 25 23:24:13 1986 Date-Received: Fri, 28-Feb-86 21:33:04 EST Sender: daemon@caip.RUTGERS.EDU Organization: Rutgers Univ., New Brunswick, N.J. Lines: 796 From: Micom Marv I am posting this for a friend... ----------------------------------------------------------------------- 25-Feb-86 00:08:46-EST,22841;000000000001 Return-Path: Received: from A.PSY.CMU.EDU by TD.CC.CMU.EDU with TCP; Tue 25 Feb 86 00:07:13-EST Date: Monday, 24 Feb 86 23:44:41 EST From: mcinerny (michael mcinerny) @ a.psy.cmu.edu Subject: PDTERM.AR To: bm17 @ td.cc.cmu.edu, ew1k @ tf.cc.cmu.edu -h- console.c 2976:1373:832 console.c #include "term.h" /* These functions are taken directly from the console.device chapter * in the Amiga V1.1 ROM KERNEL manual. See manual for documentation. */ /* Open a console device */ int OpenConsole(writerequest,readrequest,window) struct IOStdReq *writerequest; struct IOStdReq *readrequest; struct Window *window; { int error; writerequest->io_Data = (APTR) window; writerequest->io_Length = sizeof(*window); error = OpenDevice("console.device", 0, writerequest, 0); readrequest->io_Device = writerequest->io_Device; readrequest->io_Unit = writerequest->io_Unit; /* clone required parts of the request */ return(error); } /* Output a single character to a specified console */ int ConPutChar(request,character) struct IOStdReq *request; char character; { request->io_Command = CMD_WRITE; request->io_Data = (APTR)&character; request->io_Length = 1; DoIO(request); return(0); } /* Output a NULL-terminated string of characters to a console */ int ConPutStr(request,string) struct IOStdReq *request; char *string; { request->io_Command = CMD_WRITE; request->io_Data = (APTR)string; request->io_Length = -1; DoIO(request); return(0); } /* queue up a read request to a console */ int QueueRead(request,whereto) struct IOStdReq *request; char *whereto; { request->io_Command = CMD_READ; request->io_Data = (APTR)whereto; request->io_Length = 1; SendIO(request); return(0); } -h- makefile 2976:1373:832 makefile # MakeFile for Terminal Program CC = cc #CFLAGS = -O -DDBUG CFLAGS = -O #LIBS = -ldbug LIBS = CDISK = C-DEVEL: ALINK = $(CDISK)c/alink ALOBJ = $(CDISK)lib/Astartup.obj ALIBS = $(CDISK)lib/amiga.lib+$(CDISK)lib/lc.lib H = term.h FILES = $H terminal.c serial.c console.c menus.c OBJS = terminal.o serial.o console.o menus.o PDOBJS = terminal.o+serial.o+console.o+menus.o terminal : $(OBJS) $(CC) -o terminal $(OBJS) $(LIBS) terminal.o : terminal.c $H $(CC) $(CFLAGS) -c terminal.c serial.o : serial.c $H $(CC) $(CFLAGS) -c serial.c console.o : console.c $H $(CC) $(CFLAGS) -c console.c menus.o : menus.c $H $(CC) $(CFLAGS) -c menus.c pdterm : $(ALINK) FROM $(ALOBJ)+$(PDOBJS) TO pdterm LIBRARY $(ALIBS) print : copy EpsonSmall PAR: run copy terminal.c PAR: printall : run join EpsonSmall $(FILES) AS PAR: ar : ar -uv pdterm.ar makefile $(FILES) -h- menus.c 2976:1373:832 menus.c #include "term.h" /* Dynamic Intuition Text functions */ struct IntuiText *NewIText(text, left, top) char *text; int left, top; { struct IntuiText *newtext = NULL; newtext = (struct IntuiText *)AllocMem(sizeof(*newtext), MEMF_PUBLIC | MEMF_CLEAR); newtext->IText = (UBYTE *)text; newtext->FrontPen = 0; newtext->BackPen = 1; newtext->DrawMode = JAM2; newtext->LeftEdge = left; newtext->TopEdge = top; newtext->ITextFont = NULL; newtext->NextText = NULL; return(newtext); } struct IntuiText *AddIText(IText, text) struct IntuiText *IText; char *text; { struct IntuiText *newtext = NULL; newtext = (struct IntuiText *)AllocMem(sizeof(*newtext), MEMF_PUBLIC | MEMF_CLEAR); newtext->IText = (UBYTE *)text; newtext->FrontPen = IText->FrontPen; newtext->BackPen = IText->BackPen; newtext->DrawMode = IText->DrawMode; newtext->LeftEdge = IText->LeftEdge; newtext->TopEdge = IText->TopEdge + 11; newtext->ITextFont = IText->ITextFont; newtext->NextText = NULL; IText->NextText = newtext; return(newtext); } DisposeIText(IText) struct IntuiText *IText; { struct IntuiText *current, *next; current = IText; for(next = current->NextText; current != NULL; next = next->NextText){ FreeMem(current,sizeof(*current)); current = next; } } /* Dynamic Menu Constructor Functions */ #define InterMenuWidth 15 struct Menu *NewMenu(menuname, width, height) char *menuname; int width, height; { struct Menu *menu = NULL; menu = (struct Menu *)AllocMem(sizeof(*menu), MEMF_PUBLIC | MEMF_CLEAR); menu->NextMenu = NULL; menu->LeftEdge = 0; menu->TopEdge = 0; menu->Width = width; menu->Height = height; menu->Flags = MENUENABLED; menu->MenuName = menuname; menu->FirstItem = NULL; return(menu); } struct Menu *AddMenu(menus, MenuName, width, height) struct Menu *menus; char *MenuName; int width, height; { struct Menu *newmenu; newmenu = NewMenu(MenuName, width, height); newmenu->LeftEdge = menus->LeftEdge + menus->Width + InterMenuWidth; menus->NextMenu = newmenu; return(newmenu); } struct MenuItem *NewMenuItem(name, width, height) char *name; int width, height; { struct MenuItem *newitem = NULL; struct IntuiText *NewIText(), *newtext = NULL; newitem = (struct MenuItem *)AllocMem(sizeof(*newitem), MEMF_PUBLIC | MEMF_CLEAR); newtext = NewIText(name,0,1); newitem->NextItem = NULL; newitem->ItemFill = (APTR) newtext; newitem->LeftEdge = 0; newitem->TopEdge = 0; newitem->Width = width; newitem->Height = height; newitem->Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP; newitem->MutualExclude = 0; newitem->SelectFill = NULL; newitem->Command = 0; newitem->SubItem = NULL; newitem->NextSelect = 0; return(newitem); } struct MenuItem *AddNewMenuItem(menu, name, width, height) struct Menu *menu; char *name; int width, height; { struct MenuItem *newitem, *NewMenuItem(); newitem = NewMenuItem(name, width, height); menu->FirstItem = newitem; return(newitem); } struct MenuItem *AddItem(items, name) struct MenuItem *items; char *name; { struct MenuItem *newitem, *NewMenuItem(); newitem = NewMenuItem(name, items->Width, items->Height); newitem->TopEdge = items->TopEdge + items->Height; newitem->LeftEdge = items->LeftEdge; items->NextItem = newitem; return(newitem); } struct MenuItem *AddNewSubItem(item, name, width, height) struct MenuItem *item; char *name; int width, height; { struct MenuItem *newitem, *NewMenuItem(); newitem = NewMenuItem(name, width, height); item->SubItem = newitem; newitem->LeftEdge = item->Width; return(newitem); } DisposeItem(item) struct MenuItem *item; { DisposeIText((struct ItuiText *)item->ItemFill); FreeMem(item,sizeof(*item)); } DisposeItems(items) struct MenuItem *items; { struct MenuItem *current, *next; current = items; for(next = current->NextItem; current != NULL; next = next->NextItem){ DisposeItem(current); current = next; } } DisposeMenu(menu) struct Menu *menu; { DisposeItems(menu->FirstItem); FreeMem(menu,sizeof(*menu)); } DisposeMenus(menus) struct Menu *menus; { struct Menu *current, *next; current = menus; for(next = current->NextMenu; current != NULL; next = next->NextMenu){ DisposeMenu(current); current = next; } } -h- serial.c 2976:1373:832 serial.c #include "term.h" /* Open a serial device */ int OpenSerial(readrequest,writerequest) struct IOExtSer *readrequest; struct IOExtSer *writerequest; { int error; readrequest->io_SerFlags = NULL; error = OpenDevice(SERIALNAME, NULL, readrequest, NULL); writerequest->IOSer.io_Device = readrequest->IOSer.io_Device; writerequest->IOSer.io_Unit = readrequest->IOSer.io_Unit; writerequest->io_CtlChar = readrequest->io_CtlChar; writerequest->io_ReadLen = readrequest->io_ReadLen; writerequest->io_BrkTime = readrequest->io_BrkTime; writerequest->io_Baud = readrequest->io_Baud; writerequest->io_WriteLen = readrequest->io_WriteLen; writerequest->io_StopBits = readrequest->io_StopBits; writerequest->io_RBufLen = readrequest->io_RBufLen; writerequest->io_SerFlags = readrequest->io_SerFlags; writerequest->io_TermArray.TermArray0 = readrequest->io_TermArray.TermArray0; writerequest->io_TermArray.TermArray1 = readrequest->io_TermArray.TermArray1; /* clone required parts of the request */ return(error); } int SerPutChar(request,character) struct IOExtSer *request; char character; { request->IOSer.io_Command = CMD_WRITE; request->IOSer.io_Data = (APTR)&character; request->IOSer.io_Length = 1; DoIO(request); return(0); } int QueueSerRead(request, whereto) struct IOExtSer *request; char *whereto; { request->IOSer.io_Command = CMD_READ; request->IOSer.io_Data = (APTR)whereto; request->IOSer.io_Length = 1; SendIO(request); return(0); } int SetParams(io,rbuf_len,rlen,wlen,brk,baud,sf,ta0,ta1) struct IOExtSer *io; unsigned long rbuf_len; unsigned char rlen; unsigned char wlen; unsigned long brk; unsigned long baud; unsigned char sf; unsigned long ta0; unsigned long ta1; { io->io_ReadLen = rlen; io->io_WriteLen = wlen; io->io_Baud = baud; io->io_BrkTime = brk; io->io_StopBits = 0x01; io->io_RBufLen = rbuf_len; io->io_SerFlags = sf; io->io_TermArray.TermArray0 = ta0; io->io_TermArray.TermArray1 = ta1; io->IOSer.io_Command = SDCMD_SETPARAMS; return(DoIO(io)); } -h- term.h 2976:1373:832 term.h /* INCLUDES ********************************************************** */ #include "exec/types.h" #include "exec/ports.h" #include "exec/devices.h" #include "exec/io.h" #include "exec/memory.h" #include "devices/console.h" #include "devices/serial.h" #include "devices/keymap.h" #include "libraries/dos.h" #include "graphics/text.h" #include "libraries/diskfont.h" #include "intuition/intuition.h" /* EXTERNALS ***************************************************** */ extern struct Window *OpenWindow(); extern struct Screen *OpenScreen(); extern struct MsgPort *CreatePort(); extern struct IOStdReq *CreateStdIO(); extern struct IORequest *CreateExtIO(); -h- terminal.c 2976:1373:832 terminal.c /* A simple terminal emulator. Does ANSI/DEC VT-100 emulation in 80 cols by 25 lines. by Michael J. McInerny 21-Feb-86 version 1.21 */ #define INTUITION_MESSAGE (1<MutualExclude = (~(1 << 0)); SubItem->Flags |= CHECKIT; SubItem = AddItem(SubItem," 1200 "); SubItem->MutualExclude = (~(1 << 1)); SubItem->Flags |= CHECKIT | CHECKED; SubItem = AddItem(SubItem," 2400 "); SubItem->MutualExclude = (~(1 << 2)); SubItem->Flags |= CHECKIT; SubItem = AddItem(SubItem," 4800 "); SubItem->MutualExclude = (~(1 << 3)); SubItem->Flags |= CHECKIT; SubItem = AddItem(SubItem," 9600 "); SubItem->MutualExclude = (~(1 << 4)); SubItem->Flags |= CHECKIT; CurrentItem = AddItem(CurrentItem,"Length"); SubItem = AddNewSubItem(CurrentItem," 7 bits ",100,11); SubItem->MutualExclude = (~(1 << 0)); SubItem->Flags |= CHECKIT | CHECKED; SubItem = AddItem(SubItem," 8 bits "); SubItem->MutualExclude = (~(1 << 1)); SubItem->Flags |= CHECKIT; SetMenuStrip( TerminalWindow, MenuHead); } InitReqs() { consoleWritePort = CreatePort("my.con.write",0); if(consoleWritePort == 0) Cleanup(4); ConWriteReq = CreateStdIO(consoleWritePort); if(ConWriteReq == 0) Cleanup(5); consoleReadPort = CreatePort("my.con.read",0); if(consoleReadPort == 0) Cleanup(6); ConReadReq = CreateStdIO(consoleReadPort); if(ConReadReq == 0) Cleanup(7); if((OpenConsole(ConWriteReq,ConReadReq,TerminalWindow)) != 0) Cleanup(8); serReadPort = CreatePort("my.ser.read",0); if (serReadPort == NULL) Cleanup(9); SerReadReq = (struct IOExtSer *)CreateExtIO(serReadPort, sizeof(struct IOExtSer)); if (SerReadReq == NULL) Cleanup(10); serWritePort = CreatePort("my.ser.write",0); if (serWritePort == NULL) Cleanup(11); SerWriteReq = (struct IOExtSer *)CreateExtIO(serWritePort, sizeof(struct IOExtSer)); if (SerWriteReq == NULL) Cleanup(12); if ((OpenSerial(SerReadReq, SerWriteReq)) != 0) Cleanup(13); if ((SetParams( SerReadReq, 4096, 0x07, 0x07, 750000, 1200, NULL, 0x51040303, 0x03030303)) != 0) Cleanup(14); } main() { USHORT class, code, qualifier; int problem, wakeupmask, consoleReadBit, intuitionMsgBit, serReadBit; struct IntuiMessage *message; /* the message the IDCMP sends us */ InitWindow(); InitMenus(); InitReqs(); QueueRead(ConReadReq,&letter); QueueSerRead(SerReadReq, &serin); consoleReadBit = ConReadReq->io_Message.mn_ReplyPort->mp_SigBit; intuitionMsgBit = TerminalWindow->UserPort->mp_SigBit; serReadBit = SerReadReq->IOSer.io_Message.mn_ReplyPort->mp_SigBit; do { wakeupmask = Wait( INTUITION_MESSAGE | TYPED_CHARACTER | INPUT_CHARACTER); while(CheckIO(ConReadReq)) { WaitIO(ConReadReq); SerPutChar(SerWriteReq,letter); QueueRead(ConReadReq, &letter); } while(CheckIO(SerReadReq)) { WaitIO(SerReadReq); ConPutChar(ConWriteReq,serin); QueueSerRead(SerReadReq, &serin); } if(wakeupmask & INTUITION_MESSAGE) { while((message = (struct IntuiMessage *) GetMsg(TerminalWindow->UserPort) ) != NULL) { class = message->Class; code = message->Code; qualifier = message->Qualifier; ReplyMsg(message); problem = HandleEvent(class,code,qualifier); if(problem == FALSE) break; } } } while (problem); /* keep going as long as HandleEvent returns nonzero */ AbortIO(ConReadReq); /* cancel the last queued read */ AbortIO(SerReadReq); Cleanup(0); } Cleanup(problem) int problem; { if ((problem >= 14) || (problem == 0)) CloseDevice(SerReadReq); if ((problem >= 13) || (problem == 0)) DeleteExtIO(SerWriteReq,sizeof(struct IOExtSer)); if ((problem >= 12) || (problem == 0)) DeletePort(serWritePort); if ((problem >= 11) || (problem == 0)) DeleteExtIO(SerReadReq,sizeof(struct IOExtSer)); if ((problem >= 10) || (problem == 0)) DeletePort(serReadPort); if ((problem >= 9) || (problem == 0)) CloseConsole(ConWriteReq); if ((problem >= 8) || (problem == 0)) DeleteStdIO(ConReadReq); if ((problem >= 7) || (problem == 0)) DeletePort(consoleReadPort); if ((problem >= 6) || (problem == 0)) DeleteStdIO(ConWriteReq); if ((problem >= 5) || (problem == 0)) DeletePort(consoleWritePort); if ((problem >= 4) || (problem == 0)) { ClearMenuStrip(TerminalWindow); DisposeMenus(MenuHead); CloseWindow(TerminalWindow); } if ((problem >= 3) || (problem == 0)) CloseLibrary(IntuitionBase); if ((problem >= 2) || (problem == 0)) CloseLibrary(GfxBase); if(problem > 0) exit(problem+1000); else return(0); } HandleEvent(class,code,qualifier) USHORT class; USHORT code; USHORT qualifier; { switch(class) { case MENUPICK: return(MenuSwitch(code)); break; } /* end of switch( class ) */ return(TRUE); } /* end of HandleEvent */ MenuSwitch(code) USHORT code; { USHORT menunum; struct MenuItem *item; int error; error = TRUE; while(code != MENUNULL ) { item = (struct MenuItem *)ItemAddress(MenuHead, code); menunum = MENUNUM( code ); switch( menunum ) { case 0: error &= ProjectMenu(code); break; case 1: error &= SettingsMenu(code); break; } /* end of switch ( menunum ) */ code = item->NextSelect; } /* end of while (code != MENUNULL) */ return(error); } /* end of MenuSwitch */ ProjectMenu(code) USHORT code; { USHORT itemnum; struct IntuiText *InfoText, *OKText, *NewIText(), *AddIText(); itemnum = ITEMNUM( code ); switch( itemnum ) { case 0: /* About PDTerm */ InfoText = NewIText("Public Domain Terminal Emulator",12,5); AddIText(InfoText, " by Michael McInerny "); OKText = NewIText("Okay",6,3); AutoRequest(TerminalWindow, InfoText, NULL, OKText, NULL, NULL, 296, 65); DisposeIText(InfoText); DisposeIText(OKText); return(TRUE); case 1: /* Window */ return(ArrangeMenu(code)); break; case 2: /* Quit */ return( FALSE ); break; } /* end of switch ( itemnum ) */ return( TRUE ); } /* end of ProjectMenu */ ArrangeMenu(code) USHORT code; { USHORT subitem; subitem = SUBNUM( code ); switch( subitem ) { case 0: WindowToBack( TerminalWindow ); break; case 1: WindowToFront( TerminalWindow ); break; } /* end of switch ( subitem ) */ return( TRUE ); } /* end of ArrangeMenu */ SettingsMenu(code) USHORT code; { USHORT itemnum; itemnum = ITEMNUM( code ); AbortIO(SerReadReq); switch ( itemnum ) { case 0: BaudMenu(code); break; case 1: LengthMenu(code); break; } /* end of switch ( itemnum ) */ SerReadReq->IOSer.io_Command = SDCMD_SETPARAMS; DoIO(SerReadReq); QueueSerRead(SerReadReq, &serin); return( TRUE ); } /* end of SettingsMenu */ BaudMenu(code) USHORT code; { USHORT subitem; subitem = SUBNUM( code ); switch( subitem ) { case 0: SerReadReq->io_Baud = 300; break; case 1: SerReadReq->io_Baud = 1200; break; case 2: SerReadReq->io_Baud = 2400; break; case 3: SerReadReq->io_Baud = 4800; break; case 4: SerReadReq->io_Baud = 9600; break; } /* end of switch ( subitem ) */ } /* end of BaudMenu */ LengthMenu(code) USHORT code; { USHORT subitem; subitem = SUBNUM( code ); switch( subitem ) { case 0: SerReadReq->io_ReadLen = 0x07; SerReadReq->io_WriteLen = 0x07; break; case 1: SerReadReq->io_ReadLen = 0x08; SerReadReq->io_WriteLen = 0x08; break; } /* end of switch ( subitem ) */ } /* end of LengthMenu */ ----------------------------------------------------------------------- Replies to BM17@TD.CC.CMU.EDU or BM17@CMUCCVMA (Bitnet) -------