;vector_handler_40140
;--------------------
;Prevents Channel Handlers from taking over

;Entry:
; R0 - 0 or Number of channels
; R1 - 0 or Sample length
; R2 - 0 or Sample period
; R3 - 0 or Channel Handler address
; R4 - 0 or Scheduler address

.vector_handler_40140
 LDR     R11, dont_trap_sound_configure
 TEQ     R11, #0			;should we trap Sound_Configure?
 BEQ     vector_handler_forward		;NO, pass to OS

 ADR     R11, hypervised_sound_configure ;values currently in use
 LDR     R14, [R11, #sound_config_struct.Scheduler]
 STR     R14, [R13, #-4]!		;exit R4
 LDR     R14, [R11, #sound_config_struct.ChannelHandler]
 STR     R14, [R13, #-4]!		;exit R3
 LDR     R14, [R11, #sound_config_struct.period]
 STR     R14, [R13, #-4]!		;exit R2
 LDR     R14, [R11, #sound_config_struct.length]
 STR     R14, [R13, #-4]!		;exit R1
 LDR     R14, [R11, #sound_config_struct.channels]
 STR     R14, [R13, #-4]!		;exit R0

 LDR     R14, emulate_RISCOS
 CMP     R14, #&350 << 8		;emulating <RO3.5
 BHS     _P1				;NO

 TEQ     R2, #0				;YES, use previous value if R2=0
 MOVNE   R14, #0
 STRNE   R14, [R11, #sound_config_struct.VIDC1_period]
 BNE     _P1

 LDR     R14, [R11, #sound_config_struct.VIDC1_period]
 STR     R2, [R11, #sound_config_struct.VIDC1_period]
 MOVS    R2, R14			;was value previous set?
 STRNE   R2, [R13, #2 * 4]		;YES, overwrite R2 on stack

 ._P1
 TEQ     R3, #0				;Channel Handler
 STRNE   R3, [R11, #sound_config_struct.ChannelHandler]
 MOVNE   R3, #0				;we'll handle this
 TEQ     R4, #0				;Scheduler
 STRNE   R4, [R11, #sound_config_struct.Scheduler]
 MOVNE   R4, #0				;we'll handle this

 TEQ     R0, #0
 STRNE   R0, [R11, #sound_config_struct.channels]
 TEQ     R1, #0
 STRNE   R1, [R11, #sound_config_struct.length]
 TEQ     R2, #0
 STRNE   R2, [R11, #sound_config_struct.period]
 ADDEQS  R14, R0, R1			;are the values all zeros?
 EXITSWIEQ "R0-R4"			;YES, exit

 STR     R0, [R13, #-4]!
 MOV     R0, #0
 BL      check_and_return_taskID	;R0=taskID if under JIT or 0
 STR     R0, [R11, #sound_config_struct.taskID]
 LDR     R0, [R13], #4

 BL      pre_SWI_veneer			;call SWI that follows
 SWI     XSound_Configure		;PRM4-18
 BL      post_SWI_veneer
 BL      dontexit_SWI_veneer
EXITSWI "R0-R4"

 .dont_trap_sound_configure DCD 0
