home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / NFSRC305.ZIP / ASM / ISPRINT.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-01  |  12.4 KB  |  317 lines

  1. ; File......: ISPRINT.ASM
  2. ; Author....: Ted Means
  3. ; CIS ID....: 73067,3332
  4. ;
  5. ; This function is an original work by Ted Means and is placed in the
  6. ; public domain.  I got the idea from Norm Mongeau, but the code is
  7. ; all mine.
  8. ;
  9. ; Modification history:
  10. ; ---------------------
  11. ;
  12. ;     Rev 1.3   16 Jul 1993 00:00:18   GLENN
  13. ;  Modified for compatibility in protected mode under ExoSpace.  Should
  14. ;  work in real mode as well.
  15. ;
  16. ;     Rev 1.2   15 Aug 1991 23:07:56   GLENN
  17. ;  Forest Belt proofread/edited/cleaned up doc
  18. ;
  19. ;     Rev 1.1   14 Jun 1991 19:54:38   GLENN
  20. ;  Minor edit to file header
  21. ;
  22. ;     Rev 1.0   01 Apr 1991 01:03:26   GLENN
  23. ;  Nanforum Toolkit
  24. ;
  25. ;
  26.  
  27.  
  28. ;  $DOC$
  29. ;  $FUNCNAME$
  30. ;     FT_ISPRINT()
  31. ;  $CATEGORY$
  32. ;     DOS/BIOS
  33. ;  $ONELINER$
  34. ;     Check printer status
  35. ;  $SYNTAX$
  36. ;     FT_ISPRINT( [ <cDevice> ] ) -> lResult
  37. ;  $ARGUMENTS$
  38. ;     <cDevice> is optional and is the device to test (LPT2, COM1, etc.).
  39. ;     If omitted, the function will default to the PRN device.
  40. ;  $RETURNS$
  41. ;     .T.  if device is ready for output.
  42. ;     .F.  if one of the following conditions occurs:
  43. ;          1)  The device is not ready.
  44. ;          2)  The device does not exist.
  45. ;          3)  DOS couldn't open the device for some reason
  46. ;              (such as no file handles available).
  47. ;  $DESCRIPTION$
  48. ;     The Clipper IsPrinter() function is somewhat limited because it only
  49. ;     works with LPT1.  Furthermore, it talks directly to the hardware, so
  50. ;     if you have redirected LPT1 via the DOS MODE command, the IsPrinter()
  51. ;     function will return erroneous results.
  52. ;
  53. ;     This function offers a better alternative.  Instead of talking to the
  54. ;     hardware, it issues a DOS call that checks to see if the device is
  55. ;     ready or not.  That gives DOS an opportunity to deal with any
  56. ;     redirections, and since you pass the device name as a parameter, you
  57. ;     can test any device, not just LPT1 (note that the function defaults
  58. ;     to PRN if you fail to pass a valid parameter).
  59. ;
  60. ;     The function also temporarily traps the DOS critical error handler so
  61. ;     you don't get any nasty error messages if the device isn't ready.  It
  62. ;     restores the old critical error handler before exiting.
  63. ;
  64. ;     Note that although this function is mainly designed for testing
  65. ;     printers, you can also check to see if a drive is ready.  Since DOS
  66. ;     thinks the NUL device exists on every drive, you can pass a drive
  67. ;     letter followed by NUL as a parameter.  If DOS is able to open the
  68. ;     NUL device, then the drive is ready, otherwise the door is open or
  69. ;     something else is wrong.
  70. ;
  71. ;     The source code is written to adhere to Turbo Assembler's IDEAL mode.
  72. ;     To use another assembler, you will need to rearrange the PROC and
  73. ;     SEGMENT directives, and also the ENDP and ENDS directives (a very
  74. ;     minor task).
  75. ;  $EXAMPLES$
  76. ;     IF ! FT_ISPRINT()
  77. ;        Qout( "PRN is not ready!" )
  78. ;     ENDIF
  79. ;
  80. ;     IF ! FT_ISPRINT( "COM2" )
  81. ;        Qout( "Check the device on COM2.  Something is wrong." )
  82. ;     ENDIF
  83. ;
  84. ;     IF ! FT_ISPRINT( "A:\NUL" )
  85. ;        Qout( "Oops, better check drive A!" )
  86. ;     ENDIF
  87. ;  $END$
  88. ;
  89.  
  90. IDEAL
  91. P286
  92.  
  93. Public    FT_ISPRINT
  94.  
  95. Handle    EQU       Word Ptr BP - 2
  96. OpenFlag  EQU       Byte Ptr BP - 4
  97.  
  98. Extrn     __ParInfo:Far
  99. Extrn     __ParC:Far
  100. Extrn     __RetL:Far
  101. Extrn     __bcopy:Far                             ; Internal!!!
  102.  
  103. Extrn     cpmiIsProtected:Far
  104. Extrn     cpmiFarCallReal:Far
  105. Extrn     cpmiAllocateDOSMem:Far
  106. Extrn     cpmiFreeDOSMem:Far
  107. Extrn     cpmiRealPtr:Far
  108.  
  109. Struc     CPUREGS
  110. AX        DW        ?
  111. BX        DW        ?
  112. CX        DW        ?
  113. DX        DW        ?
  114. SI        DW        ?
  115. DI        DW        ?
  116. BP        DW        ?
  117. DS        DW        ?
  118. ES        DW        ?
  119. Flags     DW        ?
  120. Ends      CPUREGS
  121.  
  122. Segment   _NanFor   Word      Public    "CODE"
  123.           Assume    CS:_NanFor
  124.  
  125. Proc      FT_IsPrint          Far
  126.  
  127.           Push      BP                            ; Save BP
  128.           Mov       BP,SP                         ; Set up stack reference
  129.           Sub       SP,4                          ; Allocate room for locals
  130.           Mov       [OpenFlag],0                  ; Initialize flag
  131.  
  132.           Mov       AX,1                          ; Specify first param
  133.           Push      AX                            ; Put param # on stack
  134.           Call      __ParInfo                     ; Get data type
  135.           Inc       SP                            ; Realign stack
  136.           Inc       SP                            ; Realign stack
  137.           Test      AX,1                          ; Check for character
  138.           JNZ       @@Get                         ; If so, continue
  139.           Mov       BX,4                          ; Default to PRN
  140.           Jmp       Short @@Status                ; Bypass param retrieval
  141.  
  142. @@Get:    Mov       AX,1                          ; Specify first param
  143.           Push      AX                            ; Put param # on stack
  144.           Call      __ParC                        ; Retrieve parameter
  145.           Inc       SP                            ; Realign stack
  146.           Inc       SP                            ; Realign stack
  147.  
  148.           Push      DS                            ; Save DS
  149.           Mov       DS,DX                         ; Get segment of device name
  150.           Mov       DX,AX                         ; Get offset of device name
  151.           Mov       AX,3D01h                      ; DOS service--open file or device
  152.           Int       21h                           ; Call DOS
  153.           Pop       DS                            ; Restore DS
  154.           Mov       BX,AX                         ; Move handle to BX
  155.           Mov       AX,0                          ; Default to FALSE
  156.           CMC                                     ; Toggle carry flag
  157.           ADC       [OpenFlag],0                  ; Set open flag
  158.           JNZ       @@Status
  159.           Jmp       @@Done                        ; Bail if open failed
  160.  
  161. @@Status: Mov       [Handle],BX                   ; Store device's handle
  162.  
  163.           Call      cpmiIsProtected               ; Check CPU mode
  164.           Or        AX,AX                         ; AX clear?
  165.           JZ        @@Real                        ; If so, it's real mode
  166.  
  167.           Push      DOSBytes                      ; Put seg size on stack
  168.           Call      cpmiAllocateDOSMem            ; Allocate DOS memory
  169.           Or        AX,AX                         ; See if allocate failed
  170.           JZ        @@Done                        ; Return .F. if so
  171.  
  172.           Push      DOSBytes                      ; Put byte count on stack
  173.           Push      Seg __ftIsPrint               ; Put source ptr on stack
  174.           Push      Offset __ftIsPrint
  175.           Push      AX                            ; Put target ptr on stack
  176.           Push      0
  177.           Call      __bcopy                       ; Copy proc to low memory
  178.           Inc       SP
  179.           Inc       SP
  180.           Pop       AX
  181.           Add       SP,6                          ; Realign stack
  182.  
  183.           Push      AX                            ; Save selector
  184.  
  185.           Mov       ES,AX
  186.           Mov       [Word Ptr ES:ModCode1],Int24Ofs
  187.           Mov       [Word Ptr ES:ModCode2],ReadyOfs
  188.           Mov       [Word Ptr ES:ModCode3],ReadyOfs
  189.           Mov       [Word Ptr ES:ModCode4],ReadyOfs
  190.  
  191.           Push      ES                            ; Put pointer on stack
  192.           Push      0
  193.           Call      cpmiRealPtr                   ; Get real mode address
  194.  
  195.           Mov       BX,[Handle]                   ; Get handle
  196.  
  197.           RegPtr    EQU       ( CPUREGS Ptr BP - Size CPUREGS )
  198.  
  199.           Enter     Size CPUREGS,0                ; Allocate CPUREGS
  200.           Mov       [RegPtr.AX],BX                ; Supply handle
  201.           Push      DX                            ; Supply function pointer
  202.           Push      AX
  203.           LEA       AX,[BP - Size CPUREGS]        ; Get offset of CPUREGS
  204.           Push      SS
  205.           Push      AX
  206.           Push      SS
  207.           Push      AX
  208.           Call      cpmiFarCallReal               ; Check printer status
  209.           Mov       AX,[RegPtr.AX]
  210.           Leave                                   ; Deallocate CPUREGS
  211.  
  212.           Pop       BX                            ; Get selector back
  213.           Push      AX                            ; Save return value
  214.           Push      BX                            ; Put selector on stack
  215.           Call      cpmiFreeDOSMem                ; Free low DOS memory
  216.           Pop       AX                            ; Get return value back
  217.           Jmp       Short @@Done
  218.  
  219. @@Real:   Mov       AX,[Handle]                   ; Get handle
  220.           Call      __ftIsPrint                   ; Call status checker
  221.  
  222. @@Done:   Push      AX                            ; Put status on stack
  223.           Call      __RetL                        ; Return status to Clipper app
  224.  
  225.           Cmp       [OpenFlag],1                  ; Need to close device?
  226.           JNE       @@Exit                        ; No, so go ahead and exit
  227.           Mov       AH,3Eh                        ; DOS service--close handle
  228.           Mov       BX,[Handle]                   ; Supply file handle
  229.           Int       21h                           ; Call DOS
  230.  
  231. @@Exit:   Mov        SP,BP                        ; Realign stack
  232.           Pop        BP                           ; Restore BP
  233.           RetF                                    ; Far return to Clipper app
  234. Endp      FT_IsPrint
  235. Ends      _NanFor
  236.  
  237.  
  238.  
  239. Segment   _NanForInternal     Word      "CODE"
  240.           Assume    CS:_NanforInternal
  241.           Org       0
  242.  
  243. Old24Vec  EQU       DWord Ptr BP - 6
  244. Old24Ofs  EQU       Word Ptr BP - 6
  245. Old24Seg  EQU       Word Ptr BP - 4
  246.  
  247. Proc      __ftIsPrint         Far
  248.  
  249.           Push      BP
  250.           Mov       BP,SP
  251.           Sub       SP,6
  252.  
  253.           Mov       [Handle],AX                   ; Retrieve handle & store
  254.  
  255.           Mov       AX,3524h                      ; Get INT 24h vector
  256.           Int       21h                           ; Call DOS
  257.           Mov       [Old24Ofs],BX                 ; Save offset
  258.           Mov       [Old24Seg],ES                 ; Save segment value
  259.  
  260.           Push      DS                            ; Save DS
  261.           Push      CS                            ; Move CS . . .
  262.           Pop       DS                            ; . . . to DS
  263.  
  264.           ModCode1  =         $ - __ftIsPrint + 1
  265.  
  266.           Mov       DX,Offset Int_24              ; Get offset of handler
  267.           Mov       AX,2524h                      ; Set INT 24h vector
  268.           Int       21h                           ; Call DOS
  269.           Pop       DS                            ; Restore DS
  270.  
  271.           ModCode2  =         $ - __ftIsPrint + 3
  272.  
  273.           Mov       [CS:IsReady],1                ; Assume printer ready
  274.           Mov       AX,4407h                      ; Get output status
  275.           Mov       BX,[Handle]                   ; Choose print device
  276.           Int       21h                           ; Call DOS
  277.  
  278.           ModCode3  =         $ - __ftIsPrint + 3
  279.  
  280.           And       AL,[CS:IsReady]               ; Combine error reports
  281.           CBW                                     ; Clear high byte
  282.           Push      AX                            ; Save status for later
  283.  
  284.           Push      DS                            ; Save DS
  285.           Mov       AX,2524h                      ; Set INT 24h vector
  286.           LDS       DX,[Old24Vec]                 ; Get address of original handler
  287.           Int       21h                           ; Call DOS
  288.           Pop       DS
  289.  
  290.           Pop       AX                            ; Return status in AX
  291.           Mov       SP,BP                         ; Realign stack
  292.           Pop       BP                            ; Restore BP
  293.           RetF                                    ; Far return
  294. Endp      __ftIsPrint
  295.  
  296.  
  297.  
  298. Proc      Int_24     Far
  299.  
  300.           Int24Ofs  =         $ - __ftIsPrint
  301.  
  302.           ModCode4  =         $ - __ftIsPrint + 3
  303.  
  304.           Mov       [CS:IsReady],0                ; Indicate not ready
  305.           Xor       AX,AX                         ; Tell DOS to ignore error
  306.           IRet
  307.  
  308. @@1:      ReadyOfs  =         $ - __ftIsPrint
  309.  
  310. IsReady   DB        ?
  311.  
  312. Endp      Int_24
  313.  
  314. DOSBytes  =         $ - __ftIsPrint
  315.  
  316. Ends      _NanForInternal
  317. End