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

; R11 - pointer to VARS
; R12 - address for state

.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			;YES, is the task supported?
 BLEQ    check_SWI_in_appspace_or_JIT	;YES, is it within appspace?
 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, [R11, #emulate_RISCOS - VARS]
 CMP     R0, #&350 << 8
 MOVHS   R1, R3				;don't restrict RO3.50+
 MOVHS   R3, #0
 #if compile_RO == 400
   STR     R3, [R11, #DA2_delta - VARS]	;fix RO4/6 SA
 #endif
 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
 #if JIT_debug == 1 AND compile_IOMD == 1
   TEMP    R0
   STR     R13, dbg_pause		;pause debug whilst we switch mode
   LOCK    R0
 #endif
 #if compile_GPU == 1
   LDR     R3, [R11, #blit_in_progress - VARS]	;R3=current state of blitter
   STR     R13, [R11, #blit_in_progress - VARS]	;pause the blitter
 #endif
 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
 #if JIT_debug == 1 AND compile_IOMD == 1
   TEMP    R14
   MOV     R2, #0
   STR     R2, dbg_pause		;unpause debug
   LOCK    R14
 #endif
 #if compile_GPU == 1
   STR     R3, [R11, #blit_in_progress - VARS]	;reset the blitter state
 #endif

 ._exit
 BL      dontexit_SWI_veneer
EXITSWI "R2-R3"
