📄 s1.c
字号:
#include <stdlib.h>
#include <string.h>
#include <bios.h>
#include <dos.h>
#include <stdio.h>
#include <conio.h>
/************************************************************************
The globle variable DogAddr indicates the first memory address ( range
0 to 199) of user area in the MicroDog when you make reading and/or writing
operations.The sum of DogAddr and DogBytes should not exceed 200.
************************************************************************/
short DogAddr;
/************************************************************************
The globle variable DogBytes indicates the number ( 1-200 ) of bytes in
the operation of reading/writing or convertion. The sum of DogAddr and
DogBytes should not exceed 200.
************************************************************************/
short DogBytes;
/************************************************************************
The globle variable DosPassword indicates the password in the MicroDog
(factory value is zero), used in the reading/writing/converting operation.
***********************************************************************/
unsigned long DogPassword;
/************************************************************************
The globle variable DogResult indicates the result of converting opera-
tion.
************************************************************************/
unsigned long DogResult;
/************************************************************************
The globle variable DogData indicates the pointer variable which poi-
nts to the data for operations .
************************************************************************/
void far * DogData;
/************************************************************************
The globle variable Cascade indicates the cascade serial .
************************************************************************/
unsigned char Cascade;
extern unsigned long far WriteDog(void);
extern unsigned long far ReadDog(void);
char filename[20];
FILE *fpe;
char buf[200];
char filename[20];
int x_flag,y_flag;
long x_count,y_count;
long x_c,y_c;
int x_ss,y_ss;
int old_de;
int light_status=0;
unsigned char mask=0;
int spds;
send_a_line();
get_a_line1();
delay1(long len);
delay2(long len);
delay3(long len);
send_a_step(int x,int y);
send_a_step1(int x_step,int y_step);
long de,de1;
int des;
int error_flag;
char bu[30]={"Tide SoftDog is OK!"},bv[30];
main()
{
int ret_code,ch,success,i,ret1;
long l;
fpe = fopen("c:\\jgs\\delay.txt","r");
if (fpe != NULL){
fscanf(fpe,"%d",&des);
fclose(fpe);
}
else
des = 500;
fpe = fopen("c:\\jgs\\delay.txt","w");
fprintf(fpe,"%d",des);
fclose(fpe);
// getch();
error_flag = 0;
DogBytes=19;
DogAddr=1;
DogData=bu;
// WriteDog();
DogBytes=19;
DogAddr=1;
DogData=bv;
// ReadDog();
bv[strlen(bu)] = 0;
// if (strcmp(bu,bv) != 0){
// error_flag = 1;
// }
// else{
error_flag = 0;
// }
outportb(0x378,0);
outportb(0x37a,1);
delay(2000);
printf("Now,Is Running.\n");
fpe = fopen("c:\\jgs\\setup1.fil","rb");
if (fpe == NULL){
printf("Cann't Found File: Setup1.fil!\n");
return;
}
ch = fgetc(fpe);
while ((ch != '$')&&(ch != EOF))
ch = fgetc(fpe);
if (ch == EOF)
de = 160;
else{
i = 0;
while ((ch != 10)&&(ch != 13)&&(ch != EOF)){
ch = fgetc(fpe);
buf[i++] = ch;
}
buf[i-1] = 0;
de = atoi(buf);
}
old_de = de;
fclose(fpe);
// printf("Please Input Your File Name To Send:\n");
// scanf("%s",filename);
strcpy(filename,"c:\\jgs\\test.23");
i = 0;
while (filename[i++] != '.');
filename[i-1] = 0;
if (filename[strlen(filename)-3] != '.')
strcat(filename,".23");
// strcpy(filename,"line.23");
again:
fpe = fopen(filename,"rb");
if (fpe == NULL){
printf("Cann't Find File: %s\n",filename);
return -1;
}
ret_code = get_a_line1();
success = 0;
if (ret_code == -1){
success = 1;
}
i = 0;
while (success == 0){
if (i == 10)
return -1;
send_a_line();
ret_code = get_a_line1();
if (ret_code == -1)
success = 1;
if (error_flag == 1){
i++;
}
if (kbhit()){
ch = getch();
if (ch == 0)
ch = getch();
if (ch == 27)
success = 1;
if (ch == ' '){
ch = inportb(0x378);
ch &= 0xef;
outportb(0x378,ch);
printf("Paused, Press Space Bar To Start!\n");
wait:
ch = getch();
if (ch == 0)
ch = getch();
if (ch == 27){
success = 1;
}
else{
if (ch != ' '){
if ((ch == 'h')||(ch == 'H')){
x_c = -x_count;
y_c = -y_count;
if (x_c > 0)
x_flag = 1;
else
x_flag = 0;
light_status = 0;
for (l=0;l<labs(x_c);l++)
send_a_step(1,0);
if (y_c > 0)
y_flag = 1;
else
y_flag = 0;
for (l=0;l<labs(y_c);l++)
send_a_step(0,1);
fclose(fpe);
printf("Now, Waiting for Restart\n");
ch = getch();
if (ch != 27)
goto again;
else
exit(-1);
}
goto wait;
}
else{
if (light_status == 1){
ch = inportb(0x378);
ch |= 0x10;
outportb(0x378,ch);
light_status = 1;
}
printf("Now, Restarting\n");
}
}
}
else{
if (ch == '+'){
de = de*0.95;
if (de < old_de/3)
de = old_de/3;
}
if (ch == '-')
de = de*1.05;
}
}
}
fclose(fpe);
outportb(0x378,0);
outportb(0x37a,0);
printf("End!\n");
// if (ch == 13)
// goto again;
}
get_a_line1()
{
int ch,i;
ch = fgetc(fpe);
i = 0;
while ((ch != EOF)&&(ch != 10)&&(ch != 13)){
buf[i++] = ch;
ch = fgetc(fpe);
}
buf[i] = 0;
if (ch != EOF){
ch = fgetc(fpe);
return 1;
}
else
return -1;
}
send_a_line()
{
int i,j,x_step,y_step,oldx,oldy,x,y,time1;
unsigned char ch,outch,mas;
float delay_time;
int ret1;
if (buf[0] != 'P'){
if (buf[0] == 'O'){
if ((buf[1] == ' ')&&(buf[2] == '0')){
ch = inportb(0x378);
ch &= 0xef;
outportb(0x378,ch);
light_status = 0;
delay(des);
}
else{
ch = inportb(0x378);
ch |= 0x10;
if ((buf[2] != '3')||(buf[3] != '2')){
mas = atoi(&(buf[1]));
mask = mas*8;
ch |= mask;
}
outportb(0x378,ch);
light_status = 1;
delay(des);
}
return -1;
}
else if (buf[0] == 'M'){
if ((buf[1] == '1')&&((buf[2] == 0)||(buf[2] == ' '))){
printf("Pause, Press Space Bar To Start!\n");
getch();
}
if ((buf[1] == '1')&&(buf[2] == '0'))
mask = 0xe0; // 111
if (buf[1] == '7')
mask = 0x60; // 011
if (buf[1] == '6')
mask = 0x90; // 101
if (buf[1] == '5')
mask = 0x20; // 001
if (buf[1] == '4')
mask = 0xd0; // 110
if (buf[1] == '3')
mask = 0x40; // 010
if ((buf[1] == '1')&&(buf[2] == '2'))
mask = 0x80; // 100
if ((buf[1] == '1')&&(buf[2] == '1'))
mask = 0; // 000
outch = mask;
if (light_status == 1){
outch |= 0x10;
}
else{
outch &= 0xef;
}
outch |= mask;
outportb(0x378,outch);
return -1;
}
else if (buf[0] == 'W'){
delay_time = atof(&(buf[1]));
time1 = delay_time;
delay(time1);
return -1;
}
}
if (buf[0] == 'P'){
x_step = atoi(&(buf[1]));
if (x_step > 0)
x_flag = 1;
else{
x_flag = 0;
x_step = -x_step;
}
i = 0;
while (buf[i] != ' ')
i ++;
y_step = atoi(&(buf[i]));
if (y_step > 0)
y_flag = 1;
else{
y_flag = 0;
y_step = -y_step;
}
oldx = 0;
oldy = 0;
for (j=0;j<51;j++){
x = (float)j*x_step/50.0+0.5;
y = (float)j*y_step/50.0+0.5;
if (x > oldx){
if (y > oldy){
send_a_step(1,1);
}
else{
send_a_step(1,0);
}
}
else{
if (y > oldy){
send_a_step(0,1);
}
else{
send_a_step(0,0);
}
}
oldx = x;
oldy = y;
}
return 1;
}
if (buf[0] == 'B'){
x_step = atoi(&(buf[1]));
if (x_step > 0)
x_flag = 1;
else{
x_flag = 0;
x_step = -x_step;
}
x_c = x_step;
i = 0;
while (buf[i] != ' ')
i ++;
y_step = atoi(&(buf[i]));
if (y_step > 0)
y_flag = 1;
else{
y_flag = 0;
y_step = -y_step;
}
i++;
while (buf[i] != ' ')
i ++;
spds = atoi(&(buf[i]));
if (spds == 0){
i ++;
i --;
}
de1 = de*50/spds;
for (j=0;j<y_step;j++){
send_a_step1(0,1);
}
return 1;
}
}
send_a_step(int x_step,int y_step)
{
unsigned char outch;
outch = 0;
if (x_flag == 1){
outch |= 1;
}
if (y_flag == 1){
outch |= 4;
}
if (x_step == 1){
if (y_step == 1){
outch |= 10;
}
else{
outch |= 2;
}
}
else{
if (y_step == 1){
outch |= 8;
}
}
if (light_status == 1){
outch |= 0x10;
}
else{
outch &= 0xef;
}
outch |= mask;
outportb(0x378,outch);
// outportb(0x378,5);
delay2(1);
outch = 0;
if (x_flag == 1){
outch |= 1;
}
if (y_flag == 1){
outch |= 4;
}
if (light_status == 1){
outch |= 0x10;
}
else{
outch &= 0xef;
}
outch |= mask;
outportb(0x378,outch);
delay2(10);
// delay1(4);
if (x_flag == 1)
x_count += x_step;
else
x_count -= x_step;
if (y_flag == 1)
y_count += y_step;
else
y_count -= y_step;
if (y_step == 1){
outch = 0;
if (y_flag == 1){
outch |= 4;
}
outch |= 8;
if (light_status == 1){
outch |= 0x10;
}
else{
outch &= 0xef;
}
outch |= mask;
outportb(0x378,outch);
delay2(1);
outch = 0;
if (y_flag == 1){
outch |= 4;
}
if (light_status == 1){
outch |= 0x10;
}
else{
outch &= 0xef;
}
outch |= mask;
outportb(0x378,outch);
delay2(10);
}
}
delay1(long len)
{
long i,j;
// for (i=0;i<len;i++)
// for (j=0;j<22;j++); //375
for (j=0;j<10;j++);
}
delay2(long len)
{
long i,j;
for (j=0;j<de;j++);
}
delay3(long len)
{
long i,j;
for (j=0;j<de1;j++);
}
send_a_step1(int x_step,int y_step)
{
unsigned char outch;
outch = 0;
if (x_flag == 1){
outch |= 2;
}
if (y_flag == 1){
outch |= 8;
}
if (x_step == 1){
if (y_step == 1){
outch |= 5;
}
else{
outch |= 1;
}
}
else{
if (y_step == 1){
outch |= 4;
}
}
if (light_status == 1){
outch |= 0x10;
}
else{
outch &= 0xef;
}
outch |= mask;
outportb(0x378,outch);
// outportb(0x378,5);
delay3(1);
outch = 0;
if (x_flag == 1){
outch |= 2;
}
if (y_flag == 1){
outch |= 8;
}
if (light_status == 1){
outch |= 0x10;
}
else{
outch &= 0xef;
}
outch |= mask;
outportb(0x378,outch);
delay3(10);
// delay1(4);
if (x_flag == 1)
x_count += x_step;
else
x_count -= x_step;
if (y_flag == 1)
y_count += y_step;
else
y_count -= y_step;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -