home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 December / SOFM_Dec1995.bin / pc / os2 / vpascal / vp.txt < prev   
Text File  |  1995-10-31  |  32KB  |  788 lines

  1. TABLE OF CONTENTS
  2. ~~~~~~~~~~~~~~~~~
  3. 1. Getting started
  4.    1.1 Compilation process
  5.    1.2 Linker module definition file
  6.    1.3 Target platforms
  7.    1.4 OS/2 API interface units
  8.  
  9. 2. Borland Pascal compatibility issues
  10.    2.1 Data types
  11.    2.2 Pointer types
  12.    2.3 Integer expressions
  13.    2.4 Standard unit implementation differences
  14.        2.4.1 System unit
  15.        2.4.2 Dos unit
  16.        2.4.3 WinDos unit
  17.        2.4.4 Crt unit
  18.        2.4.5 WinCrt and Strings unit
  19.        2.4.6 32-bit Turbo Vision for OS/2
  20.    2.5 Compiler directives
  21.    2.6 Built-in assembler
  22.    2.7 Register usage
  23.        2.7.1 Embedded ASM statements
  24.        2.7.2 Assembler procedures and functions
  25.    2.8 Code generation differences
  26.    2.9 Import and export
  27.    2.10 Inline statements and inline subroutines
  28.  
  29. 3. New Virtual Pascal features
  30.    3.1 Calling conventions
  31.    3.2 Naming convention
  32.    3.3 Pure interface units
  33.    3.4 Direct port access
  34.    3.5 Import
  35.    3.6 Export
  36.    3.7 Presentation Manager resources
  37.    3.8 Writing OS/2 Dynamic Link libraries
  38.        3.8.1 Subroutine libraries
  39.        3.8.2 Subsystems
  40.  
  41.  
  42. 1. GETTING STARTED
  43. ~~~~~~~~~~~~~~~~~~
  44. There is no documentation in this beta release other than
  45. online help system of the IDE and this file. This documentation
  46. is addressed to those who are familiar with Borland Pascal.
  47. If you are a user of the Borland Pascal, you may have only few
  48. problems, because VP and BP are very much alike. Even error
  49. messages have the same numbers and spellings. This document
  50. reflects the main differences between Virtual Pascal and
  51. Borland Pascal v7.0 and introduces new Virtual Pascal features.
  52.  
  53.  
  54. 1.1  COMPILATION PROCESS
  55. ~~~~~~~~~~~~~~~~~~~~~~~~
  56. Borland Pascal compiles source code to the object code with a
  57. compiler version and target platform specific format. For a
  58. unit it generates .TPU/.TPP/.TPW files (.DCU in Delphi Pascal
  59. Compiler) that contains object code and interface symbol
  60. information. Virtual Pascal generates two kind of files:
  61.   - containing object code (.OBJ, .LIB or ASM);
  62.   - containing interface symbol information (.VPI).
  63. The following picture describes the compilation process:
  64.  
  65.                             ┌──────────────┐
  66.                  ┌────────>─┤ UnitName.OBJ │ $SmartLink-
  67.                  │          │ UnitName.VPI │ $Asm-
  68.                  │          └──────────────┘
  69.                  │          ┌──────────────┐
  70. ┌──────────────┐ │          │ UnitName.OBJ │ $SmartLink-
  71. │ UnitName.PAS ├─┼────────>─│ UnitName.ASM │ $Asm+
  72. └──────────────┘ │          │ UnitName.VPI │
  73.                  │          └──────────────┘
  74.                  │          ┌──────────────┐
  75.                  │          │ UnitName.LIB │ $SmartLink+
  76.                  └────────>─│ UnitName.VPI │
  77.                             └──────────────┘
  78.  
  79.                             ┌─────────────────┐
  80. ┌─────────────────┐         │ ProgramName.OBJ │
  81. │ ProgramName.PAS ├──┬────>─┤ ProgramName.ASM │ $Asm+
  82. └─────────────────┘  │      │ ProgramName.LNK │
  83.                      │      └─────────────────┘
  84.                      │      ┌─────────────────┐
  85.                      └────>─┤ ProgramName.OBJ │ $Asm-
  86.                             │ ProgramName.LNK │
  87.                             └─────────────────┘
  88.  
  89.                             ┌─────────────────┐
  90. ┌─────────────────┐         │ LibraryName.OBJ │
  91. │ LibraryName.PAS ├──┬────>─┤ LibraryName.ASM │ $Asm+
  92. └─────────────────┘  │      │ LibraryName.LNK │
  93.                      │      └─────────────────┘
  94.                      │      ┌─────────────────┐
  95.                      └────>─┤ LibraryName.OBJ │ $Asm-
  96.                             │ LibraryName.LNK │
  97.                             └─────────────────┘
  98.  
  99. .ASM file is a readable 386 assembly source file which can be
  100. compiled by MASM 6.0a+ or TASM 3.0+.
  101.  
  102. .OBJ and .LIB files are standard Intel Object Module Format
  103. (OMF) object and library files. They can be linked by any
  104. 32-bit OMF linker, which is capable of generating linear
  105. executables (LX) for OS/2. By default, Virtual Pascal uses
  106. LINK386 supplied with OS/2. Note, that if a unit has no code
  107. (it is simply used to define constants and types), then no
  108. object code is generated and there would be no .OBJ or .LIB
  109. file for it.
  110.  
  111. .LNK file is a linker response file which should be passed to
  112. the linker. It contains the list of object and library files,
  113. module definition file name (if compiler found it) and linker
  114. map file name (VPC: if /G command line option is specified,
  115. IDE: Linker│Map file active button is other than None).
  116.  
  117. .VPI file is a Virtual Pascal Interface file. It contains
  118. interface symbol information.
  119.  
  120. Only .VPI file format is compiler version dependent. For
  121. directions of how to distribute object code without source, see
  122. PURE INTERFACE UNITS section.
  123.  
  124. 1.2 LINKER MODULE DEFINITION FILE
  125. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  126. Borland Pascal has a built-in linker, that is why it passes
  127. additional information (segment attributes, description text,
  128. etc) to the linker by means of compiler directives. Virtual
  129. Pascal uses standalone linker, so you can use linker module
  130. definition file to supply this additional information about
  131. your application. You must use module definition file to create
  132. dynamic link libraries.
  133.  
  134. Module definition file should be located in the same directory
  135. as a primary file of the program or library, and must have the
  136. same name, but a .DEF extension.
  137.  
  138. A module definition file is a plain text file that describes
  139. the names, segment attributes, exports, imports, and other
  140. characteristics of an application or library. It contains
  141. one or more module statements. Here are the brief summary of
  142. the module statements:
  143.  
  144. BASE = BaseAddress
  145.  
  146. CODE [PRELOAD | LOADONCALL] [EXECUTEONLY | EXECUTEREAD]
  147.      [IOPL | NOIOPL] [CONFORMING | NONCONFORMING]
  148.  
  149. DATA [PRELOAD | LOADONCALL] [READONLY | READWRITE]
  150.      [NONE | SINGLE | MULTIPLE] [SHARED | NONSHARED] [IOPL | NOIOPL]
  151.  
  152. DESCRIPTION 'text'
  153.  
  154. EXETYPE OS2
  155.  
  156. EXPORTS
  157.   ExportName [= InternalName][@Ordinal][RESIDENTNAME | NONAME] [StackParams]
  158.  
  159. IMPORTS
  160.     [InternalName =] ModuleName.EntryName | ModuleName.Ordinal
  161.  
  162. LIBRARY [LibraryName] [INITGLOBAL | INITINSTANCE] [TERMGLOBAL | TERMINSTANCE]
  163.  
  164. NAME [ApplicationName] [WINDOWAPI | WINDOWCOMPAT | NOWINDOWCOMPAT]
  165.  
  166. OLD `filename.DLL'
  167.  
  168. SEGMENTS
  169.   ['] Name ['] [ CLASS ['ClassName']] [PRELOAD | LOADONCALL]
  170.   [READONLY | READWRITE] [EXECUTEONLY | EXECUTEREAD] [IOPL | NOIOPL]
  171.   [CONFORMING | NONCONFORMING] [SHARED | NONSHARED]
  172.  
  173. STUB `FileName.EXE' | NONE
  174.  
  175. 1.3 TARGET PLATFORMS
  176. ~~~~~~~~~~~~~~~~~~~~
  177. Virtual Pascal can generate code for either OS/2 full screen
  178. application or Presentation Manager application. Virtual
  179. Pascal combines all three Borland Pascal target platforms into
  180. one. You should specify the type of the application to be
  181. generated by the Linker│Application radio buttons or specify
  182. application type in the NAME statement of the module definition
  183. file (if you use linker other than LINK386).
  184.  
  185. 1.4 OS/2 API interface units
  186. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  187. It is a good practice to use standard Borland Pascal unit
  188. procedures and functions for your programs. If you need OS/2
  189. specific functions you can use OS/2 API interface units to
  190. call them directly. There are four interface units supplied:
  191.  
  192.  Os2Def:   Contains common definitions for OS/2 base and
  193.            Presentation Manager API.
  194.  Os2Base:  Contains API functions and type declarations for
  195.            writing OS/2 base applications. It also contains
  196.            16-bit API function prototypes for writing full
  197.            screen applications (KBD/VIO/MOU/MON/NLS calls).
  198.  Os2PmApi: Contains Presentation Manager interface constants,
  199.            types and function prototypes.
  200.  Os2Rexx:  Contains an interface to OS/2 REXX interpreter.
  201.  
  202. 2. BORLAND PASCAL COMPATIBILITY ISSUES
  203. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  204. Unlike Borland Pascal, Virtual Pascal generates 32-bit code.
  205. The main differences between Borland Pascal and Virtual Pascal
  206. are due to this fact. To maintain backward 16-bit compatibility,
  207. Virtual Pascal uses some tricks described in this chapter.
  208.  
  209. 2.1 DATA TYPES
  210. ~~~~~~~~~~~~~~
  211. All built-in data types have the same name, size and meaning,
  212. except for two floating point types (Real and Extended).
  213. Virtual Pascal uses only coprocessor types, that is why Real
  214. and Double types are identical. Extended type is 10-byte
  215. floating point coprocessor type, but occupies 12 bytes to
  216. maintain double word alignment. Built-in assembler accepts
  217. 12-byte sized variables as TBYTE operands.
  218.  
  219. It is not efficient to use on true 32-bit processor 16-bit
  220. integer variables. That is why to maintain backward 16-bit
  221. compatibility, in 32-bit programs written in Virtual Pascal,
  222. it is recommended to include USE32 unit into USES clause of
  223. each unit. USE32 unit redefines built-in 16-bit integer types
  224. Integer and Word as 32-bit Longint type (see source code for
  225. the USE32 unit: \VP\SOURCE\RTL\USE32.PAS). If you really need
  226. to use 16-bit integers, use SmallInt and SmallWord types
  227. instead of Integer and Word, or use fully qualified
  228. identifiers:  System.Integer and System.Word.
  229.  
  230. 2.2 POINTER TYPES
  231. ~~~~~~~~~~~~~~~~~
  232. Virtual Pascal uses 32-bit flat memory model. Pointers in
  233. Virtual Pascal have the same size (4 bytes) but denote 32-bit
  234. flat memory address rather than 16-bit segment (or selector) and 16-bit
  235. offset. As a result, Mem arrays have only one index - 32-bit
  236. flat memory offset. Segment part of the memory address is not
  237. available.
  238.  
  239. 2.3 INTEGER EXPRESSIONS
  240. ~~~~~~~~~~~~~~~~~~~~~~~
  241. In Borland Pascal all byte sized operands of the integer
  242. arithmetic operator are converted to Integer type. In Virtual
  243. Pascal all byte and word sized operands of the arithmetic
  244. operator are converted to Longint type.
  245.  
  246. 2.4 STANDARD UNIT IMPLEMENTATION DIFFERENCES
  247. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248. There are six standard units shipped: System, Dos, Crt,
  249. Strings, WinDos and WinCrt. Source code for System unit is
  250. not available. Parameters to standard procedures/functions and
  251. function return values that in Borland Pascal have Integer or
  252. Word type are extended to be Longint. Actually, they remain to
  253. be of the Integer and Word type, but USE32 unit is used to
  254. redefine the meaning of the Word and Integer.
  255.  
  256. If you do not include USE32 unit into uses clause and try to
  257. recompile your 16-bit code, you will have no portability
  258. problems for value-parameters to the standard procedures and
  259. functions that have Word or Integer arguments. For variable
  260. parameters, you will get 'Type mismatch' error, because in
  261. Virtual Pascal they are 32-bit.
  262.  
  263. 2.4.1  SYSTEM UNIT
  264. ~~~~~~~~~~~~~~~~~~
  265. Ptr standard function has only one parameter: 32-bit flat memory offset.
  266. Segment parameter is not available.
  267.  
  268. 2.4.2  DOS UNIT
  269. ~~~~~~~~~~~~~~~
  270. The following DOS specific procedures are not implemented:
  271.  
  272. procedure Intr(IntNo: Byte; var Regs: Registers);
  273. procedure MsDos(var Regs: Registers);
  274. procedure GetCBreak(var Break: Boolean);
  275. procedure SetCBreak(Break: Boolean);
  276. procedure GetIntVec(IntNo: Byte; var Vector: Pointer);
  277. procedure SetIntVec(IntNo: Byte; Vector: Pointer);
  278. procedure Keep(ExitCode: Word);
  279.  
  280. Procedure SwapVectors remains for compatibility but do nothing.
  281. New procedure FindClose is added.
  282.  
  283. procedure FindClose(var F: SearchRec);
  284.  
  285. It ends the search, initiated by FindFirst and closes the
  286. search record. FindClose should be issued whenever search
  287. record is no longer needed. Unlike DOS, OS/2 does not keep
  288. search information in the user program space (in the
  289. SearchRec). OS/2 returns only handle that identifies this
  290. information, so it should be freed, otherwise OS/2 runs out of
  291. search handles and all calls to FindFirst later on will fail.
  292.  
  293. 2.4.3 WINDOS UNIT
  294. ~~~~~~~~~~~~~~~~~
  295. The following procedures are not implemented:
  296.  
  297. procedure Intr(IntNo: Byte; var Regs: TRegisters);
  298. procedure MsDos(var Regs: TRegisters);
  299. procedure GetCBreak(var Break: Boolean);
  300. procedure SetCBreak(Break: Boolean);
  301. procedure GetIntVec(IntNo: Byte; var Vector: Pointer);
  302. procedure SetIntVec(IntNo: Byte; Vector: Pointer);
  303.  
  304. New procedure FindClose is added.
  305.  
  306. procedure FindClose(var F: TSearchRec);
  307.  
  308. It has the same purpose as FindClose procedure of the Dos unit.
  309.  
  310. 2.4.4 CRT UNIT
  311. ~~~~~~~~~~~~~~
  312. The following procedures are not implemented:
  313.  
  314. procedure Sound(Hz: Word);
  315. procedure NoSound;
  316.  
  317. You can use new procedure PlaySound instead. Essentially, it is
  318. the equivalent to three calls:
  319.  
  320. Sound(Freq);
  321. Delay(Duration);
  322. NoSound;
  323.  
  324. procedure PlaySound(Freq,Duration: Longint);
  325.  
  326. 2.4.5 WINCRT AND STRING UNIT
  327. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  328. All procedures and functions are implemented.
  329.  
  330. 2.4.6 32-BIT TURBO VISION FOR OS/2
  331. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  332. 32-bit Turbo Vision for OS/2 is available as a patch on
  333. original Borland Pascal Turbo Vision sources. Run TV4VP
  334. OS/2 command file in the \VP\SOURCE\TV directory for the
  335. details of how to apply the patch.
  336.  
  337. Low level Drivers and Objects units have been rewritten
  338. completely, in other units all assembler code has been
  339. rewritten. DOS specific TEmsStream object is not implemented.
  340. TEvent record is extended to include ShiftState byte field for
  341. evKeyDown variant. Critical error handlers are not available.
  342. OS/2 handles critical errors in a proper way (unlike DOS, OS/2
  343. does not destroy user screen). FormatStr procedure is rewritten
  344. in built-in assembler. High level units such as Menus, Dialogs,
  345. etc, remains practically unchanged.
  346.  
  347. 2.5 COMPILER DIRECTIVES
  348. ~~~~~~~~~~~~~~~~~~~~~~~
  349. All Borland Pascal compiler directives that are implemented in
  350. Virtual Pascal have the same spelling. New switch directives
  351. introduced in the Virtual Pascal have names, consisting of
  352. several letters, unlike one letter switches of the Borland
  353. Pascal (surely, it is only 26 letters). Detailed description of
  354. the Virtual Pascal compiler directives can be found in the IDE
  355. help system.
  356.  
  357. Several Borland Pascal directives are not available. Virtual
  358. Pascal simply ignores them. The alternative way of entering
  359. compiler directives is available. Comment that begins with,
  360. the ampersand (&) symbol, rather than dollar sign ($), is
  361. treated as a compiler directive. It is a convenient way to
  362. specify Virtual Pascal specific directives, Borland Pascal will
  363. treat them as ordinal comments.
  364.  
  365. Borland Pascal 7.0 compiler directives that have no effect in
  366. Virtual Pascal:
  367.  
  368. Switch compiler directives
  369.  
  370. Switch│ Meaning
  371. ══════╪═════════════════════════════════
  372.   $E  │ Emulation
  373.   $F  │ Force FAR Calls
  374.   $G  │ Generate 286 Instructions
  375.   $K  │ Smart Callbacks
  376.   $N  │ Numeric Coprocessor
  377.   $O  │ Overlay Code Generation
  378.   $W  │ Windows Stack Frame
  379.   $Y  │ Symbol Reference Information
  380.  
  381. Parameter directives
  382.  
  383. Directive    │ Meaning
  384. ═════════════╪══════════════════════════════
  385. $C Attribute │Code Segment Attribute
  386. $D Text      │Description
  387. $G UnitName  │Group Unit Segments
  388. $O UnitName  │Overlay Unit Name
  389. $R FileName  │Resource File
  390. $S SegSize   │Segment Size Preference
  391.  
  392. 2.6 BUILT-IN ASSEMBLER
  393. ~~~~~~~~~~~~~~~~~~~~~~
  394. Built-in assembler is extended to support 386,486 and Pentium
  395. instructions. Two new operators are introduced: Small and Large.
  396. They are used to modify memory addressing mode (Small: 16-bit,
  397. Large:  32-bit). They have the same meaning and syntax, as in
  398. other 32-bit assemblers, such as MASM or TASM. There are two
  399. pseudo instructions available ALIGN and POPARGS.
  400.  
  401. ALIGN pseudo instruction accepts one constant integer operand
  402. that can have the following values:
  403.  1: No code is generated.
  404.  2: Virtual Pascal generates code to align next instruction
  405.     to the word (2-byte) boundary.
  406.  4: Virtual Pascal generates code to align next instruction
  407.     to the double word boundary.
  408. Code, generated by the ALIGN instruction does not change any
  409. CPU register, except EIP.
  410.  
  411. POPARGS pseudo instruction accepts one constant integer operand
  412. that defines the size of the arguments that should be popped
  413. out after current subprogram returns. It has meaning only for
  414. assembler procedures and functions. This value is used for RET
  415. instruction, generated by the END statement of the assembler
  416. procedure or function.
  417.  
  418. In addition to @Params and @Locals symbols, @Uses symbol is
  419. introduced. It returns total size of the registers, saved in
  420. stack by the {$USES RegList} directive.
  421.  
  422. 2.7 REGISTER USAGE
  423. ~~~~~~~~~~~~~~~~~~
  424. Unlike Borland Pascal, Virtual Pascal have different register
  425. usage convention. By default, EBX, ESI and EDI registers are
  426. used as register variables to hold intermediate values across
  427. procedure or function calls and for register Self object
  428. pointer. If procedure or function uses these registers, they
  429. are saved on entry and restored on exit.
  430.  
  431. Default register usage convention is compatible with SYSCALL
  432. calling convention used by OS/2 API functions. 32-bit C/C++
  433. compilers have the same convention too. However, you can
  434. modify default register usage convention by $Saves parameter
  435. directive, but this is not recommended.
  436.  
  437. 2.7.1 EMBEDDED ASM STATEMENTS
  438. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  439. ASM statements assume the default register convention or that
  440. one which is specified by the $Saves ($Alters) directive. For
  441. default register convention this means that EBX,ESI and EDI
  442. registers should not be changed. If you change one of them, you
  443. should inform compiler about this in the $Saves or $Alters
  444. directive. If ASM statement does not modify these registers
  445. and EAX,ECX or EDX, you may inform compiler either, so it can
  446. produce more efficient code.
  447.  
  448. 2.7.2 ASSEMBLER PROCEDURES AND FUNCTIONS
  449. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  450. Assembler procedures and functions should conform to the current
  451. register usage convention. $USES statement can help you with
  452. this. The $USES directive is like USES directive of the macro
  453. assemblers. It specifies registers that will be pushed at the
  454. beginning of the procedure or function and popped before
  455. return. You can also use $FRAME directive to specify whether to
  456. set up stack frame or not. For small assembler routines you can
  457. disable the generation of the stack frame ($FRAME- state). In
  458. this case, access to local variables and arguments is performed
  459. via ESP register. This generates the fastest code, but may
  460. produce bugs. Access to the local variable or argument is
  461. legal only if you does not change the value of the ESP register
  462. (there are no pushes or pops).
  463.  
  464. 2.8 CODE GENERATION DIFFERENCES
  465. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  466. Nested procedures and functions use different model for
  467. accessing local variables and arguments of the enclosing
  468. procedure or function. It is based on ENTER CPU instruction,
  469. which pushes stack frame pointers of all enclosing routines at
  470. the beginning of the nested procedure or function. See Intel
  471. documentation for the details.
  472.  
  473. For overflow checking compiler uses INTO CPU instruction and
  474. for range checking - BOUND. This produces faster code when
  475. range and overflow checkings are enabled.
  476.  
  477. 2.9 IMPORT AND EXPORT
  478. ~~~~~~~~~~~~~~~~~~~~~
  479. Export and import are completely different. Virtual Pascal does
  480. not support EXPORTS clause, Name and Index standard procedural
  481. directives. Virtual Pascal offers more powerful and flexible
  482. language independent approach, see section 3 for the details.
  483.  
  484. 2.10 Inline statements and inline subroutines
  485. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  486. These Borland Pascal archaisms are not supported. Use
  487. ASM statement or assembler procedure/function instead.
  488.  
  489.  
  490. 3. NEW VIRTUAL PASCAL FEATURES
  491. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  492.  
  493. 3.1 CALLING CONVENTIONS
  494. ~~~~~~~~~~~~~~~~~~~~~~~
  495. Virtual Pascal supports Pascal, 16-bit Pascal (Far16) without
  496. thunking, C and StdCall calling conventions. Calling convention
  497. defines the order of the parameters and the way of stack clean
  498. up. You can change default calling convention by specifying
  499. compiler directive as follows:
  500.  
  501. Directive │ Convention    │ Parameter push order │ Stack cleanup
  502. ══════════╪═══════════════╪══════════════════════╪═════════════════
  503.  $Cdecl+  │ C language    │ Last to first        │  Caller
  504.  $Far16+  │ 16-bit Pascal │ First to last        │  Called routine
  505.  $StdCall+│ STDCALL       │ Last to first        │  Called routine
  506.  Disabled │ 32-bit Pascal │ First to last        │  Called routine
  507.  
  508. These directives are mutually exclusive. If one directive is
  509. enabled, the other ones are disabled. Specifying any directive
  510. in the disabled state (-) enables default Pascal calling
  511. convention.
  512.  
  513. For a procedure or function you can change the default calling
  514. convention by specifying Pascal, Cdecl, Far16 or StdCall
  515. standard procedure directive.
  516.  
  517. Far16 Pascal calling convention is supported only for external
  518. procedures or functions. Compiler generates special code that
  519. calls external far 16-bit Pascal procedure or function via
  520. special helper routine. This helper routine has a restriction -
  521. you cannot specify more than 16 parameters to the Far16
  522. procedure or function, if you try to specify more, compiler
  523. treats it as ordinal 32-bit Pascal. Virtual Pascal generates
  524. only 32-bit code, so Far16 directive is ignored, if it is used
  525. with non-external procedure or function. In this case calling
  526. convention would be 32-bit Pascal.
  527.  
  528. It is worth to note, that you can create procedural types that
  529. use Pascal, Cdecl and StdCall calling conventions.
  530.  
  531. Note, that unlike C/C++ compilers, calling convention of the
  532. Virtual Pascal does not change the case of the global
  533. identifiers and does not define whether to append leading
  534. underscore to global identifier or not. Next section describes
  535. naming convention used by Virtual Pascal.
  536.  
  537. 3.2 NAMING CONVENTION
  538. ~~~~~~~~~~~~~~~~~~~~~
  539. To satisfy the scope rules of Borland Pascal language,
  540. Virtual Pascal uses the following naming convention for public
  541. identifiers in the object file:
  542.  
  543.   UnitName@SymbolName
  544.   UnitName@ObjectName@MethodName
  545.  
  546. where
  547.   UnitName    is the name of the program, library or unit where
  548.               symbol is defined. If program is written without
  549.               heading (no program name is given), PROGRAM is
  550.               assumed.
  551.   SymbolName  is the name of the variable, typed constant,
  552.               procedure or function
  553.   ObjectName  is a name of the object type
  554.   MethodName  is a name of the object method.
  555.  
  556. All names have their original case. However, for variables,
  557. typed constants, procedures and functions you can change
  558. default naming convention by specifying $OrgName+ directive.
  559. $OrgName+ puts original name of the symbol converted to upper
  560. case. Its primary purpose is to declare external OS/2 API
  561. functions, for example, see Os2Base unit source. You should
  562. also use it for interface variables, procedures and functions
  563. in your Pascal program or unit when you want to link it with
  564. modules written in other languages.
  565.  
  566.  
  567. 3.3 PURE INTERFACE UNITS
  568. ~~~~~~~~~~~~~~~~~~~~~~~~
  569. Virtual Pascal stores symbol information about interface part
  570. of a unit in Virtual Pascal Interface file (.VPI). VPI files
  571. are compiler version dependent. Moreover, interface check sum
  572. sometimes depend upon compiler options used to compile unit.
  573. That is why, if you want to supply unit's object code without
  574. source, you should create pure interface unit for it.  It
  575. should contain {$PureInt+} directive at the start of the unit
  576. and all interface part. If unit has an initialization part, it
  577. implementation part should be as follows:
  578.  
  579. implementation
  580. begin
  581. end.
  582.  
  583. otherwise only
  584.  
  585. interface
  586. end.
  587.  
  588. is needed. {PureInt+} directive forces the compiler to ignore
  589. undefined forward references to procedures, functions and
  590. methods, and assume that they are implemented in the
  591. original version of the unit. No object file or library is
  592. generated for pure interface unit, so when you compile it by
  593. any newer version of the compiler, it creates appropriate .VPI
  594. file for it and uses the object file or library produced from
  595. the original unit by the old version of the compiler.
  596.  
  597.  
  598. 3.4 DIRECT PORT ACCESS
  599. ~~~~~~~~~~~~~~~~~~~~~~
  600. To obtain direct port access you should enable I/O privilege
  601. by specifying the following line in your OS/2 CONFIG.SYS:
  602.  
  603. IOPL=YES
  604.  
  605. If you use Port arrays in your Pascal program, you should
  606. either link it with DLL version of the run-time library or
  607. create linker module definition file for it with the following
  608. line included:
  609.  
  610. SEGMENTS IO16 IOPL
  611.  
  612. 3.5 IMPORT
  613. ~~~~~~~~~~
  614. Virtual Pascal does not support Name and Index standard
  615. procedural directives of the Borland Pascal. External
  616. procedures or functions should be declared using only
  617. EXTERNAL standard directive, whether they are imported or
  618. not. It is totally transparent to the language. It is
  619. linker prerogative to know whether symbol is imported.
  620. Replacing static libraries by import libraries one can easily
  621. create applications that use either static or dynamic
  622. versions of the libraries.
  623.  
  624. If procedure or function is imported, there are two ways to
  625. declare module name, entry name or ordinal number:
  626.  - Use module definition file to specify this information.
  627.    You should take into consideration naming convention of the
  628.    Virtual Pascal (see 3.2 for details).
  629.  - Create an import library for your dynamic link library.
  630.    Then you can use its name in the $L parameter directive in
  631.    a program or library which uses your DLL.
  632.  
  633.    Import library is created automatically by the IDE when you
  634.    compile dynamic link library. It has the same name as a
  635.    primary file of the library and has a .LIB extension. It is
  636.    placed to the directory that is mentioned first in the
  637.    Options│Directories│Library directories input box. Default
  638.    import library OS2.LIB contains the import declarations of
  639.    the OS/2 API functions. You need not specify it in the $L
  640.    directive.
  641.  
  642. 3.6 EXPORT
  643. ~~~~~~~~~~
  644. Virtual Pascal does not support EXPORTS clause of the Borland
  645. Pascal. You can export procedure or function by specifying
  646. Export standard directive in its declaration. Note, that unlike
  647. Borland Pascal, it can be applied only to the procedure or
  648. function in the interface part of a unit, or any procedure or
  649. function in the program or library source file.
  650.  
  651. As for the import, it is possible to use module definition file
  652. to export procedures, functions, variables and typed constants
  653. from the interface part of a unit or from the program or
  654. library source file.
  655.  
  656. You can also export the whole interface part of the unit,
  657. including procedures, functions, object methods, variables and
  658. typed constants. You should only specify required unit name as
  659. a parameter to the $Export directive in the dynamic library
  660. source file, and that is all. See source file for DLL version
  661. of the Virtual Pascal run-time library for an example
  662. (\VP\SOURCE\RTL\VPRTL*.*).
  663.  
  664. 3.7 PRESENTATION MANAGER RESOURCES
  665. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  666. Virtual Pascal uses OS/2 resource compiler RC.EXE to compile
  667. resource script file and to bind binary resource file to the
  668. executable. Virtual Pascal IDE uses the following convention:
  669. resource script file (.RC) should be located in the directories
  670. specified in the Option│Directives│Resource directives input
  671. box or in the current directory, have the same name as primary
  672. file of the program or library, but have a .RC extension. If the
  673. IDE finds such a file, it looks for a binary resource file in
  674. the output directory (Options│Directories│Output directory
  675. input box) that has the same name but a .RES extension. If
  676. there is no binary resource file or it is older than resource
  677. script file, the IDE invokes RC to compile script file to
  678. binary resource file. Then RC is invoked to bind binary
  679. resource file to the application or dynamic link library
  680. executable. If your resource script file consists of several
  681. include files and you have modified one of them, you should
  682. 'touch' (update date) the primary script file, so the IDE
  683. may recognize that it is changed.
  684.  
  685. 3.8 WRITING OS/2 DYNAMIC LINK LIBRARIES
  686. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  687. Dynamic link libraries generally fall into two categories -
  688. subroutine libraries and subsystems. Virtual Pascal lets you
  689. create both types of the dynamic link libraries, but subroutine
  690. libraries are commonly used. Note, that source level debugging
  691. is not available for procedures and functions located in the
  692. library source file, so it usually contains only library
  693. heading, uses clause, and initialization part (usually for
  694. subsystems).
  695.  
  696. 3.8.1 SUBROUTINE LIBRARIES
  697. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  698. Subroutine libraries are the most convenient way of
  699. creating dynamic version of the units. Procedures, functions
  700. and object methods in the subroutine library are written and
  701. execute in the same way as a statically linked ones. Units,
  702. included into dynamic link library works exactly as they were
  703. linked statically. The only difference is that actual linking
  704. occurs at load time instead of linking time. OS/2 creates
  705. unique static unit data (global variables and typed constants)
  706. for each application that uses subroutine dynamic link library.
  707. Subroutine libraries need not initialization and termination
  708. code. You must use module definition file to create dynamic
  709. link library. Typically it consists of three statements:
  710.  
  711.   LIBRARY LibName          ; specifies DLL name
  712.   DATA MULTIPLE NONSHARED  ; forces OS/2 to create new
  713.                            ; instances of data segments for
  714.                            ; each application that uses DLL
  715.   DESCRIPTION 'Text'       ; Inserts specified text into
  716.                            ; the library executable file
  717.  
  718. 3.8.2 SUBSYSTEMS
  719. ~~~~~~~~~~~~~~~~
  720. The term subsystem refers to a DLL that provides a set of
  721. services built around a resource. The term resource is used in
  722. the most general sense of the word, do not confuse it with
  723. Presentation Manager resource. A subsystem usually has to
  724. manage a limited resource for an effectively unlimited number
  725. of clients. That is why, subsystems have common data segment
  726. for all applications (clients) that use it. To keep track of
  727. its clients, subsystem needs to know when new clients arrive
  728. and when old clients terminate. There are two forms of
  729. subsystem initialization and termination - global and
  730. instance. A subsystem can specify either service but not both.
  731.  
  732. If global initialization is specified, the initialization entry
  733. point is called only once per activation of the subsystem. When
  734. the DLL is first referenced, OS/2 allocates the subsystem's
  735. static data segments, taking their initial values from the .DLL
  736. file. OS/2 then calls the subsystem's global initialization
  737. entry point so that the module can do its one-time
  738. initialization.
  739.  
  740. The second form of initialization is instance initialization.
  741. The instance initialization entry point is called in the same
  742. way as the global initialization entry point except that it is
  743. called for every new client when that client first attaches to
  744. the DLL.
  745.  
  746. The same applies to the DLL termination.
  747.  
  748. You must use module definition file to create subsystem's
  749. dynamic link library. Typically it consists of three
  750. statements:
  751.  
  752.   LIBRARY LibName <Init> <Term> ; specifies DLL name
  753.   DATA SINGLE NONSHARED    ; only one data segment is created
  754.   DESCRIPTION 'Text'       ; Inserts specified text into
  755.                            ; the library executable file
  756.  
  757. <Init> can be either INITGLOBAL or INITINSTANCE,
  758. <Term> can be either TERMGLOBAL or TERMINSTANCE.
  759.  
  760. The initialization and termination entry points are the same.
  761. They correspond to the initialization statement part of
  762. a library. To check whether initialization or termination is
  763. underway, you should use assembler function like this:
  764.  
  765. { Returns True for DLL initialization }
  766.  
  767. function IsInit: Boolean; assembler; {$USES None} {$FRAME-}
  768. asm
  769.                 cmp     [ebp+0Ch],0
  770.                 sete    al
  771. end;
  772.  
  773. It checks special parameter passed to the DLL initialization /
  774. termination by OS/2. It is 0 for initialization and 1 for
  775. termination.
  776.  
  777. The usual sybsystem initialization part is the following:
  778.  
  779. begin
  780.   if IsInit then
  781.   begin
  782.     ... Initialization stuff goes here
  783.   end
  784.  else
  785.   begin
  786.     ... Termination stuff are placed here
  787.   end.
  788.