home *** CD-ROM | disk | FTP | other *** search
- /* netmsg.c - TSR to receive messages
- * Thomas A. Marciniak, M.D. = ytm@nihccpc1.bitnet
- * Division of Cancer Prevention & Control, NCI
- */
-
- /* Revision history:
- * 1.01 ytm 02/06/91 add control over UR popup placement
- * 1.00 ytm 01/31/91 first release
- */
-
- /* Program notes:
- * This program uses the Tesseract TSR library.
- * Current versions are specific for TurboC.
- */
-
- #include <local.h> /* standard definitions */
- #include "netbios.h"
- #include "tess.h" /* Include file for TesSeRact */
-
- /* defines */
- #define TSR_FAILURE 100
- #define MSG_MASK 0xef00
- #define VIDEO_SEG 0xb800
- #define UR_CORNER 0x9e
- #define NO_POP 0xff
- #define USER_NUM 0xff /* receive any */
- #define MAXPACKET 512
- #define STATE_IDLE 0
- #define STATE_INIT 1
- #define STATE_RCV -1
-
- /* special externals for TurboC */
- extern void _restorezero(void);
- extern unsigned _psp; /* segment address of PSP */
- extern unsigned __heapbase; /* undocumented offset of base of */
- /* TC 1.5 heap area */
- extern unsigned _heaplen = 0;
- extern unsigned _stklen = 256;
-
- /* globals */
- NCB Ncb;
- char caPacket[MAXLINE];
- short iState = STATE_INIT;
-
- /* function prototypes */
- short main(void);
- void NetReceive(void interrupt (*pPostFn)());
- void interrupt Post(void);
-
- void NetReceive(void interrupt (*pPostFn)())
- {
- memset(&Ncb, 0, sizeof(NCB));
- Ncb.NCB_COMMAND = RECEIVE_DATAGRAM;
- Ncb.NCB_NUM = USER_NUM;
- Ncb.NCB_LENGTH = MAXLINE;
- Ncb.NCB_BUFFER = (void far *) caPacket;
- Ncb.NCB_POST = pPostFn;
- Ncb.NCB_CMD_CPLT = 0xFF;
- _ES = FP_SEG(&Ncb);
- _BX = FP_OFF(&Ncb);
- _AX = 0x0100;
- geninterrupt(0x5c);
- } /* NetReceive */
-
- void interrupt Post(void)
- {
- iState = STATE_RCV;
- } /* Post */
-
- /* check for background processing */
- unsigned far pascal TsrBackCheck(void)
- {
- return(iState);
- } /* TsrBackCheck */
-
- /* background program */
- void far pascal TsrBackProc(void)
- {
- short i = 0;
- short iStop;
- string s;
- if (iState != STATE_INIT)
- {
- if (Ncb.NCB_CMD_CPLT == 0)
- {
- TessBeep();
- if (Ncb.NCB_LENGTH < 3)
- {
- if (Ncb.NCB_LENGTH > 1) i = (caPacket[1] - '0') << 1;
- if (i > MAXLINE) i = 0;
- poke(VIDEO_SEG, UR_CORNER - i, MSG_MASK | caPacket[0]);
- }
- else
- {
- for (s = Ncb.NCB_CALLNAME; *s && *s != ' '; i += 2)
- poke(VIDEO_SEG, i, MSG_MASK | *s++);
- poke(VIDEO_SEG, i, MSG_MASK | ':');
- i += 2;
- poke(VIDEO_SEG, i, MSG_MASK | ' ');
- i += 2;
- iStop = (Ncb.NCB_LENGTH << 1) + i;
- for (s = caPacket; i < iStop; i += 2)
- poke(VIDEO_SEG, i, MSG_MASK | *s++);
- poke(VIDEO_SEG, i, MSG_MASK | ' ');
- }
- }
- }
- iState = STATE_IDLE;
- NetReceive(Post);
- } /* TsrBackProc */
-
- /* clean up on way out */
- void far pascal TsrCleanUp(unsigned InitOrShutdown)
- {
- _restorezero();
- } /* TsrCleanUp */
-
- /* main */
- short main(void)
- {
- char far *pcfStack1; /* Pointer to top of Popup Stack */
- char far *pcfStack2; /* Pointer to top of Background */
- /* stack area */
- short iRetCode = TSR_FAILURE; /* return code */
- struct SREGS Sreg;
- word wID; /* TSR Identification Number */
- word wCodeSize;
- pcfStack1 = MK_FP(_DS, __heapbase + _heaplen + (_stklen / 2) - 16);
- pcfStack2 = MK_FP(_DS, __heapbase + _heaplen + _stklen - 16);
- TsSetStack(pcfStack1, pcfStack2); /* Set Popup Stack to pcfStack1 */
- /* background stack to pcfStack2 */
- if (TsCheckResident("NETMSG ", &wID) != 0xffff)
- {
- segread(&Sreg); /* ALLSTACK variant below */
- wCodeSize = (((__heapbase + 16 + _heaplen + _stklen) >> 4)
- + Sreg.ds) - _psp;
- iRetCode = TsDoInit(NO_POP, NO_POP, TSRUSEBACK, wCodeSize);
- }
- if (iRetCode) TessBeep();
- return(iRetCode);
- } /* main */
-
-