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

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