"Fossies" - the Fresh Open Source Software Archive

Member "hp2xx-3.4.4/sources/to_hgc.c" (21 Jun 2003, 5385 Bytes) of package /linux/misc/old/hp2xx-3.4.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "to_hgc.c" see the Fossies "Dox" file reference documentation.

    1 #ifdef HAS_DOS_HGC
    2 /*
    3    Copyright (c) 1993 - 1994  Roland Emmerich & Heinz W. Werntges.
    4    All rights reserved. Distributed by Free Software Foundation, Inc.
    5 
    6 This file is part of HP2xx.
    7 
    8 HP2xx is distributed in the hope that it will be useful, but
    9 WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
   10 to anyone for the consequences of using it or for whether it serves any
   11 particular purpose or works at all, unless he says so in writing.  Refer
   12 to the GNU General Public License, Version 2 or later, for full details.
   13 
   14 Everyone is granted permission to copy, modify and redistribute
   15 HP2xx, but only under the conditions described in the GNU General Public
   16 License.  A copy of this license is supposed to have been
   17 given to you along with HP2xx so you can know your rights and
   18 responsibilities.  It should be in a file named COPYING.  Among other
   19 things, the copyright notice and this notice must be preserved on all
   20 copies.
   21 
   22 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   23 */
   24 
   25 /** to_hgc.c: HGC preview part of project "hp2xx" (PC only)
   26  **
   27  ** 93/06/16  V 1.00  RE   Originating
   28  ** 93/07/25  V 1.01  HWW  Minor adaptations to hp2xx standard
   29  ** 94/02/14  V 1.10a HWW  Adapted to changes in hp2xx.h
   30  **/
   31 
   32 /**
   33  ** NOTE:
   34  ** For white lines on a black background, uncomment the next
   35  ** #define statement:
   36  **/
   37 /* #define  HGC_INVERSE */
   38 
   39 #define HGC_XMAX    720
   40 #define HGC_YMAX    348
   41 
   42 
   43 #include <stdio.h>
   44 #include <stdlib.h>
   45 #include <ctype.h>
   46 #include <dos.h>
   47 #include <mem.h>
   48 #include <graphics.h>
   49 #include <conio.h>
   50 #include "bresnham.h"
   51 #include "hp2xx.h"
   52 
   53 /**
   54  ** HGC registers
   55  **/
   56 
   57 static unsigned int IndexReg = 0x03B4;
   58 static unsigned int DatenReg = 0x03B5;
   59 static unsigned int ModusReg = 0x03B8;
   60 static unsigned int KonfigReg = 0x03Bf;
   61 
   62 /**
   63  ** Pointer to HGC video buffer (4 memory banks)
   64  **/
   65 
   66 static unsigned int HGCBank[] = { 0xB000, 0xB200, 0xB400, 0xB600 };
   67 
   68 /**
   69  ** set_pixel_HGC(x, y) set point at x, y
   70  **/
   71 
   72 static void set_pixel_HGC(int x, int y)
   73 {
   74     unsigned int bank;
   75     unsigned int pkt_addr;
   76     unsigned char far *screen;
   77     unsigned char pixel[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
   78 
   79  /**
   80   ** The pixels are put directly into the screen buffer of the HGC,
   81   ** therefore it is necessary to check the address range
   82   **/
   83 
   84     if ((x >= 0) && (x < HGC_XMAX) && (y >= 0) && (y < HGC_YMAX)) {
   85         bank = y % 4;
   86         pkt_addr = x >> 3;
   87         pkt_addr += 90 * ((y - bank) >> 2);
   88 
   89         screen = MK_FP(HGCBank[bank], pkt_addr);
   90 #ifdef  HGC_INVERSE
   91         screen[0] |= pixel[x % 8];
   92 #else
   93         screen[0] &= ~pixel[x % 8];
   94 #endif
   95     }
   96 }
   97 
   98 
   99 
  100 /**
  101  ** switch to HGC text mode
  102  **/
  103 
  104 static void set_HGC_textmode(void)
  105 {
  106     unsigned char i;
  107     unsigned int j;
  108     unsigned int far *screen;
  109     unsigned char TextModus[] = {
  110         0x61, 0x50, 0x52, 0x0f, 0x19, 0x06,
  111         0x19, 0x19, 0x02, 0x0d, 0x0b, 0x0c,
  112         0x00, 0x00, 0x00, 0x01
  113     };
  114 
  115     outportb(KonfigReg, 0x00);
  116                 /** Partial access to HGC         **/
  117     outportb(ModusReg, 0x20);
  118                 /** Set text mode and turn off    **/
  119                 /**    the display            **/
  120     for (i = 0; i < 16; i++) {
  121         outportb(IndexReg, i);
  122                 /** set registers to textmode     **/
  123         outportb(DatenReg, TextModus[i]);
  124     }
  125     screen = MK_FP(HGCBank[0], 0);  /** Erase text screen memory,   **/
  126     for (j = 0; j < 0x2000; j++)        /** i.e. fill with spaces 0x20  **/
  127         screen[j] = 0x0720; /** and attribut "white" 0x07.  **/
  128 
  129     outportb(ModusReg, 0x28);   /** Turn on the display     **/
  130 }
  131 
  132 /**
  133  ** Switch to HGC graphic mode
  134  **/
  135 
  136 static void set_HGC_graphmode(void)
  137 {
  138     unsigned char i;
  139     unsigned int j, k, bkgrnd;
  140     unsigned int far *screen;
  141     unsigned char GrafikModus[] = {
  142         0x35, 0x2d, 0x2e, 0x07, 0x5b, 0x02,
  143         0x57, 0x57, 0x02, 0x03, 0x00, 0x00,
  144         0x00, 0x00, 0x00, 0x01
  145     };
  146 
  147     outportb(KonfigReg, 0x03);
  148                 /** Full access to HGC      **/
  149     outportb(ModusReg, 0x02);
  150                 /** Switch to graphics mode     **/
  151                 /**   and turn off the display  **/
  152     for (i = 0; i < 16; i++) {
  153         outportb(IndexReg, i);
  154         outportb(DatenReg, GrafikModus[i]);
  155     }
  156 
  157 
  158 #ifdef  HGC_INVERSE
  159     bkgrnd = 0x0000;
  160 #else
  161     bkgrnd = 0xFFFF;
  162 #endif
  163 
  164     for (k = 0; k < 4; k++)
  165         for (j = 0; j < 0x2000; j++) {
  166             screen = MK_FP(HGCBank[k], 0);
  167                     /** Erase graphics memory **/
  168             screen[j] = bkgrnd;
  169         }
  170     outportb(ModusReg, 0x0A);   /** Turn on display **/
  171 }
  172 
  173 
  174 /**
  175  ** Main entry point
  176  **/
  177 
  178 int PicBuf_to_HGC(const GEN_PAR * pg, const OUT_PAR * po)
  179 {
  180     int row_c, x, y, xoff, yoff, color_index;
  181     const RowBuf *row;
  182     const PicBuf *pb;
  183 
  184     if (!pg->quiet) {
  185         Eprintf("\nHGCpreview follows.\n");
  186         Eprintf("Press <return> to start and end graphics mode\n");
  187         SilentWait();
  188     }
  189 
  190     pb = po->picbuf;
  191     xoff = po->xoff * po->dpi_x / 25.4;
  192     yoff = po->yoff * po->dpi_y / 25.4;
  193 
  194     if ((!pg->quiet) &&
  195         (((pb->nb << 3) + xoff >= HGC_XMAX)
  196          || (pb->nr + yoff >= HGC_YMAX))) {
  197         Eprintf
  198             ("\n\007WARNING: Picture won't fit on a standard HGC!\n");
  199         Eprintf("Current range: (%d..%d) x (%d..%d) pels\n", xoff,
  200             (pb->nb << 3) + xoff, yoff, pb->nr + yoff);
  201         Eprintf("Continue anyway (y/n)?: ");
  202         if (toupper(getchar()) == 'N')
  203             return 1;
  204     }
  205 
  206     set_HGC_graphmode();
  207 
  208     for (row_c = 0, y = pb->nr + yoff - 1; row_c < pb->nr;
  209          row_c++, y--) {
  210         row = get_RowBuf(pb, row_c);
  211         if (row == NULL)
  212             continue;
  213         for (x = 0; x < pb->nc; x++) {
  214             color_index = index_from_RowBuf(row, x, pb);
  215             if (color_index != xxBackground)
  216                 set_pixel_HGC(x + xoff, y);
  217         }
  218     }
  219     SilentWait();
  220     set_HGC_textmode();
  221     return 0;
  222 }
  223 #endif