home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / r / revlcd16.zip / REVLCD.CPP < prev    next >
C/C++ Source or Header  |  1993-03-28  |  4KB  |  161 lines

  1. // RevLcd: a LCS reverser for J3100SLVW (& T3300?)
  2. //
  3. //   version 1.6  Mar. 28 1993
  4. //
  5. //   version 1.1  Initial version
  6. //   version 1.2  Fix palette set trouble in 8 colour mode
  7. //   version 1.3  Skipped to much version with ROM's version.
  8. //   version 1.4  Support ROM ver 1.4A
  9. //   version 1.5  Has own palette
  10. //   version 1.6  CheckSUM routine was changed
  11. //                
  12. //    written by NoZomi Ytow
  13. //    Copyright(C) 1992, 1993 NoZomi Ytow
  14. //
  15. //
  16. //    This program is free software; you can redistribute it and/or modify
  17. //    it under the terms of the GNU General Public License as published by
  18. //    the Free Software Foundation; either version 1, or (at your option)
  19. //    any later version.
  20. //    
  21. //    This program is distributed in the hope that it will be useful,
  22. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. //    GNU General Public License for more details.
  25. //    
  26. //    You should have received a copy of the GNU General Public License
  27. //    along with this program; if not, write to the Free Software
  28. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29.  
  30. #if defined __GNUC__
  31.  
  32.     #include    <asm/io.h>
  33.     #define inp inb_p
  34.     #define outp(port,value) outb_p((port),(value))
  35.     #define int_off() 
  36.     #define int_on() 
  37.  
  38. #else
  39.  
  40.     #include    <dos.h>
  41.     #include    <int.h>
  42.  
  43. #endif
  44.  
  45. unsigned char readCMOS(unsigned char);
  46. void writeCMOS(unsigned char port, unsigned char value);
  47. void reverse(unsigned char);
  48. unsigned char checkSum(void);
  49. void setVideo(void);
  50.  
  51. unsigned char palette16LCD[]={
  52.         0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
  53.         0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x06, 0x05, 0x07, 0x07, 0x07, 0x07, 0x08, 0x08,
  54.         0x08, 0x09, 0x09, 0x09, 0x09, 0x09, 0x0A, 0x0A, 0x0A, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C, 0x0C,
  55.         0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F
  56.         };
  57.  
  58. unsigned char palette16CRT[]={
  59.         0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05,
  60.         0x05, 0x05, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09,
  61.         0x09, 0x0A, 0x0A, 0x0A, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D,
  62.         0x0D, 0x0D, 0x0D, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F
  63.         };
  64.  
  65. unsigned char palette8[]={
  66.         0x00, 0x02, 0x02, 0x03, 0x03, 0x06, 0x06, 0x06, 0x09, 0x09, 0x0B, 0x0B, 0x0C, 0x0C, 0x0C, 0x0F
  67.         };
  68.  
  69. int main(void)
  70. {
  71.     unsigned char diff = readCMOS(0x37)-checkSum();
  72.     reverse(diff);
  73.     if(diff != 5){
  74.         setVideo();
  75.         return readCMOS(0x3D)&1;
  76.     }
  77.     else
  78.         return (readCMOS(0x3D)&0x8) >> 7;
  79. }
  80.  
  81. unsigned char checkSum(void)
  82. {
  83.     unsigned short sum = 0;
  84.     for(int port = 0x38; port < 0x3f; port++)
  85.         sum += readCMOS(port);
  86.     return (char)(sum & 0xff);
  87. }
  88.  
  89. inline void reverse(unsigned char diff)
  90. {
  91.     if(diff != 5)
  92.         writeCMOS(0x3D, readCMOS(0x3D) ^ 1);
  93.     else
  94.         writeCMOS(0x3D, readCMOS(0x3D) ^ 0x8);
  95.     writeCMOS(0x37, checkSum() + diff);
  96. }
  97.  
  98. unsigned char readCMOS(unsigned char port)
  99. {
  100.     int_off();
  101.     outp(0x70,port);
  102.     unsigned char cmos = inp(0x71);
  103.     int_on();
  104.     return cmos;
  105. }
  106.  
  107. void writeCMOS(unsigned char port, unsigned char value)
  108. {
  109.     int_off();
  110.     outp(0x70,port);
  111.     outp(0x71, value);
  112.     int_on();
  113. }
  114.  
  115. inline void setVideo(void)
  116. {
  117.     unsigned char dispMode;
  118.     unsigned int palette,crtc;
  119.     unsigned char * palettePtr;
  120.     dispMode = (readCMOS(0x3C) & 3) | ( (readCMOS(0x3D) & 3) << 2);
  121.     int_off();
  122.     if(inp(0x3CC) & 1)
  123.         crtc = 0x3D4;
  124.     else
  125.         crtc = 0x3B4;
  126.         
  127. //        outpw(crtc, 0xA634);
  128. //        outpw(crtc, 0x31);
  129. //        outpw(crtc, 0x3E);
  130. //        outp(0xE4,0xDA);
  131. //        outpw(0xE4, (((inp(0xE5) & 0xFB) | 0xB)<<8) |0xDA);
  132. //        outpw(crtc, 0x3D);
  133. //        outpw(crtc, 0x34);
  134. //        outpw(crtc, 0x3335);
  135. //        outpw(crtc, ((crtc & 0x40) << 3) | 0x3A);
  136. //        outpw(crtc, 0x35);
  137. //    unsigned int offset8Colours = offset + 0x80;
  138.  
  139.     palettePtr = palette16LCD;
  140.     if(dispMode & 1)    //external CRT ?
  141.         palettePtr = palette16CRT;
  142.     
  143.     int upTo = 0x40;
  144.     
  145.     for(int paletteNum = 0; paletteNum < upTo; paletteNum++){
  146.         palette = *palettePtr++;
  147.         if(dispMode & 8)    // 8 colours
  148.             palette = *(palette8 + palette);
  149.         
  150.         if(dispMode & 4)    // if reverse
  151.             palette ^= 0xF;
  152.         
  153.         outp(crtc++, 0x35);
  154.         outp(crtc--, 0x33);
  155.         outp(crtc++, 0x38);
  156.         outp(crtc--, paletteNum);
  157.         outpw(crtc, (palette<< 8)|0x39);
  158.     }
  159.     int_on();
  160. }
  161.