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}> enum {
> /* normal application use */
> C_OPEN=1,C_CLOSE,C_READ,C_WRITE,C_GCTL,C_SCTL,C_GSPD,C_SSPD,C_STAT,
> C_DISCOV,C_IASREQ,C_CONN,C_DISC,
> };
>
> typedef int (FAR *FPI)();
>
> static char sig[] = "RadixIrDA";
> 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 */
The following loop is examining interrupt vectors looking for
{Quote hidden}> 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));
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}> 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;
> return comm_entry(C_READ,portid,(char FAR *)buffer,len);
> }
>
> 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.
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
____________________________________________