home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / telecomm / t100.zoo / t100.c < prev    next >
C/C++ Source or Header  |  1991-09-22  |  20KB  |  957 lines

  1. /*
  2.  *    t100 - simple term emulator. vt52 and ANSI (much of vt100)
  3.  *
  4.  *    by Bill Rosenkranz (rosenkra@convex.com).
  5.  *
  6.  *    based on st52 program by Nick Castellano (entropy@ai.mit.edu) but
  7.  *    greatly changed so it bears little resemblence. i added the vt100
  8.  *    support, including font changes. also lifted rs232init from Howard
  9.  *    Chu's tip and rs232cd (carrier detect) from Steve Yelvington.
  10.  *
  11.  *    this was written with gcc 1.40 (and MiNT 10 libraries).
  12.  *
  13.  *    currently it is hardwired to vt100 (vt100_mode==1 always). i am
  14.  *    not sure why you'd want vt52 anyway. you can toggle this by adding
  15.  *    code to set vt100_mode to 0 (the host better know you changed!).
  16.  *    my reference for the ANSI/vt100 escape codes was an old Falco
  17.  *    terminal manual. it may not be accurate/modern/complete but does
  18.  *    seem accurate for all the escapes i find in standard vt100 termcap.
  19.  *
  20.  *    it should be easy to hack in an escape to execute shell commands.
  21.  *    i just have not done it. that way you could start up a kermit
  22.  *    or xmodem or whatever. i have not tested this under MiNT or mgr.
  23.  *
  24.  *    restrictions: to (re)set the fonts, i do a line A init ($A000)
  25.  *    to get the fonthdr pointer and from there get the address of the
  26.  *    font data. i poke in a new address to my own data, being careful
  27.  *    to set it back on exit (i hope :-). this means if your big-screen
  28.  *    monitor can't support this, you are SOL. it also won't run on a
  29.  *    TT since line A went bye-bye. note that you can always recompile
  30.  *    with -UUSE_FONTS and it should work fine on any system. you just
  31.  *    won't have bold and underline.
  32.  *
  33.  *    also, if you define SET_RS232_INIT at compile time, this relies
  34.  *    on Rsconf returning a value. my understanding is that this does
  35.  *    not work on TOS 1.0. the safe bet would be to check the TOS
  36.  *    version. i have not tested this part of the code. currently,
  37.  *    the rs232 paramaters are hardwired. i would set it from the
  38.  *    control panel.
  39.  *
  40.  *    major problem: i can't figure out how to tell the host we are an
  41.  *    80x25 term without changing /etc/termcap (difficult to do without
  42.  *    the root passwd). setting TERMCAP did not help, at least with
  43.  *    GNU emacs and less. maybe there is a termcap for 80x25 but i never
  44.  *    checked. standard vt100 and vt100n has li set to 24. emacs manual
  45.  *    sez stuff about this (maybe set TERM to vt100-25?). i have no idea
  46.  *    about VMS and other non-unix systems with user library routines whose
  47.  *    names contain "$". why bother? :-)
  48.  */
  49.  
  50. #ifndef lint
  51. static char *rcsid_t100_c = "$Id: t100.c,v 1.0 1991/09/12 20:32:56 rosenkra Exp $";
  52. #endif
  53.  
  54. /*
  55.  * $Log: t100.c,v $
  56.  * Revision 1.0  1991/09/12  20:32:56  rosenkra
  57.  * Initial revision
  58.  *
  59.  */
  60.  
  61. #include <stdio.h>
  62. #include <stdlib.h>
  63. #include <unistd.h>
  64. #include <string.h>
  65. #include <osbind.h>
  66. #include <mintbind.h>
  67. #include <signal.h>
  68. #include "t100.h"
  69.  
  70.  
  71.  
  72. #define MINTID        "MiNT"        /* MiNT's cookie string */
  73. #define MAXWAIT        1000        /* see note in main loop */
  74. #define PROMPT_STRING    "\n\rt100> "    /* MUST contain a newline */
  75.  
  76. #define NEWLINE        10        /* common chars */
  77. #define ESC        27
  78. #define RETURN        13
  79.  
  80.  
  81. /*
  82.  *    globals
  83.  */
  84. char        iobuf[8192];        /* new iorec for rs232 (first half */
  85.                     /* is in, second half out) */
  86. _IOREC           *recsav;            /* ptr to iorec struct */
  87. _IOREC        oldirec;        /* old input iorec */
  88. _IOREC        oldorec;        /* old output iorec */
  89.  
  90. int        par  = 0;        /* none, odd, even - 0, 1, 2 */
  91. int        baud = 4;        /* see baud table 4=2400 */
  92. int        echo = 0;        /* 0=off, 1=on */
  93. int        flow = 0;        /* none, xon/xoff, rts/cts */
  94.  
  95. int        ucr, rsr, tsr, scr;    /* for resetting rs232 regs */
  96.  
  97. char           *bauds[] = {"19200","9600","4800","3600","2400","2000",
  98.                "1800","1200","600","300","200","150","134",
  99.                "110","75","50"};        /* unused */
  100.  
  101. int        vt100_mode = 1;        /* 0 means revert to vt52 */
  102. long        mintcookie = 0L;    /* if MiNT this will be non-NULL */
  103.  
  104. /*
  105.  *    vt100 modes, etc...
  106.  */
  107. int        bold      = 0;        /* OFF 1m */
  108. int        underline = 0;        /* OFF 4m */
  109. int        blinking  = 0;        /* OFF 5m */
  110. int        reverse   = 0;        /* OFF 7m */
  111. int        wrap      = 1;        /* ON (set) */
  112. int        video     = 0;        /* 0=normal (reset) */
  113. int        repeat    = 1;        /* ON (set) */
  114. int        curskey   = 0;        /* OFF (reset) */
  115. int        keypad    = 0;        /* 0=normal (reset) */
  116. int        colwidth  = 0;        /* 0=80 (reset), 1=132 */
  117. int        smooth    = 0;        /* OFF (reset) */
  118. int        origmode  = 0;        /* 0=normal (reset) */
  119.  
  120. short        kbinit, kbrpt;        /* saved key repeat stuff */
  121.  
  122. int        outtran[256];        /* char xlation table */
  123.  
  124.  
  125.  
  126. /*------------------------------*/
  127. /*    main            */
  128. /*------------------------------*/
  129. int main (int argc, char *argv[], char *envp[])
  130. {
  131.     short        kbret;
  132.     int        x;
  133.     register long    key;            /* raw Bconin value */
  134.     register int    gnsrgh = MAXWAIT;
  135.     register int    c;
  136. #ifdef JUNK
  137.     /* this was in st52 code. i don't use it...(it was #ifdef'd already) */
  138.     char           *terminal;
  139.     char           *etmp;
  140.     char           *newenv;
  141.  
  142.  
  143.     etmp = (char *) envp;
  144.  
  145.     terminal = getenv ("TERM");
  146. #ifdef DEBUG
  147.     Cconws ("Terminal type:  ");
  148.     puts (terminal);
  149. #endif
  150.  
  151.     if (strcmp (terminal, "mgr") == 0)
  152.     {
  153.  
  154. #ifdef DEBUG
  155.         puts ("yep");
  156.         printf ("value: %d\n",
  157.         Pexec (200, "e:\\mint\\mgr\\bin\\vt52.prg",
  158.             "e:\\mint\\mgr\\bin\\vt52.prg t100", envp));
  159. #else
  160.         Pexec (200, "e:\\mint\\mgr\\bin\\vt52.prg",
  161.             "e:\\mint\\mgr\\bin\\vt52.prg t100", envp);
  162. #endif
  163.     }
  164.  
  165. #endif /*JUNK*/
  166.  
  167.  
  168.  
  169.     /*
  170.      *   some initializations: key repeat (save old) and wrap ON
  171.      */
  172.     kbret  = (short) Kbrate (15, 2);/* repeat ESC [ ? 8 h */
  173.     kbinit = (kbret >> 8) & 0x00ff;
  174.     kbrpt  = kbret & 0x00ff;
  175.  
  176.     Bconout (CON, (int) 27);    /* wrap ESC [ ? 7 h */
  177.     Bconout (CON, (int) 'v');
  178.  
  179.  
  180.  
  181.     /*
  182.      *   set up output char translation array (normally output==input,
  183.      *   but you can remap if you want here)
  184.      */
  185.     for (x = 0; x < 256; x++)
  186.         outtran[x] = x;
  187. #ifdef SWAP_DEL_AND_BS
  188.     /*
  189.      *   this swaps DEL and BS
  190.      */
  191.     outtran[127] = 8;
  192.     outtran[8]   = 127;
  193. #endif
  194.  
  195.  
  196.     /*
  197.      *   check for MiNT cookie
  198.      */
  199.     mintcookie = getcookie (MINTID);
  200. #ifdef DEBUG
  201.     printf ("MiNT cookie %lx detected\n", mintcookie);
  202. #endif
  203.  
  204.  
  205.  
  206. #ifdef USE_FONTS
  207.     /*
  208.      *   set fonts
  209.      */
  210. #ifdef DEBUG
  211.     Cconws ("\n\rset fonts...\n\r\n\r");
  212. #endif
  213.     if (vt100_mode)
  214.         fnt_roman ();
  215.  
  216. #if 0
  217. /* test fonts */
  218.             Cconws ("Roman font (normal)\n\r");
  219.     fnt_bold ();    Cconws ("BOLD font\n\r");
  220.     fnt_uline ();    Cconws ("uline font\n\r");
  221.     fnt_reverse ();    Cconws ("reverse font\n\r");
  222.     fnt_roman ();    Cconws ("back to Roman\n\r\n\r\n\r");
  223.  
  224.             Cconws ("roman ");
  225.     fnt_bold ();    Cconws ("bold ");
  226.     fnt_uline ();    Cconws ("uline ");
  227.     fnt_reverse ();    Cconws ("reverse ");
  228.     fnt_roman ();    Cconws ("roman\n\r\n\r");
  229. #endif
  230. #else /*! USE_FONTS*/
  231.     vt100_mode = 0;
  232. #endif /*USE_FONTS*/
  233.  
  234. #if 0
  235. /* test Setcolor */
  236.     Setcolor (0,0);
  237.     Setcolor (1,0x777);
  238.     Cconws ("any key\n\r");
  239.     Crawcin ();
  240.     Setcolor (0,0x777);
  241.     Setcolor (1,0);
  242. #endif
  243.  
  244.  
  245.     /*
  246.      *   introductions...
  247.      */
  248.     blurb ();
  249.  
  250.  
  251.     /*
  252.      *   initialize rs232 (buffers and baud)
  253.      */
  254.     Cconws ("\n\rinitialize rs232...\n\r");
  255.     rs232init ();
  256.     Cconws ("baud set to 2400.\n\r");
  257.  
  258.  
  259.     /*
  260.      *   prompt
  261.      */
  262.     Cconws (PROMPT_STRING);
  263.  
  264.  
  265.     /*
  266.      *   main loop...
  267.      */
  268.     for (;;)
  269.     {
  270.         /*
  271.          *   if there are characters at the AUX port, and we are
  272.          *   not going to interrupt, print them. without the
  273.          *   gnsrgh value, we can't interrupt and send a char.
  274.          *   MAXWAIT controls how many chars we let in before
  275.          *   checking the keyboard. 1000 seems reasonable.
  276.          */
  277.         if (Bconstat (AUX) && gnsrgh--)
  278.         {
  279.             /*
  280.              *   get char
  281.              */
  282.             c = (int) Bconin (AUX);
  283.  
  284.             /*
  285.              *   check for newline. if we are connected do nothing
  286.              *   special. otherwise print PROMPT_STRING (which
  287.              *   must have the newline we ignore in it)
  288.              */
  289.             if (c == NEWLINE)
  290.             {
  291.                 /*
  292.                  *   if carrier detected...
  293.                  */
  294.                 if (rs232cd ())
  295.                 {
  296.                     /*
  297.                      *   ...output the newline...
  298.                      */
  299.                     Bconout (CON, (int) c);
  300.                 }
  301.                 else
  302.                 {
  303.                     /*
  304.                      *   ...otherwise do our prompt
  305.                      */
  306.                     Cconws (PROMPT_STRING);
  307.                 }
  308.             }
  309. #ifdef EMUL_VT100
  310.             else if ((c == ESC) && vt100_mode)
  311.             {
  312.                 /*
  313.                  *   assume if we get ESC that this will be
  314.                  *   an ANSI/vt100 escape seqence and handle
  315.                  *   it. vt100 also reads AUX for the rest
  316.                  *   of the sequence. maybe it should return
  317.                  *   an error code.
  318.                  */
  319.                 vt100 ();
  320.             }
  321.             else
  322.             {
  323.                 /*
  324.                  *   just echo the char
  325.                  */
  326.                 Bconout (CON, (int) c);
  327.             }
  328. #else
  329.             else
  330.             {
  331.                 /*
  332.                  *   just echo the char. let the vt52 emulator
  333.                  *   handle the rest...
  334.                  */
  335.                 Bconout (CON, (int) c);
  336.             }
  337. #endif
  338.         }
  339.         else
  340.         {
  341.             /*
  342.              *   reset gnsrgh. see note above.
  343.              *
  344.              *   then check for keyboard input...
  345.              */
  346.             gnsrgh = MAXWAIT;
  347.             if (Bconstat (CON))
  348.             {
  349.                 /*
  350.                  *   get it...
  351.                  */
  352.                 key = Bconin (CON);
  353. #ifdef DEBUG
  354.                 printf ("-%08lx-\n", key);
  355. #endif
  356.  
  357.                 /*
  358.                  *   what was it? check for possible internal
  359.                  *   commands. here we can get fancy and look
  360.                  *   for something to do shell escapes, file
  361.                  *   xfers, etc. so far it is basic.
  362.                  *
  363.                  *   also look for arrow and keypad keys and
  364.                  *   send the right thing depending on mode.
  365.                  */
  366.                 handle_key (key);
  367.             }
  368.             else
  369.             {
  370.                 /*
  371.                  *   nothing to do so give up a quantum to
  372.                  *   others if under MiNT...
  373.                  */
  374.                 if (mintcookie)
  375.                     (void) Syield ();
  376.             }
  377.         }
  378.     }
  379.  
  380.     /*NOTREACHED*/
  381. }
  382.  
  383.  
  384.  
  385.  
  386. /*------------------------------*/
  387. /*    handle_key        */
  388. /*------------------------------*/
  389. void handle_key (long key)
  390. {
  391.  
  392. /*
  393.  *    handle key from console...
  394.  */
  395.  
  396.     char    buf[512];
  397.     int    len;
  398.  
  399.  
  400.     switch (key)
  401.     {
  402.  
  403. /* cursor keys... */
  404.  
  405.     case 0x00480000:    /* up arrow */
  406.         if (curskey)
  407.         {
  408.             Bconout (AUX, (int)ESC);
  409.             Bconout (AUX, (int)'O');
  410.             Bconout (AUX, (int)'A');
  411.         }
  412.         else
  413.         {
  414.             Bconout (AUX, (int)ESC);
  415.             Bconout (AUX, (int)'[');
  416.             Bconout (AUX, (int)'A');
  417.         }
  418.         break;
  419.     case 0x00500000:    /* down arrow */
  420.         if (curskey)
  421.         {
  422.             Bconout (AUX, (int)ESC);
  423.             Bconout (AUX, (int)'O');
  424.             Bconout (AUX, (int)'B');
  425.         }
  426.         else
  427.         {
  428.             Bconout (AUX, (int)ESC);
  429.             Bconout (AUX, (int)'[');
  430.             Bconout (AUX, (int)'B');
  431.         }
  432.         break;
  433.     case 0x004d0000:    /* right arrow */
  434.         if (curskey)
  435.         {
  436.             Bconout (AUX, (int)ESC);
  437.             Bconout (AUX, (int)'O');
  438.             Bconout (AUX, (int)'C');
  439.         }
  440.         else
  441.         {
  442.             Bconout (AUX, (int)ESC);
  443.             Bconout (AUX, (int)'[');
  444.             Bconout (AUX, (int)'C');
  445.         }
  446.         break;
  447.     case 0x004b0000:    /* left arrow */
  448.         if (curskey)
  449.         {
  450.             Bconout (AUX, (int)ESC);
  451.             Bconout (AUX, (int)'O');
  452.             Bconout (AUX, (int)'D');
  453.         }
  454.         else
  455.         {
  456.             Bconout (AUX, (int)ESC);
  457.             Bconout (AUX, (int)'[');
  458.             Bconout (AUX, (int)'D');
  459.         }
  460.         break;
  461.  
  462. /* keypad keys... */
  463.  
  464.     case 0x00700030:    /* 0 */
  465.         if (keypad)
  466.         {
  467.             Bconout (AUX, (int)ESC);
  468.             Bconout (AUX, (int)'O');
  469.             Bconout (AUX, (int)'p');
  470.         }
  471.         else
  472.         {
  473.             Bconout (AUX, (int)'0');
  474.         }
  475.         break;
  476.     case 0x006d0031:    /* 1 */
  477.         if (keypad)
  478.         {
  479.             Bconout (AUX, (int)ESC);
  480.             Bconout (AUX, (int)'O');
  481.             Bconout (AUX, (int)'q');
  482.         }
  483.         else
  484.         {
  485.             Bconout (AUX, (int)'1');
  486.         }
  487.         break;
  488.     case 0x006e0032:    /* 2 */
  489.         if (keypad)
  490.         {
  491.             Bconout (AUX, (int)ESC);
  492.             Bconout (AUX, (int)'O');
  493.             Bconout (AUX, (int)'r');
  494.         }
  495.         else
  496.         {
  497.             Bconout (AUX, (int)'2');
  498.         }
  499.         break;
  500.     case 0x006f0033:    /* 3 */
  501.         if (keypad)
  502.         {
  503.             Bconout (AUX, (int)ESC);
  504.             Bconout (AUX, (int)'O');
  505.             Bconout (AUX, (int)'s');
  506.         }
  507.         else
  508.         {
  509.             Bconout (AUX, (int)'3');
  510.         }
  511.         break;
  512.     case 0x006a0034:    /* 4 */
  513.         if (keypad)
  514.         {
  515.             Bconout (AUX, (int)ESC);
  516.             Bconout (AUX, (int)'O');
  517.             Bconout (AUX, (int)'t');
  518.         }
  519.         else
  520.         {
  521.             Bconout (AUX, (int)'4');
  522.         }
  523.         break;
  524.     case 0x006b0035:    /* 5 */
  525.         if (keypad)
  526.         {
  527.             Bconout (AUX, (int)ESC);
  528.             Bconout (AUX, (int)'O');
  529.             Bconout (AUX, (int)'u');
  530.         }
  531.         else
  532.         {
  533.             Bconout (AUX, (int)'5');
  534.         }
  535.         break;
  536.     case 0x006c0036:    /* 6 */
  537.         if (keypad)
  538.         {
  539.             Bconout (AUX, (int)ESC);
  540.             Bconout (AUX, (int)'O');
  541.             Bconout (AUX, (int)'v');
  542.         }
  543.         else
  544.         {
  545.             Bconout (AUX, (int)'6');
  546.         }
  547.         break;
  548.     case 0x00670037:    /* 7 */
  549.         if (keypad)
  550.         {
  551.             Bconout (AUX, (int)ESC);
  552.             Bconout (AUX, (int)'O');
  553.             Bconout (AUX, (int)'w');
  554.         }
  555.         else
  556.         {
  557.             Bconout (AUX, (int)'7');
  558.         }
  559.         break;
  560.     case 0x00680038:    /* 8 */
  561.         if (keypad)
  562.         {
  563.             Bconout (AUX, (int)ESC);
  564.             Bconout (AUX, (int)'O');
  565.             Bconout (AUX, (int)'x');
  566.         }
  567.         else
  568.         {
  569.             Bconout (AUX, (int)'8');
  570.         }
  571.         break;
  572.     case 0x00690039:    /* 9 */
  573.         if (keypad)
  574.         {
  575.             Bconout (AUX, (int)ESC);
  576.             Bconout (AUX, (int)'O');
  577.             Bconout (AUX, (int)'y');
  578.         }
  579.         else
  580.         {
  581.             Bconout (AUX, (int)'9');
  582.         }
  583.         break;
  584.     case 0x004a002d:    /* - */
  585.         if (keypad)
  586.         {
  587.             Bconout (AUX, (int)ESC);
  588.             Bconout (AUX, (int)'O');
  589.             Bconout (AUX, (int)'m');
  590.         }
  591.         else
  592.         {
  593.             Bconout (AUX, (int)'-');
  594.         }
  595.         break;
  596.     case 0x0072000d:    /* enter */
  597.         if (keypad)
  598.         {
  599.             Bconout (AUX, (int)ESC);
  600.             Bconout (AUX, (int)'O');
  601.             Bconout (AUX, (int)'M');
  602.         }
  603.         else
  604.         {
  605.             Bconout (AUX, (int)RETURN);
  606.         }
  607.         break;
  608.     case 0x0071002e:    /* . */
  609.         if (keypad)
  610.         {
  611.             Bconout (AUX, (int)ESC);
  612.             Bconout (AUX, (int)'O');
  613.             Bconout (AUX, (int)'n');
  614.         }
  615.         else
  616.         {
  617.             Bconout (AUX, (int)'.');
  618.         }
  619.         break;
  620. /*!!! not sure of this one */
  621.     case 0x004e002b:    /* + */
  622.         if (keypad)
  623.         {
  624.             Bconout (AUX, (int)ESC);
  625.             Bconout (AUX, (int)'O');
  626.             Bconout (AUX, (int)'T');
  627.         }
  628.         else
  629.         {
  630.             Bconout (AUX, (int)'+');
  631.         }
  632.         break;
  633.     case 0x00630028:    /* ( */
  634.         if (keypad)
  635.         {
  636.             Bconout (AUX, (int)ESC);
  637.             Bconout (AUX, (int)'O');
  638.             Bconout (AUX, (int)'P');
  639.         }
  640.         else
  641.         {
  642.             Bconout (AUX, (int)'(');
  643.         }
  644.         break;
  645.     case 0x00640029:    /* ) */
  646.         if (keypad)
  647.         {
  648.             Bconout (AUX, (int)ESC);
  649.             Bconout (AUX, (int)'O');
  650.             Bconout (AUX, (int)'Q');
  651.         }
  652.         else
  653.         {
  654.             Bconout (AUX, (int)')');
  655.         }
  656.         break;
  657.     case 0x0065002f:    /* / */
  658.         if (keypad)
  659.         {
  660.             Bconout (AUX, (int)ESC);
  661.             Bconout (AUX, (int)'O');
  662.             Bconout (AUX, (int)'R');
  663.         }
  664.         else
  665.         {
  666.             Bconout (AUX, (int)'/');
  667.         }
  668.         break;
  669.     case 0x0066002a:    /* * */
  670.         if (keypad)
  671.         {
  672.             Bconout (AUX, (int)ESC);
  673.             Bconout (AUX, (int)'O');
  674.             Bconout (AUX, (int)'S');
  675.         }
  676.         else
  677.         {
  678.             Bconout (AUX, (int)'*');
  679.         }
  680.         break;
  681.  
  682. /* keys we track for control... */
  683.  
  684.     case 0x00620000:    /* HELP */
  685.         help ();
  686.         if (!rs232cd ())
  687.             Cconws (PROMPT_STRING);
  688.         break;
  689.  
  690.     case 0x002E0000:     /* alt-c (config) */ 
  691.     case 0x000000E3:
  692.         config ();
  693.         if (!rs232cd ())
  694.             Cconws (PROMPT_STRING);
  695.         break;
  696.  
  697.     case 0x00260000:    /* alt-l (long break) */
  698.         long_break ();
  699.         if (!rs232cd ())
  700.             Cconws (PROMPT_STRING);
  701.         break;
  702.  
  703.     case 0x001f0000:    /* alt-s (shell) */
  704.         buf[0] = 127;
  705.         Cconws ("\n\r\n\rEnter shell command (eg ls):\n\r");
  706.         Cconrs (buf);
  707.         Cconws ("\n\r");
  708.         len          = buf[1];
  709.         buf[2+len+1] = '\0';
  710.         if (system (&buf[2]))
  711.         {
  712.             Cconws ("\n\r\n\rCommand failed!\n\r\n\r");
  713.         }
  714.         if (!rs232cd ())
  715.             Cconws (PROMPT_STRING);
  716.         break;
  717.  
  718.     case 0x00250000:    /* alt-k (kermit) */
  719.         buf[0] = 127;
  720.         Cconws ("\n\r\n\rEnter kermit command (eg kermit -c):\n\r");
  721.         Cconrs (buf);
  722.         len = buf[1];
  723.         buf[2+len+1] = '\0';
  724.         Cconws ("\n\r\n\rAttempting to start Kermit....\n\r\n\r");
  725.         if (system (&buf[2]))
  726.         {
  727.             Cconws ("\n\r\n\rKermit failed!\n\r\n\r");
  728.         }
  729.         if (!rs232cd ())
  730.             Cconws (PROMPT_STRING);
  731.         break;
  732.  
  733.     case 0x00100000:     /* alt-q (quit) */ 
  734.     case 0x000000F1:
  735.         Cconws ("\n\r");
  736.         bye (0);
  737.         break;
  738.  
  739.     case 0x002C0000:     /* alt-z */ 
  740.     case 0x000000FA:
  741.         /*
  742.          *   if mint, put ourselves in the
  743.          *   background
  744.          */
  745.         if (mintcookie)
  746.         {
  747.             Cconws ("\n\r");
  748.             (void) Pkill (Pgetpid (), SIGTSTP);
  749.         }
  750.         break;
  751.  
  752. /* anything else... */
  753.  
  754.     default:
  755.         /* note the character translation */
  756.         Bconout (AUX, outtran[(int) (key & KEYMASK)]);
  757.     }
  758. }
  759.  
  760.  
  761.  
  762.  
  763. /*------------------------------*/
  764. /*    blurb            */
  765. /*------------------------------*/
  766. void blurb ()
  767. {
  768.     /* remain humble and don't plaster yer name all over the screen,
  769.        asking for money :-) */
  770.     Cconws ("\n\r");
  771.     if (vt100_mode)
  772.     {
  773.         fnt_reverse ();
  774.         Cconws ("                              \n\r");
  775.         Cconws ("   ");
  776.         fnt_bold ();
  777.         Cconws (" t100: ");
  778.         fnt_uline ();
  779.         Cconws ("Terminal Program ");
  780.         fnt_reverse ();
  781.         Cconws ("   \n\r");
  782.         Cconws ("                              \n\r");
  783.         fnt_roman ();
  784.     }
  785.     else
  786.     {
  787.         Cconws ("==============================\n\r");
  788.         Cconws ("=== t100: Terminal Program ===\n\r");
  789.         Cconws ("==============================\n\r");
  790.     }
  791.     Cconws ("\n\r");
  792.     Cconws ("use HELP key for help...\n\r");
  793.     Cconws ("\n\r");
  794. }
  795.  
  796.  
  797.  
  798. /*------------------------------*/
  799. /*    rs232init        */
  800. /*------------------------------*/
  801. void rs232init ()
  802. {
  803.  
  804. /*
  805.  *    Set up a large I/O buffer for the RS232 port, and set initial
  806.  *    speed, flow control, and parity.
  807.  *
  808.  *    (lifted from howard chu's tip)
  809.  */
  810.  
  811. #ifdef SET_RS232_INIT
  812.     register long    m68901reg;
  813. #endif
  814.  
  815.     /*
  816.      *   get current buffer ptr (0 is rs232)
  817.      */
  818.     recsav           = (_IOREC *) Iorec (0);
  819.  
  820.     oldirec          = *recsav;    /* save input record (struct) */
  821.                     /* this copies a structure, BTW */
  822.     recsav->ibuf     = (char *) iobuf;
  823.     recsav->ibufsiz  = (short) 4096;
  824.     recsav->ibufhd   = (short) 0;
  825.     recsav->ibuftl   = (short) 0;
  826.     recsav->ibuflow  = (short) 100;
  827.     recsav->ibufhi   = (short) 4000;
  828.  
  829.     recsav++;
  830.  
  831.     oldorec          = *recsav;    /* save output record (struct) */
  832.  
  833.     recsav->ibuf     = (char *) &iobuf[4096];
  834.     recsav->ibufsiz  = (short) 4096;
  835.     recsav->ibufhd   = (short) 0;
  836.     recsav->ibuftl   = (short) 0;
  837.     recsav->ibuflow  = (short) 100;
  838.     recsav->ibufhi   = (short) 4000;
  839.  
  840.  
  841. #ifdef SET_RS232_INIT
  842.  
  843.     /* this ONLY works with TOS 1.2 or later!!! */
  844.     m68901reg   = Rsconf (baud, 0, -1, -1, -1, -1);
  845.  
  846.     scr         = m68901reg & 0xff;
  847.  
  848.     m68901reg >>= 8;
  849.     tsr         = m68901reg & 0xff;
  850.  
  851.     m68901reg >>= 8;
  852.     rsr         = m68901reg & 0xff;
  853.  
  854.     m68901reg >>= 8;
  855.     ucr         = m68901reg & 0xf8;
  856.  
  857.     Rsconf(-1, -1, ucr, -1, -1, -1);    /* turn off parity */
  858.  
  859. #endif
  860. }
  861.  
  862.  
  863.  
  864. /*------------------------------*/
  865. /*    bye            */
  866. /*------------------------------*/
  867. void bye (int excode)
  868. {
  869.     /*
  870.      *   reset to old I/O rec stuff, then exit
  871.      */
  872.     *recsav = oldorec;
  873.     recsav--;
  874.     *recsav = oldirec;
  875.  
  876. #ifdef USE_FONTS
  877.     fnt_normal ();
  878. #endif
  879.     Cconws ("\n\rExit t100...\n\r\n\r");
  880.  
  881.  
  882.     /*
  883.      *   reset kbrate!!!
  884.      */
  885.     Kbrate (kbinit, kbrpt);
  886.  
  887.  
  888.     exit (excode);
  889.  
  890.     /*NOTREACHED*/
  891. }
  892.  
  893.  
  894.  
  895. /*------------------------------*/
  896. /*    rs232cd            */
  897. /*------------------------------*/
  898. short rs232cd ()
  899. {
  900.  
  901. /*
  902.  * function: rs232cd
  903.  *   author: Steve Yelvington
  904.  *  purpose: checks for RS-232 carrier detect signal
  905.  *   return: 
  906.  *   values: 0 for no Carrier Detect
  907.  *           1 for Carried Detect
  908.  */
  909.  
  910.     register long    ssp;
  911.     register short *mfp;
  912.     register short    status;
  913.  
  914.     mfp    = ((short *) 0xfffffa00L);    /* base address of MFP */
  915.     ssp    = Super (0L);            /* enter supervisor mode */
  916.     status = *mfp;                /* get MFP status */
  917.     Super (ssp);                /* return to user mode */
  918.  
  919.     return (!(status & 0x0002));        /* check for carrier */
  920. }
  921.  
  922.  
  923.  
  924. /*------------------------------*/
  925. /*    dobreak            */
  926. /*------------------------------*/
  927. void dobreak ()
  928. {
  929.  
  930. /*
  931.  *    sends a break. currently unused...
  932.  */
  933.  
  934. #define _MSLP            386        /* tune this for delay */
  935. #define WAIT_MS(ms) \
  936. { \
  937.     register short _I,_MS=ms; \
  938.     for(;_MS>0;_MS--) \
  939.     for(_I=_MSLP;_I>0;_I--) \
  940.         ; \
  941. }
  942.  
  943. #ifdef SET_RS232_INIT
  944.     tsr |= 0x08;
  945.     Rsconf (-1, -1, -1, -1, tsr, -1);
  946.  
  947.     if (mintcookie)
  948.         Fselect (300, 0L, 0L, 0L);    /* sleep 300 milliseconds :-) */
  949.     else
  950.         WAIT_MS(300);            /* wait 300 ms :-( */
  951.  
  952.     tsr &= 0xf7;
  953.     Rsconf (-1, -1, -1, -1, tsr, -1);
  954. #endif
  955. }
  956.  
  957.