home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / fractint / fras1611.zip / TARGA.C < prev    next >
C/C++ Source or Header  |  1991-07-07  |  20KB  |  761 lines

  1. /** targa.c **/
  2.  
  3. #ifdef __TURBOC__
  4. #    pragma    warn -par
  5. #endif
  6.  
  7. #define TARGA_DATA
  8.  
  9. #include    <stdio.h>
  10. #include    <stdlib.h>
  11. #include    "targa.h"
  12. #include    "fractint.h"
  13.  
  14.  
  15. /*************    ****************/
  16.  
  17. extern void    helptitle();
  18. extern char far *mapdacbox;
  19.  
  20. /*************    ****************/
  21.  
  22. void    WriteTGA( int x, int y, int index );
  23. int    ReadTGA ( int x, int y );
  24. void    EndTGA    ( void );
  25. void    StartTGA( void );
  26. void    ReopenTGA( void );
  27.  
  28. /*************    ****************/
  29.  
  30. static unsigned _fastcall near Row16Calculate(unsigned,unsigned);
  31. static void    _fastcall near PutPix16(int,int,int);
  32. static unsigned _fastcall near GetPix16(int,int);
  33. static unsigned _fastcall near Row32Calculate(unsigned,unsigned);
  34. static void    _fastcall near PutPix32(int,int,int);
  35. static unsigned _fastcall near GetPix32(int,int);
  36. static void    _fastcall near DoFirstPixel(int,int,int);
  37. static void _fastcall fatalerror(char far *);
  38. static int  GetLine(int);
  39. static void _fastcall near SetDispReg(int,int);
  40. static int  VWait(void);
  41. static void _fastcall SetVBorder(int,int);
  42. static void _fastcall SetBorderColor(long);
  43. static void _fastcall SetVertShift(int);
  44. static void _fastcall SetInterlace(int);
  45. static void _fastcall SetBlndReg(int);
  46. static void _fastcall SetRGBorCV(int);
  47. static void _fastcall SetVCRorCamera(int);
  48. static void _fastcall SetMask(int);
  49. static void _fastcall SetBlndReg(int);
  50. static void _fastcall SetContrast(int);
  51. static void _fastcall SetHue(int);
  52. static void _fastcall SetSaturation(int);
  53. static void _fastcall SetHBorder(int,int);
  54. static void SetFixedRegisters(void);
  55. static void _fastcall VCenterDisplay(int);
  56. static void _fastcall SetOverscan(int);
  57. static void _fastcall near TSetMode(int);
  58. static int  GraphInit(void);
  59. static void GraphEnd(void);
  60.  
  61. /*************    ****************/
  62.  
  63. int         xorTARGA;
  64. unsigned far *tga16 = NULL;  /* [256] */
  65. long     far *tga32;         /* [256] */
  66. static int   last = 0;
  67.  
  68. /*************    ****************/
  69.  
  70. extern int    sxdots,sydots;        /* # of dots on the physical screen */
  71. static int    initialized;
  72.  
  73. /*************    ****************/
  74.  
  75. static void    (near _fastcall *DoPixel) ( int x, int y, int index );
  76. static void    (near _fastcall *PutPixel)( int x, int y, int index );
  77. static unsigned (near _fastcall *GetPixel)( int x, int y );
  78.  
  79. /**************************************************************************/
  80.  
  81. static unsigned _fastcall near Row16Calculate( unsigned line, unsigned x1 )
  82. {
  83.     outp( DESTREG, (line >> 5) );
  84.     return( ((line & 31) << 10) | (x1 << 1) ); /* calc the pixel offset */
  85. }
  86.  
  87. /**************************************************************************/
  88.  
  89. static void _fastcall near PutPix16( int x, int y, int index )
  90. {
  91. unsigned far * ip;
  92.  
  93.     /**************/
  94.     ip = MK_FP( MEMSEG, Row16Calculate( y, x ) );
  95.     if( ! xorTARGA )
  96.         *ip = tga16[index];
  97.     else
  98.         *ip = *ip ^ 0x7fff;
  99. }
  100.  
  101. /**************************************************************************/
  102.  
  103. static unsigned _fastcall near GetPix16( int x, int y )
  104. {
  105. register unsigned pixel, index;
  106. unsigned far * ip;
  107.     /**************/
  108.     ip = MK_FP( MEMSEG, Row16Calculate( y, x ) );
  109.     pixel = *ip & 0x7FFF;
  110.     if( pixel == tga16[last] ) return( last );
  111.     for( index = 0; index < 256; index++ )
  112.         if( pixel == tga16[index] ) {
  113.             last = index;
  114.             return( index );
  115.         }
  116.     return( 0 );
  117. }
  118.  
  119. /**************************************************************************/
  120.  
  121. static unsigned _fastcall near Row32Calculate( unsigned line, unsigned x1 )
  122. {
  123.     outp( DESTREG, (line >> 4) );
  124.     return ( ((line & 15) << 11) | (x1 << 2) ); /* calc the pixel offset */
  125. }
  126.  
  127. /**************************************************************************/
  128.  
  129. static void _fastcall near PutPix32( int x, int y, int index )
  130. {
  131. long far * lp;
  132.     lp = MK_FP( MEMSEG, Row32Calculate( y, x ) );
  133.     if( ! xorTARGA )
  134.         *lp = tga32[index];
  135.     else
  136.         *lp = *lp ^ 0x00FFFFFF;
  137. }
  138.  
  139. /**************************************************************************/
  140.  
  141. static unsigned _fastcall near GetPix32( int x, int y )
  142. {
  143. register int index;
  144. long    pixel;
  145. long    far * lp;
  146.  
  147.     lp = MK_FP( MEMSEG, Row32Calculate( y, x ) );
  148.     pixel = *lp & 0x00FFFFFF;
  149.     if( pixel == tga32[last] ) return( last );
  150.     for( index = 0; index < 256; index++ )
  151.         if( pixel == tga32[index] ) {
  152.             last = index;
  153.             return( index );
  154.         }
  155.     return( 0 );
  156. }
  157.  
  158. /**************************************************************************/
  159.  
  160. static void _fastcall near DoFirstPixel( int x, int y, int index )
  161. {
  162. int cnt;
  163.     TSetMode( targa.mode | 1 );
  164.     for( cnt = 0; cnt < targa.MaxBanks; cnt += 2 ) { /* erase */
  165.         outp( DESTREG, cnt );
  166.         outp( SRCREG,  cnt + 1 );
  167.         erasesegment(targa.memloc,0);  /** general.asm **/
  168.     }
  169.     TSetMode( targa.mode & 0xFFFE );
  170.     PutPixel = DoPixel;
  171.     (*PutPixel)( x, y, index );
  172. }
  173.  
  174. /***************************************************************************/
  175.  
  176. void WriteTGA( int x, int y, int index )
  177. {
  178.     OUTPORTB(MODEREG, targa.mode |= 1 );    /* TSetMode inline for speed */
  179.     (*PutPixel)( x, sydots-y, index&0xFF ); /* fix origin to match EGA/VGA */
  180.     OUTPORTB(MODEREG, targa.mode &= 0xFFFE );
  181. }
  182.  
  183. /***************************************************************************/
  184.  
  185. int ReadTGA( int x, int y )
  186. {
  187. int val;
  188.     OUTPORTB(MODEREG, targa.mode |= 1 );    /* TSetMode inline for speed */
  189.     val = (*GetPixel)( x, sydots-y );
  190.     OUTPORTB(MODEREG, targa.mode &= 0xFFFE );
  191.     return( val );
  192. }
  193.  
  194. /***************************************************************************/
  195.  
  196. void EndTGA( void )
  197. {
  198.     if( initialized ) {
  199.         GraphEnd();
  200.         initialized = 0;
  201.     }
  202. }
  203.  
  204. /***************************************************************************/
  205.  
  206. void StartTGA()
  207. {
  208. int    i;
  209. static char far couldntfind[]={"Could not find Targa card"};
  210. static char far noenvvar[]={"TARGA enviroment variable missing"};
  211. static char far insuffmem[]={"Insufficient memory for Targa"};
  212.  
  213.     /****************/
  214.     if( initialized ) return;
  215.     initialized = 1;
  216.  
  217.     /****************/
  218.     /* note that video.asm has already set the regualar video adapter */
  219.     /* to text mode (ax in Targa table entries is 3);          */
  220.     /* that's necessary because TARGA can live at 0xA000, we DO NOT   */
  221.     /* want to have an EGA/VGA in graphics mode!!              */
  222.     ReopenTGA(); /* clear text screen and display message */
  223.  
  224.     /****************/
  225.     /*** look for and activate card ***/
  226.     if ((i = GraphInit()))
  227.         fatalerror((i == -1) ? couldntfind : noenvvar);
  228.  
  229.     VCenterDisplay( sydots + 1 );
  230.  
  231.     if (tga16 == NULL)
  232.         if ( (tga16 = (unsigned far *)farmemalloc(512L)) == NULL
  233.           || (tga32 = (long     far *)farmemalloc(1024L)) == NULL)
  234.         fatalerror(insuffmem);
  235.  
  236.     SetTgaColors();
  237.  
  238.     if( targa.boardType == 16 ) {
  239.         GetPixel = GetPix16;
  240.         DoPixel = PutPix16;
  241.     }
  242.     else {
  243.         GetPixel = GetPix32;
  244.         DoPixel = PutPix32;
  245.     }
  246.     PutPixel = DoFirstPixel;    /* on first pixel --> erase */
  247.  
  248.     if( sydots == 482 ) SetOverscan( 1 );
  249.  
  250.     TSetMode( targa.mode & 0xFFFE );
  251.  
  252.     /****************/
  253.     if (mapdacbox == NULL && SetColorPaletteName("default") != 0)
  254.         exit( 1 ); /* stopmsg has already been issued */
  255.  
  256. }
  257.  
  258. void ReopenTGA()
  259. {
  260. static char far runningontarga[]={"Running On TrueVision TARGA Card"};
  261.     helptitle();
  262.     putstring(2,20,7,runningontarga);
  263.     movecursor(6,0); /* in case of brutal exit */
  264. }
  265.  
  266. static void _fastcall fatalerror(char far *msg)
  267. {
  268. static char far abortmsg[]={"...aborting!"};
  269.     putstring(4,20,15,msg);
  270.     putstring(5,20,15,abortmsg);
  271.     movecursor(8,0);
  272.     exit(1);
  273. }
  274.  
  275.  
  276.  
  277. /***  the rest of this module used to be separate, in tgasubs.c,  ***/
  278. /***  has now been merged into a single source              ***/
  279.  
  280. /*******************************************************************/
  281.  
  282. static void _fastcall VCenterDisplay( int nLines )
  283. {
  284. int    lines;
  285. int top, bottom;
  286. long color;
  287.  
  288.     lines  = nLines >> 1;        /* half value of last line 0..x */
  289.     top    = 140 - (lines >> 1);
  290.     bottom = top + lines;
  291.     SetVBorder( top, bottom );
  292.     SetVertShift( 255 - lines );    /* skip lines we're not using */
  293.  
  294.     if( targa.boardType == 16 )
  295.         color = (12 << 10) | (12 << 5) | 12;
  296.     else
  297.         color = (80 << 16) | (80 << 8) | 80;
  298.     SetBorderColor( color );
  299. }
  300.  
  301.  
  302. /*****************************************************************/
  303.  
  304. static void _fastcall near SetDispReg(int reg, int value)
  305. {
  306.     targa.DisplayRegister[reg] = value;
  307.  
  308.     TSetMode(targa.mode&MSK_REGWRITE);  /* select Index Register write */
  309.     OUTPORTB(DRREG, reg);    /* select sync register */
  310.     /*
  311.      *        Set Mask register to write value to
  312.      *        display register and to set Bit 9 in the DR
  313.      */
  314.     TSetMode( ((targa.mode|(~MSK_REGWRITE))     /* turn on write bit */
  315.                    & MSK_BIT9       )     /* turn off Bit 9 */
  316.                | ((value&0x0100)>>1)); /* set bit 9 for value */
  317.     OUTPORTB(DRREG, value); /* select sync register */
  318.  }
  319.  
  320. /*****************************************************************/
  321.  
  322. #define   WAITCOUNT  60000
  323.  
  324. static int VWait()
  325. {
  326. int    rasterreg;
  327. unsigned GiveUp;
  328.  
  329.     rasterreg = RASTERREG;
  330.  
  331.     /*
  332.      *    If beyond bottom of frame wait for next field
  333.      */
  334.     GiveUp= WAITCOUNT;
  335.     while ( (--GiveUp) && (GetLine(rasterreg) == 0) ) { }
  336.     if (GiveUp) {
  337.        /*
  338.         *       Wait for the bottom of the border
  339.         */
  340.        GiveUp= WAITCOUNT;
  341.        while ( (--GiveUp) && (GetLine(rasterreg) > 0) ) { }
  342.        }
  343.  
  344.     return ( ( GiveUp ) ? 0 : -1);
  345. }
  346.  
  347.  
  348. /*****************************************************************/
  349.  
  350. static void _fastcall SetVBorder(int top, int bottom)
  351. {
  352.     /* top border */
  353.     if ( top < MIN_TOP ) top=MIN_TOP;
  354.     SetDispReg(TOPBORDER,top);
  355.     /* bottom border */
  356.     if ( bottom > MAX_BOTTOM ) bottom=MAX_BOTTOM;
  357.     SetDispReg(BOTTOMBORDER,bottom);
  358.  
  359.     SetDispReg(DR10,top);
  360.     SetDispReg(DR11,bottom);
  361. }
  362.  
  363.  
  364. /*****************************************************************/
  365.  
  366. static void _fastcall SetRGBorCV(int type)
  367. {
  368.     /*  set the contrast level */
  369.     targa.RGBorCV = type;
  370.     targa.VCRCon = ( targa.VCRCon  & MSK_RGBORCV ) |
  371.                     (targa.RGBorCV<<SHF_RGBORCV) ;
  372.     OUTPORTB(VCRCON, targa.VCRCon );
  373. }
  374.  
  375. /*****************************************************************/
  376.  
  377. static void _fastcall SetVCRorCamera(int type)
  378. {
  379.     targa.VCRorCamera = type&1;
  380.     targa.VCRCon = ( targa.VCRCon  & MSK_VCRORCAMERA ) |
  381.                     (targa.VCRorCamera<<SHF_VCRORCAMERA) ;
  382.     OUTPORTB(VCRCON, targa.VCRCon );
  383. }
  384.  
  385.  
  386. /*****************************************************************/
  387.  
  388. static void _fastcall SetBorderColor(long color)
  389. {
  390.     targa.BorderColor = color;
  391.     OUTPORTB(BORDER, (int)(0x0000ffffL&(color)));
  392.     OUTPORTB((BORDER+2), (int)((color)>>16));
  393. }
  394.  
  395. /*****************************************************************/
  396.  
  397. static void _fastcall SetMask(int mask)
  398. {
  399.     /* mask to valid values and output to mode register */
  400.     targa.Mask = mask;
  401.     OUTPORTB(MASKREG, mask);
  402. }
  403.  
  404.  
  405. /*****************************************************************/
  406.  
  407. static void _fastcall SetVertShift(int preshift)
  408. {
  409.     /*  set the Vertical Preshift count  level */
  410.     targa.VertShift = preshift;
  411.     OUTPORTB(VERTPAN, preshift);
  412. }
  413.  
  414.  
  415. /*****************************************************************/
  416.  
  417. static void _fastcall SetOverscan(int mode)
  418. {
  419. long tempColor;
  420.  
  421.     targa.ovrscnOn = mode;
  422.     if ( mode == 0 ) {
  423.             INPORTB(UNDERREG);  /*    select underscan mode */
  424.             SetHBorder(    (DEF_LEFT+targa.xOffset),
  425.                         (DEF_RIGHT+targa.xOffset));
  426.             SetDispReg(4,352);
  427.             SetDispReg(5,1);
  428.             SetBorderColor(targa.BorderColor);
  429.     }
  430.     else    {
  431.             INPORTB(OVERREG);   /*    select overrscan mode */
  432.             SetDispReg(0,64);   /*    Set four of the display registers */
  433.             SetDispReg(1,363);  /*    to values required for Overscan */
  434.             SetDispReg(4,363);
  435.             SetDispReg(5,17);
  436.             tempColor = targa.BorderColor;
  437.             SetBorderColor(0L);
  438.             targa.BorderColor = tempColor;
  439.     }
  440. }
  441.  
  442.  
  443. /*****************************************************************/
  444.  
  445. static void _fastcall SetInterlace(int type)
  446. {
  447.     targa.InterlaceMode= type & MSK_INTERLACE;
  448.     SetDispReg(INTREG, targa.InterlaceMode);
  449.     /*
  450.      *    SET THE INTERLACE BIT TO MATCH THE INTERLACE MODE AND
  451.      *    SCREEN RESOLUTION -  SCREEN PAGE
  452.      */
  453.     if ( ( targa.InterlaceMode >= 2 ) &&
  454.          ( targa.PageMode> 1 )    &&
  455.          ( (targa.PageMode&1) != 0 )  )
  456.         TSetMode(targa.mode|(~MSK_IBIT) );
  457.     else
  458.         TSetMode(targa.mode& MSK_IBIT);
  459. }
  460.  
  461.  
  462. /*****************************************************************/
  463.  
  464. static void _fastcall SetBlndReg(int value)
  465. {
  466.     /*  set the Vertical Preshift count  level */
  467.     if ( targa.boardType == 32 ) {
  468.         targa.VCRCon = (targa.VCRCon&0xfe) | value;
  469.         OUTPORTB(BLNDREG, value);
  470.         }
  471. }
  472.  
  473.  
  474. /*****************************************************************/
  475.  
  476. static void _fastcall near TSetMode(int mode)
  477. {
  478.     /* mask to valid values and output to mode register */
  479.     OUTPORTB(MODEREG, mode );
  480.     targa.mode = mode;
  481. }
  482.  
  483.  
  484. /*****************************************************************/
  485.  
  486. static void _fastcall SetContrast(int level)
  487. {
  488.     /*  set the contrast level */
  489.     targa.Contrast = level &((~MSK_CONTRAST)>>SHF_CONTRAST);
  490.     targa.VCRCon = ( targa.VCRCon  & MSK_CONTRAST ) |
  491.             (targa.Contrast<<SHF_CONTRAST) ;
  492.     OUTPORTB(VCRCON, targa.VCRCon );
  493. }
  494.  
  495.  
  496. /*****************************************************************/
  497.  
  498. static void _fastcall SetHue(int level)
  499. {
  500.     /*  set the hue level -  Mask to valid value */
  501.     targa.Hue = level&((~MSK_HUE)>>SHF_HUE);
  502.     /* mask to valid range */
  503.     targa.SatHue = (targa.SatHue&MSK_HUE) | (targa.Hue<<SHF_HUE);
  504.     OUTPORTB(SATHUE, targa.SatHue );
  505. }
  506.  
  507.  
  508. /*****************************************************************/
  509.  
  510. static void _fastcall SetSaturation(int level)
  511. {
  512.     /*  set the saturation level */
  513.     targa.Saturation= level&( (~MSK_SATURATION)>>SHF_SATURATION);
  514.     targa.SatHue =    (targa.SatHue&MSK_SATURATION) |
  515.              (targa.Saturation<<SHF_SATURATION);
  516.     OUTPORTB(SATHUE , targa.SatHue );
  517. }
  518.  
  519.  
  520. /*************************************************************/
  521.  
  522. /*** UNUSED
  523. static void _fastcall SetPageMode(int pageMode)
  524. {
  525.     pageMode &= 0x07;
  526.     targa.PageMode = pageMode;
  527.     VWait();
  528.     TSetMode( (targa.mode)&(MSK_RES) |((pageMode<<SHF_RES)&(~MSK_RES)) ) ;
  529.     if ( ( targa.DisplayRegister[20] >= 2 ) &&
  530.          ( pageMode> 1 )  &&
  531.          ( (pageMode&1) != 0 )      )    TSetMode(targa.mode|(~MSK_IBIT) );
  532.     else
  533.         TSetMode(targa.mode& MSK_IBIT);
  534. }
  535. ***/
  536.  
  537.  
  538. /*****************************************************************/
  539.  
  540. static void _fastcall SetHBorder(int left, int right)
  541. {
  542.     SetDispReg(LEFTBORDER, left);    /* set horizontal left border */
  543.     SetDispReg(RIGHTBORDER,right);    /* set horizontal right border */
  544. /*
  545.  *                    Set DR 8 and 9 since they
  546.  *                    default to tracking DR0 and DR 1
  547.  */
  548.     SetDispReg(DR8,left);
  549.     SetDispReg(DR9,left);
  550. }
  551.  
  552.  
  553. /*****************************************************************/
  554.  
  555. /*** UNUSED
  556. static void _fastcall SetGenlock(int OnOrOff)
  557. {
  558.     TSetMode( (targa.mode)&(MSK_GENLOCK)
  559.             |((OnOrOff<<SHF_GENLOCK)&(~MSK_GENLOCK)) );
  560. }
  561. ***/
  562.  
  563.  
  564. /*****************************************************************/
  565. /* was asm, TC fast enough on AT */
  566.  
  567. static int GetLine( int port )
  568. {
  569. int cnt;
  570. int val1, val2;
  571.  
  572.     val1 = INPORTB( port );
  573.     for( cnt = 0; cnt < 20; cnt++ ) {
  574.         val2 = INPORTB( port );
  575.         if( val1 == val2 )
  576.             break;
  577.         val1 = val2;
  578.     }
  579.     return( val1 );
  580. }
  581.  
  582.  
  583. /**********************************************************************
  584.               TINIT
  585. **********************************************************************/
  586.  
  587. static int GraphInit()
  588. {
  589. int i;
  590. int bottom, top;
  591. char *envptr;
  592. unsigned switches, got_switches;
  593.  
  594.     memset( &targa, 0, sizeof(targa) );
  595.  
  596.     targa.boardType = TYPE_16;        /* default to T16 */
  597.     targa.xOffset = 0;  targa.yOffset = 0;    /* default to no offset */
  598.     targa.LinesPerField= DEF_ROWS/2;    /*  number of lines per field */
  599.     targa.AlwaysGenLock = DEF_GENLOCK;    /* default to genlock off */
  600.     targa.PageMode = 0;
  601.     targa.InterlaceMode = DEF_INT;        /* Defalut:  Interlace Mode 0 */
  602.     targa.Contrast= DEF_CONTRAST;
  603.     targa.Saturation = DEF_SATURATION;
  604.     targa.Hue = DEF_HUE;
  605.     targa.RGBorCV = CV;            /* default to Composite video */
  606.     targa.VCRorCamera = CAMERA;
  607.     targa.PanXOrig = 0; targa.PanYOrig=0;
  608.     targa.PageUpper= 0xffff;        /* set the bank flags to illega& values */
  609.     targa.PageLower= 0xffff;        /* so that they will be set the first time */
  610.     targa.ovrscnAvail = 0;            /* Assume no Overscan option */
  611.     targa.ovrscnOn = 0;
  612.  
  613.     if ((envptr = getenv("TARGA")) == NULL)
  614.        return(-2);
  615.     switches = got_switches = 0;
  616.     while (*envptr) {
  617.        if (*envptr != ' ') ++got_switches;
  618.        if (*envptr >= '2' && *envptr <= '8')
  619.           switches |= (1 << ('8' - *envptr));
  620.        ++envptr;
  621.        }
  622.     if (got_switches == 0) { /* all blanks, use default */
  623.        targa.memloc = 0xA000;
  624.        targa.iobase = 0x220;
  625.        }
  626.     else {
  627.        targa.memloc = 0x8000 + ((switches & 0x70) << 8);
  628.        targa.iobase = 0x200  + ((switches & 0x0f) << 4);
  629.        }
  630.  
  631.     if ((envptr = getenv("TARGASET"))) {
  632.        while(1) { /* parse next parameter */
  633.           while (*envptr == ' ' || *envptr == ',') ++envptr;
  634.           if (*envptr == 0) break;
  635.           if (*envptr >= 'a' && *envptr <= 'z') *envptr -= ('a'-'A');
  636.           i = atoi(envptr+1);
  637.           switch (*envptr) {
  638.          case 'T':
  639.             if (i == 16) targa.boardType = TYPE_16;
  640.             if (i == 24) targa.boardType = TYPE_24;
  641.             if (i == 32) targa.boardType = TYPE_32;
  642.             break;
  643.          /* case 'E' not done, meaning not clear */
  644.          case 'X':
  645.             targa.xOffset = i;
  646.             break;
  647.          case 'Y':
  648.             targa.yOffset = i;
  649.             break;
  650.          case 'I':
  651.             targa.InterlaceMode = i;
  652.             break;
  653.          /* case 'N' not done, I don't know how to handle it */
  654.          case 'R':
  655.             targa.RGBorCV = RGB;
  656.             break;
  657.          case 'B':
  658.             targa.VCRorCamera = CAMERA;
  659.             break;
  660.          case 'V':
  661.             targa.VCRorCamera = VCR;
  662.             break;
  663.          case 'G':
  664.             targa.AlwaysGenLock = 1;
  665.             break;
  666.          case 'C':
  667.             targa.Contrast = i * 31 / 100;
  668.             break;
  669.          case 'S':
  670.             targa.Saturation = i * 7 / 100;
  671.             break;
  672.          case 'H':
  673.             targa.Hue = i * 31 / 100;
  674.             break;
  675.          /* note: 'A' and 'O' defined but apply only to type M8 */
  676.          /* case 'P' not handled cause I don't know how */
  677.          }
  678.           while (*(++envptr) >= '0' && *envptr <= '9') { }
  679.           }
  680.        }
  681.  
  682.     if ( targa.boardType == TYPE_16 ) {
  683.         targa.MaxBanks = 16;
  684.         targa.BytesPerPixel = 2;
  685.     }
  686.     if ( targa.boardType == TYPE_24 ) {
  687.         targa.MaxBanks = 32;
  688.         targa.BytesPerPixel = 3;
  689.     }
  690.     if ( targa.boardType == TYPE_32 ) {
  691.         targa.MaxBanks = 32;
  692.         targa.BytesPerPixel = 4;
  693.     }
  694.  
  695.     /****** Compute # of rows per 32K bank    ********/
  696.     targa.RowsPerBank = 512/(targa.MaxBanks);
  697.     targa.AddressShift =  targa.MaxBanks>>4;
  698.  
  699.     /*    if initializing CVA:  set these before we quit    */
  700.     SetSaturation(targa.Saturation);
  701.     SetHue(targa.Hue);
  702.     SetContrast( targa.Contrast);
  703.  
  704.     /*    Set Genlock bit if always genlocked */
  705.     /*    Set before flipping and jerking screen */
  706.     TSetMode( (targa.AlwaysGenLock<<SHF_GENLOCK) | DEF_MODE);
  707.  
  708.     SetBlndReg(0);        /*  disable blend mode on TARGA 32 */
  709.  
  710.     SetInterlace(targa.InterlaceMode);
  711.     SetFixedRegisters();
  712.     SetOverscan( 0 );
  713.  
  714.     top    = 140 - (targa.LinesPerField / 2);
  715.     bottom = top + targa.LinesPerField;
  716.     SetVBorder(top,bottom);
  717.     SetVertShift(256-targa.LinesPerField);
  718.  
  719.     SetMask(DEF_MASK);
  720.     SetRGBorCV (targa.RGBorCV );
  721.     SetVCRorCamera(targa.VCRorCamera);
  722.  
  723.     /*    See if the raster register is working correctly and
  724.         return error flag if its not         */
  725.     return (( VWait() == -1) ? -1 : 0);
  726.  
  727. }
  728.  
  729.  
  730. /**************************************************************/
  731.  
  732. static void GraphEnd()
  733. {
  734.     TSetMode( (targa.mode)&MSK_MSEL );     /*  disable memory */
  735. }
  736.  
  737.  
  738. /**************************************************************/
  739. /* Set the registers which have required values */
  740.  
  741. #define FIXED_REGS    10
  742.  
  743. static int FixedRegs[] = {
  744.     DR6,DR7,DR12,DR13,DR14,DR15,DR16,DR17,DR18,DR19
  745. };
  746.  
  747. static int FixedValue[] = {
  748.     DEF_DR6,DEF_DR7,DEF_DR12,DEF_DR13,DEF_DR14,
  749.     DEF_DR15,DEF_DR16,DEF_DR17,DEF_DR18,DEF_DR19
  750. };
  751.  
  752. static void SetFixedRegisters()
  753. {
  754. int reg;
  755.  
  756.     for ( reg=0; reg<FIXED_REGS; reg++)
  757.         SetDispReg(FixedRegs[reg],FixedValue[reg]);
  758. }
  759.  
  760.  
  761.