home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST0407.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-31  |  1.6 KB  |  44 lines

  1. Program CCallsPascal;
  2. { This is a sample Pascal program that demonstrates a way of  }
  3. { interfacing a Turbo Pascal procedure to be called from the  }
  4. { Turbo C module that is linked in.                           }
  5. {$A-,F-}
  6.  
  7. Uses Crt;
  8.  
  9. Var
  10.   Count : Integer;       { Counter var for # of calls to proc }
  11.   _rsp : Pointer;        { Pointer to memory to save SI & DI  }
  12.   SiDiStack : Array[0..10] of Word;
  13.                          { Memory locations for SI and DI     }
  14.  
  15. {$L list4-6}
  16.  
  17. Procedure StartUpC; External;
  18.  
  19. Procedure PasProc;
  20. { This is the procedure that will be called from within the   }
  21. { Turbo C object module.  All this will do is output a string }
  22. { to the screen and increment a global variable.  This        }
  23. { variable will keep track of the number of times the routine }
  24. { is called.                                                  }
  25.  
  26. Begin
  27.   Inc( Count );          { Add 1 to global variable           }
  28.   Write( Count, '  ' );  { Ouput the new value                }
  29. End;
  30.  
  31. Begin
  32.   Count := 0;            { Initialize the counter.            }
  33.   _rsp := @SiDiStack;    { Initialize memory to save SI & DI  }
  34.   ClrScr;                { Clear the user screen              }
  35.   StartUpC;              { Call the external C routine        }
  36.   Writeln;               { Output a CR/LF to screen           }
  37.   Writeln( 'The Pascal routine was called a total of ',
  38.             Count, ' times.' );
  39.                          { Report number of times called      }
  40.   Write( 'Press any key to continue...' );
  41.   While( Not Keypressed ) Do
  42.     { NOP };             { Pause the program for keypress     }
  43. End.
  44.