timing	equ	0		;conditional assembly flag for the
				;  profiling code.

mark_overhead	equ	3	;one mark byte + one pointer (3 bytes total)

define_buffer	macro	x
x&prev_buffer	dw	?
x&next_buffer	dw	?
x&toptop	dw	?
x&topbot	dw	?
x&bottop	dw	?
x&botbot	dw	?
x&new_size	dw	?
	endm

;see if di is still below actptr.  If it isn't, we've run out of memory and
;  must abort.
chk_room	macro	segreg
	local	ok
	cmp	di,data_bottop
	jb	ok
	push	ax
	push	cx
  ifnb <segreg>
	mov	ax,segreg
  else
	mov	ax,ds
  endif
	mov	data_topbot,di
	mov	cx,100			;if we can't get 100 free bytes,
	call	buffer_free		;  we may as well not try for only 1.
	pop	cx
	pop	ax
	jnc	ok
	call	nomem
ok:
	endm

;see if di+cx is still below data_bottop.  If it isn't, we've run out of memory
;  and must abort.
chk_room_cnt	macro	segreg
	local	not_ok, ok
	push	di
	add	di,cx
	jc	not_ok
	cmp	di,data_bottop
	pop	di
	jb	ok
	push	di
not_ok:
	pop	di
	push	ax
  ifnb <segreg>
	mov	ax,segreg
  else
	mov	ax,ds
  endif
	mov	data_topbot,di
	call	buffer_free
	pop	ax
	jnc	ok
	call	nomem
ok:
	endm

;make di point to fbgn and push a copy of it.
;this macro is used by functions that return a value and don't need their
;  arguments.  More efficient than di_points_fend.
di_points_fbgn	macro
	mov	di,fbgn
	dec	di
	push	di
	endm

;make di point to fend and push a copy of it.
;this macro is used by functions that need their arguments.
di_points_fend	macro
	mov	di,fend
	add	di,2
	push	di
	endm


xchgdses	macro
	push	ds
	push	es
	pop	ds
	pop	es
	endm


dsdata	macro
	push	ss
	pop	ds
	assume	ds:data
	endm


esdata	macro
	push	ss
	pop	es
	assume	es:data
	endm
