4

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).

hippietrail
  • 6,646
  • 2
  • 21
  • 60
Fandango68
  • 225
  • 2
  • 6
  • Related question: https://retrocomputing.stackexchange.com/questions/5052/what-are-tacts-in-the-context-of-zx-spectrum-systems/ – lvd Nov 21 '19 at 20:12

2 Answers2

6

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).

Tommy
  • 36,843
  • 2
  • 124
  • 171
  • Ahh, Thanks. So where/how did the 224 T states come from? – Fandango68 Nov 21 '19 at 05:43
  • 1
    @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 08:33
  • 1
    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 https://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 https://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
  • 2
    @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
  • @Tommy, sorry I phrased it too strongly. I meant that reference to 224 t-states per line and then working out the details for 128K machine is impossible to do consistently. It should be 50.02Hz not 50.01. It should be 3.5469, not 3.546. I know it is not particularly relevant, but wanted to provide precise numbers for it all to make sense. – introspec Nov 21 '19 at 15:53
  • @introspec right, I mean, I was wrong about the 3.58Mhz clock (that's the NTSC colour subcarrier frequency, which obviously has wormed its way into my muscle memory), so the comment helped to improve the answer. Thanks! – Tommy Nov 21 '19 at 17:02
  • Maybe I should have mentioned I am in Australia, under the PAL not NTSC system? – Fandango68 Nov 22 '19 at 00:22
  • 1
    @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 04:08
2

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.

Martin Maly
  • 5,535
  • 18
  • 45