home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 340.lha / Lightning_Dial! / ldial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-26  |  27.3 KB  |  769 lines

  1. /*
  2.    Lightning Dial!  by David R. Stromberger.
  3.    Copyright (C) 1989
  4.  
  5.    Cornerstone Software.
  6.    E. 18625 Riverway
  7.    Greenacres Wa, 99016
  8.    (509) 928-8670
  9.  
  10.    This source code was written for the MANX 3.6a C compiler and is
  11.    compiled as follows:  
  12.  
  13.                  cc +l ldial
  14.                  ln ldial -lc32
  15.  
  16.    Lightning Dial! was written to demonstrate how easy it is to use
  17.    the serial port.  You may copy and modify this code 'till you drop.
  18. */
  19.  
  20.  
  21. #include <stdio.h>             /* standard stuff like getchar() */
  22. #include <exec/types.h>        /* lots of defines for things like VOID */
  23. #include <devices/serial.h>    /* serial port info */
  24. #include <exec/exec.h>         /* memory handling.  MEMF_PUBLIC ect... */
  25. #include <intuition/intuition.h> /* intuition info... what else? */
  26. #include <hardware/cia.h>        /* for the hangup routine */
  27. #include <exec/io.h>
  28. #include <exec/memory.h>
  29. #include <libraries/dos.h>
  30.  
  31.  
  32. #undef FOREVER                      /* destroy the define that intuiton
  33.                                        does and make our own. 
  34.                                      */
  35. #define FOREVER        for(;;)      /* a forever loop, never end */
  36.  
  37. struct IntuitionBase *IntuitionBase;   /* pointer to intuition */
  38. struct GfxBase *GfxBase;               /* pointer to gfx lib */
  39. extern struct MsgPort *CreatePort();   /* make Manx warnings shut up */
  40. struct IOExtSer *WriteSer_Req;         /* the serial device name,stuct */
  41. struct IOExtSer *ReadSer_Req;          /* for reading from the modem */
  42. struct Window *wd;                     /* pointer to the window */
  43. struct RastPort *rpG;                  /* pointer to a rastport */
  44. char rs_out[1];                        /* output character buffer */
  45. char rs_in[1];                         /* input character buffer which we
  46.                                           don't use here, but it's there
  47.                                           in the case that you may
  48.                                           want to expand on this system.
  49.                                         */
  50.  
  51. int nodialflag,ticks,dloop;             /* some stuff */
  52. char phonenumber[20];                   /* # to dial */
  53.  
  54. /* start of some fancy POWERWINDOWS code */
  55.  
  56. SHORT BorderVectors1[] = {
  57.         0,0,
  58.         18,0,
  59.         18,11,
  60.         0,11,
  61.         0,0
  62. };
  63. struct Border Border1 = {
  64.         -1,-1,  /* XY origin relative to container TopLeft */
  65.         3,0,JAM1,       /* front pen, back pen and drawmode */
  66.         5,      /* number of XY vectors */
  67.         BorderVectors1, /* pointer to XY vectors */
  68.         NULL    /* next border in list */
  69. };
  70.  
  71. struct Gadget Gadget11 = {
  72.         NULL,   /* next gadget */
  73.         102,54, /* origin XY of hit box relative to window TopLeft */
  74.         17,10,  /* hit box width and height */
  75.         NULL,   /* gadget flags */
  76.         RELVERIFY,      /* activation flags */
  77.         BOOLGADGET,     /* gadget type flags */
  78.         (APTR)&Border1, /* gadget border or image to be rendered */
  79.         NULL,   /* alternate imagery for selection */
  80.         NULL,   /* first IntuiText structure */
  81.         NULL,   /* gadget mutual-exclude long word */
  82.         NULL,   /* SpecialInfo structure */
  83.         11,   /* user-definable data */
  84.         NULL    /* pointer to user-definable data */
  85. };
  86.  
  87. SHORT BorderVectors2[] = {
  88.         0,0,
  89.         18,0,
  90.         18,11,
  91.         0,11,
  92.         0,0
  93. };
  94. struct Border Border2 = {
  95.         -1,-1,  /* XY origin relative to container TopLeft */
  96.         3,0,JAM1,       /* front pen, back pen and drawmode */
  97.         5,      /* number of XY vectors */
  98.         BorderVectors2, /* pointer to XY vectors */
  99.         NULL    /* next border in list */
  100. };
  101.  
  102. struct Gadget Gadget10 = {
  103.         &Gadget11,      /* next gadget */
  104.         102,41, /* origin XY of hit box relative to window TopLeft */
  105.         17,10,  /* hit box width and height */
  106.         NULL,   /* gadget flags */
  107.         RELVERIFY,      /* activation flags */
  108.         BOOLGADGET,     /* gadget type flags */
  109.         (APTR)&Border2, /* gadget border or image to be rendered */
  110.         NULL,   /* alternate imagery for selection */
  111.         NULL,   /* first IntuiText structure */
  112.         NULL,   /* gadget mutual-exclude long word */
  113.         NULL,   /* SpecialInfo structure */
  114.         10,   /* user-definable data */
  115.         NULL    /* pointer to user-definable data */
  116. };
  117.  
  118. SHORT BorderVectors3[] = {
  119.         0,0,
  120.         18,0,
  121.         18,11,
  122.         0,11,
  123.         0,0
  124. };
  125. struct Border Border3 = {
  126.         -1,-1,  /* XY origin relative to container TopLeft */
  127.         3,0,JAM1,       /* front pen, back pen and drawmode */
  128.         5,      /* number of XY vectors */
  129.         BorderVectors3, /* pointer to XY vectors */
  130.         NULL    /* next border in list */
  131. };
  132.  
  133. struct Gadget Gadget9 = {
  134.         &Gadget10,      /* next gadget */
  135.         102,27, /* origin XY of hit box relative to window TopLeft */
  136.         17,10,  /* hit box width and height */
  137.         NULL,   /* gadget flags */
  138.         RELVERIFY,      /* activation flags */
  139.         BOOLGADGET,     /* gadget type flags */
  140.         (APTR)&Border3, /* gadget border or image to be rendered */
  141.         NULL,   /* alternate imagery for selection */
  142.         NULL,   /* first IntuiText structure */
  143.         NULL,   /* gadget mutual-exclude long word */
  144.         NULL,   /* SpecialInfo structure */
  145.         9,   /* user-definable data */
  146.         NULL    /* pointer to user-definable data */
  147. };
  148.  
  149. SHORT BorderVectors4[] = {
  150.         0,0,
  151.         18,0,
  152.         18,11,
  153.         0,11,
  154.         0,0
  155. };
  156. struct Border Border4 = {
  157.         -1,-1,  /* XY origin relative to container TopLeft */
  158.         3,0,JAM1,       /* front pen, back pen and drawmode */
  159.         5,      /* number of XY vectors */
  160.         BorderVectors4, /* pointer to XY vectors */
  161.         NULL    /* next border in list */
  162. };
  163.  
  164. struct Gadget Gadget8 = {
  165.         &Gadget9,       /* next gadget */
  166.         102,14, /* origin XY of hit box relative to window TopLeft */
  167.         17,10,  /* hit box width and height */
  168.         NULL,   /* gadget flags */
  169.         RELVERIFY,      /* activation flags */
  170.         BOOLGADGET,     /* gadget type flags */
  171.         (APTR)&Border4, /* gadget border or image to be rendered */
  172.         NULL,   /* alternate imagery for selection */
  173.         NULL,   /* first IntuiText structure */
  174.         NULL,   /* gadget mutual-exclude long word */
  175.         NULL,   /* SpecialInfo structure */
  176.         8,   /* user-definable data */
  177.         NULL    /* pointer to user-definable data */
  178. };
  179.  
  180. UBYTE Gadget7SIBuff[4] =
  181.         "180";
  182. struct StringInfo Gadget7SInfo = {
  183.         Gadget7SIBuff,  /* buffer where text will be edited */
  184.         NULL,   /* optional undo buffer */
  185.         0,      /* character position in buffer */
  186.         4,      /* maximum number of characters to allow */
  187.         0,      /* first displayed character buffer position */
  188.         0,0,0,0,0,      /* Intuition initialized and maintained variables */
  189.         0,      /* Rastport of gadget */
  190.         0,      /* initial value for integer gadgets */
  191.         NULL    /* alternate keymap (fill in if you set the flag) */
  192. };
  193.  
  194. SHORT BorderVectors5[] = {
  195.         0,0,
  196.         40,0,
  197.         40,9,
  198.         0,9,
  199.         0,0
  200. };
  201. struct Border Border5 = {
  202.         -1,-1,  /* XY origin relative to container TopLeft */
  203.         3,0,JAM1,       /* front pen, back pen and drawmode */
  204.         5,      /* number of XY vectors */
  205.         BorderVectors5, /* pointer to XY vectors */
  206.         NULL    /* next border in list */
  207. };
  208.  
  209. struct Gadget Gadget7 = {
  210.         &Gadget8,       /* next gadget */
  211.         121,67, /* origin XY of hit box relative to window TopLeft */
  212.         39,8,   /* hit box width and height */
  213.         NULL,   /* gadget flags */
  214.         RELVERIFY,      /* activation flags */
  215.         STRGADGET,      /* gadget type flags */
  216.         (APTR)&Border5, /* gadget border or image to be rendered */
  217.         NULL,   /* alternate imagery for selection */
  218.         NULL,   /* first IntuiText structure */
  219.         NULL,   /* gadget mutual-exclude long word */
  220.         (APTR)&Gadget7SInfo,    /* SpecialInfo structure */
  221.         7,   /* user-definable data */
  222.         NULL    /* pointer to user-definable data */
  223. };
  224.  
  225. SHORT BorderVectors6[] = {
  226.         0,0,
  227.         35,0,
  228.         35,49,
  229.         0,49,
  230.         0,0
  231. };
  232. struct Border Border6 = {
  233.         -1,-1,  /* XY origin relative to container TopLeft */
  234.         1,2,JAM1,       /* front pen, back pen and drawmode */
  235.         5,      /* number of XY vectors */
  236.         BorderVectors6, /* pointer to XY vectors */
  237.         NULL    /* next border in list */
  238. };
  239.  
  240. struct IntuiText IText1 = {
  241.         3,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  242.         1,21,   /* XY origin relative to container TopLeft */
  243.         NULL,   /* font pointer or NULL for default */
  244.         (UBYTE *)"HOLD",        /* pointer to text */
  245.         NULL    /* next IntuiText structure */
  246. };
  247.  
  248. struct Gadget Gadget6 = {
  249.         &Gadget7,       /* next gadget */
  250.         55,15,  /* origin XY of hit box relative to window TopLeft */
  251.         34,48,  /* hit box width and height */
  252.         NULL,   /* gadget flags */
  253.         RELVERIFY,      /* activation flags */
  254.         BOOLGADGET,     /* gadget type flags */
  255.         (APTR)&Border6, /* gadget border or image to be rendered */
  256.         NULL,   /* alternate imagery for selection */
  257.         &IText1,        /* first IntuiText structure */
  258.         NULL,   /* gadget mutual-exclude long word */
  259.         NULL,   /* SpecialInfo structure */
  260.         6,   /* user-definable data */
  261.         NULL    /* pointer to user-definable data */
  262. };
  263.  
  264. UBYTE Gadget5SIBuff[17] =
  265.         "Stromberger";
  266. struct StringInfo Gadget5SInfo = {
  267.         Gadget5SIBuff,  /* buffer where text will be edited */
  268.         NULL,   /* optional undo buffer */
  269.         0,      /* character position in buffer */
  270.         17,     /* maximum number of characters to allow */
  271.         0,      /* first displayed character buffer position */
  272.         0,0,0,0,0,      /* Intuition initialized and maintained variables */
  273.         0,      /* Rastport of gadget */
  274.         0,      /* initial value for integer gadgets */
  275.         NULL    /* alternate keymap (fill in if you set the flag) */
  276. };
  277.  
  278. SHORT BorderVectors7[] = {
  279.         0,0,
  280.         239,0,
  281.         239,9,
  282.         0,9,
  283.         0,0
  284. };
  285. struct Border Border7 = {
  286.         -1,-1,  /* XY origin relative to container TopLeft */
  287.         3,0,JAM1,       /* front pen, back pen and drawmode */
  288.         5,      /* number of XY vectors */
  289.         BorderVectors7, /* pointer to XY vectors */
  290.         NULL    /* next border in list */
  291. };
  292.  
  293. struct Gadget Gadget5 = {
  294.         &Gadget6,       /* next gadget */
  295.         121,55, /* origin XY of hit box relative to window TopLeft */
  296.         238,8,  /* hit box width and height */
  297.         NULL,   /* gadget flags */
  298.         RELVERIFY+STRINGCENTER, /* activation flags */
  299.         STRGADGET,      /* gadget type flags */
  300.         (APTR)&Border7, /* gadget border or image to be rendered */
  301.         NULL,   /* alternate imagery for selection */
  302.         NULL,   /* first IntuiText structure */
  303.         NULL,   /* gadget mutual-exclude long word */
  304.         (APTR)&Gadget5SInfo,    /* SpecialInfo structure */
  305.         5,   /* user-definable data */
  306.         NULL    /* pointer to user-definable data */
  307. };
  308.  
  309. UBYTE Gadget4SIBuff[17] =
  310.         "David R.";
  311. struct StringInfo Gadget4SInfo = {
  312.         Gadget4SIBuff,  /* buffer where text will be edited */
  313.         NULL,   /* optional undo buffer */
  314.         0,      /* character position in buffer */
  315.         17,     /* maximum number of characters to allow */
  316.         0,      /* first displayed character buffer position */
  317.         0,0,0,0,0,      /* Intuition initialized and maintained variables */
  318.         0,      /* Rastport of gadget */
  319.         0,      /* initial value for integer gadgets */
  320.         NULL    /* alternate keymap (fill in if you set the flag) */
  321. };
  322.  
  323. SHORT BorderVectors8[] = {
  324.         0,0,
  325.         239,0,
  326.         239,9,
  327.         0,9,
  328.         0,0
  329. };
  330. struct Border Border8 = {
  331.         -1,-1,  /* XY origin relative to container TopLeft */
  332.         3,0,JAM1,       /* front pen, back pen and drawmode */
  333.         5,      /* number of XY vectors */
  334.         BorderVectors8, /* pointer to XY vectors */
  335.         NULL    /* next border in list */
  336. };
  337.  
  338. struct Gadget Gadget4 = {
  339.         &Gadget5,       /* next gadget */
  340.         121,42, /* origin XY of hit box relative to window TopLeft */
  341.         238,8,  /* hit box width and height */
  342.         NULL,   /* gadget flags */
  343.         RELVERIFY+STRINGCENTER, /* activation flags */
  344.         STRGADGET,      /* gadget type flags */
  345.         (APTR)&Border8, /* gadget border or image to be rendered */
  346.         NULL,   /* alternate imagery for selection */
  347.         NULL,   /* first IntuiText structure */
  348.         NULL,   /* gadget mutual-exclude long word */
  349.         (APTR)&Gadget4SInfo,    /* SpecialInfo structure */
  350.         4,   /* user-definable data */
  351.         NULL    /* pointer to user-definable data */
  352. };
  353.  
  354. UBYTE Gadget3SIBuff[17] =
  355.         "By:";
  356. struct StringInfo Gadget3SInfo = {
  357.         Gadget3SIBuff,  /* buffer where text will be edited */
  358.         NULL,   /* optional undo buffer */
  359.         0,      /* character position in buffer */
  360.         17,     /* maximum number of characters to allow */
  361.         0,      /* first displayed character buffer position */
  362.         0,0,0,0,0,      /* Intuition initialized and maintained variables */
  363.         0,      /* Rastport of gadget */
  364.         0,      /* initial value for integer gadgets */
  365.         NULL    /* alternate keymap (fill in if you set the flag) */
  366. };
  367.  
  368. SHORT BorderVectors9[] = {
  369.         0,0,
  370.         239,0,
  371.         239,9,
  372.         0,9,
  373.         0,0
  374. };
  375. struct Border Border9 = {
  376.         -1,-1,  /* XY origin relative to container TopLeft */
  377.         3,0,JAM1,       /* front pen, back pen and drawmode */
  378.         5,      /* number of XY vectors */
  379.         BorderVectors9, /* pointer to XY vectors */
  380.         NULL    /* next border in list */
  381. };
  382.  
  383. struct Gadget Gadget3 = {
  384.         &Gadget4,       /* next gadget */
  385.         121,28, /* origin XY of hit box relative to window TopLeft */
  386.         238,8,  /* hit box width and height */
  387.         NULL,   /* gadget flags */
  388.         RELVERIFY+STRINGCENTER, /* activation flags */
  389.         STRGADGET,      /* gadget type flags */
  390.         (APTR)&Border9, /* gadget border or image to be rendered */
  391.         NULL,   /* alternate imagery for selection */
  392.         NULL,   /* first IntuiText structure */
  393.         NULL,   /* gadget mutual-exclude long word */
  394.         (APTR)&Gadget3SInfo,    /* SpecialInfo structure */
  395.         3,   /* user-definable data */
  396.         NULL    /* pointer to user-definable data */
  397. };
  398.  
  399. UBYTE Gadget2SIBuff[17] =
  400.         "Lightning Dial!";
  401. struct StringInfo Gadget2SInfo = {
  402.         Gadget2SIBuff,  /* buffer where text will be edited */
  403.         NULL,   /* optional undo buffer */
  404.         0,      /* character position in buffer */
  405.         17,     /* maximum number of characters to allow */
  406.         0,      /* first displayed character buffer position */
  407.         0,0,0,0,0,      /* Intuition initialized and maintained variables */
  408.         0,      /* Rastport of gadget */
  409.         0,      /* initial value for integer gadgets */
  410.         NULL    /* alternate keymap (fill in if you set the flag) */
  411. };
  412.  
  413. SHORT BorderVectors10[] = {
  414.         0,0,
  415.         239,0,
  416.         239,9,
  417.         0,9,
  418.         0,0
  419. };
  420. struct Border Border10 = {
  421.         -1,-1,  /* XY origin relative to container TopLeft */
  422.         3,0,JAM1,       /* front pen, back pen and drawmode */
  423.         5,      /* number of XY vectors */
  424.         BorderVectors10,        /* pointer to XY vectors */
  425.         NULL    /* next border in list */
  426. };
  427.  
  428. struct Gadget Gadget2 = {
  429.         &Gadget3,       /* next gadget */
  430.         121,15, /* origin XY of hit box relative to window TopLeft */
  431.         238,8,  /* hit box width and height */
  432.         NULL,   /* gadget flags */
  433.         RELVERIFY+STRINGCENTER, /* activation flags */
  434.         STRGADGET,      /* gadget type flags */
  435.         (APTR)&Border10,        /* gadget border or image to be rendered */
  436.         NULL,   /* alternate imagery for selection */
  437.         NULL,   /* first IntuiText structure */
  438.         NULL,   /* gadget mutual-exclude long word */
  439.         (APTR)&Gadget2SInfo,    /* SpecialInfo structure */
  440.         2,   /* user-definable data */
  441.         NULL    /* pointer to user-definable data */
  442. };
  443.  
  444. SHORT BorderVectors11[] = {
  445.         0,0,
  446.         35,0,
  447.         35,49,
  448.         0,49,
  449.         0,0
  450. };
  451. struct Border Border11 = {
  452.         -1,-1,  /* XY origin relative to container TopLeft */
  453.         1,2,JAM1,       /* front pen, back pen and drawmode */
  454.         5,      /* number of XY vectors */
  455.         BorderVectors11,        /* pointer to XY vectors */
  456.         NULL    /* next border in list */
  457. };
  458.  
  459. struct IntuiText IText2 = {
  460.         3,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  461.         2,21,   /* XY origin relative to container TopLeft */
  462.         NULL,   /* font pointer or NULL for default */
  463.         (UBYTE *)"BYE!",        /* pointer to text */
  464.         NULL    /* next IntuiText structure */
  465. };
  466.  
  467. struct Gadget Gadget1 = {
  468.         &Gadget2,       /* next gadget */
  469.         11,15,  /* origin XY of hit box relative to window TopLeft */
  470.         34,48,  /* hit box width and height */
  471.         NULL,   /* gadget flags */
  472.         RELVERIFY,      /* activation flags */
  473.         BOOLGADGET,     /* gadget type flags */
  474.         (APTR)&Border11,        /* gadget border or image to be rendered */
  475.         NULL,   /* alternate imagery for selection */
  476.         &IText2,        /* first IntuiText structure */
  477.         NULL,   /* gadget mutual-exclude long word */
  478.         NULL,   /* SpecialInfo structure */
  479.         1,   /* user-definable data */
  480.         NULL    /* pointer to user-definable data */
  481. };
  482.  
  483. #define GadgetList1 Gadget1
  484.  
  485. struct IntuiText IText8 = {
  486.         1,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  487.         196,67, /* XY origin relative to container TopLeft */
  488.         NULL,   /* font pointer or NULL for default */
  489.         (UBYTE *)"LIGHTNING DIAL!",     /* pointer to text */
  490.         NULL    /* next IntuiText structure */
  491. };
  492.  
  493. struct IntuiText IText7 = {
  494.         1,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  495.         22,67,  /* XY origin relative to container TopLeft */
  496.         NULL,   /* font pointer or NULL for default */
  497.         (UBYTE *)"Wait ~Ticks:",        /* pointer to text */
  498.         &IText8 /* next IntuiText structure */
  499. };
  500.  
  501. struct IntuiText IText6 = {
  502.         1,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  503.         102,55, /* XY origin relative to container TopLeft */
  504.         NULL,   /* font pointer or NULL for default */
  505.         (UBYTE *)"4:",  /* pointer to text */
  506.         &IText7 /* next IntuiText structure */
  507. };
  508.  
  509. struct IntuiText IText5 = {
  510.         1,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  511.         102,42, /* XY origin relative to container TopLeft */
  512.         NULL,   /* font pointer or NULL for default */
  513.         (UBYTE *)"3:",  /* pointer to text */
  514.         &IText6 /* next IntuiText structure */
  515. };
  516.  
  517. struct IntuiText IText4 = {
  518.         1,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  519.         102,28, /* XY origin relative to container TopLeft */
  520.         NULL,   /* font pointer or NULL for default */
  521.         (UBYTE *)"2:",  /* pointer to text */
  522.         &IText5 /* next IntuiText structure */
  523. };
  524.  
  525. struct IntuiText IText3 = {
  526.         1,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  527.         102,15, /* XY origin relative to container TopLeft */
  528.         NULL,   /* font pointer or NULL for default */
  529.         (UBYTE *)"1:",  /* pointer to text */
  530.         &IText4 /* next IntuiText structure */
  531. };
  532.  
  533. #define IntuiTextList1 IText3
  534.  
  535. struct NewWindow NewWindowStructure1 = {
  536.         127,65, /* window XY origin relative to TopLeft of screen */
  537.         377,78, /* window width and height */
  538.         1,2,    /* detail and block pens */
  539.         GADGETUP+GADGETDOWN,   /* IDCMP flags */
  540.         WINDOWDRAG+WINDOWDEPTH+ACTIVATE+NOCAREREFRESH,  /* other window flags */
  541.         &Gadget1,       /* first gadget in gadget list */
  542.         NULL,   /* custom CHECKMARK imagery */
  543.         (UBYTE *)"(C) 1989 CORNERSTONE SOFTWARE",       /* window title */
  544.         NULL,   /* custom screen pointer */
  545.         NULL,   /* custom bitmap */
  546.         5,5,    /* minimum width and height */
  547.         -1,-1,  /* maximum width and height */
  548.         WBENCHSCREEN    /* destination screen type */
  549. };
  550.  
  551.  
  552. /* end of PowerWindows source generation */
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559. VOID              /* open the serial device. */
  560. Open_Serial()
  561. {
  562.  
  563. /*
  564.    just read "Amiga Programmers Handbook Volume II" if you want to know
  565.    what all this stuff does. 
  566.  
  567.    This program has two serial ports, one for reading, and one for
  568.    writing.  This will allow you to expand on this program with little
  569.    trouble.
  570. */
  571.  
  572. ReadSer_Req = (struct IOExtSer *)AllocMem((long)sizeof(*ReadSer_Req),MEMF_PUBLIC|MEMF_CLEAR);
  573. ReadSer_Req->io_SerFlags = SERF_SHARED|SERF_XDISABLED;
  574. ReadSer_Req->IOSer.io_Message.mn_ReplyPort = CreatePort("Read_RS",0);
  575. if(OpenDevice(SERIALNAME,NULL,ReadSer_Req,NULL))
  576.    {
  577.    puts("Can not open Read device.\n");
  578.    DeletePort(ReadSer_Req->IOSer.io_Message.mn_ReplyPort);
  579.    FreeMem(ReadSer_Req,(long)sizeof(*ReadSer_Req));
  580.    exit(TRUE);
  581.    }
  582. ReadSer_Req->IOSer.io_Command = CMD_READ;
  583. ReadSer_Req->IOSer.io_Length = 1L;
  584. ReadSer_Req->IOSer.io_Data = (APTR) &rs_in[0];
  585. WriteSer_Req = (struct IOExtSer *)AllocMem((long)sizeof(*WriteSer_Req),MEMF_PUBLIC|MEMF_CLEAR);
  586. WriteSer_Req->io_SerFlags = SERF_SHARED|SERF_XDISABLED;
  587. WriteSer_Req->IOSer.io_Message.mn_ReplyPort = CreatePort("Write_RS",0);
  588. if(OpenDevice(SERIALNAME,NULL,WriteSer_Req,NULL))
  589.    {
  590.    puts("Can not open Write device.\n");
  591.    DeletePort(WriteSer_Req->IOSer.io_Message.mn_ReplyPort);
  592.    FreeMem(WriteSer_Req,(long)sizeof(*WriteSer_Req));
  593.    DeletePort(ReadSer_Req->IOSer.io_Message.mn_ReplyPort);
  594.    FreeMem(ReadSer_Req,(long)sizeof(*ReadSer_Req));
  595.    exit(TRUE);
  596.    }
  597. WriteSer_Req->IOSer.io_Command = CMD_WRITE;
  598. WriteSer_Req->IOSer.io_Length = 1L;
  599. WriteSer_Req->IOSer.io_Data = (APTR) &rs_out[0];
  600. ReadSer_Req->io_SerFlags = SERF_SHARED|SERF_XDISABLED;
  601. ReadSer_Req->io_Baud = 1200L;       
  602. ReadSer_Req->io_ReadLen = 8;      
  603. ReadSer_Req->io_WriteLen = 8;     
  604. ReadSer_Req->io_CtlChar = 1L;
  605. ReadSer_Req->IOSer.io_Command = SDCMD_SETPARAMS;
  606. DoIO(ReadSer_Req);
  607. ReadSer_Req->IOSer.io_Command = CMD_READ;
  608. BeginIO(ReadSer_Req);
  609.  
  610. VOID
  611. Close_Serial()                /* close the serial port to be clean */
  612. {
  613. AbortIO(WriteSer_Req);        /* make sure no messages are pending */
  614. CloseDevice(WriteSer_Req);    /* close the write device */
  615. DeletePort(WriteSer_Req->IOSer.io_Message.mn_ReplyPort);  /* kill it */
  616. FreeMem(WriteSer_Req,(long)sizeof(*WriteSer_Req));       /* free the mem */
  617.  
  618. AbortIO(ReadSer_Req);             /* do same as above exect for readser */
  619. CloseDevice(ReadSer_Req);
  620. DeletePort(ReadSer_Req->IOSer.io_Message.mn_ReplyPort);
  621. FreeMem(ReadSer_Req,(long)sizeof(*ReadSer_Req));
  622. }
  623.  
  624. VOID
  625. Send_Char(character)         /* send a character to the modem */
  626. char character;
  627. {
  628. rs_out[0] = character;       /* put it in the buffer */
  629. DoIO(WriteSer_Req);          /* dump it to the modem */
  630. }
  631.  
  632. VOID                         /* dial a phone number */
  633. Dial(phone_number)
  634. char *phone_number;          /* pointer to a phone number to dial */
  635. {
  636. int index=0;
  637. while(phone_number[index] != NULL)    /* send it char by char */
  638.     {
  639.     Send_Char(phone_number[index]);
  640.     index+=1;
  641.     }
  642. }
  643.  
  644. VOID
  645. DTR()          /* hang up the modem via DTR bit */
  646. {
  647. struct CIA *cia_ptr;   /* initialize a pointer to a CIA structure     */
  648. cia_ptr = 0xBFD000;    /* point at the cia register A (see the RKM )  */
  649. cia_ptr->ciaddra |= CIAF_COMDTR;  
  650.                                   
  651. cia_ptr->ciapra |= CIAF_COMDTR;          /* set DTR to low value */
  652. Delay(5L);
  653. cia_ptr->ciapra &= ~CIAF_COMDTR;         /* set DTR to high value */
  654. }
  655.  
  656. VOID                   /* finish up and return to CLI */
  657. Go2Bed()
  658. {
  659. DTR();                      /* make sure we don't try to dial again */
  660. Close_Serial();              /* close the serial ports */
  661. CloseLibrary(GfxBase);
  662. CloseLibrary(IntuitionBase); /* close the library we opened */
  663. CloseWindow(wd);             /* close the window */
  664. exit(TRUE);                  /* exit to CLI */
  665. }
  666.  
  667. VOID            /* handle an intuition event */
  668. HandleEvent(object)
  669. struct Gadget *object;
  670. {
  671. long id;
  672.  
  673. id = object->GadgetID;      /* get the message */
  674.  
  675. switch(id)
  676.    {
  677.    case 1:           /* quit the program */
  678.          Go2Bed();   /* good bye, and good night */
  679.          break;
  680.    case 6:           /* hold button */
  681.          nodialflag=!nodialflag;   /* toggle dialing on and off */
  682.          dloop=ticks;
  683.          DTR(); Delay(25L); DTR();
  684.          break;
  685.    case 7:        /* modify ticks */
  686.          ticks = atol(Gadget7SIBuff);
  687.          break;
  688.    case 8:          /* phone 1 */
  689.          strcpy(phonenumber,Gadget2SIBuff);  /* establish new phone num */         
  690.          nodialflag = FALSE;
  691.          dloop=ticks;
  692.          SetWindowTitles(wd,phonenumber,-1);
  693.          break;
  694.    case 9:       /* phone 2 */
  695.          nodialflag = FALSE;
  696.          strcpy(phonenumber,Gadget3SIBuff);  /* establish new phone num */
  697.          dloop=ticks;
  698.          SetWindowTitles(wd,phonenumber,-1);
  699.          break;
  700.    case 10:      /* phone 3 */
  701.          strcpy(phonenumber,Gadget4SIBuff);  /* establish new phone num */
  702.          nodialflag = FALSE;
  703.          dloop=ticks;
  704.          SetWindowTitles(wd,phonenumber,-1);
  705.          break;
  706.    case 11:      /* phone 4 */
  707.          strcpy(phonenumber,Gadget5SIBuff);  /* establish new phone num */
  708.          nodialflag = FALSE;
  709.          dloop=ticks;
  710.          SetWindowTitles(wd,phonenumber,-1);
  711.          break;
  712.    }
  713. }
  714.  
  715. /** =============================================================== **/
  716.  
  717. VOID               /* main program, put it all together */
  718. main()    /* get some args from CLI */
  719. {
  720. struct IntuiMessage *ms;   /* pointer to an intuimessage structure */
  721.         ULONG class;
  722.         struct Gadget *object;   /* gadget pointer */
  723.  
  724.  
  725.  
  726. ticks = 180;    /* default ticks */
  727.  
  728. Open_Serial();  /* don't forget to open it up first */
  729. IntuitionBase=OpenLibrary("intuition.library",0L);  /* open intuition */
  730. GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L);
  731.  
  732. wd = OpenWindow(&NewWindowStructure1);              /* open the window */
  733. rpG = wd->RPort;        /* get a rastport pointer for the window */
  734. PrintIText(rpG,&IntuiTextList1,0L,0L);  /* Print the text */
  735.  
  736. nodialflag = TRUE;  /* don't dial right off the bat */
  737.  
  738. FOREVER
  739.     {       /* if its ok to dial... */
  740.     if((nodialflag == FALSE)&&(phonenumber[0] != NULL))
  741.       {
  742.       Dial("ATDT");       /* at command */
  743.       Dial(phonenumber);  /* the number */
  744.       Dial("\r"); 
  745.       }
  746.  
  747.     for(dloop=0;dloop<ticks;dloop++)      /* loop 'ticks' times */
  748.       {         /* get a message */
  749.        if((ms=(struct IntuiMessage *)GetMsg(wd->UserPort))!=NULL)
  750.                         {
  751.                                 object = (struct Gadget *)(ms->IAddress);  /* Gadget */
  752.                                 class = ms->Class;
  753.                                 ReplyMsg(ms);
  754.                                 if (( class == GADGETUP ) ||    /* Gagdets */
  755.                                         ( class == GADGETDOWN ))
  756.                                          {   /* handle the message */
  757.                                          HandleEvent(object);
  758.                                          }
  759.                         }
  760.       Delay(1L);                             /* tick */
  761.       }   /* if its ok to dial, then we need to do this first */
  762.     if((nodialflag == FALSE)&&(phonenumber[0] != NULL))
  763.       {
  764.       DTR();              /* hang up the phone via dropping DTR */
  765.       Delay(25L);         /* let modem recover */
  766.       }
  767.     }
  768. }