home *** CD-ROM | disk | FTP | other *** search
- /*
- * printer.c
- * contains: prdouble(),prcomp(),premph(),prbold(),prnorm(),prfixlf(),
- * contains: prvarlf(),prskip(),prbufclr(),prselect(),prbell(),prsetflen(),
- * contains: prhtabset(),prsetht(),prvtabset(),prsetvt(),prputc(),prs(),
- * contains: prputl(),prputcr(),prputlf(),prcrlf(),prblanks(),prhtab(),
- * contains: prvtab(),formfeed(),prunidir(),prunder(),prsub(),prsuper(),
- * contains: prhome(),prstop(),prfont(),prbits(),prx(),pruse(),prmode(),
- * contains: prreset(),prscreen(),prstatus(),
- *
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- *
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include "gfuncts.h"
-
- int tabs[3] = {
- 1,0,0 }; /* tab stops for default condition */
- int curr_printer=0, /* current printer number */
- _lptmode=1; /* 1 to use bdos(5..), 0 for bios I/O */
-
- /*
- * void
- * prdouble(ctrl)
- *
- * ARGUMENT
- * (int) ctrl - ON/OFF - enable/disable
- *
- * DESCRIPTION
- * This function sets or clears double width printing.
- */
- void GF_CONV prdouble(ctrl)
- int ctrl;
- {
- if (ctrl==ON||ctrl==SET) {
- prx((char)0x0E);
- prx((char)ESC);
- prx((char)'W');
- prx((char)1);
- } else {
- prx((char)0x14);
- prx((char)ESC);
- prx((char)'W');
- prx((char)0);
- }
- }
-
- /*
- * void
- * prcomp(ctrl)
- *
- * ARGUMENT
- * (int) ctrl - ON/OFF - enable/disable
- *
- * DESCRIPTION
- * Set or clear compressed print (17cpi)
- */
- void GF_CONV prcomp(ctrl)
- int ctrl;
- {
- if(ctrl==ON||ctrl==SET)
- prx((char)0x0F);
- else
- prx((char)0x12);
- }
-
- /*
- * void
- * premph(ctrl)
- *
- * ARGUMENT
- * (int) ctrl - ON/OFF
- *
- * DESCRIPTION
- * Sets or clears emphasized printing
- */
- void GF_CONV premph(ctrl)
- int ctrl;
- {
- prx((char)ESC);
- if(ctrl==ON||ctrl==SET)
- prx((char)'E');
- else
- prx((char)'F');
- }
-
- /*
- * void
- * prbold(ctrl)
- *
- * ARGUMENT
- * (int) ctrl - set or clear bold printing
- *
- * DESCRIPTION
- * This function sets or clears bold printing
- */
- void GF_CONV prbold(ctrl)
- int ctrl;
- {
- prx((char)ESC);
- if(ctrl==ON||ctrl==SET)
- prx((char)'G');
- else
- prx((char)'H');
- }
-
- /*
- * void
- * prnorm(ctrl)
- *
- * ARGUMENT
- * (int) ctrl - set/clear (must be 1)
- *
- * DESCRIPTION
- * Set normal font mode.
- */
- void GF_CONV prnorm(ctrl)
- int ctrl;
- {
- if (ctrl==ON) {
- prdouble(OFF);
- prcomp(OFF);
- premph(OFF);
- prbold(OFF);
- prunidir(OFF);
- prsub(OFF);
- prsuper(OFF);
- prunder(OFF);
- prfixlf(6,12);
- prhtabset(OFF,(int *)0);
- prvtabset(OFF,(int *)0);
- }
- }
-
- /*
- * int
- * prfixlf(inc,n)
- *
- * ARGUMENT
- * (int) inc = 6 (1/6 inch)
- * 8 (1/8 inch)
- * 772 (7/72 inch)
- * 72 (n/72 inch)
- * 216 (n/216 inch)
- * (int) n Number of 1/216ths of inch or 1/72ths
- *
- * DESCRIPTION
- * Set fixed linefeed increment
- *
- * RETURNS
- * OK if successful, ERROR if argument is out of range
- */
- int GF_CONV prfixlf(inc,n)
- int n, inc;
- {
- prx((char)ESC);
- switch (inc) {
- default:
- case NORM:
- case 6:
- prx((char)'2');
- prx((char)ESC);
- prx((char)'2');
- break;
- case 8:
- prx((char)'0');
- break;
- case 772:
- prx((char)'1');
- break;
- case 216:
- if(n<1||n>255)
- return ERROR;
- else {
- prx((char)'3');
- prx((char)n);
- }
- break;
- case 72:
- if(n<1||n>85)
- return ERROR;
- else {
- prx((char)'A');
- prx((char)n);
- prx((char)ESC);
- prx((char)'2');
- break;
- }
- }
- return (OK);
- }
-
- /*
- * int
- * prvarlf(inc,n)
- *
- * ARGUMENT
- * (int) n - see prfixlf()
- * (int) n - "
- *
- * DESCRIPTION
- * Set variable linefeed increment.
- */
- int GF_CONV prvarlf(inc,n)
- int inc,n;
- {
- return (prfixlf(inc,n));
- }
-
- /*
- * void
- * prskip(ctrl,n)
- *
- * ARGUMENT
- * (int) ctrl - ENABLE/CLEAR
- * (int) n - Number of lines to skip
- *
- * DESCRIPTION
- * Set skip perforation. Skip n lines at bottom of page: prskip(SET,12)
- * will print to 54th line on 66 line page, then skip the remainder
- */
- void GF_CONV prskip(ctrl,n)
- int ctrl,n;
- {
- prx((char)ESC);
- if(ctrl==ON||ctrl==SET) {
- prx((char)'N');
- prx((char)n);
- } else
- prx((char)'O');
- }
-
- /*
- * void
- * prbufclr(void)
- *
- * ARGUMENT
- * (none)
- *
- * DESCRIPTION
- * Clear printer buffer
- */
- void GF_CONV prbufclr()
- {
- prx((char)0x18);
- }
-
- /*
- * void
- * prselect(ctrl)
- *
- * ARGUMENT
- * (int) ctrl - select/deselect
- *
- * DESCRIPTION
- * This function sends select/deselect code to printer.
- */
- void GF_CONV prselect(ctrl)
- int ctrl;
- {
- if(ctrl==ON||ctrl==SET)
- prx((char)0x11);
- else
- prx((char)0x13);
- }
-
- /*
- * void
- * prbell(void)
- *
- * ARGUMENT
- * (none)
- *
- * DESCRIPTION
- * Sound BELL on printer.
- */
- void GF_CONV prbell()
- {
- prx((char)0x07);
- }
-
- /*
- * int
- * prsetflen(ctrl,n)
- *
- * ARGUMENT
- * (int) ctrl LINES/INCHES
- * (int) n LINES/INCHES per page
- * DESCRIPTION
- * Set Form length in printer.
- *
- * RETURNS
- * ERROR if argument error, else OK
- */
- int GF_CONV prsetflen(ctrl,n)
- int ctrl;
- int n;
- {
- if(ctrl==LINES) {
- if(n>=1&&n<=127) {
- prx((char)ESC);
- prx((char)'C');
- prx((char)n);
- return OK;
- } else
- return ERROR;
- } else if(ctrl==INCHES) {
- if(n>=1 && n<=22) {
- prx((char)ESC);
- prx((char)'C');
- prx((char)0);
- prx((char)n);
- return OK;
- } else
- return ERROR;
- } else
- return ERROR;
- }
-
- /*
- * void
- * prhtabset(ctrl,tabarray)
- *
- * ARGUMENT
- * (int) ctrl - OFF/CLEAR, ON/SET
- * (int *) tabarray - Points to array of tabsettings, must be
- * NULL terminated.
- *
- * DESCRIPTION
- * Set up to 112 horizontal Tabs on the printer, or clear all tabs.
- */
- void GF_CONV prhtabset(ctrl,tabarray)
- int ctrl;
- int *tabarray;
- {
- if(ctrl==OFF||ctrl==CLEAR)
- prsetht(tabs);
- else if(ctrl==ON||ctrl==SET)
- prsetht(tabarray);
- }
-
- /*
- * void
- * prsetht(ptab)
- *
- * ARGUMENT
- * (int *) ptab - Points to tabstop to set
- *
- * DESCRIPTION
- * This function sets a horizontal tab stop as specified by *ptab;
- * worker for prhtabset().
- */
- void GF_CONV prsetht(ptab)
- int *ptab;
- {
- int tabstop;
- prx((char)ESC);
- prx((char)'D');
- while (1) {
- tabstop = *ptab++;
- if(tabstop==0)
- break;
- else
- prx((char)tabstop);
- }
- prx((char)0);
- }
-
- /*
- * void
- * prvtabset(ctrl,tabarray)
- *
- * ARGUMENT
- * (int) ctrl - set/clear tabs
- * (int *) tabarray - points to a NULL terminated array of
- * tab stops.
- *
- * DESCRIPTION
- * Set up to 64 vertical tabs or reset tabs.
- */
- void GF_CONV prvtabset(ctrl,tabarray)
- int ctrl;
- int *tabarray;
- {
- if(ctrl==OFF||ctrl==CLEAR)
- prsetvt(tabs);
- else if(ctrl==ON||ctrl==SET)
- prsetvt(tabarray);
- }
-
- /*
- * void
- * prsetvt(tabarray)
- *
- * ARGUMENT
- * (int *) tabarray
- *
- * DESCRIPTION
- * worker for prvtabset()
- */
- void GF_CONV prsetvt(tabarray)
- int *tabarray;
- {
- int tabstop;
-
- prx((char)ESC);
- prx((char)'B');
- while (1) {
- tabstop = *tabarray++;
- if (tabstop==0)
- break;
- else
- prx((char)tabstop);
- }
- prx((char)0);
- }
-
- /*
- * void
- * prputc(c)
- *
- * ARGUMENT
- * (char) c - character to print
- *
- * DESCRIPTION
- * Print a single character
- */
- void GF_CONV prputc(c)
- char c;
- {
- prx((char)c);
- }
-
- /*
- * void
- * prs(string)
- *
- * ARGUMENT
- * (char *) string - Print a NULL terminated string.
- *
- * DESCRIPTION
- * This function prints a null terminated string, expanding tabs to
- * eight spaces.
- */
- void GF_CONV prs(str)
- char *str;
- {
- char c;
- int i;
-
- i=0;
- while (1) {
- c = *str;
- if(!c)
- break;
- if(c=='\t') {
- do
- prputc(BLANK);
- while(++i % 8);
- ++str;
- } else {
- prputc(c);
- ++i;
- ++str;
- }
- }
- }
-
- /*
- * void
- * prputl(string)
- *
- * ARGUMENT
- * (char *) string - points to null terminated string to print
- *
- * DESCRIPTION
- * This function prints a null terminated string then prints a CR/LF
- */
- void GF_CONV prputl(str)
- char *str;
- {
- prs(str);
- prcrlf();
- }
-
- /*
- * void
- * prputcr(void)
- *
- * ARGUMENT
- * (none)
- *
- * DESCRIPTION
- * Print carriage return character on printer.
- */
- void GF_CONV prputcr()
- {
- prx((char)CR);
- }
-
- /*
- * void
- * prputlf(void)
- *
- * ARGUMENT
- * (none)
- *
- * DESCRIPTION
- * Print line feed character on printer.
- */
- void GF_CONV prputlf()
- {
- prx((char)LF);
- }
-
- /*
- * void
- * prcrlf(void)
- *
- * ARGUMENT
- * (none)
- *
- * DESCRIPTION
- * Print carriage return/line feed sequence on printer
- */
- void GF_CONV prcrlf()
- {
- prx((char)CR);
- prx((char)LF);
- }
-
- /*
- * void
- * prblanks(n)
- *
- * ARGUMENT
- * (int) n - Number of blanks to print
- *
- * DESCRIPTION
- * Print (n) blanks on printer.
- */
- void GF_CONV prblanks(n)
- int n;
- {
- int i;
-
- for(i=1;i<=n;i++)
- prx((char) ' ' );
- }
-
- /*
- * void
- * prhtab(void)
- *
- * ARGUMENT
- * (none)
- *
- * DESCRIPTION
- * Print a Horizontal Tab character on printer.
- */
- void GF_CONV prhtab()
- {
- prx((char)0x09);
- }
-
- /*
- * void
- * prvtab(void)
- *
- * ARGUMENT
- * (none)
- *
- * DESCRIPTION
- * Print a Vertical Tab character.
- */
- void GF_CONV prvtab()
- {
- prx((char)0x0B);
- }
-
- /*
- * void
- * formfeed(void)
- *
- * ARGUMENT
- * (none)
- *
- * DESCRIPTION
- * Send a formfeed to the line printer.
- */
- void GF_CONV formfeed()
- {
- prx((char)FF);
- }
-
- /*
- * void
- * prunidir(control)
- *
- * ARGUMENT
- * (int) control - Enable/Disable Unidirectional mode
- *
- * DESCRIPTION
- * This function sends the codes to enable/disable unidirectional mode
- * on the Graphics printer.
- */
- void GF_CONV prunidir(ctrl)
- int ctrl;
- {
- prx((char)ESC);
- prx((char)'U');
- if(ctrl==ON||ctrl==SET)
- prx((char)1);
- else
- prx((char)0);
- }
-
- /*
- * void
- * prunder(control)
- *
- * ARGUMENT
- * (int) prunder - Set/Clear option
- *
- * DESCRIPTION
- * Set or Clear Underline mode (Graphics Printer Only)
- */
- void GF_CONV prunder(ctrl)
- int ctrl;
- {
- prx((char)ESC);
- prx((char)'-');
- if(ctrl==ON||ctrl==SET)
- prx((char)1);
- else
- prx((char)0);
- }
-
- /*
- * void
- * prsub(ctrl)
- *
- * ARGUMENT
- * (int) ctrl - option SET/CLEAR
- *
- * DESCRIPTION
- * This function sends codes to the printer to set or clear subscript
- * mode. (print tiny characters below the line)
- */
- void GF_CONV prsub(ctrl)
- int ctrl;
- {
- prx((char)ESC);
- if(ctrl==ON) {
- prx((char)'S');
- prx((char)1);
- } else
- prx((char)'T'); /* clear subscript */
- }
-
- /*
- * void
- * prsuper(ctrl)
- *
- * ARGUMENT
- * (int) ctrl - Enable/disable
- *
- * DESCRIPTION
- * This function sends codes to the printer that will enable superscript
- * mode. (tiny characters above line).
- */
- void GF_CONV prsuper(ctrl)
- int ctrl;
- {
- prx((char)ESC);
- if(ctrl==ON) {
- prx((char)'S');
- prx((char)0);
- } else
- prx((char)'T'); /* clear superscript */
- }
-
- /*
- * void
- * prhome(void)
- *
- * ARGUMENT
- * (none)
- *
- * DESCRIPTION
- * Home the print head (graphics printer only)
- */
- void GF_CONV prhome()
- {
- prx((char)ESC);
- prx((char)'<');
- }
-
- /*
- * void
- * prstop(ctrl)
- *
- * ARGUMENT
- * (int) ctrl - option stop=ON, ignore=(OFF)
- *
- * DESCRIPTION
- * Set printer to stop on end of paper switch or ignore it.
- */
- void GF_CONV prstop(ctrl)
- int ctrl;
- {
- prx((char)ESC);
- if(ctrl==ON)
- prx((char)'9');
- else
- prx((char)'8');
- }
-
- /*
- * void
- * prfont(font)
- *
- * ARGUMENT
- * (int) font - font select, 1/2
- *
- * DESCRIPTION
- * Character Set (font) select (graphics printer only).
- */
- void GF_CONV prfont(font)
- int font;
- {
- if(font<1||font>2)
- return; /* only 2 fonts recognized */
- prx((char)ESC);
- if(font==1)
- prx((char)'7');
- else if(font==2)
- prx((char)'6');
- }
-
- /*
- * int
- * prbits(density,length,bitarray)
- *
- * ARGUMENT
- * (int) density - density 480,960 etc.
- * (int) length - length in bytes of bitarray
- * (char *) bitarray - graphics bit image data
- *
- *
- * DESCRIPTION
- * Graphics bit image print from array.
- *
- * RETURNS
- * ERROR if length is too long for density.
- */
- int GF_CONV prbits(density,length,bitarray)
- int density,length;
- char *bitarray;
- {
- char *p;
- int i,n1,n2;
-
- n1=length % 256;
- n2=length/256;
- p=bitarray;
- prx((char)ESC);
- switch (density) {
- default:
- case 480:
- if(length<1||length>480)
- return ERROR;
- else
- prx((char)'K');
- break;
- case 960:
- if(length<1||length>960)
- return ERROR;
- else
- prx((char)'L');
- break;
- case FAST:
- if(length<1||length>960)
- return ERROR;
- else
- prx((char)'Y');
- break;
- case 1920:
- if(length<1||length>1920)
- return ERROR;
- else
- prx((char)'Z');
- break;
- }
- prx((char)n1);
- prx((char)n2); /* send 2 length bytes */
- for(i=1;i<=length;i++)
- prx(*p++); /* send bit array content */
- return(OK);
- }
-
- /*
- * int
- * prx(data)
- *
- * ARGUMENT
- * (char) data - data to print
- *
- * DESCRIPTION
- * Primitive to send a byte of data to the currently selected printer.
- * Note: we switch on _LPTMODE: if 1 use int 17h, if 0 use bdos(5,,,)
- *
- * RETURNS
- * Printer status if using int 17h, otherwise 0.
- */
- int GF_CONV prx(data)
- char data;
- {
- struct GFREGS in,out;
-
- if (_lptmode==1) {
- in.ax = (int)(data&0x00FF);
- in.dx = curr_printer;
- sysint(0x17, &in, &out );
- return((int)((out.ax&0xFF00)>>8));
- } else {
- bdos(5,data,0);
- return 0;
- }
- }
-
- /*
- * void
- * pruse(n)
- *
- * ARGUMENT
- * (int) n - Printer to use, 0=LPT1, 1=LPT2 etc.
- *
- * DESCRIPTION
- * printer selection primitive.
- */
- void GF_CONV pruse(n)
- int n;
- {
- curr_printer=n;
- }
-
- /*
- * void
- * prmode(mode)
- *
- * ARGUMENT
- * (int) mode - 0 = use MS-DOS, 1 = use ROM-BIOS
- *
- * DESCRIPTION
- * Printer I/O mode selection, this function determines which mode
- * will be used to output data to the printer.
- */
- void GF_CONV prmode(mode)
- int mode;
- {
- if(mode<0||mode>1)
- return;
- else
- _lptmode=mode;
- }
-
- /*
- * int
- * prreset(n)
- *
- * ARGUMENT
- * (int) n - printer number to reset
- *
- * DESCRIPTION
- * Sends reset sequence to specified printer.
- *
- * SIDE EFFECTS
- * printer is reset to power up condition
- */
- int GF_CONV prreset(n)
- int n;
- {
- struct GFREGS in, out;
-
- in.ax = 0x0100;
- in.dx = n&0x0003;
- sysint(0x17,&in,&out);
- return((out.ax&0x00FF)>>8); /* return status */
- }
-
- /*
- * void
- * prscreen(void)
- *
- * ARGUMENT
- * (none)
- *
- * DESCRIPTION
- * does software interrupt #5 print screen
- */
- void GF_CONV prscreen()
- {
- struct GFREGS in,out;
- sysint(5,&in,&out);
- }
-
- /*
- * int
- * prstatus(n)
- *
- * ARGUMENT
- * (int) n - which printer.
- *
- * DESCRIPTION
- * This function calls the ROM-BIOS returning the printer status.
- *
- * RETURNS
- *
- * Status bits:
- *
- * 0 - TimeOut 1,2 - Unused 3 - I/O Error
- * 4 - Selected 5 - Out of Paper 6 - Acknowledge
- * 7 - Not Busy
- */
- int GF_CONV prstatus(n)
- int n;
- {
- struct GFREGS in,out;
-
- in.ax=0x0200;
- in.dx=n;
- sysint(0x17,&in,&out);
- return((int)((out.ax&0xFF00)>>8));
- }
-