;Entry_ADFReserveMemory
;-----------------------
;Allocates nKB of memory and prevents the DA from shrinking
;
;
;Entry:
; R0 - KB to reserve, or 0 to unreserve
; R12 - pointer to module private word

.Entry_ADFReserveMemory
 STMFD   R13!, {R1-R2, R4, R14}
 LDR     R12, [R12, #0]

 MOV     R1, R0				;command tail
 MOV     R0, #10			;base 10 number
 SWI     XOS_ReadUnsigned		;read the value PRM1-460
 MOVVS   R2, #0				;set to 0 on error
 MOVVC   R2, R2, LSL #10		;convert to bytes
 STR     R2, [R12, #reserve_DA - VARS]
 LDMVSFD R13!, {R1-R2, R4, PC}		;exit on error

 LDR     R0, [R12, #ADF_Buffer_Length - VARS]	;current size of data in buffer
 LDR     R1, [R12, #DA_size - VARS]		;current DA size

 CMP     R1, R2				;is the DA big enough?
 CMPLO   R0, R2				;is the reserve too small?
 LDMHSFD R13!, {R1-R2, R4, PC}		;YES, exit

 MOV     R4, R1
 LDR     R0, [R12, #our_Floppy_DA_number - VARS]	;our DA number
 SUBS    R1, R2, R4			;delta to reserve
 SWIPL   XOS_ChangeDynamicArea		;PRM1-384
 ADD     R4, R4, R1
 STR     R4, [R12, #DA_size - VARS]	;R4 = new length

LDMFD   R13!, {R1-R2, R4, PC}
