;
; 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 saves the 68000's registers.
;
; (C) Copyright Rich Teer 1990, 2023, 2026.
;

	globl	_save_regs
	globl	_io_save_regs

_save_regs:
	MOVE.L	A0,-(A7)			; Save A0 on stack
	MOVE.L	$08(A7),A0			; Move address of process descriptor into A0
	MOVE.L	(SP),$04(A0)		; Put original A0 in PD
	MOVE.L	A1,$08(A0)			; Save A1 in PD
	MOVE.L	A2,$0C(A0)			; Save A2 in PD
	MOVE.L	A3,$10(A0)			; Save A3 in PD
	MOVE.L	A4,$14(A0)			; Save A4 in PD
	MOVE.L	A5,$18(A0)			; Save A5 in PD
	MOVE.L	A6,$1C(A0)			; Save A6 in PD
	MOVE.L	D0,$20(A0)			; Save D0 in PD
	MOVE.L	D1,$24(A0)			; Save D1 in PD
	MOVE.L	D2,$28(A0)			; Save D2 in PD
	MOVE.L	D3,$2C(A0)			; Save D3 in PD
	MOVE.L	D4,$30(A0)			; Save D4 in PD
	MOVE.L	D5,$34(A0)			; Save D5 in PD
	MOVE.L	D6,$38(A0)			; Save D6 in PD
	MOVE.L	D7,$3C(A0)			; Save D7 in PD
	MOVE.L	A7,D0				; Copy SP to D0
	ADDQ.L	#$04,D0				; Bypass A0 on the stack
	MOVE.L	D0,(A0)				; Save "fudged" SP in PD
	MOVE.L	(A7)+,A0			; Restore A0
	RTS							; and return

_io_save_regs:
	MOVE.L	A0,-(A7)			; Save A0 on stack
	MOVE.L	$08(A7),A0			; Move address of process descriptor into A0
	MOVE.L	(SP),$04(A0)		; Put original A0 in PD
	MOVE.L	A1,$08(A0)			; Save A1 in PD
	MOVE.L	A2,$0C(A0)			; Save A2 in PD
	MOVE.L	A3,$10(A0)			; Save A3 in PD
	MOVE.L	A4,$14(A0)			; Save A4 in PD
	MOVE.L	A5,$18(A0)			; Save A5 in PD
	MOVE.L	A6,$1C(A0)			; Save A6 in PD
	MOVE.L	D0,$20(A0)			; Save D0 in PD
	MOVE.L	D1,$24(A0)			; Save D1 in PD
	MOVE.L	D2,$28(A0)			; Save D2 in PD
	MOVE.L	D3,$2C(A0)			; Save D3 in PD
	MOVE.L	D4,$30(A0)			; Save D4 in PD
	MOVE.L	D5,$34(A0)			; Save D5 in PD
	MOVE.L	D6,$38(A0)			; Save D6 in PD
	MOVE.L	D7,$3C(A0)			; Save D7 in PD
	MOVE.L	A7,D0				; Copy SP to D0
	ADD.L	#$0E,D0				; Bypass A0 and rest of crap on stack 
	MOVE.L	D0,(A0)				; Save "fudged" SP in PD
	MOVE.L	(A7)+,A0			; Restore A0
	RTS							; and return
