home *** CD-ROM | disk | FTP | other *** search
- ;_ parall.asm Thu Feb 4 1988 Modified by: Walter Bright */
- ; Copyright (C) 1985-1988 by Northwest Software
- ; All rights reserved
- ; Written by Walter Bright
-
- include macros.asm
-
- c_extrn _doserrno,word
-
- begcode parall
-
- c_public paralloc,parcallo,parfree
-
- ; Storage allocator
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Allocate a block of data.
- ; Use:
- ; p = paralloc(unsigned numpara);
- ; Returns:
- ; segment of allocated data else 0
-
- func paralloc
- push BP
- mov BP,SP
- mov BX,P[BP] ;get numpara
- bdos 48h ;allocate memory
- jnc A1 ;no error
- mov _doserrno,AX
- clr AX
- A1: pop BP
- ret
- c_endp paralloc
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Allocate a block of data and clear it.
- ; Use:
- ; p = parcallo(numpar);
- ; Returns:
- ; segment of allocated data else NULL
-
- func parcallo
- push BP
- mov BP,SP
- push P[BP]
- callm paralloc
- mov SP,BP
- tst AX ;error?
- jz CA2 ;yes
- .save DI
- cld
- clr DI ;start at ES:0
- mov BX,AX ;save segment of result
- CA4: mov ES,AX
- mov CX,P[BP] ;# of paragraphs
- jcxz CA1
- and CX,03FFFh
- jnz CA3
- mov CX,1000h ;clear 64k
- CA3: sub P[BP],CX
- shl CX,1
- shl CX,1
- shl CX,1 ;# of words
- mov AX,DI ;AX = 0
- rep stosw ;clear the memory
- mov AX,ES
- add AX,1000h ;next segment
- jmp CA4
-
- CA1: .restore DI
- if SPTR
- push DS
- pop ES
- endif
- mov AX,BX ;restore segment of result
- CA2: pop BP
- ret
- c_endp parcallo
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Free memory that was allocated by paralloc() or parcallo().
- ; Use:
- ; parfree(segment);
- ; Returns:
- ; 0 success
- ; -1 error
-
- func parfree
- push BP
- mov BP,SP
- mov ES,P[BP] ;get segment
- bdos 49h ;free allocated memory
- if SPTR
- push DS
- pop ES
- endif
- jnc F1 ;no error
- mov _doserrno,AX
- F1: sbb AX,AX
- pop BP
- ret
- c_endp parfree
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Modify allocated memory.
- ; unsigned dos_setblock(newsize,segment);
- ; Returns:
- ; if _doserrno is set, it returns the max possible size
-
- c_public dos_setblock
- func dos_setblock
- push BP
- mov BP,SP
- les BX,P[BP]
- bdos 4Ah ;modify allocated memory
- jnc S1 ;no error
- mov _doserrno,AX
- S1: mov AX,BX ;return max possible
- if SPTR
- push DS
- pop ES
- endif
- pop BP
- ret
- c_endp dos_setblock
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Copy paragraphs of memory.
- ; void _copy(unsigned newseg,unsigned oldseg,unsigned numpar);
-
- c_public _copy
- func _copy
- push BP
- mov BP,SP
- .save <SI,DI>
- push DS
- cld
- clr DI ;start at ES:0
- clr SI ;start at DS:0
- mov ES,P[BP] ;newseg
- mov DS,P+2[BP] ;oldseg
- mov BX,P+4[BP] ;numpar
- COP4: mov CX,BX ;# of paragraphs
- jcxz COP1
- and CX,03FFFh
- jnz COP3
- mov CX,1000h ;clear 64k
- COP3: sub BX,CX
- shl CX,1
- shl CX,1
- shl CX,1 ;# of words
- mov AX,DI ;AX = 0
- rep movsw ;clear the memory
- mov AX,ES
- add AX,1000h ;next segment
- mov ES,AX
- mov AX,DS
- add AX,1000h ;next segment
- mov DS,AX
- jmp COP4
-
- COP1: pop DS
- .restore <DI,SI>
- if SPTR
- push DS
- pop ES
- endif
- pop BP
- ret
- c_endp _copy
-
- endcode parall
-
- end
-