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

.vector_handler_2A
 TEQ     R0, #DA2_magic_number		;is it us?
 ANDEQ   R0, R0, #&FF			;YES
 BEQ     vector_handler_forward		; |+ pass to OS
 TEQ     R0, #2				;screen DA?
 BLEQ    check_taskID
 BNE     vector_handler_forward		;NO, pass to OS

 STMFD   R13!, {R2-R3}
 MOV     R3, R1
 BL      pre_SWI_veneer			;call SWI that follows
 SWI     XOS_ReadDynamicArea
 LDR     R0, emulate_RISCOS
 CMP     R0, #&350 << 8
 MOVHS   R1, R3				;don't restrict RO3.50+
 MOVHS   R3, #0
 TEMP    R0
 STR     R3, DA2_delta			;store the delta being requested
 LOCK    R0
 BHS     _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
   LDR     R3,  blit_in_progress	;R3=current state of blitter
   STR     R13, blit_in_progress	;pause the blitter
   #endif
 LOCK    R0
 BL      unmap_screen_memory		;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      check_taskID			;is the task supported?
 BLEQ    map_screen_memory		;YES, re-map the RO3.1 screen memory

 ._P1
 TEMP    R14
 #if JIT_debug == 1 AND compile_IOMD == 1
   MOV     R2, #0
   STR     R2, dbg_pause		;unpause debug
 #endif
 #if compile_GPU == 1
   STR     R3, blit_in_progress		;reset the blitter state
 #endif
 LOCK    R14

 ._exit
 BL      dontexit_SWI_veneer
EXITSWI "R2-R3"
