主题:一个海龟作图程序在tc3.0不能运行,为什么?
下面是程序应该是正确的,但是在tc3.0上不能运行
#include "graphics.h"
#include "math.h"
#include "stdio.h"
#include "conio.h"
#include "bios.h"
#include "dos.h"
#include "io.h"
char key_state[128],key_pressed[128];
void interrupt far (*OldInt9Handler)();
enum modes {AUTO, HIGH};
enum bool {FALSE=0, TRUE=1};
#define MODE enum modes
#define BOOL enum bool
#define K_ENTER 0x1c
#define K_DOWN 0x50
#define K_UP 0x48
#define K_SPACE 0x39
#define K_ESC 0x01
#define K_C 0x2e
#define K_A 0x1e
#define K_X 0x2d
#define UP 0
#define DOWN 1
#define PI 3.1415
#define MODE_KEY 0
#define MODE_CMD 1
#define MAX_CMD_NUM 15
/*Instruction define*/
#define EXIT 0
#define CHM 1
#define PU 2
#define PD 3
#define CHC 4
#define CHHT 5
#define ADTH 6
#define FW 7
#define BW 8
#define CLR 9
#define CHP 10
enum hlpmsg{ALL_CMD, IN_ERROR, PU_OK, PD_OK, CHC_OK, CHP_OK, CHM_OK,
FW_OK, BW_OK, CHHT_OK, ADTH_OK, CLR_OK, M_KEY, IN_COLOR,
IN_POS, IN_HEAD, IN_STEPS};
#define HLPMSG enum hlpmsg
typedef int penState;
typedef struct{float v,h;}aPoint;
typedef struct
{
float heading;
penState pen;
int color;
aPoint Pos;
}newTurtle;
newTurtle turtle;
char GMODE=MODE_CMD;
char CmdWords[MAX_CMD_NUM][4]={
{'E', 'X', 'I', 'T'}, {'C', 'H', 'M', ' '},
{'P', 'U', ' ', ' '}, {'P', 'D', ' ', ' '},
{'C', 'H', 'C', ' '}, {'C', 'H', 'H', 'T'},
{'A', 'D', 'T', 'H'}, {'F', 'W', ' ', ' '},
{'B', 'W', ' ', ' '}, {'C', 'L', 'R', ' '},
{'C', 'H', 'P', ' '},
};
char CmdTmp[4];
unsigned char NumTmp[4];
unsigned char NumTmp1[4];
typedef struct node
{
int color;
int x1, x2, y1, y2;
}NODE;
/*---------------------------------------*/
/*other functions*/
void OpenSecCmdWnd()
{
setcolor(2);
rectangle(510, 250, 595, 275);
while(bioskey(1)==0)
{
setcolor(2);
line(513, 270, 518, 270);
setcolor(0);
line(513, 270, 518, 270);
}
window(66, 17, 66, 17);
}
void CloseSecCmdWnd()
{
setfillstyle(SOLID_FILL, 0);
bar(511, 250, 595, 275);
}
int Cvt4CToInt(int i)
{
if(i==0)
return NumTmp[0]+NumTmp[1]*10+NumTmp[2]*100+NumTmp[3]*1000-53328;
else
return NumTmp1[0]+NumTmp1[1]*10+NumTmp1[2]*100+NumTmp1[3]*1000-53328;
}
int GetAn4BInterger()
{
int i, j;
union REGS regs;
unsigned char t;
regs.h.ah=0x07;
IN_AGAIN:
for(i=0;i<4;i++)
NumTmp[i]=48;
for(i=0;i<4;i++)
{
IN:
while(bioskey(1)==0) {;};
if(bioskey(1)==0x1c0d)
{ bioskey(0); goto OUT;}
int86(0x21, ®s, ®s);
t=regs.h.al;
if(t>57 || t<48) goto IN;
else
{
for(j=3;j>0;j--)
NumTmp[j]=NumTmp[j-1];
NumTmp[0]=t;
printf("%c", t);
}
}
while(bioskey(1)==0) {;}
if(bioskey(1)!=0x1c0d)
{
bioskey(0);
CloseSecCmdWnd();
OpenSecCmdWnd();
goto IN_AGAIN;
}
OUT:
return Cvt4CToInt(0);
}
void StoreTwo4BInterger()
{
int i, j;
union REGS regs;
unsigned char t;
regs.h.ah=0x07;
IN_AGAIN1:
for(i=0;i<4;i++)
{
NumTmp[i]=48;
NumTmp1[i]=48;
}
for(i=0;i<4;i++)
{
IN1:
while(bioskey(1)==0) {;};
if(bioskey(1)==0x1c0d)
{ bioskey(0); goto OVER;}
int86(0x21, ®s, ®s);
t=regs.h.al;
if(t==44)
{
printf("%c", t);
goto OUT1;
}
if(t>57 || t<48) goto IN1;
else
{
for(j=3;j>0;j--)
NumTmp[j]=NumTmp[j-1];
NumTmp[0]=t;
printf("%c", t);
}
}
while(bioskey(1)==0) {;}
if(bioskey(1)!=0x1c0d)
{
int86(0x21, ®s, ®s);
t=regs.h.al;
if(t==44)
{
printf("%c", t);
goto OUT1;
}
CloseSecCmdWnd();
OpenSecCmdWnd();
goto IN_AGAIN1;
}
OUT1:
for(i=0;i<4;i++)
NumTmp1[i]=48;
for(i=0;i<4;i++)
{
IN2:
while(bioskey(1)==0) {;};
if(bioskey(1)==0x1c0d)
{ bioskey(0); goto OVER;}
int86(0x21, ®s, ®s);
t=regs.h.al;
if(t>57 || t<48) goto IN2;
else
{
for(j=3;j>0;j--)
NumTmp1[j]=NumTmp1[j-1];
NumTmp1[0]=t;
printf("%c", t);
}
}
while(bioskey(1)==0) {;}
if(bioskey(1)!=0x1c0d)
{
bioskey(0);
CloseSecCmdWnd();
OpenSecCmdWnd();
goto IN_AGAIN1;
}
OVER: ;
}
void far interrupt NewInt9(void)
{
unsigned char ScanCode,temp;
ScanCode=inportb(0x60);
temp=inportb(0x61);
outportb(0x61,temp | 0x80);
outportb(0x61,temp & 0x7f);
if(ScanCode&0x80)
{
ScanCode&=0x7f;
key_state[ScanCode]=0;
}
else
{
key_state[ScanCode]=1;
key_pressed[ScanCode]=1;
}
outportb(0x20,0x20);
};
void InstallKeyboard(void)
{
int i;
for(i=0;i<128;i++)
key_state[i]=key_pressed[i]=0;
OldInt9Handler=getvect(9);
setvect(9,NewInt9);
}
void ShutDownKeyboard(void)
{
setvect(9,OldInt9Handler);
}
int GetKey(int ScanCode)
{
int res;
res=key_state[ScanCode]|key_pressed[ScanCode];
key_pressed[ScanCode]=0;
return res;
}
void InitMyGraph(MODE m)
{
int graphdriver, graphmode;
if(m==AUTO)
graphdriver=DETECT;
else if(m==HIGH)
{
graphdriver=VGA;
graphmode=VGAHI;
}
else
{
printf("Wrong prameter of \"init_mygraph();\"");
return ;
}
/*registerbgidriver(EGAVGA_driver);*/
initgraph(&graphdriver, &graphmode, "");
};
int GetKey1()
{
union REGS rg;
rg.h.ah=0;
int86(0x16, &rg, &rg);
return rg.h.ah;
};
void InputNote()
{
while(bioskey(1)==0)
{
setcolor(9);
line(467, 270, 472, 270);
setcolor(0);
line(467, 270, 472, 270);
}
}
void GetACmd()
{
int i, j;
window(60, 17, 60, 17);
InputNote();
for(i=0;i<4;i++)
{
AGAIN:
while(bioskey(1)==0)
{};
if(bioskey(1)==0x0f09) {bioskey(0); goto AGAIN;}
if(bioskey(1)==0x0e08) {bioskey(0); goto AGAIN;}
if(bioskey(1)==0x1c0d)
{
for(;i<4;i++) CmdTmp[i]=' ';
break;
};
CmdTmp[i]=getch();
printf("%c", CmdTmp[i]);
}
}
int DecideCmd()
{
int i, j, r=MAX_CMD_NUM;
for(i=0;i<MAX_CMD_NUM;i++)
{
if(CmdWords[i][0]==CmdTmp[0])
{
r=i;
for(j=1;j<4;j++)
{
if(CmdWords[i][j]!=CmdTmp[j])
{
r=MAX_CMD_NUM;
break;
}
}
}
if(r!=MAX_CMD_NUM) break;
}
return r;
}
/*display the turtle to every prameter of its own*/
void DisTurtle()
{
float x, y, h, v, x1, y1;
circle(turtle.Pos.h-8, turtle.Pos.v, 4);
circle(turtle.Pos.h+8, turtle.Pos.v, 4);
circle(turtle.Pos.h, turtle.Pos.v+8, 4);
circle(turtle.Pos.h, turtle.Pos.v-8, 4);
circle(turtle.Pos.h, turtle.Pos.v, 15);
h=18*cos(turtle.heading*PI/180);
v=18*sin(turtle.heading*PI/180);
x=turtle.Pos.h+h;
y=turtle.Pos.v-v;
circle(x, y, 3);
x=turtle.Pos.h-h;
y=turtle.Pos.v+v;
x1=turtle.Pos.h-15*cos(turtle.heading*PI/180+PI/45);
y1=turtle.Pos.v+15*sin(turtle.heading*PI/180+PI/45);
line(x, y, x1, y1);
x1=turtle.Pos.h-15*cos(turtle.heading*PI/180-PI/45);
y1=turtle.Pos.v+15*sin(turtle.heading*PI/180-PI/45);
line(x, y, x1, y1);
}
void DisHelpMenu()
{
setcolor(2);
outtextxy(465, 55, "HELP:");
outtextxy(465, 300, "TURTLE STATE:");
outtextxy(465, 240, "STRUCTION INPUT:");
rectangle(465, 250, 510, 275);
}
void DisTState()
{
setfillstyle(SOLID_FILL, 8);
bar(465, 310, 595, 445);
setcolor(1);
outtextxy(480, 315, "Pen:");
outtextxy(480, 328, "GMode:");
outtextxy(480, 341, "Color:");
outtextxy(480, 353, "Heading:");
outtextxy(480, 365, "Position");
outtextxy(490, 377, "x:");
outtextxy(490, 389, "y:");
outtextxy(480, 401, "X Range:");
outtextxy(480, 422, "Y Range;");
setcolor(7);
outtextxy(520, 413, "0 ~ 360");
outtextxy(520, 435, "0 ~ 350");
}
void RenovateTState()
{
char* t;
setfillstyle(SOLID_FILL, 0);
bar(520, 315, 599, 322);
setcolor(7);
if(turtle.pen==UP)
outtextxy(520, 315, "UP ");
else
outtextxy(520, 315, "DOWN");
bar(536, 328, 599, 335);
if(GMODE==MODE_KEY)
outtextxy(536, 328, "Key");
else
outtextxy(536, 328, "Command");
bar(550, 353, 599, 360);
sprintf(t, "%.1f", turtle.heading);
outtextxy(550, 353, t);
bar(515, 377, 599, 384);
sprintf(t, "%.2f", turtle.Pos.h-65);
outtextxy(515, 377, t);
bar(515, 389, 599, 396);
sprintf(t, "%.2f", turtle.Pos.v-75);
outtextxy(515, 389, t);
setfillstyle(SOLID_FILL, turtle.color);
bar(536, 341, 590, 348);
if(turtle.color==8)
{
setcolor(7);
rectangle(536, 341, 590, 348);
}
}
int GetAColor()
{
int c;
OpenSecCmdWnd();
c=GetAn4BInterger();
return c;
}
#include "graphics.h"
#include "math.h"
#include "stdio.h"
#include "conio.h"
#include "bios.h"
#include "dos.h"
#include "io.h"
char key_state[128],key_pressed[128];
void interrupt far (*OldInt9Handler)();
enum modes {AUTO, HIGH};
enum bool {FALSE=0, TRUE=1};
#define MODE enum modes
#define BOOL enum bool
#define K_ENTER 0x1c
#define K_DOWN 0x50
#define K_UP 0x48
#define K_SPACE 0x39
#define K_ESC 0x01
#define K_C 0x2e
#define K_A 0x1e
#define K_X 0x2d
#define UP 0
#define DOWN 1
#define PI 3.1415
#define MODE_KEY 0
#define MODE_CMD 1
#define MAX_CMD_NUM 15
/*Instruction define*/
#define EXIT 0
#define CHM 1
#define PU 2
#define PD 3
#define CHC 4
#define CHHT 5
#define ADTH 6
#define FW 7
#define BW 8
#define CLR 9
#define CHP 10
enum hlpmsg{ALL_CMD, IN_ERROR, PU_OK, PD_OK, CHC_OK, CHP_OK, CHM_OK,
FW_OK, BW_OK, CHHT_OK, ADTH_OK, CLR_OK, M_KEY, IN_COLOR,
IN_POS, IN_HEAD, IN_STEPS};
#define HLPMSG enum hlpmsg
typedef int penState;
typedef struct{float v,h;}aPoint;
typedef struct
{
float heading;
penState pen;
int color;
aPoint Pos;
}newTurtle;
newTurtle turtle;
char GMODE=MODE_CMD;
char CmdWords[MAX_CMD_NUM][4]={
{'E', 'X', 'I', 'T'}, {'C', 'H', 'M', ' '},
{'P', 'U', ' ', ' '}, {'P', 'D', ' ', ' '},
{'C', 'H', 'C', ' '}, {'C', 'H', 'H', 'T'},
{'A', 'D', 'T', 'H'}, {'F', 'W', ' ', ' '},
{'B', 'W', ' ', ' '}, {'C', 'L', 'R', ' '},
{'C', 'H', 'P', ' '},
};
char CmdTmp[4];
unsigned char NumTmp[4];
unsigned char NumTmp1[4];
typedef struct node
{
int color;
int x1, x2, y1, y2;
}NODE;
/*---------------------------------------*/
/*other functions*/
void OpenSecCmdWnd()
{
setcolor(2);
rectangle(510, 250, 595, 275);
while(bioskey(1)==0)
{
setcolor(2);
line(513, 270, 518, 270);
setcolor(0);
line(513, 270, 518, 270);
}
window(66, 17, 66, 17);
}
void CloseSecCmdWnd()
{
setfillstyle(SOLID_FILL, 0);
bar(511, 250, 595, 275);
}
int Cvt4CToInt(int i)
{
if(i==0)
return NumTmp[0]+NumTmp[1]*10+NumTmp[2]*100+NumTmp[3]*1000-53328;
else
return NumTmp1[0]+NumTmp1[1]*10+NumTmp1[2]*100+NumTmp1[3]*1000-53328;
}
int GetAn4BInterger()
{
int i, j;
union REGS regs;
unsigned char t;
regs.h.ah=0x07;
IN_AGAIN:
for(i=0;i<4;i++)
NumTmp[i]=48;
for(i=0;i<4;i++)
{
IN:
while(bioskey(1)==0) {;};
if(bioskey(1)==0x1c0d)
{ bioskey(0); goto OUT;}
int86(0x21, ®s, ®s);
t=regs.h.al;
if(t>57 || t<48) goto IN;
else
{
for(j=3;j>0;j--)
NumTmp[j]=NumTmp[j-1];
NumTmp[0]=t;
printf("%c", t);
}
}
while(bioskey(1)==0) {;}
if(bioskey(1)!=0x1c0d)
{
bioskey(0);
CloseSecCmdWnd();
OpenSecCmdWnd();
goto IN_AGAIN;
}
OUT:
return Cvt4CToInt(0);
}
void StoreTwo4BInterger()
{
int i, j;
union REGS regs;
unsigned char t;
regs.h.ah=0x07;
IN_AGAIN1:
for(i=0;i<4;i++)
{
NumTmp[i]=48;
NumTmp1[i]=48;
}
for(i=0;i<4;i++)
{
IN1:
while(bioskey(1)==0) {;};
if(bioskey(1)==0x1c0d)
{ bioskey(0); goto OVER;}
int86(0x21, ®s, ®s);
t=regs.h.al;
if(t==44)
{
printf("%c", t);
goto OUT1;
}
if(t>57 || t<48) goto IN1;
else
{
for(j=3;j>0;j--)
NumTmp[j]=NumTmp[j-1];
NumTmp[0]=t;
printf("%c", t);
}
}
while(bioskey(1)==0) {;}
if(bioskey(1)!=0x1c0d)
{
int86(0x21, ®s, ®s);
t=regs.h.al;
if(t==44)
{
printf("%c", t);
goto OUT1;
}
CloseSecCmdWnd();
OpenSecCmdWnd();
goto IN_AGAIN1;
}
OUT1:
for(i=0;i<4;i++)
NumTmp1[i]=48;
for(i=0;i<4;i++)
{
IN2:
while(bioskey(1)==0) {;};
if(bioskey(1)==0x1c0d)
{ bioskey(0); goto OVER;}
int86(0x21, ®s, ®s);
t=regs.h.al;
if(t>57 || t<48) goto IN2;
else
{
for(j=3;j>0;j--)
NumTmp1[j]=NumTmp1[j-1];
NumTmp1[0]=t;
printf("%c", t);
}
}
while(bioskey(1)==0) {;}
if(bioskey(1)!=0x1c0d)
{
bioskey(0);
CloseSecCmdWnd();
OpenSecCmdWnd();
goto IN_AGAIN1;
}
OVER: ;
}
void far interrupt NewInt9(void)
{
unsigned char ScanCode,temp;
ScanCode=inportb(0x60);
temp=inportb(0x61);
outportb(0x61,temp | 0x80);
outportb(0x61,temp & 0x7f);
if(ScanCode&0x80)
{
ScanCode&=0x7f;
key_state[ScanCode]=0;
}
else
{
key_state[ScanCode]=1;
key_pressed[ScanCode]=1;
}
outportb(0x20,0x20);
};
void InstallKeyboard(void)
{
int i;
for(i=0;i<128;i++)
key_state[i]=key_pressed[i]=0;
OldInt9Handler=getvect(9);
setvect(9,NewInt9);
}
void ShutDownKeyboard(void)
{
setvect(9,OldInt9Handler);
}
int GetKey(int ScanCode)
{
int res;
res=key_state[ScanCode]|key_pressed[ScanCode];
key_pressed[ScanCode]=0;
return res;
}
void InitMyGraph(MODE m)
{
int graphdriver, graphmode;
if(m==AUTO)
graphdriver=DETECT;
else if(m==HIGH)
{
graphdriver=VGA;
graphmode=VGAHI;
}
else
{
printf("Wrong prameter of \"init_mygraph();\"");
return ;
}
/*registerbgidriver(EGAVGA_driver);*/
initgraph(&graphdriver, &graphmode, "");
};
int GetKey1()
{
union REGS rg;
rg.h.ah=0;
int86(0x16, &rg, &rg);
return rg.h.ah;
};
void InputNote()
{
while(bioskey(1)==0)
{
setcolor(9);
line(467, 270, 472, 270);
setcolor(0);
line(467, 270, 472, 270);
}
}
void GetACmd()
{
int i, j;
window(60, 17, 60, 17);
InputNote();
for(i=0;i<4;i++)
{
AGAIN:
while(bioskey(1)==0)
{};
if(bioskey(1)==0x0f09) {bioskey(0); goto AGAIN;}
if(bioskey(1)==0x0e08) {bioskey(0); goto AGAIN;}
if(bioskey(1)==0x1c0d)
{
for(;i<4;i++) CmdTmp[i]=' ';
break;
};
CmdTmp[i]=getch();
printf("%c", CmdTmp[i]);
}
}
int DecideCmd()
{
int i, j, r=MAX_CMD_NUM;
for(i=0;i<MAX_CMD_NUM;i++)
{
if(CmdWords[i][0]==CmdTmp[0])
{
r=i;
for(j=1;j<4;j++)
{
if(CmdWords[i][j]!=CmdTmp[j])
{
r=MAX_CMD_NUM;
break;
}
}
}
if(r!=MAX_CMD_NUM) break;
}
return r;
}
/*display the turtle to every prameter of its own*/
void DisTurtle()
{
float x, y, h, v, x1, y1;
circle(turtle.Pos.h-8, turtle.Pos.v, 4);
circle(turtle.Pos.h+8, turtle.Pos.v, 4);
circle(turtle.Pos.h, turtle.Pos.v+8, 4);
circle(turtle.Pos.h, turtle.Pos.v-8, 4);
circle(turtle.Pos.h, turtle.Pos.v, 15);
h=18*cos(turtle.heading*PI/180);
v=18*sin(turtle.heading*PI/180);
x=turtle.Pos.h+h;
y=turtle.Pos.v-v;
circle(x, y, 3);
x=turtle.Pos.h-h;
y=turtle.Pos.v+v;
x1=turtle.Pos.h-15*cos(turtle.heading*PI/180+PI/45);
y1=turtle.Pos.v+15*sin(turtle.heading*PI/180+PI/45);
line(x, y, x1, y1);
x1=turtle.Pos.h-15*cos(turtle.heading*PI/180-PI/45);
y1=turtle.Pos.v+15*sin(turtle.heading*PI/180-PI/45);
line(x, y, x1, y1);
}
void DisHelpMenu()
{
setcolor(2);
outtextxy(465, 55, "HELP:");
outtextxy(465, 300, "TURTLE STATE:");
outtextxy(465, 240, "STRUCTION INPUT:");
rectangle(465, 250, 510, 275);
}
void DisTState()
{
setfillstyle(SOLID_FILL, 8);
bar(465, 310, 595, 445);
setcolor(1);
outtextxy(480, 315, "Pen:");
outtextxy(480, 328, "GMode:");
outtextxy(480, 341, "Color:");
outtextxy(480, 353, "Heading:");
outtextxy(480, 365, "Position");
outtextxy(490, 377, "x:");
outtextxy(490, 389, "y:");
outtextxy(480, 401, "X Range:");
outtextxy(480, 422, "Y Range;");
setcolor(7);
outtextxy(520, 413, "0 ~ 360");
outtextxy(520, 435, "0 ~ 350");
}
void RenovateTState()
{
char* t;
setfillstyle(SOLID_FILL, 0);
bar(520, 315, 599, 322);
setcolor(7);
if(turtle.pen==UP)
outtextxy(520, 315, "UP ");
else
outtextxy(520, 315, "DOWN");
bar(536, 328, 599, 335);
if(GMODE==MODE_KEY)
outtextxy(536, 328, "Key");
else
outtextxy(536, 328, "Command");
bar(550, 353, 599, 360);
sprintf(t, "%.1f", turtle.heading);
outtextxy(550, 353, t);
bar(515, 377, 599, 384);
sprintf(t, "%.2f", turtle.Pos.h-65);
outtextxy(515, 377, t);
bar(515, 389, 599, 396);
sprintf(t, "%.2f", turtle.Pos.v-75);
outtextxy(515, 389, t);
setfillstyle(SOLID_FILL, turtle.color);
bar(536, 341, 590, 348);
if(turtle.color==8)
{
setcolor(7);
rectangle(536, 341, 590, 348);
}
}
int GetAColor()
{
int c;
OpenSecCmdWnd();
c=GetAn4BInterger();
return c;
}