;mouse_ptr_abort
;---------------
;An attempt was made to write to the Mouse Pointer memory space
;1F03800-1F03FFF - logical address space
;2081800-2081FFF - physical address space
;
;Entry:
; DAV_r0 - memory block, containing R0, R1 ... R14, PC
; R1 - aborting address

.mouse_ptr_abort
 MOV     R7, R1				;R7=aborting address

 SUB     R1, R1, #RO3xx_Pointer_Buffer
 CMP     R1, #&800			;is it within the Pointer buffer?
 BHS     AbortI_skip			;NO, skip instruction

 LDR     R0, DAV_abort			;the faulting address
 ADR     R6, DAV_r0			;R6 = register stack

 LDR     R0, [R0, #0]			;load the faulting instruction in R0
                 ;%100PUSWL		;STM instruction
 AND     R1, R0, #%11100001 << 20
 TEQ     R1,     #%10000000 << 20	;STMxx Rx, {Rn...Rn} ?
 BNE     _not_STM			;NO

					;R0 bits 15...0 contain registers
					;..written
 MOV     R5, R0, LSL #17		;reduce R5 to registers being written
 MOVS    R5, R5, LSR #18		;stripping off PC and leaving R0 in CS
 ._STM_loop
   LDRCS   R0, [R6]			;C set if register used
   BLCS    translate_mouse_ptr		;|+   perform the translation
   ADD     R6, R6, #4			;go to next register
   MOVS    R5, R5, LSR #1		;are there any more registers?
 BNE     _STM_loop			;loop until we've handled all registers
 BCS     _STM_loop			;catch the last register in C

B       AbortI_skip			;exit back to user code


 ._not_STM
                 ;%01IPUBWL		;STR instruction
 AND     R1, R0, #%11000001 << 20
 TEQ     R1,     #%01000000 << 20	;STR Rd, [Rn ...] ?
 MOVNE   R12, #9			;NO, ADFF5009
 BNE     report_unimplemented		;report until its coded

					;R0 contains instruction to decode
 AND     R1, R0, #%1111 << 12		;R0 = R2 << 12

 LDR     R0, [R6, R1, LSR #12 - 2]	;R0 = value to write
 BL      translate_mouse_ptr		;perform the translation

B       AbortI_skip			;exit back to user code


;Entry:
; R0 - value to write
; R7 - aborting address

.translate_mouse_ptr
 STR     R0, [R7], #4			;proxy the write
 MOV     PC, R14
