|
|
DataMuseum.dkPresents historical artifacts from the history of: CP/M |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about CP/M Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 4402 (0x1132)
Types: TextFile
Names: »CPASDEMO.PAS«
└─⟦505fbc898⟧ Bits:30002732 Turbo Pascal 5.0 for C-DOS Partner
└─⟦this⟧ »DEMOS\CPASDEMO.PAS«
æ Copyright (c) 1985, 88 by Borland International, Inc. å
program CPASDEMO;
(*
This program demonstrates how to interface Turbo Pascal and Turbo C.
Turbo C is used to generate an .OBJ file (CPASDEMO.OBJ). Then
this .OBJ is linked into this Turbo Pascal program using the æ$Lå
compiler directive.
NOTES:
1. Data declared in the Turbo C module cannot be accessed from
the Turbo Pascal program. Shared data must be declared in
Pascal.
2. If the C functions are only used in the implementation section
of a unit, declare them NEAR. If they are declared in the
interface section of a unit, declare them FAR. Always compile
the Turbo C modules using the small memory model.
3. Turbo C runtime library routines cannot be used because their
modules do not have the correct segment names. However, if you have
the Turbo C runtime library source (available from Borland),
you can use individual library modules by recompiling
them using CTOPAS.BAT. If you do recompile them, make sure
that you include prototypes in your C module for all C
library functions that you use.
4. Some of the code that Turbo C generates are calls to internal
routines. These cannot be used without recompiling the relevant
parts of the Turbo C runtime library source code.
In order to run this demonstration program you will need the following
files:
TCC.EXE and TURBO.CFG or
TC.EXE and CTOPAS.TC
To run the demonstration program CPASDEMO.EXE do the following:
1. First create a CPASDEMO.OBJ file compatible with Turbo Pascal 5.0
using Turbo C.
a) If you are using the Turbo C integrated environment (TC.EXE)
then at the DOS prompt execute:
TC /CCTOPAS.TC CPASDEMO.C
then create the .OBJ file by pressing ALT-F9.
b) If you are using the Turbo C command line version (TCC.EXE)
then at the DOS prompt execute:
TCC CPASDEMO.C
Note: Use the same configuration file (TURBO.CFG or CTOPAS.TC)
when you create your own Turbo C modules for use with
Turbo Pascal 5.0
2. Compile and execute the Turbo Pascal program CPASDEMO.PAS
This simple program calls each of the functions defined in the Turbo C
module. Each of the Turbo C functions changes the current display color
by calling the Turbo Pascal procedure SetColor.
*)
uses Crt;
var
Factor : Word;
æ$L CPASDEMO.OBJå æ link in the Turbo C-generated .OBJ module å
function Sqr(I : Integer) : Word; external;
æ Change the text color and return the square of I å
function HiBits(W : Word) : Word; external;
æ Change the text color and return the high byte of W å
function Suc(B : Byte) : Byte; external;
æ Change the text color and return B + 1 å
function Upr(C : Char) : Char; external;
æ Change the text color and return the upper case of C å
function Prd(S : ShortInt) : ShortInt; external;
æ Change the text color and return S - 1 å
function LoBits(L : LongInt) : LongInt; external;
æ Change the text color and return the low word of L å
procedure StrUpr(var S : string); external;
æ Change the text color and return the upper case of S - Note that the Turbo å
æ C routine must skip the length byte of the string. å
function BoolNot(B : Boolean) : Boolean; external;
æ Change the text color and return NOT B å
function MultByFactor(W : Word) : Word; external;
æ Change the text color and return W * Factor - note Turbo C's access of å
æ Turbo Pascal's global variable. å
procedure SetColor(NewColor : Byte); æ A procedure that changes the current å
begin æ display color by changing the CRT å
TextAttr := NewColor; æ variable TextAttr å
end; æ SetColor å
var
S : string;
begin
Writeln(Sqr(10)); æ Call each of the functions defined å
Writeln(HiBits(30000)); æ passing it the appropriate info. å
Writeln(Suc(200));
Writeln(Upr('x'));
Writeln(Prd(-100));
Writeln(LoBits(100000));
S := 'abcdefg';
StrUpr(S);
Writeln(S);
Writeln(BoolNot(False));
Factor := 100;
Writeln(MultbyFactor(10));
SetColor(LightGray);
end.
«eof»