home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / mondello / clgd5472.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  18KB  |  563 lines

  1. /*
  2.    file: clgd5472.c
  3.    auth: Peter McDermott
  4.    date: Mon Feb 12 16:49:41 CST 1996
  5. */
  6.  
  7.  
  8. #include "mondello/clgd5471.h"
  9. #include "mondello/clgd547x.h"
  10. #include "mondello/compiler.h"     /* outb(), inb() */
  11. #include "mondello/clgd5472.h"
  12. #include <math.h>         /* fabs() in clgd5472CalcClockVals */
  13.  
  14. /* #define DEBUG_CLGD5472 */
  15.  
  16. /* reference clock */
  17. #define clgd5472_REF_CLOCK 14.31818E6
  18. #define clgd5472_MAX_CLOCK_IN_KHZ 135000
  19.  
  20. /* overlay registers */
  21. #define clgd5472_HOSTART 0x12
  22. #define clgd5472_HOEND   0x14
  23. #define clgd5472_VOSTART 0x22
  24. #define clgd5472_VOEND   0x24
  25.  
  26. /* horizontal display timing registers */
  27. #define clgd5472_HTOTAL  0x10
  28. #define clgd5472_HDEND   0x16
  29. #define clgd5472_HSSTART 0x18
  30. #define clgd5472_HSEND   0x1A
  31. #define clgd5472_HBSTART 0x68
  32. #define clgd5472_HBEND   0x6A
  33.  
  34. /* vertical display timing registers */
  35. #define clgd5472_VTOTAL  0x20
  36. #define clgd5472_VDEND   0x26
  37. #define clgd5472_VSSTART 0x28
  38. #define clgd5472_VSEND   0x2A
  39. #define clgd5472_VBSTART 0x78
  40. #define clgd5472_VBEND   0x7A
  41.  
  42. /* various and sundry display timing registers */
  43. #define clgd5472_CRTC         0x50
  44. #define clgd5472_PIXELFMT     0x51
  45. #define clgd5472_SYNC         0x53
  46. #define clgd5472_PCLKNUM      0x57
  47. #define clgd5472_PCLKDEN      0x58
  48. #define clgd5472_MONDELLOMODE 0x70
  49. #define clgd5472_TEST         0xF3  /* used to select internal or ref clk */
  50.  
  51. /* color control registers */
  52. #define clgd5472_PDOWN           0x02
  53. #define clgd5472_DAC_WRITE_INDEX 0x60
  54. #define clgd5472_DAC_READ_INDEX  0x62
  55. #define clgd5472_DAC_PIXEL_MASK  0x64
  56. #define clgd5472_DAC_DATA        0x65
  57.  
  58. typedef struct {
  59.   unsigned long htotal;
  60.   unsigned long hdend;
  61.   unsigned long hsstart;
  62.   unsigned long hsend;
  63.   unsigned long vtotal;
  64.   unsigned long vdend;
  65.   unsigned long vsstart;
  66.   unsigned long vsend;
  67.   unsigned long crtc;
  68.   unsigned long pixelfmt;
  69.   unsigned long sync;
  70.   unsigned long pclknum;
  71.   unsigned long pclkden;
  72.   unsigned long hbstart;
  73.   unsigned long hbend;
  74.   unsigned long mondellomode;
  75.   unsigned long vbstart;
  76.   unsigned long vbend;
  77. } clgd5472CRTCRegs, *clgd5472CRTCRegPtr;
  78.  
  79. clgd5472CRTCRegs regs;
  80.  
  81. void outDacB(int address, BYTE data);
  82. void outDacW(int address, int data);
  83. int inDacB(int address);
  84.  
  85. /* default palette values */
  86. static const unsigned char default_red[256]
  87. =
  88. {0, 0, 0, 0, 42, 42, 42, 42, 21, 21, 21, 21, 63, 63, 63, 63,
  89.  0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
  90.  0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 47, 31, 16,
  91.  0, 0, 0, 0, 0, 0, 0, 0, 31, 39, 47, 55, 63, 63, 63, 63,
  92.  63, 63, 63, 63, 63, 55, 47, 39, 31, 31, 31, 31, 31, 31, 31, 31,
  93.  45, 49, 54, 58, 63, 63, 63, 63, 63, 63, 63, 63, 63, 58, 54, 49,
  94.  45, 45, 45, 45, 45, 45, 45, 45, 0, 7, 14, 21, 28, 28, 28, 28,
  95.  28, 28, 28, 28, 28, 21, 14, 7, 0, 0, 0, 0, 0, 0, 0, 0,
  96.  14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 24, 21, 17,
  97.  14, 14, 14, 14, 14, 14, 14, 14, 20, 22, 24, 26, 28, 28, 28, 28,
  98.  28, 28, 28, 28, 28, 26, 24, 22, 20, 20, 20, 20, 20, 20, 20, 20,
  99.  0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 8, 4,
  100.  0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 12, 14, 16, 16, 16, 16,
  101.  16, 16, 16, 16, 16, 14, 12, 10, 8, 8, 8, 8, 8, 8, 8, 8,
  102.  11, 12, 13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 13, 12,
  103.  11, 11, 11, 11, 11, 11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0};
  104. static const unsigned char default_green[256]
  105. =
  106. {0, 0, 42, 42, 0, 0, 21, 42, 21, 21, 63, 63, 21, 21, 63, 63,
  107.  0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
  108.  0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 31, 47, 63, 63, 63, 63,
  109.  63, 63, 63, 63, 63, 47, 31, 16, 31, 31, 31, 31, 31, 31, 31, 31,
  110.  31, 39, 47, 55, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39,
  111.  45, 45, 45, 45, 45, 45, 45, 45, 45, 49, 54, 58, 63, 63, 63, 63,
  112.  63, 63, 63, 63, 63, 58, 54, 49, 0, 0, 0, 0, 0, 0, 0, 0,
  113.  0, 7, 14, 21, 29, 28, 28, 28, 28, 28, 28, 28, 28, 21, 14, 7,
  114.  14, 14, 14, 14, 14, 14, 14, 14, 14, 17, 21, 24, 28, 28, 28, 28,
  115.  28, 28, 28, 28, 28, 24, 21, 17, 20, 20, 20, 20, 20, 20, 20, 20,
  116.  20, 22, 24, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22,
  117.  0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 12, 16, 16, 16, 16,
  118.  16, 16, 16, 16, 16, 12, 8, 4, 8, 8, 8, 8, 8, 8, 8, 8,
  119.  8, 10, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10,
  120.  11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 15, 16, 16, 16, 16,
  121.  16, 16, 16, 16, 16, 15, 13, 12, 0, 0, 0, 0, 0, 0, 0, 0};
  122. static const unsigned char default_blue[256]
  123. =
  124. {0, 42, 0, 42, 0, 42, 0, 42, 21, 63, 21, 63, 21, 63, 21, 63,
  125.  0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
  126.  63, 63, 63, 63, 63, 47, 31, 16, 0, 0, 0, 0, 0, 0, 0, 0,
  127.  0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39,
  128.  31, 31, 31, 31, 31, 31, 31, 31, 31, 39, 47, 55, 63, 63, 63, 63,
  129.  63, 63, 63, 63, 63, 58, 54, 49, 45, 45, 45, 45, 45, 45, 45, 45,
  130.  45, 49, 54, 58, 63, 63, 63, 63, 28, 28, 28, 28, 28, 21, 14, 7,
  131.  0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 14, 21, 28, 28, 28, 28,
  132.  28, 28, 28, 28, 28, 24, 21, 17, 14, 14, 14, 14, 14, 14, 14, 14,
  133.  14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22,
  134.  20, 20, 20, 20, 20, 20, 20, 20, 20, 22, 24, 26, 28, 28, 28, 28,
  135.  16, 16, 16, 16, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0,
  136.  0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10,
  137.  8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 12, 14, 16, 16, 16, 16,
  138.  16, 16, 16, 16, 16, 15, 13, 12, 11, 11, 11, 11, 11, 11, 11, 11,
  139.  11, 12, 13, 15, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0};
  140.  
  141.  
  142. /*----------------------------------------------------------------------------
  143.   outDacB(addr,data) - send a byte to the 5472 DAC at address addr
  144. -----------------------------------------------------------------------------*/
  145. void outDacB(int address, BYTE data)
  146. {
  147.   int i;
  148.   iopl(3);
  149.  
  150.   for (i=0; i<10; i++)
  151.     outb(0x80,0xaa);
  152.  
  153.   *((BYTE *)(clgd547xLogicalBase+0x3ffe00+address))=data;
  154.  
  155.   for (i=0; i<10; i++)
  156.     outb(0x80,0xaa);
  157.   
  158. }
  159.  
  160. /*----------------------------------------------------------------------------
  161.   outDacW(addr,data) send a word to the 5472 DAC at address addr
  162. -----------------------------------------------------------------------------*/
  163. void outDacW(int address, int data)
  164. {
  165.   int i;
  166.  
  167.   iopl(3);
  168.   for (i=0; i<10; i++)
  169.     outb(0x80,0xaa);
  170.   
  171.   *((char *)((unsigned)clgd547xLogicalBase+0x3ffe00+address))=data & 0x00ff;
  172.   *((char *)((unsigned)clgd547xLogicalBase+0x3ffe00+address+1))=
  173.     (data >> 8)&0xff;
  174.  
  175.   for (i=0; i<10; i++)
  176.     outb(0x80,0xaa);
  177.   
  178. }
  179.  
  180. /*----------------------------------------------------------------------------
  181.   inDacB(addr) read a byte from the 5472 DAC at address addr
  182. -----------------------------------------------------------------------------*/
  183. int inDacB(int address)
  184. {
  185.   int i;
  186.   char c;
  187.  
  188.   iopl(3);
  189.  
  190.   for (i=0; i<10; i++)
  191.     outb(0x80,0xaa);
  192.  
  193.   c=*((char *)((unsigned)clgd547xLogicalBase+0x3ffe00+address));
  194.   
  195.   return ((int)c)&0xff;  
  196. }
  197.  
  198. /*---------------------------------------------------------------------------
  199.   clgd5472InitLUT()
  200.   Loads the Look-Up Table with all black. 
  201. -----------------------------------------------------------------------------*/
  202. void clgd5472InitLUT(void)
  203. {
  204.     unsigned int i;
  205.  
  206.     outDacB(clgd5472_DAC_PIXEL_MASK,0xff);  /* get rid of cmap mask */
  207.     outDacB(clgd5472_DAC_WRITE_INDEX, 0);   /* set the write index to 0 */
  208.     iopl(3);
  209.     for (i = 0; i < 256; i++) { /* clear LUT */
  210.       outb(0x80,0xaa);
  211.       outb(0x80,0xaa);
  212.       outb(0x80,0xaa);
  213.       outb(0x80,0xaa);
  214.       outb(0x80,0xaa);
  215.       outDacB(clgd5472_DAC_DATA,default_red[i]);
  216.       outDacB(clgd5472_DAC_DATA,default_green[i]);
  217.       outDacB(clgd5472_DAC_DATA,default_blue[i]);
  218.     }
  219.     iopl(0);
  220. }
  221.  
  222. /*---------------------------------------------------------------------------
  223.   clgd5472WriteIndex()
  224.   Writes r,g,b tuple to given index of LUT
  225. -----------------------------------------------------------------------------*/
  226. void clgd5472WriteIndex(uint index, uint red, uint green, uint blue)
  227. {
  228.     unsigned int i;
  229.  
  230. #ifdef DEBUG_CLGD5472
  231.     printf("clgd5472WriteIndex() - writing index %d=(%d,%d,%d)\n",index,red,green,blue);
  232. #endif
  233.      
  234.     outDacB(clgd5472_DAC_PIXEL_MASK,0xff);  /* get rid of cmap mask */
  235.     outDacB(clgd5472_DAC_WRITE_INDEX,index);   /* set the write index to 0 */
  236.     iopl(3);
  237.     outb(0x80,0xaa);
  238.     outb(0x80,0xaa);
  239.     outb(0x80,0xaa);
  240.     outb(0x80,0xaa);
  241.     outb(0x80,0xaa);
  242.     outDacB(clgd5472_DAC_DATA, red);
  243.     outDacB(clgd5472_DAC_DATA, green);
  244.     outDacB(clgd5472_DAC_DATA, blue);
  245.     iopl(0);
  246. }
  247.  
  248.  
  249. /*-----------------------------------------------------------------------------
  250.   CalcClockVals - calculate the proper clock numerator, denominator and 
  251.                  post scalar given a clock frequency.
  252. -----------------------------------------------------------------------------*/
  253. void clgd5472CalcClockVals(long freq, int *inP, int *inQ, int *inPostScale)
  254. {
  255.   int p,q,p2,q2;
  256.   double calcError;
  257.   double calcError2;
  258.   float pDivQ;
  259.  
  260.   if (freq > 135E6) {   /* frequency out of range */
  261.     printf("%d clock too high\n",freq);
  262.     return;
  263.   }
  264.  
  265.   if (freq < 40E6) {    /* need to apply post scalar? */
  266.     *inPostScale=2;
  267.     freq*=2;
  268.   }
  269.   else {
  270.     *inPostScale=1;
  271.   }
  272.  
  273.   calcError2=100000E6;     /* initial error */
  274.  
  275.   pDivQ=freq/clgd5472_REF_CLOCK;
  276.   for(q=1;q<32;q++) {
  277.     if ((clgd5472_REF_CLOCK/q >= 200E3) && (clgd5472_REF_CLOCK/q <= 1E6)) {
  278.       for(p=q;p<127;p++) {
  279.         calcError=fabs(pDivQ-(p/q));
  280.         if (calcError<calcError2) {
  281.           calcError2=calcError;
  282.           q2=q;
  283.           p2=p;
  284.         }
  285.       }
  286.     }
  287.   }   
  288.   *inP=p2;
  289.   *inQ=q2;   
  290. }
  291.  
  292. static short clgd5472Inited = FALSE;
  293.  
  294. /*-----------------------------------------------------------------------------
  295.   clgd5472CalcCRTCRegs - Calculates 5472 parameters for a given mode
  296. -----------------------------------------------------------------------------*/
  297.  
  298. void clgd5472CalcCRTCRegs(clgd5472CRTCRegs *crtcRegs, mode *m)
  299. {
  300.   int p,q,postScale;
  301.   char outstr[128];
  302.   
  303. #ifdef DEBUG
  304.   printModeInfo(mode);
  305. #endif
  306.  
  307.   crtcRegs->hdend=crtcRegs->hbstart= m->CrtcHDisplay/8;
  308.   crtcRegs->hbend=crtcRegs->htotal=  m->CrtcHTotal/8;
  309.   crtcRegs->hsstart=                 m->CrtcHSyncStart/8;
  310.   crtcRegs->hsend=                   m->CrtcHSyncEnd/8;
  311.  
  312. #ifdef DEBUG
  313.   printf("CalcCRTCRegs: register values:\n");
  314.   sprintf(outstr,"CalcCRTCRegs:   hdend, hbstart: %d\n",crtcRegs->hbstart);
  315.   printf(outstr);
  316.   sprintf(outstr,"CalcCRTCRegs:   hbend, htotal:  %d\n",crtcRegs->hbend);
  317.   printf(outstr);
  318.   sprintf(outstr,"CalcCRTCRegs:   hsstart:        %d\n",crtcRegs->hsstart);
  319.   printf(outstr);
  320.   sprintf(outstr,"CalcCRTCRegs:   hsend:          %d\n",crtcRegs->hsend);
  321.   printf(outstr);
  322. #endif
  323.  
  324.   if (m->Flags & V_INTERLACE) {
  325.     crtcRegs->crtc=11;
  326.     crtcRegs->vtotal=crtcRegs->vbend=  (m->CrtcVTotal >> 1)-1;
  327.     crtcRegs->vbstart=crtcRegs->vdend= (m->CrtcVDisplay >> 1)-1;
  328.     crtcRegs->vsstart=                 (m->CrtcVSyncStart >> 1)-1;
  329.     crtcRegs->vsend=                   (m->CrtcVSyncEnd >> 1)-1;
  330.   }
  331.   else {
  332.     crtcRegs->crtc=3;
  333.     crtcRegs->vtotal=crtcRegs->vbend=  m->CrtcVTotal;
  334.     crtcRegs->vbstart=crtcRegs->vdend= m->CrtcVDisplay;
  335.     crtcRegs->vsstart=                 m->CrtcVSyncStart;
  336.     crtcRegs->vsend=                   m->CrtcVSyncEnd;
  337.   }
  338.  
  339. #ifdef DEBUG
  340.   sprintf(outstr,"CalcCRTCRegs:   crtc:           %d\n",crtcRegs->crtc);
  341.   printf(outstr);
  342.   sprintf(outstr,"CalcCRTCRegs:   vbend, vtotal:  %d\n",crtcRegs->vbend);
  343.   printf(outstr);
  344.   sprintf(outstr,"CalcCRTCRegs:   vbstart, vdend: %d\n",crtcRegs->vbstart);
  345.   printf(outstr);
  346.   sprintf(outstr,"CalcCRTCRegs:   vsstart:        %d\n",crtcRegs->vsstart);
  347.   printf(outstr);
  348.   sprintf(outstr,"CalcCRTCRegs:   vsend:          %d\n",crtcRegs->vsend);
  349.   printf(outstr);
  350. #endif
  351.  
  352.   switch (m->bitsPerPixel) {
  353.   case 8: 
  354.     crtcRegs->pixelfmt=3;
  355.     crtcRegs->mondellomode=0x10;
  356.     break;   
  357.   case 24:
  358.     crtcRegs->pixelfmt=8;
  359.     crtcRegs->mondellomode=0x00;
  360.     break; 
  361.   case 32: /* not supported */
  362.     crtcRegs->pixelfmt=12;
  363.     crtcRegs->mondellomode=0x16;
  364.     break;
  365.   }
  366.  
  367. #ifdef DEBUG
  368.   sprintf(outstr,"CalcCRTCRegs:   pixelfmt:       %d\n",crtcRegs->pixelfmt);
  369.   printf(outstr);
  370. #endif
  371.  
  372.   if (m->Flags & V_NHSYNC) 
  373.     crtcRegs->sync=12;
  374.   else 
  375.     crtcRegs->sync=76;
  376.  
  377.   if (m->Flags & V_NVSYNC) 
  378.     crtcRegs->sync|=0;
  379.   else 
  380.     crtcRegs->sync|=128;
  381.  
  382. #ifdef DEBUG
  383.   sprintf(outstr,"CalcCRTCRegs:   sync:           %d\n",crtcRegs->sync);
  384.   printf(outstr);
  385. #endif
  386.  
  387.   clgd5472CalcClockVals(m->Clock*1000*1000,&p,&q,&postScale);
  388.  
  389.   crtcRegs->pclknum = p << 1;
  390.   crtcRegs->pclkden = (postScale==2)?(0x01|(q<<3)) : (q<<3);
  391.  
  392. #ifdef DEBUG
  393.   sprintf(outstr,"CalcCRTCRegs:   pclknum:        %d\n",crtcRegs->pclknum);
  394.   printf(outstr);
  395.   sprintf(outstr,"CalcCRTCRegs:   pclkden:        %d\n",crtcRegs->pclkden);
  396.   printf(outstr);
  397. #endif
  398.  
  399. }
  400.  
  401. /*-----------------------------------------------------------------------------
  402.   setCsrSize - sets the size of the cursor (0x0 to 64x64)
  403. -----------------------------------------------------------------------------*/
  404. void clgd5472SetCsrSize(int xSize, int ySize)
  405. {
  406.   outDacB(0x32,(char)xSize & 0x3f);
  407.   outDacB(0x35,(char)ySize & 0x3f);
  408. }
  409.  
  410. /*-----------------------------------------------------------------------------
  411.   setCsrPos - sets the position of the cursor
  412. -----------------------------------------------------------------------------*/
  413. void clgd5472SetCsrPos(int xPos, int yPos) 
  414. {
  415.   outDacW(0x30,xPos & 0x0fff);
  416.   outDacW(0x33,yPos & 0x0fff);
  417. }
  418.  
  419. /*-----------------------------------------------------------------------------
  420.  clgd5472SetCRTCRegs --
  421.       Initializes the clgd5472 for the currently selected CRTC parameters.
  422. -----------------------------------------------------------------------------*/
  423. void clgd5472SetCRTCRegs(crtcRegs)
  424.      clgd5472CRTCRegPtr crtcRegs;
  425. {
  426.   int i;
  427.  
  428.   iopl(3);
  429.   
  430.   printf("clgd5472SetCRTCRegs: setting up 5471\n");
  431.   outSeq(0x2101); /* stop '71 screen refresh to DRAM, 8 dot clock */
  432.   outSeq(0x0f02); /* enable all maps for writing */
  433.   outSeq(0x0003); /* pri font = 2nd font = @ 0K offset in RAM */
  434.   outSeq(0x0804); /* select no Chain-4, no Odd/Even, 64K window in ram mode */
  435.   outSeq(0x1206); /* unlock extended regs */
  436.   outSeq(0x1107); /* map high memory in */
  437.   outSeq(0x100f); /* select 32 bit dram bus width  */
  438.   outSeq(0x321e); /* bit 0=0, Vlck no div by 2 */
  439.   
  440.   i=33;
  441.   i=(int)(((float)(i*8)/14.318)+0.5);
  442.   i=i<<8 | 0x401f;
  443.   outw(0x3c4,i);
  444.   
  445.   outGraph(0x0005); /* write mode 0, 2/4/16 color mode, vid shift EGA */
  446.   outGraph(0x0506); /* graphics (!text), map 64K at A000:0000 */
  447.   outGraph(0x0f07); /* set all planes to active for color compare */
  448.   outGraph(0x8017); /* ?? */
  449.   outGraph(0x8038); /* enable extended Mondello mode */
  450.  
  451.   printf("clgd5472SetCRTCRegs: setting up 5472\n");
  452.  
  453.   inb (0x3c6);
  454.   inb (0x3c6);
  455.   inb (0x3c6);
  456.   inb (0x3c6);
  457.   outb (0x3c6, 0xc6);
  458.  
  459.   outDacB(0xf3,0x80); /* use external clock */
  460.   outDacB(0x00,0x04); /* put 5472 into extended mode */
  461.   outDacB(0x02,0x00); /* normal DAC operation */
  462.  
  463.   printf("SetCRTCRegs: seting overlay regs\n");
  464.   outDacW(clgd5472_HOSTART,0);
  465.   outDacW(clgd5472_HOEND,0);
  466.   outDacW(clgd5472_VOSTART,0);
  467.   outDacW(clgd5472_VOEND,0);
  468.  
  469.   printf("SetCRTCRegs: setting horizontals\n");
  470.   outDacW(clgd5472_HTOTAL,crtcRegs->htotal);
  471.   outDacW(clgd5472_HDEND,crtcRegs->hdend);
  472.   outDacW(clgd5472_HSSTART,crtcRegs->hsstart);
  473.   outDacB(clgd5472_HSEND,crtcRegs->hsend);
  474.   outDacW(clgd5472_HBSTART,crtcRegs->hbstart);
  475.   outDacB(clgd5472_HBEND,crtcRegs->hbend);
  476.  
  477.   printf("SetCRTCRegs: setting verticals\n");
  478.   outDacW(clgd5472_VTOTAL,crtcRegs->vtotal);
  479.   outDacW(clgd5472_VDEND,crtcRegs->vdend);
  480.   outDacW(clgd5472_VSSTART,crtcRegs->vsstart);
  481.   outDacB(clgd5472_VSEND,crtcRegs->vsend);
  482.   outDacW(clgd5472_VBSTART,crtcRegs->vbstart);
  483.   outDacB(clgd5472_VBEND,crtcRegs->vbend);
  484.  
  485.   printf("SetCRTCRegs: setting misc\n");
  486.   outDacB(0x64,0xff); /* palette mask reg */
  487.  
  488.   outDacB(0x66,0x08); /* set palette access mode to allow access to csr clrs */
  489.  
  490.   outDacB(0x60,0x00); /* access cursor background color */
  491.   for(i=0;i<10;i++)
  492.     outb(0x80,0xaa);
  493.   outDacB(0x65,0x00); /* set cursor background color to black */
  494.   outDacB(0x65,0x00);
  495.   outDacB(0x65,0x00);
  496.  
  497.   outDacB(0x60,0x0f); /* access cursor foreground color */
  498.   for(i=0;i<10;i++)
  499.     outb(0x80,0xaa);
  500.   outDacB(0x65,0xff);  /* set csr foreground color to white */
  501.   outDacB(0x65,0xff);
  502.   outDacB(0x65,0xff);
  503.  
  504.   outDacB(0x66,0x00);  /* set palette access mode back to normal */
  505.  
  506.   outDacB(0x37,0x00);  /* set csr size to 64x64 */
  507.   clgd5472SetCsrSize(10,10);
  508.   clgd5472SetCsrPos(128,128);
  509.   outDacB(0x3c,0x00); /* Overlay control */
  510.   outDacB(0x4c,0x00); /* Color Key */
  511. /*  outDacB(0x70,0x10); */ /* select first of 2 buffers */  
  512. /*  outDacB(0x71,0x01); */ /* inconsitency between Goran's code and book! */
  513.  
  514.   outDacB(clgd5472_CRTC,crtcRegs->crtc);
  515.   outDacB(clgd5472_PIXELFMT,crtcRegs->pixelfmt);
  516.   outDacB(clgd5472_SYNC,crtcRegs->sync);
  517.   outDacB(clgd5472_PCLKNUM,crtcRegs->pclknum);
  518.   outDacB(clgd5472_PCLKDEN,crtcRegs->pclkden);
  519.   outDacB(clgd5472_MONDELLOMODE,crtcRegs->mondellomode);
  520.   outDacB(0x71,0x01);
  521.   outDacB(clgd5472_TEST,0x00); /* use internal clock */ 
  522.   outDacB(0xf0,0x00); /* why is this done?! */
  523.   outDacB(0x66,0x00); /* palette state */
  524.   outDacB(0x64,0xff); /* palette pixel mask */
  525.  
  526.   clgd5472Inited = TRUE;
  527.   
  528.   iopl(0);
  529. }
  530.  
  531. void clgd5472SetMode(mode *m) 
  532.   clgd5472CalcCRTCRegs(®s,m);
  533.   clgd5472SetCRTCRegs(®s);
  534. }
  535.  
  536. clgd5472State *clgd5472CreateState()
  537. {
  538.   return (clgd5472State*)malloc(sizeof(clgd5472State));  
  539. }
  540.  
  541. void clgd5472DeleteState(clgd5472State *state)
  542. {
  543.   free(state);
  544. }
  545.  
  546. void clgd5472SaveState(clgd5472State *state)
  547. {
  548. }
  549.  
  550. void clgd5472RestoreState(clgd5472State *state)
  551. {
  552.   /* turn off Mondello Mode */
  553.   iopl(3);
  554.   outDacB(0x00,0x00);
  555.   iopl(0);
  556. }
  557.  
  558. void setBuffer(int buffer)
  559. {
  560.   clgd547x_setBuffer(buffer);
  561.