home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / isprin.zip / ISPRINT.ASM next >
Assembly Source File  |  1993-07-14  |  9KB  |  224 lines

  1. ; File......: ISPRINT.ASM
  2. ; Author....: Ted Means
  3. ; Date......: $Date:   15 Aug 1991 23:07:56  $
  4. ; Revision..: $Revision:   1.2  $
  5. ; Log file..: $Logfile:   E:/nanfor/src/isprint.asv  $
  6. ; This function is an original work by Ted Means and is placed in the
  7. ; public domain.  I got the idea from Norm Mongeau, but the code is
  8. ; all mine.
  9. ;
  10. ; Modification history:
  11. ; ---------------------
  12. ;
  13. ; $Log:   E:/nanfor/src/isprint.asv  $
  14. ;  
  15. ;     Rev 1.2   15 Aug 1991 23:07:56   GLENN
  16. ;  Forest Belt proofread/edited/cleaned up doc
  17. ;  
  18. ;     Rev 1.1   14 Jun 1991 19:54:38   GLENN
  19. ;  Minor edit to file header
  20. ;  
  21. ;     Rev 1.0   01 Apr 1991 01:03:26   GLENN
  22. ;  Nanforum Toolkit
  23. ;  
  24. ;
  25.  
  26.  
  27. ;  $DOC$
  28. ;  $FUNCNAME$
  29. ;     FT_ISPRINT()
  30. ;  $CATEGORY$
  31. ;     DOS/BIOS
  32. ;  $ONELINER$
  33. ;     Check printer status
  34. ;  $SYNTAX$
  35. ;     FT_ISPRINT( [ <cDevice> ] ) -> lResult
  36. ;  $ARGUMENTS$
  37. ;     <cDevice> is optional and is the device to test (LPT2, COM1, etc.).
  38. ;     If omitted, the function will default to the PRN device.
  39. ;  $RETURNS$
  40. ;     .T.  if device is ready for output.
  41. ;     .F.  if one of the following conditions occurs:
  42. ;          1)  The device is not ready.
  43. ;          2)  The device does not exist.
  44. ;          3)  DOS couldn't open the device for some reason
  45. ;              (such as no file handles available).
  46. ;  $DESCRIPTION$
  47. ;     The Clipper IsPrinter() function is somewhat limited because it only
  48. ;     works with LPT1.  Furthermore, it talks directly to the hardware, so
  49. ;     if you have redirected LPT1 via the DOS MODE command, the IsPrinter()
  50. ;     function will return erroneous results.
  51. ;
  52. ;     This function offers a better alternative.  Instead of talking to the
  53. ;     hardware, it issues a DOS call that checks to see if the device is
  54. ;     ready or not.  That gives DOS an opportunity to deal with any
  55. ;     redirections, and since you pass the device name as a parameter, you
  56. ;     can test any device, not just LPT1 (note that the function defaults
  57. ;     to PRN if you fail to pass a valid parameter).
  58. ;
  59. ;     The function also temporarily traps the DOS critical error handler so
  60. ;     you don't get any nasty error messages if the device isn't ready.  It
  61. ;     restores the old critical error handler before exiting.
  62. ;
  63. ;     Note that although this function is mainly designed for testing
  64. ;     printers, you can also check to see if a drive is ready.  Since DOS
  65. ;     thinks the NUL device exists on every drive, you can pass a drive
  66. ;     letter followed by NUL as a parameter.  If DOS is able to open the
  67. ;     NUL device, then the drive is ready, otherwise the door is open or
  68. ;     something else is wrong.
  69. ;
  70. ;     The source code is written to adhere to Turbo Assembler's IDEAL mode.
  71. ;     To use another assembler, you will need to rearrange the PROC and
  72. ;     SEGMENT directives, and also the ENDP and ENDS directives (a very
  73. ;     minor task).
  74. ;  $EXAMPLES$
  75. ;     IF ! FT_ISPRINT()
  76. ;        Qout( "PRN is not ready!" )
  77. ;     ENDIF
  78. ;
  79. ;     IF ! FT_ISPRINT( "COM2" )
  80. ;        Qout( "Check the device on COM2.  Something is wrong." )
  81. ;     ENDIF
  82. ;
  83. ;     IF ! FT_ISPRINT( "A:\NUL" )
  84. ;        Qout( "Oops, better check drive A!" )
  85. ;     ENDIF
  86. ;  $END$
  87. ;
  88.  
  89.  
  90.          IDEAL
  91.  
  92. Public   FT_ISPRINT
  93.  
  94. Old24Vec EQU       DWord Ptr BP - 4
  95. Old24Ofs EQU       Word Ptr BP - 4
  96. Old24Seg EQU       Word Ptr BP - 2
  97. Handle   EQU       Word Ptr BP - 6
  98. OpenFlag EQU       Byte Ptr BP - 8
  99.  
  100. Extrn    __ParInfo:Far
  101. Extrn    __ParC:Far
  102. Extrn    __RetL:Far
  103.  
  104. Group    DGROUP    _ftData
  105.  
  106. Segment  _ftData   Word      Public    "DATA"
  107. IsReady  DB        ?
  108. Ends     _ftData
  109.  
  110. Segment  _NanFor   Word      Public    "CODE"
  111.          Assume    CS:_NanFor,DS:DGROUP
  112.  
  113. Proc     FT_ISPRINT          Far
  114.  
  115.          Push      BP                        ; Save BP
  116.          Mov       BP,SP                     ; Set up stack reference
  117.          Sub       SP,8                      ; Allocate room for locals
  118.          Mov       [Handle],4                ; Default to PRN
  119.          Mov       [OpenFlag],0              ; Initialize flag
  120.  
  121.          Xor       AX,AX                     ; Request param count
  122.          Push      AX                        ; Put request on stack
  123.          Call      __ParInfo                 ; Count params
  124.          Or        AX,AX                     ; Zero params?
  125.          JZ        PrtTest                   ; Yes, so use default
  126.  
  127. ParType: Mov       AX,1                      ; Specify first param
  128.          Push      AX                        ; Put param # on stack
  129.          Call      __ParInfo                 ; Get type
  130.          Test      AX,1                      ; Character?
  131.          JZ        PrtTest                   ; No, so use default
  132.  
  133. GetParam:Mov       AX,1                      ; Specify first param
  134.          Push      AX                        ; Put param # on stack
  135.          Call      __ParC                    ; Retrieve parameter
  136.  
  137.          Push      DS                        ; Save DS
  138.          Mov       DS,DX                     ; Get segment of device name
  139.          Mov       DX,AX                     ; Get offset of device name
  140.          Mov       AX,3D01h                  ; DOS service--open file or device
  141.          Int       21h                       ; Call DOS
  142.          Pop       DS                        ; Restore DS
  143.          JNC       DHandle                   ; No error, so device was opened
  144.          Xor       AX,AX                     ; Set return value to false
  145.          Jmp       Short RetVal              ; We're outta here
  146.  
  147. DHandle: Mov       [Handle],AX               ; Supply device's handle
  148.          Inc       [OpenFlag]                ; Set flag so close can occur
  149.          
  150. PrtTest: Call      Near _FTHook24            ; Install local INT 24h handler
  151.          Mov       [IsReady],1               ; Assume printer ready
  152.          Mov       AX,4407h                  ; DOS service--get output status
  153.          Mov       BX,[Handle]               ; Choose standard print device
  154.          Int       21h                       ; Call DOS
  155.          And       AL,[IsReady]              ; Combine error reports
  156.          CBW                                 ; Clear high byte
  157.          Call      Near _FTUnHook24          ; Restore old INT 24h vector
  158.  
  159. RetVal:  Push      AX                        ; Put return value on stack
  160.          Call      __RetL                    ; Return status to Clipper app
  161.  
  162.          Cmp       [OpenFlag],1              ; Need to close device?
  163.          JNE       Exit                      ; No, so go ahead and exit
  164.          Mov       AH,3Eh                    ; DOS service--close handle
  165.          Mov       BX,[Handle]               ; Supply file handle
  166.          Int       21h                       ; Call DOS
  167.  
  168. Exit:    Mov       SP,BP                     ; Realign stack
  169.          Pop       BP                        ; Restore BP
  170.          Ret                                 ; Far return to Clipper app
  171. Endp     FT_ISPRINT
  172.  
  173.  
  174.  
  175. Proc     _FTHook24 Near
  176.  
  177.          Push      DS                        ; Save DS
  178.  
  179.          Mov       AX,3524h                  ; DOS service--get INT 24h vector
  180.          Int       21h                       ; Call DOS
  181.          Mov       [Old24Ofs],BX             ; Save offset
  182.          Mov       [Old24Seg],ES             ; Save segment value
  183.  
  184.          Push      CS
  185.          Pop       DS                        ; Set DS to local segment
  186.          Mov       DX,Offset _NanFor:Int_24  ; Offset of local handler
  187.          Mov       AX,2524h                  ; DOS service--set INT 24h vector
  188.          Int       21h                       ; Call DOS  
  189.  
  190.          Pop       DS
  191.          Ret                                 ; Near return
  192. Endp     _FTHook24
  193.  
  194.  
  195.  
  196. Proc     _FTUnHook24         Near
  197.  
  198.          Push      DS                        ; Save DS
  199.          Push      AX                        ; Save AX
  200.          Mov       AX,2524h                  ; DOS service--set INT 24h vector
  201.          LDS       DX,[Old24Vec]             ; Get address of original handler
  202.          Int       21h                       ; Call DOS
  203.          Pop       AX
  204.          Pop       DS
  205.          Ret                                 ; Near return
  206. Endp     _FTUnHook24
  207.  
  208.  
  209.  
  210. Proc     Int_24    Far
  211.  
  212.          Push      DS
  213.          Mov       AX,DGROUP
  214.          Mov       DS,AX
  215.          Mov       [IsReady],0               ; Indicate not ready
  216.          Pop       DS
  217.          Xor       AX,AX                     ; Tell DOS to ignore error
  218.          IRet
  219. Endp     Int_24
  220. Ends     _NanFor
  221. End
  222. 
  223.