home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_int86.asm < prev    next >
Assembly Source File  |  1993-06-06  |  9KB  |  283 lines

  1.     PAGE        60,132
  2.     INCLUDE     EXTENDA.MAC
  3.  
  4.     PUBLIC        GT_INT86
  5.  
  6. ;;
  7. ;; GT CLIPPER STANDARD HEADER
  8. ;;
  9. ;; File......: gt_int86.asm
  10. ;; Author....: Brian Dukes & Andy "Dr. VxD" Sawyer
  11. ;; BBS.......: THE CELLAR bbs
  12. ;; Net/Node..: 013/203
  13. ;; User Name.: Brian Dukes
  14. ;; Date......: 12/5/93
  15. ;; Revision..: 1.0
  16. ;;
  17. ;; This is an original work by Brian Dukes and is placed in the
  18. ;; public domain.
  19. ;;
  20. ;; Modification history:
  21. ;; ---------------------
  22. ;; $Log$
  23. ;; 2/6/93 - BJD+AMS - Due to super clever stuff with 486 processor caching
  24. ;;                    this program didn't seem to work on a 486.  So changed
  25. ;;                    the code to call the dos interupt rather than self-
  26. ;;                    modifying code.
  27. ;;
  28. ;;    Thanks must go to Andy Sawyer, who showed me why the __storni funcs
  29. ;;    were not working properly.  He put the code in which sets up DS to
  30. ;;    point to DGROUP.
  31. ;;
  32. ;;
  33. ;;
  34. ;;  $DOC$
  35. ;;  $FUNCNAME$
  36. ;;      GT_INT86()
  37. ;;  $CATEGORY$
  38. ;;      System
  39. ;;  $ONELINER$
  40. ;;      Performs an interrupt function call.
  41. ;;  $SYNTAX$
  42. ;;      ret := GT_INT86(<intno>,@<AX>,@<BX>,@<CX>,@<DX>,@<SI>,@<DI>,
  43. ;;                      @<BP>,@<DS>,@<ES>)
  44. ;;  $ARGUMENTS$
  45. ;;      <intno> - Interrupt Function number to call  (33dec = int 21h)
  46. ;;      <AX>    - Input register value of AX - PASSED BY REFERENCE
  47. ;;      <BX>    - Input register value of BX - PASSED BY REFERENCE
  48. ;;      <CX>    - Input register value of CX - PASSED BY REFERENCE
  49. ;;      <DX>    - Input register value of DX - PASSED BY REFERENCE
  50. ;;      <SI>    - Input register value of SI - PASSED BY REFERENCE
  51. ;;      <DI>    - Input register value of DI - PASSED BY REFERENCE
  52. ;;      <BP>    - Input register value of BP - PASSED BY REFERENCE
  53. ;;      <DS>    - Input register value of DS - PASSED BY REFERENCE
  54. ;;      <ES>    - Input register value of ES - PASSED BY REFERENCE
  55. ;;  $RETURNS$
  56. ;;      <ret>   - The value of carry flag!
  57. ;;      <AX>    - Output register value of AX
  58. ;;      <BX>    - Output register value of BX
  59. ;;      <CX>    - Output register value of CX
  60. ;;      <DX>    - Output register value of DX
  61. ;;      <SI>    - Output register value of SI
  62. ;;      <DI>    - Output register value of DI
  63. ;;      <BP>    - Output register value of BP
  64. ;;      <DS>    - Output register value of DS
  65. ;;      <ES>    - Output register value of ES
  66. ;;  $DESCRIPTION$
  67. ;;      This little <grin> function allows your Clipper application to make
  68. ;;      use of dos functions and interrupts, such as scrolling screens, direct
  69. ;;      disk access, video bios calls, etc.
  70. ;;
  71. ;;      It works by setting up Register Variables in your Clipper program
  72. ;;      and passing them in to GT_INT86() by REFERENCE; this is important
  73. ;;      if you want to see what the outcome of those registers are on return
  74. ;;      from the dos function.  Although, this will still work if you do not
  75. ;;      pass by reference - you obviosly will not be returned any of the
  76. ;;      outgoing register values.
  77. ;;
  78. ;;      In addition to updating the registers, it will return the carry flag
  79. ;;      to the calling process.  If 0 is returned by the function then the
  80. ;;      carry flag was not set after performing your dos function.  If 1 is
  81. ;;      returned then the carry flag was set (usually indicating an error).
  82. ;;
  83. ;;  $EXAMPLES$
  84. ;;
  85. ;;
  86. ;;      #translate makehi( <X> )   => (<X> * (2 ^ 8))
  87. ;;      #translate highbyte( <X> ) => int( <X> / 256 )
  88. ;;      #translate lowbyte( <X> )  => int( <X> % 256 )
  89. ;;
  90. ;;      local s := "Hello World$"
  91. ;;      local rax := 0
  92. ;;      local rbx := 0
  93. ;;      local rcx := 0
  94. ;;      local rdx := 0
  95. ;;      local rsi := 0
  96. ;;      local rdi := 0
  97. ;;      local rbp := 0
  98. ;;      local rds := 0
  99. ;;      local res := 0
  100. ;;      local inter := 0
  101. ;;      local ret := 0
  102. ;;
  103. ;;      rax := makehi(9)
  104. ;;      rds := gt_segment(s)
  105. ;;      rdx := gt_offset(s)
  106. ;;
  107. ;;      ret := gt_int86(33, rax, rbx, rcx, rdx, rsi, rdi, rbp, rds, res)
  108. ;;      /* The above line Displays Hello World */
  109. ;;
  110. ;;      * The following will get the current date
  111. ;;      rax := makehi(42)
  112. ;;      inter := 33
  113. ;;      ret := gt_int86(33,@rax,@rbx,@rcx,@rdx,@rsi,@rdi,@rbp,@rds,@res)
  114. ;;
  115. ;;      * Returns  AL = DOW,  CX = Year,  DH = Month,  DL = Day
  116. ;;      ? "it's the "+str(lowbyte(rax))+" Day of the Week"
  117. ;;      ? "The Date Is : "
  118. ;;      ?? lowbyte(rdx)
  119. ;;      ?? "/"
  120. ;;      ?? highbyte(rdx)
  121. ;;      ?? "/"
  122. ;;      ?? rcx
  123. ;;      ?
  124. ;;      ? "Return : "+str(ret)
  125. ;;
  126. ;;  $SEEALSO$
  127. ;;      STRING.EHO:GT_Segment()   STRING.EHO:GT_Offset()
  128. ;;  $END$
  129. ;;
  130.  
  131. ;;;;; Assembled Using MASM
  132.  
  133.  
  134.  
  135. PUT_INT    MACRO    parm,val
  136.     mov    ax,parm
  137.     push    ax
  138.     mov    ax,val
  139.     push    ax
  140.     call    __storni
  141.     add    sp,4
  142.     ENDM
  143.  
  144.          EXTRN    __STORNI:FAR
  145.  
  146. DGROUP GROUP datasg
  147.  
  148. datasg    segment    public para    'DATA'        ; start of data segment
  149. ;
  150. ; Parameters :  Int, AX, BX, CX, DX, SI, DI, BP, DS, ES
  151. _GT_RAX dw    0h
  152. _GT_RBX dw    0h
  153. _GT_RCX dw    0h
  154. _GT_RDX dw    0h
  155. _GT_RSI dw    0h
  156. _GT_RDI dw    0h
  157. _GT_RBP dw    0h
  158. _GT_RDS dw    0h
  159. _GT_RES dw    0h
  160. _GT_CAR dw      0h
  161. ;
  162. datasg    ends                        ; end of data segment
  163. ;
  164. ;
  165.  
  166. _code segment byte public 'CODE'
  167.  
  168. assume          cs:_code,ds:nothing,es:nothing
  169.  
  170. GT_INT86     PROC       FAR
  171.  
  172.              push       bp              ; Save registers
  173.              mov        bp,sp
  174.              push       es
  175.              push       si
  176.              push       di
  177.              push       bx
  178.              push       cx
  179.              push       dx
  180.              push       ds
  181.  
  182.              get_int    2     ; Get AX
  183.              push       ax
  184.              get_int    3     ; Get BX
  185.              push       ax
  186.              get_int    4     ; Get CX
  187.              push       ax
  188.              get_int    5     ; Get DX
  189.              push       ax
  190.              get_int    6     ; Get SI
  191.              push       ax
  192.              get_int    7     ; Get DI
  193.              push       ax
  194.              get_int    8     ; Get BP
  195.              push       ax
  196.              get_int    9     ; Get DS
  197.              push       ax
  198.              get_int    10    ; Get ES
  199.              push       ax
  200.              get_int    1     ; Get the interrupt number
  201.              push       ax
  202.  
  203.              pop        ax              ; Get the interrupt number and poke it into
  204.              mov        ah,35h
  205.              int        21h             ; Get DOS Interrupt Vector
  206.              mov        cs:_vecseg,ES
  207.              mov        cs:_vecoff,BX
  208.              pop        es              ; Grab the rest of the registers from Stack
  209.              pop        ds
  210.              pop        bp
  211.              pop        di
  212.              pop        si
  213.              pop        dx
  214.              pop        cx
  215.              pop        bx
  216.              pop        ax
  217.  
  218. ;; This junk emulates (almost) a software interrupt!
  219.  
  220.              pushf
  221.              cli
  222.              call       CS:[_vector]
  223.  
  224.              ; Make Sure DS points to DGROUP!!
  225.              push    ds
  226.          push    ax
  227.          mov    ax,SEG DGROUP
  228.          mov    ds,ax
  229.              assume     ds:DGROUP
  230.          pop    ax
  231.          mov    _GT_RAX,ax
  232.          pop    ax
  233.          mov    _GT_RDS,ax
  234.  
  235. ;; Andy's well trick bit of code for saving the carry flag
  236.              mov        ax,0
  237.              adc        ax,0
  238.              mov        _GT_CAR,ax
  239.  
  240.  
  241.              mov        _GT_RBX,BX   ; Save all of the returning Register Values
  242.              mov        _GT_RCX,CX
  243.              mov        _GT_RDX,DX
  244.              mov        _GT_RSI,SI
  245.              mov        _GT_RDI,DI
  246.              mov        _GT_RBP,BP
  247.              mov        _GT_RES,ES
  248.  
  249.          PUT_INT     2,_GT_RAX
  250.          PUT_INT     3,_GT_RBX
  251.              PUT_INT     4,_GT_RCX
  252.              PUT_INT     5,_GT_RDX
  253.              PUT_INT     6,_GT_RSI
  254.              PUT_INT     7,_GT_RDI
  255.              PUT_INT     8,_GT_RBP
  256.              PUT_INT     9,_GT_RDS
  257.              PUT_INT    10,_GT_RES
  258.  
  259.              mov        ax,_GT_CAR      ; Setup function return as Carry Flag
  260.              push       ax
  261.              call       __retni
  262.              add        sp,2
  263.  
  264.              pop        ds
  265.              pop        dx
  266.              pop        cx
  267.              pop        bx
  268.              pop        di              ; Restore registers
  269.              pop        si
  270.              pop        es
  271.              pop        bp
  272.  
  273.              ret                     ; Go on back to Clipper
  274.  
  275. _vector      label DWORD
  276. _vecoff      dw 0h
  277. _vecseg      dw 0h
  278. GT_INT86     ENDP                    ; End of routine
  279.  
  280. _code        ENDS                    ; End of code segment
  281.              END
  282.  
  283.