Game music

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
kelp7
Vic 20 Amateur
Posts: 40
Joined: Fri Aug 29, 2008 4:16 am

Game music

Post by kelp7 »

Hi,

I've always wondered how the programming for in-game music is achieved. Does the programmer set up an interrupt that jumps to a music routine? Or do you manually jump during the vertical blank? How does the music regulate its tempo if you are just manually jumping every 1/50th second to a music routine?

Thanks!
kelp
MZ-80A Secrets
http://mz-80a.com
malcontent
Vic 20 Hobbyist
Posts: 129
Joined: Sun Dec 26, 2010 1:51 pm

Re: Game music

Post by malcontent »

It is usually jsr'ed to in the IRQ. Tempo wise you have a decent amount of wiggle, as in practice you'll be holding notes; even a sixteenth note needs to be sustained for several screen refreshes.

Music is done using tables, with values to feed into the registers, and a value to determine length. Each time the routine is called, the length is decremented or compared, and if it's over, the next note/length in the table is grabbed.
User avatar
Kweepa
Vic 20 Scientist
Posts: 1314
Joined: Fri Jan 04, 2008 5:11 pm
Location: Austin, Texas
Occupation: Game maker

Re: Game music

Post by Kweepa »

Here's an example, from Doom:
https://github.com/Kweepa/vicdoom/blob/ ... laysound.s
It works pretty much as malcontent describes.
I didn't change the interrupt frequency away from its default 60Hz.
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Re: Game music

Post by tlr »

If you require raster splits for graphics purposes in your code then it's a good idea to also call the music synchronized with the screen update.

I tend to do that always unless there is a specific reason.
User avatar
kelp7
Vic 20 Amateur
Posts: 40
Joined: Fri Aug 29, 2008 4:16 am

Re: Game music

Post by kelp7 »

As ever I applaud this forum and its forumites :-) always receive many a helpful answer when I pose these (probably newbie) questions...
thanks!
kelp
MZ-80A Secrets
http://mz-80a.com
User avatar
kelp7
Vic 20 Amateur
Posts: 40
Joined: Fri Aug 29, 2008 4:16 am

Re: Game music

Post by kelp7 »

Actually, on a similar topic to this (and bear with me because I really am pretty new to writing games). Sound effects in games, are these done in a similar way to the music? In my younger years when I did actually try writing my own games the sound would always stop the rest of the program, i.e. the action on screen would halt while the sound played. Obviously, I wasn't writing in machine language or assembly then... just BASIC. I'm guessing from the above answers that it's a pretty similar method to the music?
kelp
MZ-80A Secrets
http://mz-80a.com
User avatar
beamrider
Vic 20 Scientist
Posts: 1447
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: Game music

Post by beamrider »

Not sure about anyone else but my sounds in Pooyan are actually small tunes. I have two music players. The effects player steals channels from the background music as needed.

Sent from my Nexus 5 using Tapatalk
User avatar
beamrider
Vic 20 Scientist
Posts: 1447
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: Game music

Post by beamrider »

.....So I can play a sound effect or tune by just setting a value in memory that gets polled during the IRQ handler

Sent from my Nexus 5 using Tapatalk
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Game music

Post by Mike »

kelp7 wrote:[...](and bear with me because I really am pretty new to writing games).[...]
Really?

http://sleepingelephant.com/ipw-web/bul ... php?t=2904

... and to quote from this posting in 2008:
I [...] am going to jump straight in at the deep end with machine language rather than BASIC. (Simply because i've written other games in machine code on other machines).
Sorry, but ... :roll:
User avatar
Kweepa
Vic 20 Scientist
Posts: 1314
Joined: Fri Jan 04, 2008 5:11 pm
Location: Austin, Texas
Occupation: Game maker

Re: Game music

Post by Kweepa »

Doom's sound effects are similar to the music - the code is in the same file.
I use the noise channel exclusively for sound effects, but I pause the music because the volume for the effects needs to be cranked up to be heard.
User avatar
tokra
Vic 20 Scientist
Posts: 1120
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

Re: Game music

Post by tokra »

Would it possible to do it like this?

- first interrupt cycle silents noise-channels, sets volume to 8, plays music note
- second interrupt cycle silents music-channels, sets volume to 15, plays noise channel
- repeat

No idea if that would sound as one would expect (low music, loud noise).
User avatar
kelp7
Vic 20 Amateur
Posts: 40
Joined: Fri Aug 29, 2008 4:16 am

Re: Game music

Post by kelp7 »

Mike wrote:
kelp7 wrote:[...](and bear with me because I really am pretty new to writing games).[...]
Really?

http://sleepingelephant.com/ipw-web/bul ... php?t=2904

... and to quote from this posting in 2008:
I [...] am going to jump straight in at the deep end with machine language rather than BASIC. (Simply because i've written other games in machine code on other machines).
Sorry, but ... :roll:
Haha, yep. I'd still consider myself a newbie. Any 'games' I may have written before were pretty basic themselves and I understand a reasonable amount of programming theory (iteration, jumps, etc) but there are plenty of things I still have no clue about :-) Scary how much time has passed since writing that and I still never found time to properly get into all this. However, that said, I now do have some amount of time to dedicate to writing stuff. I have said in another thread here that I'm currently writing for a different machine than the VIC but I come here to ask questions as this is an extremely helpful and active forum! I do actually intend to write for the VIC in the not too distant future. Heh, sorry for the contradictory-sounding posts!
kelp
MZ-80A Secrets
http://mz-80a.com
User avatar
kelp7
Vic 20 Amateur
Posts: 40
Joined: Fri Aug 29, 2008 4:16 am

Re: Game music

Post by kelp7 »

...and thanks everyone for the rest of the replies! Very helpful and does shed light on how these things work...
MZ-80A Secrets
http://mz-80a.com
Post Reply