Simplest Sound Effects Library for BASIC programs

These files might not work on the most current version of the Commander X16, or these may be held over from the previous forum. To find previous versions of the emulator, so you can test old programs, please visit Our GitHub Page
Post Reply
User avatar
DusanStrakl
Posts: 127
Joined: Sun Apr 26, 2020 9:15 pm
Location: Bay Area, California
Contact:

Simplest Sound Effects Library for BASIC programs

Post by DusanStrakl »


Usage




Because of its simplicity the library can be stored in a 1K space below basic programs, starting at $0400.



Save the EFFECTS.PRG program in the directory where your BASIC program is stored, which would typically be in the same directory from where you are running the emulator.



 



Load library with LOAD command:



 



LOAD”EFFECTS.PRG”,8,1,$0400



 



Since this routine after the first run adds a new interrupt handler it is good practice to only load it once. It is therefore recommended to do a simple check:



 



IF PEEK($400)=0 THEN LOAD”EFFECTS.PRG”,8,1,$0400



 



 



And that is it. Now you only need to call the needed sound effect from the BASIC program with a simple SYS command. We have four different effects so four different addresses can be called:



 




























SYS $400

PING

Is designed for events like picking coins or rewards.

SYS $403

SHOOT

Effect that can be used for shooting the gun or other weapon.

SYS $406

ZAP

Electricity zapping or perhaps a laser gun sound.

SYS $409

EXPLODE

Long explosion for when we successfully blow something up



 



Alternative binary named EFFECTSHI.PRG that loads into memory at $9000 can be downloaded. Of course calls are then $9000 for PING, $9003 for SHOOT, $9006 for ZAP and $9009 for EXPLODE.



 



Full source code and walk through is available at my blog:





 



Demo video:











 



 



 


Updated version saves VERA state in the IRQ player which was before interfering with some graphical functions in BASIC programs like scrolling.


Attachments
Simplest Sound Effects Library for BASIC programs
Simplest Sound Effects Library for BASIC programs
EffectsEnvelope.png (19.63 KiB) Viewed 6035 times
EFFECTS.PRG
Simplest Sound Effects Library for BASIC programs
(361 Bytes) Downloaded 358 times
EFFECTSHI.PRG
Simplest Sound Effects Library for BASIC programs
(361 Bytes) Downloaded 343 times
mobluse
Posts: 175
Joined: Tue Aug 04, 2020 2:16 pm
Location: Lund, Sweden
Contact:

Re: Simplest Sound Effects Library for BASIC programs

Post by mobluse »

I cannot get EFFECTS.PRG or EFFECTSHI.PRG to work in x16emu R43, but they work in R42. In R43 they crash the program and they hang or you get into the debugger/monitor. At least EFFECTS.PRG doesn't work in the web emulator R43. I use EFFECTS.PRG in Aritm on this site. You can use Aritm if you remove the lines with SYS: 2405 and 3620. I plan to replace EFFECTS.PRG with PSG sound effects in BASIC. It would be interesting to know why EFFECTS.PRG crashes in R43.
X16&C64 Quiz: Try It Now! Huge Char Demo: Try It Now! DECPS: Try It Now! Aritm: Try It Now!
Post Reply