home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / MAILMIND.ZOO / NETMSG.ASM < prev    next >
Assembly Source File  |  1992-03-11  |  6KB  |  232 lines

  1.  TITLE NETMSG.ASM --  TSR to receive messages
  2. ;Thomas A. Marciniak, M.D. = ytm@nihccpc1.bitnet
  3. ;Division of Cancer Prevention & Control, NCI
  4.  
  5. ;Revision history:
  6. ;1.01  ytm  02/19/91  correct uninitialized use of bp
  7. ;1.00  ytm  02/05/91  first release
  8.  
  9. ;Program notes:
  10. ;This program uses the Tesseract TSR library.
  11. ;Modify for:
  12. ;  Monochrome monitor;
  13. ;  Second video page;
  14. ;  Graphics skip.
  15.  
  16.  PAGE 60,80
  17.  LOCALS
  18. .MODEL tiny
  19.  
  20.  INCLUDE NETBIOS.INC
  21.  
  22. ;equates
  23. MSG_ATTR    EQU 0efh
  24. VIDEO_SEG   EQU 0b800h
  25. UR_CORNER   EQU 09eh
  26. MAXLINE     EQU 81
  27. STATE_IDLE  EQU 0
  28. STATE_INIT  EQU 1
  29. STATE_RCV   EQU 2
  30.  
  31. ;external refererences
  32. EXTRN TESSBEEP:NEAR
  33. EXTRN TSDOINIT:NEAR
  34. EXTRN TSCHECKRESIDENT:NEAR
  35. EXTRN TSSETSTACK:NEAR
  36.  
  37. .CODE
  38.  
  39. ;globals
  40. State      DW STATE_INIT                ;state flag
  41. NetmsgNum  DW 0                         ;ID number
  42. NetmsgName DB 'NETMSG  '                ;Identification string
  43. Packet     DB MAXLINE DUP (0)           ;message buffer
  44. Ncb        NCB_STRUC <>
  45.  
  46. ;posting routine for NETBIOS receive datagram
  47. Post    PROC    FAR
  48.         ASSUME cs:_TEXT
  49.     mov    cs:[State], STATE_RCV
  50.     iret    
  51. Post    ENDP
  52.  
  53. ;TesSeRact Entry Points
  54. PUBLIC  TSRUSERPROC, TSRTIMERPROC, TSRBACKCHECK, TSRMAIN, TSRBACKPROC
  55. PUBLIC  TSRCLEANUP
  56.  
  57. ;NULL procedures
  58. TSRUSERPROC:
  59. TSRMAIN:
  60. TSRCLEANUP:
  61. TSRTIMERPROC:
  62.         ret
  63.  
  64. TSRBACKCHECK PROC NEAR
  65.         ASSUME cs:_TEXT, ds:_TEXT
  66.         mov     ax, [State]
  67.         ret
  68. TSRBACKCHECK ENDP
  69.  
  70. TSRBACKPROC PROC NEAR
  71.         ASSUME cs:_TEXT, ds:_TEXT
  72.         push    es
  73.         push    di
  74.         push    si
  75.     cmp    WORD PTR [State], STATE_INIT
  76.         jne     @@ChkCmdCplt
  77.     jmp     @@NetRcv
  78. @@ChkCmdCplt:
  79.     cmp    BYTE PTR [Ncb.NCB_CMD_CPLT], 0 ;0 = receive OK
  80.         je      @@DoMsg
  81.     jmp    @@NetRcv
  82. @@DoMsg:
  83.     call    TESSBEEP
  84.     xor    si, si                  ;displacement for character store
  85.     mov    ax, VIDEO_SEG
  86.     mov    es, ax                  ;video seg pointer
  87.         mov     dh, MSG_ATTR            ;message attribute character
  88.     cmp    WORD PTR [Ncb.NCB_LENGTH], 3 ;< 3 URC; > 2 ULC of screen
  89.     jae    SHORT @@LongMsg
  90.     cmp    WORD PTR [Ncb.NCB_LENGTH], 1 ;1 = no displacement character
  91.     jbe    SHORT @@PutOne
  92.     mov    al, BYTE PTR [Packet + 1] ;get displacement character
  93.         mov     ah, 0
  94.     add    ax, 0 - '0'
  95.     shl    ax, 1
  96.     mov    si, ax
  97.     cmp    si, MAXLINE
  98.     jle    SHORT @@PutOne
  99.     xor    si, si
  100. @@PutOne:
  101.     mov    bx, UR_CORNER
  102.     sub    bx, si
  103.     mov    dl, BYTE PTR [Packet]
  104.     mov    WORD PTR es:[bx], dx
  105.     jmp    @@NetRcv
  106. @@LongMsg:
  107.     mov    di, OFFSET [Ncb.NCB_CALLNAME]
  108.     jmp    SHORT @@ChkNameC
  109. @@PutNameC:
  110.     mov    dl, BYTE PTR [di]
  111.     mov    WORD PTR es:[si], dx
  112.     inc    di
  113.     mov    ax, si
  114.     inc    ax
  115.     inc    ax
  116.     mov    si, ax
  117. @@ChkNameC:
  118.     cmp    BYTE PTR [di], 0
  119.     je    SHORT @@PutColon
  120.     cmp    BYTE PTR [di], ' '
  121.     jne    SHORT @@PutNameC
  122. @@PutColon:
  123.     mov    dl, ':'
  124.     mov    WORD PTR es:[si], dx
  125.     mov    ax, si
  126.     inc    ax
  127.     inc    ax
  128.     mov    si, ax
  129.     mov    dl, ' '
  130.     mov    WORD PTR es:[si], dx
  131.     mov    ax, si
  132.     inc    ax
  133.     inc    ax
  134.     mov    si, ax
  135.     mov    ax, WORD PTR [Ncb.NCB_LENGTH]
  136.     shl    ax, 1
  137.     add    ax, si
  138.     mov    cx, ax                  ;cx = stop pos
  139.     mov    ax, si
  140.     mov    di, OFFSET Packet
  141.     jmp    SHORT @@ChkStop
  142. @@PutMsgC:
  143.     mov    dl, BYTE PTR [di]
  144.     mov    WORD PTR es:[si], dx
  145.     inc    di
  146.     mov    ax, si
  147.     inc    ax
  148.     inc    ax
  149. @@ChkStop:
  150.     cmp    ax, cx
  151.     mov    si, ax
  152.     jl    SHORT @@PutMsgC
  153.     mov    dl, ' '
  154.     mov    WORD PTR es:[si], dx
  155. @@NetRcv:
  156.     mov    WORD PTR [State], STATE_IDLE
  157.         mov     ax, ds                  ;zero Ncb
  158.         mov     es, ax
  159.     mov    di, OFFSET Ncb
  160.         mov     cx, 32                  ;Ncb length in words
  161.     xor    ax, ax
  162.         cld
  163.         rep stosw
  164.     mov    BYTE PTR [Ncb.NCB_COMMAND], RECEIVE_DATAGRAM ;setup Ncb
  165.     mov    BYTE PTR [Ncb.NCB_NUM], 0ffh ;0ffh = from any user
  166.     mov    WORD PTR [Ncb.NCB_LENGTH], MAXLINE
  167.     mov    WORD PTR [Ncb.NCB_BUF_OFF], OFFSET Packet
  168.     mov    WORD PTR [Ncb.NCB_BUF_SEG], ds
  169.     mov    WORD PTR [Ncb.NCB_POST_OFF], OFFSET Post
  170.     mov    WORD PTR [Ncb.NCB_POST_SEG], cs
  171.     mov    BYTE PTR [Ncb.NCB_CMD_CPLT], 0ffh ;0ffh = not completed
  172.     mov    ax, ds
  173.     mov    es, ax
  174.     mov    bx, OFFSET Ncb
  175.     mov    ax, 100h
  176.     int    05ch                    ;NETBIOS call
  177.         pop     si
  178.         pop     di
  179.         pop     es
  180.         ret
  181. TSRBACKPROC ENDP
  182.  
  183. ;TSR stack
  184. PUBLIC TsrStack
  185. PUBLIC TopStack
  186. TsrStack        DB 256 dup(0)           ;stack to use
  187. TopStack        EQU this byte
  188.  
  189. PUBLIC TESSINITSTART                    ;required entry point
  190. TESSINITSTART:
  191.         ASSUME cs:_TEXT, ds:_TEXT
  192.         mov     dx, OFFSET Signon
  193.         mov     ah, 09
  194.         int     21h                     ;display the signon message
  195.         mov     si, OFFSET NetmsgName
  196.         mov     di, OFFSET NetmsgNum
  197.         call    TSCHECKRESIDENT
  198.         or      ax, ax
  199.         jz      @@Install
  200.         mov     dx, OFFSET AlreadyInstalled ;we must already be installed
  201.         mov     ah, 09
  202.         int     21h                     ;display message
  203. @@Terminate:
  204.         mov     ax, 4c01h
  205.         int     21h                     ;and exit with error code
  206. @@Install:
  207.         mov     di, OFFSET TopStack
  208.         dec     di
  209.         dec     di
  210.         mov     si, di
  211.         call    TSSETSTACK
  212.         mov     dx, OFFSET Installed
  213.         mov     ah, 09
  214.         int     21h
  215.         mov     dx, OFFSET TESSINITSTART
  216.         mov     bx, 1020h               ;no pop graphics, background procs
  217.         xor     ax, ax                  ;no hotkey!
  218.         dec     ax                      ;no hotkey is -1
  219.         call    TSDOINIT
  220.         jmp     @@Terminate               ;we should never do this!
  221.  
  222. ;messages
  223. Signon  DB      13,10,'NETMSG.COM v1.01',13,10,'$'
  224. Installed       LABEL   BYTE
  225.         DB      'NETMSG installed',13,10,'$'
  226. AlreadyInstalled       LABEL   BYTE
  227.         DB      'NETMSG already installed',7,13,10,'$'
  228.  
  229. _TEXT ENDS
  230.  
  231.         END
  232.