Microsoft KB Archive/57348

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 10:19, 21 July 2020 by X010 (talk | contribs) (Text replacement - ">" to ">")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


Passing Single Precision Between QuickBASIC and MPW Pascal

Article ID: 57348

Article Last Modified on 11/21/2006

This article was previously published under Q57348

SUMMARY

The two programs shown below demonstrate how a Microsoft QuickBASIC program can pass single precision numbers to and from Apple MPW Pascal version 3.00 pure code resources.

This information about interlanguage calling applies to Microsoft QuickBASIC version 1.00 for the Apple Macintosh.

MORE INFORMATION

When doing interlanguage calling with Microsoft QuickBASIC, the other language can make calls to the BASIC run time to get the address of passed arguments. This is accomplished with the GetNextLibArg statement.

GetNextLibArg returns a pointer to a variant record containing another pointer to each possible type of QuickBASIC variable (single precision, double precision, integer, etc.). Usually a double indirection of pointers is used to get the actual passed data.

Using double indirection of pointers with Apple MPW (Macintosh Programmer's Workshop) Pascal, however, does not return the correct value. This is a QuickBASIC header file problem. The routine below demonstrates how an inline assembly-language routine can be used in place of the double indirection to work around the problem.

More information on interlanguage calling with Microsoft QuickBASIC can be found in the "Microsoft QuickBASIC for Apple Macintosh: Language Reference," starting on page 444.

Compile and link PrintSng.p from Apple MPW Pascal version 3.00 as follows:

   pascal -p PrintSng.p
   link -p -rt MBPC=999 PrintSng.p.o BasicLib.a.o -o PrintDbl
                

Note: The file BasicLib.a.o comes with Microsoft QuickBASIC for the Apple Macintosh on the Examples disk in the User Libraries:MBPC Rsrcs:MPWP PCR Folder.

Once PrintSng is compiled and linked, ResEdit should be used to change parameters in PrintSng as follows:

  1. In ResEdit, find the newly created file PrintSng, and click once on the name so that it is highlighted.
  2. While holding down the COMMAND key, press the "I" key. This is the same as choosing Get Info from the File menu. Change the following in the dialog box that appears:

    1. Change the File field to "PrintSng".
    2. Change the Type field to "MBPC".
    3. Change the Creator field to "MSBB".
  3. Close the dialog box, and click Yes when asked if you want to save.
  4. Double-click PrintSng to open it. There should be one resource of MBPC displayed; double-click this also. Single-click the displayed MBPC and press COMMAND+I. In the Get Info dialog box that is brought up, change the Name field to PrintSng.

PrintSng is now a pure code resource that can be used with the RetSng QuickBASIC program.

It should be noted that PrintSng uses the record structure BigRec to pass the single precision number to the assembly language subroutine. This is because MPW Pascal automatically converts single and double precision numbers to an extended 10 byte format when passing them. Using the record structure stops MPW Pascal from performing this conversion.

Code Example

The following QuickBASIC program is RetSng, which invokes an Apple MPW Pascal routine to return a series of single precision numbers:

   LIBRARY "PrintSng"

   A! = 0 : B! = 0 : C! = 0
   CALL PrintDouble(A!, B!, C!)
   PRINT A!; B!; C!

   WHILE INKEY$ = "" : WEND
                

The following Apple MPW Pascal routine is PrintSng.p, which accepts a series of passed single precision numbers from a Microsoft QuickBASIC program and returns a constant value in them:

{**************************************************************}
{* PrintSng.p (c) 1989 Microsoft Corporation                  *}
{**************************************************************}
{* Description: Example to show how to pass single precision  *}
{*              number from QuickBASIC to MPW Pascal and back.*}
{**************************************************************}
{$R-}   { Turn off range checking}
UNIT PrintVerRec;

{*======================== INCLUDE FILE=======================*}
USES
   {$U MemTypes.p }      MemTypes,
   {$U BasicLibMPWP.p }  BasicLib;

TYPE
    BigRec = RECORD
       singnum: SINGLE;
    END;

   procedure AssignSng (ptr: LIBARGPTR; val: BigRec);
   inline
      $225f,  { movea.l (a7)+,a1                             }
      $2e19,  { move.l  (a1)+,d7   ;get Long value           }
      $205f,  { movea.l (a7)+,a0   ;get ptr to Int variable  }
      $20C7;  { move.l   d7, (a0)+ ;assign the Int value     }

PROCEDURE Main;

{$S Main}
{*------------------------------------------------------------*
 * A routine to pass back to BASIC single precision constants *
 *    Called from BASIC as:                                   *
 *    CALL PrintSng (< single precision argument list >)      *
 *------------------------------------------------------------*}
PROCEDURE MAIN;
VAR
   tempflag,argtype: INT16;
   valptr:  LIBARGPTR;
   tempsng: SINGLE;

BEGIN
   argtype := GetNextLibArg(valptr,tempflag);

   WHILE (argtype <> _ARGSEND) DO
      BEGIN
         if (argtype = _SINGARG) THEN
            BEGIN
               tempsng := 20.25;
               AssignSng(valptr, BigRec(tempsng));
            END;
         argtype := GetNextLibArg(valptr,tempflag);
      END;

END; {* of MAIN *}
                

Running RetSng produces the following output:

   20.25  20.25  20.25
                


Additional query words: MQuickB

Keywords: KB57348