package com.mindprod.pentium;

/**
 * Access Pentium/AMD specific features.
 * Uses JNI native C++/ASM code that only works on
 * XP, Windows 2000, Windows NT and Windows 98.
 *
 * Must generate pentium.h after compiling Pentium.java with
 * javah.exe -jni -o pentium.h com.mindprod.pentium.Pentium
 * NOT javah.exe Pentium
 *
 * @author Roedy Green
 * @version 1.0
 */
public class Pentium
   {

   /**
   * Get the vendor ID of the CPU.
   *
   * @return vendor, "GenuineIntel" for Intel chips, "AuthenticAMD" for AMD.
   */
   public static native String cpuIdVendor();

   /*
    * Get the brand/model of the CPU.
    *
    * @return brand, e.g. "AMD Athlon(TM) XP 2000+"
    */
   public static native String cpuIdBrand();

   /**
    * Get the stepping ID of the CPU.
    *
    * @return stepping ID.
    */
   public static native int cpuIdStep();

   /**
    * Get the model of the CPU.
    *
    * @return model, possibly null if not Pentium.
    */
   public static native int cpuIdModel();

   /**
    * Get the instruction set family of the CPU.
    *
    * @return family, possibly null if not Pentium.
    */
   public static native int cpuIdFamily();

   /**
    * Get the cpu Serial number
    *
    * @return family, possibly 0 if not Pentium.
    */
   public static native long cpuSerNo();

   /**
    * Get the time stamp counter register with the RDTSC instruction
    * giving the count of machine cycles since last boot.
    * This is very high resolution timer, with frequency matching the cpu
    * clock crystal, not any defined time unit.
    *
    * @return RDTSC Timestamp counter.
    */
   public static native long rdtsc();

   static {
      // get DLL loaded from somewhere on java.library path.
      System.loadLibrary( "nativepentium" );
      // if have troubles change this code to use load( "C:\\com\\mindprod\\pentium\\nativepentium.dll" );
   }

   /**
    * test harness
    *
    * @param args not used
    */
   public static void main ( String[] args )
      {
      out.println( "cpuIdVendor:" + cpuIdVendor() );
      out.println( "cpuIdBrand:" + cpuIdBrand() );
      out.println( "cpuIdStep:" + cpuIdStep() );
      out.println( "cpuIdModel:" + cpuIdModel() );
      out.println( "cpuIdFamily:" + cpuIdModel() );
      out.println( "cpuSerNo:" + Pentium.cpuSerNo() );
      out.println( "rdtsc:" + Pentium.rdtsc() );
      }
   }