TurboSound: Three AY Chips Behind Two Ports
Two ports, three chips. In most of engineering, that sentence is the opening line of a bug report. On the Next, well, it is a feature. Load a 128K game that has never heard of the Next, and its tune plays on the first AY chip exactly as it did on the 128K. Load a Next tracker, and you hear nine channels at once, each chip parked at its own spot between your left and right ear. So how can three chips share two ports without the old software ever noticing that it has company?
Have you ever written music for one AY chip? Then you know how tight three voices are. You get a melody, a bass, and one more voice for everything else, and the drums have to elbow their way in between whenever the other three take a breath. Three chips give you nine. That is enough for full chords, a drum part of its own, and sound effects that no longer have to mug the melody for a channel. And because you can place each chip left, right or in the middle, you can spread a tune across the stereo field like a mixing desk, minus the coffee stains. If you ask me, this is the most generous upgrade the Next gave the 128K’s sound.
Everything here builds on One AY Chip: Tones, Noise and Envelopes, which takes a
single chip apart, with its registers and ports $FFFD and $BFFD. I will not repeat any of
that here; we only look at what changes when there are three of them. If stereo and panning are new to you,
the background chapter’s section
Two speakers explains
them in a few minutes. Go on, I will wait.
The road ahead
Uhm, I have to confess something: the whole of TurboSound rests on one small idea. Some values a program can
write to port $FFFD can never be a register number, so the Next is free to give them a new meaning, “talk to
this chip from now on”. We start there, because everything else follows from it, and then play one note to see
the idea at work. Next comes the switch that turns TurboSound on and off, and the curious way the chosen chip
freezes while it is off. Then we look at where each chip’s three channels land between your two ears, in ABC,
ACB or mono, and how you can push a whole chip to one side. After that, a look at how much of the mixer nine
channels at full volume really take, and what a reset clears. We end with what programs do with all this.
Levels are in the units of the Next’s mixer: one AY channel at full volume adds 255. The chips are in YM2149 mode, and every capture plays channel B, or all three channels, at full volume. The waveforms are captured from an emulated Next at 48,000 samples a second, from programs checked to do what the text says; in them the AY chips count up from 0, as they do on the hardware.
Three chips, two ports
The Next has three AY chips, numbered 0, 1 and 2. I call them the trio, because they share one stage
and, most of the time, one tune. All three listen to the 128K’s two ports, port $FFFD (select a
register) and port $BFFD (write it). But only one of them is allowed to answer: the selected chip.
Whatever you write, and whatever you read, goes to that chip, while the other two politely look the other way.
Here is the trick, and I think it is a lovely one. A register number is 0 to 31, so when a 128K program selects a register, bits 7–5 are always 0. It has no reason to put anything else there. Those upper values are an empty room in an old house, and TurboSound simply moves in and gives some of them a meaning of their own:
- Bit 7 is 1: “this is not a register number”.
- Bits 4–2 are
111: “and I really mean it: I am choosing a chip”. - Bits 1–0 pick the chip:
11for chip 0,10for chip 1,01for chip 2. (00picks chip 0 as well.) - Bits 6–5 set that chip’s pan, which you meet properly a little later: bit 6 lets the chip into the left side, bit 5 into the right.
With both pan bits set, you get three values that are easy to remember: $FF for chip 0, $FE for chip 1 and
$FD for chip 2. And what if you write a value with bit 7 set but some other pattern in bits 4–2, or one with
bit 7 clear but bits 6–5 not both 0? Nothing at all. The Next simply shrugs.
Look at what this buys you. An old program cannot select a chip by accident, because it never writes such a value. A new program needs no new port, because the old one had room to spare all along. It is the kind of design I wish I had come up with myself.
Well, there is one small catch: none of this works until TurboSound is switched on. You will see what that means in a moment.
One note, five writes
Let’s play a note on chip 1’s channel A. It takes exactly one write more than it would on a 128K: you select the chip first, and then carry on as you always did.
- Write
$FEto port$FFFD: chip 1 is now the selected chip (and plays on both sides). - Write
0to port$FFFD: you have selected register 0 of chip 1. - Write the period’s low byte to port
$BFFD: it lands in chip 1’s R0. - Write
8to port$FFFD, then the volume to port$BFFD: chip 1’s R8, and the note sounds.
That’s all. One thing I want you to remember from this little exercise, though: each chip keeps its own selected register, like three clerks who each keep their own place in the ledger. So when you switch from one chip to another, select the register again, and do not count on the last one you used. The chip itself stays selected until your next chip select, which is why a music player usually visits each chip once per frame and writes all of its registers in one go. That is also the habit I would recommend: one visit per chip, all registers at once, and no guessing about which clerk has his finger on which line.
Reading works the same way: port $FFFD gives you the selected register of the selected chip. And if your
program has lost track of whom it is talking to (it happens to the best of us), port $BFF5 will tell it, as
AY or YM in the previous chapter
explains. Its bits 7–6 read 11, 10 or 01, the same codes the select uses, and bits 4–0 hold the selected
register.
TurboSound on, TurboSound off
TurboSound has a switch: bit 1 of the Peripheral 3 Setting register, NextReg $08. It is off after
power-on, and then your Next does a very convincing impression of a 128K:
- Only the selected chip sounds. The other two stay silent, whatever their registers hold.
- The selection is frozen. The Next ignores every chip select, so the selected chip cannot change. After power-on that is chip 0, which is why every 128K program plays on chip 0 and never suspects a thing.
“Frozen” means exactly what it says: the selection stays wherever it was when the music stopped, like a game of musical chairs. Switch TurboSound on, select chip 2, switch TurboSound off again, and chip 2 stays selected. All your writes go to it, and it is the only chip you hear. Nothing is lost meanwhile. All three chips keep their registers, and when you switch TurboSound back on, the other two come back with whatever they held, as if they had never left the room. I find this rule a little cheeky, but I cannot fault its logic.
Let me show you the same little program three ways. It selects each chip in turn and gives it one note on channel B: C on chip 0, E on chip 1, G on chip 2.
Look at the middle one closely. I mean it: this is what your shiny TurboSound program sounds like on a Next where nobody switched TurboSound on. Its selects are ignored, every write lands in chip 0, and the three chips’ parts overwrite each other there until only the last one is left standing. The trio has become a soloist who keeps forgetting his lines. So here is my advice, and it is the most important sentence in this section: if your program wants three chips, it must switch TurboSound on itself. Never assume someone else already did.
Where the channels go
Each chip has three channels, but you have only two ears. Every chip has to decide where its A, B and C go, and the Next gives you three ways to settle the argument. It adds the channels up as it spreads them:
- ABC (what you get after power-on): left = A + B, right = C + B. A sits on the left, C on the right, and B, which both sides hear equally, in the middle.
- ACB: left = A + C, right = C + B. A on the left, B on the right, and now C is in the middle.
- Mono: both sides = A + B + C. Everybody in the middle, shoulder to shoulder.
I always remember them like this: read the name from left to right, and the middle letter is the channel in the middle. In ABC that is B; in ACB, C. Simple. And the middle seat is the best one in the house: it is where a musician puts the part that must not lean to either side, usually the bass or the melody.
Bit 5 of the Peripheral 3 Setting register, NextReg $08, chooses ACB (1) or ABC (0), for all three chips
at once. Bits 7–5 of the Peripheral 4 Setting register, NextReg $09, put chips 2, 1 and 0 in mono, each on
its own, and for a chip in mono, mono wins over ACB. What does that mean for the levels? With one chip at full
volume:
- In ABC or ACB, each side adds two channels: at most 2 × 255 = 510.
- In mono, each side adds all three: at most 3 × 255 = 765, on both sides.
Now, have you wondered why you would want a choice at all? It comes down to how a tune is mixed. Its composer had one layout in mind, and put the part that belongs in the middle on the middle channel. Play it with the other layout, and that part slides off to one side while a side part wanders into the middle. On headphones you hear it at once: a balanced tune turns lopsided, like a band whose drummer set up in the car park. Spectrum music was not all written for the same layout, so the Next offers both. And mono? That one is for the tunes written for the 128K’s single speaker. I like that the Next does not pick a winner here; it lets the tune decide.
Panning a whole chip
ABC, ACB and mono place the channels inside a chip. Panning then places the whole chip. Every chip has a 2-bit pan, and you set it with bits 6–5 of the very value that selects the chip. I think of the pan as the usher: it shows each chip of the trio to its seat, left, right, both, or out of the hall:
11: both sides (what every chip has after a reset).10: left only.01: right only.00: muted, the chip’s equivalent of being sent to its room.
The pan works on the chip’s own mix, after ABC, ACB or mono. With pan 10, the chip’s left side goes to the
mixer’s left, and its right side is dropped. Let’s try it with three chips, each playing one note on
channel B (the middle channel in ABC), with chip 0 panned left, chip 1 to both sides and chip 2 right:
Now let me warn you about one thing, because it is very easy to get wrong: every chip select sets the pan
again. The usher does not remember yesterday’s seating; he seats the chip again every time you call it by
name. Say you panned chip 1 to the left. Later you select it with $FE, out of sheer habit, and
congratulations: you have just dragged it back to the middle. From then on, you must select it with $DE
(%1101 1110: bit 6 set, bit 5 clear). Oh, and a pan you write while TurboSound is off goes nowhere. The Next
ignores it together with the select it came in. My habit is to keep each chip’s select value in one constant,
pan bits included, and never type $FE by hand again.
Nine channels in the mixer
The mixer adds the three chips’ sides into one AY input per side. How much of its range that takes depends on the layout you chose:
- Stereo (ABC or ACB), every channel of every chip at full volume: 3 × 510 = 1,530 per side.
- Mono on all three chips: 3 × 765 = 2,295 per side, the most the AY input can ever carry.
The audio jack plays sums up to 4,095, and a silent Next already sits at 1,536 (the mixer chapter’s Headroom explains why), so you have 2,559 left for everything else. Nine channels in stereo fit, with room to spare for the beeper. Three chips in mono fit on their own too. But put the beeper’s 512 on top, and the sum passes 4,095: the jack wraps around, and you hear a crackle that no musician ordered.
Should you worry about it? Honestly, I hardly ever would. Channels are seldom all at full volume, and square waves at different pitches are seldom all high at the same moment. Here is what nine channels at full volume look like, three chords on three chips:
See those rare peaks that touch the top? That is all nine square waves happening to be high at the same instant. It does happen, but only for a moment, and then the waves drift apart again.
When the chips are reset
A reset clears more than the chips’ registers. Every chip’s registers go back to their reset values (all 0,
R7 $FF), so all three fall silent; chip 0 is selected, and register 0 in it; and every pan goes back to
11, both sides. In short, the Next tidies up the room and the usher puts everyone back in the middle.
A soft reset does not touch the NextRegs, though. TurboSound’s switch, ACB and the mono bits keep whatever they
held, and only a hard reset clears them. This one is easy to miss, so let me say it plainly: if your program
relies on ABC, set the Peripheral 3 Setting register, NextReg $08, yourself rather than trusting that a
reset did it for you.
There is one more way to reset the chips. Set bits 1–0 of the Peripheral 2 Setting register, NextReg $06,
to 11, and they stay in reset for as long as the mode stays 11. They are silent, their registers are
cleared, chip 0 is selected, every pan is back to both sides, and every write you make is ignored, however hard
you insist. Choose YM or AY again, and they start afresh from there.
What programs do with nine channels
If you take only one idea about TurboSound into your own game, take this one: keep music and effects apart. Play the music on chips 0 and 1 and the sound effects on chip 2, and an explosion never cuts a note short. On a 128K, every effect had to steal a channel from the tune, and believe me, the tune always noticed.
Trackers for the Next write for all three chips at once: chords, a bass and drums of their own, and echo effects made by repeating a part quietly on another chip. Panning adds a sense of space. Put a chip playing a pad on the left and one playing an arpeggio on the right, keep the bass and the melody in the middle on channel B in ABC, and suddenly a little 8-bit machine sounds like a room full of musicians. That, to my ear, is when the trio earns its name.
And sometimes, well, the best thing to do with TurboSound is nothing at all. Leave it off, pick ABC or ACB to match the tune, and a 128K program plays on chip 0 just as its composer mixed it.
What to take home
Three chips on two ports, then, and not a single new port needed. TurboSound puts the trio behind the 128K’s
ports $FFFD and $BFFD, and only the selected chip answers. A register select always has bits 7–5 clear,
so the Next uses values that look like %1 pp 111 cc to pick a chip instead: cc names the chip (11, 10
and 01 for chips 0, 1 and 2) and pp sets its pan. Written with both pan bits, they are $FF, $FE and
$FD.
Bit 1 of NextReg $08 switches TurboSound on. While it is off, as after power-on, only the selected chip sounds
and the selection is frozen, which puts every 128K program on chip 0 without it ever knowing.
Each chip spreads its channels in ABC (left A + B, right C + B) or ACB (left A + C, right C + B), chosen
by bit 5 of NextReg $08 for all chips, or in mono (A + B + C on both sides), chosen per chip by bits 7–5 of
NextReg $09. The pan, the usher, set again by every select, then lets the chip into the left, the right, both
or neither. Per side, the three chips add at most 1,530 in stereo and 2,295 in mono, comfortably inside
the jack’s 2,559 of room above silence.
A reset, or mode 11 in NextReg $06, clears the chips, selects chip 0 and puts every pan back in the middle;
a soft reset leaves the NextReg settings alone. Switch TurboSound on yourself, keep your select values in
constants, and the rest is up to your music.