# ZX Spectrum: What is the “T” state value, with reference to sound?

I have that awesome book - Zx Spectrum ROM Disassembled (correct the title if I got it wrong), where the author wrote about the audio code in the ROM and referring to "T" state, "... T200... T5000, etc". What is this?

UPDATE In reference to 48K Spectrum, in Australia under the 50Mhz spectrum (PAL).

In the Spectrum lexicon, a t-state is just a "time state" — a single cycle of the ~3.5Mhz clock.

For implied evidence of that, see e.g. this document of 128K ZX Spectrum Technical Information, which states

... there are 70908 T states per frame, and the '50 Hz' interrupt occurs at 50.01 Hz.

70908 t-states per frame * 50.01 Hz = 3.546 million t-states per second. Which is the clock rate of the processor (slightly rounded, because the 50.01 is slightly rounded).

• Ahh, Thanks. So where/how did the 224 T states come from? – Fandango68 Nov 21 '19 at 5:43
• @Fandango68 from TV signal timing and screen resolution ... you know screen is outputed 50Hz so a frame is 20ms but not whole time is the screen rendering there are blank and sync times in it too ... so if you take just single line of TV signal its just fraction of the 20ms and precomputed to CPU clock equal to 224T ... btw take a look at What are tacts in the context of ZX Spectrum systems? – Spektre Nov 21 '19 at 8:33
• There are several mistakes here, which make details inconsistent. A single line of output takes 224 t-states on 48K ZX Spectrum, but 228 t-states on 128K ZX Spectrum models. 48K ZX Spectrum has Z80 clocked at precisely 3.5MHz (see faqwiki.zxnet.co.uk/wiki/ZX_Spectrum_16K/48K), so it has line frequency 3500000/224=15625Hz and, with 312 lines per frame, frame frequency 50.08Hz. 128K ZX Spectrum models have Z80 clocked at 3.5469MHz (see faqwiki.zxnet.co.uk/wiki/ZX_Spectrum_128), so its line and frame frequencies are 3546900/228~15556.6Hz and, with 311 lines per frame, 50.02Hz. – introspec Nov 21 '19 at 11:57
• @introspec from that I count exactly one mistake — citing a 3.58Mhz clock. I’ve taken out the 48kb example as it was more straightforward to do so than to add a more explicit “this document about the 128kb, which is slightly different”. But even as originally written the answer made no further mistakes. – Tommy Nov 21 '19 at 13:04
• @Fandango68 oh, no, sorry — the NTSC number is why I originally typed 3.58Mhz, which is not the correct clock rate for a Spectrum. I've no idea what Timex did in NTSC world, the answer is entirely about the Spectrum's native PAL timings. – Tommy Nov 22 '19 at 4:08

The mysterious "T" is CPU clock tick, as mentioned above, and it figures as a "non-dividable time quantum" on this computer. When you need to do something with perfect timing (e.g. audio generation), you had to compute how much ticks your routine takes (each instruction takes a known amount of T). It is very painful, but because ZX Spectrum has no HW timers, there was no other way.

ZX Spectrum's BEEP is a quite simple "square wave generator". At first, it computes how much Ts (= CPU clock ticks) it will need per one wave cycle, then repeat: toggle EAR output between 0 and 1 and wait for a given number of Ts.