home *** CD-ROM | disk | FTP | other *** search
/ Datatid 1999 June / Datatid_1999-06.iso / internet / Tango352Promo / P.SQL / PTKPKG.1 / COBBTRV.ASM < prev    next >
Encoding:
Assembly Source File  |  1997-02-13  |  8.5 KB  |  217 lines

  1. ;*************************************************************************
  2. ;
  3. ;  Copyright 1982-1997 Pervasive Software Inc. All Rights Reserved
  4. ;
  5. ;*************************************************************************
  6. ;*************************************************************************
  7. ;   COBBTRV.ASM
  8. ;      This program is the interface between Micro Focus COBOL\2 programs and
  9. ;      Btrieve.  It is conditionally assembled to produce either
  10. ;      'cobrbtrv.obj' or 'cobpbtrv.obj', which are object modules for DOS &
  11. ;      OS2, respectively.
  12. ;
  13. ;       Calling Procedure from COBOL
  14. ;         If using COBOL Animator (debugger) replace '_BTRV' with 'MF2BTRV'.
  15. ;
  16. ;         CALL "_BTRV" USING FUNCTION, STATUS, POSITION-BLOCK, DATA-RECORD,
  17. ;                              DATA-LEN, KEY-VALUE, KEY-NUMBER.
  18. ;           where
  19. ;              FUNCTION       - pointer to function    PIC 9999 COMP-5 (hi-lo)
  20. ;              STATUS         - pointer to ret status  PIC 9999 COMP-5 (hi-lo)
  21. ;              POSITION-BLOCK - pointer to 128-byte position block
  22. ;              DATA-RECORD    - pointer to data buffer
  23. ;              DATA-LEN       - pointer to length of data buffer
  24. ;              KEY-VALUE      - pointer to key buffer
  25. ;              KEY-NUMBER     - pointer to key number PIC 9999 COMP-5  (lo-hi)
  26. ;
  27. ;             note: All numerical values passed to Btrieve as a parameter
  28. ;                   must be in the Intel format (LO-HIGH byte order).  To
  29. ;                   do this define them as COMP-5.
  30. ;
  31. ;
  32. ;        IMPORTANT
  33. ;        ---------
  34. ;        Pervasive Software Inc., invites you to modify this file
  35. ;        if you find it necessary for your particular situation.  However,
  36. ;        we cannot provide technical support for this module if you
  37. ;        do modify it.
  38. ;
  39. ;        For an OS2 module, define 'OS2=1' to your assembler.  If you do
  40. ;        not define OS2, then the assembled module will be for DOS.
  41. ;        Examples of assembler switch: /DOS2=0 or /DOS2=1
  42. ;
  43. ;        This module is current as of 06/07/94.
  44. ;
  45. ;*************************************************************************
  46.         PUBLIC  _BTRV
  47. ;*************************************************************************
  48. ;       Define parameter offsets on stack
  49. ;*************************************************************************
  50. PARM_OFF   = 6
  51. FUNCTION   = PARM_OFF + 0
  52. STATUS     = PARM_OFF + 4
  53. POS_BLK    = PARM_OFF + 8
  54. DATA_REC   = PARM_OFF + 12
  55. DATA_LEN   = PARM_OFF + 16
  56. KEY_BUFFER = PARM_OFF + 20
  57. KEY_NUM    = PARM_OFF + 24
  58. ;*************************************************************************
  59. ;       Define offets within position block where FCB and
  60. ;       currency information are stored.
  61. ;*************************************************************************
  62. FCB        EQU 0
  63. CUR        EQU 38
  64. VAR_ID     EQU 06176H                   ;Variable record interface id
  65. BTR_ERR    EQU 20                       ;status - Btrieve not initialized
  66. BTR_INT    EQU 07BH
  67. BTR_OFFSET EQU 033H
  68. BTR_VECTOR EQU BTR_INT * 4              ;Absolute vector offset for interrupt
  69.  
  70. ;*************************************************************************
  71. ;  OS2 is defined on the assembler command line as 0 or 1.
  72. ;*************************************************************************
  73. IF OS2
  74. extrn BTRCALL:FAR
  75. ENDIF
  76.  
  77. ;*************************************************************************
  78. ;  Declare a data segment.
  79. ;*************************************************************************
  80. _XDATA segment word public 'DATA'
  81. BTRPARMS DB 28 DUP (?)
  82. USER_BUF STRUC
  83.    USER_BUF_ADDR   DD      ?            ;callers data buffer offset
  84.    USER_BUF_LEN    DW      ?            ;length of callers data buffer
  85.    USER_CUR_ADDR   DD      ?            ;callers currency info offset
  86.    USER_FCB_ADDR   DD      ?            ;disk FCB for current request
  87.    USER_FUNCTION   DW      ?            ;requested function
  88.    USER_KEY_ADDR   DD      ?            ;callers key buffer offset
  89.    USER_KEY_LENGTH DB      ?            ;length of key buffer
  90.    USER_KEY_NUMBER DB      ?            ;key of reference for request
  91.    USER_STAT_ADDR  DD      ?            ;callers status word offset
  92.    XFACE_ID        DW      ?            ;language identifier
  93. USER_BUF ENDS
  94.  
  95. _XDATA ENDS
  96.  
  97. ;*************************************************************************
  98. ;  Declare a code segment.
  99. ;*************************************************************************
  100. _TEXT   segment word public 'CODE'
  101.          assume cs:_TEXT
  102.          assume ds:_XDATA
  103.  
  104. ;*************************************************************************
  105. ;  _BTRV
  106. ;*************************************************************************
  107. _BTRV proc far
  108.         PUSH    BP
  109.         MOV     BP,SP
  110.         PUSH    ES
  111.         PUSH    DS
  112.         PUSH    SI
  113.  
  114.         MOV     DX,SEG _XDATA
  115.         MOV     DS,DX
  116.  
  117.         LEA     SI,BTRPARMS
  118. IFE OS2                                 ;assembling for OS2 ?
  119.         MOV     AX,3500H + BTR_INT      ;  N
  120.         INT     21H
  121.         CMP     BX,BTR_OFFSET
  122.         JE      LOADED                  ;Has Btrieve been initialized?
  123.         LES     BX,DWORD PTR [BP]+STATUS;  N
  124.         MOV     AX,BTR_ERR
  125.         MOV     ES:[BX],AX
  126.         JMP     SHORT ERROUT
  127. ENDIF
  128. LOADED:
  129.         ;get function parameter
  130.         LES     BX,DWORD PTR [BP]+FUNCTION      ;get function address
  131.         MOV     CX,WORD PTR ES:[BX]             ;get function number
  132.         MOV     [SI].USER_FUNCTION,CX
  133.  
  134.         ;get address of callers status word from parameter
  135.         LES     BX,DWORD PTR [BP]+STATUS        ;get address of status word
  136.         MOV     WORD PTR [SI].USER_STAT_ADDR,BX
  137.         MOV     WORD PTR [SI].USER_STAT_ADDR+2,ES
  138.  
  139.         ;get position block
  140.         LES     BX,DWORD PTR [BP]+POS_BLK       ; address of position block
  141.         LEA     AX,[BX]+FCB                     ;get diskette file block addr
  142.         MOV     WORD PTR [SI].USER_FCB_ADDR,AX
  143.         MOV     WORD PTR [SI].USER_FCB_ADDR+2,ES
  144.         LEA     AX,[BX]+CUR                     ;get currency block addr
  145.         MOV     WORD PTR [SI].USER_CUR_ADDR,AX
  146.         MOV     WORD PTR [SI].USER_CUR_ADDR+2,ES
  147.  
  148.         ;get data buffer
  149.         LES     BX,DWORD PTR [BP]+DATA_REC
  150.         MOV     WORD PTR [SI].USER_BUF_ADDR,BX
  151.         MOV     WORD PTR [SI].USER_BUF_ADDR+2,ES
  152.  
  153.         ;get data buffer length
  154.         LES     BX,[BP]+DATA_LEN                ;get data length address
  155.         MOV     CX,WORD PTR ES:[BX]             ;get data length
  156.         MOV     WORD PTR [SI].USER_BUF_LEN,CX
  157.  
  158.         ;get callers key buffer address and length
  159.         LES     BX,DWORD PTR [BP]+KEY_BUFFER    ;get key buffer addr
  160.         MOV     WORD PTR [SI].USER_KEY_ADDR,BX
  161.         MOV     WORD PTR [SI].USER_KEY_ADDR+2,ES
  162.         MOV     BYTE PTR [SI].USER_KEY_LENGTH,255 ;set key length to max
  163.  
  164.         ;get key number parameter
  165.         LES     BX,DWORD PTR [BP]+KEY_NUM       ;get key number address
  166.         MOV     CX,WORD PTR ES:[BX]             ;get key number
  167.         MOV     BYTE PTR [SI].USER_KEY_NUMBER,CL
  168.  
  169.         ;set language and go process request
  170.         MOV     WORD PTR [SI].XFACE_ID,VAR_ID
  171.         MOV     DX,SI                           ;DX => user parms
  172.  
  173. IFE OS2
  174.         INT     BTR_INT                         ;process request on DOS
  175. ELSE
  176.         ;push parameters for OS/2 call and make call to Btrieve DLL
  177.         MOV     CX,WORD PTR [SI].USER_FUNCTION
  178.         PUSH    CX
  179.         LES     CX,DWORD PTR [SI].USER_FCB_ADDR
  180.         PUSH    ES
  181.         PUSH    CX
  182.         LES     CX,DWORD PTR [SI].USER_BUF_ADDR
  183.         PUSH    ES
  184.         PUSH    CX
  185.         MOV     CX,SI
  186.         ADD     CX,USER_BUF_LEN
  187.         PUSH    DS
  188.         PUSH    CX
  189.         LES     CX,DWORD PTR [SI].USER_KEY_ADDR
  190.         PUSH    ES
  191.         PUSH    CX
  192.         SUB     CX,CX
  193.         MOV     CL,BYTE PTR [SI].USER_KEY_LENGTH
  194.         PUSH    CX
  195.         MOV     CL,BYTE PTR [SI].USER_KEY_NUMBER
  196.         PUSH    CX
  197.  
  198.         CALL    BTRCALL
  199.  
  200.         LES     BX,DWORD PTR [SI].USER_STAT_ADDR ;get address of status
  201.         MOV     ES:[BX],AX                      ;Store Btrieve status
  202. ENDIF
  203.         ;update data length as reported by Btrieve
  204.         MOV     CX,WORD PTR [SI].USER_BUF_LEN   ;data length returned
  205.         LES     BX,[BP]+DATA_LEN                ;address of data length
  206.         MOV     ES:[BX],CX                      ;set user's data length
  207. ERROUT:
  208.         POP     SI
  209.         POP     DS
  210.         POP     ES
  211.         POP     BP
  212.         RET
  213. _BTRV endp
  214.  
  215. _TEXT ends
  216. END
  217.