home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / xbase / library / clipper / rettig / source / dosfunc.asm < prev    next >
Assembly Source File  |  1990-10-21  |  7KB  |  258 lines

  1. ; DOSFUNC.ASM
  2. ;
  3. ; by Ralph Davis
  4. ; modified by Rick Spence
  5. ;
  6. ; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  7. ;
  8.  
  9.             PUBLIC DOSFUNC
  10.  
  11.             EXTRN __TR_HTOI:FAR    ; Library C function (hex-to-integer)
  12.             EXTRN __TR_ITOD:FAR    ; Library C function (integer-to-double)
  13.             EXTRN __TR_HEXASM:FAR  ; Produces hex string
  14.  
  15. PARMS_IN    STRUC
  16.  
  17. BP_OLD      DW      ?
  18. RET_ADDR    DD      ?
  19. IN_PARM     DD      ?
  20. FLAG_PARM   DD      ?
  21.  
  22. PARMS_IN    ENDS
  23.  
  24. ;****************************************
  25. DOSFUNC_TEXT SEGMENT BYTE PUBLIC 'CODE'
  26.             ASSUME  CS:DOSFUNC_TEXT
  27. ;----------------------------------------
  28. DOSFUNC     PROC    FAR            ; DOS INT 21H interface
  29.             JMP     SHORT GO
  30.  
  31. PCOUNT      DW      0              ; Counts parameters passed
  32. SAVE_COUNT  DW      8              ; Saves count
  33. THIS_PARM   DB      4 DUP (?),0    ; Holds current parameter
  34.  
  35. ; Register values passed
  36.  
  37. AX_IN       DW      ?
  38. BX_IN       DW      ?   
  39. CX_IN       DW      ?
  40. DX_IN       DW      ?
  41. SI_IN       DW      ?
  42. DI_IN       DW      ?
  43. DS_IN       DW      ?
  44. ES_IN       DW      ?
  45.  
  46. ; Register return values
  47.  
  48. AX_OUT      DW      ?
  49. BX_OUT      DW      ?
  50. CX_OUT      DW      ?
  51. DX_OUT      DW      ?
  52. SI_OUT      DW      ?
  53. DI_OUT      DW      ?
  54. DS_OUT      DW      ?
  55. ES_OUT      DW      ?
  56.  
  57. ; Parameter pointer table
  58.  
  59. PARM1_PTR   DW      ?
  60.             DW      ?
  61. PARM2_PTR   DW      ?
  62.             DW      ?
  63. PARM3_PTR   DW      ?
  64.             DW      ?
  65. PARM4_PTR   DW      ?
  66.             DW      ?
  67. PARM5_PTR   DW      ?
  68.             DW      ?
  69. PARM6_PTR   DW      ?
  70.             DW      ?
  71. PARM7_PTR   DW      ?
  72.             DW      ?
  73. PARM8_PTR   DW      ?
  74.             DW      ?
  75.  
  76. REG_AX      DW      PARM1          ; Jump table
  77. REG_BX      DW      PARM2
  78. REG_CX      DW      PARM3
  79. REG_DX      DW      PARM4
  80. REG_SI      DW      PARM5
  81. REG_DI      DW      PARM6
  82. REG_DS      DW      PARM7
  83. REG_ES      DW      PARM8
  84.  
  85.  
  86. GO:         PUSH    BP
  87.             MOV     BP,SP
  88.             PUSH    DS
  89.             PUSH    ES
  90.             PUSH    AX
  91.             PUSH    BX
  92.             PUSH    CX
  93.             PUSH    DX
  94.             PUSH    SI
  95.             PUSH    DI
  96.             CLD
  97.             XOR     AX,AX
  98.             MOV     CS:PCOUNT,AX   ; Initialize parameter counter to 0
  99.             MOV     CX,16          ; Initialize parameter pointer table
  100.             PUSH    CS             ;    (all zeroes)
  101.             POP     ES
  102.             MOV     DI,OFFSET CS:PARM1_PTR
  103.             REP     STOSW
  104. GET_PARM:   LDS     SI,[BP].IN_PARM
  105.             MOV     DI,OFFSET CS:THIS_PARM
  106.             CALL    CONV_PARM             ; CONV_PARM adds 4 to SI
  107.             INC     CS:PCOUNT
  108.             CALL    CONV_PARM
  109.             INC     CS:PCOUNT
  110.             CALL    CONV_PARM
  111.             INC     CS:PCOUNT
  112.             CALL    CONV_PARM
  113.             INC     CS:PCOUNT
  114.             CALL    CONV_PARM
  115.             INC     CS:PCOUNT
  116.             CALL    CONV_PARM
  117.             INC     CS:PCOUNT
  118.             CALL    CONV_PARM
  119.             INC     CS:PCOUNT
  120.             CALL    CONV_PARM
  121.             INC     CS:PCOUNT
  122.  
  123.             INT     21H
  124.             PUSHF
  125.             MOV     CS:ES_OUT,ES
  126.             MOV     CS:DS_OUT,DS
  127.             MOV     CS:DI_OUT,DI
  128.             MOV     CS:SI_OUT,SI
  129.             MOV     CS:DX_OUT,DX
  130.             MOV     CS:CX_OUT,CX
  131.             MOV     CS:BX_OUT,BX
  132.             MOV     CS:AX_OUT,AX
  133.             MOV     CX,CS:SAVE_COUNT
  134. RET_PARM:   MOV     SI,CX
  135.             DEC     SI
  136.             SHL     SI,1
  137.             XOR     AX,AX
  138.             PUSH    AX
  139.             PUSH    CS:[AX_OUT][SI]
  140.             CALL    __TR_HEXASM
  141.             ADD     SP,4
  142.             SHL     SI,1
  143.             MOV     ES,CS:[PARM1_PTR][SI+2]       ; Destination string pointer
  144.             MOV     DI,CS:[PARM1_PTR][SI]
  145.             MOV     DS,DX                       ; Source string pointer
  146.             MOV     SI,AX
  147.             PUSH    CX
  148.             MOV     CX,4
  149.             REP     MOVSB
  150.             POP     CX
  151.             LOOP    RET_PARM
  152.             JMP     SHORT EXIT
  153. ERROR_EXIT: 
  154.             STC                  ; DOS uses Carry flag for error signal
  155. EXIT:       LDS     SI,[BP].FLAG_PARM
  156.             POPF
  157.             PUSHF
  158.             POP     AX
  159.             MOV    [SI],AX
  160.             POP     DI
  161.             POP     SI
  162.             POP     DX
  163.             POP     CX
  164.             POP     BX
  165.             POP     AX
  166.             POP     ES
  167.             POP     DS
  168.             POP     BP
  169.             RET
  170. DOSFUNC     ENDP
  171. ;----------------------------------------------------
  172. CONV_PARM   PROC    NEAR
  173.             MOV     BX,CS:PCOUNT
  174.             PUSH    BX
  175.             SHL     BX,1
  176.             SHL     BX,1
  177.             MOV     CS:PARM1_PTR[BX],SI
  178.             MOV     CS:PARM1_PTR[BX+2],DS
  179.             PUSH    CX
  180.             MOV     CX,4
  181.     
  182.             ; DS:SI points to instring--ES:DI points to THIS_PARM
  183.             REP     MOVSB
  184.             SUB     DI,4
  185.             PUSH    DX
  186.             PUSH    SI             ; at this point, SI points to next parm 
  187.             PUSH    ES             ; pass location
  188.             PUSH    DI
  189.             CALL    __TR_HTOI           ; AX now holds integer value
  190.             POP     DI
  191.             POP     ES
  192.             POP     SI
  193.             POP     DX
  194.             POP     CX
  195.             POP     BX             ; Retrieve PCOUNT
  196.             SHL     BX,1           ; PCOUNT becomes offset into 
  197.                                    ; jump table
  198.             CALL    CS:[REG_AX][BX]
  199.             RET
  200. CONV_PARM   ENDP
  201. ;--------------------------------------------
  202. PARM1       PROC    NEAR
  203.             MOV     CS:AX_IN,AX
  204.             RET
  205. PARM1       ENDP
  206. ;----------------------------------------------------
  207. PARM2       PROC    NEAR
  208.             MOV     CS:BX_IN,AX
  209.             RET
  210. PARM2       ENDP
  211. ;----------------------------------------------------
  212. PARM3       PROC    NEAR
  213.             MOV     CS:CX_IN,AX
  214.             RET
  215. PARM3       ENDP
  216. ;----------------------------------------------------
  217. PARM4       PROC    NEAR
  218.             MOV     CS:DX_IN,AX
  219.             RET
  220. PARM4       ENDP
  221. ;----------------------------------------------------
  222. PARM5       PROC    NEAR
  223.             MOV     CS:SI_IN,AX
  224.             RET
  225. PARM5       ENDP
  226. ;----------------------------------------------------
  227. PARM6       PROC    NEAR
  228.             MOV     CS:DI_IN,AX
  229.             RET
  230. PARM6       ENDP
  231. ;----------------------------------------------------
  232. PARM7       PROC    NEAR
  233.             MOV     CS:DS_IN,AX
  234.             RET
  235. PARM7       ENDP
  236. ;----------------------------------------------------
  237. PARM8       PROC    NEAR
  238.             MOV     BX,CS:BX_IN
  239.             MOV     CX,CS:CX_IN
  240.             MOV     DX,CS:DX_IN
  241.             MOV     SI,CS:SI_IN
  242.             MOV     DI,CS:DI_IN
  243.             CMP     CS:DS_IN,0
  244.             JE      PARM8_ES
  245. PARM8_DS:   MOV     DS,CS:DS_IN
  246.  
  247. PARM8_ES:   CMP     AX,0
  248.             JE      PARM8_RET
  249.             MOV     ES,AX
  250. PARM8_RET:  MOV     AX,AX_IN
  251.             RET
  252. PARM8       ENDP
  253. ;----------------------------------------------------
  254. DOSFUNC_TEXT       ENDS
  255. ;****************************************************
  256.             END
  257.  
  258.