请你翻译C------>>DELPHI :)(300分)

  • 主题发起人 主题发起人 zhaohai9
  • 开始时间 开始时间
Z

zhaohai9

Unregistered / Unconfirmed
GUEST, unregistred user!
第一个:
/********************************************************/
/* */
/* File name: ps_cucr.c */
/* Date : 10/5/1995 */
/* Object : Program with communication board */
/* Command : ps_cucr [station number] [frame type] */
/* */
/********************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <io.h>
#include <time.h>
#include <conio.h>

int cuc_read(int addr,int sta_num,int frame_type);
int htoi(char *s);
int btoi(char *s);

char rec[100];
int aii[100];

int main(int argc,char *argv[])
{
int i,A8255,num=1;
clrscr();
if(argc < 4)
{ printf("/nError: Parameter is wrong./n");
printf("Example: ps_cucr [sta_num] [frame_num].");
goto end; }
sscanf(argv[1],"%x",&amp;A8255);
start:
gotoxy(5,1);
printf("num=%d",num);
if(cuc_read(A8255,atoi(argv[2]),atoi(argv[3])) == -1) printf("Execute failure./n");
else
{
if (atoi(argv[3]) == 0)
{
for(i = 1; i < 11; i ++)
{
gotoxy(5, 12 + i);
printf("aii[%2d]=%5u", i, aii);
gotoxy(30, 12 + i);
printf("aii[%2d]=%5u", i+10, aii[i+10]);
gotoxy(55, 12 + i);
printf("aii[%2d]=%5u", i+20, aii[i+20]);
}
}
else
{
for(i = 1; i < 11; i ++)
{
gotoxy(5, 12 + i);
printf("aii[%2d]=%4d", i, aii);
gotoxy(30, 12 + i);
printf("aii[%2d]=%4d", i+10, aii[i+10]);
gotoxy(55, 12 + i);
printf("aii[%2d]=%4d", i+20, aii[i+20]);
}
}
delay(5000);num++;
if ( kbhit() ) goto end;
else goto start;
}
end:;
return(0);
}

/* Read IEEE 485 communication board */
int cuc_read(addr,sta_num,frame_type)
int addr; /* Communication board address */
int sta_num; /* Station number */
int frame_type; /* The type of frame */
{
int i,k,log,w;
log=0;
loop1:
k=inportb(addr+2);
if((k &amp; 0x80) == 0) goto loop1;
outportb(addr,0x00); /* Send Command byte */
loop2:
k=inportb(addr+2);
if((k &amp; 0x80) == 0) goto loop2;
outportb(addr,0x03); /* Send command classic */
loop3:
k=inportb(addr+2);
if((k &amp; 0x80) == 0) goto loop3;
outportb(addr,sta_num); /* target station num */
loop4:
k=inportb(addr+2);
if((k &amp; 0x80) == 0) goto loop4;
outportb(addr,frame_type); /* frame_type */
loop5:
k=inportb(addr+2);
if((k &amp; 0x80) == 0) goto loop5;
outportb(addr,0xff); /* end type */
loop6:
k=inportb(addr+2);
if((k &amp; 0x80) == 0) goto loop6;
delay(3);
loop7:
k=inportb(addr+2);
if((k &amp; 0x20) == 0) goto loop7;
k=inportb(addr);
if ((k &amp; 0x00ff) == 0xff) goto loop7;
gotoxy(30,1);
printf("k= %x/n/n",k&amp;0x00ff);
if (k != 0x00) goto ini;
for(i = 0; i < 61; i ++ )
{
loop8:
k=inportb(addr+2);
if((k &amp; 0x20) == 0) goto loop8;
else
{
rec = inportb(addr); /* Read data */
printf("%2X/t ", rec &amp; 0xff);
if ( (i+1) % 8 == 0) printf("/n");
}

}
switch(frame_type)
{case 0:for(i = 0; i < 30; i ++)
{w = htoi(rec + (i * 2)); /* 液位 */
aii[i + 1] = w;
}
break;
case 1:for(i = 0; i < 30; i ++) /* 温度 */
{w = btoi(rec + (i * 2));
aii[i + 1] = w;
}
break;
}
ini:;
return(log);
}



int htoi(char *s)
{int k,w0,w1;
w0=s[0]; w0=w0 &amp; 0x00ff;
w1=s[1]; w1=w1 &amp; 0x00ff;
k=((w1<<8) &amp; 0xff00) | w0;
return(k);
}


int btoi(char *s)
{int k,w0,w1;
w0=s[0] &amp; 0x0f;
w1=((s[0]>>4) &amp; 0x0f)*10;
k=w0+w1;
w0=(s[1] &amp; 0x0f)*100;
w1=0;
k=k+w0+w1;
if((s[1] &amp; 0x40)==0) k=0-k;
return(k);
}


第二个:



/*******************************************************************/
/* */
/* File name: ps_init.c */
/* Date : 10/05/1995 */
/* Object : Program with communication board */
/* Command : ps_init [Sta_num(tank_num)] [sta_num(tank_num)] */
/* */
/*******************************************************************/

#include <stdio.h>
#include <dos.h>

int cuc_init(int addr);
int cuc_ready(int port,int mark,int log);

