Add tools/ and manual/, move sources to src/
[dpadhero2.git] / src / sound / sfx.asm
blob0fe08f03137817708ecb332fbaf248ae66c80f49
2 ; Copyright (C) 2004, 2005 Kent Hansen.
4 ; This file is part of Neotoxin.
6 ; Neotoxin is free software; you can redistribute it and/or modify
7 ; it under the terms of the GNU General Public License as published by
8 ; the Free Software Foundation; either version 2 of the License, or
9 ; (at your option) any later version.
11 ; Neotoxin is distributed in the hope that it will be useful,
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ; GNU General Public License for more details.
16 ; You should have received a copy of the GNU General Public License
17 ; along with this program; if not, write to the Free Software
18 ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ; Description:
22 ; Routines for starting and updating sound effects.
24 .include "mixer.h"
26 .dataseg zeropage
28 sfx .ptr
30 .codeseg
32 .public start_sfx
33 .public start_square_sfx
34 .public start_tri_sfx
35 .public start_noise_sfx
36 .public sfx_tick
38 .extrn mixer:mixer_state
39 .extrn sfx_table:ptr
40 .extrn mixer_invalidate_period_save:proc
42 ; Starts playing a sound effect on given channel.
43 ; Params: A = SFX #
44 ; X = channel # * 4
45 ; Destroys: Y
46 .proc start_sfx
47 asl
48 tay
49 lda sfx_table.lo,y
50 sta mixer.sfx.ptr.lo,x
51 lda sfx_table.hi,y
52 sta mixer.sfx.ptr.hi,x
53 lda #1
54 sta mixer.sfx.counter,x ; triggers on next sfx_tick()
55 rts
56 .endp
58 ; Starts playing a sound effect on square channel 1.
59 ; Params: Y = *_SFX (see sfx.h)
60 ; Destroys: A, Y
62 .proc start_square_sfx
63 txa
64 pha
65 ldx #4 ; square channel 1
66 go_sfx:
67 tya
68 jsr start_sfx
69 pla
70 tax
71 rts
72 .endp
74 .proc start_tri_sfx
75 txa
76 pha
77 ldx #8 ; triangle channel
78 jmp go_sfx
79 .endp
81 .proc start_noise_sfx
82 txa
83 pha
84 ldx #12 ; noise channel
85 jmp go_sfx
86 .endp
88 ; Does one "tick" of SFX processing.
89 ; Params: X = offset into sfx array
91 .proc sfx_tick
92 dec mixer.sfx.counter,x
93 bne ++
94 lda mixer.sfx.ptr.lo,x
95 sta sfx.lo
96 lda mixer.sfx.ptr.hi,x
97 sta sfx.hi
98 ldy #0
99 lda [sfx],y
100 bne +
101 ; end sfx
102 sta mixer.sfx.ptr.hi,x ; NULL
103 cpx #8
104 bcs ++
105 ; for square channels, force the mixer to refresh HW regs
106 jmp mixer_invalidate_period_save
107 ++ rts
108 + sta mixer.sfx.counter,x ; # of ticks until next update
110 ; write new values to sound regs
111 lda [sfx],y
112 sta $4000,x ; this works since sizeof(sfx_state) is 4 bytes
114 lda [sfx],y
115 sta $4001,x
117 lda [sfx],y
118 sta $4002,x
120 lda [sfx],y
121 sta $4003,x
123 ; increment SFX pointer
126 adc mixer.sfx.ptr.lo,x
127 sta mixer.sfx.ptr.lo,x
128 bcc +
129 inc mixer.sfx.ptr.hi,x
130 + rts
131 .endp
133 .end