PowerBASIC and Turbo C

 BBS: Inland Empire Archive
Date: 09-20-92 (09:20)             Number: 382
From: LAWRENCE GORDON              Refer#: NONE
  To: ROBERT CHURCH                 Recvd: NO  
Subj: PowerBASIC and Turbo C         Conf: (2) Quik_Bas
 On 09-17-92 Robert Church wrote to All...

 RC> Will PowerBASIC link with Turbo C?

Robert - The answer to that is yes. I've done it.

Here's how it's done:
If the word "necessary" is not used, it normally
means optional.
In Turbo C do the following:
 1. Set Options/Compiler/Model to Huge.
 2. Set Options/Compiler/Defines, do nothing here

 3. Set Options/Compiler/Code Generation as follows:
   Calling convention       C
   Instruction set          8088/8086
   Floating Point           Emulation
   Default char type        Signed
   Alignment                Byte          <---necessary
   Generate underbars       OFF           <---necessary
   Merge duplicate strings  OFF
   Standard Stack Frame     ON
   Test stack overflow      OFF
   Line numbers             OFF
   Obj debug information    ON

 4. Set Options/Compiler/Optimization
   Optimize for             Size
   Use register variables   On
   Register optimization    Off
   Jump optimization        Off

 5. Set Options/Compiler/Source
   Identifier length        32
   Nested comments          Off
   ANSI keywords            Off

 6. Set Options/Compiler/Errors
   Errors: stop after       25
   Warnings: stop after     100
   Display warnings         On
   Portability warnings:
   a: on,b: on,c:on,d:on,e:off,f:off,g:off
   Ansi Violations:
   a: to h: all on
   Common Errors:
   a:off,b: to g: all ON
   Less Common Errors:
   a: to f: all OFF

 7. Set Options/Compiler/Names/Code Names/Segment name to CSEG.
    Set Options/Compiler/Names/Code Names/Group   name to
    Set Options/Compiler/Names/Code Names/Class   name to
    (yes, even remove the '*', it defaults to it->*.)

 8. Set Options/Compiler/Names/Data names/Segment name to DSEG.
    Set Options/Compiler/Names/Data Names/Group   name to
    Set Options/Compiler/Names/Data Names/Class   name to
    (yes, even remove the '*', it defaults to it-> *.)

 9. Set Options/Compiler/Names/BSS  Names/Segment name to
    Set Options/Compiler/Names/BSS  Names/Group   name to
    Set Options/Compiler/Names/BSS  Names/Class   name to
    (yes, even remove the '*', it defaults to it-> *.)
    (not necessary but recommended.)

 10.  You DO NOT have to Options/Linker/Initialize segments).
      Map file               OFF
      Initialize segements   ON
      Default libraries      OFF
      Graphics Library       ON
      Warn duplicate symbols OFF
      Stack warning          ON
      Case-sensitive link    ON

 11. Set Options/Environment
     Message Tracking Current File
     Keep messages            NO
     Config autosave          OFF
     Edit Auto Save           ON
     Backup Files             ON
     Tab Size                 8
     Zoomed Windows           Off
     Screen Size    / 25 line display

 12. Set Options/Directories
     Set this as needed

 13. Set Options/Arguments
     this is not used

 14. After selection all your options be sure to save them.

 15. Now you can $LINK the .OBJ module into your PB program.
     Source code is shown below.

Here's a simple example of a C function which takes an integer
as a parameter, adds 17 to it, and returns it to the PB program:


  /* compile this to MYCCODE.OBJ */
  int pascal DOCALC (int far *pbvar)
  return (*pbvar)+17;


  $link "myccode.obj"
  declare function DOCALC%(integer)
  print DOCALC%(5)     'prints 22 (5+17)

Some things to note: the C function is declared to use
PASCAL calling conventions (because of the way C handles
parameter passing and the C function must clean up
the stack after the call, not PB), the parameter PBVAR
is declared to be a far pointer to an integer since PB
passes all parameters as far pointers, the function has
a return type of INT which causes the returned integer to
be placed in the AX register upon return (which is what PB
expects of an external function that returns an integer), and
PB's DECLARE statement must explicitly specify that the C
function is an integer function which takes an integer as a

Here's a simple example of a C routine which changes
the first character of a PB string which is passed to
it as a parameter:


  /* compile as MYCCODE.OBJ */

  #include <dos.h>

  void pascal DOSTR(unsigned far *stseg, unsigned far *stofs, int far *stlen)
  char far *stdata;     /* will point to actual string data */

  if (*stlen) {         /* if string length > 0 */
    stdata = (char far *) MK_FP(*stseg, *stofs);  /* get data pointer */
    if (stdata)         /* if valid string */
      *stdata = '*';    /* change 1st char of string to '*' */
Name: The Sniffler #111 @2095 VirtualNET Thru Gateway #2 @6852
Date: Tue Sep 22, 1992 13:07
From: WWIVnet - Snafu Software (Illinois) [618-234-2631]

Re: Detect Remote Connect...
By: Val #1 @6189 VirtualNET  

  You can define your com ports as an MSR, depending on which it is, then
call a subroutine to detect carrier or not.  For example:

 Assuming Port$="Com1" or "Com2"
If port$="Com1" then MSR = &H3FE
If port$="Com2" then MSR = &H2FE

  gosub checkonline
  if on=1 then goto useronline
  if on=0 then goto nouseronline


  if imp(MSR) >= 128 then online=1 : return
                          online=0 : return
                                                       The Sniffler

Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET