loose pages / hardware / unfinished business
DEVLOG
the machine was already there.
001 / HARDWARE NOTES
GAYBOY SEQUENCER: This is not another chiptune tracker
Filling wave RAM with good intentions four bytes at a time. There are sixteen bytes available. This should be enough room for a bass sound and whatever is wrong with me.
The table begins at $FF30. Two samples per byte, upper nibble first in memory. I've written that down because the first sample fetched after a trigger is the lower nibble. The upper one waits until the waveform loops. Memory order and playback order have already stopped speaking.
There is also the old sample in the output buffer. Trigger doesn't replace it. It stays there until the next fetch. The previous note has left something in the apartment.
When the bass hits at C1 on the wave channel my entire butthole fell out
Enough about the interface. On monochrome Game Boy hardware, retriggering CH3 while it fetches a wave byte can corrupt the start of the table. This part is documented. A fetch from one of the first four bytes can replace byte zero with the fetched byte. Later fetches can copy an aligned group of four into the first four bytes. Byte nine brings eight through eleven.
Love is tearing us apart again. Four bytes at a time. The bass has retained most of its personality, which makes it harder to explain why it suddenly sounds like it has been chewing foil.
In the reference notes: deactivate through NR30 before the update and restart. No active retrigger, no collision of that kind. There is still a DAC transition and a restarted waveform. The data can survive while the sound suffers. This distinction has consumed an unreasonable amount of paper. [CH3 buffer and DMG retrigger corruption]
It will only accept apologies printed on thermal receipts. By the time the cops come to inspect the evidence, the evidence will be blank.
NR30 / NR34 / previous sample / first fetch / WHY
A new waveform doesn't necessarily begin with a new output sample. This is the thing I keep trying to forget. Every nice clean diagram starts at time zero. The machine was already doing something before time zero. The diagram has never had a previous tenant.
I would like to speak to whoever owns $FF3F
During active playback, the wave channel owns the memory selection. The CPU supplies an address, but that doesn't mean the addressed byte is the byte it gets. On DMG, access is additionally restricted to the channel's fetch window; otherwise reads return $FF and writes are ignored. On CGB, active accesses follow the byte CH3 is reading. Advance compatibility hardware rejects active writes and returns $FF for reads.
Sixteen bytes. Three rejection policies. The same song can be refused for different administrative reasons depending on which Game Boy receives the application.
“Stream speech through the wave channel.” It's written here with the confidence of a person who has not reached the next page. The next page contains the access rules. After that, the handwriting changes.
There are fetch-timed tricks, but the target hardware and the timing are part of the trick. A loop writing sixteen consecutive addresses is just a loop writing sixteen consecutive addresses. While CH3 is active, that description says remarkably little about where the data ends up. [active access rules; executable tests linked in Pan Docs]
NR32 doesn't help in the way a volume fader ought to. Half and quarter output right-shift the digital samples. That moves their bias as well as reducing their excursion. The analog high-pass filter settles afterward. Turning something down can produce a transient. The apology printer has started feeding paper before I've finished the sentence.
Tampering with evidence
A raster split can be stable until sprites enter the line. Nothing mysterious in the code. The display's pixel transfer takes longer.
456 dots per scanline. OAM search takes 80. Pixel transfer takes between 172 and 289. HBlank receives the remainder. A budget written against the empty scene is a budget written against an absent witness.
At the beginning of transfer, fine scroll costs SCX modulo eight dots. Window startup costs six. Each fetched object adds six to eleven, depending on fetch alignment. Transparent pixels don't remove that work. OAM X=0 has its own eleven-dot penalty. Even the sprite standing entirely off the left edge has found a way to expense the trip.
There are the familiar effects: a different horizontal scroll for successive bands, hills apparently moving behind a foreground, water pulling itself sideways. Then there is the actual schedule underneath them. The register write is waiting for its moment while a sprite fetch takes the moment apart.
On DMG, a mid-line BGP write can expose the delays through where the palette boundary appears. A changed shade marks the disturbance. Very considerate. The sound hardware turns your ears against you. [pixel-transfer stalls and object penalties]
SCX 0…7 / window / objects / worst line, not prettiest line
This is also where the notes about tile reuse stop being nostalgic. A reused pattern is less data to move. Replacing a pattern animates every map reference to it. A conveyor belt, water, a machine apparently working. The machine on screen has no maintenance department. I envy it.
Two bitplanes, one custody hearing
Before CGB-D, vertical scroll is sampled separately for the two bitplanes in a tile fetch. An SCY change placed between those reads can supply different rows to the two planes. Bits from one row combine with bits from another. The resulting pixel values belong to neither parent.
This is a real fetcher exploit. CGB-D and later use the same Y coordinate for both planes, so the effect doesn't carry over. The label “Game Boy Color” has failed to disclose a relevant change in domestic arrangements.
SCX has another split personality: its low three bits are latched at scanline start, while the scrolling registers otherwise get sampled during tile fetches. A write has a time, and each part of the display has a different occasion to notice it. There isn't one universal instant when the whole screen agrees that the register changed. [scroll sampling and the CGB-D revision boundary]
1000 → 1500 → dead
Back to CH1. Sweep keeps a shadow copy of the period. A direct NR13/NR14 pitch write doesn't update that copy. Next sweep step can replace the live pitch with a result derived from the old shadow. The software slide has been arguing with a memory of itself.
Increasing sweep, shift one, period 1000. The step reaches 1500. Then the prospective overflow calculation reaches 2250, beyond 2047, and disables the channel. The current value was legal. The future value wasn't even going to be written yet.
I would have blamed the envelope. That's the dangerous part. Tight lips don't name the subsystem that owns them.
There is a trigger-time overflow check when the shift is nonzero. There is also the direction-bit trap: switching from subtraction to addition after a subtraction calculation has happened can disable CH1. All the little arrows in the instrument editor look so agreeable. [sweep shadow state, overflow checks, direction change]
The pulse duty position survives retrigger too. The timer resets; position doesn't. Its timer's low two bits even survive the trigger. Retrigger often enough and the duty step never gets to advance. My proposed cure for a stale attack has immobilised the patient.
Period writes without the trigger bit. A new pitch, no new attack. This distinction belongs somewhere obvious. Instead it's here, between the imaginary printer requisition and the list of things sweep can kill.
The graphics code denies knowing the envelope
DIV reset. Relevant bit was high. Falling edge supplied to the APU sequencer. Visible DIV bit four at normal speed, bit five in CGB double speed.
Envelopes normally clock at 64 Hz, lengths at 256, sweep at 128. Those rates assume the divider is allowed to proceed normally. An extra edge advances the sequence, with the consequences depending on its step. Resetting a timer can reach the sound through a register nobody filed under sound.
The initial suspicion was the song data. On paper, anyway. These are documented failure mechanisms, not a report that all of them happened in one miraculous disaster. I have enough ordinary disasters without fabricating measurements. [divider-derived APU timing]
OAM DMA belongs in this pile. 160 M-cycles. On DMG the CPU can access only HRAM during the transfer; the wait routine lives there. Interrupt entry wants a stack and handler, which is inconvenient when the bus is otherwise occupied. A musical event due in the gap remains due.
Mid-frame OAM replacement can put one set of objects above another, exceeding forty across the frame without changing the ten-per-line limit. It spends lines on missing objects while the PPU loses normal OAM access; starting during pixel transfer can corrupt object fetches. The extra sprites arrive with damage and a scheduling conflict. [DMA duration, bus restrictions, mid-frame transfers]
I'm trying to keep the deadline on the same page as the effect. The page is full. There is room on the back of a receipt.
What remains legible: hardware revision, divider phase, write order, previous state. SameSuite has small tests for several of these behaviors. SameBoy is the emulator reference for listening and timing here; hardware decides whether the result survives outside the explanation. None of this gets resolved by a screenshot of a perfectly behaving menu.
The project attached to these notes is GAYBOY, a Game Boy music workstation. The printer is still a proposed purchase.