home *** CD-ROM | disk | FTP | other *** search
- /*
- * printer.c: hterm printer control
- *
- * Author: HIRANO Satoshi
- * (C) 1989 Halca Computer Science Laboratory TM
- * University of Tokyo
- *
- * 2.2 89/05/16 Halca.Hirano V2.2 distribution
- * 2.3 89/08/03 Halca.Hirano add checkPrinterReady()
- * ---- V2.4.0 distribution ----
- * 2.4 89/11/10 Tominaga@Titech ported to J3100 (NOT TESTED!)
- * ---- V2.4.2 distribution ----
- * ---- V2.5.1 distribution ----
- * 2.5 89/12/16 Tominaga@Titech fix printer ready checking bug
- * (I missed BIOS calling interrupt nubmer)
- *
- * $Header: printer.cv 1.9 90/07/04 00:59:46 hirano Exp $
- */
-
-
- #include <stdio.h>
- #include <fcntl.h>
- #include <io.h>
- #include "config.h"
- #include "hterm.h"
- #include "option.h"
- #include "default.h"
- #include "global.h"
-
- #define STATE_ASCII 0
- #define STATE_KANJI 1
- static char kanBeg[] = "\x1bK";
- static char kanEnd[] = "\x1bH";
- static int printStat;
- static int prPath;
-
- static void outKanjiPrinter(unsigned short c);
-
- void printInit()
- /*
- * initialize printer
- */
- {
- spacing = DEFAULT_PRINTER_SPACING;
- printMode = DEFAULT_PRINT_MODE;
- printStat = STATE_ASCII;
-
- if ((prPath = open(DEFAULT_PRINTER_DEVICE, O_WRONLY|O_BINARY)) == ERR) {
- prPath = 0;
- }
- }
-
- /*
- ** void printSetup()
- *
- * enable printer if printMode is YES
- */
- void printSetup()
- {
- if (printMode && checkPrinterReady() == OK)
- printOn();
- else
- printMode = NO; /* if printer is not ready, disable print mode */
- }
-
- void printEnd()
- {
- if (prPath)
- close(prPath);
- }
-
- void printOn()
- /*
- * enable printer;
- * return:
- * OK printer is ready
- * ERR printer is not ready
- */
- {
- #ifdef PC98
- printStat = STATE_ASCII;
- write(prPath, kanEnd, 2);
- #endif /* PC98 */
- }
-
- #if defined IBMPC || defined J3100
- void outPrinter(c)
- /* output a char to printer */
- u_short c;
- {
- char buf[2];
-
- #ifdef KANJI
- if (c & 0xff00) {
- outKanjiPrinter(c);
- return;
- }
- #endif
- buf[0] = c & 0xff;
- write(prPath, buf, 1);
- }
-
- #ifdef KANJI
- static void outKanjiPrinter(c)
- u_short c;
- {
- u_char buf[2];
-
- c = JIStoSJIS(c>>8, c & 0xff);
- buf[0] = (c>>8);
- buf[1] = c;
- write (prPath, buf, 2);
- }
- #endif /*KANJI*/
-
- int checkPrinterReady()
- {
- rg.h.ah = 2;
- rg.x.dx = 0; /* printer 0 */
- int86(PRINTER_BIOS, &rg, &rg); /* check status */
- if ((rg.h.ah & 0x28) || !(rg.h.ah & 0x80))
- return(ERR); /* I/O error, paper end or not ready */
- return(OK);
- }
- #endif /* IBMPC || J3100 */
-
- #ifdef PC98
- void outPrinter(c)
- u_short c;
- {
- u_char buf[2];
-
- if (c & 0xff00) {
- outKanjiPrinter(c);
- return;
- }
- if (printStat == STATE_KANJI)
- write(prPath, kanEnd, 2);
- buf[0] = c;
- write(prPath, buf, 1);
- printStat = STATE_ASCII;
- }
-
- static void outKanjiPrinter(c)
- u_short c;
- {
- u_char buf[4];
-
- if (printStat == STATE_ASCII) {
- write(prPath, kanBeg, 2);
- }
- c &= 0x7f7f;
- buf[0] = c >> 8; buf[1] = c & 0xff; buf[2] = ESC; buf[3] = spacing;
- write(prPath, buf, 4);
- printStat = STATE_KANJI;
- }
-
- #ifdef PC98XA
- /* Rewrite by H.Dohi for ONLY PC98XA and MSC5.1 89/10/17 */
- int checkPrinterReady()
- {
- unsigned port;
- int result;
-
- result = inp(PRINTER_PORT);
- if ((result & 0xf4) == 0x64)
- return(OK);
- return(ERR);
- }
-
- #else
-
- int checkPrinterReady()
- {
- rg.h.ah = 0x12;
- int86(PRINTER_BIOS, &rg, &rg); /* call printer BIOS */
- if (rg.h.ah & 1)
- return(OK); /* ready */
- return(ERR);
- }
-
- #endif /* PC98XA */
- #endif /* PC98 */
-
-