Remember this was a retrocomputing blog? A certain cookie company remembers, but if they want their name shout-out they’re going to have to send me some cookies. Today, we’re going to pick that up again, and look at fixing one of the major weak points of my lovely Apple ][plus: its audio capability. Let’s break out the AY-3s and dig in!

Stop this Apple ][ slander immediately!

Why am I so critical? The Apple ][ has the best built-in audio of the 1977 trinity, after all. By which I mean to say, it has audio. The PET 2001 and the TRS-80 Model 1 didn’t; of course, once Commodore added a similar beeper speaker to the PET and Tandy users realized they could use the microphone jack for audio that lead disappeared. And in 1979 Atari’s 8-bit computers introduced home users to the POKEY. But still! 1977!

And what is that sound support? The Apple ][ has a built-in speaker with no other audio output. This is controlled with a “soft switch”. This is just a memory address that isn’t actually memory; the 6502 processor can only access memory, so all IO must pretend to be a memory address. In this case, address $C030 controls the speaker. (In decimal this is 49200, so remember that for later) This sort of “memory-mapped IO” may seem strange, but it’s actually very common even today.

The Apple II plus circuitboard, with its 6502 in the center

And when I say controls the speaker, I mean literally controls the speaker. The speaker is a paper diaphragm controlled by an electromagnet. One write to the address energizes the electromagnet. The next write will de-energize it. This is agonizingly low-level; to make a 1000 Hz tone, like the famous Apple ][ boot-up tone, you have to write to the address 2000 times a second. And remember, the stock Apple ][ has no timers or interrupts; the only way to time is by knowing the processor clock frequency, and counting your cycles.

Let’s see and hear how limited this is in reality. If you have an Apple II or an emulator, go to Applesoft and type in X=PEEK(49200), where X can be any variable. (I just used X and never looked at it; because the processor and BASIC think you’re reading memory, it’ll want somewhere to put the result) You may not hear anything, but if you do it’ll be the faintest click. Now type the following:

10 X=PEEK(49200)
20 GOTO 10

Recorded with my webcam, you’ll probably hear a low-pitched tone like this:

If you change the program to the following, you’ll hear the tone disappear and be replaced with a series of clicks. Just one additional BASIC command makes this too slow.

10 X=PEEK(49200)
20 PRINT "NYA"
30 GOTO 10

That low tone is probably the highest-pitched tone you can achieve in BASIC. Of course, assembly language can do better because it runs a lot faster; the Apple ][ rom includes a beep routine you can access by calling CALL -16336. Of course, it drops you in the monitor afterwards, so have fun with that, my BASIC-using friend.

In Jeremy Parish’s NES Works series on YouTube, he notes that the Famicom/NES was designed around the game Donkey Kong. While a computer, the Apple ][ was also designed around a single game: Breakout. Having already implemented it in hardware for Atari (though his design was not used), computer enthusiast Steve Wozniak wanted to make a computer that could run it in BASIC. And he succeeded.

A listing of BASIC code

Game Over screen in Little Brick Out. Only a few bricks are broken and the game is telling me my score is not too good.

Breakout has a few beeps. But it’s not exactly a symphony.

That being said, there are definitely Apple ][ software that did very impressive things with the speaker; but if you’re wondering why most games don’t play music while also playing the game, it’s because of difficulties like this. Playing music takes all of the CPU’s attention; the precise timing is a pain.

Steve Wozniak gave us an out, though. Remember, the Apple ][ didn’t outlive all of its competition for nothing; it’s got slots. And honestly, I could do to use more of them.

Introduce the card already

So, if you’re capable of speaking, imagine the human voice. At least in my experience, I can make a tone with my voice. I can raise that tone higher and lower. And to me, consciously, I feel like I’m just changing the pitch. Sure, the muscles in my larynx are moving at various speeds, but I don’t have to control them manually. What if we could give the Apple ][ that capability? Unlike the human mind, the Apple ][ can’t learn to sing on its own, but unlike the human mind, we can plug modules into it, so it’s a fair tradeoff.

Behold, the Mockingboard:

The ReactiveMicro Mockingboard v2.2. It has two 6522 chips and two AY-3-8910 chips.

This is a reproduction of an original design, with some updates and improvements, sold today by ReactiveMicro. (No affiliation; this was bought with my own funds) The original Mockingboard dates back to 1983. Unfortunately, this recreation includes slots for but does not include the speech chips that the original could use; therefore, my computer will not be talking to me today.

You might wonder why Apple didn’t release a sound card in this period; they did after all release things like the Super Serial Card and the Disk ][ that became standard. Perhaps music synthesis wasn’t considered necessary for Apple’s audience of small businesses, enthusiasts, and schools. Or perhaps they were still worried about the Apple Corps. In any case, the Apple IIgs would change all that, but it didn’t come out until 1986, and its audio wasn’t backwards-compatible. On the 8-bit Apple ][s, this seems to have been the most common solution. Or at least, the most supported by software.

Of course, installing a card on the Apple ][ is pretty easy. I put the card in slot 4, but this seems to not be necessary as a lot of software will detect the slot. However, since slot 4 was open, I figured I might as well. I didn’t hook up the speaker solely because I was worried about turning on the machine and not hearing the familiar beep if my audio setup wasn’t configured right. I can’t take that risk.

The inside of an Apple II. Cards are installed, including the Mockingboard.

So how does it sound? The Mockingboard is based around the General Instrument AY-3-8910. This is a three-voice sound chip that we’ve seen before on this channel. That’s right, it all comes back to Pitfall II; this is the sound chip used by the MSX computer, along with the 16-bit Intellivision, the Vectrex, the Amstrad CPC, and a whole host of machines. It’s similar but not the same as the SN76489 that was discussed in the past few Master System and Sega System 1 posts.

Let’s recall how the Pitfall II music sounded on the MSX.

And did you know, they released Pitfall II on the Apple ][! It’s true! It’s very similar in terms of gameplay to the home computer ports, and it’s actually a pretty interesting example of Apple ][ graphics. See the black specs in the sky? Green and blue can never “touch” on the Apple ][. Most of the gameplay area, therefore, uses the Blue and Orange “palette” and therefore doesn’t have to worry about color clashes. But Apple ][ colors probably warrant a post of their own.

Pitfall II on the Apple II

In any case, this game also uses Mockingboard audio. I suspect it was designed for early Mockingboards that only had one AY-3-8910, though. Still, this game is definitely much better with sound, and it might surprise you that it’s quite a bit different sounding from the MSX version.

I suspect there may be a bit more filtering on the Mockingboard than on the MSX, for one. But another big difference is that the Apple ][ game doesn’t need to worry about sound effects. On the MSX1, the AY-3 is the only sound output you had; both music and sound effects need to go over it. But on the Apple, you also had the beeper speaker; this game chose to have all sound effects therefore use the beeper, so that users without a Mockingboard can still hear them.

It’s worth stressing that Pitfall II doesn’t use the full capabilities of the Mockingboard. And in fact, later games, like Ultima V would go so far as to use two Mockingboards simultaneously for even more advanced sound. So in a sense this is only going one quarter as hard as Ultima V can. But I don’t have two Mockingboards.

For a simple example, here’s something from the Mockingboard demo disk. Pop Goes the Weasel in Stereo, with one AY-3 on each channel. Hard-panning: It’s not just for the Amiga anymore.

How does it work?

The Mockingboard is a pretty simple design. There are two VIA (Versatile Interface Adapter) chips; this is the Peripheral Interface Adapter, the MOS 6522. This board uses Rockwell parts, but WDC, makers of the 65C02 and 65C816, still sell their version of the 6522 today. Remember how I mentioned that the 6502 can’t actually interface with anything that doesn’t act like memory? The 6522 papers over these differences, giving you general-purpose IO pins.

Zoom in on the two PIA chips

Each VIA has two data ports; these look like memory addresses to the 6502, but are actually IO lines. The Mockingboard hooks up those two sets of IO lines to the control port and the data pins. There are two VIA chips because there are two AY-3-8910s. (The speech chips can interface with the data bus more directly)

Coding?

After all the talk of BASIC above, I was all for going through and trying to write to each register on the AY-3-8910 through POKEs and PEEKs. However, this gets a bit complex; unfortunately, you might still have to move on from BASIC. However, the aforementioned Mockingboard demo disk (available freely on ReactiveMicro’s Wiki) actually contains this for you.

Apple II Mockingboard register control. Registers listed are Tone Per Fine, Tone Per Coarse, Noise Period, Enable, Amplitude, Envl Per Fine, Envl Per Coarse, and Envl Shape

If you do mess with it, I recommend seeing how if you start playing, you can go on and do other things. The sound will keep playing until you tell it to stop. This is the key advantage of the Mockingboard or other sound synthesizers. Instead of talking to the speaker every single time the paper cone needs to move, you only need to signal to it every time you want to change notes. This frees up a lot of CPU time for other things; though of course, you’re still limited by the Apple ][’s lack of timers.

UPDATE 10/10. Thanks to reader “cjs” for pointing out that the VIA chips I mentioned both have timers. One is hooked up to the IRQ line of the Apple ][, the other the NMI– thus, the coder will now have access to timed interrupts, which will definitely be very useful for songs, and is probably, as he pointed out, the main reason for using a VIA at all for this.

Apple IIgs and beyond

So, you might assume that the Mockingboard isn’t useful on the Apple IIgs, since the system has an Ensoniq chip that honestly blows it away. However, no provision for backwards compatibility was made, so if you want to run 8-bit software; even modern software like Nox Archaist, you might want one in your IIgs after all. And it definitely has the slots. There is a slight catch though.

Apple IIgs control panel

To configure the slots for 8-bit software, you’ll need to set the slot you’re using in the Apple IIgs control panel to “My Card”. And if you want to use Slot 4, then you might find yourself having to disable the mouse port. The internal additions to the IIgs were mapped to virtual slots, which is usually a convenience feature. Still, once this is done there shouldn’t be any issues.

Having the Mockingboard is usually seen as a must for any Apple ][ owner these days; it’s kind of surprising that I hadn’t bothered to get one until now. Perhaps because I use the ][plus and most of its software predates 1983; but if you’re using a //e and want to take advantage of those ever-nebulous enhancements, you’ll definitely want one of these onboard. (For example, the 8-bit Guy’s recent release of Attack of the PETSCII Robots for the Apple ][ only supports Mockingboard audio if you have 128kiB of RAM)