home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / network / netio.asm < prev    next >
Assembly Source File  |  1986-01-20  |  17KB  |  444 lines

  1. PAGE    60,132
  2.  
  3. TITLE   "NETIO" -- NETWORK I/O DRIVER
  4. CSEG    SEGMENT PARA PUBLIC 'CODE'
  5.         ASSUME CS:CSEG,SS:STACK
  6.  
  7. ;------------------------------------------------;
  8. ;       DRIVER HEADER                            ;
  9. ;------------------------------------------------;
  10.                 DD      -1             ; Ptr to next device driver
  11.                 DW      1100000000000000B ; Attribute byte, char dev.
  12.                 DW      OFFSET STRATEGY ; OFFSET to STRATEGY routine
  13.                 DW      OFFSET IRPT    ; OFFSET to INTERRUPT routine
  14.                 DB      'NETIO   '     ; Character device name
  15.  
  16. RH_PTR  LABEL   DWORD                  ; Storage of PTR to request header
  17. RH_PTRO DW      0                      ; OFFSET (filled by strat. rout)
  18. RH_PTRS DW      0                      ; SEGMENT  "
  19.  
  20. ;------------------------------------------------;
  21. ;       REQUEST HEADER, COMMON PORTION           ;
  22. ;------------------------------------------------;
  23. RH              EQU     DS:[BX]
  24.  
  25. RHC             STRUC
  26. RHC_LEN         DB      ?              ; Length of request header + data
  27.                 DB      ?              ; unit code (Ignored)
  28. RHC_CMD         DB      ?              ; Command code
  29. RHC_STA         DW      ?              ; Status word
  30.                 DQ      ?              ; Reserved for DOS
  31. RHC             ENDS
  32.  
  33. ;------------------------------------------------;
  34. ;       REQUEST HEADER FOR INIT COMMAND          ;
  35. ;------------------------------------------------;
  36. RH0             STRUC
  37.                 DB      (TYPE RHC) DUP (?)      ;Common portion
  38. RH0_NUM         DB      ?              ; Number of units (Ignored)
  39. RH0_ENDO        DW      ?              ; OFFSET of ending address of res. code
  40. RH0_ENDS        DW      ?              ; SEGMENT of ending address of res. code
  41. RH0_BPB         DD      ?              ; Address of BPB (Ignored)
  42. RH0_DRIV        DB      ?              ; Drive code (Ignored)
  43. RH0             ENDS
  44.  
  45. ;------------------------------------------------;
  46. ;       REQUEST HEADER FOR I/O                   ;
  47. ;------------------------------------------------;
  48. RH1             STRUC
  49.                 DB      (TYPE RHC) DUP (?)      ;Common portion
  50.                 DB      ?              ; Media descriptor byte (Ignored)
  51. RH1_BUFO        DW      ?              ; OFFSET to buffer address
  52. RH1_BUFS        DW      ?              ; SEGMENT of buffer address
  53. RH1_CNT         DB      ?              ; Bytes transferred count
  54. RH1             ENDS
  55.  
  56. RH1_BUF         EQU     DWORD PTR RH1_BUFO ; OFFSET/SEG of buffer
  57.  
  58. ;------------------------------------------------;
  59. ;       REQUEST HEADER FOR INPUT NO WAIT         ;
  60. ;------------------------------------------------;
  61. RH2             STRUC
  62.                 DB      (TYPE RHC) DUP (?)      ;Common portion
  63. RH2_DATA        DB      ?              ; Data from driver service routine
  64. RH2             ENDS
  65.  
  66.  
  67. ;------------------------------------------------;
  68. ;       FLAGS FOR REQUEST HEADER STATUS WORD     ;
  69. ;------------------------------------------------;
  70. STAT_DONE       EQU     01H            ; Done flag
  71. STAT_CMDERR     EQU     8003H          ; Command error flag
  72. STAT_BUSY       EQU     0200H          ; Busy -- I/O in progress
  73.  
  74. CTRL_C          EQU     03H
  75. BELL            EQU     07H
  76. CR              EQU     0DH
  77. LF              EQU     0AH
  78.  
  79. ;------------------------------------------------;
  80. ; NETWORK CONTROL BLOCK ( GENERIC )              ;
  81. ;------------------------------------------------;
  82. NCB             EQU     $
  83. NCB_COMMAND     DB      00H               ; NCB Command field
  84. NCB_RETCODE     DB      00H               ; NCB Return code
  85. NCB_LSN         DB      00H               ; NCB Local session number
  86. NCB_NUM         DB      00H               ; NCB Number of your name
  87. NCB_BUFFER@     DW      OFFSET CHAR       ; NCB Ptr to message buffer
  88.                 DW      CSEG
  89. NCB_LENGTH      DW      0001H             ; NCB Message buffer length
  90. NCB_CALLNAME    DB      'HUNTER THOMPSON '; NCB Name on remote adapter
  91. NCB_NAME        DB      'RAOUL DUKE      '; NCB Name on local adapter
  92. NCB_RTO         DB      00H               ; NCB Receive timeout
  93. NCB_STO         DB      00H               ; NCB Send timeout
  94. NCB_POST@       DD      00000000H         ; NCB Ptr to POST routine
  95. NCB_LANA_NUM    DB      00H               ; NCB Adapter number (00H = 1st Adapter)
  96. NCB_CMD_CPLT    DB      00H               ; NCB Command status
  97. NCB_RESERVE     DB      14 DUP (0)        ; Reserved
  98.  
  99. CHAR            DB      0              ; Our 1 Character 'BUFFER'
  100. INSTALLED       DB      0              ; Network session started flag
  101. BUFF            DB      16 DUP(0)
  102. BUFF_STAT       DB      0
  103. NEXT_TO_READ    DW      0
  104. NEXT_TO_ADD     DW      0
  105. BUFF_PTR        DW      0
  106. OUT_BUFF        DB      64 DUP(0)
  107.  
  108. ;------------------------------------------------;
  109. ;       STRATEGY ROUTINE, STORES HEADER ADDRESS  ;
  110. ;------------------------------------------------;
  111. STRATEGY        PROC    FAR
  112.                 MOV     CS:RH_PTRS,ES
  113.                 MOV     CS:RH_PTRO,BX
  114.                 RET
  115. STRATEGY        ENDP
  116.  
  117. ;------------------------------------------------;
  118. ;       JUMP TABLE FOR PROCESSING DRIVER COMMANDS;
  119. ;------------------------------------------------;
  120. CMD_TABLE       LABEL   WORD
  121.                 DW      OFFSET INIT             ; 0 - Initialization
  122.                 DW      OFFSET MEDIA_CHECK      ; 1 - Media Check
  123.                 DW      OFFSET BLD_BPB          ; 2 - Build BPB
  124.                 DW      OFFSET INPUT_IOCTL      ; 3 - IOCTL Input
  125.                 DW      OFFSET INPUT            ; 4 - Input
  126.                 DW      OFFSET INPUT_NDINW      ; 5 - Non-Destr. Input
  127.                 DW      OFFSET INPUT_STATUS     ; 6 - Input Status
  128.                 DW      OFFSET INPUT_FLUSH      ; 7 - Input Flush
  129.                 DW      OFFSET OUTPUT           ; 8 - Output
  130.                 DW      OFFSET OUTPUT_VER       ; 9 - Output w/Verify
  131.                 DW      OFFSET OUTPUT_STATUS    ;10 - Output Status
  132.                 DW      OFFSET OUTPUT_FLUSH     ;11 - Output Flush
  133.                 DW      OFFSET OUTPUT_IOCTL     ;12 - IOCTL Output
  134.                 DW      OFFSET DEVICE_OPEN      ;13 - Device OPEN
  135.                 DW      OFFSET DEVICE_CLOSE     ;14 - Device CLOSE
  136. MAX_CMD         EQU     ($ - CMD_TABLE)/2       ;Highest Valid Command
  137.                 DW      OFFSET REMOVABLE_MED    ;15 - Removeable Media
  138.  
  139. ;------------------------------------------------;
  140. ;       DEVICE INTERRUPT ENTRY POINT             ;
  141. ;------------------------------------------------;
  142. IRPT            PROC    FAR
  143.                 PUSH    DS             ; Save registers
  144.                 PUSH    ES
  145.                 PUSH    AX
  146.                 PUSH    BX
  147.                 PUSH    CX
  148.                 PUSH    DX
  149.                 PUSH    DI
  150.                 PUSH    SI
  151.  
  152.                 CLD                    ; All moves forward
  153.                 LDS     BX,CS:RH_PTR   ; Get req header address
  154.                 MOV     AL,RH.RHC_CMD  ; Command code from request header
  155.                 CBW
  156.                 CMP     AL,MAX_CMD     ; Valid command?
  157.                 JA      IRPT_CMD_HIGH  ;  Jump to error routine
  158.                 MOV     DI,OFFSET IRPT_CMD_EXIT ; Return addr from cmd proc.
  159.                 PUSH    DI             ; Save it
  160.                 ADD     AX,AX          ; Double command for jump table
  161.                 MOV     DI,AX          ; Move into index register
  162.                 XOR     AX,AX
  163.                 JMP     CS:CMD_TABLE[DI] ; Go to proper processing rout.
  164.  
  165. IRPT_CMD_ERROR:                        ; Called for unsupported commands
  166. MEDIA_CHECK:
  167. BLD_BPB:
  168. DEVICE_OPEN:
  169. DEVICE_CLOSE:
  170. REMOVABLE_MED:
  171.                 POP     AX             ; POP Off return address
  172. IRPT_CMD_HIGH:
  173.                 MOV     AX,STAT_CMDERR ; Set Command error flag in status
  174. IRPT_CMD_EXIT:
  175.                 LDS     BX,CS:RH_PTR   ; Restore DS:BX as req head. ptr
  176.                 OR      AH,STAT_DONE   ; Set DONE flag
  177.                 MOV     RH.RHC_STA,AX  ; Store STATUS in header
  178.                 POP     SI             ; Restore Registers
  179.                 POP     DI
  180.                 POP     DX
  181.                 POP     CX
  182.                 POP     BX
  183.                 POP     AX
  184.                 POP     ES
  185.                 POP     DS
  186.                 RET
  187. IRPT            ENDP
  188. ;------------------------------------------------;
  189. ;       COMMAND HANDLER ROUTINES                 ;
  190. ;------------------------------------------------;
  191. INPUT           PROC
  192.                 PUSH    ES
  193.                 PUSH    BX             ; Store OFFSET of header
  194.                 CMP     INSTALLED,00H  ; Is NET session started?
  195.                 JNE     INPUT0
  196.                 CALL    INSTALL
  197.  
  198. INPUT0:         CMP     BUFF_STAT,0
  199.                 JE      INPUT0
  200.                 MOV     DI,NEXT_TO_READ
  201.                 MOV     AL,BUFF[DI]
  202.                 INC     DI
  203.                 CMP     DI,0FH
  204.                 JLE     INPUT1
  205.                 XOR     DI,DI
  206. INPUT1:         MOV     NEXT_TO_READ,DI
  207.                 DEC     BUFF_STAT
  208.                 POP     BX
  209.                 POP     ES
  210.                 MOV     DI,RH.RH1_BUFO
  211.                 MOV     ES,RH.RH1_BUFS
  212.                 MOV     ES:[DI],AL
  213.                 MOV     RH.RH1_CNT,01H
  214.                 XOR     AX,AX
  215.                 RET
  216. INPUT           ENDP
  217.  
  218. INPUT_STATUS    PROC
  219.                 CMP     BUFF_STAT,0H
  220.                 JE      BUFF_EMPTY
  221.                 XOR     AX,AX
  222.                 RET
  223. BUFF_EMPTY:     MOV     AX,STAT_BUSY
  224.                 RET
  225. INPUT_STATUS    ENDP
  226.  
  227. INPUT_NDINW     PROC
  228.                 PUSH    ES
  229.                 PUSH    BX             ; Store OFFSET of header
  230.                 CMP     INSTALLED,00H  ; Is NET session started?
  231.                 JNE     NDINW0
  232.                 CALL    INSTALL
  233.  
  234. NDINW0:         POP     BX
  235.                 POP     ES
  236.  
  237.                 CMP     BUFF_PTR,00H   ; Is output buffer empty?
  238.                 JE      NDINW1
  239.  
  240.                 MOV     DI,BUFF_PTR    ; if not, empty it...
  241.                 MOV     NCB_BUFFER@+2,CS
  242.                 MOV     NCB_BUFFER@,OFFSET OUT_BUFF
  243.                 MOV     NCB_COMMAND,014H
  244.                 MOV     NCB_LENGTH,DI
  245.                 MOV     BX,CS
  246.                 MOV     ES,BX
  247.                 MOV     BX,OFFSET NCB
  248.                 INT     5CH
  249.                 MOV     BUFF_PTR,00H   ; now buffer is empty
  250.                 CMP     NCB_RETCODE,00H
  251.                 JE      NDINW1
  252.                 JMP     IRPT_CMD_ERROR ; if anything went wrong, abort
  253.  
  254. NDINW1:         MOV     DI,NEXT_TO_READ ; get next char in buffer
  255.                 MOV     AL,BUFF[DI]
  256.                 MOV     RH.RH2_DATA,AL ; return it via req header
  257.                 CMP     BUFF_STAT,0H
  258.                 JE      NWBUFF_EMPTY
  259.  
  260. NDINW_LOOP:     CMP     AL,CTRL_C      ; scan active buffer for ^C
  261.                 JNE     NDINW2
  262.                 MOV     BUFF_PTR,04H   ; got one!
  263.                 MOV     OUT_BUFF,'^'   ; print ^C<CR><LF> on remote
  264.                 MOV     OUT_BUFF+1,'C'
  265.                 MOV     OUT_BUFF+2,CR
  266.                 MOV     OUT_BUFF+3,LF
  267.                 CALL    INPUT_FLUSH    ; flush input buffer
  268.                 INT     23H            ; tell DOS
  269.  
  270. NDINW2:         INC     DI             ; get next char in active buffer
  271.                 CMP     DI,0FH         ; check buffer rollover
  272.                 JLE     NDINW3
  273.                 XOR     DI,DI
  274. NDINW3:         CMP     DI,NEXT_TO_ADD ; check end of active buffer
  275.                 JE      NDINW_EXIT
  276.                 MOV     AL,BUFF[DI]
  277.                 JMP     NDINW_LOOP
  278.  
  279. NDINW_EXIT:     XOR     AX,AX          ; clear error flag for return
  280.                 RET
  281.  
  282. NWBUFF_EMPTY:   MOV     AX,STAT_BUSY   ; set buffer empty flag
  283.                 RET
  284. INPUT_NDINW     ENDP
  285.  
  286. INPUT_FLUSH     PROC
  287.                 MOV     BUFF_STAT,0H   ; 0 chars in buffer
  288.                 MOV     NEXT_TO_READ,0H ; offset for reading buffer
  289.                 MOV     NEXT_TO_ADD,0H ; offset for adding to buffer
  290.                 RET
  291. INPUT_FLUSH     ENDP
  292.  
  293. INPUT_IOCTL     PROC
  294.                 RET
  295. INPUT_IOCTL     ENDP
  296.  
  297. OUTPUT_IOCTL    PROC
  298.                 RET
  299. OUTPUT_IOCTL    ENDP
  300.  
  301. OUTPUT          PROC
  302. OUTPUT_VER:
  303.                 MOV     RH.RH1_CNT,01H
  304.                 MOV     DI,RH.RH1_BUFO ; Load DTA OFFSET
  305.                 MOV     ES,RH.RH1_BUFS ; Load DTA SEGMENT
  306.                 CMP     INSTALLED,0H   ; Is NETWORK session on?
  307.                 JNE     NET_OUT
  308.                 CALL    INSTALL        ;  If not, wait for CALL
  309.  
  310. NET_OUT:
  311.                 MOV     AL,ES:[DI]     ; Get char to send
  312.                 MOV     DI,BUFF_PTR    ; Put into output buffer
  313.                 MOV     OUT_BUFF[DI],AL
  314.                 INC     DI             ; Update output buffer pointer
  315.                 CMP     DI,040H        ; check for output buffer full
  316.                 JNE     OUT_EXIT
  317.  
  318.                 MOV     DI,00H         ; it's full, send it on its way
  319.                 MOV     NCB_BUFFER@+2,CS
  320.                 MOV     NCB_BUFFER@,OFFSET OUT_BUFF
  321.                 MOV     NCB_LENGTH,040H
  322.                 MOV     NCB_COMMAND,014H
  323.                 MOV     AX,CS
  324.                 MOV     ES,AX
  325.                 MOV     BX,OFFSET NCB
  326.                 INT     5CH
  327.                 CMP     NCB_RETCODE,00H
  328.                 JE      OUT_EXIT
  329.                 JMP     IRPT_CMD_ERROR
  330.  
  331. OUT_EXIT:       XOR     AX,AX          ; Clear error code
  332.                 MOV     BUFF_PTR,DI
  333.                 RET
  334. OUTPUT          ENDP
  335.  
  336. OUTPUT_STATUS   PROC
  337.                 RET
  338. OUTPUT_STATUS   ENDP
  339.  
  340. OUTPUT_FLUSH    PROC
  341.                 RET
  342. OUTPUT_FLUSH    ENDP
  343.  
  344. ;------------------------------------------------;
  345. ;      DO A NETBIOS "ADD NAME"                   ;
  346. ;------------------------------------------------;
  347. INSTALL         PROC
  348.                 MOV     BX,CS
  349.                 MOV     ES,BX
  350.                 MOV     NCB_COMMAND,030H ; ADDNAME Command code
  351.                 MOV     BX,OFFSET NCB   ; ES:BX points to NCB
  352.                 INT     5CH             ; NETWORK function call
  353.  
  354. ;------------------------------------------------;
  355. ;      DO A NETBIOS "LISTEN"                     ;
  356. ;------------------------------------------------;
  357. LISTEN:
  358.                 MOV     NCB_COMMAND,011H ; LISTEN Command code
  359.                 INT     5CH            ; NETWORK function call
  360.                 MOV     INSTALLED,01H
  361. POST_REC:       MOV     NCB_COMMAND,095H
  362.                 MOV     NCB_POST@,OFFSET POST
  363.                 MOV     NCB_POST@+2,CS
  364.                 INT     5CH
  365.                 JMP     INST_EXIT
  366. INST_ERR_EXIT:  POP     AX
  367. INST_EXIT:
  368.                 RET
  369. INSTALL         ENDP
  370.  
  371. INIT            PROC
  372.                 MOV     RH.RH0_ENDS,CS
  373.                 MOV     RH.RH0_ENDO,OFFSET HELLO
  374.                 RET
  375. INIT            ENDP
  376.  
  377. POST            PROC    FAR
  378.                 PUSH    DI
  379.                 PUSH    AX
  380.                 PUSH    BX
  381.                 PUSH    CX
  382.                 PUSH    DX
  383.                 CLI
  384.  
  385.                 CMP     CHAR,0FFH      ; Is session over?
  386.                 JNE     NORMAL_POST
  387.  
  388.                 MOV     CHAR,00H       ; Yes, so reset everything
  389.                 MOV     NCB_COMMAND,012H
  390.                 MOV     BX,CS
  391.                 MOV     ES,BX
  392.                 MOV     BX,OFFSET NCB
  393.                 INT     5CH            ; RESET adapter
  394.                 MOV     INSTALLED,00H
  395.                 POP     DX
  396.                 POP     CX
  397.                 POP     BX
  398.                 POP     AX
  399.                 POP     DI
  400.                 IRET
  401.  
  402. NORMAL_POST:    CMP     BUFF_STAT,0FH  ; Is input buffer full?
  403.                 JL      XFER
  404.                 STI
  405.                 JMP     XEXIT
  406.  
  407. XFER:           MOV     DL,CHAR        ; transfer char to input buffer
  408.                 MOV     DI,NEXT_TO_ADD
  409.                 MOV     BUFF[DI],DL
  410.                 INC     DI             ; update next_to_add pointer
  411.                 CMP     DI,0FH         ; check for buffer rollover
  412.                 JLE     XFER2
  413.                 XOR     DI,DI
  414. XFER2:          MOV     NEXT_TO_ADD,DI ; restore pointer
  415.                 INC     BUFF_STAT      ; increment # of chars in buffer
  416.  
  417.                 MOV     AX,CS          ; POST another receive...
  418.                 MOV     ES,AX
  419.                 MOV     BX,OFFSET NCB
  420.                 MOV     NCB_BUFFER@,OFFSET CHAR
  421.                 MOV     NCB_BUFFER@+2,AX
  422.                 MOV     NCB_COMMAND,095H
  423.                 MOV     NCB_POST@,OFFSET POST
  424.                 MOV     NCB_POST@+2,AX
  425.                 STI
  426.                 INT     5CH
  427. XEXIT:          POP     DX
  428.                 POP     CX
  429.                 POP     BX
  430.                 POP     AX
  431.                 POP     DI
  432.                 IRET
  433. POST            ENDP
  434.  
  435. HELLO           EQU    $
  436.  
  437. CSEG            ENDS
  438.  
  439. STACK  SEGMENT PARA STACK 'STACK'
  440.        DB     64 DUP('STACK   ')
  441.  
  442. STACK  ENDS
  443.                 END                    ; Eric W. DeSilva Nov 1985
  444.