Posted: Mon Jun 18, 2007 11:30 am
Good news, everyone! I finally got this all up and running! I pulled sickie today and instead of going to work I stayed home and worked on the code. This is the first real 6502 coding I have done and my code is very simple and primative (I am too ashamed to post it just yet) but it seems to be working. Lots of little problems along the way of course.
The circuit is simple. The 6502 controls a 6522. I use the upper four bits on one port to select which audio chip to play the sampled audio from (I have three but in theory you could do 10) and the lower four bits to preload the starting address on my binary counter hooked up to the audio ROMs. Each ROM is basically broken into 16 one second blocks and I can choose which one to start playing from. Another bit on a VIA port simultaneously loads the upper address bits on the counter and clears the lower bits. The audio board has it's own clock so a further bit on the VIA is used to AND with this clock to start it playing. I did it this way (instead of the CPU or VIA generating the clock) just so I can manually vary the clock rate for the audio and hence the playback speed. Samples can go over the one second boundaries. To know when to stop playing I have a 8 input NAND on the ROM output. I code a FF into the sample as a stop bit. The NAND generates a pulse which I feed into an interrupt pin on the VIA. That interrupts the processor and I stop the playback and reset everything. That was the hardest part. I couldn't get it to play more than once at first but that was because I wasn't disabling the VIA interrupt inside the interrupt handler and I think it was then never getting past that code as it would just keep interrupting and never reset.
All the main code does is loop around storing a value for each chip and sample to play (15 different phrases in all). After storing each one it polls a button hanging off the VIA to see if it is pressed. If so it just plays whatever sample it just stored address info for. It then ignores button presses until the sample stops playing. Since the processor is loading and reloading all the addresses so much faster than the playing of the samples it is almost random as to what sample you get when you hit the button. Random enough for me anyway.
I know there are much better ways to achieve what I have done but the point was to use a 6502 in some way and, crude as it is, this definitely works and it has been fun building it too!
When I have put together a little web page about the entire Bender and his brain I will post a link to it here.
Simon
The circuit is simple. The 6502 controls a 6522. I use the upper four bits on one port to select which audio chip to play the sampled audio from (I have three but in theory you could do 10) and the lower four bits to preload the starting address on my binary counter hooked up to the audio ROMs. Each ROM is basically broken into 16 one second blocks and I can choose which one to start playing from. Another bit on a VIA port simultaneously loads the upper address bits on the counter and clears the lower bits. The audio board has it's own clock so a further bit on the VIA is used to AND with this clock to start it playing. I did it this way (instead of the CPU or VIA generating the clock) just so I can manually vary the clock rate for the audio and hence the playback speed. Samples can go over the one second boundaries. To know when to stop playing I have a 8 input NAND on the ROM output. I code a FF into the sample as a stop bit. The NAND generates a pulse which I feed into an interrupt pin on the VIA. That interrupts the processor and I stop the playback and reset everything. That was the hardest part. I couldn't get it to play more than once at first but that was because I wasn't disabling the VIA interrupt inside the interrupt handler and I think it was then never getting past that code as it would just keep interrupting and never reset.
All the main code does is loop around storing a value for each chip and sample to play (15 different phrases in all). After storing each one it polls a button hanging off the VIA to see if it is pressed. If so it just plays whatever sample it just stored address info for. It then ignores button presses until the sample stops playing. Since the processor is loading and reloading all the addresses so much faster than the playing of the samples it is almost random as to what sample you get when you hit the button. Random enough for me anyway.
I know there are much better ways to achieve what I have done but the point was to use a 6502 in some way and, crude as it is, this definitely works and it has been fun building it too!
When I have put together a little web page about the entire Bender and his brain I will post a link to it here.
Simon