Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>program structure</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Program Structure


   To interface an assembly language routine to Clipper using the Extend
   System requires that you follow some specific rules.

   . Declare your routine PUBLIC.

   . Declare the Extend functions to be used as EXTRN and FAR or INCLUDE
     EXTENDA.INC which makes these declarations for you.

   . If you define your own data segment, group it together with
     Clipper's DGROUP.  Otherwise, DS must point to DGROUP before you
     call any Extend function.

   . Class your code segment PROG for Autumn '86 or CODE for Summer '87.

   . If you have not passed a value back to Clipper, call __RET just
     before your assembler routine ends.


   Note: Since assembly language gives you access to the lowest
   level of software and hardware interaction, you must exercise
   appropriate caution.  All the functions above require that you save
   the registers before you can use them to call the Extend functions.
   Be certain that after calling any Extend function you restore the
   stack by incrementing the stack pointer (SP).  Failure to restore the
   original environment will usually cause the system to crash.


-------------------------------- Code Template -----------------------------

   The following is a shell of a typical Clipper user-defined function
   written in assembly language that demonstrates these rules:

        PUBLIC          <func_name>
        EXTRN           <exten_func>:FAR
        DGROUP          GROUP   <data_seg>

        <data_seg>      SEGMENT PUBLIC  'DATA'
        ;
        ;       <your data declarations>
        ;
        <data_seg>      ENDS

        <code_seg>      SEGMENT 'CODE'
                        ASSUME cs:<code_seg>, ds:DGROUP

        <func_name>     PROC    FAR

                        push    bp              ; Save registers
                        mov     bp,sp
                        push    ds
                        push    es
                        push    si
                        push    di

                <your code goes here>

                        pop     di              ; Restore registers
                        pop     si
                        pop     es
                        pop     ds
                        pop     bp

        <func_name>     ENDP                    ; End of routine

        <code_seg>      ENDS                    ; End of code segment
                        END


--------------------------------- Code Example -----------------------------

   The following is an operational assembly language routine that clears
   a region of the screen.

   In Clipper:

   Clearit(10, 10, 20, 60)


   In assembly language:

        PUBLIC  Clearit                 ; Declare as public.

        EXTRN   __PARNI:FAR             ; Declare functions
        EXTRN   __RET:FAR               ; as external.

        DGROUP  GROUP   DATASG          ; Combine your data segment with
                                        ; Clipper's.

        DATASG  SEGMENT 'DATA'          ; Start of data segment.

                TOP     DB      0
                LEFT    DB      0
                BOTTOM  DB      0
                RIGHT   DB      0

        DATASG          ENDS            ; End of data segment.

        _PROG   segment 'CODE'          ; Start of code segment.

                ASSUME  cs:_PROG,ds:DGROUP

   CLEARIT      PROC    FAR             ; Start of process.

                push    bp              ; Preserve return address.
                mov     bp, sp
                push    ds              ; Save registers.
                push    es
                push    si
                push    di

                mov     ax, 1           ; Point to parameter.
                push    ax              ; Place on stack.
                call    __PARNI 1       ; Call Clipper.
                add     sp, 2           ; Restore stack.
                mov     top, al         ; Assign parameter
                                        ; to top.

                mov     ax, 2           ; Repeat process for next
                                        ; parameter.
                push    ax
                call    __PARNI
                add     sp, 2
                mov     left, al        ; Assign to left.
                mov     ax, 3           ; Repeat process for next
                                        ; parameter.
                push    ax
                call    __PARNI
                add     sp, 2
                mov     BOTTOM, al      ; Assign to bottom.

                mov     ax, 4           ; Repeat process for next
                                        ; parameter.
                push    ax
                call    __PARNI
                add     sp, 2
                mov     RIGHT, al       ; Assign to right.

                mov     ch, TOP         ; Place coordinates in
                                        ; CX:DX.
                mov     cl, LEFT
                mov     dh, BOTTOM
                mov     dl, RIGHT

                mov     ax, 0600h       ; Request roll up service.
                mov     bh, 07          ; Normal attribute.
                int     10h             ; Issue video interrupt.

                pop     di
                pop     si
                pop     es              ; Restore registers.
                pop     ds
                pop     bp

                call    __RET           ; Clipper return

                ret                     ; Actual physical return.
   CLEARIT      ENDP                    ; End of process.

   _prog        ENDS
                END


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson