home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / msdos / programm / 10591 < prev    next >
Encoding:
Text File  |  1992-11-13  |  9.1 KB  |  293 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!munnari.oz.au!bruce.cs.monash.edu.au!monu6!giaeb!s1110238
  3. From: s1110238@giaeb.cc.monash.edu.au (Lee Hollingworth)
  4. Subject: Re: Specifying printer ports
  5. Message-ID: <s1110238.721657043@giaeb>
  6. Keywords: printer
  7. Sender: news@monu6.cc.monash.edu.au (Usenet system)
  8. Organization: Monash University, Melb., Australia.
  9. References: <1992Nov11.150935.20036@aruba.uucp>
  10. Date: Fri, 13 Nov 1992 12:17:23 GMT
  11. Lines: 280
  12.  
  13. rickt@aruba.UUCP (Rickey Thomas Tom) writes:
  14.  
  15. >    I have an application that requires printing through the parallel port.
  16. >Normally, I could say something like
  17.  
  18. >        fprintf( stdprn,".....");
  19.  
  20. >However, I believe that this will send output to LPT1. But, in my application, I
  21. >am using LPT1 to do other things (interrupt driven data acquisition). I need a
  22. >way of forcing output to LPT2 within the program. I have several TSR program
  23. >which would work, but I would like to avoid using them if I can.
  24.  
  25. Note sure if this will help, but here is some code I use in a text editor
  26. I wrote...
  27.  
  28. Lee Hollingworth
  29. s1110238@giaeb.cc.monash.edu.au
  30.  
  31. # This is a shell archive.  Remove anything before this line,
  32. # then unpack it by saving it in a file and typing "sh file".
  33. #
  34. # Wrapped by Lee Hollingworth <s1110238@giaeb> on Fri Nov 13 23:35:19 1992
  35. #
  36. # This archive contains:
  37. #    biosibm.asm    biosibm.h    readme.1st    utils.c        
  38. #
  39.  
  40. LANG=""; export LANG
  41. PATH=/bin:/usr/bin:$PATH; export PATH
  42.  
  43. echo x - biosibm.asm
  44. cat >biosibm.asm <<'@EOF'
  45. ;---------------------------------------------------------------------------
  46. ; file:       biosibm.asm
  47. ; purpose:    int 16h keyboard status functions and int 17h printer functions
  48. ; assembler:  MASM 6.0
  49. ; compile:    ml /c /Cp /Cx /W3 biosibm.asm
  50. ; author:     Lee Hollingworth s1110238@giaeb.cc.monash.edu.au
  51. ; header:     biosibm.h
  52. ;---------------------------------------------------------------------------
  53.  
  54. key_ready   equ     11h             ; function K_READY
  55.  
  56.             .model small
  57.             .code
  58. public      _bioskeybrd
  59. ;----------------------- bioskeybrd ----------------------------------------
  60. ;   call    unsigned int bioskeybrd(service);
  61. ;           unsigned int service;
  62. ;   services
  63. ;           K_READ      read character and scan code, wait if none ready
  64. ;           K_READY     check if a key is waiting to be read
  65. ;           K_STATUS    get the current keyboard status
  66. ;               refer to biosibm.h for defines
  67. ;----------------------------------------------------------------------------
  68. _bioskeybrd proc
  69.             push    bp
  70.             mov     bp, sp              ; mov stack pointer to base pointer
  71.             push    si
  72.             push    di
  73.  
  74.             mov     ah, [bp+4]          ; get service argument
  75.             cmp     ah, key_ready       ; special case for key_ready service
  76.             jne     key_read_status     ; jump if not key_ready
  77.             int     16h
  78.             jnz     alldone             ; jmp if character waiting to be read
  79.             xor     ax, ax              ; otherwise return 0
  80.             jmp     alldone
  81.  
  82. key_read_status:
  83.             int     16h                 ; simple call for read or status
  84.  
  85. alldone:
  86.             pop     di
  87.             pop     si
  88.             pop     bp
  89.             ret
  90. _bioskeybrd endp
  91.  
  92. public      _prnwrite
  93. ;------------------------- prnwrite ----------------------------------------
  94. ;   call    unsigned int prnwrite(ch, port);
  95. ;           unsigned char ch
  96. ;           unsigned int port
  97. ;               refer to biosibm.h for defines
  98. ;----------------------------------------------------------------------------
  99. _prnwrite   proc
  100.             push    bp
  101.             mov     bp, sp              ; mov stack pointer to base pointer
  102.             push    si
  103.             push    di
  104.  
  105.             mov     al, [bp+4]          ; get character to print
  106.             mov     dx, [bp+6]          ; get port number
  107.             mov     ah, 00h
  108.             int     17h
  109.             xor     al, al              ; clear al
  110.  
  111.             pop     di
  112.             pop     si
  113.             pop     bp
  114.             ret
  115. _prnwrite   endp
  116.  
  117. public      _prninit
  118. ;------------------------- prninit ----------------------------------------
  119. ;   call    unsigned int prninit(port);
  120. ;           unsigned int port
  121. ;               refer to biosibm.h for defines
  122. ;----------------------------------------------------------------------------
  123. _prninit   proc
  124.             push    bp
  125.             mov     bp, sp              ; mov stack pointer to base pointer
  126.             push    si
  127.             push    di
  128.  
  129.             mov     al, [bp+4]          ; get printer port
  130.             mov     ah, 01h
  131.             int     17h
  132.             xor     al, al              ; clear al
  133.  
  134.             pop     di
  135.             pop     si
  136.             pop     bp
  137.             ret
  138. _prninit   endp
  139.  
  140. public      _prnstatus
  141. ;------------------------- prnstatus ----------------------------------------
  142. ;   call    unsigned int prnstatus(port);
  143. ;           unsigned int port
  144. ;               refer to biosibm.h for defines
  145. ;----------------------------------------------------------------------------
  146. _prnstatus   proc
  147.             push    bp
  148.             mov     bp, sp              ; mov stack pointer to base pointer
  149.             push    si
  150.             push    di
  151.  
  152.             mov     al, [bp+4]          ; get printer port
  153.             mov     ah, 02h
  154.             int     17h
  155.             xor     al, al              ; clear al
  156.  
  157.             pop     di
  158.             pop     si
  159.             pop     bp
  160.             ret
  161. _prnstatus   endp
  162.  
  163.             end
  164. @EOF
  165.  
  166. chmod 600 biosibm.asm
  167.  
  168. echo x - biosibm.h
  169. cat >biosibm.h <<'@EOF'
  170. /****
  171.  * file:    biosibm.h
  172.  * purpose: defines for biosibm.asm
  173.  * author:  Lee Hollingworth s1110238@giaeb.cc.monash.edu.au
  174.  ****/
  175.  
  176. #ifndef BIOSKEYS
  177. #define BIOSKEYS
  178.  
  179. /* bioskeybrd services */
  180. #define K_READ      0x10
  181. #define K_READY     0x11
  182. #define K_STATUS    0x12
  183.  
  184. /* enhanced keyboard status bits */
  185. #define K_RSHIFT    0x0000         /* right shift is down   */
  186. #define K_LSHIFT    0x0002         /* left shift is down    */
  187. #define K_CTRL      0x0004         /* both Ctrl keys down   */
  188. #define K_ALT       0x0008         /* both Alt keys down    */
  189. #define K_SCROLL    0x0010         /* scroll lock toggle on */
  190. #define K_NUM       0x0020         /* num lock toggle on    */
  191. #define K_CAP       0x0040         /* cap lock toggle on    */
  192. #define K_INS       0x0080         /* insert toggle is on   */
  193. #define K_LCTRL     0x0100         /* left Ctrl key down    */
  194. #define K_LALT      0x0200         /* left Alt key down     */
  195. #define K_RCTRL     0x0400         /* right Ctrl key down   */
  196. #define K_RALT      0x0800         /* right Alt key down    */
  197. #define K_PSCROLL   0x1000         /* scroll key is down    */
  198. #define K_PNUM      0x2000         /* num key is down       */
  199. #define K_PCAP      0x4000         /* cap key is down       */
  200. #define K_SYSRQ     0x8000         /* sys rq key is down    */
  201.  
  202. #endif
  203.  
  204. #ifndef BIOSPRN
  205. #define BIOSPRN
  206.  
  207. #define LPT1            0           /* printer port 1 */
  208. #define LPT2            1           /* printer port 2 */
  209. #define LPT3            2           /* printer port 3 */
  210.  
  211. #define PR_TIME_OUT     0x0100      /* printer timed out */
  212. #define PR_IO_ERROR     0x0800      /* printer i/o error occurred */
  213. #define PR_SELECETED    0x1000      /* printer selected */
  214. #define PR_OUT_OF_PAPER 0x2000      /* out of paper */
  215. #define PR_ACK          0x4000      /* printer acknowlege */
  216. #define PR_NOT_BUSY     0x8000      /* printer is not busy */
  217.  
  218. #endif
  219.  
  220.  
  221. extern unsigned bioskeybrd(unsigned int service);
  222. extern unsigned prnwrite(unsigned int ch, unsigned int port);
  223. extern unsigned prninit(unsigned int port);
  224. extern unsigned prnstatus(unsigned int port);
  225. @EOF
  226.  
  227. chmod 600 biosibm.h
  228.  
  229. echo x - readme.1st
  230. cat >readme.1st <<'@EOF'
  231.  
  232. The functions in these files have been cut out of another application
  233. and are not expected to run as is -- they must be included into the
  234. body of another program.
  235.  
  236. Lee Hollingworth
  237. s1110238@giaeb.cc.monash.edu.au
  238. @EOF
  239.  
  240. chmod 600 readme.1st
  241.  
  242. echo x - utils.c
  243. cat >utils.c <<'@EOF'
  244. #include <stdio.h>
  245. #include "common.h"     /* global variables */
  246. #include "biosibm.h"
  247.  
  248. /***
  249.  * function: print
  250.  * purpose : print the current text file
  251.  * passed  : fname -- file name
  252.  ***/
  253. status print(char *fname)
  254. {
  255.     FILE *infile;
  256.     unsigned count = 0;             /* lines counted so far */
  257.     int ch;                         /* character to print */
  258.     int i = 0;                      /* loop counter */
  259.     extern unsigned g_prn_port;     /* global printer port */
  260.     extern unsigned g_lines_pp;     /* global lines per page */
  261.  
  262.     if ((infile = fopen(fname, "r")) == NULL) {
  263.         perror(fname);
  264.         return ERROR;
  265.     }
  266.     prninit(g_prn_port);
  267.     while ((ch = fgetc(infile)) != EOF) {
  268.         if (ch == '\n') {
  269.             prnwrite(CR, g_prn_port);
  270.             prnwrite(LF, g_prn_port);
  271.             if (g_lines_pp) {
  272.                 if (++count >= g_lines_pp) {
  273.                     count = 0;
  274.                     prnwrite(FF, g_prn_port);
  275.                 }
  276.             }
  277.         }
  278.         else if (ch != FF || ch != VT) {
  279.             prnwrite(ch, g_prn_port);
  280.         }
  281.     }
  282.     prnwrite(FF, g_prn_port);
  283.     fclose(infile);
  284.     return OK;
  285. }
  286.  
  287.  
  288. @EOF
  289.  
  290. chmod 600 utils.c
  291.  
  292. exit 0
  293.