home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TURBO.ZIP / TURXFACE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-06-01  |  7.4 KB  |  114 lines

  1. {                                                                              }
  2. {  Module Name:  TURXFACE.PAS                                                  }
  3. {                                                                              }
  4. {  Description:  This is the Btrieve interface for Turbo Pascal  (MS-DOS).     }
  5. {                This routine sets up the parameter block expected by          }
  6. {                Btrieve, and issues interrupt 7B.  It should be compiled      }
  7. {                with the $V- switch so that runtime checks will not be        }
  8. {                performed on the variable parameters.                         }
  9. {                                                                              }
  10. {  Synopsis:     STAT := BTRIEVE (OP, POS.START, DATA.START, KBUF.START, KEY); }
  11. {                              where                                           }
  12. {                        OP is an integer,                                     }
  13. {                        POS.START is the integer variant of a 128 byte array, }
  14. {                        DATA.START is the integer variant of the data buffer, }
  15. {                        KBUF.START is the integer variant of the key buffer,  }
  16. {                    and KEY is an integer.                                    }
  17. {                                                                              }
  18. {  Returns:      Btrieve status code (see Appendix B of the Btrieve Manual).   }
  19. {                                                                              }
  20. {  Note:         It is important that the 2nd, 3rd and 4th actual parameters   }
  21. {                be declared as variant records, with an integer type as one   }
  22. {                of the variants (used for Btrieve calls).  For example,       }
  23. {                                                                              }
  24. {                var DATA = record case boolean of                             }
  25. {                    FALSE: ( START: integer);                                 }
  26. {                    TRUE:  ( EMPLOYEE_ID: 0..99999;                           }
  27. {                             EMPLOYEE_NAME: packed array [1..50] of char;     }
  28. {                             SALARY: real;                                    }
  29. {                             DATE_OF_HIRE:DATE_TYPE);                         }
  30. {                end;                                                          }
  31. {                                                                              }
  32. {                There should NEVER be any string variables declared in the    }
  33. {                data or key records, because strings store an extra byte for  }
  34. {                the length, which affects the total size of the record.       }
  35. {                                                                              }
  36. function BTRIEVE (OP:integer; var POS:integer; var DATA: integer;
  37.                               var KBUF:integer; KEY:integer):integer;
  38. const
  39.      PASCAL_ID = $AAAA;          {PASCAL language id}
  40. type
  41.      ADDR32 = record             {32 bit address}
  42.         OFFSET:  integer;
  43.         SEGMENT: integer;
  44.         end;
  45.      BTR_PARMS = RECORD
  46.         USER_BUF_ADDR:   ADDR32;   {data buffer address}
  47.         USER_BUF_LEN:    integer;  {data buffer length}
  48.         USER_CUR_ADDR:   ADDR32;   {currency block address}
  49.         USER_FCB_ADDR:   ADDR32;   {file control block address}
  50.         USER_FUNCTION:   integer;  {Btrieve operation}
  51.         USER_KEY_ADDR:   ADDR32;   {key buffer address}
  52.         USER_KEY_LENGTH: BYTE;     {key buffer length}
  53.         USER_KEY_NUMBER: BYTE;     {key number}
  54.         USER_STAT_ADDR:  ADDR32;   {return status address}
  55.         XFACE_ID:        integer;  {language interface id}
  56.         end;
  57. var
  58.      STAT:  integer;               {Btrieve Status code}
  59.      XDATA:BTR_PARMS;              {Btrieve parameter block}
  60.  
  61. begin
  62.      with XDATA do
  63.         begin
  64. {          USER_BUF_ADDR   :=  ADDR(DATA[0]);          {set data buffer address}
  65.            USER_BUF_LEN    :=  4090;                  {assume it's large enough}
  66. {          USER_FCB_ADDR   :=  ADDR(POS);                      {set FCB address}
  67.            USER_CUR_ADDR.SEGMENT:= USER_FCB_ADDR.SEGMENT;      {set cur segment}
  68.            USER_CUR_ADDR.OFFSET := USER_FCB_ADDR.OFFSET;       {set cur segment}
  69.            USER_FUNCTION   :=  OP;                  {set Btrieve operation code}
  70. {          USER_KEY_ADDR   :=  ADDR(KBUF);              {set key buffer address}
  71.            USER_KEY_LENGTH :=  255;                   {assume it's large enough}
  72.            USER_KEY_NUMBER :=  KEY;                             {set key number}
  73. {          USER_STAT_ADDR  :=  ADDR(STAT);               {return status address}
  74.            XFACE_ID        :=  PASCAL_ID;                      {set language id}
  75. {                                                                              }
  76.      begin inline               {additional inline code cause ADDR don't work  }
  77.         (  $8B / $46 / $0C /    {       MOV  AX,12[BP]                         }
  78.            $89 / $46 / $E2 /    {       MOV  -30[BP],AX  ;data buffer seg      }
  79.            $8B / $46 / $0A /    {       MOV  AX,10[BP]                         }
  80.            $89 / $46 / $E0 /    {       MOV  -32[BP],AX  ;data buffer off      }
  81.            $8B / $46 / $10 /    {       MOV  AX,16[BP]                         }
  82.            $89 / $46 / $EC /    {       MOV  -20[BP],AX  ;fcb seg              }
  83.            $89 / $46 / $E8 /    {       MOV  -24[BP],AX  ;cur block seg        }
  84.            $8B / $46 / $0E /    {       MOV  AX,14[BP]                         }
  85.            $89 / $46 / $EA /    {       MOV  -22[BP],AX  ;fcb off              }
  86.            $05 / $26 / $00 /    {       ADD  AX,38                             }
  87.            $89 / $46 / $E6 /    {       MOV  -26[BP],AX  ;cur block off        }
  88.            $8B / $46 / $08 /    {       MOV  AX,8[BP]                          }
  89.            $89 / $46 / $F2 /    {       MOV  -14[BP],AX  ;key buffer seg       }
  90.            $8B / $46 / $06 /    {       MOV  AX,6[BP]                          }
  91.            $89 / $46 / $F0 /    {       MOV  -16[BP],AX  ;key buffer off       }
  92.            $8D / $46 / $FC /    {       LEA  AX,-4[BP]                         }
  93.            $89 / $46 / $F6 /    {       MOV  -10[BP],AX  ;status off           }
  94.            $8C / $D0 /          {       MOV  AX,SS                             }
  95.            $89 / $46 / $F8 )    {       MOV  -8[BP],AX   ;status seg           }
  96.      end;
  97.   end;
  98.  
  99.      if MemW[$0000:$01EC] <> $0033 then         {make sure Btrieve is installed}
  100.         STAT := 20
  101.      else
  102.         begin inline            {inline code to invoke Btrieve via interrupt 7B}
  103.         (  $55 /                {       PUSH BP          ;save base pointer    }
  104.            $1E /                {       PUSH DS          ;save data segment    }
  105.            $16 /                {       PUSH SS          ;set default data seg }
  106.            $1F /                {       POP  DS          ;    to stack seg     }
  107.            $8D / $56 / $E0 /    {       LES  DX,XDATA    ;set parm address     }
  108.            $CD / $7B /          {       INT  7BH         ;issue interrupt      }
  109.            $1F /                {       POP  DS          ;restore data segment }
  110.            $5D )                {       POP  BP          ;restore base pointer }
  111.          end;
  112.       BTRIEVE := STAT;                                   {return status to user}
  113. end;
  114.