/[projet1]/users/twilighte/Stormlord/Wave_Player.s
Defence Force logotype

Contents of /users/twilighte/Stormlord/Wave_Player.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 412 - (show annotations)
Thu Oct 7 20:50:23 2010 UTC (8 years, 9 months ago) by dbug
File size: 10569 byte(s)
Added Stormlord
1 ;Wave_Player.s - Play Compiled tune
2 #define VIA_PORTB $0300
3 #define VIA_PCR $030C
4 #define VIA_PORTA $030F
5
6 #define SYS_IRQPATCH $24A
7
8 #define MUSICTRIGGERLOC $BFE0
9
10
11
12 ;+00 Wave Version ID(00)
13 ;+01 Music Tempo
14 ;+02-03 Offset to Pattern Address Table
15 ;+04-05 Offset to Effect Address Table
16 ;+06-07 Offset to Ornament Address Table
17 ;+08-09 Offset to Sample Address Table
18 ;+0A List Loop Position, List
19 ;+?? Pattern Address Table (lo,hi,lo)
20 ;+?? Patterns
21 ; 000-005 Sample(6)
22 ; 006-068 EGPeriod(63)
23 ; 069-071 Cycle(3)
24 ; 072-102 Noise(31)
25 ; 103-164 Note(62)
26 ; 165-165 Rest(1)
27 ; 166-166 Bar(1)
28 ; 167-170 Volume(4)
29 ; 171-185 Effect(15)
30 ; 186-200 Ornament(15)
31 ; 201-207 Command(7)
32 ; 208-239 Parameter(31)
33 ; 240-240 Long Row Rest(Second byte holds period)
34 ; 241-255 Short Row Rest(15)
35 ;If a row contains at least 1 change then all three channel rests are written
36 ;+?? Effect Address Table (lo,hi,lo)
37 ;+?? Loop Position, Effect,
38 ;
39 ;+?? Ornament Address Table (lo,hi,lo)
40 ;+?? Loop Position, Ornaments,
41 ;+?? Sample Address Table (lo,hi,llo,lhi,pro)
42 ;+?? Samples
43 ;PageAlligning
44 ; .dsb 256-(*&255)
45 ;Ensure this is kept page alligned
46
47 InitMusic lda #<Stormlord_Music
48 sta header
49 lda #>Stormlord_Music
50 sta header+1
51 lda #11
52 sta ListIndex
53
54 ;Set up pat
55 ldy #2
56 lda (header),y
57 clc
58 adc header
59 sta pat
60 iny
61 lda (header),y
62 adc header+1
63 sta pat+1
64
65 ;Set up eat
66 ldy #4
67 lda (header),y
68 clc
69 adc header
70 sta eat
71 iny
72 lda (header),y
73 adc header+1
74 sta eat+1
75
76 ;Set up oat
77 ldy #6
78 lda (header),y
79 clc
80 adc header
81 sta oat
82 iny
83 lda (header),y
84 adc header+1
85 sta oat+1
86
87 jsr ProcList
88
89 lda #%11000000
90 sta MusicActivity
91
92 ;Set up Music Tempo as 1 so that first irq call pattern
93 lda #01
94 sta MusicTempoCount
95
96 lda #8
97 sta ayw_Volume+2
98
99 cli
100 rts
101
102 MusicIRQ
103 jsr ProcMusic
104
105 SendAY ;Control Option_Sound
106 ldx #13
107 .(
108 loop1 lda ayw_Bank,x
109
110 ldy ayVolumeFlag,x
111 beq skip2
112 ldy Option_Sound
113 beq skip2
114 dey
115 bne skip3
116 and #15
117 sbc #6
118 bcs skip2
119 skip3 lda #00
120 skip2 cmp ayr_Bank,x
121 beq skip1
122 sta ayr_Bank,x
123 ldy ayRealRegister,x
124 sty VIA_PORTA
125 ldy #$FF
126 sty VIA_PCR
127 ldy #$DD
128 sty VIA_PCR
129 sta VIA_PORTA
130 lda #$FD
131 sta VIA_PCR
132 sty VIA_PCR
133 skip1 dex
134 bpl loop1
135 .)
136 rts
137
138 ayVolumeFlag
139 .byt 0,0,0,0,0,0,0,0,1,1,1,0,0,0
140
141
142 ProcMusic
143 dec MusicTempoCount
144 bne ProcSound
145 lda #12 ;MusicTempoRef
146 sta MusicTempoCount
147
148 jsr ProcPattern
149
150 ProcSound
151 ldx #2
152 .(
153 loop1 lda MusicActivity
154 and NoiseBit,x ;B3 B4 B5
155 cmp #1
156 lda PatternNote,x
157 bcc skip1
158
159 ;ProcOrnament
160 ldy OrnamentID,x
161 lda header
162 clc
163 adc (oat),y
164 sta ornament
165 lda header+1
166 iny
167 adc (oat),y
168 sta ornament+1
169 loop2 ldy OrnamentIndex,x
170 lda (ornament),y
171 bne skip2
172 ldy #00
173 lda (ornament),y
174 bmi skip6
175 sta OrnamentIndex,x
176 jmp loop2
177 skip6 lda MusicActivity
178 and NoiseMask,x
179 sta MusicActivity
180 lda #00
181 skip2 clc
182 adc PatternNote,x
183 and #127
184 inc OrnamentIndex,x
185
186 ;Convert to Pitch
187 skip1 tay
188 lda PitchTableLo,y
189 sta IntermediatePitchLo
190 lda PitchTableHi,y
191 sta IntermediatePitchHi
192
193 ;Check Effect
194 lda MusicActivity
195 and EffectBit,x
196 beq skip3
197
198 ;Process Effect
199 ldy EffectID,x
200 lda header
201 clc
202 adc (eat),y
203 sta effect
204 lda header+1
205 iny
206 adc (eat),y
207 sta effect+1
208 ldy EffectIndex,x
209 loop3 lda (effect),y
210 and #%11100000
211 lsr
212 sta vector1+1
213 lda (effect),y
214 iny
215 and #31
216 adc #255-15
217 sec
218 vector1 jsr pmeLoopOrEnd
219 bcs loop3
220 tya
221 sta EffectIndex,x
222
223 skip3 ;Transfer Intermediate Pitch to AY Registers
224 lda IntermediatePitchLo
225 sta ayw_PitchLo,x
226 lda IntermediatePitchHi
227 sta ayw_PitchHi,x
228
229 ;Progress to next Effect/Ornament
230 dex
231 bmi skip4
232 jmp loop1
233 skip4 rts
234 .)
235
236
237
238 ProcPattern
239 lda PatternRestCount
240 .(
241 beq skip4
242 dec PatternRestCount
243 jmp skip3
244
245 skip4 lda #00
246 sta BarFlag
247 sta ChannelID
248 ;We don't want any new note to adopt the previous effect/ornament if not specified
249 sta NewActivity
250 ; ;Reset Music Activity for ornaments and Effects
251 ; lda MusicActivity
252 ; and #%11000000
253 ; sta MusicActivity
254 ldy #00
255 lda (pattern),y
256 cmp #166
257 bne loop1
258 jsr ProcList
259 loop1 ldy #00
260 lda (pattern),y
261 inc pattern
262 bne skip2
263 inc pattern+1
264 skip2 ldx #12
265 loop2 cmp PatternRangeThreshhold-1,x
266 bcs skip1
267 dex
268 bne loop2
269 sec
270 skip1 sbc PatternRangeThreshhold-1,x
271 ldy PatternRangeCommandLo,x
272 sty vector1+1
273 ldy PatternRangeCommandHi,x
274 sty vector1+2
275 clc
276 vector1 jsr $dead
277 bcc loop1
278
279 skip3 dec PatternRow
280 .)
281 bne AvoidList
282
283 ProcList ;Get next List PatternID
284 ldy ListIndex ;Offset by $0B
285 cpy #36
286 .(
287 bcc skip1
288 ldy #11
289 sty ListIndex
290 skip1
291 .)
292 ProcList2 ldy ListIndex
293 lda (header),y
294
295 ;Calculate address of Pattern
296 asl
297 tay
298 lda header
299 adc (pat),y
300 sta pattern
301 lda header+1
302 iny
303 adc (pat),y
304 sta pattern+1
305
306 ;Progress List Index
307 inc ListIndex
308
309 ;Reset Pattern Stuff
310 lda #64
311 sta PatternRow
312 lda #00
313 sta PatternRestCount
314
315 AvoidList rts
316
317 PatternRangeThreshhold
318 ;The above loop searches and exits on 0 defaulting to Sample so we can save
319 ;a massive one byte here!
320 ; .byt 0 ;00 prcSample
321 .byt 6 ;06 01 prcEGPeriod
322 .byt 69 ;45 02 prcCycle
323 .byt 72 ;48 03 prcNoise
324 .byt 103 ;67 04 prcNote
325 .byt 165 ;A5 05 prcRest
326 .byt 166 ;A6 06 prcBar
327 .byt 167 ;A7 07 prcVolume
328 .byt 171 ;AB 08 prcEffect
329 .byt 186 ;BA 09 prcOrnament
330 .byt 201 ;C9 10 prcCommand
331 .byt 208 ;D0 11 prcLongRowRest
332 .byt 209 ;D1 12 prcShortRowRest
333
334 PatternRangeCommandLo
335 .byt <prcSample
336 .byt <prcEGPeriod
337 .byt <prcCycle
338 .byt <prcNoise
339 .byt <prcNote
340 .byt <prcRest
341 .byt <prcBar
342 .byt <prcVolume
343 .byt <prcEffect
344 .byt <prcOrnament
345 .byt <prcCommand
346 .byt <prcLongRowRest ;(Second byte holds period)
347 .byt <prcShortRowRest
348
349
350
351 prcCycle tax
352 lda CycleCode,x
353 sta ayw_Cycle
354 lda #128
355 sta ayr_Cycle
356 rts
357
358
359 prcNote ldx ChannelID
360 adc #11
361 sta PatternNote,x
362 ;If Note specified always default to Noise Off, Tone On
363 lda ayw_Status
364 and ToneMask,x
365 ora NoiseBit,x
366 sta ayw_Status
367 inc ChannelID
368 lda ChannelID
369 cmp #3 ;If end of Row then indicate with Carry
370 ;If effect/Ornament not set and note then reset in musicactivity
371 lda NewActivity
372 and EffectBit,x
373 beq NoteDisableEffect
374 lda NewActivity
375 and OrnamentBit,x
376 beq NoteDisableOrnament
377 rts
378
379 prcRest ldx ChannelID
380 inx
381 stx ChannelID
382 cpx #3
383 rts
384
385 NoteDisableEffect
386 lda MusicActivity
387 and ToneMask,x
388 sta MusicActivity
389 ;If no effect (And EG not set) ensure Pattern Volume gets into AY
390 lda EGActiveFlag,x
391 .(
392 bne skip1
393 lda PatternVolume,x
394 sta ayw_Volume,x
395 skip1 rts
396 .)
397
398 NoteDisableOrnament
399 lda MusicActivity
400 and NoiseMask,x
401 sta MusicActivity
402 rts
403
404
405 prcVolume
406 tax
407 lda RealVolume,x
408 ldx ChannelID
409 sta PatternVolume,x
410 rts
411
412 prcEffect
413 ldx ChannelID
414 ;Shift left so it can directly index eat
415 asl
416 sta EffectID,x
417 lda #01
418 sta EffectIndex,x
419 lda NewActivity
420 ora ToneBit,x
421 sta NewActivity
422 lda MusicActivity
423 ora ToneBit,x
424 sta MusicActivity
425 rts
426
427 prcOrnament
428 ldx ChannelID
429 ;Shift left so it can directly index oat
430 asl
431 sta OrnamentID,x
432 lda #01
433 sta OrnamentIndex,x
434 lda NewActivity
435 ora NoiseBit,x
436 sta NewActivity
437 lda MusicActivity
438 ora NoiseBit,x
439 sta MusicActivity
440 rts
441
442 prcCommand
443 tax
444 ldy #00
445 lda (pattern),y
446 inc pattern
447 .(
448 bne skip1
449 inc pattern+1
450 skip1 ldy CommandVectorLo,x
451 .)
452 sty vector1+1
453 ldy CommandVectorHi,x
454 sty vector1+2
455 vector1 jmp $DEAD
456
457
458 prcLongRowRest ;(Second byte holds period)
459 ldy #00
460 lda (pattern),y
461 inc pattern
462 bne prcShortRowRest
463 inc pattern+1
464 prcShortRowRest
465 sta PatternRestCount
466 sec
467 rts
468
469 CommandVectorLo
470 .byt <prcCom_Tempo
471 .byt <prcCom_TriggerOut
472 .byt <prcCom_Pitchbend
473 .byt <prcCom_SlideUp
474 .byt <prcCom_SlideDown
475 .byt <prcCom_SampleType
476 .byt <prcCom_CopyLeftSibling
477
478 CommandVectorHi
479 .byt >prcCom_Tempo
480 .byt >prcCom_TriggerOut
481 .byt >prcCom_Pitchbend
482 .byt >prcCom_SlideUp
483 .byt >prcCom_SlideDown
484 .byt >prcCom_SampleType
485 .byt >prcCom_CopyLeftSibling
486
487
488
489 prcCom_TriggerOut
490 sta MUSICTRIGGERLOC
491 rts
492
493 ayw_Bank
494 ayw_PitchLo .byt 0,0,0
495 ayw_PitchHi .byt 0,0,0
496 ayw_Noise .byt 0
497 ayw_Status .byt %01111000
498 ayw_Volume .byt 0,0,0
499 ayw_EGPeriod .byt 0,0
500 ayw_Cycle .byt 0
501
502 BarFlag .byt 0
503 Temp01 .byt 0
504
505 ;Page alligned stuff was here but its been moved to start of driver.s
506 CycleCode
507 .byt 8,10,0
508 OrnamentMask
509 NoiseMask
510 .byt %11110111
511 .byt %11101111
512 .byt %11011111
513 OrnamentID
514 .dsb 3,0
515 OrnamentIndex
516 .dsb 3,0
517 RealVolume
518 .byt 0,4,8,15
519 EGActiveFlag
520 .byt 0,0,0
521 IntermediatePitchLo .byt 0
522 IntermediatePitchHi .byt 0
523 ;The following Commands are not supported
524 prcSample
525 prcCom_Pitchbend
526 prcCom_SlideUp
527 prcCom_SlideDown
528 prcCom_SampleType
529 prcCom_CopyLeftSibling
530 rts
531 PatternRangeCommandHi
532 .byt >prcSample
533 .byt >prcEGPeriod
534 .byt >prcCycle
535 .byt >prcNoise
536 .byt >prcNote
537 .byt >prcRest
538 .byt >prcBar
539 .byt >prcVolume
540 .byt >prcEffect
541 .byt >prcOrnament
542 .byt >prcCommand
543 .byt >prcLongRowRest ;(Second byte holds period)
544 .byt >prcShortRowRest
545
546 PitchTableLo
547 .byt <3822,<3606,<3404,<3214,<3032,<2862,<2702,<2550,<2406,<2272,<2144,<2024
548 .byt <1911,<1803,<1702,<1607,<1516,<1431,<1351,<1275,<1203,<1136,<1072,<1012
549 .byt <955,<901,<851,<803,<758,<715,<675,<637,<601,<568,<536,<506
550 .byt <477,<450,<425,<401,<379,<357,<337,<318,<300,<284,<268,<253
551 .byt <238,<225,<212,<200,<189,<178,<168,<159,<150,<142,<134,<126
552 .byt <119,<112,<106,<100,<94,<89,<84,<79,<75,<71,<67,<63
553 .byt <59,<56,<53,<50,<47,<44,<42,<39,<37,<35,<33,<31
554 .byt <29,<28,<26,<25,<23,<22,<21,<19,<18,<17,<16,<15
555 .byt <14,<14,<13,<12,<11,<11,<10,<9,<9,<8,<8,<7
556 .byt 7,7,6,6,5,5,5,4,4,4,4,3
557 .byt 3,3,3,3,2,2,2,2
558 PitchTableHi
559 .byt >3822,>3606,>3404,>3214,>3032,>2862,>2702,>2550,>2406,>2272,>2144,>2024
560 .byt >1911,>1803,>1702,>1607,>1516,>1431,>1351,>1275,>1203,>1136,>1072,>1012
561 .byt >955,>901,>851,>803,>758,>715,>675,>637,>601,>568,>536,>506
562 .byt >477,>450,>425,>401,>379,>357,>337,>318,>300,>284,>268,>253
563 .byt >238,>225,>212,>200,>189,>178,>168,>159,>150,>142,>134,>126
564 .byt >119,>112,>106,>100,>94,>89,>84,>79,>75,>71,>67,>63
565 .byt >59,>56,>53,>50,>47,>44,>42,>39,>37,>35,>33,>31
566 .byt >29,>28,>26,>25,>23,>22,>21,>19,>18,>17,>16,>15
567 .byt >14,>14,>13,>12,>11,>11,>10,>9,>9,>8,>8,>7
568 .byt 0,0,0,0,0,0,0,0,0,0,0,0
569 .byt 0,0,0,0,0,0,0,0
570 EndOfPlayer
571 .byt 0
572
573
574

  ViewVC Help
Powered by ViewVC 1.1.26