home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / THEPRN14.ZIP / DEMO_PRN.C < prev    next >
C/C++ Source or Header  |  1994-01-13  |  5KB  |  213 lines

  1. /************************************************************************
  2.  
  3.    Demo_Prn.C     The Printer (tm) demo.  Copyright 1994, Rob W. Smetana
  4.  
  5.    << BEFORE running this, turn screen-swapping ON if appropriate. >>
  6.  
  7.    Purpose:       * Demonstrate reading printer code records.
  8.  
  9.                   * Show how one might display printer codes.
  10.  
  11.                     Something like this might be used inside a
  12.                     program to show users which codes are
  13.                     available (ie., not blank) and perhaps what
  14.                     they should do to invoke each option.
  15.  
  16.       NOTE:       Some printer codes may contain control codes which
  17.                   will screw up the display.  Try a different printer.
  18.                   And in your own programs you might want to use an ASM
  19.                   "quickprint" routine to overcome this problem.
  20.  
  21.    Requires:
  22.  
  23.     1. Printer.Cfg -- a 2k printer code file saved by Printer.Exe
  24.  
  25.     2. The_Prn.C   -- an include file with data structures (although
  26.                       we won't use those structures here)
  27.  
  28. ************************************************************************/
  29.  
  30. #include "the_prn.c"        /* for database structures */
  31.  
  32. #include <string.h>         /* for function prototypes */
  33. #include <conio.h>          /* ditto */
  34. #include <stdio.h>          /* ditto */
  35.  
  36. #include <dos.h>            /* for CLS (Clear Screen) and LOCATE */
  37. #define  VIDEO  0x10        /* ditto */
  38.  
  39. /*
  40.    For what we're about to do here, it's easier reading printer codes
  41.    with some simple variables -- rather than our types.
  42.  
  43.    Printer.Cfg consists of 2 1024-byte records (Labels and Codes).
  44.    Both records start with a 44-byte header, followed by 980 bytes
  45.    of labels or printer codes.
  46. */
  47.  
  48. char Header [44];
  49. char Labels [980];
  50. char Codes  [980];
  51.  
  52.  
  53. /* prototypes for local functions */
  54. void locate (unsigned char , unsigned char);
  55. void cls (unsigned char);
  56. void PrintHeader (void);
  57.  
  58. /* locate the cursor using BIOS SetCursor function -- page 0 hardcoded */
  59.  
  60. void locate (row, col)
  61. unsigned char row, col;
  62. {
  63.    union REGS reg;
  64.    reg.h.ah = 2;
  65.    reg.h.dh = row-1;           /* we use 1,1 as top, left; BIOS uses 0,0 */
  66.    reg.h.dl = col-1;
  67.    reg.h.bh = 0;
  68.    int86(VIDEO, ®, ®);
  69. }
  70.  
  71. /* CLS using BIOS Scroll function.  ALSO homes cursor:  Locate (1,1). */
  72.  
  73. void cls (colr)
  74.  
  75. unsigned char colr;
  76.  
  77. {
  78.     union REGS reg;
  79.  
  80.     reg.h.ah = 6;           /* service 6 -- scroll up  */
  81.     reg.h.al = 0;           /* scroll 0 lines -- clear */
  82.  
  83.     reg.h.ch = 0;           /* scroll 25 x 80 screen:  0,0 to 24,79 */
  84.     reg.h.cl = 0;
  85.     reg.h.dh = 24;
  86.     reg.h.dl = 79;
  87.     reg.h.bh = colr;
  88.     int86(VIDEO, ®, ®);
  89.  
  90.     locate (1, 1);
  91. }
  92.  
  93.  
  94. /* print Manufacturer, model, etc. */
  95.  
  96. /*************************************************************************/
  97. void PrintHeader ()
  98. /*************************************************************************/
  99.  
  100. {
  101.   unsigned char n;
  102.  
  103.   cls (27);
  104.  
  105.   for (n = 0; n < 44; ++n)            /* print our 44-byte header */
  106.   {
  107.     switch (n)
  108.       {
  109.       case 1:
  110.         printf (" Manufacturer: ");
  111.         break;
  112.       case 16:
  113.         printf ("  Model: ");
  114.         break;
  115.       case 30:
  116.         printf ("  Emulates: ");
  117.         break;
  118.       }
  119.      printf("%c",Header [n]);
  120.   }
  121. }
  122.  
  123.  
  124. /************************************************************************/
  125.  
  126. int main (void)
  127.  
  128.    {
  129.  
  130.    char Cfg_File[64];
  131.    FILE *fp;
  132.  
  133.    int c, offset;
  134.    char n, row, col;
  135.  
  136.    /* home cursor */
  137.    cls (27);
  138.  
  139.    strcpy (Cfg_File, "PRINTER.CFG");
  140.  
  141.    fp = fopen (Cfg_File, "rb");
  142.  
  143.    if (fp == NULL)
  144.       {
  145.         return(-999);     /* file not found */
  146.       }
  147.  
  148.    /* Read 2 1024-byte records:  Labels and Printer Codes. */
  149.    /* Both records begin with the same 44-byte header.     */
  150.  
  151.    fread (Header, sizeof Header, 1, fp);
  152.    fread (Labels, sizeof Labels, 1, fp);
  153.  
  154.    PrintHeader();
  155.  
  156.    fread (Header, sizeof Header, 1, fp);
  157.    fread (Codes, sizeof Codes, 1, fp);
  158.  
  159.    offset =1 ;
  160.    row = 3;
  161.    col = 4;
  162.  
  163.    for (n = 1; n < 71; ++n)
  164.    {
  165.  
  166.      locate (row,col);
  167.  
  168.      /* Print the labels */
  169.      for (c = 0; c < 14; ++c)
  170.          printf("%c",Labels[offset+c-1]);
  171.  
  172.      printf("    ");
  173.  
  174.      /* and now the codes */
  175.      for (c = 0; c < 14; ++c)
  176.          printf("%c",Codes[offset+c-1]);
  177.  
  178.      /* move to the next Label/Printer Code */
  179.      offset = offset + 14;
  180.  
  181.      /*
  182.        There are more codes than will fit on a screen.
  183.        So pause after 1st screen.
  184.      */
  185.  
  186.      if (n == 42)
  187.      {
  188.        locate(25,15);
  189.        printf ("There's more.   Press <SPACE> to continue . . .");
  190.        getche();
  191.        PrintHeader ();
  192.        row = 2;
  193.        col = 4;
  194.      }
  195.  
  196.      row++;
  197.  
  198.      if (row > 23)
  199.         {
  200.          row =3;
  201.          col = 40;
  202.         }
  203.    }
  204.  
  205.    locate (25, 15);
  206.    printf ("That's all.     Press <SPACE> to continue . . .");
  207.    getche();
  208.    cls(7);
  209.    return (0);
  210.  
  211. }
  212.  
  213.