Table of Contents        Previous topic       Next topic       

Cycle Interval and Timeout Counting

The jState.Core object supports the setInterval() and setTimeout() functions.  These can be used to set events on a count of the number of simulated machine cycles.

Both functions take two parameters.  The first parameter is the name of the Javascript function that will handle the event. The second parameter is the number of simulated machine cycles that should elapse before the event is generated.

Note that the simulator is not 100% cycle accurate and so the cycle count only approximates the cycle count of the real chip

Both functions return a handle which can be used to cancel the event.  These functions are clearInterval() and clearTimeout().

Examples of the use of these functions are shown below:

var interval = function(event) {
         // add your javascript code here:
var hInterval = jState.core.setInterval(interval, 500);


var timeout = function(event) {
      // add your javascript code here:
var hTimeout = jState.core.setTimeout(timeout, 500);


For both the setInterval() and setTimeout() functions, the event parameter object will contain the following properties:

event.machinecycles contains the cycle count from the start of simulation

event.tripcounter contains the cycle count since the trip counter was reset

event.lastcommandcounter contains the cycle count since the last simulation command was issued

The jState code creation wizard for the Core object is able to generate the setInterval () and setTimeout() calls and outline handler functions.