static double SIN45=0.707106781186548;
unsigned gmode;
int CUR_PAGE=0,PAGEN;
int CUR_COLOR=15;
int SCANLENG,CUR_X,CUR_Y;
int SCREEN_WIDTH,SCREEN_HEIGHT;
int SVGAmodeNo;
unsigned Max_x=640,Max_y=480,Hi_Max_x=1280,vram=0,page;
struct type_1{
unsigned int offset;
int pageno;
};
union type_2 {
unsigned long addr;
type_1 O_P;
} dp;
union type_3 {
unsigned char far *ptr;
type_1 O_P;
} dptr={(unsigned char far *)0xa0000000}; //直接写屏指针
void savedac(int dacno,int num,unsigned char huge *addr)
{
unsigned vseg,voff;
vseg=FP_SEG(addr);
voff=FP_OFF(addr);
asm {
push es
mov ax,0x1017
mov bx,dacno
mov cx,num
mov es,vseg
mov dx,voff
int 0x10
pop es
}
}
void restoredac(int dacno,int num,unsigned char huge *addr)
{
unsigned vseg,voff;
vseg=FP_SEG(addr);
voff=FP_OFF(addr);
asm {
push es
mov ax,0x1012
mov bx,dacno
mov cx,num
mov es,vseg
mov dx,voff
int 0x10
pop es
}
}
void covert_pal(unsigned char (*dac)[3],unsigned char *covert)
{
int i,j,k,n,num,s,search,con[16][2],t=0;
long com[16],sum;
for (i=0;i<16;i++) com[i]=0xffffff;
for (i=0;i<255+16;i++)
for (j=i+1;(j>15) && (j<256+16);j++)
{
sum=0;
for (k=0;k<3;k++)
{
int tmp=dac[i][k]; tmp-=dac[j][k]; tmp*=tmp; sum+=tmp;
}
n=0;
for (k=1;k<16;k++) if (com[n]<com[k]) n=k;
if ((sum<com[n]))
{
for (k=0;k<16;k++) if (con[k][1]==j) break;
if(k==16)
{
com[n]=sum; con[n][0]=i; con[n][1]=j;
}
else
{
if (sum<com[k] && com[k]==0xffffff)
com[k]=sum; con[k][0]=i;
}
}
}
s=16; num=0;
for (i=0;i<256;i++)
{
n=0; search=i+16; t=1;
do
{
if (con[n][1]==search) {search=con[n][0]; n=0; t=0;}
else n++;
}
while (n<16);
if (t)
{
for (k=0;k<3;k++) dac[s][k]=dac[search][k];
for (k=0;k<16;k++)
{
if (con[k][1]==search) con[k][1]=s;
if (con[k][0]==search) con[k][0]=s;
}
search=s++;
}
covert[num++]=search;
}
}