home *** CD-ROM | disk | FTP | other *** search
- name dosalloc
-
- public dosalloc_
-
- ;------------------------------------------------------------------------------
- ; (c) Copyright 1984,1985,1986,1987 Front Line Software. All Rights Reserved.
- ;
- ; DOSALLOC.ASM
- ;
- ; RELEASE 2.0
- ;
- ; 'C' routine to allocate paragraphs of memory (MSDOS function 48)
- ;
- ; LARGE MODEL VERSION
- ; (routine will execute a FAR return).
- ;
- ; Written: 12/31/84
- ; Updated: 07/16/87
- ;
- ; This function is called by SALLOC() and SFREE(). It is not designed
- ; to be a stand alone program.
- ;
- ;------------------------------------------------------------------------------
- ;
- cgroup group code
- dgroup group data,const,stack
- assume cs:cgroup, ds:dgroup, es:dgroup, ss:dgroup
- stack segment stack 'stack'
- stack ends
- data segment 'data'
- data ends
- const segment 'const'
- const ends
- code segment 'code'
- dosalloc_ proc far ; Entry conforms to 'Mark Williams 'C''
-
- push si ; Change these three register saves to
- push di ; port to a different compiler. Also
- push bp ; change two lines down [bp + 10]. For
- ; every register you add, add two more
- ; to BP (as [bp + 12]). For every one
- ; you subtract, subtract 2 (as [bp + 8]).
- ; Don't forget the exit code at the end
- ; of this file.
-
- mov bp,sp
- mov ax,[bp + 10]; ; load # of bytes
-
- test ax,3fffH ; is the request for zero ?
- jz no_go ; then don't divide !
- mov dx,0000H ; clear upper word for division
- mov cx,0010H ; 16 decimal
- div cx ; convert bytes to paragraphs
- mov bx,ax ; put results into bx
- mov ax,dx
- test ax,3fffH ; was there a remainder ?
- jz get_blk ; no, go get the memory
- add bx,0001H ; yes, round the paragraphs up
- get_blk: mov ah,48H ; DOS function 48
- int 0021H ;
- jnb seta ; jump if no error retruned
- no_go: mov ax,0000H ; else return NULL
-
- seta: mov dx,ax ; segment in dx
- mov ax,0000H ; offset in ax
-
-
- mov sp,bp ;Exit conforms to 'Mark Williams 'C''
-
- pop bp ; Here are the three registers to change
- pop di ; if you are porting. Remember, they get
- pop si ; Pop'ed in the reverse order of which
- ret ; they get Push'ed.
- dosalloc_ endp
- code ends
- end
-
-