Class Clock

  extended by java.lang.Thread
      extended by org.razvan.jzx.Clock
All Implemented Interfaces:

public class Clock
extends java.lang.Thread

Spectrum interrupt clock which is used for generating the 20ms interrupt on which the screen frames are synchronized.

The Spectrum clock is integral to emulating the Spectrum at a speed that resembles that of the original machine. Specifically, the main loop decodes and executes instructions at the full speed of the host machine. As each instruction is decoded, a virtual T-State counter is incremented, and whenever the virtual T-States add up to what should be one screen frame, the emulation loop simply blocks on the Clock thread until an interrupt is generated. The Clock thereby ensures that although the instructions are decoded much faster than in the original machine, the screen frames, and thus the CPU interrupts are produced at the same rate as the original hardware.

Razvan Surdulescu (c) 2001 - 2006
You may use and distribute this software for free provided you include this copyright notice. You may not sell this software, use my name for publicity reasons or modify the code without permission from me.
See Also:

Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
Field Summary
 boolean interrupted
          This is set to true, and notifyAll() is called whenever an interrupt has been generated.
Fields inherited from class java.lang.Thread
Constructor Summary
Clock(long frequency, ILogger logger)
          Create the Clock thread and mark it as daemon.
Method Summary
 void end()
          Stops the Clock thread and causes it to exit (asynchronous.)
 long getFrequency()
          Get the clock frequency.
 void run()
          Generate interrupts every specified number of milliseconds.
 void setFrequency(long frequency)
          Set the clock frequency.
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


public volatile boolean interrupted
This is set to true, and notifyAll() is called whenever an interrupt has been generated.

Whomever is listening for the notifyAll() call is responsible for setting the interrupted flag back to false.

Constructor Detail


public Clock(long frequency,
             ILogger logger)
Create the Clock thread and mark it as daemon.

Method Detail


public long getFrequency()
Get the clock frequency.

The clock frequency (in milliseconds).


public void setFrequency(long frequency)
Set the clock frequency.

frequency - The clock frequency (in milliseconds).


public void run()
Generate interrupts every specified number of milliseconds.

Specified by:
run in interface java.lang.Runnable
run in class java.lang.Thread


public void end()
Stops the Clock thread and causes it to exit (asynchronous.)