package nxm.train.prim;

import nxm.sys.inc.*;
import nxm.sys.lib.*;

/** This primitive counts. */
public class counter extends Primitive {
  private int count; // Current count
  private int end;   // The ending count
  
  public int open() {
    count = MA.getL("START");
    end   = MA.getL("END");
    
    M.info("Counting from "+count+" to "+end);
    return NORMAL;
  }
  
  public int process() {
    if (count <= end) {
      M.info("Count is at "+count);
      count++;
    }
    return (count <= end)? NORMAL: FINISH;
  }

  public int close() {
    M.info("Done counting");
    return NORMAL;
  }
}
