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 >
Wrap
C/C++ Source or Header
|
1993-03-28
|
4KB
|
161 lines
// RevLcd: a LCS reverser for J3100SLVW (& T3300?)
//
// version 1.6 Mar. 28 1993
//
// version 1.1 Initial version
// version 1.2 Fix palette set trouble in 8 colour mode
// version 1.3 Skipped to much version with ROM's version.
// version 1.4 Support ROM ver 1.4A
// version 1.5 Has own palette
// version 1.6 CheckSUM routine was changed
//
// written by NoZomi Ytow
// Copyright(C) 1992, 1993 NoZomi Ytow
//
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 1, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#if defined __GNUC__
#include <asm/io.h>
#define inp inb_p
#define outp(port,value) outb_p((port),(value))
#define int_off()
#define int_on()
#else
#include <dos.h>
#include <int.h>
#endif
unsigned char readCMOS(unsigned char);
void writeCMOS(unsigned char port, unsigned char value);
void reverse(unsigned char);
unsigned char checkSum(void);
void setVideo(void);
unsigned char palette16LCD[]={
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x06, 0x05, 0x07, 0x07, 0x07, 0x07, 0x08, 0x08,
0x08, 0x09, 0x09, 0x09, 0x09, 0x09, 0x0A, 0x0A, 0x0A, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C, 0x0C,
0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F
};
unsigned char palette16CRT[]={
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05,
0x05, 0x05, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09,
0x09, 0x0A, 0x0A, 0x0A, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D,
0x0D, 0x0D, 0x0D, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F
};
unsigned char palette8[]={
0x00, 0x02, 0x02, 0x03, 0x03, 0x06, 0x06, 0x06, 0x09, 0x09, 0x0B, 0x0B, 0x0C, 0x0C, 0x0C, 0x0F
};
int main(void)
{
unsigned char diff = readCMOS(0x37)-checkSum();
reverse(diff);
if(diff != 5){
setVideo();
return readCMOS(0x3D)&1;
}
else
return (readCMOS(0x3D)&0x8) >> 7;
}
unsigned char checkSum(void)
{
unsigned short sum = 0;
for(int port = 0x38; port < 0x3f; port++)
sum += readCMOS(port);
return (char)(sum & 0xff);
}
inline void reverse(unsigned char diff)
{
if(diff != 5)
writeCMOS(0x3D, readCMOS(0x3D) ^ 1);
else
writeCMOS(0x3D, readCMOS(0x3D) ^ 0x8);
writeCMOS(0x37, checkSum() + diff);
}
unsigned char readCMOS(unsigned char port)
{
int_off();
outp(0x70,port);
unsigned char cmos = inp(0x71);
int_on();
return cmos;
}
void writeCMOS(unsigned char port, unsigned char value)
{
int_off();
outp(0x70,port);
outp(0x71, value);
int_on();
}
inline void setVideo(void)
{
unsigned char dispMode;
unsigned int palette,crtc;
unsigned char * palettePtr;
dispMode = (readCMOS(0x3C) & 3) | ( (readCMOS(0x3D) & 3) << 2);
int_off();
if(inp(0x3CC) & 1)
crtc = 0x3D4;
else
crtc = 0x3B4;
// outpw(crtc, 0xA634);
// outpw(crtc, 0x31);
// outpw(crtc, 0x3E);
// outp(0xE4,0xDA);
// outpw(0xE4, (((inp(0xE5) & 0xFB) | 0xB)<<8) |0xDA);
// outpw(crtc, 0x3D);
// outpw(crtc, 0x34);
// outpw(crtc, 0x3335);
// outpw(crtc, ((crtc & 0x40) << 3) | 0x3A);
// outpw(crtc, 0x35);
// unsigned int offset8Colours = offset + 0x80;
palettePtr = palette16LCD;
if(dispMode & 1) //external CRT ?
palettePtr = palette16CRT;
int upTo = 0x40;
for(int paletteNum = 0; paletteNum < upTo; paletteNum++){
palette = *palettePtr++;
if(dispMode & 8) // 8 colours
palette = *(palette8 + palette);
if(dispMode & 4) // if reverse
palette ^= 0xF;
outp(crtc++, 0x35);
outp(crtc--, 0x33);
outp(crtc++, 0x38);
outp(crtc--, paletteNum);
outpw(crtc, (palette<< 8)|0x39);
}
int_on();
}