🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #3652

Re: Specifying printer ports

#3652
From: Lee Hollingworth
Date: Fri, 13 Nov 1992 12:17
280 lines
9581 bytes
rickt@aruba.UUCP (Rickey Thomas Tom) writes:

>    I have an application that requires printing through the parallel port.
>Normally, I could say something like

>        fprintf( stdprn,".....");

>However, I believe that this will send output to LPT1. But, in my application, I
>am using LPT1 to do other things (interrupt driven data acquisition). I need a
>way of forcing output to LPT2 within the program. I have several TSR program
>which would work, but I would like to avoid using them if I can.

Note sure if this will help, but here is some code I use in a text editor
I wrote...

Lee Hollingworth
s1110238@giaeb.cc.monash.edu.au

# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by Lee Hollingworth <s1110238@giaeb> on Fri Nov 13 23:35:19 1992
#
# This archive contains:
#	biosibm.asm	biosibm.h	readme.1st	utils.c		
#

LANG=""; export LANG
PATH=/bin:/usr/bin:$PATH; export PATH

echo x - biosibm.asm
cat >biosibm.asm <<'@EOF'
;---------------------------------------------------------------------------
; file:       biosibm.asm
; purpose:    int 16h keyboard status functions and int 17h printer functions
; assembler:  MASM 6.0
; compile:    ml /c /Cp /Cx /W3 biosibm.asm
; author:     Lee Hollingworth s1110238@giaeb.cc.monash.edu.au
; header:     biosibm.h
;---------------------------------------------------------------------------

key_ready   equ     11h             ; function K_READY

            .model small
            .code
public      _bioskeybrd
;----------------------- bioskeybrd ----------------------------------------
;   call    unsigned int bioskeybrd(service);
;           unsigned int service;
;   services
;           K_READ      read character and scan code, wait if none ready
;           K_READY     check if a key is waiting to be read
;           K_STATUS    get the current keyboard status
;               refer to biosibm.h for defines
;----------------------------------------------------------------------------
_bioskeybrd proc
            push    bp
            mov     bp, sp              ; mov stack pointer to base pointer
            push    si
            push    di

            mov     ah, [bp+4]          ; get service argument
            cmp     ah, key_ready       ; special case for key_ready service
            jne     key_read_status     ; jump if not key_ready
            int     16h
            jnz     alldone             ; jmp if character waiting to be read
            xor     ax, ax              ; otherwise return 0
            jmp     alldone

key_read_status:
            int     16h                 ; simple call for read or status

alldone:
            pop     di
            pop     si
            pop     bp
            ret
_bioskeybrd endp

public      _prnwrite
;------------------------- prnwrite ----------------------------------------
;   call    unsigned int prnwrite(ch, port);
;           unsigned char ch
;           unsigned int port
;               refer to biosibm.h for defines
;----------------------------------------------------------------------------
_prnwrite   proc
            push    bp
            mov     bp, sp              ; mov stack pointer to base pointer
            push    si
            push    di

            mov     al, [bp+4]          ; get character to print
            mov     dx, [bp+6]          ; get port number
            mov     ah, 00h
            int     17h
            xor     al, al              ; clear al

            pop     di
            pop     si
            pop     bp
            ret
_prnwrite   endp

public      _prninit
;------------------------- prninit ----------------------------------------
;   call    unsigned int prninit(port);
;           unsigned int port
;               refer to biosibm.h for defines
;----------------------------------------------------------------------------
_prninit   proc
            push    bp
            mov     bp, sp              ; mov stack pointer to base pointer
            push    si
            push    di

            mov     al, [bp+4]          ; get printer port
            mov     ah, 01h
            int     17h
            xor     al, al              ; clear al

            pop     di
            pop     si
            pop     bp
            ret
_prninit   endp

public      _prnstatus
;------------------------- prnstatus ----------------------------------------
;   call    unsigned int prnstatus(port);
;           unsigned int port
;               refer to biosibm.h for defines
;----------------------------------------------------------------------------
_prnstatus   proc
            push    bp
            mov     bp, sp              ; mov stack pointer to base pointer
            push    si
            push    di

            mov     al, [bp+4]          ; get printer port
            mov     ah, 02h
            int     17h
            xor     al, al              ; clear al

            pop     di
            pop     si
            pop     bp
            ret
_prnstatus   endp

            end
@EOF

chmod 600 biosibm.asm

echo x - biosibm.h
cat >biosibm.h <<'@EOF'
/****
 * file:    biosibm.h
 * purpose: defines for biosibm.asm
 * author:  Lee Hollingworth s1110238@giaeb.cc.monash.edu.au
 ****/

