lllpt.asm
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:7k
源码类别:

操作系统开发

开发平台:

Visual C++

  1.         TITLE   LLLPT - GW-BASIC Printer Interface
  2. ;***
  3. ; LLLPT - GW-BASIC Printer Interface
  4. ;
  5. ;       Copyright <C> 1986, Microsoft Corporation
  6. ;
  7. ;Purpose:
  8. ;
  9. ;******************************************************************************
  10.         INCLUDE switch.inc
  11. INCLUDE rmacros.inc
  12. useSeg _DATA
  13. useSeg DV_TEXT 
  14. INCLUDE seg.inc 
  15.         INCLUDE ibmunv.inc
  16. sBegin _DATA
  17. LPTNAM  DB      "LPT"           ;name for use in printer open
  18. LPTNUM  DB      " ",0           ;number of printer to open (1 to 3)
  19. sEnd _DATA
  20. sBegin DV_TEXT 
  21. externNP B$DOS3CHECK ; Check for dos 3
  22. assumes CS,DV_TEXT
  23. ;***
  24. ;B$OPNLPT - OPEN selected printer
  25. ;OEM-interface routine
  26. ;
  27. ;Purpose:
  28. ; This routine will open a communications channel to a printer
  29. ; and return a file handle to this channel and a status flag.
  30. ;
  31. ; There are two ways to implement the three LPT routines
  32. ; (B$OPNLPT, B$SNDLPT, and B$CLSLPT). They are based
  33. ; on the fact that the file handle used by all three is
  34. ; never checked or used outside of these routines.  The rest
  35. ; of the runtime will just store it away and pass it back to
  36. ; these routines.
  37. ;
  38. ; 1.) Direct output to a printer.  In this case, there would be
  39. ;     no file handle, and the value passed can be ignored.
  40. ;     B$OPNLPT would have no work to do, and could just return
  41. ;     with AH=0. B$CLSLPT would just return.  The disadvantage
  42. ;     to this is that it will not work over networks or for
  43. ;     redirected output.
  44. ;
  45. ; 2.) Use DOS file handles.  This is probably the most standard
  46. ;     method as it allows for redirected printers and network
  47. ;     printing.  In this case, B$OPNLPT would open the printer
  48. ;     as a file, possibly do hardware checks for the existence
  49. ;     of the printer if it is not redirected, and return the
  50. ;     handle for use in other two routines.  B$SNDLPT would
  51. ;     use the file for writing, and B$CLSLPT would close the
  52. ;     file.
  53. ;
  54. ; If the B$OPNLPT returns [AH] = 1, the runtime will signal
  55. ; a Device Not Available Error.
  56. ;
  57. ;
  58. ;Entry:
  59. ; [AH]  = printer number (0-2)
  60. ;
  61. ;Exit:
  62. ; [BX]  = file handle
  63. ; [AH]  = 0 if open successful, 1 if open failed.
  64. ;
  65. ;Uses:
  66. ; Per convention
  67. ;
  68. ;Preserves:
  69. ; CX,DX
  70. ;
  71. ;Exceptions:
  72. ; None.
  73. ;******************************************************************************
  74. cProc B$OPNLPT,<NEAR,PUBLIC>,<DX,SI> 
  75. cBegin
  76.         CMP     AH,2            ;test against upper limit
  77.         JA      OPNLPT_UNAVAIL  ;if too high, then not available
  78.         MOV     BL,AH           ;move index into register
  79.         XOR     BH,BH           ;make it a 16-bit value
  80.         SHL     BX,1            ;shift to make it a word index
  81.         MOV     SI,BX           ;keep word index for later
  82.         ADD     AH,"1"          ;map 0 to "1", 1 to "2", etc.
  83.         MOV     LPTNUM,AH       ;put unit number in device name
  84.         MOV     DX,OFFSET DGROUP:LPTNAM ;define name string to open
  85.         MOV     AX,3D01H        ;ready to open file for writing
  86.         INT     21H             ;open the file
  87.         JC      OPNLPT_UNAVAIL  ;jump if device not available
  88.         MOV     BX,AX           ;move handle
  89.         MOV     AX,4400H        ;get device status
  90.         INT     21H             ;perform the action
  91.         TEST    DL,80H          ;test if character device
  92.         JZ      OPNLPT_CLOSE    ;jump if error to close and exit
  93.         MOV     AX,4401H        ;IOCTL to set device status
  94.         OR      DL,20H          ;change to raw mode
  95.         XOR     DH,DH           ;clear upper byte...
  96.         INT     21H             ;set the mode
  97. cCall B$DOS3CHECK ; See if DOS 3
  98.         JB      OPNLPT_DOS2     ;jump if DOS2
  99.         MOV     AX,440AH        ;get IOCTL call for redirection
  100.         INT     21H             ;flag is in DH
  101.         TEST    DH,80H          ;flag set if redirected
  102.         JNZ     OPNLPT_SUCCESS  ;jump if redirected, done
  103. OPNLPT_DOS2:
  104.         PUSH    DS              ;save BASCOM data segment
  105.         MOV     AX,40H          ;get BIOS data segment
  106.         MOV     DS,AX           ;establish addressability
  107.         TEST    DS:8[SI],0FFFFH ;test if adapter exists
  108.         POP     DS              ;restore data segment
  109.         JNZ     OPNLPT_SUCCESS  ;if so, success, jump
  110. OPNLPT_CLOSE:
  111.         MOV     AH,3EH          ;system code for closing
  112.         INT     21H             ;close the file opened
  113. OPNLPT_UNAVAIL:
  114.         MOV     AH,1            ;error code for device unavailable
  115.         XOR     BX,BX           ;clear BX for error condition
  116. JMP SHORT OPNLPT_DONE ;jump to exit
  117. OPNLPT_SUCCESS:
  118.         XOR     AH,AH           ;clear error code for success
  119. OPNLPT_DONE:
  120. cEnd
  121. ;***
  122. ;B$SNDLPT - Send a character to selected printer
  123. ;OEM-interface routine
  124. ;
  125. ;Purpose:
  126. ; This routine takes a character and a file handle from
  127. ; B$OPNLPT and sends the character to the printer specified
  128. ; by the file handle.  If there are any errors, they are
  129. ; returned in AH.
  130. ;
  131. ; See the documentation for B$OPNLPT for more information.
  132. ;
  133. ;Entry:
  134. ; [AL]  = character
  135. ; [BX]  = file handle
  136. ;
  137. ;Exit:
  138. ; [AH]  = 0: success
  139. ; 1: device not available
  140. ; 2: time out
  141. ; 3: out of paper
  142. ;
  143. ;Uses:
  144. ; Per Convention
  145. ;
  146. ;Preserves:
  147. ; BX, CX, DX
  148. ;
  149. ;Exceptions:
  150. ;
  151. ;******************************************************************************
  152. cProc B$SNDLPT,<NEAR,PUBLIC>,<DX,CX> 
  153. cBegin
  154. PUSH AX ; store byte in stack
  155. MOV DX,SP ; [DS:DX] points to data to be output
  156. .ERRE ID_SSEQDS ; assumes DS=SS
  157.         MOV     CX,1            ;[CX] = # of bytes to be written
  158.         MOV     AH,40H          ;read operation
  159.         INT     21H             ;success reflected in carry
  160. POP DX ; even stack
  161.         JC      SNDLPT_UNAVAIL  ;jump if error on write
  162.         XOR     AH,AH           ;return 0 in AH for no error
  163.         JMP     SHORT SNDLPT_DONE ;jump to finish up
  164. SNDLPT_UNAVAIL:
  165.         MOV     AH,1            ;set error code
  166. SNDLPT_DONE:
  167. cEnd
  168. ;***
  169. ; B$CLSLPT - Close selected printer
  170. ;OEM-interface routine
  171. ;
  172. ;Purpose:
  173. ; This routine takes a file handle prepared by B$OPNLPT
  174. ; for a line printer and closes the associated communications
  175. ; channel.  All needed termination for the printer should be
  176. ; done at this point.  All errors are ignored.
  177. ;
  178. ; See the documentation for B$OPNLPT for more information.
  179. ;
  180. ;Entry:
  181. ; [BX]  = file handle
  182. ;
  183. ;Exit:
  184. ; None
  185. ;
  186. ;Uses:
  187. ; Per Convention
  188. ;
  189. ;Preserves:
  190. ; AX, BX, CX, DX
  191. ;
  192. ;Exceptions:
  193. ; None.
  194. ;******************************************************************************
  195. cProc B$CLSLPT,<NEAR,PUBLIC>,AX 
  196. cBegin
  197.         MOV     AH,3EH          ;system code for closing
  198.         INT     21H             ;close the file opened
  199. cEnd
  200. sEnd DV_TEXT 
  201.         END