summaryrefslogtreecommitdiff
path: root/v4.0/src/MAPPER/ALLOCSEG.ASM
blob: 36de869561a1010e52ec70d3c9f11a96ffc08fa8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
;0
page 80,132
;
title CP/DOS  DosAllocSeg  mapper
;
dosxxx	segment byte public 'dos'
	assume	cs:dosxxx,ds:nothing,es:nothing,ss:nothing
;
; ************************************************************************* *
; *
; *	 MODULE: DosAllocSeg
; *
; *	 FUNCTION: This module allocates a segment of memory to the
; *		requesting process
; *
; *	 CALLING SEQUENCE:
; *
; *		push	size		; number of bytes requested
; *		push@	selector	; selector allocated (returned)
; *		push	shareind	; whether segment will be shared
; *		call	dosallocseg
; *
; *	 RETURN SEQUENCE:
; *
; *		AX = error	, 0 = no error
; *
; *	 MODULES CALLED:  DOS int 21h
; *
; *************************************************************************
;
	public	dosallocseg
	.sall
	.xlist
	include macros.inc
	.list
;
str	struc
old_bp	 dw	 ?
return	 dd	 ?
ShareIndicator	dw	?	; whether segment will be shared
SelectorPtr	dd	?	; selector allocated
SegmentSize	dw	?	; number of bytes requested
str	ends

dosallocseg proc   far
	Enter	dosallocseg		 ; push registers

	mov	bx,[bp].SegmentSize	 ; Get segment size

	test	bx,0000fh		 ; check segment size
	jz	NoRoundRequired

	and	bx,not 0000fh
	add	bx,00010h

NoRoundRequired:
	cmp	bx,0			 ; check for 0 (full seg)
	je	AllocateMax		 ; jmp to full seg

	shr	bx,1			 ; convert segment in bytes to
	shr	bx,1			 ; paragraph
	shr	bx,1
	shr	bx,1
	jmp	HaveSize

AllocateMax:
	mov	bx,4096 		 ; setup default paragraph size

HaveSize:
	mov	ah,48h			 ; set up for dos allocate call
	int	21h			 ; allocate segment
	jc	ErrorExit		 ; jump if error

	lds	si,[bp].SelectorPtr	 ; get selector address
	mov	ds:[si],ax		 ; save allocated memory block

AllocDone:
	sub	ax,ax			 ; set good return code
ErrorExit:
	mexit				 ; pop registers
	ret	size str - 6		 ; return

dosallocseg endp

dosxxx	ends

	end