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

  1. /* 
  2.   file: clgd5471.c
  3. */
  4.  
  5. #include "mondello/clgd547x.h"
  6. #include "mondello/type.h"
  7. #include "mondello/lut.h"
  8. #include "mondello/clgd5471.h"
  9. #include "mondello/clgd5472.h"
  10. #include "mondello/compiler.h"
  11.  
  12. BYTE clgd5471SequencerRegs[] =
  13.   {0x01,0x02,0x03,0x04,0x06,0x07,0x0f,0x1e,0x1f};
  14. int clgd5471NumSequencerRegs = sizeof(clgd5471SequencerRegs)/sizeof(BYTE);
  15.  
  16. BYTE clgd5471GraphicsRegs[]=
  17.   {0x05,0x06,0x07,0x17,0x38};
  18. int clgd5471NumGraphicsRegs = sizeof(clgd5471GraphicsRegs)/sizeof(BYTE);
  19.  
  20. BYTE clgd5471VGAIOBase;
  21.  
  22. BYTE textSeq[]  =  { 0, 3, 0, 2, 18, 0, 23, 51, 28 };
  23. BYTE textGraph[] = { 16, 14, 0, 0, 0 };
  24. BYTE textMisc = { 0 };
  25.   
  26. /*-----------------------------------------------------------------------------
  27.   clgd5471Unlock - unlocks the extended registers on the '71
  28. -----------------------------------------------------------------------------*/
  29. void clgd5471Unlock()
  30. {
  31.   outb(0x3c4,0x06);
  32.   outb(0x3c5,0x12); 
  33. }
  34.  
  35. /*----------------------------------------------------------------------------
  36.   clgd5471Lock - locks the extended registers on the '71
  37. -----------------------------------------------------------------------------*/
  38. void clgd5471Lock()
  39. {
  40.   outb(0x3c4,0x06);
  41.   outb(0x3c5,0x00); 
  42. }
  43.  
  44. /*-----------------------------------------------------------------------------
  45.   clgd5471CreateState - allocate a new state structure
  46. -----------------------------------------------------------------------------*/
  47. clgd5471State *clgd5471CreateState()
  48. {
  49.   clgd5471State *s=(clgd5471State*)malloc(sizeof(clgd5471State));
  50.  
  51.   s->validState=0;
  52.  
  53.   s->sequencerRegs=(BYTE*)malloc(clgd5471NumSequencerRegs*sizeof(BYTE));
  54.   s->graphicsRegs=(BYTE*)malloc(clgd5471NumGraphicsRegs*sizeof(BYTE));
  55.  
  56.   s->hostMemory=(BYTE*)malloc(1024*1024); /* one meg video memory */
  57.   return s;
  58. }
  59.  
  60. /*-----------------------------------------------------------------------------
  61.   clgd5471DeleteState - delete state structure
  62. -----------------------------------------------------------------------------*/
  63. void clgd5471DeleteState(clgd5471State *s)
  64. {
  65.   free(s->sequencerRegs);
  66.   free(s->graphicsRegs);
  67.   free(s->hostMemory);
  68.   free(s);
  69. }
  70.  
  71. /*-----------------------------------------------------------------------------
  72.    getRegs - get a series of registers 
  73. -----------------------------------------------------------------------------*/
  74. void getRegs(BYTE *regs, int port, BYTE *regAddress, int num)
  75. {
  76.   int i;
  77.  
  78.   clgd5471Unlock();
  79.     
  80.   for(i=0; i<num; i++) {
  81.     outb(port,regAddress[i]);
  82.     regs[i]=inb(port+1);
  83.   }
  84. }
  85.  
  86. /*-----------------------------------------------------------------------------
  87.    setRegs - set a series of registers 
  88. -----------------------------------------------------------------------------*/
  89. void setRegs(BYTE *regs, int port, BYTE *regAddress, int num)
  90. {
  91.   int i;
  92.  
  93.   clgd5471Unlock();
  94.   
  95.   for(i=0; i<num; i++) {
  96.     outb(port,regAddress[i]);
  97.     outb(port+1,regs[i]);
  98.   }  
  99. }
  100.  
  101. /*-----------------------------------------------------------------------------
  102.    clgd5471SaveState - save video state
  103. -----------------------------------------------------------------------------*/
  104. void clgd5471SaveState(clgd5471State *s)
  105. {  
  106.   iopl(3);
  107.   getRegs(s->sequencerRegs,0x3C4,clgd5471SequencerRegs,clgd5471NumSequencerRegs);
  108.   getRegs(s->graphicsRegs,0x3CE,clgd5471GraphicsRegs,clgd5471NumGraphicsRegs);
  109.   
  110.   /* what register is at 0x3c6 -- find the IBM I/O reg map */
  111.   inb(0x3c6);
  112.   inb(0x3c6);
  113.   inb(0x3c6);
  114.   inb(0x3c6);
  115.   s->miscReg=inb(0x3c6);
  116.   iopl(0);
  117.  
  118. }
  119.  
  120. /*-----------------------------------------------------------------------------
  121.    clgd5471RestoreState - restore the video state
  122. -----------------------------------------------------------------------------*/
  123. void clgd5471RestoreState(clgd5471State *s)
  124. {
  125.   iopl(3);
  126.  
  127.   setRegs(s->sequencerRegs,0x3C4,clgd5471SequencerRegs,clgd5471NumSequencerRegs);
  128.   setRegs(s->graphicsRegs,0x3CE,clgd5471GraphicsRegs,clgd5471NumGraphicsRegs);
  129.  
  130.   inb(0x3c6);
  131.   inb(0x3c6);
  132.   inb(0x3c6);
  133.   inb(0x3c6);
  134.   outb(0x3c6,s->miscReg);
  135.  
  136.   iopl(0);
  137. }
  138.  
  139. /*---------------------------------------------------------------------------*/
  140. void textMode()
  141. {
  142.   clgd5472RestoreState(0);  /* turns off 5472 */
  143.  
  144.   iopl(3);
  145.   setRegs(textSeq,0x3c4,clgd5471SequencerRegs,clgd5471NumSequencerRegs);
  146.   setRegs(textGraph,0x3ce,clgd5471GraphicsRegs,clgd5471NumGraphicsRegs);
  147.  
  148.   inb(0x3c6);
  149.   inb(0x3c6);
  150.   inb(0x3c6);
  151.   inb(0x3c6);
  152.   outb(0x3c6,textMisc);
  153.   iopl(0);
  154. }
  155.  
  156. /*---------------------------------------------------------------------------*/
  157.  
  158. clgd5471Init()
  159. {
  160.   clgd5471VGAIOBase=(inb(0x3cc) & 0x01) ? 0x3d0 : 0x3b0;
  161. }
  162.  
  163.  
  164.