int main(int argc, char *argv[])
{
int kk, sta, tanks, i, A8255;
if ((argc < 2) || (argc > 5))
{ printf("/nError: Incorrect parameter number./n");
printf("Example:/n ps_init {sta_num[(tank_num)}/n");
return(1);
}
sscanf(argv[1],"%x",&amp;A8255);
cuc_init(A8255);
/* judge whether data fetched */
if(cuc_ready(A8255+2,0x80,1) == -1) { return(2); }
for(i=2;i<argc;i++)
{ sscanf(argv,"%d(%d)",&amp;sta,&amp;tanks);
if((sta<1) || (sta>4) || (tanks<1) || (tanks>30)) {return(3);}
outportb(A8255,0x00); /* Send command classic */
if(cuc_ready(A8255+2,0x80,1) == -1) { return(4); }
if(i == 2) outportb(A8255,0x00); /* command 0 */
else outportb(A8255,0x01); /* command 1 */
if (cuc_ready(A8255+2,0x80,1) == -1) { return(5); }
outportb(A8255,sta); /* Send station number */
if (cuc_ready(A8255+2,0x80,1) == -1) { return(6); }
outportb(A8255,tanks); /* Send tank number */
if (cuc_ready(A8255+2,0x80,1) == -1) { return(7); }
outportb(A8255,0xff); /* Send end byte */
if (cuc_ready(A8255+2,0x20,1) == -1) { return(8); }
kk=inportb(A8255);
printf("/nValue return from communication card is:");
printf("/nkk=%x/n", kk &amp; 0x00ff);
if(kk == 0x00) /* if receivecode=0x00 */
{ /* then init success */
printf("Port Init success./n"); /* else init failure */
printf("Execute Over./n");
}
else {printf("Port Init failure./n");}
}

return(0);
}

/* Initiate IEEE 485 communication board */
int cuc_init(addr)
int addr; /* Communication board address */
{
int i, j, k;
outportb(addr+3,0xc1); /* set work mode of 8255
A group
port C (upper half): output
port A: output
mode select: mode 2
B group
port C (lower half): input
port B: output
mode select: mode 0 */
for(i=0,j=2;i<20000;i++) k=i*j;
outportb(addr+1,0xff); /* reset 8031 */
for(i=0,j=2;i<20000;i++) k=i*j;
outportb(addr+3,0xc1);
for(i=0,j=2;i<20000;i++) k=i*j;
outportb(addr+1,0x00);
for(i=0,j=2;i<20000;i++) k=i*j;
return(k*0);
}

/* Check communication status */
int cuc_ready(port,mark,log)
int port; /* i/o port address */
int mark; /* compute mark */
int log; /* process logic mark */
{
int k,rlog;
rlog=0;
loop:
k=inportb(port);
switch(log)
{ case 0: if((k &amp; mark) != 0) goto loop; else break;
case 1: if((k &amp; mark) == 0) goto loop; else break;
case 2: if(k != mark) goto loop; else break;
default: break;
}
return(rlog);
}

 
我一般是 Delphi To C
[^]
 
老兄:上面这段代码没什么难度呀,只要熟悉pascal语法很快就翻译完
难道你不懂pascal语法吗
 
上学时学的pascal,C就从来没学过。
 
自己翻译吧,没难度的,在说别人的时间也是很宝贵的,并不一定非的要那300分。
 
建议专门成立一个组织,翻译 C--DELPHI国外有一个叫JEDI的就是这样的一个组织,很好!
 
头文件不好办,就是把你这东东翻译了,在Delphi下也不一定能编译
 
DOS时代的东西
 
>>头文件不好办,就是把你这东东翻译了,在Delphi下也不一定能编译

对呀,最烦麻的就是这个呀。
 
发到我的邮箱, tseug@263.net, 如果不着急的话, 有空的话我给你翻译. 估计要到春节后.
 
翻成PASCAL7.0的好了,不过完全可以自己动手的啊
 
麻烦大家了。
 
哇!好长![:(]
 
C || Pascal
#include <stdio.h> Uses stdio //调用一个单元
int cuc_read(int addr); Function cuc_read(addr:integer):Integer ;
int htoi(char *s); Function htoi(S:Pachr):integer;
char rec[100]; rev:array[0..99]of char;
int aii[100]; aii:array[0..99]of integer;
int main(char *argv[]); Function main(argv:array of char):integer;
clrscr(); clrscr(); //在某一个单元中
gotoxy(x,y); gotoxy(x,y);//在某一个单元中
printf("/nwrong/n"); writeln;writeln("nwrong");
if((k &amp; 0x80) == 0) goto loop1 if((k&amp;&amp;0x80)=0) then goto loop1
scanf(); read();
差不多了!
 
直译是行不通的,要意译。

DELPHI并没有提供读写端口的功能,但我记得有人已用其他方法实现了。先找这个!
 
here!
http://www.delphibbs.com/delphibbs/dispq.asp?lid=835507
 
用C不是挺好的吗?
 
用headconv 4.2
 
不是有个c转到pascal的application吗?
大富翁download里就有的嘛
 

Similar threads

I
回复
0
查看
729
import
I
I
回复
0
查看
1K
import
I
I
回复
0
查看
658
import
I
I
回复
0
查看
843
import
I
后退
顶部