******************************************************************************
;
;ChipMemPri 1.0 (8.2.96)
;by Torbjörn Andersson, Public Domain
;
;ChipMemPri was created for use with ShapeShifter.  It
;reboots and sets the priority of the chip memory to 127
;(max).  System resources will then be located in chip
;memory, leaving other memory free for other use.
;
******************************************************************************

NEWCHIPPRI=127

******************************************************************************

Start:
	move.l	(4).w,a6

	lea	$0142(a6),a0		; MemList
	jsr	-$0084(a6)		; _LVOForbid

.Loop
	move.l	(a0),a0
	tst.l	(a0)
	beq	.Quit
	btst	#1,$000F(a0)		; mh_Attributes+1, MEMB_CHIP
	beq	.Loop
	cmp.b	#NEWCHIPPRI,$0009(a0)	; ln_Pri
	beq	.Quit

	lea	Code(pc),a0
	move.l	a0,$002E(a6)		; CoolCapture
	bsr	ChkSum
	jsr	-$02D6(a6)		; _LVOColdReboot

.Quit
	jsr	-$008A(a6)		; _LVOPermit
	moveq	#0,d0
	rts

******************************************************************************

Code:
	lea	$0142(a6),a2		; MemList

.Loop
	move.l	(a2),a2
	tst.l	(a2)
	beq	.Rts
	btst	#1,$000F(a2)		; mh_Attributes+1, MEMB_CHIP
	beq	.Loop

	move.l	a2,a1			; node
	jsr	-$00FC(a6)		; _LVORemove
	move.b	#NEWCHIPPRI,$0009(a2)	; ln_Pri
	lea	$0142(a6),a0		; list, MemList
	move.l	a2,a1			; node
	jsr	-$010E(a6)		; _LVOEnqueue

.Rts
	rts

******************************************************************************

ChkSum:
	lea	$0022(a6),a0		; SoftVer
	moveq	#0,d0
	moveq	#22,d1

.Loop
	add	(a0)+,d0
	dbf	d1,.Loop
	not	d0
	move	d0,$0052(a6)		; ChkSum
	rts

******************************************************************************

	END

******************************************************************************
