home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / graf / fract5.zip / TGASUBS.C < prev    next >
C/C++ Source or Header  |  1989-06-05  |  19KB  |  829 lines

  1. /* tsubs.c */
  2.  
  3. #define TARGA_DATA
  4.  
  5. #include    "targa.h"
  6.  
  7. /*******************************************************************/
  8.  
  9. void
  10. VCenterDisplay( nLines )
  11. int nLines;
  12. {
  13. int    lines;
  14. int top, bottom;
  15. long color;
  16.  
  17.     lines  = nLines >> 1;                    /* half value of last line 0..x */
  18.     top         = 140 - (lines >> 1);
  19.     bottom = top + lines;
  20.     SetVBorder( top, bottom );
  21.     SetVertShift( 255 - lines );    /* skip lines we're not using */
  22.  
  23.     if( targa->boardType == 16 )
  24.         color = (12 << 10) | (12 << 5) | 12;
  25.     else
  26.         color = (80 << 16) | (80 << 8) | 80;
  27.     SetBorderColor( (long *)&color );
  28. }
  29.  
  30.  
  31. /*****************************************************************/
  32.  
  33. void
  34. SetDispReg(reg, value)
  35. int reg, value;
  36. {
  37.     targa->DisplayRegister[reg] = value;    
  38.  
  39.     TSetMode(targa->mode&MSK_REGWRITE);  /* select Index Register write */
  40.     OUTPORTB(DRREG, reg);    /* select sync register */
  41.     /* 
  42.      *        Set Mask register to write value to
  43.      *        display register and to set Bit 9 in the DR
  44.      */
  45.     TSetMode( ((targa->mode|(~MSK_REGWRITE))     /* turn on write bit */
  46.                            & MSK_BIT9      )     /* turn off Bit 9 */
  47.                            | (value&0x0100)>>1); /* set bit 9 for value */
  48.     OUTPORTB(DRREG, value);    /* select sync register */
  49.     return;
  50.  }
  51.  
  52. /*****************************************************************/
  53.  
  54. #define   WAITCOUNT  20000
  55.  
  56. int
  57. VWait()
  58. {
  59. int    rasterreg, GiveUp;
  60.     
  61.     rasterreg = RASTERREG;
  62.  
  63.     GiveUp= WAITCOUNT;
  64.     /*
  65.       *    If beyond bottom of frame wait for next field
  66.      */
  67.     if ( GetLine(rasterreg) == 0 ) {
  68.         while ( (GiveUp>0) && (GetLine(rasterreg)==0) ) GiveUp--;
  69.     }
  70.     /*
  71.      *    Wait for the bottom of the border
  72.      */
  73.     while ( (GiveUp>0) && (GetLine(rasterreg) >0) ) GiveUp--;
  74.  
  75.     if ( GiveUp > 0 )  return(0);
  76.     else               return(-1);
  77. }
  78.  
  79.  
  80. /*****************************************************************/
  81.  
  82. void
  83. SetVBorder(top, bottom)
  84. int top, bottom;
  85. {
  86.     /* top border */
  87.     if ( top < MIN_TOP ) top=MIN_TOP;    
  88.     SetDispReg(TOPBORDER,top);
  89.     /* bottom border */
  90.     if ( bottom > MAX_BOTTOM ) bottom=MAX_BOTTOM;
  91.     SetDispReg(BOTTOMBORDER,bottom);
  92.  
  93.     SetDispReg(DR10,top);
  94.     SetDispReg(DR11,bottom);
  95. }
  96.  
  97.  
  98. /*****************************************************************/
  99.  
  100. void
  101. SetRGBorCV(type)
  102. int    type;
  103. {
  104.     /*  set the contrast level */
  105.     targa->RGBorCV = type;
  106.     targa->VCRCon = ( targa->VCRCon  & MSK_RGBORCV ) | 
  107.                     (targa->RGBorCV<<SHF_RGBORCV) ;
  108.     OUTPORTB(VCRCON, targa->VCRCon );
  109.     return;
  110. }
  111.  
  112. /*****************************************************************/
  113.  
  114. void
  115. SetVCRorCamera(type)
  116. int    type;
  117. {
  118.     targa->VCRorCamera = type&1;
  119.     targa->VCRCon = ( targa->VCRCon  & MSK_VCRORCAMERA ) | 
  120.                     (targa->VCRorCamera<<SHF_VCRORCAMERA) ;
  121.     OUTPORTB(VCRCON, targa->VCRCon );
  122.  
  123. }
  124.  
  125.  
  126. /*****************************************************************/
  127.  
  128. void
  129. SetBorderColor(color)
  130. long *color;
  131. {
  132.     targa->BorderColor = *color;
  133.     OUTPORTB(BORDER, (int)(0x0000ffffL&(*color)));
  134.     OUTPORTB((BORDER+2), (int)(*(color)>>16));
  135.  
  136.     return;
  137. }
  138.  
  139. /*****************************************************************/
  140.  
  141. void
  142. SetMask(mask)
  143. int mask;
  144. {
  145.     /* mask to valid values and output to mode register */
  146.     targa->Mask = mask;
  147.     OUTPORTB(MASKREG, mask);
  148.     return;
  149. }
  150.  
  151.  
  152. /*****************************************************************/
  153.  
  154. void
  155. SetVertShift(preshift)
  156. int    preshift;
  157. {
  158.     /*  set the Vertical Preshift count  level */
  159.     targa->VertShift = preshift;
  160.     OUTPORTB(VERTPAN, preshift);
  161.     return;
  162. }
  163.  
  164.  
  165. /*****************************************************************/
  166.  
  167. static   long  black =0L;
  168.  
  169. void
  170. SetOverscan(mode)
  171. int mode;
  172. {
  173. int temp;
  174. long tempColor;
  175.  
  176.     targa->ovrscnOn = mode;
  177.     if ( mode == 0 ) {
  178.             INPORTB(UNDERREG);   /*  select underscan mode */
  179.              SetHBorder(    (DEF_LEFT+targa->xOffset),
  180.                         (DEF_RIGHT+targa->xOffset));
  181.             SetDispReg(4,352);
  182.             SetDispReg(5,1);
  183.             SetBorderColor(&targa->BorderColor);
  184.     }
  185.     else    {
  186.             INPORTB(OVERREG);   /*  select overrscan mode */
  187.             SetDispReg(0,64);    /*  Set four of the display registers */
  188.             SetDispReg(1,363);  /*  to values required for Overscan */
  189.             SetDispReg(4,363);
  190.             SetDispReg(5,17);
  191.             tempColor = targa->BorderColor;
  192.             SetBorderColor(&black);
  193.             targa->BorderColor = tempColor;
  194.     }
  195. }
  196.  
  197.  
  198. /*****************************************************************/
  199.  
  200. void
  201. SetInterlace(type)
  202. int type;
  203. {
  204. int pageMode;
  205.  
  206.     pageMode= GetPageMode();
  207.     targa->InterlaceMode= type & MSK_INTERLACE;
  208.     SetDispReg(INTREG, targa->InterlaceMode);
  209.     /*
  210.      *    SET THE INTERLACE BIT TO MATCH THE INTERLACE MODE AND 
  211.      *    SCREEN RESOLUTION -  SCREEN PAGE
  212.      */
  213.     if ( ( targa->InterlaceMode >= 2 ) && 
  214.          ( pageMode> 1 )  &&
  215.          ( (pageMode&1) != 0 )    )     TSetMode(targa->mode|(~MSK_IBIT) );
  216.     else                                TSetMode(targa->mode& MSK_IBIT);
  217.     return;
  218. }
  219.  
  220.  
  221. /*****************************************************************/
  222.  
  223. void
  224. SetBlndReg(value)
  225. int    value;
  226. {
  227.     /*  set the Vertical Preshift count  level */
  228.     if ( targa->boardType == 32 ) {
  229.         targa->VCRCon = (targa->VCRCon&0xfe) | value;
  230.         OUTPORTB(BLNDREG, value);
  231.         }
  232.     return;
  233. }
  234.  
  235.  
  236. /*****************************************************************/
  237.  
  238. void
  239. TSetMode(mode)
  240. int mode;    /*   Mode Register Value */
  241. {
  242.     /* mask to valid values and output to mode register */
  243.     OUTPORTB(MODEREG, mode );
  244.     targa->mode = mode;
  245. }
  246.  
  247.  
  248. /*****************************************************************/
  249.  
  250. void
  251. SetContrast(level)
  252. int    level;
  253. {
  254.     /*  set the contrast level */
  255.     targa->Contrast = level &((~MSK_CONTRAST)>>SHF_CONTRAST);
  256.     targa->VCRCon = ( targa->VCRCon  & MSK_CONTRAST ) | 
  257.             (targa->Contrast<<SHF_CONTRAST) ;
  258.     OUTPORTB(VCRCON, targa->VCRCon );
  259.     return;
  260. }
  261.  
  262.  
  263. /*****************************************************************/
  264.  
  265. void
  266. SetHue(level)
  267. int    level;
  268. {
  269.         /*  set the hue level -  Mask to valid value */
  270.         targa->Hue = level&((~MSK_HUE)>>SHF_HUE);
  271.                     /* mask to valid range */
  272.         targa->SatHue = (targa->SatHue&MSK_HUE) | 
  273.                    (targa->Hue<<SHF_HUE);
  274.         OUTPORTB(SATHUE, targa->SatHue );
  275.     return;
  276. }
  277.  
  278.  
  279. /*****************************************************************/
  280.  
  281. void
  282. SetSaturation(level)
  283. int    level;
  284. {
  285.     /*  set the saturation level */
  286.  
  287.         targa->Saturation= level&( (~MSK_SATURATION)>>SHF_SATURATION);
  288.         targa->SatHue =  (targa->SatHue&MSK_SATURATION) |
  289.                 (targa->Saturation<<SHF_SATURATION);
  290.         OUTPORTB(SATHUE , targa->SatHue );
  291.     return;
  292. }
  293.  
  294.  
  295. /*****************************************************************/
  296.  
  297. int
  298. GetPageMode()
  299. {
  300.     return(targa->PageMode);
  301. }
  302.  
  303.  
  304. /*************************************************************/
  305.  
  306. void
  307. SetPageMode(pageMode)
  308. int    pageMode;
  309. {
  310.  
  311.     pageMode &= 0x07;
  312.     targa->PageMode = pageMode;
  313.     VWait();
  314.     TSetMode( (targa->mode)&(MSK_RES) |((pageMode<<SHF_RES)&(~MSK_RES)) ) ;
  315.     if ( ( targa->DisplayRegister[20] >= 2 ) && 
  316.          ( pageMode> 1 )  &&
  317.          ( (pageMode&1) != 0 )    )     TSetMode(targa->mode|(~MSK_IBIT) );
  318.     else
  319.         TSetMode(targa->mode& MSK_IBIT);
  320.     return;
  321. }
  322.  
  323.  
  324. /*****************************************************************/
  325.  
  326. void
  327. SetHBorder(left, right)
  328. int left, right;    /* left & right border positions */
  329. {
  330.     SetDispReg(LEFTBORDER, left);    /* set horizontal left border */
  331.     SetDispReg(RIGHTBORDER,right);    /* set horizontal right border */
  332. /*
  333.  *                    Set DR 8 and 9 since they
  334.  *                    default to tracking DR0 and DR 1
  335.  */    
  336.     SetDispReg(DR8,left);
  337.     SetDispReg(DR9,left);
  338.  
  339.     return;
  340. }
  341.  
  342.  
  343. /*****************************************************************/
  344.  
  345. void
  346. SetGenlock(OnOrOff)
  347. int    OnOrOff;
  348. {
  349.     TSetMode( (targa->mode)&(MSK_GENLOCK)
  350.             |((OnOrOff<<SHF_GENLOCK)&(~MSK_GENLOCK)) );
  351. }
  352.  
  353.  
  354. /*****************************************************************/
  355. /* was asm, TC fast enough on AT */
  356.  
  357. int
  358. GetLine( port )
  359. int    port;
  360. {
  361. int cnt;
  362. int val1, val2;
  363.     
  364.     val1 = INPORTB( port );
  365.     for( cnt = 0; cnt < 20; cnt++ ) {
  366.         val2 = INPORTB( port );
  367.         if( val1 == val2 )
  368.             break;
  369.         val1 = val2;
  370.     }
  371.     return( val1 );
  372. }
  373.  
  374. /**********************************************************************
  375.                           TFIND
  376. **********************************************************************/
  377.  
  378. /*****************************************************************
  379.      FindTarga : seek and find the first targa
  380.  
  381.     Usage:
  382.         int   ret=0;
  383.         ret = FindTarga(type, ioBase, memLoc)
  384.         int    *type;         targa type (8, 16, 24, 32)
  385.        int    *ioBase;     io base location    
  386.         int    *memLoc;     memory base location
  387.  
  388.         ret = 0 if no targa is found or the TARGA is an invalid type
  389.               and the  arguments are not changed
  390. *****************************************************************/
  391.  
  392. #define    IOPOSSIBLE      16
  393. #define    MEMPOSSIBLE      8
  394.  
  395. static unsigned ioPossible[] = {
  396.     0x220, 0x230, 0x200, 0x210, 0x240, 
  397.     0x250, 0x260, 0x270, 0x220, 0x290, 
  398.     0x2a0, 0x2b0, 0x2c0, 0x2d0, 0x2e0,
  399.     0x2f0
  400. };
  401.  
  402. static unsigned memPossible[] = {
  403.     0xa000, 0xd000, 0x8000, 0x9000, 
  404.     0xc000, 0xe000, 0xf000, 0xb000
  405. };
  406.  
  407.  
  408. int
  409. FindTarga(type, ioBase, memLoc)
  410. int    *type;        /* targa type (8, 16, 24, 32)    */
  411. int    *ioBase;    /* io base location        */
  412. int    *memLoc;    /* memory base location        */
  413. {
  414. int    i;
  415. int    j;
  416.  
  417. int    huntType;    /* type we hunt for    */
  418. int    targaFound;
  419. int    firstFound;
  420. int    tmpMemLoc;
  421. int    tmpIoBase;
  422. int    tmpType;
  423. int    possMemLoc;
  424. int    possIoBase;
  425. int    possType;
  426.  
  427.     /*
  428.      *    Find its I/O Space by searching for raster counter.
  429.      *
  430.      *    Look for the finger print of an I/O port register that
  431.      *    cycles between 0 and 242 and its companion which is always
  432.      *    flipping between 0 and 1
  433.      */
  434.  
  435.     targaFound = FALSE;
  436.     firstFound = TRUE;
  437.     huntType = *type;
  438.  
  439.     targaFound = FALSE;
  440.     for(i = 0; i < IOPOSSIBLE; i++){ /* look for matching type    */
  441.         if(CheckRCounter(ioPossible[i]) == 0){
  442.             continue;
  443.         }
  444.         else{
  445.             possIoBase = ioPossible[i];
  446.         }
  447.  
  448.         /*
  449.          *    find the memory address
  450.          *
  451.          *    Look for a memory segment that responds
  452.          *    to the memory segment.
  453.          */
  454.  
  455.         for(j = 0; (j < MEMPOSSIBLE) &&
  456.             (CheckMemLoc(possIoBase, memPossible[j]) == 0); j++);
  457.             if(j == MEMPOSSIBLE){ 
  458.                 continue;
  459.             }
  460.             else{
  461.                 possMemLoc = memPossible[j]; 
  462.             }
  463.  
  464.         /*
  465.          *    See if this is a TARGA 8, M8,  16, 24, 32
  466.          */
  467.         if ( (possType = FindBoardType(possIoBase, possMemLoc))== -1 ) 
  468.             continue;
  469.  
  470.         targaFound = TRUE;
  471.  
  472.         if(firstFound){
  473.             tmpMemLoc = possMemLoc;
  474.             tmpIoBase = possIoBase;
  475.             tmpType = possType;
  476.             firstFound = FALSE;
  477.         }
  478.  
  479.         if((possType == huntType) && targaFound) {
  480.             *memLoc = possMemLoc;
  481.             *ioBase = possIoBase;
  482.             *type = possType;
  483.             return(1);
  484.         }
  485.     }
  486.  
  487.     if(targaFound) {
  488.         if(possType != huntType){
  489.             *memLoc = tmpMemLoc;
  490.             *ioBase = tmpIoBase;
  491.             *type = tmpType;
  492.         }
  493.     }
  494.  
  495.     if(targaFound)
  496.         return(1);
  497.     else
  498.         return(0);
  499. }
  500.  
  501.  
  502. /*****************************************************************
  503.     CheckRCounter --  See if raster counter at this base IO address
  504.  
  505.     usage:     ret = CheckRCounter(ioBase)
  506.             unsigned ioBase;
  507.                 
  508.         ret ==  0   if not at this address
  509.             1   if fingerprint found
  510.  
  511. *****************************************************************/
  512.  
  513. #define LINES    1000    /*  Pulled out of the air            */
  514.  
  515. #define CHANGES  20    /*  This is the number of valid changes        */
  516.  
  517. int
  518. CheckRCounter(ioBase)
  519. unsigned    ioBase;
  520. {
  521. int    i;                    /* array index */
  522. int    changes;        /*  number of valid transitions */
  523. int    new;                /*  temporary variable */
  524. int    old;                /*  last valid raster value */
  525. int    rasterReg;    /*  value of the raster Register */
  526.  
  527.     old =  0;    /*  insure that we don't blow out when starting */
  528.     changes =  0;        /*  zero change counter */
  529.     rasterReg = ioBase + (signed)0xC00 ;   /*  add offset to I/O base */
  530.  
  531.     /*
  532.     *    Read LINES raster values and check if each is valid wrt
  533.     *    previous value.  Quit and return 0 if invalid 
  534.     */
  535.  
  536.     for (i=0; i<LINES; i++){
  537.         if ((new = INPORTB(rasterReg)) > old ){
  538.             if(new > 243){ return(0);}   /* return if illegal */
  539.             old = new;
  540.             changes++;
  541.         }
  542.         else if(new != old){    /*   if new is less than old */
  543.             if(new != 0)  {
  544.                 /*  This is only valid if new == 0 */
  545.                 return(0);
  546.             }
  547.             /* quit otherwise */
  548.             old = 0;
  549.             changes++;
  550.         }
  551.     }
  552.     if(changes > CHANGES)     
  553.         return(1);
  554.     else
  555.         return(0);
  556. }
  557.  
  558.  
  559. /*****************************************************************
  560.  
  561.     CheckMemLoc  --  See if specified Memory Segment is associated with
  562.                     the specified IO space
  563.  
  564.     usage:   ret = CheckMemLoc(ioBase,memAddr)
  565.                 
  566.         ret  =  0   if not valid memory
  567.             1   i valid memory/IO pair
  568. *****************************************************************/
  569.  
  570. CheckMemLoc(ioBase,memAddr)
  571.     unsigned ioBase;    /*  previously determine ioSpace */
  572.     unsigned memAddr;    /*   proposed memory segment */
  573. {
  574.     int    modeReg,  maskReg;
  575.     int    saveValue, temp;
  576.     int    loop;
  577.  
  578.     modeReg = ioBase + (signed)0xC00;
  579.     maskReg = ioBase + (signed)0x800;
  580.     OUTPORTB(modeReg, (signed)0x01);       /*   Select display memory */
  581.     OUTPORTW(maskReg, (signed)0x0000);    /* clear the mask for valid read */
  582.  
  583.     PEEK(0, memAddr, &saveValue, 2 );
  584.  
  585.     /*    loop and see if this is real or just junk on the bus
  586.     *    assume open bus if junk 
  587.     */
  588.  
  589.  
  590.     for(loop = 0; loop<20; loop++){
  591.  
  592.         PEEK(0, memAddr, &temp, 2 );
  593.         if(saveValue != temp){
  594.             OUTPORTB(modeReg, 0);    /*   Deselect display memory */
  595.             return(0);
  596.         }
  597.     }
  598.  
  599.     /*
  600.     *    if savevalue is -1 then we can't check using mask w/o
  601.     *    first writing out new value 
  602.     */
  603.  
  604.     if(saveValue == (signed)0xFFFF){
  605.         disable();
  606.  
  607.         temp=0;
  608.         POKE(0, memAddr, &temp,2);
  609.  
  610.         /*    If write did not work , enable ints, and fail */
  611.  
  612.         PEEK(0, memAddr, &temp, 2 );
  613.         if( temp != 0){
  614.             enable();
  615.             OUTPORTB(modeReg, 0);    /*   Deselect display memory */
  616.             return(0);
  617.         }
  618.     }
  619.  
  620.     /*    set mask and see if it returns 0xffff    */
  621.  
  622.     temp = (signed)0xffff;
  623.     OUTPORTW(maskReg, temp);
  624.  
  625.     PEEK(0, memAddr, &temp, 2 );
  626.     if(temp == (signed)0xFFFF)  loop=1;
  627.     else                loop=0;
  628.  
  629.     OUTPORTW(maskReg,0);
  630.  
  631.     if(saveValue == (signed)0xFFFF){
  632.         POKE(0, memAddr, &saveValue, 2);
  633.         enable();
  634.     }
  635.  
  636.     OUTPORTB(modeReg, 0);    /*   Deselect display memory */
  637.     return(loop);
  638. }
  639.  
  640.  
  641. /*****************************************************************
  642.   FindBoardType  -  find out what type o board is assoicated with
  643.             the TARGA located at a specied IO amd memory
  644.             space
  645.  
  646.     Usage:   ret = FindBoardType(ioBase,memAddr);
  647.  
  648.             unsigned  ioBase;    TARGA's base io address
  649.             unsigned  memAddr;    TARGA's memory space
  650.  
  651.             ret = 8 , 16, 24, 32 ----  Targa type
  652.                 -1    Unknown or invalid board
  653. ********************************************************************/
  654.  
  655. FindBoardType(ioBase,memAddr)
  656.     unsigned    ioBase;
  657.     unsigned    memAddr;
  658. {
  659.     int    modeReg,  maskReg;
  660.     int    saveVal1, saveVal2;
  661.     int    test1, test2;
  662.     int    type, temp;
  663.  
  664.  
  665.     modeReg = ioBase + (signed)0xC00;
  666.     maskReg = ioBase + (signed)0x800;
  667.     OUTPORTB(modeReg, 0x01);       /*   Select display memory */
  668.     OUTPORTW(maskReg, 0x0000);    /* clear the mask for valid read */
  669.  
  670.     PEEK(0, memAddr, &saveVal1, 2 );
  671.     PEEK(2, memAddr, &saveVal2, 2 );
  672.  
  673.     /* write ff's to the first four bytes */
  674.  
  675.     temp =(signed)0xffff;
  676.     POKE(0, memAddr, &temp, 2);
  677.     POKE(2, memAddr, &temp, 2);
  678.  
  679.     OUTPORTW(maskReg, (signed)0x7FFe);    /* set write to known pattern */
  680.     temp =0;
  681.     POKE(0, memAddr, &temp, 2);    /*  and determine is 8, 16, 24, or 32 */
  682.     POKE(2, memAddr, &temp, 2);    /*  from pattern read */
  683.  
  684.     OUTPORTW(maskReg, 0);
  685.     PEEK(0, memAddr, &test1, 2 );
  686.  
  687.     type = -1;
  688.     if(test1 == (signed)0x7ffe) type = TYPE_16;
  689.     if(test1 == (signed)0xfffc){
  690.         PEEK(2, memAddr, &test2, 2 );
  691.         if(test2 == (signed)0x7fff) type = TYPE_32;
  692.         if(test2 == (signed)0xffff) type = TYPE_24;
  693.     }
  694.  
  695.     OUTPORTW(maskReg, 0x0000);    /* clear the mask for valid read */
  696.     POKE(0, memAddr, &saveVal1, 2);
  697.     POKE(2, memAddr, &saveVal2, 2);
  698.     OUTPORTB(modeReg, 0);    /*   Deselect display memory */
  699.     return(type);
  700. }
  701.  
  702. /**********************************************************************
  703.                           TINIT
  704. **********************************************************************/
  705.  
  706. GraphInit( board )
  707. int board;
  708. {
  709. int    cnt;
  710. int bottom, top;
  711. int  mode, tBoard;
  712.     
  713.     board = board;
  714.  
  715.     memset( &tstructure, 0, sizeof(tstructure) );
  716.     targa = &tstructure;
  717.  
  718.     targa->boardType = -1;                                        /*  assume the resident board */
  719.     targa->xOffset = 0;  targa->yOffset = 0;  /* default to no offset */
  720.     targa->LinesPerField= DEF_ROWS/2;                 /*  number of lines per field */
  721.     targa->AlwaysGenLock = DEF_GENLOCK;                /* default to genlock off */
  722.     targa->PageMode = 0;
  723.     targa->InterlaceMode = DEF_INT;                       /* Defalut:  Interlace Mode 0 */
  724.     targa->Contrast= DEF_CONTRAST;
  725.     targa->Saturation = DEF_SATURATION;
  726.     targa->Hue = DEF_HUE;
  727.     targa->RGBorCV = CV;                                            /*  default to Composite video */
  728.     targa->VCRorCamera = CAMERA;
  729.     targa->PanXOrig = 0; targa->PanYOrig=0;
  730.     targa->PageUpper= 0xffff;                    /*  set the bank flags to illega& values */
  731.     targa->PageLower= 0xffff;               /*  so that they will be set the first time */
  732.     targa->ovrscnAvail = 0;                   /*  Assume no Overscan option */
  733.     targa->ovrscnOn = 0;
  734.     targa->iobase = TIOBASE;
  735.     targa->memloc = TSEG;
  736.  
  737.     targa->boardType = TYPE_16;        /* default to looking for a 16 */
  738.     for( cnt = 0; ;cnt++ ) {
  739.         if( FindTarga(&targa->boardType, &targa->iobase, &targa->memloc) )
  740.             break;                                        /* if multiple, first card only */
  741.         else if( cnt == 5 )
  742.             return( -1 );        /* not found */
  743.     }
  744.  
  745.     if ( targa->boardType == TYPE_16 ) {
  746.             targa->MaxBanks = 16;
  747.             targa->BytesPerPixel = 2;
  748.     }
  749.     if ( targa->boardType == TYPE_24 ) {
  750.             targa->MaxBanks = 32;
  751.             targa->BytesPerPixel = 3;
  752.     }
  753.     if ( targa->boardType == TYPE_32 ) {
  754.             targa->MaxBanks = 32;
  755.             targa->BytesPerPixel = 4;
  756.     }
  757.  
  758.         /******    Compute # of rows per 32K bank  ********/
  759.     targa->RowsPerBank = 512/(targa->MaxBanks);
  760.     targa->AddressShift =  targa->MaxBanks>>4;
  761.  
  762.         /*    if initializing CVA:  set these before we quit    */
  763.     SetSaturation(targa->Saturation);
  764.     SetHue(targa->Hue);
  765.     SetContrast( targa->Contrast);
  766.     
  767.         /*    Set Genlock bit if always genlocked */
  768.         /*    Set before flipping and jerking screen */
  769.     TSetMode( (targa->AlwaysGenLock<<SHF_GENLOCK) | DEF_MODE);
  770.  
  771.     SetBlndReg(0);        /*  disable blend mode on TARGA 32 */
  772.  
  773.     SetInterlace(targa->InterlaceMode);
  774.     SetFixedRegisters();
  775.     SetOverscan( 0 );
  776.  
  777.     top         = 140 - (targa->LinesPerField / 2);
  778.     bottom = top + targa->LinesPerField;
  779.     SetVBorder(top,bottom);
  780.     SetVertShift(256-targa->LinesPerField);
  781.  
  782.     SetMask(DEF_MASK);
  783.     SetRGBorCV (targa->RGBorCV );
  784.     SetVCRorCamera(targa->VCRorCamera);
  785.  
  786.     /*    See if the raster register is working correctly and
  787.         return error flag if its not     */
  788.     if ( VWait() == -1)
  789.         return(-1);
  790.     else
  791.         return(0);
  792. }
  793.  
  794.  
  795. /**************************************************************/
  796. void
  797. GraphEnd()
  798. {
  799.     TSetMode( (targa->mode)&MSK_MSEL );    /*  disable memory */
  800.     return;
  801. }
  802.  
  803.  
  804. /**************************************************************/
  805. /* Set the registers which have required values */
  806.  
  807. #define    FIXED_REGS    10
  808.  
  809. static int FixedRegs[] = {
  810.     DR6,DR7,DR12,DR13,DR14,DR15,DR16,DR17,DR18,DR19
  811. };
  812.  
  813. static int FixedValue[] = {
  814.     DEF_DR6,DEF_DR7,DEF_DR12,DEF_DR13,DEF_DR14,
  815.     DEF_DR15,DEF_DR16,DEF_DR17,DEF_DR18,DEF_DR19
  816. };
  817.  
  818. SetFixedRegisters()
  819. {
  820. int reg;
  821.  
  822.     for ( reg=0; reg<FIXED_REGS; reg++)
  823.         SetDispReg(FixedRegs[reg],FixedValue[reg]);
  824.     return;
  825. }
  826.  
  827.  
  828.  
  829.