Counting T states in Excel

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
arkannoyed
Manic Miner
Posts: 438
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: Counting T states in Excel

Post by arkannoyed »

I seem to recall an ancient thread on WOS many years ago, where a useful utility that went by the name of 'Ticks' or something similar could be used to give accurate T-state timings for a piece of assembly code. Googling it though, I can't find it now.
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Counting T states in Excel

Post by djnzx48 »

Is this it? ticks.0.15.zip
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Counting T states in Excel

Post by Ast A. Moore »

djnzx48 wrote: Tue May 21, 2019 9:21 am I'm pretty sure it would be possible. Since the machine behaviour is deterministic, you could just have another emulation running ahead of the main one that remembers the instruction timings.
Generally, true. The problem is mostly with branching and conditionals.

Most debuggers display the current number of T states elapsed since the beginning of the frame, anyway. Most of the time, that’s enough. If I optimize my routines, I simply put the number of T states for each instruction in square brackets in the code’s commentary and calculate them manually. However, I still mostly use my gut feeling and experience for optimization. Seems to work best.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
arkannoyed
Manic Miner
Posts: 438
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: Counting T states in Excel

Post by arkannoyed »

djnzx48 wrote: Tue May 21, 2019 10:52 am Is this it? ticks.0.15.zip
Thats the one, though I've not much of in idea for how to use it though?
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Counting T states in Excel

Post by djnzx48 »

OK, I just found some basic instructions here:
https://github.com/z88dk/z88dk/wiki/Tool---ticks

Edit: I just read that apparently ticks does not support contention. So it may not be the best choice for accurate measurements.
User avatar
arkannoyed
Manic Miner
Posts: 438
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: Counting T states in Excel

Post by arkannoyed »

Ah yes, good find, those might help
AndyC
Dynamite Dan
Posts: 1407
Joined: Mon Nov 13, 2017 5:12 am

Re: Counting T states in Excel

Post by AndyC »

Contention makes things harder on the Speccy because it isn't just about what instruction you are executing, but when you are executing it. The same instruction within a loop might not always take the same length of time. I can't say I've ever entirely got my head around the various descriptions of it.

Contrast this with say the Amstrad CPC where contention is universally applied and highly predictable, then it is really just a case of having a slightly different list of instruction timings to check against.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Counting T states in Excel

Post by RMartins »

The Zero emulator has an interesting trace feature (but it does make the emulator a bit slower), which allows you to track the instructions that are executing, while keeping a log of them.

This has proven useful to check timings of loop code, since you can check the T-State count, on start, during stepping and on exit.
Post Reply