;
; Heap.aii.i
;
; Imports and macros for the Heap.
;
; Copyright © 1989, Claris Corporation
;
; 5/3/89	Kevin A. Watts	from older H_Heap.aii.i and H_Block.aii.i
;
;----------------------------------------------------------------

  IF &Type('&__FILE__') = 'UNDEFINED' THEN
	gblc	&__FILE__
&__FILE__	setc	''
  ENDIF

H_TOO_OLD	equ	-1
H_TOO_NEW	equ	-2
H_BAD		equ	-3

  IF &__FILE__ ­ 'Heap' THEN
	IMPORT	H_Init
	IMPORT	H_CurrentHeap
	IMPORT	H_SetHeap
	IMPORT	H_UnsetHeap
	IMPORT	H_ResetHeap
	IMPORT	H_NewHeap
	IMPORT	H_DisposeHeap
	IMPORT	H_ReadHeap
	IMPORT	H_WriteHeap
  ENDIF

  IF &__FILE__ ­ 'Block' THEN
	IMPORT	H_NewBlock
	IMPORT	H_DisposeBlock
	IMPORT	H_ResizeBlock
	IMPORT	H_CopyBlock
	IMPORT	H_GetBlockPtr
	IMPORT	H_GetBlockSize
	IMPORT	H_TruncHeap
  ENDIF

;----------------------------------------------------------------

  IF &__FILE__ ­ 'Heap' AND &__FILE__ ­ 'Block' THEN
	MACRO
	H_Init			; H_Init
	jsl	H_Init
	ENDM


	MACRO			; H_SetHeap
	H_SetHeap	&Heap
  IF &Heap='' THEN
	AERROR	'Bad usage of: H_SetHeap HeapID'
  ENDIF
	MoveLong	&Heap,xy
	jsl	H_SetHeap
	ENDM


	MACRO			; H_UnsetHeap
	H_UnsetHeap
	jsl	H_UnsetHeap
	ENDM


	MACRO			; H_ResetHeap
	H_ResetHeap
	jsl	H_ResetHeap
	ENDM


	MACRO			; H_NewHeap
	H_NewHeap	&Heap,&err==
  IF &Heap='' THEN
	AERROR	'Bad usage of: H_NewHeap HeapID [,err=]'
  ENDIF
	jsl	H_NewHeap
  IF &err­'' THEN
	sty	&err
  ENDIF
 	MoveLong	ax,&Heap
	ENDM


	MACRO			; H_DisposeHeap
	H_DisposeHeap
	jsl	H_DisposeHeap
	ENDM


	MACRO			; H_WriteHeap
	H_WriteHeap	&FileID,&err==
  IF &FileID='' THEN
	AERROR	'Bad usage of: H_WriteHeap FileID [,err=]'
  ENDIF
	MoveWord	&FileID,x
	jsl	H_WriteHeap
  IF &err­'' THEN
	sty	&err
  ENDIF
	ENDM


	MACRO			; H_ReadHeap
	H_ReadHeap	&FileID,&Heap,&err==
  IF &Heap='' OR &FileID='' THEN
	AERROR	'Bad usage of: H_ReadHeap FileID, HeapID [,err=]'
  ENDIF
	MoveWord	&FileID,x
	jsl	H_ReadHeap
  IF &err­'' THEN
	sty	&err
  ENDIF
 	MoveLong	ax,&Heap
	ENDM


	MACRO			; H_NewBlock
	H_NewBlock	&Size,&Index,&Ptr,&err==
  IF &Size='' OR &Index='' THEN
	AERROR	'Bad usage of: H_NewBlock Size, Index [,Ptr] [,err=]'
  ENDIF
	SpaceLong
	MoveLong	&Size,xy
	jsl	H_NewBlock
  IF &err­'' THEN
	sty	&err
  ENDIF
  IF &Index='ax' OR &Index='ay' THEN
	AERROR	'Bad usage of H_NewBlock: Index may not be ax or ay'
  ENDIF
	MoveLong	ax,&Index
  IF &Ptr='' THEN
	pla
	pla
  ELSE
	PullLong	&Ptr
  ENDIF
  	ENDM
	
	
	MACRO			; H_DisposeBlock
	H_DisposeBlock	&Index
  IF &Index='' THEN
	AERROR	'Bad usage of: H_DisposeBlock Index'
  ENDIF
	MoveLong	&Index,xy
	jsl	H_DisposeBlock
	ENDM
	
	
	MACRO			; H_ResizeBlock
	H_ResizeBlock	&Index,&Size,&Ptr,&err==
  IF &Index='' OR &Size='' THEN
	AERROR	'Bad usage of: H_ResizeBlock Index, Size [,Ptr] [,err=]'
  ENDIF
	PushLong	&Index
	MoveLong	&Size,xy
	jsl	H_ResizeBlock
  IF &err­'' THEN
  	sty	&err
  ENDIF
  IF &Ptr­'' THEN
	MoveLong	ax,&Ptr
  ENDIF
	ENDM
	
	
	MACRO			; H_CopyBlock
	H_CopyBlock	&Index,&NewIndex,&NewPtr,&err==
  IF &Index='' OR &NewIndex='' THEN
	AERROR	'Bad usage of: H_CopyBlock Index, NewIndex [,NewPtr] [,err=]'
  ENDIF
	SpaceLong
	MoveLong	&Index,xy
	jsl	H_CopyBlock
  IF &err­'' THEN
	sty	&err
  ENDIF
  IF &NewIndex='ax' OR &NewIndex='ay' THEN
	AERROR	'Bad usage of H_CopyBlock: NewIndex may not be ax or ay'
  ENDIF
	MoveLong	ax,&NewIndex
  IF &NewPtr='' THEN
	pla
	pla
  ELSE
	PullLong	&NewPtr
  ENDIF
	ENDM


	MACRO			; H_GetBlockPtr
	H_GetBlockPtr	&Index,&Ptr
  IF &Index='' OR &Ptr='' THEN
	AERROR	'Bad usage of: H_GetBlockPtr Index, Ptr'
  ENDIF
	MoveLong	&Index,xy
	jsl	H_GetBlockPtr
	MoveLong	ax,&Ptr
	ENDM


	MACRO			; H_GetBlockSize
	H_GetBlockSize	&Index,&Size
  IF &Index='' OR &Size='' THEN
	AERROR	'Bad usage of: H_GetBlockSize Index, Size'
  ENDIF
	MoveLong	&Index,xy
	jsl	H_GetBlockSize
	MoveLong	ax,&Size
	ENDM


	MACRO			; H_TruncHeap
	H_TruncHeap
	jsl	H_TruncHeap
	ENDM
  ENDIF
