"""Countdown of a periodic timer and a one-shot timer.

Not a CPU. Initial count 8. Each step is one tick after the divide.
Periodic reloads 8 when the count hits 0. One-shot stays at 0.
"""


def run(mode: str, initial: int = 8, steps: int = 12) -> None:
    current = initial
    print(mode)
    for step in range(1, steps + 1):
        irq = False
        if current > 0:
            current -= 1
        if current == 0:
            irq = True
            if mode == "periodic":
                current = initial
            else:
                irq = step == initial
        print(f"  step={step} current={current} irq={irq}")


if __name__ == "__main__":
    run("periodic")
    run("oneshot", steps=11)
