]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/SELECT/INITMEM.ASM

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / SELECT / INITMEM.ASM
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;
3 ; DUMMY DATA SEGMENT THAT WILL LINK WITH THE DATA.MAC
4 ; FILE. THIS RESOLVES ANY REFERENCES TO THE DATA SEGMENT.
5 ;
6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 DATA SEGMENT BYTE PUBLIC 'DATA' ;AN000;
8 HELPBUFSEG DW 0 ;AN000;
9 MEM_ALLOC DB 0 ;AN000;DT Memory allocated indicator
10 HELP_ALLOC EQU 80H ;AN000;DT Help memory allocated
11 BLOCK_ALLOC EQU 40H ;AN000;DT PANEL memory allocated
12 LVB_ALLOC EQU 20H ;AN000;DT LVB memory allocated
13 BLOCK_SET EQU 01H ;AN000;DT SETBLOCK done
14 DATA ENDS ;AN000;DATA
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 ;
17 ; Define dummy segment to calculate end of program
18 ;
19 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20 ZSEG SEGMENT PARA PUBLIC 'ZSEG' ;AN000;marks end of routine
21 ZSEG ENDS ;AN000;ZSEG will alphabetically appear
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 ;
24 ; INITMEM.ASM
25 ;
26 ;
27 ; Allocate Memory
28 ;
29 ; This routine will free up the required memory from DOS to make
30 ; space for the panels, scroll, help, and input field data.
31 ;
32 ;
33 ; INPUT: BX = # paragraphs to keep (in the program) ZSEG-PSP_SEG
34 ; CX = Length of program in bytes
35 ; DX = # paragraphs to allocate
36 ; DS = ES = CS - 10H
37 ;
38 ; OUTPUT: DS:DX = segment:offset of allocated buffer
39 ; BX = length of allocated buffer
40 ;
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42 EXTRN WR_MAXMEMPAR:WORD ;AN000;
43 EXTRN WR_MAXHELPSZ:WORD ;AN000;
44 EXTRN WR_DATA2SEG:WORD ;AN000;
45 EXTRN WR_DATA2OFF:WORD ;AN000;
46 EXTRN WR_DATA2LEN:WORD ;AN000;
47 EXTRN WR_LVBSEG:WORD ;AN000;DT
48 EXTRN WR_LVBOFF:WORD ;AN000;DT
49 EXTRN WR_LVBLEN:WORD ;AN000;DT
50 EXTRN WR_LVBMEM:WORD ;AN000;DT
51 EXTRN HRD_BUFSEG:WORD ;AN000;
52 EXTRN HRD_BUFOFF:WORD ;AN000;
53 EXTRN HRD_BUFLEN:WORD ;AN000;
54 ;
55 SERVICE SEGMENT PARA PUBLIC 'SERVICE' ;AN000;segment for far routine
56 ASSUME CS:SERVICE,DS:DATA ;AN000;
57 ;
58 PUBLIC ALLOCATE_MEMORY_CALL ;AN000;
59 PUBLIC DEALLOCATE_MEMORY_CALL ;AN000;
60 PUBLIC ALLOCATE_HELP ;AN000;
61 PUBLIC DEALLOCATE_HELP ;AN000;
62 PUBLIC ALLOCATE_BLOCK ;AN000;
63 PUBLIC DEALLOCATE_BLOCK ;AN000;
64 PUBLIC ALLOCATE_LVB ;AN000;
65 PUBLIC DEALLOCATE_LVB ;AN000;
66 ;
67 SET_BLOCK equ 4AH ;AN000;
68 ALLOCATEB equ 48H ;AN000;
69 FREE_BLOCK equ 49H ;AN000;
70 ;
71 INCLUDE STRUC.INC ;AN000;
72 INCLUDE MACROS.INC ;AN000;
73 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DS and AX will auto pop on ret
74 ;
75 ; ALLOCATE_MEMORY_CALL
76 ;
77 ; This first takes the memory held by the active program
78 ; (initially all of remaining memory) and requests only the
79 ; memory held by the running program. Next, memory is
80 ; re-allocated to the running program - specified by WR_MAXMEMPAR
81 ; starting from the end of the program (re/ZSEG).
82 ;
83 ; ENTRY:
84 ; AX = CODE segment (PSP+100H)
85 ;
86 ;
87 ; EXIT:
88 ; if CY = 0 then,
89 ; WR_DATA2SEG = start of allocated segment
90 ; WR_DATA2OFF = start of allocated offset (always 0)
91 ; WR_DATA2LEN = length of allocated block (always WR_MAXMEMPAR)
92 ;
93 ; if CY = 1 then an error occurred allocating memory
94 ;
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96 ALLOCATE_MEMORY_CALL PROC FAR ;AN000;
97 PUSHH <AX,BX,DX,DS,ES> ;AN000;
98 ;
99 TEST MEM_ALLOC,BLOCK_SET ;AN000;DT SETBLOCK done?
100 JNZ AM_SBDONE ;AN000;DT if so, skip it
101 ;
102 MOV AH,62H ;AN000; Get the PSP segment
103 INT 21H ;AN000;
104 MOV AX,BX ;AN000;save the PSP segment of SELECT
105 MOV BX,ZSEG ;AN000;get last address of code (from ZSEG)
106 MOV ES,AX ;AN000;set PSP segment in ES
107 SUB BX,AX ;AN000;calc # of paragraphs in the program
108 MOV AH,SET_BLOCK ;AN000;setblock function number
109 DOSCALL ;AN000;free used memory
110 .IF < C > ;AC000;DT
111 GOTO ALLOC_RET ;AN000;DT If error, exit
112 .ENDIF ;AN000;DT
113 OR MEM_ALLOC,BLOCK_SET ;AN000;DT
114 ;
115 AM_SBDONE: ;AN000;
116 MOV AX,DATA ;AN000;initialize data segment
117 MOV DS,AX ;AN000; and extra segment
118 ;
119 PUSH CS ;AN000;call far procedure
120 CALL ALLOCATE_BLOCK_NEAR ;AN000;now allocate Panel block
121 .IF < C > ;AC000;DT
122 GOTO ALLOC_RET ;AN000;DT If error, exit
123 .ENDIF ;AN000;
124 ;
125 PUSH CS ;AN000;call far procedure
126 CALL ALLOCATE_LVB_NEAR ;AN000;now allocate LVB block
127 .IF < C > ;AC000;DT
128 GOTO ALLOC_RET ;AN000;DT If error, exit
129 .ENDIF ;AN000;
130 ;
131 PUSH CS ;AN000;call far procedure
132 CALL ALLOCATE_HELP_NEAR ;AN000;now allocate help
133 ;
134 ALLOC_RET: ;AN000;
135 POPP <ES,DS,DX,BX,AX> ;AN000;
136 RET ;AN000;
137 ALLOCATE_MEMORY_CALL ENDP ;AN000;
138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
139 ;
140 ; DEALLOCATE_MEMORY_CALL
141 ;
142 ; This is the house-cleaning before the running program
143 ; returns to DOS.
144 ;
145 ; ENTRY:
146 ; none
147 ;
148 ; EXIT:
149 ; if CY = 0 then,
150 ; The memory after (WR_DATA2SEG) is released to DOS
151 ; if CY = 1 then,
152 ; An error occurred while trying to release this memory
153 ;
154 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
155 DEALLOCATE_MEMORY_CALL PROC FAR;AN000;
156 PUSHH <AX,DS,ES> ;AN000;
157 MOV AX,DATA ;AN000;
158 MOV DS,AX ;AN000;
159 PUSH CS ;AN000;call far procedure
160 CALL DEALLOCATE_BLOCK_NEAR ;AN024;now deallocate Panel block
161 PUSH CS ;AN000;call far procedure
162 CALL DEALLOCATE_LVB_NEAR ;AN024; deallocate LVB block
163 PUSH CS ;AN000;call far procedure
164 CALL DEALLOCATE_HELP_NEAR ;AN000;now deallocate help
165 POPP <ES,DS,AX> ;AN000;
166 RET ;AN000;
167 DEALLOCATE_MEMORY_CALL ENDP ;AN000;
168 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DS and AX will auto pop on ret
169 ;
170 ; ALLOCATE_HELP
171 ;
172 ;
173 ; ENTRY:
174 ; AX = CODE segment (PSP+100H)
175 ;
176 ;
177 ; EXIT:
178 ; if CY = 0 then, ok
179 ; if CY = 1 then an error occurred allocating memory
180 ;
181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
182 ALLOCATE_HELP PROC FAR ;AN000;
183 ALLOCATE_HELP_NEAR: ;AN000;
184 PUSHH <AX,BX,DX,DS,ES> ;AN000;
185 MOV AX,DATA ;AN000;
186 MOV DS,AX ;AN000;
187 ;
188 TEST MEM_ALLOC,HELP_ALLOC ;AN000;DT Is help allocated
189 JNZ AH_RET ;AN000;DT if so, skip allocation
190 ;now allocate help
191 MOV BX,WR_MAXHELPSZ ;AN000;set BX to max # of paragraphs
192 SHR BX,1 ;AN000;
193 SHR BX,1 ;AN000;
194 SHR BX,1 ;AN000;
195 SHR BX,1 ;AN000;
196 MOV AH,ALLOCATEB ;AN000;set allocate function number
197 DOSCALL ;AN000;allocate memory
198 .IF < NC > ;AN000;
199 MOV HRD_BUFSEG,AX ;AN000;save segment
200 MOV HELPBUFSEG,AX ;AN000;save segment
201 MOV HRD_BUFOFF,0 ;AN000; and offset
202 MOV BX,WR_MAXHELPSZ ;AN000;set BX to max # of byte
203 MOV HRD_BUFLEN,BX ;AN000;
204 OR MEM_ALLOC,HELP_ALLOC ;AN000;DT
205 CLC ;AN000;
206 .ENDIF ;AN000;
207 AH_RET: ;AN000;
208 POPP <ES,DS,DX,BX,AX> ;AN000;
209 RET ;AN000;
210 ALLOCATE_HELP ENDP ;AN000;
211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
212 ;
213 ; DEALLOCATE_HELP
214 ;
215 ; This is the house-cleaning before the running program
216 ; returns to DOS.
217 ;
218 ; ENTRY:
219 ; none
220 ;
221 ; EXIT:
222 ; if CY = 0 then, OK
223 ; if CY = 1 then,
224 ; An error occurred while trying to release this memory
225 ;
226 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
227 DEALLOCATE_HELP PROC FAR ;AN000;
228 DEALLOCATE_HELP_NEAR: ;AN000;
229 PUSHH <AX,BX,DS,ES> ;AN000;
230 MOV AX,DATA ;AN000;
231 MOV DS,AX ;AN000;
232 TEST MEM_ALLOC,HELP_ALLOC ;AN000;DT Is help allocated
233 JZ DH_RET ;AN000;DT if not, skip deallocation
234 MOV AX,HELPBUFSEG ;AN000;free help segment
235 MOV ES,AX ;AN000;
236 MOV AH,FREE_BLOCK ;AN000;
237 DOSCALL ;AN000;
238 AND MEM_ALLOC,255-HELP_ALLOC ;AN000;DT
239 DH_RET: ;AN000;
240 POPP <ES,DS,BX,AX> ;AN000;
241 RET ;AN000;
242 DEALLOCATE_HELP ENDP ;AN000;
243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DS and AX will auto pop on ret
245 ;
246 ; ALLOCATE_BLOCK
247 ;
248 ; Allocate Panel and Scroll memory.
249 ;
250 ; ENTRY:
251 ; none
252 ; EXIT:
253 ; if CY = 0 then,
254 ; WR_DATA2SEG = start of allocated segment
255 ; WR_DATA2OFF = start of allocated offset (always 0)
256 ; WR_DATA2LEN = length of allocated block (always WR_MAXMEMPAR)
257 ;
258 ; if CY = 1 then an error occurred allocating memory
259 ;
260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
261 ALLOCATE_BLOCK PROC FAR ;AN000;
262 ALLOCATE_BLOCK_NEAR: ;AN000;
263 PUSHH <AX,BX,DX,DS,ES> ;AN000;
264 MOV AX,DATA ;AN000;initialize data segment
265 MOV DS,AX ;AN000; and extra segment
266 ;
267 TEST MEM_ALLOC,BLOCK_ALLOC ;AN000;DT Is PANEL block allocated
268 JNZ AB_RET ;AN000;DT if so, skip allocation
269 ;
270 MOV BX,WR_MAXMEMPAR ;AN000;set DX to max # of 16 byte parag's
271 MOV AH,ALLOCATEB ;AN000;set allocate function number
272 DOSCALL ;AN000;allocate memory
273 .IF < NC > ;AC000;DT
274 MOV BX,WR_MAXMEMPAR ;AN000;
275 SHL BX,1 ;AN000;THIS SHOULD BE REMOVED WHEN
276 SHL BX,1 ;AN000;THE INITIALIZE ROUTINE TREATS
277 SHL BX,1 ;AN000;WR_DATA2LEN AS PARAGRAPHS AND
278 SHL BX,1 ;AN000;NOT BYTES......
279 MOV WR_DATA2SEG,AX ;AN000;save segment
280 MOV WR_DATA2OFF,0 ;AN000;
281 MOV WR_DATA2LEN,BX ;AN000;
282 OR MEM_ALLOC,BLOCK_ALLOC ;AN000;DT PANEL block allocated
283 .ENDIF ;AN000;
284 AB_RET: ;AN000;
285 POPP <ES,DS,DX,BX,AX> ;AN000;
286 RET ;AN000;
287 ALLOCATE_BLOCK ENDP ;AN000;
288 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
289 ;
290 ; DEALLOCATE_BLOCK
291 ;
292 ; This is the house-cleaning before the running program
293 ; returns to DOS.
294 ;
295 ; ENTRY:
296 ; none
297 ;
298 ; EXIT:
299 ; if CY = 0 then, OK
300 ; if CY = 1 then,
301 ; An error occurred while trying to release this memory
302 ;
303 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
304 DEALLOCATE_BLOCK PROC FAR ;AN000;
305 DEALLOCATE_BLOCK_NEAR: ;AN000;
306 PUSHH <AX,BX,DS,ES> ;AN000;
307 MOV AX,DATA ;AN000;
308 MOV DS,AX ;AN000;
309 TEST MEM_ALLOC,BLOCK_ALLOC ;AN000;DT Is PANEL block allocated
310 JZ DB_RET ;AN000;DT if not, skip deallocation
311 MOV AX,WR_DATA2SEG ;AN000;free up allocated segment
312 MOV ES,AX ;AN000;
313 MOV AH,FREE_BLOCK ;AN000;
314 DOSCALL ;AN000;
315 AND MEM_ALLOC,255-BLOCK_ALLOC ;AN000;DT
316 DB_RET: ;AN000;
317 POPP <ES,DS,BX,AX> ;AN000;
318 RET ;AN000;
319 DEALLOCATE_BLOCK ENDP ;AN000;
320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DS and AX will auto pop on ret
321 ;
322 ; ALLOCATE_LVB
323 ;
324 ;
325 ; ENTRY:
326 ; AX = none
327 ;
328 ;
329 ; EXIT:
330 ; if CY = 0 then, ok
331 ; if CY = 1 then an error occurred allocating memory
332 ;
333 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
334 ALLOCATE_LVB PROC FAR ;AN000;
335 ALLOCATE_LVB_NEAR: ;AN000;
336 PUSHH <AX,BX,DX,DS,ES> ;AN000;
337 ;
338 MOV AX,DATA ;AN000;
339 MOV DS,AX ;AN000;
340 ;;;;;;;
341 TEST MEM_ALLOC,LVB_ALLOC ;AN000;DT Is LVB block allocated
342 JNZ ALVB_RET ;AN000;DT if so, skip allocation
343 ;
344 MOV BX,WR_LVBMEM ;AN000;set BX to max # of 16 byte parag's
345 MOV AH,ALLOCATEB ;AN000;set allocate function number
346 DOSCALL ;AN000;allocate memory
347 .IF < NC > ;AN000;
348 MOV WR_LVBSEG,AX ;AN000;save segment
349 MOV WR_LVBOFF,0 ;AN000;and offset
350 SHL BX,1 ;AN000;THIS SHOULD BE REMOVED WHEN
351 SHL BX,1 ;AN000;THE INITIALIZE ROUTINE TREATS
352 SHL BX,1 ;AN000;WR_DATA2LEN AS PARAGRAPHS AND
353 SHL BX,1 ;AN000;NOT BYTES......
354 MOV WR_LVBLEN,BX ;AN000;and byte length
355 OR MEM_ALLOC,LVB_ALLOC ;AN000;DT LVB block allocated
356 .ENDIF ;AN000;
357 ;
358 ALVB_RET: ;AN000;
359 POPP <ES,DS,DX,BX,AX> ;AN000;
360 RET ;AN000;
361 ALLOCATE_LVB ENDP ;AN000;
362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
363 ;
364 ; DEALLOCATE_LVB
365 ;
366 ;
367 ; ENTRY:
368 ; none
369 ;
370 ; EXIT:
371 ; if CY = 0 then, OK
372 ; if CY = 1 then,
373 ; An error occurred while trying to release this memory
374 ;
375 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376 DEALLOCATE_LVB PROC FAR ;AN000;
377 DEALLOCATE_LVB_NEAR: ;AN000;
378 PUSHH <AX,BX,DS,ES> ;AN000;
379 MOV AX,DATA ;AN000;
380 MOV DS,AX ;AN000;
381 TEST MEM_ALLOC,LVB_ALLOC ;AN000;DT Is LVB block allocated
382 JZ DLVB_RET ;AN000;DT if not, skip deallocation
383 MOV AX,WR_LVBSEG ;AN000;free up LVB allocated segment
384 MOV ES,AX ;AN000;
385 MOV AH,FREE_BLOCK ;AN000;
386 DOSCALL ;AN000;
387 AND MEM_ALLOC,255-LVB_ALLOC ;AN000;DT
388 DLVB_RET: ;AN000;
389 POPP <ES,DS,BX,AX> ;AN000;
390 RET ;AN000;
391 DEALLOCATE_LVB ENDP ;AN000;
392
393 SERVICE ENDS ;AN000;
394 END ;AN000;