1 ; ***********************************************************
  2 ; *                                                         *
  3 ; * Copyright, (C) Honeywell Bull Inc., 1987                *
  4 ; *                                                         *
  5 ; * Copyright, (C) Honeywell Information Systems Inc., 1986 *
  6 ; *                                                         *
  7 ; ***********************************************************
  8 
  9 ; HISTORY COMMENTS:
 10 ;  1) change(87-04-30,Flegel), approve(87-07-13,MCR7580),
 11 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 12 ;     Created.
 13 ;                                                      END HISTORY COMMENTS
 14 
 15 ;/* : PROCEDURE FUNCTION (free_program)
 16 ;
 17 ; Release the memory occupied by a program which is resident.  This consists
 18 ; of releasing the environment block and the program block of memory.
 19 ;
 20 ; Environment memory block paragraph:  [PSP + 2Ch]
 21 ; Program memory block paragraph:      CS
 22 ;
 23 ; Arguments:  ES - CS of program
 24 ; Returns:    ax - error code from DOS free function (49h)
 25 ;*/
 26 
 27 include dos.mac          ;Lattice include file
 28 include xoscall.mac      ;Bios and Dos Call macros
 29 include ws.mac           ;MOWSE definitions
 30 include cat.mac          ;CAT structure
 31 
 32 env_addr equ 2Ch         ; location of address of environment string on PSP
 33 
 34 page
 35 ;*****************************************************************************
 36 ;                                       DATA
 37 ;*****************************************************************************
 38 dseg
 39 
 40 ;------- External Declarations -----------------------------------------------
 41 
 42 ;------- Public Declarations -------------------------------------------------
 43 
 44 public  free_program
 45 public  free_cat_program
 46 
 47 endds
 48 
 49 page
 50 ;*****************************************************************************
 51 ;                               Program mainline
 52 ;*****************************************************************************
 53 pseg
 54 
 55 free_program proc near
 56 
 57 ; Free environment block
 58 
 59         push    ES                       ; ES = CS of program
 60 
 61         mov     ax,ES:[env_addr]         ; ax = environment block segment
 62         mov     ES,ax                    ; argument in ES
 63 
 64         mov     ah,49h
 65         xor     al,al
 66         int     21h                      ; free environment block
 67 
 68         cmp     ax,7                     ; error on free (destroyed block) ?
 69         je      error_return             ;  YES - return
 70         cmp     ax,9                     ; error on free (invalid block) ?
 71         je      error_return             ;  YES - return
 72 
 73 ; Free program block
 74 
 75         pop     ES                       ; Get ES = CS again
 76         push    ES
 77 
 78         mov     ah,49h
 79         xor     al,al
 80         int     21h                      ; free program memory
 81 
 82         cmp     ax,7                     ; error on free (destroyed block) ?
 83         je      error_return             ;  YES - return
 84         cmp     ax,9                     ; error on free (invalid block) ?
 85         je      error_return             ;  YES - return
 86 
 87         xor     ax,ax                    ; All worked, no error
 88 
 89 error_return:
 90         pop     ES
 91         ret
 92 
 93 free_program endp
 94 
 95 ;/* : PROCEDURE FUNCTION (free_cat_program)
 96 ;
 97 ; Release the memory occupied by a program which is resident.  This consists
 98 ; of releasing the environment block and the program block of memory.
 99 ;
100 ; Arguments:  CAT pointer of program to be terminated
101 ; Returns:    ax - error code from DOS free function (49h)
102 ;*/
103 
104 free_cat_program proc near
105 
106         push    bp                       ; save registers
107         mov     bp,sp
108         push    ES
109         push    bx
110 
111         mov     bx,[bp+4]                ; bx = CAT pointer
112         mov     ax,csreg[bx]             ; ax = CS of program
113         mov     ES,ax                    ; argument in ES
114         call    free_program             ; free application memory
115 
116         pop     bx
117         pop     ES                       ; restore registers
118         pop     bp
119         ret
120 
121 free_cat_program endp
122 
123 endps
124         end