home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n002 / 4.ddi / ECLSRCA.ZIP / XC_TSR.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-08-16  |  14.2 KB  |  371 lines

  1. ;
  2. ;       XC_TSR.ASM  Mainline module of Terminate-Stay-Resident XCOMMS
  3. ;
  4. ;       Copyright 1989, South Mountain Software Inc
  5. ;       All Rights Reserved
  6. ;
  7. ;       <Main> is called from THE_END module.  It will setup the XCOMMS vector
  8. ;       and will return to THE_END and make everything resident.  If XCOMMS
  9. ;       is already loaded, not enough memory for buffers, or no vectors
  10. ;       are available an error message is returned.
  11. ;
  12. ;       Invoke:
  13. ;               XCOMMS                  Start XCOMMS TSR
  14. ;               XCOMMS 8                Start XCOMMS TSR with 8K buffers
  15. ;               XCOMMS 8 COMi           Start and enable COMi interrupts
  16. ;               XCOMMS 8 COMi           Start and enable COMi interrupts
  17. ;               XCOMMS 8 COMi COMj      Start and enable COMi & COMj interrupts
  18. ;                                       [Enable XON/XOFF with COMiX or COMjX]
  19. ;
  20. ;       Return status (ERRORLEVEL):
  21. ;
  22. ;           Successful:
  23. ;               0       Successfully installed
  24. ;           Errors:
  25. ;               1       XCOMMS already installed
  26. ;               2       No vector available to install XCOMMS
  27. ;               3       Not enough space for buffers
  28. ;               4       Illegal argument (out of range or not working)
  29. ;
  30. ;
  31. ;
  32.  
  33. ;
  34. ;       ===============================================================
  35. ;       References
  36. ;       ===============================================================
  37. ;
  38.  
  39.         INCLUDE ECLMACRO.INC            ; Default ECL assembler macros
  40.         PUBLIC  Main                    ; The TSR mainline routine
  41.         
  42.                                         ; The_end:
  43.         EXTRN   The_end : NEAR          ; The end of the TSR program label
  44.         EXTRN   getarg  : NEAR          ; Get command argument routine
  45.         EXTRN   atoi    : NEAR          ; Convert ASCII string to integer
  46.                                         ; XCOMMS kernal:
  47.         EXTRN   XCOMMS  : NEAR          ; The XCOMMS kernal interrupt driver
  48.         EXTRN   COMMS_GPORT : NEAR      ; Verify port existence COMMS function
  49.  
  50. ;
  51. ;       ===============================================================
  52. ;       Definitions
  53. ;       ===============================================================
  54. ;
  55.  
  56. NULL            EQU     00h             ; End of copyright message string
  57. CR              EQU     0Dh             ; Carriage return
  58. LF              EQU     0Ah             ; Line feed
  59.  
  60. DEFAULT_XCOMMS  EQU     7Fh             ; Assumed this to be XCOMMS vector
  61. LOW_INTERRUPT   EQU     41h             ; This is the last one to search
  62. XCOMMS_ID       EQU     0A66Ah          ; Signature
  63. DEFAULT_BUFSIZE EQU     8               ; (in K bytes) the size of buffers
  64. BUFFER_SHIFT    EQU     6               ; K/para shift left factor
  65.  
  66.  
  67.  
  68.  
  69. CSEG            SEGMENT BYTE PUBLIC 'CODE'
  70.                 ASSUME  CS:CSEG, DS:CSEG, ES:CSEG
  71. ;
  72. ;       ===============================================================
  73. ;       Local data
  74. ;       ===============================================================
  75. ;
  76. ;       NOTE - xcomms_int CONTAINING XCOMMS VECTOR IS WITHIN Main routine
  77. ;
  78.  
  79. Copyr   DB      "XCOMMS revision 2.0", CR, LF
  80.         DB      "Copyright (C) 1986, 1987, 1988 Essential Software Incorporated", CR, LF
  81.         DB      "Copyright (C) 1986, 1987, 1988 Advanced Firmware Engineering", CR, LF
  82.         DB      NULL
  83.  
  84. XCOMMS_buffers  DW      ?               ; Number of buffers (1K each)
  85.  
  86. ;
  87. ;       ===============================================================
  88. ;       Local procedures
  89. ;       ===============================================================
  90. ;
  91. ;       XCOMMS_Link      Link the XCOMMS guy
  92. ;       atoi             ASCII to integer
  93.  
  94. ;
  95. ;       ===============================================================
  96. ;       XCOMMS_Link      Link the XCOMMS guy
  97. ;       ===============================================================
  98. ;
  99. ;       Called initially when XCOMMS is being setup from CLI.
  100. ;
  101. ;       Input           Description
  102. ;       --------------  ---------------------------
  103. ;       Not applicable
  104. ;
  105. ;       Output          Description
  106. ;       --------------  ---------------------------
  107. ;       CY = NC         OK - linked successfully
  108. ;            AL = 00    
  109. ;       CY = C          Error - used by XCOMMS (or anything else)
  110. ;            AL = 01    Already installed
  111. ;            AL = 02    All vectors used - none are available
  112. ;
  113. ;       Registers used  Description
  114. ;       --------------  ---------------------------
  115. ;       CX              Interrupt vector list counter
  116. ;       ES, DX          The vector segment register
  117. ;       BX              The vector offset
  118. ;       ===============================================================
  119. ;
  120.  
  121.  
  122. XCOMMS_Link     PROC    NEAR
  123.  
  124.                 PUSH    ES
  125.                 PUSH    DX
  126.                 PUSH    CX
  127.                 PUSH    BX
  128.  
  129. ;
  130. ;       Examine all of the available interrupt vectors between
  131. ;       xcomms_int and LOW_INTERRUPT.  If XCOMMS is already
  132. ;       installed, an error code is returned.  Otherwise, the
  133. ;       vector number is stored (in xcomms_int) and the 
  134. ;       previous contents forgotten.  THE TSR VERSION OF XCOMMS MUST
  135. ;       ALWAYS KEEP ITS VECTOR!
  136. ;
  137.                 MOV     CL, xcomms_int
  138.                 XOR     CH, CH
  139.                 SUB     CX, LOW_INTERRUPT
  140.                 INC     CX                      ; Setup loop counter
  141. _XL_try_again:
  142.                 MOV     AL, xcomms_int
  143.                 getvec
  144.                 MOV     AX, BX
  145.                 OR      AX, DX
  146.                 JNE     _XL_loop                ; Someone used it!
  147.  
  148.                 MOV     AL, xcomms_int
  149.                 MOV     BX, OFFSET XCOMMS
  150.                 MOV     DX, SEG XCOMMS
  151.                 setvec
  152.                 CLC
  153.                 MOV     AL, 00h
  154.                 JMP     SHORT _XL_Exit
  155.  
  156. _XL_loop:                                       ; Who owns the vector?
  157.                 MOV     ES, DX
  158.                 CMP     WORD PTR ES:[BX+2], XCOMMS_ID
  159.                 MOV     AL, 01h
  160.                 JE      _XL_Error               ; XCOMMS is already there???
  161.                 DEC     xcomms_int              ; Look for another vector
  162.                 LOOP    _XL_try_again
  163.                 MOV     AL, 02h                 ; None are available
  164. _XL_Error:
  165.                 STC
  166. _XL_Exit:
  167.                 POP     BX
  168.                 POP     CX
  169.                 POP     DX
  170.                 POP     ES
  171.                 RET
  172. XCOMMS_Link     ENDP
  173.  
  174. ;
  175. ;       ===============================================================
  176. ;       Global procedures
  177. ;       ===============================================================
  178. ;
  179. ;       Main            Entry program (called from THE_END module)
  180.  
  181. ;
  182. ;       ===============================================================
  183. ;       Main            Entry program (called from THE_END module)
  184. ;       ===============================================================
  185. ;
  186. ;       First the XCOMMS interrupt vector is allocated as long as
  187. ;               (1) a vector is available, and
  188. ;               (2) XCOMMS was not previously installed
  189. ;
  190. ;       Next, XCOMMS_Entry routine (XCOMMS request 0002) is called
  191. ;       with the buffer pool address and number of buffers to setup.
  192. ;
  193. ;       Finally, the number of paragraphs are returned to reserve based
  194. ;       on the following components:
  195. ;               Take the size of the program (offset The_End) and divide by 16
  196. ;               Add 1 for left overs
  197. ;               Take the number of buffers, adjust based on 16 (BUFFER_SHIFT)
  198. ;               
  199. ;       NOTE - xcomms_int CONTAINING XCOMMS VECTOR IS WITHIN Main routine
  200. ;
  201. ;       Input           Description
  202. ;       --------------  ---------------------------
  203. ;       DS, CS          Pointer to CSEG (this) segment
  204. ;
  205. ;       Output          Description
  206. ;       --------------  ---------------------------
  207. ;       AH = 00         Terminate (and DO NOT MAKE RESIDENT)
  208. ;            AL         Exit status (ERRORLEVEL)  
  209. ;       AH = 01         Terminate and make resident
  210. ;            AL = 00    Success status
  211. ;            DX         Number of paragraphs to reserve for XCOMMS
  212. ;
  213. ;       Registers used  Description
  214. ;       --------------  ---------------------------
  215. ;       Not applicable
  216. ;
  217. ;       ===============================================================
  218. ;
  219.  
  220. Main            PROC NEAR
  221.  
  222. ;       Setup all XCOMMS services
  223.  
  224.                 CALL    XCOMMS_Link             ; First find a vector
  225.                 MOV     AH, 0                   ; Assume cannot make resident
  226.                 JNC     _Main_skip 
  227.                 JMP     _Main_exit              ; Already in Use! ERROR !!!!
  228. _Main_skip:
  229. ;       Are there any arguments?
  230.  
  231.                 CALL    getarg
  232.                 MOV     CX, DEFAULT_BUFSIZE 
  233.                 JC      _Main_buffer_init
  234.                 CALL    atoi                    ; Convert the argument
  235.                                                 ; CX has number of buffers!
  236.  
  237. ;       Everything is OK - now invoke the XCOMMS kernal XC_entry
  238. ;       function with the buffer addresses:
  239. ;
  240. ;               DX:BX   Buffer address
  241. ;               CX      Number of 1K buffers
  242.  
  243. _Main_buffer_init:
  244.                 MOV     XCOMMS_buffers, CX      ; Save buffer count
  245.                 MOV     BX, OFFSET The_End      ; Base buffer address
  246.                 MOV     DX, SEG The_End
  247.                 MOV     AX, 0002                ; xc_entry kernal request
  248.                 CALL    DO_XCOMMS
  249. ;
  250. ;       Check if anymore arguments:  (AX implies call to XCOMMS_link)
  251. ;
  252. ;               argument        AX      CX      DX
  253. ;               COM1            1401    0000    0000
  254. ;               COM2            1401    0000    0001
  255. ;               COM1X           1401    0001    0000
  256. ;               COM2X           1401    0001    0001
  257. ;                           |
  258. ;                           |
  259. ;                           V
  260.  
  261. xcomms_loop:
  262.                 CALL    getarg                  ; Get next argument
  263.                 JNC     xcomms_nope             ; Exit - no more arguments
  264.                 JMP     xcomms_bye              ; Exit - no more arguments
  265. xcomms_nope:
  266.                 MOV     AX, 0004                ; Assume an argument error
  267.  
  268.                 CMP     BYTE PTR [SI], 'C'      ; First character 'C'
  269.                 JE      _1
  270.                 CMP     BYTE PTR [SI], 'c'
  271.                 JE      _1
  272.                 JMP     _Main_exit             ; Exit - illegal argument??
  273. _1:
  274.                 INC     SI
  275.                 CMP     BYTE PTR [SI], 'O'     ; Second character 'O'
  276.                 JE      _2
  277.                 CMP     BYTE PTR [SI], 'o'
  278.                 JE      _2
  279.                 JMP     _Main_exit             ; Exit - illegal argument??
  280. _2:
  281.                 INC     SI
  282.                 CMP     BYTE PTR [SI], 'M'     ; Third character 'M'
  283.                 JE      _3
  284.                 CMP     BYTE PTR [SI], 'm'
  285.                 JE      _3
  286.                 JMP     _Main_exit             ; Exit - illegal argument??
  287. _3:
  288.                 INC     SI                     ; *** Rev 2.0 start ***
  289.                 CALL    atoi
  290.                 DEC     CX                     ; COM1 really is unit 0
  291.                 MOV     DX, CX                 ; Return port number
  292.                 PUSH    DX
  293.                 CALL    COMMS_GPORT
  294.                 POP     DX
  295.                 CMP     AX, 0                  ; Test for port presence
  296.                 JL      _Main_exit
  297.                                                ; *** Rev 2.0 end ***
  298.                                                ; Drop on down, SI point to next OK
  299. _4:
  300.                 MOV     CX, 0001               ; Assume XON and XOFF
  301.                 CMP     BYTE PTR [SI], 'X'     ; Optional Fifth character 'X'
  302.                 JE      _5
  303.                 CMP     BYTE PTR [SI], 'x'
  304.                 JE      _5
  305.                 MOV     CX, 0000
  306. _5:
  307.                 PUSH    CX                      ; Save XON/XOFF flag
  308.                 PUSH    DX                      ; Save unit #
  309.                 MOV     AX, 01401h              ; XCOMMS_Link request
  310.                 MOV     CX, 0000                ; Ignore DTR, RTS stuff
  311.                 CALL    DO_XCOMMS
  312.                 POP     DX                      ; Restore unit # and flag
  313.                 PUSH    DX
  314.                 MOV     AX, 1403h               ; DTR on
  315.                 CALL    DO_XCOMMS
  316.                 POP     DX                      ; Restore unit # and flag
  317.                 PUSH    DX
  318.                 MOV     AX, 1405h               ; RTS on
  319.                 CALL    DO_XCOMMS
  320.                 POP     DX                      ; Restore unit # and flag
  321.                 POP     CX
  322.                 CMP     CX, 0000                ; Enable XON?
  323.                 JE      xcomms_tagain
  324.                 MOV     AX, 1409h               ; Enable XON flow control
  325.                 MOV     BX, 10
  326.                 MOV     CX, 800                 ; XON-XOFF range
  327.                 CALL    DO_XCOMMS
  328.                 MOV     AX, 0004                ; Something wrong???
  329.                 JC      _Main_exit
  330. xcomms_tagain:
  331.                 JMP     xcomms_loop
  332. xcomms_bye:
  333.  
  334. ;
  335. ;       return to the caller COMMAND LINE invoker (THE_END module) with:
  336. ;       
  337. ;               AH = 01 Make XCOMMS resident
  338. ;               AL = 00 Successful status
  339. ;               DX      Number of paragraphs to save
  340. ;
  341.  
  342.                 MOV     CL, 4
  343.                 MOV     DX, OFFSET The_End      ; Save Vector procedures
  344.                 SHR     DX, CL
  345.                 INC     DX                      ; Add for paragraph boundary
  346.                 ADD     DX, 256/16              ; Adjust for SPH
  347.  
  348.                 MOV     BX, XCOMMS_buffers      ; Add the buffer size
  349.                 MOV     CL, BUFFER_SHIFT
  350.                 SHL     BX, CL
  351.                 ADD     DX, BX
  352.  
  353.                 MOV     AL, 00h                 ; SUCCESS! Install it
  354.                 MOV     AH, 01h
  355.  
  356. _Main_exit:
  357.                 RET
  358. Main            ENDP
  359.  
  360.  
  361. DO_XCOMMS       PROC    NEAR
  362.                 DB      0CDh                    ; Int <XCOMMS>
  363. xcomms_int      DB      DEFAULT_XCOMMS          ; XCOMMS Interrupt Entry
  364.                 RET
  365. DO_XCOMMS       ENDP
  366.  
  367. CSEG            ENDS
  368.                 END
  369.  
  370.  
  371.