home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / MAILMIND.ZOO / NETMSG.C < prev    next >
Text File  |  1992-03-11  |  4KB  |  144 lines

  1. /* netmsg.c - TSR to receive messages
  2.  * Thomas A. Marciniak, M.D. = ytm@nihccpc1.bitnet
  3.  * Division of Cancer Prevention & Control, NCI
  4.  */
  5.  
  6. /* Revision history:
  7.  * 1.01  ytm  02/06/91  add control over UR popup placement
  8.  * 1.00  ytm  01/31/91  first release
  9.  */
  10.  
  11. /* Program notes:
  12.  * This program uses the Tesseract TSR library.
  13.  * Current versions are specific for TurboC.
  14.  */
  15.  
  16. #include <local.h>                      /* standard definitions */
  17. #include "netbios.h"
  18. #include "tess.h"                       /* Include file for TesSeRact */
  19.  
  20. /* defines */
  21. #define TSR_FAILURE 100
  22. #define MSG_MASK    0xef00
  23. #define VIDEO_SEG   0xb800
  24. #define UR_CORNER   0x9e
  25. #define NO_POP      0xff
  26. #define USER_NUM    0xff                /* receive any */
  27. #define MAXPACKET   512
  28. #define STATE_IDLE  0
  29. #define STATE_INIT  1
  30. #define STATE_RCV   -1
  31.  
  32. /* special externals for TurboC */
  33. extern void _restorezero(void);
  34. extern unsigned _psp;                   /* segment address of PSP */
  35. extern unsigned __heapbase;             /* undocumented offset of base of */
  36.                                         /*   TC 1.5 heap area */
  37. extern unsigned _heaplen = 0;
  38. extern unsigned _stklen = 256;
  39.  
  40. /* globals */
  41. NCB    Ncb;
  42. char   caPacket[MAXLINE];
  43. short  iState = STATE_INIT;
  44.  
  45. /* function prototypes */
  46. short main(void);
  47. void NetReceive(void interrupt (*pPostFn)());
  48. void interrupt Post(void);
  49.  
  50. void NetReceive(void interrupt (*pPostFn)())
  51. {
  52. memset(&Ncb, 0, sizeof(NCB));
  53. Ncb.NCB_COMMAND = RECEIVE_DATAGRAM;
  54. Ncb.NCB_NUM = USER_NUM;
  55. Ncb.NCB_LENGTH = MAXLINE;
  56. Ncb.NCB_BUFFER = (void far *) caPacket;
  57. Ncb.NCB_POST = pPostFn;
  58. Ncb.NCB_CMD_CPLT = 0xFF;
  59. _ES = FP_SEG(&Ncb);
  60. _BX = FP_OFF(&Ncb);
  61. _AX = 0x0100;
  62. geninterrupt(0x5c);
  63. } /* NetReceive */ 
  64.  
  65. void interrupt Post(void)
  66. {
  67. iState = STATE_RCV;
  68. } /* Post */
  69.  
  70. /* check for background processing */
  71. unsigned far pascal TsrBackCheck(void)
  72. {
  73. return(iState);
  74. } /* TsrBackCheck */
  75.  
  76. /* background program */
  77. void far pascal TsrBackProc(void)
  78. {
  79. short    i = 0;
  80. short    iStop;
  81. string   s;
  82. if (iState != STATE_INIT)
  83.   {
  84.   if (Ncb.NCB_CMD_CPLT == 0)
  85.     {
  86.     TessBeep();
  87.     if (Ncb.NCB_LENGTH < 3)
  88.       {
  89.       if (Ncb.NCB_LENGTH > 1) i = (caPacket[1] - '0') << 1;
  90.       if (i > MAXLINE) i = 0;
  91.       poke(VIDEO_SEG, UR_CORNER - i, MSG_MASK | caPacket[0]);
  92.       }
  93.     else
  94.       {
  95.       for (s = Ncb.NCB_CALLNAME; *s && *s != ' '; i += 2)
  96.         poke(VIDEO_SEG, i, MSG_MASK | *s++);
  97.       poke(VIDEO_SEG, i, MSG_MASK | ':');
  98.       i += 2;
  99.       poke(VIDEO_SEG, i, MSG_MASK | ' ');
  100.       i += 2;
  101.       iStop = (Ncb.NCB_LENGTH << 1) + i;
  102.       for (s = caPacket; i < iStop; i += 2)
  103.         poke(VIDEO_SEG, i, MSG_MASK | *s++);
  104.       poke(VIDEO_SEG, i, MSG_MASK | ' ');
  105.       }
  106.     }
  107.   }
  108. iState = STATE_IDLE;
  109. NetReceive(Post);
  110. } /* TsrBackProc */
  111.  
  112. /* clean up on way out */
  113. void far pascal TsrCleanUp(unsigned InitOrShutdown)
  114. {
  115. _restorezero();
  116. } /* TsrCleanUp */
  117.  
  118. /* main */
  119. short main(void)
  120. {
  121. char far *pcfStack1;                    /* Pointer to top of Popup Stack */
  122. char far *pcfStack2;                    /* Pointer to top of Background */
  123.                                         /*   stack area */
  124. short  iRetCode = TSR_FAILURE;          /* return code */
  125. struct SREGS Sreg;    
  126. word   wID;                             /* TSR Identification Number */
  127. word   wCodeSize;
  128. pcfStack1 = MK_FP(_DS, __heapbase + _heaplen + (_stklen / 2) - 16);
  129. pcfStack2 = MK_FP(_DS, __heapbase + _heaplen + _stklen - 16);
  130. TsSetStack(pcfStack1, pcfStack2);       /* Set Popup Stack to pcfStack1 */
  131.                                         /*   background stack to pcfStack2 */
  132. if (TsCheckResident("NETMSG  ", &wID) != 0xffff)
  133.   {
  134.   segread(&Sreg);                       /* ALLSTACK variant below */
  135.   wCodeSize = (((__heapbase + 16 + _heaplen + _stklen) >> 4)
  136.                + Sreg.ds) - _psp;
  137.   iRetCode = TsDoInit(NO_POP, NO_POP, TSRUSEBACK, wCodeSize);
  138.   }
  139. if (iRetCode) TessBeep();
  140. return(iRetCode);
  141. } /* main */
  142.  
  143.  
  144.