org.razvan.jzx
Class Clock

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

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.

Author:
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:
BaseSpectrum.emulate()

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
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
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

interrupted

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

Clock

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

Method Detail

getFrequency

public long getFrequency()
Get the clock frequency.

Returns:
The clock frequency (in milliseconds).

setFrequency

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

Parameters:
frequency - The clock frequency (in milliseconds).

run

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

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

end

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