;   VERSION 0003
        NAME    INIT3

        ASSUME  CS:CODE,DS:DATA

;You may modify the following equate statment to permit the passing of
;shared global data between chained programs.  The value in the equate
;statment must be 0100 hex plus the size of your shared global data area. 

dsize   EQU     0100H           ;normal default value
        
DATA    SEGMENT PUBLIC
DATA    ENDS

CODE    SEGMENT PUBLIC
        PUBLIC  @INI3
        
@INI3   PROC    NEAR

        MOV     AX,DS
        MOV     ES,AX   ;NOW ES:0 IS START OF DATA AREA
        MOV     DI,6    ;6 IS OFFSET OF DSEG LENGTH
        MOV     CX,ES:WORD PTR [DI]
        SUB     CX,dsize ;SEGMENT LENGTH IS IN BYTES
        MOV     DI,dsize ;START ADDRESS OF FILL
        XOR     AX,AX   ;DATA TO FILL WITH
        REP
        STOSB           ;ZERO IT ALL
        
;
;       NOW IF OVERLAYS ARE LINKED INTO THE ROOT ZERO THE FIRST
;       BYTE OF THE OVERLAY AREAS
;
        MOV     AX,CS
        MOV     ES,AX   ;NOW CS:0 IS START OF CODE
        MOV     DI,0CH  ;0C IS OFFSET OF NAME CONTROL BLOCK
        MOV     AX,ES:WORD PTR [DI]
        MOV     BX,ES:WORD PTR 2[DI]
;
;       IF AX=BX THEN OVERLAYS WERE NOT LINKED INTO THIS PROGRAM
;
        CMP     AX,BX
        JZ      XIT
        
        MOV     DI,BX   ;ELSE EI:DI NOW POINTS TO OVERLAY AREA TABLE
        MOV     CX,16   ;NUMBER OF ENTRIES IN THE TABLE

LP:     MOV     SI,ES:WORD PTR [DI] ;GET OFFSET OF OVERLAY AREA
        MOV     ES:BYTE PTR [SI],0  ;PUT A ZERO THERE
        INC     DI                  ;AND BUMP TO NEXT OFFSET IN TABLE
        INC     DI
        LOOP    LP                  ;DO IT 16 TIMES

XIT:    RET
        
@INI3   ENDP

CODE    ENDS

        END
        

