/*圖形函數庫圖形設備治理頭文件*/
/*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