;References:
;swi - vector_handler_forward

;R12, R14 are on the stack


;vector_handler_2A
;-----------------
;Tracks the size of DA2 when running on RO3.5+

.vector_handler_2A
 TEQ     R0, #2				;screen DA?
 BNE     vector_handler_forward		;NO, pass to OS

 LDR     R12, is_screen_remapped
 TEQ     R12, #0			;is screen memory remapped?
 LDREQ   R12, Screen_Cache_Off		;NO, turn the screen cache off?
 TEQEQ   R12, #0
 BEQ     vector_handler_forward		;NO, exit

 #if JIT_WIMP_support == 1
   BL      check_task_ID		;is the task supported?
   BNE     vector_handler_forward	;NO
 #endif

 TEMP    R0
 STR     R1, DA2_delta			;store the delta being requested
 LOCK    R0

 STMFD   R13!, {R2-R3}
 MOV     R3, R1
 MOV     R0, #2
 ADR     R12, _SPSR
 BL      pre_SWI_veneer			;call SWI that follows
 SWI     XOS_ReadDynamicArea
 LDR     R0, emulate_RISCOS
 CMP     R0, #&350 << 8			;don't restrict RO3.50+
 MOVHS   R1, R3
 BGE     _ok

 ADD     R0, R1, R3
 MOV     R2, #480 * 1024		;max memory pre RO3.5 supports
 CMP     R0, R2
 SUBGT   R1, R2, R1			;more, cap it
 MOVLE   R1, R3				;less, so leave alone
 TEQ     R1, #0				;do we need to alter DA2 size?
 BEQ     _exit				;NO

 ._ok
 TEMP    R0
 #if JIT_debug == 1 AND compile_IOMD == 1
   STR     R13, dbg_pause		;pause debug whilst we switch mode
 #endif
 #if compile_GPU == 1
   STR     R13, blit_in_progress	;pause the blitter
 #endif
 LOCK    R0
 LDR     R0, Screen_Cache_Off
 TEQ     R0, #0				;is the screen cache off?
 BLEQ    unmap_screen_memory		;NO, unmap the RO3.1 screen memory
 MOV     R0, #2				;preserve R0
 BL      pass_SWI_on
 SWI     XOS_ChangeDynamicArea		;PRM1-384
 BL      post_SWI_veneer

 BL      get_screen_start		;get DA2 address and size
 BL      get_DA2_size			;work out the DA size
 BL      map_screen_memory		;re-map the RO3.1 screen memory

 TEMP    R14
 #if JIT_debug == 1 AND compile_IOMD == 1
   MOV     R2, #0
   STR     R2, dbg_pause		;unpause debug
 #endif
 #if compile_GPU == 1
   BL      start_fifty_hz_ticker	;reset Vsync counters
   MOV     R2, #0
   STR     R2, blit_in_progress		;unpause the blitter
 #endif
 LOCK    R14

 ._exit
 BL      dontexit_SWI_veneer
 LDMFD   R13!, {R2-R3}
B       vector_handler_trap

 ._SPSR		DBD 4
