home *** CD-ROM | disk | FTP | other *** search
- GRASP Advanced Technical Document number 0001 Doug Wolfgram
- -----------------------------------------------------------------------------
-
- Calling GRASP functions from external programs -------- September 6, 1986
-
- written by and for Microtex Industries, Inc. - Irvine, California
-
- -----------------------------------------------------------------------------
-
- GRASP version required: GRASP version 1.10c - September 1986
-
- This and all subsequent versions of GRASP have a function within them which
- allows the GRASP functions to be called from external sources. This was
- accomplished by defining function 'G' under interrupt 10h to pass a string
- to the resident GRASP routines which is nothing more than a simple GRASP
- command. The definition of the INT 10h function is as follows:
-
- on entry:
-
- Interrupt 10h
-
- AH - contains the function number, 'G'
- CX - contains the length of the string
- DX - contains a pointer to the string
-
- The general theory for applying this is to create a function which does this
- for your programming language, then to write and compile your program
- including calls to this function. In some cases, it will be in-line code
- while in others it may be a routine in one of your libraries, or it may also
- be an external function, as in our TPASCAL example in this document. Then,
- create a simple GRASP program (perhaps only one line!) which EXECs to your
- program. This will load the GRASP routines in memory and place them in
- available range for your program to use.
-
- -----------------------------------------------------------------------------
- Some specific Examples 1: Generic 'C' function.
-
- For most 'C' compilers, it is best to create a function which you can link
- with your program, either stand alone, or in a library. The function, written
- here for CI-C86 or AZTEC/MANX C, is quite simple.
-
-
- ; CTOGR.ASM
- ;
- ; written by John Bridges
- ;
- ; Call GRASP functions from your 'C' programs
- ;
- ; after assembling and linking this routine with your 'C' program, you would
- ; execute GRASP commands by entering 'C' function calls like:
- ;
- ; grasp("video a\r");
- ; grasp("pload picture1,1\r");
- ; grasp("pfade 20,1\r");
- ;
- ;
- codeseg segment para public 'code'
- assume cs:codeseg
-
- extrn strlen:near
- public grasp
-
- grasp proc near ; grasp(string)
- push bp
- mov bp,sp
- mov ax,4[bp] ; pointer to string
- push ax
- call strlen ; standard C function to return length
- add sp,2
- mov cx,ax ; put length into CX
- mov dx,4[bp] ; get pointer into DX
- mov ax,ds
- mov es,ax ; set ES to data segment
- mov ah,'G' ; load function number
- int 10h ; execute it!
- pop bp
- ret
- grasp endp
-
- codeseg ends
- end
-
- Here is a sample 'C' program to illustrate how it works:
-
- /*******************************
- CTEST.C
- sample test program
- ********************************/
- #include "stdio.h"
-
- main()
- {
- grasp("text 0,0,\"Hi there number 1\"\r\n");
- }
-
- Compile and link with ctogr.obj and your standard 'C' library.
-
- Then, here is a sample GRASP program to call it:
-
- video 1
- exec ctest.exe
- text 0,5,"Hi there number 2"
- waitkey
-
- The EXEC command will cause your program to call GRASP to print the first
- message, then GRASP back under its own control will print the second, then
- GRASP will wait for a keypress to end.
-
- -----------------------------------------------------------------------------
- Some specific Examples 2: Turbo Pascal function.
-
- For Turbo Pascal, we will create an external COM file which contains the
- calling function to GRASP, and then refer to it as an external function
- call with TPascal. The external file is similar to our example for 'C':
-
- ; GREXT.ASM - external function call for TPascal to interface to GRASP
- ;
- code segment
- assume cs:code
-
- grasp proc near
- push bp
- mov bp,sp
- les dx,[bp+4]
- push bx
- mov bx,dx
- mov cl,es:[bx]
- pop bx
- mov ch,0
- mov al,0
- mov ah,'G'
- int 10h
- mov sp,bp
- pop bp
- ret 4
- grasp endp
-
- code ends
- end
-
- This should be assembled and linked and then converted to a .COM file. The
- GREXT.COM file in this example is provided for your convenience.
-
- Then, create your TPascal file, which should be something like:
-
- type
- anystring = string[255];
-
- var
- grcmd: anystring;
-
- procedure grasp(var grcmd: anystring); external 'grext.com';
-
- begin
- readln(grcmd);
- grcmd:=grcmd+chr(13)+chr(10);
- grasp(grcmd);
- end.
-
- This particular example prompts you for a line which is a command in
- GRASP, then passes it to GRASP.
-
- And, as in the 'C' example, your GRASP
- program which calls your TPascal which calls your external function:
-
- video A
- color 3
- exec ptest.com
- text 5,4,"hi there how are you today"
- waitkey
-
- You will notice that this example sets the video mode to A, then the
- program it calls (which is above) prompts you for a string. Type in
- video 1, which is 80 column text. Then notice how the rest of the GRASP
- program runs in that video mode. Notice also, that by applying the patch
- defined in TURBO.PAT we are able to run a TPascal program without
- screwing up the video mode!
-
- -----------------------------------------------------------------------------
-
-
-