home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / network / monitor.asm < prev    next >
Assembly Source File  |  1994-03-04  |  9KB  |  220 lines

  1. TITLE   "MONITOR" -- NETWORK I/O USER PROGRAM
  2. PAGE            60,132
  3. DATA            SEGMENT PARA PUBLIC 'DATA'
  4.  
  5. ;--------------------------------------------------------------------;
  6. ; NETWORK CONTROL BLOCK ( GENERIC )                                  ;
  7. ;--------------------------------------------------------------------;
  8. NCB             EQU     $
  9. NCB_COMMAND     DB      00H               ;NCB COMMAND FIELD
  10. NCB_RETCODE     DB      00H               ;NCB RETURN CODE
  11. NCB_LSN         DB      00H               ;NCB LOCAL SESSION NUMBER
  12. NCB_NUM         DB      00H               ;NCB NUMBER OF YOUR NAME
  13. NCB_BUFFER@     DD      00000000H         ;NCB POINTER TO MESSAGE BUFFER
  14. NCB_LENGTH      DW      0000H             ;NCB MESSAGE BUFFER LENGTH
  15. NCB_CALLNAME    DB      'RAOUL DUKE      ';NCB NAME ON REMOTE ADAPTER
  16. NCB_NAME        DB      'HUNTER THOMPSON ';NCB NAME ON LOCAL ADAPTER
  17. NCB_RTO         DB      00H               ;NCB RECEIVE TIMEOUT
  18. NCB_STO         DB      00H               ;NCB SEND TIMEOUT
  19. NCB_POST@       DD      00000000H         ;NCB POINTER TO POST ROUTINE
  20. NCB_LANA_NUM    DB      00H               ;NCB ADAPTER NUMBER (00H = 1ST ADAPTER)
  21. NCB_CMD_CPLT    DB      00H               ;NCB COMMAND STATUS
  22. NCB_RESERVE     DB      14 DUP(0)
  23.  
  24. CTRL_A          EQU     01H
  25. CR              EQU     0DH
  26. LF              EQU     0AH
  27. ESC             EQU     1BH
  28.  
  29. ERR_MSG         DB      CR,LF,'00 NET ERROR',CR,LF,'$'
  30. MSG_INIT        DB      CR,LF,'TALKING TO REMOTE...',CR,LF,'$'
  31. BAD_INIT        DB      CR,LF,'HOST ENGAGED OR CRASHED',CR,LF,'$'
  32. PROMPT          DB      CR,LF,'NET: $'
  33. BUFFER          DB      'BUFFER'
  34. O_BUFFER        DB      64 DUP(0)
  35. OUTPUT          DW      0
  36. TABLE           DB      '0123456789ABCDEF'
  37.  
  38. DATA ENDS
  39.  
  40. CSEG           SEGMENT PARA PUBLIC 'CODE'
  41.                ASSUME CS:CSEG, DS:DATA,ES:DATA,SS:STACK
  42. TEST           PROC FAR
  43.                PUSH     DS             ; store stuff so we can return
  44.                XOR      AX,AX
  45.                PUSH     AX
  46.                MOV      AX,DATA
  47.                MOV      ES,AX
  48.                MOV      DS,AX
  49.                CALL     ADD_NAME
  50.                MOV      NCB_COMMAND,010H ;COMMAND CODE FOR CALL
  51.                MOV      NCB_STO,120    ;1MIN TIMEOUT
  52.                MOV      NCB_RTO,120    ;1MIN TIMEOUT
  53.                MOV      BX,OFFSET NCB  ;ES:BX MUST EQUAL NCB ADDRESS
  54.                INT      5CH            ;INVOKE NETBIOS
  55.                CMP      NCB_RETCODE,00H ;FINAL RETURN CODE OKAY?
  56.                JE       C2             ;
  57.                MOV      DX,OFFSET BAD_INIT
  58.                MOV      AH,09H
  59.                INT      21H
  60.                JMP      EXIT
  61. C2:
  62.                CALL     RECEIVE        ; POST initial receive
  63.                MOV      DX,OFFSET MSG_INIT ; tell'm we're connected
  64.                MOV      AH,09H
  65.                INT      21H
  66. LOOP:
  67.                MOV      AH,06H         ; check for keypress
  68.                MOV      DL,0FFH
  69.                INT      21H
  70.                JNZ      KBD_HIT
  71.                CMP      OUTPUT,00H     ; check for chars in output buffer
  72.                JE       LOOP
  73.  
  74.                XOR      BX,BX          ; output chars in buffer
  75. O_LOOP:
  76.                MOV      AH,06H
  77.                MOV      DL,O_BUFFER[BX]
  78.                INT      21H
  79.                INC      BX
  80.                CMP      BX,OUTPUT
  81.                JNE      O_LOOP
  82.                MOV      OUTPUT,00H     ; clear buffer and POST receive
  83.                CALL     RECEIVE
  84.                JMP      LOOP
  85.  
  86. KBD_HIT:
  87.                CMP      AL,CTRL_A      ; SEND everything but CTRL-a
  88.                JNE      TSEND
  89.                MOV      DX,OFFSET PROMPT
  90.                MOV      AH,09H         ; print 'NET: ' prompt
  91.                INT      21H
  92.                MOV      AH,07H         ; get another char
  93.                INT      21H
  94.                CMP      AL,CTRL_A      ; if another ctrl-a, send it
  95.                JE       TSEND
  96.                MOV      BUFFER,0FFH    ; if anything else, exit
  97.                CALL     SEND
  98.                JMP      EXIT
  99. TSEND:
  100.                MOV      BUFFER,AL
  101.                CALL     SEND
  102.                JMP      LOOP
  103. EXIT:
  104.                CALL     HANGUP         ; bye bye!
  105.                CALL     DELETE_NAME
  106.                RET
  107.  
  108. TEST           ENDP
  109. TALK           PROC     NEAR
  110.                ASSUME   CS:CSEG,DS:DATA,ES:DATA,SS:STACK
  111. ;--------------------------------------------------------------------;
  112. ;      DO A NETBIOS "ADD NAME" - NAME TO USE ON THE NETWORK          ;
  113. ;--------------------------------------------------------------------;
  114. ADD_NAME:
  115.                MOV      NCB_COMMAND,030H ;ADDNAME COMMAND CODE
  116.                MOV      NCB_STO,0      ;NO TIMEOUT
  117.                MOV      NCB_RTO,0      ;NO TIMEOUT
  118.                MOV      BX,OFFSET NCB  ;ES:BX MUST EQUAL NCB ADDRESS
  119.                INT      5CH            ;INVOKE NETBIOS
  120.                CMP      NCB_RETCODE,00H ;FINAL RETURN CODE OKAY?
  121.                JE       A2
  122.                JMP      ERROR
  123. A2:            RET
  124.  
  125. ;--------------------------------------------------------------------;
  126. ;      DO A NETBIOS "RECEIVE" - OBTAIN MESSAGE FROM THE OTHER PC     ;
  127. ;--------------------------------------------------------------------;
  128. RECEIVE:
  129.                 MOV      NCB_COMMAND,095H ;RECEIVE COMMAND CODE
  130.                 MOV      NCB_STO,120   ;1MIN TIMEOUT
  131.                 MOV      NCB_RTO,120   ;1MIN TIMEOUT
  132.                 MOV      NCB_POST@,OFFSET POST
  133.                 MOV      NCB_POST@+2,CS
  134.                 MOV      NCB_BUFFER@,OFFSET O_BUFFER ;WHERE MESSAGE IS TO GO
  135.                 MOV      NCB_BUFFER@+2,DS
  136.                 MOV      NCB_LENGTH,040H ;HOW LONG (BYTES) MY BUFFER IS
  137.                 MOV      BX,OFFSET NCB ;ES:BX MUST EQUAL NCB ADDRESS
  138.                 INT      5CH           ;INVOKE NETBIOS
  139.                 RET
  140.  
  141. ;--------------------------------------------------------------------;
  142. ;      DO A NETBIOS "SEND" - SEND MESSAGE ON THE NETWORK             ;
  143. ;--------------------------------------------------------------------;
  144. SEND:
  145.                 MOV      NCB_COMMAND,014H ;SEND COMMAND CODE
  146.                 MOV      NCB_STO,120   ;1MIN TIMEOUT
  147.                 MOV      NCB_RTO,120   ;1MIN TIMEOUT
  148.                 MOV      NCB_BUFFER@,OFFSET BUFFER  ;PLACE THE ADDRESS OF BUFFER
  149.                 MOV      NCB_BUFFER@+2,DS ;TO SEND IN THE SEND_NCB.
  150.                 MOV      NCB_LENGTH,01H
  151.                 MOV      BX,OFFSET NCB ;ES:BX MUST EQUAL NCB ADDRESS
  152.                 INT      5CH           ;INVOKE NETBIOS
  153.                 CMP      NCB_RETCODE,00H ;FINAL RETURN CODE OKAY?
  154.                 JE       S2
  155.                 JMP      ERROR
  156. S2:             RET
  157. ;--------------------------------------------------------------------;
  158. ;      DO A NETBIOS "HANG UP" - KILL NETWORK SESSION                 ;
  159. ;--------------------------------------------------------------------;
  160. HANGUP:
  161.                 MOV      NCB_COMMAND,12H ;HANGUP COMMAND CODE
  162.                 MOV      NCB_STO,0     ;NO TIMEOUT
  163.                 MOV      NCB_RTO,0     ;NO TIMEOUT
  164.                 MOV      BX,OFFSET NCB ;ES:BX MUST EQUAL NCB ADDRESS
  165.                 INT      5CH           ;INVOKE NETBIOS
  166.                 RET
  167.  
  168. ;--------------------------------------------------------------------;
  169. ;      DO A NETBIOS "DELETE NAME" - REMOVE NAME FROM NETWORK TABLE   ;
  170. ;--------------------------------------------------------------------;
  171. DELETE_NAME:
  172.                 MOV      NCB_COMMAND,31H ;DELETE NAME COMMAND CODE
  173.                 MOV      NCB_STO,0     ;NO TIMEOUT
  174.                 MOV      NCB_RTO,0     ;NO TIMEOUT
  175.                 MOV      BX,OFFSET NCB ;ES:BX MUST EQUAL NCB ADDRESS
  176.                 INT      5CH           ;INVOKE NETBIOS
  177.                 RET
  178.  
  179. ;--------------------------------------------------------------------;
  180. ;      SPIT OUT ERROR MESSAGE                                        ;
  181. ;--------------------------------------------------------------------;
  182. ERROR:
  183.                 XOR      BX,BX         ;CLEAR BX
  184.                 MOV      BL,NCB_RETCODE ;GET RETURN CODE FROM NETBIOS
  185.                 AND      BL,0FH        ;GET LOW ORDER BITS
  186.                 MOV      AH,TABLE[BX]  ;LOAD HEXADECIMAL CHAR
  187.                 MOV      ERR_MSG + 3,AH ;PUT INTO ERROR MESSAGE
  188.                 MOV      BL,NCB_RETCODE ;RELOAD RETURN
  189.                 MOV      CL,4          ;GET READY TO SHIFT BITS
  190.                 SHR      BL,CL         ;SHIFT OVER HI ORDER BITS
  191.                 MOV      AH,TABLE[BX]  ;LOAD HEXADECIMAL CHAR
  192.                 MOV      ERR_MSG + 2,AH ;PUT INTO ERROR MESSAGE
  193.  
  194.                 MOV      DX,OFFSET ERR_MSG ;ERROR HAS OCCURRED IN NETBIOS
  195.                 MOV      AH,09H           ;DISPLAY ERROR MESSAGE
  196.                 INT      21H
  197.  
  198. QUIT:
  199.                 RET
  200. TALK            ENDP
  201.  
  202. POST            PROC    FAR
  203.                 PUSH    AX
  204.                 PUSH    DX
  205.                 MOV     AX,DATA
  206.                 MOV     DS,AX
  207.                 MOV     DI,DS:NCB_LENGTH
  208.                 MOV     DS:OUTPUT,DI
  209.                 POP     DX
  210.                 POP     AX
  211.                 IRET
  212. POST            ENDP
  213.  
  214. CSEG            ENDS
  215. STACK           SEGMENT PARA STACK 'STACK'
  216.                 DB     64 DUP('STACK   ')
  217.  
  218. STACK           ENDS
  219.                 END                    ; Eric W. DeSilva Nov 1985
  220.