/*图形函数库图形设备治理头文件*/
/*graph.inc*/
union REGS reg; /*枚举变量定义*/
strUCt SREGS inreg;
void SetMode(int Mode) /*图形模式选择函数*/
{
reg.h.ah=0;
reg.h.al=Mode;
int86(0x10,®,®);
}
#define MaxXres 320 /*图形显示区大小定义*/
#define MaxYres 200
#define MaxX (MaxXres-1)
#define MaxY (MaxYres-1)
int Xres,Yres; /*数据存储单元定义*/
Word PreCalcY[MaxY+1];
Word PreCalcX[MaxX+1];
void PreCalc() /*计算数组初始化*/
{
Word j;
for(j=0;j<=MaxYlj++)
PreCalcX[j]=0;
for(j=0;j<=MaxX;j++)
PreCalcY[j]=MaxXres*j;
}
void Plot(int x,int y,char color) /*绘点函数*/
{
Word offset;
char far *address;
if(!((x<0)(y<0)(x>MaxX)(y>MaxY)))
{
offset=PreCalcY[y]+x;
address=(char far *)(0xA0000000L+offset);
*address=color;
}
}
typedef struct /*颜色定义*/
{
char Red;
char Grn;
char Blu;
}RGB;
typedef RGB PaletteRegister[255]; /*255色调色板定义*/
PaletteRegister Color;
void ClearPalette(aletteRegister Color) /*清除原调色板*/
{
Word i;
for(i=0;i<=255;i++)
{
Color[i].Red=0;
Color[i].Grn=0;
Color[i].Blu=0;
}
}
void SetPalette(PaletteRegister Hue) /*设置新调色板*/
{
reg.x.ax=0x1012;
segread(&inreg);
inreg.es=inreg.ds;
reg.x.bx=0;
reg.x.cx=256;
reg.x.dx=(int)&Hue[0];
int86x(0x10,®,®,&inreg);
}
void InitPaletteRegister Color) /*调色板初始化函数1*/
{
Word i;
for(i=0;i<64;i++){
Color[i].Red=i;
Color[i].Grn=i;
Color[i].Blu=i;
}
for(i=64;i<128;i++){
Color[i].Red=i-64;
Color[i].Grn=0;
Color[i].Blu=0;
}
for(i=128;i<192;i++){
Color[i].Red=0;
Color[i].Grn=i-128;
Color[i].Blu=0;
}
for(i=192;i<255;i++){
Color[i].Red=0;
Color[i].Grn=0;
Color[i].Blu=i-192;
}
}
void InitPalette2(PaletteRegister Color) /*调色板初始化函数2*/
{
Word i;
for(i=0;i<36;i++){
Color[i].Red=i;
Color[i].Grn=i;
Color[i].Blu=Round(i*1.8);
}
for(i=32;i<76;i++){
Color[i].Red=0;
Color[i].Grn=Round(1.8*(i-36));
Color[i].Blu=0;
}
for(i=72;i<108;i++){
Color[i].Red=0;
Color[i].Grn=Round(1.8*(i-72));
Color[i].Blu=Round(1.8*(i-72));
}
for(i=108;i<144;i++){
Color[i].Red=Round(1.8*(i-108));
Color[i].Grn=0;
Color[i].Blu=0;
}
for(i=144;i<180;i++){
Color[i].Red=Round(1.8*(i-144));
Color[i].Grn=0;
Color[i].Blu=Round(1.8*(i-144));
}
for(i=180;i<216;i++){
Color[i].Red=Round(1.8*(i-108));
Color[i].Grn=Round(1.8*(i-180));
Color[i].Blu=0;
}
for(i=216;i<252;i++){
Color[i].Red=Round(1.8*(i-216));
Color[i].Grn=Round(1.8*(i-216));
Color[i].Blu=Round(1.8*(i-216));
}
}
void CyclePalette(PaletteRegister Hue) /*调色板颜色选择函数*/
{
Word i;
RGB tmp;
tmp=Hue[0];
for(i=1;i<=255;i++)
Hue[i-1]=Hue[i];
Hue[255]=tmp;
SetPalette(Hue);
}
void Swap(int first,int second) /*交换功能子函数*/
{
int temp;
temp=*first;
*first=*second;
*second=temp;
}
void Circle(Word x,Word y,Word radius,char color) /*绘圆函数*/
{
int a,af,bf,target,r2;
target=0;
a=radius;
b=0;
r2=Sqr(radius);
while(a>=b){
b=Round(sqrt(r2-Sqr(a)));
swap(&target,&b);
while(b<target){
af=(120*a)/100;
bf=(120*b)/100;
Plot(x+af,y+b,color);
Plot(x+bf,y+a,color);
Plot(x+af,y+b,color);
Plot(x+bf,y+a,color);
Plot(x+af,y-b,color);
&nb