changeset 13:26d73f210da8

Add some comments related to sound
author William Astle <lost@l-w.ca>
date Mon, 22 Dec 2014 22:51:46 -0700
parents a1b93f4bd329
children adfc4ab79eeb
files dod.s
diffstat 1 files changed, 47 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/dod.s	Mon Apr 21 22:20:29 2014 -0600
+++ b/dod.s	Mon Dec 22 22:51:46 2014 -0700
@@ -269,7 +269,7 @@
 V25B		rmb 2
 V25D		rmb 2
 V25F		rmb 2
-V261		rmb 1
+soundvol	rmb 1				sound: volume multiplier for sound playing
 V262		rmb 1
 V263		rmb 2
 V265		rmb 6
@@ -1433,10 +1433,10 @@
 LC7C8		ldx 12,s			fetch return address
 		lda ,x+				fetch immediate data
 		stx 12,s			update return address
-		ldb #$ff
+		ldb #$ff			set to maximum volume
 ; swi 28 routine
 ; play a sound specified by the value in A
-LC7D0		stb V261
+LC7D0		stb soundvol			set the volume for the sound playing routine
 		ldx #LC7DC			point to sound routine jump table
 		lsla				two bytes per jump table entry
 		jsr [a,x]			call the sound generator routine
@@ -1461,46 +1461,52 @@
 		fdb LC8DA			sound 15
 		fdb LC8A6			sound 16
 		fdb LC8B2			sound 17
-		fdb LC93F			sound 18
+		fdb LC93F			sound 18 - attack hit
 		fdb LC8E6			sound 19
 		fdb LC872			sound 20
 		fdb LC86D			sound 21
-		fdb LC88A			sound 22
+		fdb LC88A			sound 22 - wizard
 ; sound 12
-LC80A		ldu #LC823
-		lda #4
-		bra LC816
+LC80A		ldu #LC823			point to 144Hz base tone
+		lda #4				repeat sound 4 times
+		bra LC816			go do the sound
 ; sound 13
-LC811		ldu #LC81F
-		lda #10
-LC816		sta V25F
-LC818		jsr ,u
-		dec V25F
-		bne LC818
+LC811		ldu #LC81F			point to 288Hz base tone
+		lda #10				repeat sound 10 times
+LC816		sta V25F			set repeat counter
+LC818		jsr ,u				make a sound
+		dec V25F			have we done enough of them?
+		bne LC818			brif not
 		rts
-LC81F		ldx #$40
+; These routines produce a "sliding" tone starting at the base frequency. The specified base
+; frequency is a rough estimate. The tones are created using square waves. After each full wave,
+; the delay in reduced by one which increases the frequency. The last cycle is with the delay
+; equal to 1 which yields an approximate frequency of 9520Hz.
+LC81F		ldx #$40			set low frequency of sliding tone to ~288Hz
 		fcb $10
-LC823		ldx #$80
+LC823		ldx #$80			set low frequency of sliding tone to ~144Hz
 		fcb $10
 ; sound 14
-LC827		ldx #$100
+LC827		ldx #$100			set low frequency of sliding tone to ~72Hz
 		fcb $10
 ; sound 0
-LC82B		ldx #$20
-LC82E		bsr LC835
-		leax -1,x
-		bne LC82E
+LC82B		ldx #$20			set low frequency of sliding tone to ~566Hz
+LC82E		bsr LC835			do one square wave
+		leax -1,x			reduce delay (increase frequency)
+		bne LC82E			brif not yet reached maximum frequency
 		rts
-LC835		lda #$ff
-		bsr LC869
-		clra
-		bra LC869
+; Output a square wave with wave time defined by delay in X
+LC835		lda #$ff			(2~) hold DAC high for delay in X
+		bsr LC869			(7~)
+		clra				(2~) hold DAC low for delay in X
+		bra LC869			(3~)
 ; sound 3
-LC83C		ldx #$500
-LC83F		bsr LC835
-		leax $30,x
-		cmpx #$800
-		blo LC83F
+; Output a series of 16 ascending tones with a base frequency descending from 14.5Hz to 9Hz.
+LC83C		ldx #$500			set for an ascending tone from 14.5Hz
+LC83F		bsr LC835			go make the sound
+		leax $30,x			decrease starting tone frequency by a bit
+		cmpx #$800			have we reached 9Hz?
+		blo LC83F			brif not
 		rts
 ; sound 6
 LC84A		lda #2
@@ -1521,8 +1527,8 @@
 		bne LC854
 		rts
 LC867		bsr LC8CE
-LC869		bsr LC8C5
-		bra LC8BD
+LC869		bsr LC8C5			(7~) program the DAC
+		bra LC8BD			(3~) count down delay non-destructively
 ; sound 21
 LC86D		ldu #LDBDA
 		bra LC893
@@ -1568,15 +1574,15 @@
 LC8B6		bsr LC926
 		bra LC8B6
 LC8BA		ldx #$1000
-LC8BD		pshs x
-LC8BF		leax -1,x
-		bne LC8BF
-LC8C3		puls x,pc
-LC8C5		ldb V261
-		mul
-		anda #$fc
-		sta PIA1
-		rts
+LC8BD		pshs x				(7~) save delay counter
+LC8BF		leax -1,x			(5~) has timer expired?
+		bne LC8BF			(3~) brif not
+LC8C3		puls x,pc			(9~) restore delay counter and return
+LC8C5		ldb soundvol			(5~) fetch volume multiplier for sound
+		mul				(11~) multiply it by the value we're trying to set
+		anda #$fc			(2~) lose the non-DAC bits
+		sta PIA1			(5~) set DAC
+		rts				(5~)
 LC8CE		ldd V256
 		lslb
 		rola