Page 1 of 1

Playing samples

Posted: Sun Jul 16, 2017 7:49 pm
by robcfg
Hi!

I'm trying to play a 3000hz sample, but as I've never programmed sound on the Dragon, I'm sure I'm not doing it right.

Here's my code:

Code: Select all

	ORG 20000
	orcc #$50 ; Disable Interrupts
	lda	$ff01			; Select DAC as sound source
	anda	#$f7
	sta	$ff01
	lda	$ff03
	anda	#$f7
	sta	$ff03

	lda	$ff21			; PIA direction
	anda #$FB
	sta	$ff21

	lda	$ff23			; Enable sound
	ora	#$8
	sta	$ff23

	LDX #$35E2
doit LDA ,x+	; 5 cycles
	ANDA #$FC
	STA $FF20  	; 5 cycles
	; 272 cycles
	CMPU #0		; 4 * 8 = 32 cycles
	CMPS #0
	CMPU #0
	CMPS #0
	CMPU #0		; 4 * 8 = 32 cycles
	CMPS #0
	CMPU #0
	CMPS #0
	CMPU #0		; 4 * 8 = 32 cycles
	CMPS #0
	CMPU #0
	CMPS #0
	CMPU #0		; 4 * 8 = 32 cycles
	CMPS #0
	CMPU #0
	CMPS #0
	CMPU #0		; 4 * 8 = 32 cycles
	CMPS #0
	CMPU #0
	CMPS #0
	CMPU #0		; 4 * 8 = 32 cycles
	CMPS #0
	CMPU #0
	CMPS #0
	CMPU #0		; 4 * 8 = 32 cycles
	CMPS #0
	CMPU #0
	CMPS #0
	CMPU #0		; 4 * 8 = 32 cycles
	CMPS #0
	CMPU #0
	CMPS #0
	CMPU #0		; 2 * 8 = 16 cycles
	CMPS #0
	TFR x,d 	; 6 cycles
	CMPD #$4498 ; 8 cycles
	BEQ theend 	; 3 cycles
	LBRA doit	; 5 cycles	
theend ANDCC #$AF
	RTS
The CMPU/CMPS instructions are there to provide the necessary delay between samples.

Can anyone please tell me what am I doing wrong?

Cheers,
Rob

Re: Playing samples

Posted: Sun Jul 16, 2017 9:21 pm
by robcfg
Just solved it!

I made two big changes. I changed the idle instructions for sta to the dac port (in case it doesn't latch the values) and put the right start of the sample :P

Here's the code:

Code: Select all

	ORG 20000
	orcc #$50 ; Disable Interrupts
	lda	$ff01			; Select DAC as sound source
	anda	#$f7
	sta	$ff01
	lda	$ff03
	anda	#$f7
	sta	$ff03

	lda	$ff21			; PIA direction
	anda #$FB
	sta	$ff21

	lda	$ff23			; Enable sound
	ora	#$8
	sta	$ff23

	LDX #$2328
doit LDA ,x+	; 5 cycles
	ANDA #$FC
	LDB #28

loop STA $FF20  ; 5 cycles
	DECB 		; 2 cycles
	BNE loop	; 3 cycles
	TFR x,d 	; 6 cycles
	CMPD #$4498 ; 8 cycles
	BEQ theend 	; 3 cycles
	LBRA doit	; 5 cycles	
theend ANDCC #$AF
	RTS