home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a011 / 2.ddi / COBXBTRV.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-02-09  |  7.2 KB  |  308 lines

  1.     .XLIST
  2.     PAGE    60,132
  3.     TITLE    Btrieve Record Manager, Copyright (c) 1982 SoftCraft, Inc.
  4.     SUBTTL    COBXFACE - Interface to COBOL, Btrieve record manager version 4
  5.     PAGE
  6.     .LIST
  7. ;-----------------------------------------------------------------
  8. ;COB_XFACE
  9. ;    This routine interfaces between COBOL programs and
  10. ;    Btrieve assembly routines.
  11. ;
  12. ;    Calling Procedure from COBOL
  13. ;      CALL 'BTRV' USING FUNCTION, STATUS, POSITION-BLOCK, DATA-RECORD,
  14. ;                   DATA-LEN, KEY-VALUE, KEY-NUMBER.
  15. ;          where
  16. ;        FUNCTION - function number for request
  17. ;        STATUS - return status from request
  18. ;        POSITION-BLOCK - 128 byte buffer containing position block
  19. ;        DATA-RECORD - User data buffer
  20. ;        DATA-LEN  - Length of the user's data buffer
  21. ;        KEY-VALUE - string pointer to key buffer
  22. ;        KEY-NUMBER - key number to be processed
  23. ;-----------------------------------------------------------------
  24. ;
  25. ;
  26. ;    Define parameter offsets on stack
  27. ;
  28. PARM_OFF  = 10
  29. FUNCTION   = PARM_OFF + 12
  30. STATUS       = PARM_OFF + 10
  31. POS_BLK    = PARM_OFF + 8
  32. DATA_REC   = PARM_OFF + 6
  33. DATA_LEN   = PARM_OFF + 4
  34. KEY_BUFFER = PARM_OFF + 2
  35. KEY_NUM    = PARM_OFF
  36. ;
  37. ;    Define offets within position block where FCB and
  38. ;    currency information are stored.
  39. ;
  40. FCB      = 0
  41. CUR      = 38
  42. ;
  43. VAR_ID        EQU    06176H    ;Variable record interface id
  44. BTR_ERR     EQU    20    ;Return status when Btrieve not initialized
  45. BTR_INT     EQU    07BH
  46. BTR2_INT    EQU    02FH
  47. MULTI_FUNCTION    EQU    0ABH
  48. BTR_OFFSET    EQU    033H
  49. BTR_VECTOR    EQU BTR_INT * 4 ;Absolute vector offset for interrupt
  50. CREATE        EQU    14    ;Create function call
  51. STAT        EQU    15    ;Stat function call
  52. CREATE_SUPP    EQU    31    ;Create supplemental index call
  53. ;
  54.     INCLUDE USERSEG.MAC
  55. ;
  56.     START_CSEG BTRV
  57.     JMP    SHORT START
  58. ;
  59. USER_BUF_ADDR    DD    ?        ;callers data buffer offset
  60. USER_BUF_LEN    DW    ?        ;length of callers data buffer
  61. USER_CUR_ADDR    DD    ?        ;callers currency info offset
  62. USER_FCB_ADDR    DD    ?        ;disk FCB for current request
  63. USER_FUNCTION    DW    ?        ;requested function
  64. USER_KEY_ADDR    DD    ?        ;callers key buffer offset
  65. USER_KEY_LENGTH DB    ?        ;length of key buffer
  66. USER_KEY_NUMBER DB    ?        ;key of reference for request
  67. USER_STAT_ADDR    DD    ?        ;callers status word offset
  68. XFACE_ID    DW    ?        ;language identifier
  69. ;
  70. PROCID        DW    0        ;Process Id for use by BMulti
  71. MULTI        DW    0
  72. VSET        DW    0
  73. ;
  74. START:
  75. ;
  76. ;    save callers segment and establish current segments
  77. ;
  78.     PUSH    ES            ;save callers segment registers
  79.     PUSH    DS
  80.     PUSH    BP
  81.     PUSH    DS            ;ES := users DS
  82.     POP    ES
  83.     PUSH    CS            ;DS used by index routines
  84.     POP    DS
  85.     MOV    BP,SP            ;set base parm list
  86. ;
  87. ;    ensure Btrieve has been initialized
  88. ;
  89.     PUSH    ES
  90.     PUSH    BX
  91.     MOV    AX,3500H + BTR_INT
  92.     INT    21H
  93.     CMP    BX,BTR_OFFSET        ;Has Btrieve been initialized?
  94.     POP    BX
  95.     POP    ES
  96.     JE    BAS_10            ;  Yes
  97.     MOV    BX,[BP]+STATUS        ;BX = status offset
  98.     MOV    AX,BTR_ERR
  99.     xchg    ah,al
  100.     MOV    ES:[BX],AX        ;Set return status
  101.     JMP    BAS_16            ;Skip interrupt since invalid
  102. BAS_10:
  103.     CMP    VSET,0
  104.     JNE    BAS_11
  105.     INC    VSET
  106.     PUSH    AX
  107.     MOV    AX,3000H
  108.     INT    21H
  109.     CMP    AL,3
  110.     POP    AX
  111.     JB    BAS_11
  112.     MOV    AX,MULTI_FUNCTION * 256
  113.     INT    BTR2_INT
  114.     CMP    AL,'M'
  115.     JNE    BAS_11
  116.     INC    MULTI
  117. BAS_11:
  118. ;
  119. ;    get function parameter
  120. ;
  121.     MOV    SI,[BP]+FUNCTION    ;get function address
  122.     MOV    CX,ES:[SI]        ;get function number
  123.     XCHG    CL,CH
  124.     MOV    USER_FUNCTION,CX
  125. ;
  126. ;    get address of callers status word from parameter
  127. ;
  128.     MOV    CX,[BP]+STATUS        ;get address of status word
  129.     MOV    WORD PTR USER_STAT_ADDR,CX
  130.     MOV    WORD PTR USER_STAT_ADDR+2,ES
  131. ;
  132. ;    get position block
  133. ;
  134.     MOV    BX,[BP]+POS_BLK     ;BX = address of position block
  135.     LEA    AX,[BX]+FCB        ;get diskette file block addr
  136.     MOV    WORD PTR USER_FCB_ADDR,AX
  137.     MOV    WORD PTR USER_FCB_ADDR+2,ES
  138.     LEA    AX,[BX]+CUR        ;get currency block addr
  139.     MOV    WORD PTR USER_CUR_ADDR,AX
  140.     MOV    WORD PTR USER_CUR_ADDR+2,ES
  141. ;
  142. ;    get data buffer
  143. ;
  144.     MOV    BX,[BP]+DATA_REC
  145.     MOV    WORD PTR USER_BUF_ADDR,BX
  146.     MOV    WORD PTR USER_BUF_ADDR+2,ES
  147. ;
  148. ;    get data buffer length
  149. ;
  150.     MOV    SI,[BP]+DATA_LEN    ;get data length address
  151.     MOV    CX,ES:[SI]        ;get data length
  152.     XCHG    CL,CH
  153.     MOV    USER_BUF_LEN,CX
  154. ;
  155. ;    get callers key buffer address and length
  156. ;
  157.     MOV    BX,[BP]+KEY_BUFFER    ;get key buffer addr
  158.     MOV    WORD PTR USER_KEY_ADDR,BX
  159.     MOV    WORD PTR USER_KEY_ADDR+2,ES
  160.     MOV    USER_KEY_LENGTH,255    ;set key length to max
  161. ;
  162. ;    get key number parameter
  163. ;
  164.     MOV    SI,[BP]+KEY_NUM     ;get key number address
  165.     MOV    CX,ES:[SI]        ;get key number
  166.     MOV    USER_KEY_NUMBER,CH
  167. ;
  168. ;    set language and go process request
  169. ;
  170.     MOV    XFACE_ID,VAR_ID     ;get interface id
  171.     LEA    DX,USER_BUF_ADDR    ;DX => user parms
  172.     CALL    PRE_SW
  173. ;
  174. ;
  175. ;
  176.     CMP    MULTI,0
  177.     JE    NOT_MULTI
  178. MAKE_CALL:
  179.     XOR    AX,AX
  180.     INC    AX            ;Initialize function setting for BMulti
  181.     MOV    BX,PROCID        ;Set Process id for BMulti
  182.     OR    BX,BX            ;Do we need to get a process id?
  183.     JE    CALL_MULTI        ;  Yes, Let BMulti know
  184.     INC    AX            ;Tell BMulti you have a process id
  185. CALL_MULTI:
  186.     MOV    AH,MULTI_FUNCTION
  187.     INT    BTR2_INT
  188.     CMP    AL,0
  189.     JE    DONE_CALL
  190.     MOV    AX,200H
  191.     INT    7FH
  192.     JMP    SHORT MAKE_CALL
  193. DONE_CALL:
  194.     CMP    PROCID,0
  195.     JNE    BAS_12
  196.     MOV    PROCID,BX
  197.     JMP    BAS_12
  198. NOT_MULTI:
  199.     INT    BTR_INT         ;process request
  200. BAS_12:
  201.     CALL    POST_SW
  202. BAS_15:
  203. ;
  204. ;    restore callers stack and segment before returning
  205. ;
  206.     MOV    CX,USER_BUF_LEN     ;data length returned
  207.     XCHG    CL,CH
  208.     MOV    BX,[BP]+DATA_LEN    ;address of data length
  209.     MOV    ES:[BX],CX        ;set user's data length
  210. BAS_16:
  211.     MOV    BX,[BP]+STATUS        ;get users status
  212.     MOV    AX,ES:[BX]        ; since COBOL reverses bytes
  213.     XCHG    AH,AL
  214.     MOV    ES:[BX],AX        ; new user status
  215.     POP    BP
  216.     POP    DS
  217.     POP    ES
  218. ;
  219. ;    bytes to pop off stack = number parameters * 2 (including status)
  220. ;
  221.     RET    14            ;return to caller
  222. ;
  223. ;
  224. ; These routines are used to put the control blocks for CREATE
  225. ; and STAT into a regular form.  Cobol always reverses the high and
  226. ; low order byte in words.
  227. ;
  228. POST_SW PROC    NEAR
  229.     CMP    USER_FUNCTION,STAT    ;if stat function
  230.     JE    POST_10         ; do switch
  231. PRE_SW    LABEL    NEAR
  232.     CMP    USER_FUNCTION,CREATE    ;if create function then
  233.     JE    POST_10         ; do switch
  234.     CMP    USER_FUNCTION,CREATE_SUPP    ;if not create supp,
  235.     JNE    POST_99         ; skip switch
  236. POST_10:
  237.     PUSH    AX
  238.     PUSH    BX
  239.     PUSH    CX
  240.     PUSH    DX
  241.     PUSH    SI
  242.     PUSH    DS
  243.     MOV    DX,USER_FUNCTION
  244.     LDS    BX,USER_BUF_ADDR    ;BX => file structure
  245.     PUSH    BX            ;save BX for later
  246.     MOV    CX,8            ;8 words in the header
  247. POST_20:
  248.     MOV    AX,[BX]         ;get word
  249.     XCHG    AL,AH            ;exchange bytes
  250.     MOV    [BX],AX         ;replace word as COBOL expects it
  251.     INC    BX
  252.     INC    BX
  253.     LOOP    POST_20
  254.     POP    SI            ;SI = old BX
  255.     MOV    CX,4[SI]        ;cx = # keys
  256.     CMP    CH,0
  257.     JE    POST_25
  258.     XCHG    CL,CH
  259. POST_25:
  260.     CMP    CX,24            ;if > max indexex then
  261.     JA    POST_90         ; must be a bad specification
  262. ;
  263. ; test for any segmented key specs
  264. ;
  265.     PUSH    BX            ;BX -> 1st key spec
  266.     SUB    BX,16
  267.     SUB    AX,AX
  268. POST_27:
  269.     INC    AX
  270.     ADD    BX,16
  271.     CMP    DX,CREATE
  272.     JNE    POST_28
  273.     TEST    WORD PTR 4[BX],1000h    ;Does this spec have another segment
  274.     JNE    POST_27         ; yes
  275.     JMP    SHORT POST_29
  276. POST_28:
  277.     TEST    WORD PTR 4[BX],0010h    ;Does this spec have another segment
  278.     JNE    POST_27         ; yes
  279. POST_29:
  280.     LOOP    POST_27
  281.     POP    BX            ;BX -> 1st key spec
  282.     MOV    CX,AX            ;CX = real number of key specs
  283. ;
  284. ; now which the total number of key specs
  285. ;
  286.     MOV    AL,8            ;number of words in key spec
  287.     MUL    CL
  288.     MOV    CX,AX            ;CX = number of words in key specs
  289. POST_30:
  290.     MOV    AX,[BX]         ;get word
  291.     XCHG    AL,AH            ;exchange bytes
  292.     MOV    [BX],AX         ;replace word as COBOL expects it
  293.     INC    BX
  294.     INC    BX
  295.     LOOP    POST_30
  296. POST_90:
  297.     POP    DS
  298.     POP    SI
  299.     POP    DX
  300.     POP    CX
  301.     POP    BX
  302.     POP    AX
  303. POST_99:
  304.     RET
  305. POST_SW ENDP
  306.     END_CSEG BTRV
  307.     END
  308.