Searching \ for '[EE] C and Pascal question' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/language/index.htm?key=c
Search entire site for: 'C and Pascal question'.

Exact match. Not showing close matches.
'[EE] C and Pascal question'
2004\10\23@085020 by

I have used EE for topic, please change it OT if you feel this does not
belong here.

I have a friend who is trying to access the IrDA port on a Radix unit, the
manufacturer sent him a C code example; however, he is coding in Pascal.  I
know C but not Pascal.  The C code uses function pointers and if there are
any ideas how to convert it to Pascal I will appriciate it.

This is the definitions:

enum {
/* normal application use */
C_DISCOV,C_IASREQ,C_CONN,C_DISC,
};

typedef int (FAR *FPI)();

FPI comm_entry = 0L;

The FPI is giving him the trouble.  Below is the function to find the
function:

/*
* locate IrDA interrupt and save entry point in comm_entry
*/
static int find_irda(void)
{
int i;
void FAR *p;
char FAR *s;

if (comm_entry != 0) return 1;      /* already located */

for (i=0x60;i<=0x67;i++) {          /* else look for it */
p = MAKEFAR(0,(i<<2));
if ((s = *(char FAR * FAR *)p) != 0L) {
if (!strcmpf(s+3,sig)) {
comm_entry = (FPI)s;
return 1;
}
}
}
return 0;
}

The confusing lines are:

p = MAKEFAR(0,(i<<2));
if ((s = *(char FAR * FAR *)p) != 0L)

After this function is called, they use the following functions to access
the port:

int IrDA_open(void)
{
if (find_irda()) {
hport = comm_entry(C_OPEN);
}
return hport;
}

int IrDA_recv(int portid,char *buffer,int len)
{
if (portid != hport) return -1;
}

They are accesing the comm_entry with different number of parameters which
confuses him.  I have told him that comm_entry is a function pointer and the
first parameter points to the actual function, comm_entry is not a function
itself.  I hope this is correct.

Any pointers are appriciated,

Regards, Omer

____________________________________________
The comments below assume that the "C" language environment is 16-bit
Microsoft or Borland C, and that the Pascal involved is a 16-bit real-mode
version of Borland/Turbo Pascal...

{Quote hidden}

The following loop is examining interrupt vectors looking for
{Quote hidden}

>
> p = MAKEFAR(0,(i<<2));

This is creating a pointer to the interrupt vector table entry for interrupt
number 'i'.

> if ((s = *(char FAR * FAR *)p) != 0L)

This is extracting the interrupt vector table entry and treating it as a
pointer to char. In reality, it is a pointer to the code located at the
interrupt vector.

> if (!strcmpf(s+3,sig)) {
>{
>            comm_entry = (FPI)s;

If the memory starting 3 bytes beyond the code matches the signature, then
set 'comm-entry' to be a (far) pointer to the code. The first instruction is
probably a three byte jump instruction over the signature string.

{Quote hidden}

You are correct in that comm_entry is a function pointer. The "C"
declaration for that function pointer would be...

int (FAR *comm_entry) (int functioncode, ...);

This is a function that can accept a functioncode, followed by whatever
parameters are used by that function code.

You will have an issue with the different calling sequences of "C" and
"PASCAL" functions. The differences are the order in which arguments are
pushed on the stack, and  whether the caller or callee is responsible for
removing the parameters from the stack. You can build a set of 'shim'
functions in (inline) assembly to allow you to call the "C" functions out of
Pascal.

Bob Ammerman
RAm Systems

____________________________________________
Bob Ammerman,

Thank you for the reply.  It does give more detailed information about the C
code, and hopefully, make some sense to him so that the conversion can be
completed.

Regards, Omer

____________________________________________

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...