Playing samples

Hardware Hacking, Programming and Game Solutions/Cheats
Post Reply
User avatar
robcfg
Posts: 1232
Joined: Sat Apr 04, 2009 10:16 pm
Location: Stockholm, Sweden

Playing samples

Post by robcfg » Sun Jul 16, 2017 7:49 pm

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

User avatar
robcfg
Posts: 1232
Joined: Sat Apr 04, 2009 10:16 pm
Location: Stockholm, Sweden

Re: Playing samples

Post by robcfg » Sun Jul 16, 2017 9:21 pm

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

Post Reply