One of my favorite Apple II hacks was with the speaker. Basically, you
could do one thing. You reference a softswitch in memory ($c030) and the
speaker is popped from in to out or vice versa depending on the state it was
in, so writing a square wave generator was easy, and that's about as far as
most people got.
The faster you tweak the speaker, the higher the pitch. So I tried to generate
the highest pitch possible:
l1 sta $c030 ; tweak the speaker
jmp l1
When run, it makes no noise. Well, almost no noise. You can hear a faint
whine from the speaker. What happens is that you can pop the speaker back
into one position before it reaches the other from the last pop, damping the
sound. A little tweaking gave me a software volume control by putting to
tweaks close together with a balanced timing loop:
sta $c030
l1 ldy #$01
l2 dey
bne l2
sta $c030
l3 ldy #$07
l4 dey
bne l4
The trick was equalizing the delay, so you self-modify the code before you
start playing sound (since ldy with an absolute address used 2 more cycles
than a ldy immediate):
lda volume
and #$7
sta l1+1 ; self-modify the preceding loops
tay
lda compliment,y ; get the compliment of the volume
sta l3+1
volume hex 01
compliment
hex 01020304050607
Which now gave you a way to generate up to 7 volumes. But wait, there's more!
The "standard" way of generating sound was to click the speaker, run a delay
loop then loop back. This would give you a simple square wave with a problem
that higher frequencies had shorted durations than lower frequencies, since
the duration was partially dependent on how long your delay was. Bogus!
My solution was have one outside loop and click the speaker every nth time
through the loop (which also gave finer frequency control). This meant that
most of my time wasn't spent running a delay, but instead skipping over the
speaker click. This allowed me to nest two separate speaker click routines
allowing two different voices with independent volume control.
It also turned out that I could do all this using only the A and Y registers and
that left me with the X register for something else... hmm, what can I do now?
I know! Attack and decay! Of course, with all of this added in the frequency
values were not quite linear, ie, doubling the frequency value didn't *quite*
double the generated frequency. I never quite found my way around that one...
Then again, I was only 15 at the time.
I moved on to other things, like writing a digitizer that used the cassette
input port and used every available sector on the disk (including that one
track you could only get to by modifying the cmp #$23 instruction in RWTS
before you initialized the disk), and then writing a playback program that
loaded the largest hunks it could get off of disk at once (about 40K) and
play them back. This amounted to about 2 minutes of sound. I got thrown
out of the school library by setting it up to continuosly play Eruption by
Eddie Van Halen...
*sigh* I miss my salad days sometimes...
Have you ever noticed that nostalgia just isn't what it used to be?
Steve Hawley
haw...@adobe.com
--
"Did you know that a cow was *MURDERED* to make that jacket?"
"Yes. I didn't think there were any witnesses, so I guess I'll have to kill
you too." -Jake Johansen