Source to src/dspbase.gas


Enter a symbol's name here to quickly find it.

_dspbase::
 .dsp
 .org $f1b000


RISC_FLAGS    	.equ    $f1a100
MODMASK			.equ	$f1a118
DIVCONTROL		.equ	$f1a11c

;MAIN_STACK    	.equ 	$f1d000
MAIN_STACK    	.equ 	$f1ce00
PERM_DATA		.equ	$f1ce00
LOADPOINT		.equ	$f1b140

_soundbuffer	==		$1f0000

R_DAC			.equ	$f1a148	
L_DAC			.equ	$f1a14c

;=============================================================================

S_LE	.ccdef  $14     ; PL
U_LE	.ccdef  $04     ; CC
S_GT    .ccdef	$18   	; MI
U_GT    .ccdef	$08  	; CS

S_LT	.ccdef	$15		; PL+NE
U_LT	.ccdef	$05		; CC+NE

FP 			.equr r14
scratch 	.equr r10
scratch2	.equr r11
RETURNVALUE .equr r29
RETURNPOINT .equr r28
MATH_A 		.equr r27
MATH_B 		.equr r26
MATH_C 		.equr r25
MATH_RTS 	.equr r24
MATH_SIGN 	.equr r23

;==============================================================================
	
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	
ALT_RISC_FLAGS	.equr	r13
ALT_FLAGSTEMP	.equr	r14
ALT_PCTEMP		.equr	r15
ALT_SAMPLECOUNT_P	.equr	r16
ALT_SCRATCH		.equr	r17
ALT_LDAC		.equr	r18
ALT_RDAC		.equr	r19
ALT_STACKRESET	.equr	r20
ALT_SAMPLE_P	.equr	r21
ALT_SAMPLE		.equr	r22
ALT_SAMPLECOUNT	.equr	r23

;----------------------
;
; int_1
;
; Sample output
; org $f1b010
;----------------------
int_1:
	load	(ALT_RISC_FLAGS),ALT_FLAGSTEMP	; get current flags
; start load of sample from external memory
	loadw	(ALT_SAMPLE_P),ALT_SAMPLE
	addqmod	#2,ALT_SAMPLE_P				; bump sample pos after getting flags
 	
; start interrupt cleanup
	bclr	#3,ALT_FLAGSTEMP			; clear IMASK
	bset	#10,ALT_FLAGSTEMP			; and interrupt 1 latch
	addq	#1,ALT_SAMPLECOUNT			; bump fast timing counter

	load 	(r31),ALT_PCTEMP			; get last instruction address
	move	ALT_STACKRESET,r31			; reset stack to safe spot
	addq	#2,ALT_PCTEMP				; point to next instruction to execute
	store	ALT_SAMPLECOUNT,(ALT_SAMPLECOUNT_P)	; store it to memory
		
; play left and right samples through dacs
	store	ALT_SAMPLE,(ALT_LDAC)
	store	ALT_SAMPLE,(ALT_RDAC)
	
; return from interrupt
	jump	T,(ALT_PCTEMP)					; return
	store	ALT_FLAGSTEMP,(ALT_RISC_FLAGS)	; restore flags
	
	.long

_samplecount::		.dc.l	0

_dspcodestart::		.dc.l	0
_dspfinished::		.dc.l	$def6

_olddspcodestart::	.dc.l	0

_int_stack:			.dc.l	0,0,0,0		; give it some room to be flaky...

;--------------------
;
; startup code
;
;--------------------
_dspbase_init::
;
; set up bank 0 registers for interrupt usage
;
	movei	#RISC_FLAGS,ALT_RISC_FLAGS
	movei	#_samplecount,ALT_SAMPLECOUNT_P
	movei	#L_DAC,ALT_LDAC
	movei	#R_DAC,ALT_RDAC
	movei	#_int_stack+8,ALT_STACKRESET	
	movei	#_soundbuffer,ALT_SAMPLE_P
	moveq	#0,ALT_SAMPLECOUNT
	
	movei	#MODMASK,scratch
	movei	#$ffffe000,scratch2
	store	scratch2,(scratch)		; set up for 16k circular buffers
	
	move	ALT_STACKRESET,r31				; in register bank 0	
	
	movei	#(1<<5)+(1<<14),r0			; enable I2S interrupts and regpage 
	store	r0,(ALT_RISC_FLAGS)

	nop									; wait for the reg page to flip
	nop
	nop
	nop
		
;--------------------
;
; wait for a load command
;
;--------------------
nothingwaiting:

waitcmd:
	movei	#_dspcodestart,r2
	load	(r2),r1
	or		r1,r1
	jr		EQ,nothingwaiting
	nop
		
;
; if still in memory, skip the load
;
	movei	#_olddspcodestart,r3
	load	(r3),r4
	cmp		r1,r4
	movei	#skipload,r5
	jump	EQ,(r5)			; still in memory
	store	r1,(r3)			; delay slot

	move	r1,r2
	subq	#4,r2			; code size is just before start
	load	(r2),r2
	addq	#7,r2
	shrq	#3,r2			; number of phrases to bopy
	
	movei	#LOADPOINT,r0	; destination for code
	move	r1,r3
	move	r0,r4
	addq	#4,r3
	addq	#4,r4
loadloop:
	load	(r1),r5
	load	(r3),r6
	store	r5,(r0)
	addqt	#8,r1
	addqt	#8,r3
	store	r6,(r4)
	subq	#1,r2			; decrement count
	addqt	#8,r4
	jr		PL,loadloop
	addqt	#8,r0
	nop
	
;	
; call it
;
skipload:
	movei	#LOADPOINT,r0
	movei	#dspreturn,RETURNPOINT
	movei   #MAIN_STACK,r14
 
 	jump	T,(r0)
	nop

dspreturn:
	movei	#_dspcodestart,r2
	moveq	#0,r0
	store	r0,(r2)				; dspcodestart = 0

	movei	#_dspfinished,r2
	movei	#$def6,r0
	store	r0,(r2)				; dspcodestart = 0

	movei	#waitcmd,r0
	jump	T,(r0)
	nop




	.phrase
	.68000