; os_change_dynamic_area_no_fail - Extend or shrink dynamic area without throwing error if
;	the change was only partially performed
;
; Initial Release 	08-Nov-00	Tony van der Hoff
;
;OSLib---efficient, type-safe, transparent, extensible,
;   register-safe A P I coverage of RISC O S
;
;   OSLib is free software; you can redistribute it and/or modify
;it under the terms of the GNU General Public Licence as published by
;the Free Software Foundation; either version 1, or (at your option)
;any later version.
;
;   OSLib is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.
;
;   You should have received a copy of the GNU General Public Licence
;along with this programme; if not, write to the Free Software
;Foundation, Inc, 675 Mass Ave, Cambridge, MA 02139, U S A.

	GET HDR.OSHeap

R0      RN      0
R1      RN      1
R2      RN      2
R3      RN      3
R4      RN      4
R5      RN      5
R6      RN      6
R7      RN      7
R8      RN      8
R9      RN      9

A1      RN      0
A2      RN      1
A3      RN      2
A4      RN      3
V1      RN      4
V2      RN      5
V3      RN      6
V4      RN      7
V5      RN      8
V6      RN      9

R       RN      0

SL      RN      10
FP      RN      11
IP      RN      12
SP      RN      13
LR      RN      14
PC      RN      15

	EXPORT	xos_change_dynamic_area_no_fail

	AREA	|SWI$$Code|, CODE, READONLY, PIC

;	os_change_dynamic_area_no_fail
; 	APCS Compliant
;Entry  A1 =  area type
;	A2 =  required size change in bytes (signed integer)
;	A3 -> actual size change in bytes (unsigned integer)
;
;  C Prototype:
;extern os_error* os_change_dynamic_area_no_fail( os_dynamic_area_no area,
;				   	    	  int size_increase,
;					          int* size_change
;			                        );
;
; This code works around the problem that OS_ChangeDynamicArea throws an error if the move is only
; partially performed. OSLib is then unable to return the amount by which the area has changed.
; The object code is patched into the library at build time by the MakeFile.

xos_change_dynamic_area_no_fail ROUT
        MOV     IP, LR			;

        SWI     XOS_ChangeDynamicArea	; XOS_ChangeDynamicArea
        BVC 	%90			; no error - normal return

        ;Test for Error_ChDynamNotAllMoved -  return any other error
	LDR 	R1, =Error_ChDynamNotAllMoved
	CMP 	R0, R1
	BNE	%99			; return error

	; ignore Error_ChDynamNotAllMoved

	; valid return
90	TEQ	A3, #0			; check null pointer
	STRNE	R3, [A3]		; output R3
	MOV	R,  #0			; clear error pointer

	; exit
99
	[ {CONFIG} = 32
	MOV	PC, IP
	|
        MOVS    PC, IP
	]

	LTORG

	END

