Ok, akkor kemi, vagy saxus, vagy akárki, akinek van rálátása mindkét nyelvre. Itt az eredeti 4 függvénystruct timeval {
ULONG tv_secs;
ULONG tv_micro;
};
struct timerequest {
struct IORequest tr_node;
struct timeval tr_time;
};
struct timerequest *create_timer(ULONG unit)
{
LONG error;
struct MsgPort *timerport;
struct timerequest *TimerIO;
timerport = CreatePort(0, 0);
if (timerport == NULL)
{
return(NULL);
}
TimerIO = (struct timerequest *) CreateExtIO(timerport, sizeof(struct timerequest));
if (TimerIO == NULL)
{
DeletePort(timerport);
return(NULL);
}
error = OpenDevice(TIMERNAME, unit, (struct IORequest *) TimerIO, 0L);
if (error != 0)
{
delete_timer(TimerIO);
return(NULL);
}
return( TimerIO );
}
void wait_for_timer(struct timerequest *tr, struct timeval *tv)
{
tr->tr_node.io_Command = TR_ADDREQUEST;
tr->tr_time = *tv;
DoIO((struct IORequest *) tr);
}
void delete_timer(struct timerequest *tr )
{
struct MsgPort *tp;
if (tr != 0 )
{
tp = tr->tr_node.io_Message.mn_ReplyPort;
if (tp != 0)
{
DeletePort(tp);
}
CloseDevice( (struct IORequest *) tr);
DeleteExtIO( (struct IORequest *) tr);
}
}
LONG time_delay(struct timeval *tv, LONG unit)
{
struct timerequest *tr;
tr = create_timer(unit);
if (tr == NULL)
{
return(-1L);
}
wait_for_timer(tr, tv);
delete_timer(tr);
return (0L);
} itt meg amit Pascalban sikerült alkotnom.type
ttimeval = packed record
tv_secs: longword;
tv_micro: longword;
end;
ptimeval = ^ttimeval;
ttimerequest = packed record
tr_node: tiorequest;
tr_time: ttimeval;
end;
ptimerequest = ^ttimerequest;
function create_timer(_unit: longword): pttimerequest;
var
error: longint;
timerport: pmessageport;
timerio: ptimerequest;
begin
timerport := createport(0, 0);
if (timerport = nil) then
begin
create_timer := nil;
exit
end;
timerio := ptimerequest(createextio(timerport, sizeof(ttimerequest)));
if (timerio = nil) then
begin
deleteport(timerport);
create_timer := nil;
exit;
end;
error := opendevice('timer.device', _unit, piorequest(timerio), 0);
if (error <> 0) then
begin
delete_timer(timerio);
create_timer := nil;
exit;
end;
create_timer := timerio;
end;
procedure wait_for_timer(tr: ptimerequest; tv: ptimeval);
begin
tr.tr_node.io := 9;
tr.tr_time := tv^;
doio(piorequest(tr));
end;
procedure delete_timer(tr: ptimerequest);
var tp: pmsgport;
begin
if (tr <> nil) then
begin
tp := tr.tr_node.io_message.mn_replyport;
if (tp <> nil) then
begin
deleteport(tp);
end;
closedevice(piorequest(tr));
deleteextio(piorequest(tr));
end;
end;
function time_delay(tv: ptimeval, _unit: longword): longint;
var tr: ptimerequest;
begin
tr := create_timer(_unit);
if (tr = nil) then
begin
time_delay := -1;
exit;
end;
wait_for_timer(tr, tv);
delete_timer(tr);
time_delay := 0;
end; Stimmel? Elbasztam? Egyéb? |