/************************************************************************ * One of many Terminal Programs for the Amiga * Features: Ascii, Xmodem, and CompuServe 'B' protocol transfers * Phone Library support * Function Key support * Limited direct DOS support * * * Originally derived from AmigaTerm 1.0 - written by Michael Mounier * * Version 2.0 - May, 1986 --- Bob Rakosky * - corrected buffer capture to use xon/xoff when flushing * buffer to disk, to prevent lost characters * - increased buffer size of capture buffer and allocated memory * dynamically * - added Phone Library support * - modularized code to speed up compiles for fixes/mods * - added CRC option to Xmodem transfers * * Version 2.1 - June, 1986 --- Bob Rakosky * - changed to a 'borderless' window, allowing full 80 char line * - added DOS 'directory' and 'change current directory' gadgets * to menu line border * - Added function key support * - Added CompuServe B-protocol * - Restructured 'modularization' of code segments for a more * logical breakdown of source components * * * Functions in this module: * InitFileItems() - initializes File sub-menu * InitRSItems() - initializes Baud Rate sub-menu * InitPHItems() - initializes Phone support sub-menu * InitMenu() - initializes Menu structures * init_window() - initializes/opens program window * * main() - initialization, main process loop, termination * ************************************************************************/ #include "term.h" extern char *getmem(); char *bufr = NULL; int fd, capture = FALSE, bufr_ptr = NULL, cap_open = FALSE, timeout = FALSE; FILE *tranr = NULL; long bytes_xferred; ULONG class; USHORT code, qual, menunum, itemnum; int KeepGoing, send; char c, name[32]; FILE *trans = NULL; /* Intuition always wants to see these declarations */ struct IntuitionBase *IntuitionBase; struct GfxBase *GfxBase; /* structures for GADGETS for window structure */ struct IntuiText hlp_txt = { 3,2, /* front pen, back */ JAM2, /* draw mode */ 0,0, /* relative start */ NULL, /* font */ (UBYTE *) " Help ", /* text */ NULL /* chain */ }; struct IntuiText dir_txt = { 3,2, /* front pen, back */ JAM2, /* draw mode */ 0,0, /* relative start */ NULL, /* font */ (UBYTE *) " Dir ", /* text */ NULL /* chain */ }; struct IntuiText cd_txt = { 0,1, /* front pen, back */ JAM2, /* draw mode */ -26,0, /* relative start */ NULL, /* font */ (UBYTE *) "cd:", /* text */ NULL /* chain */ }; UBYTE cd_nam[128]; extern UBYTE undo_buf[]; struct StringInfo cd_nm_buf = { cd_nam, /* buffer */ undo_buf, /* undo buffer */ 0, /* buf pos */ 128, /* Max chars */ 0, /* first disp pos */ 0, /* Undo pos */ 0, /* current char count */ 0,0,0, NULL,NULL }; /* Macros for identifying gadgets */ #define HLP_GAD 210 #define DIR_GAD 211 #define CD_GAD 212 #define UP_HLP_GAD (gad->GadgetID == HLP_GAD) #define UP_DIR_GAD (gad->GadgetID == DIR_GAD) #define UP_CD_GAD (gad->GadgetID == CD_GAD) struct Gadget cd_gad = { NULL, /* chain to next */ 384,0, /* left, top */ 192,9, /* width, height */ GADGHCOMP, /* flags */ RELVERIFY, STRGADGET, /* gadget type */ NULL, NULL, /* render ptrs */ &cd_txt, /* gadget label */ NULL, /* exclude */ (APTR)&cd_nm_buf, /* string buffers */ CD_GAD, /* gadget id */ NULL /* user data */ }; struct Gadget dir_gad = { &cd_gad, /* chain to next */ 240,0, /* left, top */ 48,9, /* width, height */ GADGHCOMP, /* flags */ RELVERIFY, BOOLGADGET, /* gadget type */ NULL, NULL, /* render ptrs */ &dir_txt, /* gadget label */ NULL, /* exclude */ NULL, /* string buffers */ DIR_GAD, /* gadget id */ NULL /* user data */ }; struct Gadget hlp_gad = { &dir_gad, /* chain to next */ 160,0, /* left, top */ 48,9, /* width, height */ GADGHCOMP, /* flags */ RELVERIFY, BOOLGADGET, /* gadget type */ NULL, NULL, /* render ptrs */ &hlp_txt, /* gadget label */ NULL, /* exclude */ NULL, /* string buffers */ HLP_GAD, /* gadget id */ NULL /* user data */ }; /* my window structure */ struct NewWindow NewWindow = { 0, 0, 640, 200, 0, 1, CLOSEWINDOW | RAWKEY | MENUPICK | GADGETUP, WINDOWCLOSE | SMART_REFRESH | ACTIVATE | BORDERLESS | WINDOWDEPTH | REPORTMOUSE, &hlp_gad, NULL, "Term Plus 2.1", NULL, NULL, 100, 35, 640, 200, WBENCHSCREEN, }; struct Window *mywindow; /* ptr to applications window */ struct IntuiMessage *NewMessage; /* msg structure for GetMsg() */ /***************************************************** * File Menu *****************************************************/ /* define maximum number of menu items */ #define FILEMAX 6 /* declare storage space for menu items and * their associated IntuiText structures */ struct MenuItem FileItem[FILEMAX]; struct IntuiText FileText[FILEMAX+1]; /* define maximum number of sub-menu items for XMODEM options */ #define X_SUB_MAX 4 /* declare storage space for menu items and * their associated IntuiText structures */ struct MenuItem X_Sub_Item[X_SUB_MAX]; struct IntuiText X_Sub_Text[X_SUB_MAX]; /*****************************************************************/ /* The following function initializes the structure arrays */ /* needed to provide the File menu topic. */ /*****************************************************************/ InitFileItems() { short n; /* initialize each menu item and IntuiText with loop */ for( n=0; nRPort,1); emit(12); BeginIO(Read_Request); while( KeepGoing ) { /* wait for window message or serial port message */ Wait((1 << Read_Request->IOSer.io_Message.mn_ReplyPort->mp_SigBit) | ( 1 << mywindow->UserPort->mp_SigBit)); if(CheckIO(Read_Request)) { WaitIO(Read_Request); c=rs_in[0] & 0x7f; BeginIO(Read_Request); switch (ESC_Seq_State) { case 0: switch (c) { case ESC: ESC_Seq_State = 1; break; case ENQ: /* Enquiry -- send ACK for packet 0 */ sendchar(DLE); sendchar('0'); break; case DLE: ESC_Seq_State = 2; break; default: emit(c); if (capture) add_cap(c); } break; case 1: /* ESC -- process any escape sequences here */ switch (c) { case 'I': /* * Reply to the VIDTEX "ESC I" identify sequence */ cp = VIDTEX_Response; while (*cp != 0) sendchar(*cp++); ESC_Seq_State = 0; break; default: emit(ESC); if (capture) add_cap(ESC); emit(c); if (capture) add_cap(c); ESC_Seq_State = 0; } break; case 2: /* DLE */ if (c == 'B') { /* Start of "B" protocol packet. Go into protocol * mode and transfer the file as requested. */ if (!B_prot_xfer()) emits("Transfer failed!"); } else { emit(DLE); if (capture) add_cap(DLE); emit(c); if (capture) add_cap(c); } ESC_Seq_State = 0; } /* end switch(ESC_Seq_State) */ } /* end if (CheckIO(Read_Request)) */ while( NewMessage=(struct IntuiMessage *)GetMsg(mywindow->UserPort) ) { class = NewMessage->Class; code = NewMessage->Code; qual = NewMessage->Qualifier; gad = (struct Gadget *)NewMessage->IAddress; ReplyMsg( NewMessage ); switch( class ) { case CLOSEWINDOW: /* User is ready to quit, so indicate * that execution should terminate * with next iteration of the loop. */ KeepGoing = FALSE; break; case RAWKEY: /* User has touched the keyboard */ switch (i = toasc(code,qual)) { case -1: do_fkey(code,qual); case 0: break; default: sendchar(i); } break; case MENUPICK: do_menu(MENUNUM(code),ITEMNUM(code),SUBNUM(code)); break; case GADGETUP: if (UP_HLP_GAD) do_help(); else if (UP_DIR_GAD) do_dir(); else if (UP_CD_GAD) do_cd(); break; } /* end of switch (class) */ } /* end of while ( newmessage )*/ } /* end while ( keepgoing ) */ /* It must be time to quit, so we have to clean * up and exit. */ if (cap_open) clos_cap(); if (bufr) rlsmem(bufr,BufSize); reset_dir(); clos_ser(); ClearMenuStrip( mywindow ); CloseWindow( mywindow ); exit(FALSE); } /* end of main */