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

  1. ;*************************************************************************
  2. ;
  3. ;  Copyright 1982-1997 Pervasive Software Inc. All Rights Reserved
  4. ;
  5. ;*************************************************************************
  6. ;*************************************************************************
  7. ;   MFXBTRV.ASM
  8. ;      This program interfaces between Micro Focus COBOL animated programs and
  9. ;      Btrieve assembly routines.  It is loaded as MFXBTRV.BIN by the COBOL
  10. ;      runtime, and uses non-Intel byte order.
  11. ;
  12. ;      Calling Procedure from COBOL:
  13. ;      CALL "MFXBTRV" USING FUNCTION, STATUS, POSITION-BLOCK, DATA-BUFFER,
  14. ;                     DATA-LEN, KEY-VALUE, KEY-NUMBER.
  15. ;           where
  16. ;              FUNCTION       - pointer to function    PIC 9999 COMP-0 (hi-lo)
  17. ;              STATUS         - pointer to ret status  PIC 9999 COMP-0 (hi-lo)
  18. ;              POSITION-BLOCK - pointer to 128-byte position block
  19. ;              DATA-BUFFER    - pointer to data buffer
  20. ;              DATA-LEN       - pointer to length of data buffer
  21. ;              KEY-VALUE      - pointer to key buffer
  22. ;              KEY-NUMBER     - pointer to key number PIC 9999 COMP-0  (hi-lo)
  23. ;
  24. ;        IMPORTANT
  25. ;        ---------
  26. ;        Pervasive Software Inc., invites you to modify this file
  27. ;        if you find it necessary for your particular situation.  However,
  28. ;        we cannot provide technical support for this module if you
  29. ;        do modify it.
  30. ;
  31. ;*************************************************************************
  32.         PAGE    60,132
  33.         PUBLIC BTRV
  34. ;*************************************************************************
  35. ;       Define parameter offsets from BX
  36. ;*************************************************************************
  37. PARM_OFF   = 6
  38. FUNCTION   = PARM_OFF + 24
  39. STATUS     = PARM_OFF + 20
  40. POS_BLK    = PARM_OFF + 16
  41. DATA_REC   = PARM_OFF + 12
  42. DATA_LEN   = PARM_OFF + 8
  43. KEY_BUFFER = PARM_OFF + 4
  44. KEY_NUM    = PARM_OFF
  45. ;*************************************************************************
  46. ;       Define offets within position block where FCB and
  47. ;       currency information are stored.
  48. ;*************************************************************************
  49. FCB = 0
  50. CUR = 38
  51. ;
  52. VAR_ID          EQU     06176H          ;Variable record interface id
  53. BTR_ERR         EQU     20              ;status - Btrieve not initialized
  54. BTR_INT         EQU     07BH
  55. BTR_OFFSET      EQU     033H
  56. BTR_VECTOR      EQU     BTR_INT * 4     ;Absolute vector offset for interrupt
  57. CREATE          EQU     14              ;Create function call
  58. STAT            EQU     15              ;Stat function call
  59. CREATE_SUPP     EQU     31              ;Create supplemental index call
  60. ;*************************************************************************
  61. ;   Code Segment
  62. ;*************************************************************************
  63. CODE    SEGMENT 'CODE'
  64.         ASSUME CS:CODE,DS:CODE
  65. ;*************************************************************************
  66. ;   BTRV
  67. ;*************************************************************************
  68. BTRV    PROC    FAR
  69.     JMP    COB_0
  70.  
  71. USER_BUF_ADDR   DD      ?               ;callers data buffer offset
  72. USER_BUF_LEN    DW      ?               ;length of callers data buffer
  73. USER_CUR_ADDR   DD      ?               ;callers currency info offset
  74. USER_FCB_ADDR   DD      ?               ;disk FCB for current request
  75. USER_FUNCTION   DW      ?               ;requested function
  76. USER_KEY_ADDR   DD      ?               ;callers key buffer offset
  77. USER_KEY_LENGTH DB      ?               ;length of key buffer
  78. USER_KEY_NUMBER DB      ?               ;key of reference for request
  79. USER_STAT_ADDR  DD      ?               ;callers status word offset
  80. XFACE_ID        DW      ?               ;language identifier
  81.  
  82. COB_0:  PUSH    BP
  83.         MOV     BP,SP
  84.         PUSH    ES
  85.         PUSH    DS
  86.         PUSH    SI
  87.  
  88.         ;set up to access data within this code segment
  89.         PUSH    CS
  90.         POP     DS
  91.  
  92.         ;see if Btrieve has been initialized
  93.         PUSH    ES
  94.         PUSH    BX
  95.         MOV     AX,3500H + BTR_INT
  96.         INT     21H
  97.         CMP     BX,BTR_OFFSET
  98.         POP     BX
  99.         POP     ES
  100.         JE      COB_1                           ;Has Btrieve been initialized?
  101.         LES     SI,DWORD PTR [BP]+STATUS        ;  N, BX = status offset
  102.         MOV     AX,BTR_ERR
  103.         XCHG    AH,AL
  104.         MOV     ES:[SI],AX                      ;Set return status
  105.         JMP     COB_2                           ;Skip interrupt since invalid
  106. COB_1:
  107.        ;get function parameter
  108.         LES     SI,DWORD PTR [BP]+FUNCTION      ;get function address
  109.         MOV     CX,ES:[SI]                      ;get function number
  110.         XCHG    CL,CH
  111.         MOV     USER_FUNCTION,CX
  112.  
  113.         ;get address of callers status word from parameter
  114.         LES     CX,DWORD PTR [BP]+STATUS        ;get address of status word
  115.         MOV     WORD PTR USER_STAT_ADDR,CX
  116.         MOV     WORD PTR USER_STAT_ADDR+2,ES
  117.  
  118.         ;get position block
  119.         LES     SI,DWORD PTR [BP]+POS_BLK       ;SI = address of position block
  120.         LEA     AX,ES:[SI]+FCB                  ;get diskette file block addr
  121.         MOV     WORD PTR USER_FCB_ADDR,AX
  122.         MOV     WORD PTR USER_FCB_ADDR+2,ES
  123.         LEA     AX,ES:[SI]+CUR                  ;get currency block addr
  124.         MOV     WORD PTR USER_CUR_ADDR,AX
  125.         MOV     WORD PTR USER_CUR_ADDR+2,ES
  126.  
  127.         ;get data buffer
  128.         LES     SI,DWORD PTR [BP]+DATA_REC
  129.         MOV     WORD PTR USER_BUF_ADDR,SI
  130.         MOV     WORD PTR USER_BUF_ADDR+2,ES
  131.  
  132.         ;get data buffer length
  133.         LES     SI,DWORD PTR [BP]+DATA_LEN      ;get length address
  134.         MOV     CX,ES:[SI]                      ;get length
  135.         XCHG    CL,CH
  136.         MOV     USER_BUF_LEN,CX
  137.  
  138.         ;get callers key buffer address and length
  139.         LES     SI,DWORD PTR [BP]+KEY_BUFFER    ;get key buffer addr
  140.         MOV     WORD PTR USER_KEY_ADDR,SI
  141.         MOV     WORD PTR USER_KEY_ADDR+2,ES
  142.         MOV     USER_KEY_LENGTH,255             ;set key length to max
  143.  
  144.         ;get key number parameter
  145.         LES     SI,DWORD PTR [BP]+KEY_NUM       ;get key number address
  146.         MOV     CX,ES:[SI]                      ;get key number
  147.         MOV     USER_KEY_NUMBER,CH
  148.  
  149.         ;set language and go process request
  150.         MOV     XFACE_ID,VAR_ID                 ;get interface id
  151.         LEA     DX,USER_BUF_ADDR                ;DX => user parms
  152.         CALL    PRE_SW
  153.         INT     BTR_INT                         ;process request
  154.         CALL    POST_SW
  155.         MOV     CX,USER_BUF_LEN
  156.         XCHG    CL,CH
  157.         LES     SI,DWORD PTR [BP]+DATA_LEN      ;get length address
  158.         MOV     ES:[SI],CX                      ;reset length in user's space
  159. COB_2:
  160.         LES     SI,USER_STAT_ADDR
  161.         MOV     AX,ES:[SI]
  162.         XCHG    AH,AL
  163.         MOV     ES:[SI],AX
  164.  
  165.         POP     SI
  166.         POP     DS
  167.         POP     ES
  168.         POP     BP
  169.         RET
  170. BTRV    ENDP
  171.  
  172. ;*************************************************************************
  173. ; These routines are used to put the control blocks for CREATE, CREATE_SUPP,
  174. ; and STAT into a regular form.  Cobol always reverses the high and low
  175. ; order byte in words.
  176. ;*************************************************************************
  177. POST_SW PROC    NEAR
  178.         CMP     USER_FUNCTION,STAT      ;if stat function
  179.         JE      POST_10                 ; do switch
  180. PRE_SW  LABEL   NEAR
  181.         CMP     USER_FUNCTION,CREATE    ;if create function then
  182.         JE      POST_10                 ; do switch
  183.         CMP     USER_FUNCTION,CREATE_SUPP ;if not create supp,
  184.         JNE     POST_99                 ; skip switch
  185. POST_10:
  186.         PUSH    AX
  187.         PUSH    BX
  188.         PUSH    CX
  189.         PUSH    DX
  190.         PUSH    SI
  191.         PUSH    DS
  192.  
  193.         MOV     DX,USER_FUNCTION
  194.         LDS     BX,USER_BUF_ADDR        ;BX => file structure
  195.         PUSH    BX                      ;save BX for later
  196.         MOV     CX,8                    ;8 words in the header
  197. POST_20:
  198.         MOV     AX,[BX]                 ;get word
  199.         XCHG    AL,AH                   ;exchange bytes
  200.         MOV     [BX],AX                 ;replace word as COBOL expects it
  201.         INC     BX
  202.         INC     BX
  203.         LOOP    POST_20
  204.         POP     SI                      ;SI = old BX
  205.         MOV     CX,4[SI]                ;cx = # keys
  206.         CMP     CH,0
  207.         JE      POST_25
  208.         XCHG    CL,CH
  209. POST_25:
  210.         CMP     CX,119                  ;if > max indexex then
  211.         JA      POST_90                 ; must be a bad specification
  212.         CMP     CX,0
  213.         JE      POST_90                 ;Does this file have any keys?
  214.                                         ;  Y
  215.         ;test for any segmented key specs
  216.         PUSH    BX                      ;BX -> 1st key spec
  217.         SUB     BX,16
  218.         SUB     AX,AX
  219. POST_27:
  220.         INC     AX
  221.         ADD     BX,16
  222.         CMP     DX,CREATE
  223.         JNE     POST_28
  224.         TEST    WORD PTR 4[BX],1000h    ;Does this spec have another segment
  225.         JNE     POST_27                 ; yes
  226.         JMP     SHORT POST_29
  227. POST_28:
  228.         TEST    WORD PTR 4[BX],0010h    ;Does this spec have another segment
  229.         JNE     POST_27                 ; yes
  230. POST_29:
  231.         LOOP    POST_27
  232.         POP     BX                      ;BX -> 1st key spec
  233.         MOV     CX,AX                   ;CX = real number of key specs
  234.  
  235.         ;now switch the total number of key specs
  236.         MOV     AL,8                    ;number of words in key spec
  237.         MUL     CL
  238.         MOV     CX,AX                   ;CX = number of words in key specs
  239. POST_30:
  240.         MOV     AX,[BX]                 ;get word
  241.         XCHG    AL,AH                   ;exchange bytes
  242.         MOV     [BX],AX                 ;replace word as COBOL expects it
  243.         INC     BX
  244.         INC     BX
  245.         LOOP    POST_30
  246. POST_90:
  247.         POP     DS
  248.         POP     SI
  249.         POP     DX
  250.         POP     CX
  251.         POP     BX
  252.         POP     AX
  253. POST_99:
  254.         RET
  255. POST_SW ENDP
  256.  
  257. CODE    ENDS
  258.         END
  259.