;
; This file and its contents are supplied under the terms of the
; Mozilla Public License (MPL) version 2.0.  You may only use this
; file in accordance with the terms of version 2.0 of the MPL.
;
; A full copy of the text of the MPL should have accompanied this
; source.  A copy of the MPL is also available via the Internet at
; https://www.mozilla.org/en-CA/MPL/2.0.
;
; This Source Code Form is "Incompatible With Secondary Licenses",
; as defined by the Mozilla Public License, v. 2.0.
;
; This file sets the interrupt vector and interrupt mask.
;
; (C) Copyright Rich Teer 1990, 2023, 2026.
;

	globl	_set_vector
	globl	_int_handler

_set_vector:
	MOVE.L	$04(A7),A0					; Get vector address off of stack
	MOVE.W	#$4EF9,(A0)					; and put JMP xxxx there
	MOVE.L	#_int_handler,$02(A0)		; Put address of interrupt handler in JMP instruction
	RTS									; and return

	globl	_set_int_mask
	globl	_reset_int_mask

_set_int_mask:
	MOVE.W	SR,saved_sr					; Save the old interrupt level
	MOVE.L	D0,-(A7)					; Save D0
	MOVE.L	$08(A7),D0					; Get the interrupt level from the stack
	ADD.L	#$20,D0						; Add $20
	ASL.L	#8,D0						; Shift left 8 places
	MOVE.W	D0,SR						; Stick the new interrupt level in the SR
	MOVE.L	(A7)+,D0					; Restore D0
	RTS									; and return

_reset_int_mask:
	MOVE.W	saved_sr,SR					; Put the saved interrupt mask back in the SR
	RTS									; and return

saved_sr:
	DS.W	1							; Space for saved SR
