home *** CD-ROM | disk | FTP | other *** search
/ 64'er 1993 October / 64er_Magazin_93-10_1993_Markt__Technik_de_Side_B.d64 / soundroutine.src (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  11KB  |  426 lines

  1. 100 rem****  musik-kurs   (teil 7)
  2. 101 rem****  5-voice-player
  3. 102 rem****
  4. 103 rem****  by a.& f.hugenroth
  5. 104 rem****
  6. 105 :
  7. 106 sys9*4096:.opt oo:s = 54272
  8. 107 :
  9. 108 initirq sei
  10. 109 lda #<newirq:sta $314
  11. 110 lda #>newirq:sta $315
  12. 111 lda #4:sta count
  13. 112 lda fstep:sta cstep
  14. 113 lda #0:sta cnote
  15. 114 ldy #31:iirq2 sta snsp1,y
  16. 115 sta snsp2,y:sta snsp3,y
  17. 116 dey:bpl iirq2
  18. 117 lda #<nmi1:sta $318
  19. 118 lda #>nmi1:sta $319
  20. 119 lda #$81:sta $dd0d:lda #1:sta $dd0e
  21. 120 lda #128:sta $dd04:sta $dd05
  22. 121 lda #$c8:sta $a6:sta $a9
  23. 122 lda #$c7:sta $a5:sta $a8
  24. 123 lda #$ff:sta $a4:sta $a7
  25. 124 lda #$44:sta $c800
  26. 125 cli
  27. 126 rts
  28. 127 :
  29. 128 nmi1 sta $9b:sty $9e:ldy #0:clc
  30. 129 lda ($a4),y:adc ($a7),y:sta $9f
  31. 130 and #15:ora $aa:sta $d418
  32. 131 lda $a6:cmp $a5:beq nmi1b
  33. 132 inc $a4:bne nmi1b:inc $a5
  34. 133 nmi1b lda #<nmi2:sta $318
  35. 134 lda $dd0d:ldy $9e:lda $9b:rti
  36. 135 nmi2 sta $9b:lda $9f
  37. 136 lsr:lsr:lsr:lsr:ora $aa:sta $d418
  38. 137 lda #<nmi1:sta $318
  39. 138 lda $a9:cmp $a8:beq nmi2b
  40. 139 inc $a7:bne nmi2b:inc $a8
  41. 140 nmi2b lda $dd0d:lda $9b:rti
  42. 141 :
  43. 142 newirq lda 1:pha:lda #54:sta 1
  44. 143 jsr play:jsr sound
  45. 144 pla:sta 1:jmp $ea31
  46. 145 :
  47. 146 play dec count:bmi play2:rts
  48. 147 play2 lda #4:sta count
  49. 148 ldx cstep
  50. 149 lda $a000,x:sta tkt1
  51. 150 lda $a100,x:sta tsp1
  52. 151 lda $a200,x:sta tkt2
  53. 152 lda $a300,x:sta tsp2
  54. 153 lda $a400,x:sta tkt3
  55. 154 lda $a500,x:sta tsp3
  56. 155 lda $a600,x:sta $b0
  57. 156 lda $a700,x:sta $b1
  58. 157 lda $a800,x:sta $b2
  59. 158 lda $a900,x:sta $b3
  60. 159 lda tkt1:and #3:tax
  61. 160 lda tktadrlo,x:sta $f7
  62. 161 lda tkt1:lsr:lsr:tax
  63. 162 lda tktadrhi,x:sta $f8
  64. 163 lda tkt2:and #3:tax
  65. 164 lda tktadrlo,x:sta $f9
  66. 165 lda tkt2:lsr:lsr:tax
  67. 166 lda tktadrhi,x:sta $fa
  68. 167 lda tkt3:and #3:tax
  69. 168 lda tktadrlo,x:sta $fb
  70. 169 lda tkt3:lsr:lsr:tax
  71. 170 lda tktadrhi,x:sta $fc
  72. 171 ldy cnote
  73. 172 lda ($f7),y:sta note1
  74. 173 lda ($f9),y:sta note2
  75. 174 lda ($fb),y:sta note3
  76. 175 lda ($b0),y:sta digi1
  77. 176 lda ($b2),y:sta digi2
  78. 177 tya:clc:adc #32:tay
  79. 178 lda ($f7),y:sta snd1
  80. 179 lda ($f9),y:sta snd2
  81. 180 lda ($fb),y:sta snd3
  82. 181 ldx #2
  83. 182 play3 lda note1,x:and #127
  84. 183 cmp #96:beq play5
  85. 184 cmp #95:beq play4
  86. 185 clc:adc tsp1,x:ldy snd1,x
  87. 186 bpl play11:sta glideto,x:lda #1
  88. 187 sta glideon,x:jmp play10
  89. 188 play11 sta aktnote1,x
  90. 189 play10 lda note1,x:bmi play0
  91. 190 lda #1:sta on1,x
  92. 191 play0 jsr resetfx
  93. 192 stx $f9:lda snd1,x:and #7:tax
  94. 193 lda sndadrl,x:sta $f7:lda snd1,x
  95. 194 and #127
  96. 195 lsr:lsr:lsr:tax:lda sndadrh,x
  97. 196 sta $f8:lda $f9:asl:asl:asl:asl:asl
  98. 197 tax:ldy #0
  99. 198 play6 lda ($f7),y:sta snsp1,x
  100. 199 inx:iny:cpy #32:bcc play6
  101. 200 ldx $f9:jsr fxinit
  102. 201 jmp play5
  103. 202 play4 lda #0:sta on1,x
  104. 203 play5 dex:bmi play9:jmp play3
  105. 204 play9 ldx digi1:beq play12
  106. 205 lda $ae00,x:sta $a4
  107. 206 lda $ae40,x:sta $a5
  108. 207 lda $ae80,x:sta $a6
  109. 208 lda $aec0,x:sta $dd04
  110. 209 lda $af00,x:sta $dd05
  111. 210 play12 ldx digi2:beq play13
  112. 211 lda $ae00,x:sta $a7
  113. 212 lda $ae40,x:sta $a8
  114. 213 lda $ae80,x:sta $a9
  115. 214 play13 lda cnote
  116. 215 lda cnote
  117. 216 clc:adc #1
  118. 217 cmp #32:bcc play7
  119. 218 inc cstep:lda cstep
  120. 219 cmp lstep:beq play8:bcc play8
  121. 220 lda fstep:sta cstep
  122. 221 play8 lda #0
  123. 222 play7 sta cnote
  124. 223 rts
  125. 224 :
  126. 225 resetfx lda #0:sta arpcount,x
  127. 226 sta viblo,x
  128. 227 sta vibhi,x:sta pulsri,x
  129. 228 sta portlo,x:sta porthi,x
  130. 229 sta glidlo,x:sta glidhi,x
  131. 230 rts
  132. 231 :
  133. 232 fxinit ldy #24
  134. 233 lda ($f7),y:sta arpspeed,x
  135. 234 ldy #9:lda ($f7),y:lsr:sta viblev,x
  136. 235 ldy #3:lda ($f7),y:sta pcount,x
  137. 236 dey:lda ($f7),y:pha:asl:asl:asl:asl
  138. 237 sta pulslo,x:pla:lsr:lsr:lsr:lsr
  139. 238 sta pulshi,x:ldy #16
  140. 239 lda ($f7),y:beq fxinit2:stx trigger
  141. 240 lda #0:sta fricht,x:iny:lda ($f7),y
  142. 241 sta ftime1,x:iny:lda ($f7),y
  143. 242 sta ftime2,x
  144. 243 fxinit2 rts
  145. 244 :
  146. 245 setsid lda snsp1+10:sta s+5
  147. 246 lda snsp1+11:sta s+6
  148. 247 lda snsp2+10:sta s+5+7
  149. 248 lda snsp2+11:sta s+6+7
  150. 249 lda snsp3+10:sta s+5+14
  151. 250 lda snsp3+11:sta s+6+14
  152. 251 ldy #0:clc
  153. 252 lda aktnote1:adc arpnote:sta $f7
  154. 253 lda aktnote2:adc arpnote+1:sta $f8
  155. 254 lda aktnote3:adc arpnote+2:sta $f9
  156. 255 ldx snsp1+29:beq ssid1a
  157. 256 dec snsp1+31:bpl ssid1b
  158. 257 sty snsp1+29:ssid1b lda snsp1+30
  159. 258 sta $f7:jmp ssid2
  160. 259 ssid1a ldx snsp1
  161. 260 lda on1:bne ssid2
  162. 261 ldx snsp1+1
  163. 262 ssid2 stx s+4
  164. 263 ldx snsp2+29:beq ssid2a
  165. 264 dec snsp2+31:bpl ssid2b
  166. 265 sty snsp2+29:ssid2b lda snsp2+30
  167. 266 sta $f8:jmp ssid3
  168. 267 ssid2a ldx snsp2
  169. 268 lda on2:bne ssid3
  170. 269 ldx snsp2+1
  171. 270 ssid3 stx s+4+7
  172. 271 ldx snsp3+29:beq ssid3a
  173. 272 dec snsp3+31:bpl ssid3b
  174. 273 sty snsp3+29:ssid3b lda snsp3+30
  175. 274 sta $f9:jmp ssid4
  176. 275 ssid3a ldx snsp3
  177. 276 lda on3:bne ssid4
  178. 277 ldx snsp3+1
  179. 278 ssid4 stx s+4+14
  180. 279 ldx $f7:clc
  181. 280 lda notelo,x:adc tlo+0:sta s
  182. 281 lda notehi,x:adc thi+0:sta s+1
  183. 282 ldx $f8:clc
  184. 283 lda notelo,x:adc tlo+1:sta s+7
  185. 284 lda notehi,x:adc thi+1:sta s+1+7
  186. 285 ldx $f9:clc
  187. 286 lda notelo,x:adc tlo+2:sta s+14
  188. 287 lda notehi,x:adc thi+2:sta s+1+14
  189. 288 lda pulslo+0:sta s+2
  190. 289 lda pulshi+0:sta s+3
  191. 290 lda pulslo+1:sta s+2+7
  192. 291 lda pulshi+1:sta s+3+7
  193. 292 lda pulslo+2:sta s+2+14
  194. 293 lda pulshi+2:sta s+3+14
  195. 294 lda trigger:asl:asl:asl:asl:asl
  196. 295 clc:adc #<snsp1:sta $f7
  197. 296 lda #>snsp1:adc #0:sta $f8
  198. 297 ldy #22:lda ($f7),y
  199. 298 asl:asl:asl:asl:sta $f9:ldy #16
  200. 299 lda ($f7),y:beq ssidend:and #15
  201. 300 ora $f9:sta s+23:lda ($f7),y
  202. 301 and #240:sta $aa:lda #0:sta s+21
  203. 302 ldy #23:lda ($f7),y:sta s+22
  204. 303 ssidend lda timerl:sta $dc04
  205. 304 lda timerh:sta $dc05:rts
  206. 305 :
  207. 306 sound ldx #0:lda #<snsp1
  208. 307 sta $f7:lda #>snsp1:sta $f8
  209. 308 ;**
  210. 309 ;** arpeggio
  211. 310 ;**
  212. 311 sound1 lda #25:clc
  213. 312 adc arpcount,x:tay:lda ($f7),y
  214. 313 sta arpnote,x
  215. 314 dec arpspeed,x:bpl sound2
  216. 315 ldy #24:lda ($f7),y:sta arpspeed,x
  217. 316 lda arpcount,x:clc:adc #1
  218. 317 and #3:sta arpcount,x
  219. 318 ;**
  220. 319 ;** vibrato
  221. 320 ;**
  222. 321 sound2 ldy #7:lda ($f7),y
  223. 322 beq sound2b:sec:sbc #1:sta ($f7),y
  224. 323 jmp sound3
  225. 324 sound2b dec viblev,x:bpl sound2c
  226. 325 ldy #8:lda ($f7),y:eor #255
  227. 326 sta ($f7),y:iny:lda ($f7),y
  228. 327 sta viblev,x:sound2c ldy #8
  229. 328 lda ($f7),y:bmi sound2d:clc
  230. 329 adc viblo,x:sta viblo,x:lda vibhi,x
  231. 330 adc #0:sta vibhi,x:jmp sound3
  232. 331 sound2d eor #255:sta $f9:sec
  233. 332 lda viblo,x:sbc $f9:sta viblo,x
  234. 333 lda vibhi,x:sbc #0:sta vibhi,x
  235. 334 ;**
  236. 335 ;** pulse
  237. 336 ;**
  238. 337 sound3 ldy #5:lda ($f7),y:sta $f9
  239. 338 lda pulsri,x:bmi sound3a
  240. 339 lda pulslo,x:clc:adc $f9
  241. 340 sta pulslo,x:lda pulshi,x:adc #0
  242. 341 sta pulshi,x
  243. 342 dec pcount,x:bpl sound4
  244. 343 ldy #4:lda ($f7),y:sta pcount,x
  245. 344 lda #128:sta pulsri,x:jmp sound4
  246. 345 sound3a lda pulslo,x:sec:sbc $f9
  247. 346 sta pulslo,x:lda pulshi,x:sbc #0
  248. 347 sta pulshi,x:dec pcount,x
  249. 348 bpl sound4:ldy #3:lda ($f7),y
  250. 349 sta pcount,x:lda #0:sta pulsri,x
  251. 350 ldy #6:lda ($f7),y:and #16
  252. 351 bne sound4:dey:lda #0:sta ($f7),y
  253. 352 ;**
  254. 353 ;** portamento
  255. 354 ;**
  256. 355 sound4 ldy #6:lda ($f7),y:and #15
  257. 356 beq sound5:and #3:cmp #1
  258. 357 beq sound4a:ldy #12:lda portlo,x
  259. 358 clc:adc ($f7),y:sta portlo,x
  260. 359 iny:lda porthi,x:adc ($f7),y
  261. 360 sta porthi,x:iny:cmp ($f7),y
  262. 361 bcc sound5:jmp sound4b
  263. 362 sound4a ldy #12:lda portlo,x:sec
  264. 363 sbc ($f7),y:sta portlo,x
  265. 364 iny:lda porthi,x:sbc ($f7),y
  266. 365 sta porthi,x:iny:cmp ($f7),y
  267. 366 bcs sound5:sound4b ldy #6
  268. 367 lda ($f7),y:and #4:beq sound4c
  269. 368 lda #0:sta portlo,x:sta porthi,x
  270. 369 jmp sound5:sound4c lda ($f7),y
  271. 370 and #240:sta ($f7),y
  272. 371 ;**
  273. 372 ;** filter
  274. 373 ;**
  275. 374 sound5 cpx trigger:bne sound6
  276. 375 lda fricht,x:bmi sound5a
  277. 376 dec ftime1,x:bpl sound5b:lda #255
  278. 377 sta fricht,x:sta ftime1,x
  279. 378 jmp sound6:sound5b ldy #19
  280. 379 lda ($f7),y:ldy #23:clc:adc ($f7),y
  281. 380 sta ($f7),y:jmp sound6
  282. 381 sound5a dec ftime2,x
  283. 382 bpl sound5d:lda #0:sta fricht,x
  284. 383 lda #255:sta ftime2,x
  285. 384 ldy #21:lda ($f7),y:beq sound6
  286. 385 ldy #17:lda ($f7),y:sta ftime1,x
  287. 386 iny:lda ($f7),y:sta ftime2,x
  288. 387 jmp sound6:sound5d ldy #20
  289. 388 lda ($f7),y:ldy #23:clc:adc ($f7),y
  290. 389 sta ($f7),y
  291. 390 ;**
  292. 391 ;** glide
  293. 392 ;**
  294. 393 sound6 lda glideon,x:bne sound6d
  295. 394 jmp sound7:sound6d ldy aktnote1,x
  296. 395 lda notelo,y:clc
  297. 396 adc tlo,x:sta $f9:lda notehi,y
  298. 397 adc thi,x:sta $fa
  299. 398 lda glideto,x:cmp aktnote1,x
  300. 399 bcc sound6a:ldy #12:lda glidlo,x
  301. 400 clc:adc ($f7),y:sta glidlo,x:iny
  302. 401 lda glidhi,x:adc ($f7),y
  303. 402 sta glidhi,x:ldy glideto,x
  304. 403 lda $fa:cmp notehi,y
  305. 404 bcc sound7:bne sound6b
  306. 405 lda $f9:cmp notelo,y:bcc sound7
  307. 406 jmp sound6b
  308. 407 sound6a ldy #12:lda glidlo,x
  309. 408 sec:sbc ($f7),y:sta glidlo,x:iny
  310. 409 lda glidhi,x:sbc ($f7),y
  311. 410 sta glidhi,x:ldy glideto,x
  312. 411 lda notehi,y:cmp $fa:bcc sound7
  313. 412 bne sound6b:lda notelo,y
  314. 413 cmp $f9:bcc sound7
  315. 414 sound6b lda #0:sta glideon,x
  316. 415 sta glidlo,x:sta glidhi,x
  317. 416 lda glideto,x:sta aktnote1,x
  318. 417 ;**
  319. 418 ;** soundende
  320. 419 ;**
  321. 420 sound7 lda viblo,x:clc
  322. 421 adc portlo,x:sta tlo,x:lda tlo,x
  323. 422 clc:adc glidlo,x:sta tlo,x
  324. 423 lda vibhi,x:adc porthi,x:sta thi,x
  325. 424 lda thi,x:clc:adc glidhi,x
  326. 425 sta thi,x:lda tlo,x:clc:ldy #15
  327. 426 adc ($f7),y:sta tlo,x
  328. 427 lda thi,x:adc #0:sta thi,x
  329. 428 lda $f7:clc:adc #32:sta $f7
  330. 429 lda $f8:adc #0:sta $f8
  331. 430 inx:cpx #3:bcs sounde:jmp sound1
  332. 431 sounde jmp setsid
  333. 432 :
  334. 433 :
  335. 434 :
  336. 435 tktadrlo .byt $00,$40,$80,$c0
  337. 436 tktadrhi .byt $b0,$b1,$b2,$b3
  338. 437 :        .byt $b4,$b5,$b6,$b7
  339. 438 :        .byt $b8,$b9,$ba,$bb
  340. 439 :        .byt $bc,$bd,$be,$bf
  341. 440 note1 .byt 0
  342. 441 note2 .byt 0
  343. 442 note3 .byt 0
  344. 443 tkt1 .byt 0
  345. 444 tkt2 .byt 0
  346. 445 tkt3 .byt 0
  347. 446 tsp1 .byt 0
  348. 447 tsp2 .byt 0
  349. 448 tsp3 .byt 0
  350. 449 snd1 .byt 0
  351. 450 snd2 .byt 0
  352. 451 snd3 .byt 0
  353. 452 on1 .byt 0
  354. 453 on2 .byt 0
  355. 454 on3 .byt 0
  356. 455 tlo .byt 0,0,0
  357. 456 thi .byt 0,0,0
  358. 457 pulsri .byt 0,0,0
  359. 458 pcount .byt 0,0,0
  360. 459 pulslo .byt 0,0,0
  361. 460 pulshi .byt 0,0,0
  362. 461 arpcount .byt 0,0,0
  363. 462 arpnote .byt 0,0,0
  364. 463 arpspeed .byt 0,0,0
  365. 464 viblev .byt 0,0,0
  366. 465 viblo .byt 0,0,0
  367. 466 vibhi .byt 0,0,0
  368. 467 portlo .byt 0,0,0
  369. 468 porthi .byt 0,0,0
  370. 469 fricht .byt 0,0,0
  371. 470 ftime1 .byt 0,0,0
  372. 471 ftime2 .byt 0,0,0
  373. 472 glideon .byt 0,0,0
  374. 473 glideto .byt 0,0,0
  375. 474 glidlo .byt 0,0,0
  376. 475 glidhi .byt 0,0,0
  377. 476 trigger .byt 0
  378. 477 cnote .byt 0
  379. 478 cstep .byt 0
  380. 479 fstep .byt 0
  381. 480 lstep .byt 3
  382. 481 count .byt 0
  383. 482 speed .byt 0
  384. 483 timerl .byt 0
  385. 484 timerh .byt $39
  386. 485 digi1 .byt 0
  387. 486 digi2 .byt 0
  388. 487 snsp1 .asc "********************************"
  389. 488 snsp2 .asc "********************************"
  390. 489 snsp3 .asc "********************************"
  391. 490 aktnote1 .byt 0
  392. 491 aktnote2 .byt 0
  393. 492 aktnote3 .byt 0
  394. 493 notelo .byt 22,39,57,75,95,116,138
  395. 494 :      .byt 161,186,212,240,14,45
  396. 495 :      .byt 78,113,150,190,231,20
  397. 496 :      .byt 66,116,169,224,27,90
  398. 497 :      .byt 156,226,45,123,207,39
  399. 498 :      .byt 133,232,81,193,55,180
  400. 499 :      .byt 56,196,89,247,158,78
  401. 500 :      .byt 10,208,162,129,109,103
  402. 501 :      .byt 112,137,178,237,59,157
  403. 502 :      .byt 20,160,69,3,219,207
  404. 503 :      .byt 225,18,101,219,118,58
  405. 504 :      .byt 39,65,138,5,181,157
  406. 505 :      .byt 193,36,201,182,237,115
  407. 506 :      .byt 78,130,20,10,106,59
  408. 507 :      .byt 130,72,147,107,218,231
  409. 508 :      .byt 156,4,40,20
  410. 509 notehi .byt 1,1,1,1,1,1,1,1,1,1,1
  411. 510 :      .byt 2,2,2,2,2,2,2,3,3,3,3
  412. 511 :      .byt 3,4,4,4,4,5,5,5,6,6,6
  413. 512 :      .byt 7,7,8,8,9,9,10,10,11
  414. 513 :      .byt 12,13,13,14,15,16,17
  415. 514 :      .byt 18,19,20,21,23,24,26
  416. 515 :      .byt 27,29,31,32,34,36,39
  417. 516 :      .byt 41,43,46,49,52,55,58
  418. 517 :      .byt 62,65,69,73,78,82,87
  419. 518 :      .byt 92,98,104,110,117,124
  420. 519 :      .byt 131,139,147,156,165
  421. 520 :      .byt 175,185,196,208,221
  422. 521 :      .byt 234,248
  423. 522 sndadrl .byt $00,$20,$40,$60
  424. 523 :       .byt $80,$a0,$c0,$e0
  425. 524 sndadrh .byt $aa,$ab,$ac,$ad
  426.