-
Notifications
You must be signed in to change notification settings - Fork 1
/
RBSOUN.MAC
264 lines (263 loc) · 6.5 KB
/
RBSOUN.MAC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
.TITLE RBSOUN-(WAS T2SOUN)
.RADIX 16
.INCLUDE COND65 ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.ENABLE AMA
.REPT 0
*****************************************
*
*POKEY SOUND SYSTEM CONTROL
*
*PROJECT #: 22603 (RED BARON)
*HARDWARE: A CORRECTLY INSTALLED POKEY
*
*DESCRIPTION: THIS CONTAINS 2 ROUTINES:
* 1) THE FIRST ROUTINE STARTS A SOUND.
* IT MAY BE CALLED ANYTIME, BUT CERTAIN
* PRIORITY RULES ON SOUNDS APPLY (SEE ROUTINE)
* 2) THE SECOND MUST BE CALLED ONCE EVERY 4 MSEC.
* THIS ROUTINE CONTINUES A SOUND.
* IT ALSO SHUTS THINGS UP WHEN DONE.
*
******************************************
*
*PROGRAMMER: RICH ADAM
*
******************************************
.ENDR
.PAGE
.SBTTL GLOBLS
;ENTRY POINTS (AS SUBROUTINES)
.GLOBL SNDON,MODSND
;RAM CELLS
.GLOBB GAMODE,SLAMSN
;SOUND RAM CELLS
.GLOBL POINT,CURRENT,FRAMES,COUNT
;HARDWARE
.GLOBL POKEY
.PAGE
.SBTTL SOUND DESCRIPTION
;THE FOLLOWING MUST BE DEFINED SOME WHERE IN YOUR RAM ALLOCATION
;SOUND ROUTINE VARIABLES
.REPT 0
;*** NOTE: 'IDLEV' CAN BE REPLACED BY A 6 BYTE TABLE WITH
; NO CHANGE TO THE CODE. USING RAM ALLOWS YOU TO
; CHANGE THE OUTPUT SOUND WITHOUT USING 'STSOUND'
; BY SIMPLY PUTTING THE DESIRED SOUND INFORMATION
; INTO THE ABOVE 6 BYTE. THE SOUND ROUTINES WILL
; CONTINUE TO OUTPUT THIS 'FORCED' SOUND UNTIL
; YOU CALL 'STSOUND' OR PUT SOME OTHER VALUE INTO
; 'IDLEV'. IF YOU USE A TABLE, THE FOLLOWING DATA
; IS RECOMENDED:
; IDLEV: .BYTE 0C0,0,1F,80,0FE,80
;*************************************************************
;
.ENDR
;
;POKEY REGISTER FUNCTIONS
;
;AUDCTL - AUDIO CONTROL
;
;D7 CHANGE 17 BIT POLY INTO 9 BIT POLY
;D6 CLOCK CHANNEL 1 W/1.79 MHZ (INSTEAD OF 64 KHZ)
;D5 " " 3 W/ " " " "
;D4 " " 2 W/CHANNEL 1 (INSTEAD OF 64 KHZ)(16 BIT)
;
;D3 " " 4 " 3 " " " "
;D2 HI-PASS FILTER IN CHANNEL 1 CLOCKED BY CHANNEL 3
;D1 " " " 2 " " 4
;D0 CHANGE NORMAL 64 KHZ TO 15 KHZ
;
;[N IS SET IN AUDIO FREQUENCY REGISTERS @ AUDF1,+2,+4,+6
;
;ACC - AUDIO CHANNEL CONTROL @ AUDF1+1,+3,+5,+7
;
;D7 D6 D5 D4 (D3-D0 = VOLUME)
;
; 0 0 0 0 17 BIT POLY / 5 BIT POLY / N
; 0 0 1 0 5 BIT POLY / N / 2
; 0 1 0 0 4 BIT POLY / 5 BIT POLY / N
; 0 1 1 0 5 BIT POLY / N / 2
; 1 0 0 0 17 BIT POLY / N
; 1 X 1 0 PURE TONE / N / 2
; 1 1 0 0 4 BIT POLY / N
; X X X 1 FORCE OUTPUT (VOLUME ONLY)
;
;EACH TABLE ENTRY IS 4 BYTES DESCRIBING A SEQUENCE, CONSISTING OF:
STVAL =0 ;VALUE TO START SEQUENCE
FRCNT =1 ;# OF FRAMES BEFORE ANY CHANGE
CHANGE =2 ;AMOUNT OF CHANGE
NUMBER =3 ;TOTAL NUMBER OF CHANGES IN THIS SEQUENCE-1
;EX1: 0FF,1,-1,6 DESCRIBES THE FOLLOWING SEQUENCE
; 0FF,0FE,0FD,0FC,0FB,0FA,0F9
;EX2: 0,45,0,1 WILL OUTPUT 0 FOR 46 FRAMES
;
.PAGE
.SBTTL OFFSET MACROS FOR SOUND ROUTINES
.MACRO OFFSET,LABEL
.IRPC X,<12345678>
.IF DF,LABEL''X
.BYTE LABEL''X-SOUND
.IFF
.BYTE 0
.ENDC
.ENDR
.ENDM
;
;THE ABOVE MACRO GENERATES THE OFFSETS FROM THE 'SOUND' BASE ADDRESS
;FOR A CHANNEL OF DATA.
;IF LESS THAN 4 CHANNELS ARE USED, THE REMAINING POINTERS ARE SET TO 0
;A 0 VALUE POINTER INDICATES AN IDLE CHANNEL.
;
;EX: SOUND: .BYTE 0
;
; CH1: .BYTE 0,45,0,1
; CH2: .BYTE 0,45,0,2,3,7,9,1
;
;BY CALLING 'OFFSET CH' , THE FOLLOWING WILL BE PLACED IN LINE
; .BYTE CH1-SOUND
; .BYTE CH2-SOUND
; .BYTE 0,0,0,0
;
.PAGE
.SBTTL SOUND TABLES
;
;TABLES OF OFFSET POINTER FOR SOUNDS. (6 BYTES PER SOUND NUMBER)
.CSECT RBSOUN
PNTRS: OFFSET TK
OFFSET WP
OFFSET BN
OFFSET TH
OFFSET TP
PTLEN =.-PNTRS
;AUDIO CONTROL CHANNEL VALUE (1 BYTE PRE SOUND NUMBER)
IDLEV =0
;SOUND TABLES
;ALL OF THESE LABELS GO
;HERE SO THEY HAVE AN
;OFFSET OF 0, WHICH
;PREVENTS THE SOUND FROM
;AFFECTING THOSE CHANNELS
;WHICH HAVE AN OFFSET
;OF 0
SOUND: .BYTE 0
.PAGE
;A GOOD PLACE FOR THE CHECKSUM
;DATA STRUCTURES:
;A CHANNEL CONSISTS OF A SERIES OF 4 BYTE SEQUENCES:
; BYTE FUNCTION
; 1 STARTING VALUE OF SEQUENCE
; 2 # OF FRAMES BEFORE NEXT CHANGE
; 3 AMOUNT OF CHANGE
; 4 TOTAL NUMBER OF CHANGES (# OF DIFFERENT VALUES-1)
;TO STOP A CHANNEL & RETURN TO ITS IDLE STATE, PUT IN AS A
;2 BYTE SEQUENCE X,0 WHERE X WILL BE USED AS THE NEW IDLE VALUE.
;
;POINT TICK
TK1: .BYTE 30,7,0,4
.BYTE 0,0
TK2: .BYTE 0A4,7,0FF,4
.BYTE 0,0
;
;BONUS LIFE
;
BN1: .BYTE 06,1,1,30
.BYTE 06,1,1,30
.BYTE 06,1,1,30
.BYTE 06,1,1,30
.BYTE 06,1,1,30
.BYTE 06,1,1,30
.BYTE 0,0
BN2: .BYTE 0A4,2,0,90
.BYTE 0,0
;
;NEW PLANE SOUND
;
WP5: .BYTE 54,2,0FF,3C
.BYTE 54,2,0FF,3C
.BYTE 54,2,0FF,3C
.BYTE 0,0
WP6: .BYTE 0A4,2,0,0B4
.BYTE 0,0
;
;THREE HUNDRED POINTS SOUND
;
TH3: .BYTE 79,2,0,10
.BYTE 6C,2,0,10
.BYTE 60,2,0,10
.BYTE 40,2,0,20
.BYTE 60,2,0,10
.BYTE 40,2,0,20
.BYTE 0,0
TH4: .BYTE 0A4,2,0,80
.BYTE 0,0
;
;10 POINT TICK
;
TP1: .BYTE 38,0A,0,4
.BYTE 0,0
TP2: .BYTE 0A4,0A,0FF,4
.BYTE 0,0
.PAGE
;
;ACC=SOUND OFFSET
;
SNDON: BIT Z,GAMODE ;ATTRACT MODE?
BPL 10$ ;YES
CPY I,PTLEN+7 ;PAST TABLE?
IFCC
LDX I,7
BEGIN
LDA Y,PNTRS
IFNE ;IF POINTER 0 DONT TOUCH THIS CHANNEL
STA X,POINT ;IF NOT SET UP POINTER
LDA I,1
STA X,FRAMES ;DUMMY START, NO SOUND
STA X,COUNT ;TILL MODSND STORES TO POKEY
THEN
DEY
DEX
MIEND
THEN
10$: RTS
.PAGE
.SBTTL SOUND ROUTINE
;
;CONTINUES A PREVIOUSLY STARTED SOUND
;
MODSND: LDX I,7 ;4 CHANNELS (FREQUENCY, PURE/POLY & VOLUME) 2 BYTES/
10$: LDY X,POINT ;GET DATA POINTER
BEQ 40$ ;NOT ACTIVE CHANNEL
DEC X,FRAMES ;CHANGE THIS FRAME
BNE 30$
DEC X,COUNT ;DATA CHANGES LEFT?
BNE 20$ ;NO -- NONE
LDA Y,SOUND+STVAL ;GET CURRENT VALUE
STA X,CURRENT ;SAVE
LDA Y,SOUND+FRCNT ;GET FRAMES OF THIS LEVEL
STA X,FRAMES ;UPDATE FRAME NUMBER
BNE 17$ ;IF 0, THIS CHANNEL JUST ENDED
STA X,POINT ;SET POINTER TO 0 TO IDLE CHANNEL
BEQ 30$ ;JUST IDLE CHANNEL (ALWAYS)
17$: LDA Y,SOUND+NUMBER
STA X,COUNT ;# OF CHANGES
LDA X,POINT
CLC
ADC I,4 ;POINT TO NEXT SEQUENCE
STA X,POINT
JMP 30$
20$: LDA Y,SOUND+FRCNT-4 ;FRAME RATE
;THE -4 TO CORRECT FOR THE POINTER BEING ALREADY
;INCREMENTED TO POINT TO THE NEXT BLOCK.
STA X,FRAMES
LDA X,CURRENT
CLC
ADC Y,SOUND+CHANGE-4 ;STEP THRU SEQUENCE
STA X,CURRENT
30$: LDA X,CURRENT ;MORE THAN 1 PATH HERE SO LOAD CURRENT
STA X,POKEY ;OUTPUT
40$: DEX
BPL 10$
MODSEX: RTS
.PAGE
.END