Background Music

Basic and Machine Language

Moderator: Moderators

Post Reply
tonyrocks
Vic 20 Hobbyist
Posts: 118
Joined: Mon Jan 04, 2016 10:17 pm
Website: http://www.tonyrocks.com
Location: Pittsburgh
Occupation: IBM Watson Engr

Background Music

Post by tonyrocks »

Is it possible play sounds or background music using BASIC (and perhaps DATA) and not have the other basic routines get in the way?
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Re: Background Music

Post by tlr »

Using only basic is hard but you can include a small ml-program in data statements which is poked in and started in the background with a sys.
tonyrocks
Vic 20 Hobbyist
Posts: 118
Joined: Mon Jan 04, 2016 10:17 pm
Website: http://www.tonyrocks.com
Location: Pittsburgh
Occupation: IBM Watson Engr

Re: Background Music

Post by tonyrocks »

thanks TLR. Anybody have any examples? :)
User avatar
Mike
Herr VC
Posts: 4839
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Background Music

Post by Mike »

In BASIC you'd need a main loop that's executed in a fairly regular manner. Not that hard to accomplish, as such a loop is a central element of most games. Getting a constant execution time for that loop is a little more difficult. That given, you'd just POKE the sound registers with new values upon each new main loop iteration.

Here's an example that plays a children's song alongside a well known animation from the VIC user's guide: (link)

With interrupts, and in machine language, it's much easier to do, obviously. Like thus (download):

Code: Select all

1 FORT=828TO939:READA:POKET,A:NEXT:SYS828
2 DATA 120,169,81,141,20,3,169,3,141,21,3,169,0,141,137,3,141,138,3,88,96,174,137,3,202
3 DATA 16,30,172,138,3,185,140,3,141,12,144,240,2,169,15,9,240,141,139,3,200,192,32,144
4 DATA 2,160,0,140,138,3,162,14,142,137,3,173,14,144,41,240,13,137,3,45,139,3,141,14
5 DATA 144,76,191,234,0,0,0,204,204,0,204,201,201,204,204,0,225,221,215,210,204,204,0
6 DATA 204,204,0,204,195,195,187,187,0,225,221,215,210,204,204,0
It's still (mostly) BASIC and DATA, so there you go. ;)
User avatar
pixel
Vic 20 Scientist
Posts: 1351
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Background Music

Post by pixel »

In the end you'd have get hold of an assembly coder or – much, much better – you get into assembly yourself which is a very rewarding experience. The 6502 instruction set is poetry. 8)
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
tonyrocks
Vic 20 Hobbyist
Posts: 118
Joined: Mon Jan 04, 2016 10:17 pm
Website: http://www.tonyrocks.com
Location: Pittsburgh
Occupation: IBM Watson Engr

Re: Background Music

Post by tonyrocks »

thanks guys, you've been a big help. Im trying to push limits with BASIC for myself, but I'm finding it difficult to push where I want to go :) heh
Post Reply