SOUND.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. *******************************************************************************
  2. *
  3. * SOUND.S by Kevin G. Osborn
  4. * Contains subroutines
  5. * TUNER
  6. * SCRAPALL
  7. * SCRAPONE
  8. * TUNIN
  9. *******************************************************************************
  10. ********************************************************************************
  11. * SIMPSONG VERSION 0.03
  12. *
  13. * THIS SIMPLE SOUND DRIVER HAS, IN SOME WAYS, FEWER FEATURES BUT USES LESS RAM
  14. * AND ROM AND DOES NOT BACK UP SOUNDS FOR LATER (SOMETIMES MUCH LATER)
  15. * CONTINUATION. IT FEATURES 256 NOTE TUNES, SINGLE DURATION PER TUNE, ENDLESS
  16. * TUNES. IF A VALUE IN THE CONTROL OR VOLUME TABLES HAS THE HIGH BIT SET, THAT
  17. * VOLUME OR CONTROL WILL REMAIN IN EFFECT TILL THE END OF THE TUNE.
  18. * AN FF IN THE FREQUENCY TABLE WILL TERMINATE THE TUNE, AN FE WILL CAUSE IT TO
  19. * RESTART. AN FD WILL CALL THE TUNE NUMBER FOLLOWING (IN THE FREQ TABLE).
  20. *
  21. * SUBROUTINES:
  22. * SCRAPALL -- KILL ALL TUNES. SHOULD BE CALLED AT POWERUP, CHANGING PLAYERS,
  23. * AND GAME OVER
  24. *
  25. * SCRAPONE -- KILL A PARTICULAR TUNE. PUT THE NUMBER OF THE TUNE YA WANNA
  26. * AXE IN THE ACCUMULATOR.
  27. *
  28. * TUNIN -- START THAT TUNE YOU PUT IN ACC.
  29. *
  30. * THE ABOVE ROUTINES PRESERVE THE X AND Y REGS
  31. *
  32. * TABLES NEEDED ARE:
  33. * RAM:
  34. *DCH0 DS 1 ONE BYTE--DURATION CNTR CHAN. 0
  35. *DCH1 DS 1 ONE BYTE--DURATION CNTR CHAN. 1
  36. *TUNNUM DS 1 ONE BYTE--TUNE NUM FOR CHAN. 0
  37. *TUNNUM1 DS 1 ONE BYTE--TUNE NUM FOR CHAN. 1
  38. *TINDEX0 DS 1 ONE BYTE--NOTE POINTER 0
  39. *TINDEX1 DS 1 ONE BYTE--NOTE POINTER 1
  40. *CINDEX0 DS 1 CONTROL INDEX
  41. *CINDEX1 DS 1
  42. *VINDEX0 DS 1 VOLUME INDEX
  43. *VINDEX1 DS 1
  44. *MPTRL EQU KTEMP0 ZERO PAGE TEMP(NOT GAMEPLAY)
  45. *MPTRH EQU KTEMP1 ZERO PAGE TEMP(NOT GAMEPLAY)
  46. *TUNTEMP EQU TEMP0 ANY GAMEPLAY TEMP
  47. * ROM:
  48. * DURTABL ONE DURATION IN FRAMES PER TUNE
  49. * TBASE LOW ADDRESS OF THE START OF FREQ DATA BY TUNE NUMBER
  50. * TBASEH DITTO FOR HIGH ADDRESS
  51. * VBASE LOW ADDRESS OF THE START OF VOL DATA BY TUNE NUMBER
  52. * VBASEH DITTO FOR HIGH ADDRESS
  53. * CBASE LOW ADDRESS OF THE START OF CTRL DATA BY TUNE NUMBER
  54. * CBASEH DITTO FOR HIGH ADDRESS
  55. * PRYOR PRIORITY BY TUNE NUMBERS -- ZERO THE LOWEST
  56. * VOLTABL VOLUMES
  57. * FREQTABL FREQUENCIES
  58. * CTLTABL CONTROLS
  59. GLBL DURTABL,TBASE,TBASEH,VBASE,VBASEH,CBASE,CBASEH
  60. GLBL VOLTABL,FREQTABL
  61. GLBL DCH0,DCH1,TUNNUM,TUNNUM1,TINDEX0,TINDEX1,CINDEX0
  62. GLBL VINDEX0,VINDEX1,MPTRL,MPTRH,TUNTEMP
  63. GLBL STATATTR
  64. GLBL IRTNDONE
  65. GLBL TUNEDONE
  66. GLBL SCRAPALL,SCRAPONE,TUNIN,TUNER
  67. GLBL MATTRACT
  68. GLBL MPAUSE,MBLANK
  69. GLBL TRUE,FALSE
  70. ; globals in Tables.s
  71. GLBL CTRLTABL,PRYOR,ZTUNE0F
  72. GLBL ZTUNE1F,ZTUNE2F,ZTUNE1V,ZTUNE2V,ZTUNE0V
  73. GLBL ZTUNE3F,ZTUNE3V,ZTUNE4F,ZTUNE4V,ZTUNE5F,ZTUNE5V
  74. GLBL ZTUNE6F,ZTUNE6V,ZTUNE7F,ZTUNE7V,ZTUNE8F,ZTUNE8V
  75. GLBL ZTUNE9F,ZTUNE9V,ATUNE10F,ZTUNE10V,ATUNE11F,ZTUNE11V
  76. GLBL ATUNE12F,ZTUNE12V,ATUNE13F,ZTUNE13V,ZTUNE14F,ZTUNE14V
  77. GLBL ZTUNE15F,ZTUNE15V,ZTUNE16F,ZTUNE16V,ZTUNE17F,ZTUNE17V
  78. GLBL ZTUNE18F,ZTUNE18V,ZTUNE19F,ZTUNE19V,ZTUNE20F,ZTUNE20V
  79. GLBL ZTUNE21F,ZTUNE21V,ZTUNE22F,ZTUNE22V,ZTUNE23F,ZTUNE23V
  80. GLBL ZTUNE24F,ZTUNE24V,ZTUNE25F,ZTUNE25V,ZTUNE26F,ZTUNE26V
  81. GLBL ZTUNE27F,ZTUNE27V,ZTUNE28F,ZTUNE28V,ZTUNE29F,ZTUNE29V
  82. GLBL ZTUNE30F,ZTUNE30V,ZTUNE31F,ZTUNE31V,ZTUNE32F,ZTUNE32V
  83. RAMDEF ; ZERO PAGE
  84. RSEG CODE1
  85. ********************************************************************************
  86. * SCRAPALL
  87. * KILL ALL TUNES. SHOULD BE CALLED AT POWERUP, CHANGING PLAYERS,
  88. * AND GAME OVER
  89. * ALSO BEFORE INITIATING A TUNE WITH TWO VOICES
  90. SCRAPALL TYA
  91. PHA
  92. TXA
  93. PHA
  94. LDY #0
  95. STY AUDV0
  96. STY AUDV1
  97. DEY
  98. STY TUNNUM
  99. STY TUNNUM1
  100. PLA
  101. TAX
  102. PLA
  103. TAY
  104. RTS
  105. ; IF YOU WANT, LOOP THIS UP
  106. ********************************************************************************
  107. * SCRAPONE
  108. * KILL A PARTICULAR TUNE. PUT THE NUMBER OF THE TUNE YA WANNA
  109. * AXE IN THE ACCUMULATOR.
  110. ;SCRAPONE CMP TUNNUM
  111. ; BNE CKCH1
  112. ; LDA #0
  113. ; STA AUDV0
  114. ; LDA #$FF
  115. ; STA TUNNUM
  116. ; RTS
  117. ;CKCH1 SEC
  118. ; SBC TUNNUM1
  119. ; BNE REETS
  120. ; STA AUDV1
  121. ; LDA #$FF
  122. ; STA TUNNUM1
  123. ;REETS RTS
  124. ********************************************************************************
  125. * TUNEDONE
  126. * RETURNS TRUE IF NO TUNES ARE PLAYING
  127. * IF BOTH TUNNUM CHANNELS ARE FF, THEN RETURN TRUE
  128. ;TUNEDONE LDA TUNNUM1
  129. ; CMP #$FF
  130. ; BNE TDRTNF
  131. ; LDA TUNNUM
  132. ; CMP #$FF
  133. ; BNE TDRTNF
  134. ; LDA #TRUE
  135. ; RTS
  136. ;TDRTNF LDA #FALSE
  137. REETS RTS
  138. ********************************************************************************
  139. * TUNIN
  140. * START THAT TUNE YOU PUT IN ACC.
  141. TUNIN STA TUNTEMP
  142. LDA MODE ; NO SOUND IN ATTRACT
  143. CMP #MATTRACT
  144. BEQ REETS
  145. LDA DOITOVER ; NO SOUND IN REPLAY
  146. BNE REETS
  147. TYA
  148. PHA
  149. TXA
  150. PHA
  151. LDY #1
  152. LDX TUNTEMP
  153. TROIKA LDA TUNNUM,Y ;FIRST CHECK FOR AN EMPTY CHANNEL
  154. CMP #$FF
  155. BEQ DO
  156. TRKNX DEY
  157. BPL TROIKA
  158. LDA TUNNUM1 ;THIS IS DONE TO PREVENT GLITCHINESS
  159. AND #$7F
  160. TAY
  161. LDA PRYOR,X
  162. CMP PRYOR,Y ;CHECK FOR LOWEST PRIORITY
  163. LDY #1
  164. BCS DO
  165. LDA TUNNUM ;THIS IS DONE TO PREVENT GLITCHINESS
  166. AND #$7F
  167. TAY
  168. LDA PRYOR,X
  169. CMP PRYOR,Y ;CHECK FOR LOWEST PRIORITY
  170. BCC ROOTS
  171. LDY #0
  172. DO TXA
  173. ORA #$80
  174. STA TUNNUM,Y
  175. ROOTS PLA
  176. TAX
  177. PLA
  178. TAY
  179. RTS
  180. ********************************************************************************
  181. *TUNER SHOULD BE CALLED ONCE PER FRAME, NO INPUTS, AND IT OPERATES WITH
  182. *A TOTAL DISREGARD FOR REGISTER SANCTITY. EACH TUNE CAN BE 256 NOTES LONG
  183. *IF YOUR TUNES ARE VERY SMALL, YOU COULD DO AWAY WITH ALL THE INDIRECT STUFF
  184. TUNER LDA STATUS
  185. CMP #STATATTR
  186. BEQ REETS ; RTS
  187. LDA MODE ; DURING PAUSE, RETAIN STATE OF
  188. CMP #MPAUSE ; CURRENT SOUNDS
  189. BEQ REETS
  190. CMP #MBLANK
  191. BEQ REETS
  192. LDX #1
  193. TUNLOP LDY TUNNUM,X
  194. INY
  195. BNE NETN ;TUNNUM=FF DO NEXT CHANNEL
  196. JNXTCH JMP NXTCH
  197. NETN DEY
  198. BPL BOOGIE
  199. TYA ;NEW TUNE--INTITIATE
  200. AND #$7F
  201. STA TUNNUM,X
  202. TAY
  203. LDA CTRLTABL,Y
  204. STA AUDC0,X ; IN EFFECT UNTIL CHANGED
  205. LDA #1
  206. STA DCH0,X ;START
  207. LDA #$FF ; INCREMENTS ON THE FIRST CALL
  208. STA TINDEX0,X
  209. * STA CINDEX0,X
  210. STA VINDEX0,X
  211. BOOGIE LDA TBASE,Y
  212. STA MPTRL
  213. LDA TBASEH,Y
  214. STA MPTRH
  215. DEC DCH0,X
  216. BNE JNXTCH ; SAME AS PATTY'S SOUND EDITOR
  217. LDA DURTABL,Y
  218. STA DCH0,X
  219. LDY TINDEX0,X
  220. * INC CINDEX0,X
  221. INC VINDEX0,X
  222. TESTBYTE INY
  223. TBYTE0 LDA (MPTRL),Y ;FREQ
  224. CMP #$FF
  225. BNE CKNXTT
  226. STA TUNNUM,X ;END THIS FUNKY TUNE
  227. LDA #0
  228. STA AUDV0,X
  229. BEQ JNXTCH
  230. ;CKENL CMP #$FE ; NO REPEATS FOR ME !
  231. ; BEQ FOOBEQ
  232. CKNXTT CMP #$FD ; CONTINUE WITH THE NEXT TUNE
  233. BEQ NEXTTUNE
  234. CMP #$FC ; A VALID STOPPING POINT
  235. BEQ SIRTRUE
  236. CMP #$FB ; NO LONGER VALID FOR STOPPING
  237. BEQ SIRFALSE
  238. JMP STFREQ
  239. SIRTRUE LDA #TRUE
  240. JMP SETIRTN
  241. SIRFALSE LDA #FALSE
  242. SETIRTN STA IRTNDONE
  243. JMP TESTBYTE ; PROCESS THE NEXT BYTE
  244. NEXTTUNE INY ; NEXT BYTE IS TUNE INDEX
  245. LDA (MPTRL),Y
  246. TAY
  247. ORA #$80 ; SO THAT NEW CTRL AND VOLUME GET READ
  248. STA TUNNUM,X
  249. LDA TBASE,Y ; GET ADDRESS OF NEW TUNE
  250. STA MPTRL
  251. LDA TBASEH,Y
  252. STA MPTRH
  253. LDY #0 ; JUMP HERE FOR REPEAT
  254. TYA ; Y MUST BE 0, IT'S THE FREQ. INDEX
  255. * STA CINDEX0,X
  256. STA VINDEX0,X
  257. JMP TBYTE0 ; IN CASE IT'S AN IR SPECIAL
  258. FRQLOOP LDA (MPTRL),Y
  259. STFREQ BPL SKIP0 ; IF BIT 7 SET, GET NEW DURATION
  260. INY
  261. LDA (MPTRL),Y
  262. STA DCH0,X
  263. DEY
  264. LDA (MPTRL),Y
  265. INY
  266. JMP STIT0
  267. SKIP0 ASL A
  268. BPL SKIP1 ; IF BIT 6 SET, THIS IS A REST
  269. LSR A
  270. AND #$BF
  271. STA DCH0,X
  272. TYA
  273. STA TINDEX0,X
  274. DEC VINDEX0,X
  275. * DEC CINDEX0,X
  276. LDA #0
  277. STA AUDV0,X
  278. BEQ NXTCH
  279. SKIP1 ASL A
  280. BPL STIT ; IF BIT 5 IS SET, THIS IS A NEW CTRL
  281. LSR A
  282. LSR A
  283. AND #$1F
  284. STA AUDC0,X
  285. INY
  286. JMP FRQLOOP ; DO NEXT BYTE BEFORE RETURNING
  287. STIT LSR A
  288. LSR A
  289. STIT0 STA AUDF0,X
  290. TYA
  291. STA TINDEX0,X
  292. LDY TUNNUM,X
  293. LDA VBASE,Y
  294. STA MPTRL
  295. LDA VBASEH,Y
  296. STA MPTRH
  297. LDY VINDEX0,X
  298. LDA (MPTRL),Y
  299. BPL STVL
  300. DEY
  301. STVL STA AUDV0,X
  302. TYA
  303. STA VINDEX0,X
  304. * LDY TUNNUM,X
  305. * LDA CBASE,Y
  306. * STA MPTRL
  307. * LDA CBASEH,Y
  308. * STA MPTRH
  309. * LDY CINDEX0,X
  310. * LDA (MPTRL),Y
  311. * BPL STCTRL
  312. * DEY
  313. *STCTRL STA AUDC0,X
  314. * TYA
  315. * STA CINDEX0,X
  316. NXTCH DEX
  317. BMI ROTS
  318. JMP TUNLOP
  319. ROTS RTS
  320. ********************************************************************************
  321. * pointer tables.
  322. TBASE DB L(ZTUNE0F),L(ZTUNE1F),L(ZTUNE2F),L(ZTUNE3F)
  323. DB L(ZTUNE4F),L(ZTUNE5F),L(ZTUNE6F),L(ZTUNE7F),L(ZTUNE8F)
  324. DB L(ZTUNE9F),L(ATUNE10F),L(ATUNE11F),L(ATUNE12F)
  325. DB L(ATUNE13F),L(ZTUNE14F),L(ZTUNE15F),L(ZTUNE16F)
  326. DB L(ZTUNE17F),L(ZTUNE18F),L(ZTUNE19F),L(ZTUNE20F)
  327. DB L(ZTUNE21F),L(ZTUNE22F),L(ZTUNE23F)
  328. DB L(ZTUNE24F),L(ZTUNE25F),L(ZTUNE26F)
  329. DB L(ZTUNE27F),L(ZTUNE28F),L(ZTUNE29F)
  330. DB L(ZTUNE30F),L(ZTUNE31F),L(ZTUNE32F)
  331. TBASEH DB H(ZTUNE0F),H(ZTUNE1F),H(ZTUNE2F),H(ZTUNE3F)
  332. DB H(ZTUNE4F),H(ZTUNE5F),H(ZTUNE6F),H(ZTUNE7F),H(ZTUNE8F)
  333. DB H(ZTUNE9F),H(ATUNE10F),H(ATUNE11F),H(ATUNE12F)
  334. DB H(ATUNE13F),H(ZTUNE14F),H(ZTUNE15F),H(ZTUNE16F)
  335. DB H(ZTUNE17F),H(ZTUNE18F),H(ZTUNE19F),H(ZTUNE20F)
  336. DB H(ZTUNE21F),H(ZTUNE22F),H(ZTUNE23F)
  337. DB H(ZTUNE24F),H(ZTUNE25F),H(ZTUNE26F)
  338. DB H(ZTUNE27F),H(ZTUNE28F),H(ZTUNE29F)
  339. DB H(ZTUNE30F),H(ZTUNE31F),H(ZTUNE32F)
  340. VBASE DB L(ZTUNE0V),L(ZTUNE1V),L(ZTUNE2V),L(ZTUNE3V)
  341. DB L(ZTUNE4V),L(ZTUNE5V),L(ZTUNE6V),L(ZTUNE7V),L(ZTUNE8V)
  342. DB L(ZTUNE9V),L(ZTUNE10V),L(ZTUNE11V),L(ZTUNE12V)
  343. DB L(ZTUNE13V),L(ZTUNE14V),L(ZTUNE15V),L(ZTUNE16V)
  344. DB L(ZTUNE17V),L(ZTUNE18V),L(ZTUNE19V),L(ZTUNE20V)
  345. DB L(ZTUNE21V),L(ZTUNE22V),L(ZTUNE23V)
  346. DB L(ZTUNE24V),L(ZTUNE25V),L(ZTUNE26V)
  347. DB L(ZTUNE27V),L(ZTUNE28V),L(ZTUNE29V)
  348. DB L(ZTUNE30V),L(ZTUNE31V),L(ZTUNE32V)
  349. VBASEH DB H(ZTUNE0V),H(ZTUNE1V),H(ZTUNE2V),H(ZTUNE3V)
  350. DB H(ZTUNE4V),H(ZTUNE5V),H(ZTUNE6V),H(ZTUNE7V),H(ZTUNE8V)
  351. DB H(ZTUNE9V),H(ZTUNE10V),H(ZTUNE11V),H(ZTUNE12V)
  352. DB H(ZTUNE13V),H(ZTUNE14V),H(ZTUNE15V),H(ZTUNE16V)
  353. DB H(ZTUNE17V),H(ZTUNE18V),H(ZTUNE19V),H(ZTUNE20V)
  354. DB H(ZTUNE21V),H(ZTUNE22V),H(ZTUNE23V)
  355. DB H(ZTUNE24V),H(ZTUNE25V),H(ZTUNE26V)
  356. DB H(ZTUNE27V),H(ZTUNE28V),H(ZTUNE29V)
  357. DB H(ZTUNE30V),H(ZTUNE31V),H(ZTUNE32V)
  358. END