;
; DSP library interface
; routines:
;
; void DSPload(long *dspprog):
;	loads up the DSP program pointed to by "dspprog"
;	the first 2 longs are assumed to be the start and end
;	addresses, respectively
;
; void DSPrun(long *gpuaddr):
;	execute a GPU program, starting at the given address
;	in GPU ram, and wait for it to complete
;
	.include	'jaguar.inc'
	.include	'blit.inc'


_DSPload::
	move.l	4(sp),a0		; get pointer to program
	move.l	(a0)+,a1		; get pointer to start
	move.l	(a0)+,d0		; get pointer to length
;
; assembly language interface to load the DSP
; input: a0 points to source
;	 a1 points to destination in DSP land
;	 d0 is the length of the program

dspload::
	asr.l	#2,d0				;convert bytes to longs
	subq.l	#1,d0				;subtract 1 for loop counter
.20:	move.l	(a0)+,(a1)+
	dbra		d0,.20
	rts

_DSPrun::
	move.l	4(sp),a0
dsprun::
	move.l	a0,D_PC
	lea	D_CTRL,a1
	move.l	#$11,(a1)		; turn on the DSP
.10:
	divs	d0,d0			; useless instruction, but gets us off the bus
	move.l	(a1),d0			; wait for DSP completion
	btst.l	#0,d0
	bne.b	.10
.ret:
	rts