#ifndef BIOSKEYS
#define BIOSKEYS

/* bioskeybrd services */
#define K_READ      0x10
#define K_READY     0x11
#define K_STATUS    0x12

/* enhanced keyboard status bits */
#define K_RSHIFT    0x0000         /* right shift is down   */
#define K_LSHIFT    0x0002         /* left shift is down    */
#define K_CTRL      0x0004         /* both Ctrl keys down   */
#define K_ALT       0x0008         /* both Alt keys down    */
#define K_SCROLL    0x0010         /* scroll lock toggle on */
#define K_NUM       0x0020         /* num lock toggle on    */
#define K_CAP       0x0040         /* cap lock toggle on    */
#define K_INS       0x0080         /* insert toggle is on   */
#define K_LCTRL     0x0100         /* left Ctrl key down    */
#define K_LALT      0x0200         /* left Alt key down     */
#define K_RCTRL     0x0400         /* right Ctrl key down   */
#define K_RALT      0x0800         /* right Alt key down    */
#define K_PSCROLL   0x1000         /* scroll key is down    */
#define K_PNUM      0x2000         /* num key is down       */
#define K_PCAP      0x4000         /* cap key is down       */
#define K_SYSRQ     0x8000         /* sys rq key is down    */

#endif

#ifndef BIOSPRN
#define BIOSPRN

#define LPT1            0           /* printer port 1 */
#define LPT2            1           /* printer port 2 */
#define LPT3            2           /* printer port 3 */

#define PR_TIME_OUT     0x0100      /* printer timed out */
#define PR_IO_ERROR     0x0800      /* printer i/o error occurred */
#define PR_SELECETED    0x1000      /* printer selected */
#define PR_OUT_OF_PAPER 0x2000      /* out of paper */
#define PR_ACK          0x4000      /* printer acknowlege */
#define PR_NOT_BUSY     0x8000      /* printer is not busy */

#endif


extern unsigned bioskeybrd(unsigned int service);
extern unsigned prnwrite(unsigned int ch, unsigned int port);
extern unsigned prninit(unsigned int port);
extern unsigned prnstatus(unsigned int port);
@EOF

chmod 600 biosibm.h

echo x - readme.1st
cat >readme.1st <<'@EOF'

The functions in these files have been cut out of another application
and are not expected to run as is -- they must be included into the
body of another program.

Lee Hollingworth
s1110238@giaeb.cc.monash.edu.au
@EOF

chmod 600 readme.1st

echo x - utils.c
cat >utils.c <<'@EOF'
#include <stdio.h>
#include "common.h"     /* global variables */
#include "biosibm.h"

/***
 * function: print
 * purpose : print the current text file
 * passed  : fname -- file name
 ***/
status print(char *fname)
{
    FILE *infile;
    unsigned count = 0;             /* lines counted so far */
    int ch;                         /* character to print */
    int i = 0;                      /* loop counter */
    extern unsigned g_prn_port;     /* global printer port */
    extern unsigned g_lines_pp;     /* global lines per page */

    if ((infile = fopen(fname, "r")) == NULL) {
        perror(fname);
        return ERROR;
    }
    prninit(g_prn_port);
    while ((ch = fgetc(infile)) != EOF) {
        if (ch == '\n') {
            prnwrite(CR, g_prn_port);
            prnwrite(LF, g_prn_port);
            if (g_lines_pp) {
                if (++count >= g_lines_pp) {
                    count = 0;
                    prnwrite(FF, g_prn_port);
                }
            }
        }
        else if (ch != FF || ch != VT) {
            prnwrite(ch, g_prn_port);
        }
    }
    prnwrite(FF, g_prn_port);
    fclose(infile);
    return OK;
}


@EOF

chmod 600 utils.c

exit 0
Technical Details
Message-ID: <s1110238.721657043@giaeb>
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!bruce.cs.monash.edu.au!monu6!giaeb!s1110238
References: <1992Nov11.150935.20036@aruba.uucp>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!bruce.cs.monash.edu.au!monu6!giaeb!s1110238
From: s1110238@giaeb.cc.monash.edu.au (Lee Hollingworth)
Subject: Re: Specifying printer ports
Message-ID: <s1110238.721657043@giaeb>
Keywords: printer
Sender: news@monu6.cc.monash.edu.au (Usenet system)
Organization: Monash University, Melb., Australia.
References: <1992Nov11.150935.20036@aruba.uucp>
Date: Fri, 13 Nov 1992 12:17:23 GMT
Lines: 280