]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/MAPPER/ALLOCSEG.ASM

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / MAPPER / ALLOCSEG.ASM
1 ;\ f\e0
2 page 80,132
3 ;
4 title CP/DOS DosAllocSeg mapper
5 ;
6 dosxxx segment byte public 'dos'
7 assume cs:dosxxx,ds:nothing,es:nothing,ss:nothing
8 ;
9 ; ************************************************************************* *
10 ; *
11 ; * MODULE: DosAllocSeg
12 ; *
13 ; * FUNCTION: This module allocates a segment of memory to the
14 ; * requesting process
15 ; *
16 ; * CALLING SEQUENCE:
17 ; *
18 ; * push size ; number of bytes requested
19 ; * push@ selector ; selector allocated (returned)
20 ; * push shareind ; whether segment will be shared
21 ; * call dosallocseg
22 ; *
23 ; * RETURN SEQUENCE:
24 ; *
25 ; * AX = error , 0 = no error
26 ; *
27 ; * MODULES CALLED: DOS int 21h
28 ; *
29 ; *************************************************************************
30 ;
31 public dosallocseg
32 .sall
33 .xlist
34 include macros.inc
35 .list
36 ;
37 str struc
38 old_bp dw ?
39 return dd ?
40 ShareIndicator dw ? ; whether segment will be shared
41 SelectorPtr dd ? ; selector allocated
42 SegmentSize dw ? ; number of bytes requested
43 str ends
44
45 dosallocseg proc far
46 Enter dosallocseg ; push registers
47
48 mov bx,[bp].SegmentSize ; Get segment size
49
50 test bx,0000fh ; check segment size
51 jz NoRoundRequired
52
53 and bx,not 0000fh
54 add bx,00010h
55
56 NoRoundRequired:
57 cmp bx,0 ; check for 0 (full seg)
58 je AllocateMax ; jmp to full seg
59
60 shr bx,1 ; convert segment in bytes to
61 shr bx,1 ; paragraph
62 shr bx,1
63 shr bx,1
64 jmp HaveSize
65
66 AllocateMax:
67 mov bx,4096 ; setup default paragraph size
68
69 HaveSize:
70 mov ah,48h ; set up for dos allocate call
71 int 21h ; allocate segment
72 jc ErrorExit ; jump if error
73
74 lds si,[bp].SelectorPtr ; get selector address
75 mov ds:[si],ax ; save allocated memory block
76
77 AllocDone:
78 sub ax,ax ; set good return code
79 ErrorExit:
80 mexit ; pop registers
81 ret size str - 6 ; return
82
83 dosallocseg endp
84
85 dosxxx ends
86
87 end