;resetVectors
;------------
;Resets key vectors during image loading

.resetVectors
 STMFD   R13!, {R0-R7, R10-R12, R14}

 ADR     R6, softwareVectorBitmap
 ADR     R4, softwareVectors - (8 * FirstVectorToTrack)

 MOV     R0, #Vector_CLIV
 BL      checkVector
 MOV     R0, #Vector_ByteV
 BL      checkVector
 MOV     R0, #Vector_WordV
 BL      checkVector
 MOV     R0, #Vector_FileV
 BL      checkVector
 MOV     R0, #Vector_ArgsV
 BL      checkVector
 MOV     R0, #Vector_BGetV
 BL      checkVector
 MOV     R0, #Vector_BPutV
 BL      checkVector
 MOV     R0, #Vector_GBPBV
 BL      checkVector
 MOV     R0, #Vector_FindV
 BL      checkVector
LDMFD   R13!, {R0-R7, R10-R12, PC}



;checkVector
;-----------
;checks if a vector has change and points it back to ths OS if it has
;
;Entry:
; R0 = vector
; R4 = pointer to our vector table copy
; R6 = pointer to softwareVectorBitmap
;
;Exit:
; R1-R3   - corrupt
; R7      - corrupt
; R10-R12 - corrupt

.checkVector
 ADD     R7, R4, R0, LSL #3		;R7 = our copy of the vector in question

 LDRB    R1, [R6, R0, LSR #3]		;load relevant word from bitmap table
 AND     R2, R0, #%111			;bitmask
 MOV     R3, #1
 MOV     R3, R3, LSL R2			;R3 = bit to check
 TST     R1, R3				;have we already released the vector
 BNE     _reclaim			;YES, reclaim it

 LDMIA   R7, {R1, R2}			;load R12, PC values into registers
 TEQ     R1, #0				;do we have values?
 MOVEQ   PC, R14			;NO, exit

 STMFD   R13!, {R0, R14}
 ORR     R0, R0, #1<<31
 SWI     XOS_Release			;temporarily release the vector
 LDMVSFD R13!, {R0, PC}			;failed..hmm..hope for the best
 LDR     R0, [R13], #4

 LDRB    R1, [R6, R0, LSR #3]		;load relevant word from bitmap table
 AND     R2, R0, #%111			;bitmask
 MOV     R3, #1
 ORR     R1, R1, R3, LSL R2
 STRB    R1, [R6, R0, LSR #3]		;update so we know we've claimed it
LDR     PC, [R13], #4


 ._reclaim
 LDMIA   R7, {R1, R2}			;load R12, PC values into registers

 STMFD   R13!, {R0, R14}
 ORR     R0, R0, #1<<31
 SWI     XOS_Claim			;hand it back
 LDR     R0, [R13], #4

 LDRB    R1, [R6, R0, LSR #3]		;load relevant word from bitmap table
 AND     R2, R0, #%111			;bitmask
 MOV     R3, #1
 BIC     R1, R1, R3, LSL R2
 STRB    R1, [R6, R0, LSR #3]		;update so we know we've claimed it
LDR     PC, [R13], #4
