home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / graspext / graspext.doc < prev    next >
Encoding:
Text File  |  1986-09-06  |  5.1 KB  |  183 lines

  1. GRASP Advanced Technical Document number 0001                   Doug Wolfgram
  2. -----------------------------------------------------------------------------
  3.  
  4. Calling GRASP functions from external programs   --------   September 6, 1986
  5.  
  6.      written by and for Microtex Industries, Inc. - Irvine, California
  7.  
  8. -----------------------------------------------------------------------------
  9.  
  10. GRASP version required:  GRASP version 1.10c - September 1986
  11.  
  12. This and all subsequent versions of GRASP have a function within them which
  13. allows the GRASP functions to be called from external sources. This was
  14. accomplished by defining function 'G' under interrupt 10h to pass a string
  15. to the resident GRASP routines which is nothing more than a simple GRASP
  16. command. The definition of the INT 10h function is as follows:
  17.  
  18. on entry:
  19.  
  20. Interrupt 10h
  21.  
  22. AH - contains the function number, 'G' 
  23. CX - contains the length of the string
  24. DX - contains a pointer to the string 
  25.  
  26. The general theory for applying this is to create a function which does this
  27. for your programming language, then to write and compile your program
  28. including calls to this function. In some cases, it will be in-line code
  29. while in others it may be a routine in one of your libraries, or it may also
  30. be an external function, as in our TPASCAL example in this document. Then,
  31. create a simple GRASP program (perhaps only one line!) which EXECs to your
  32. program. This will load the GRASP routines in memory and place them in 
  33. available range for your program to use. 
  34.  
  35. -----------------------------------------------------------------------------
  36. Some specific Examples 1: Generic 'C' function.
  37.  
  38. For most 'C' compilers, it is best to create a function which you can link
  39. with your program, either stand alone, or in a library. The function, written
  40. here for CI-C86 or AZTEC/MANX C, is quite simple.
  41.  
  42.  
  43. ; CTOGR.ASM
  44. ;
  45. ; written by John Bridges
  46. ;
  47. ; Call GRASP functions from your 'C' programs
  48. ;
  49. ; after assembling and linking this routine with your 'C' program, you would
  50. ; execute GRASP commands by entering 'C' function calls like:
  51. ;
  52. ; grasp("video a\r");
  53. ; grasp("pload picture1,1\r");
  54. ; grasp("pfade 20,1\r");
  55. ;
  56. ;
  57. codeseg segment para public 'code'
  58.     assume cs:codeseg
  59.  
  60.     extrn    strlen:near
  61.     public    grasp
  62.  
  63. grasp    proc    near        ; grasp(string)
  64.     push    bp
  65.     mov    bp,sp
  66.     mov    ax,4[bp]    ; pointer to string
  67.     push    ax
  68.     call    strlen        ; standard C function to return length
  69.     add    sp,2
  70.     mov    cx,ax        ; put length into CX
  71.     mov    dx,4[bp]    ; get pointer into DX
  72.     mov    ax,ds
  73.     mov    es,ax        ; set ES to data segment
  74.     mov    ah,'G'        ; load function number
  75.     int    10h        ; execute it!
  76.     pop    bp
  77.     ret
  78. grasp    endp
  79.  
  80. codeseg    ends
  81.     end
  82.  
  83. Here is a sample 'C' program to illustrate how it works:
  84.  
  85. /*******************************
  86.             CTEST.C 
  87.       sample test program
  88. ********************************/
  89. #include "stdio.h"
  90.  
  91. main()
  92. {
  93.     grasp("text 0,0,\"Hi there number 1\"\r\n");
  94. }
  95.  
  96. Compile and link with ctogr.obj and your standard 'C' library.
  97.  
  98. Then, here is a sample GRASP program to call it:
  99.  
  100. video 1
  101. exec ctest.exe
  102. text 0,5,"Hi there number 2"
  103. waitkey
  104.  
  105. The EXEC command will cause your program to call GRASP to print the first
  106. message, then GRASP back under its own control will print the second, then
  107. GRASP will wait for a keypress to end.
  108.  
  109. -----------------------------------------------------------------------------
  110. Some specific Examples 2: Turbo Pascal function.
  111.  
  112. For Turbo Pascal, we will create an external COM file which contains the
  113. calling function to GRASP, and then refer to it as an external function
  114. call with TPascal. The external file is similar to our example for 'C':
  115.  
  116. ; GREXT.ASM - external function call for TPascal to interface to GRASP
  117. ;
  118. code    segment
  119.     assume    cs:code
  120.  
  121. grasp    proc    near
  122.     push    bp
  123.     mov    bp,sp
  124.     les    dx,[bp+4]
  125.     push    bx
  126.     mov    bx,dx
  127.     mov    cl,es:[bx]
  128.     pop    bx
  129.     mov    ch,0
  130.     mov    al,0
  131.     mov    ah,'G'
  132.     int    10h
  133.     mov    sp,bp
  134.     pop    bp
  135.     ret    4
  136. grasp    endp
  137.  
  138. code    ends
  139.     end
  140.  
  141. This should be assembled and linked and then converted to a .COM file. The
  142. GREXT.COM file in this example is provided for your convenience.
  143.  
  144. Then, create your TPascal file, which should be something like:
  145.  
  146. type
  147.   anystring   = string[255];
  148.  
  149. var
  150.   grcmd: anystring;
  151.  
  152. procedure grasp(var grcmd: anystring); external 'grext.com';
  153.  
  154. begin
  155.   readln(grcmd);
  156.   grcmd:=grcmd+chr(13)+chr(10);
  157.   grasp(grcmd);
  158. end.
  159.  
  160. This particular example prompts you for a line which is a command in
  161. GRASP, then passes it to GRASP.
  162.  
  163. And, as in the 'C' example, your GRASP
  164. program which calls your TPascal which calls your external function:
  165.  
  166. video A
  167. color 3
  168. exec ptest.com
  169. text 5,4,"hi there how are you today"
  170. waitkey
  171.  
  172. You will notice that this example sets the video mode to A, then the
  173. program it calls (which is above) prompts you for a string. Type in
  174. video 1, which is 80 column text. Then notice how the rest of the GRASP
  175. program runs in that video mode. Notice also, that by applying the patch
  176. defined in TURBO.PAT we are able to run a TPascal program without
  177. screwing up the video mode!
  178.  
  179. -----------------------------------------------------------------------------
  180.  
  181.  
  182.  
  183.