/*
 Access Pentium/AMD specific features, e.g. RDTSC, CPUSERNO

copyright (c) 2005-2008 Roedy Green, Canadian Mind Products
may be copied and used freely for any purpose but military.

Roedy Green
Canadian Mind Products
#101 - 2536 Wark Street
Victoria, BC Canada
V8T 4G8
tel: (250) 361-9093
roedy g at mindprod dotcom
http://mindprod.com

version History

1.1 2005-07-30 - ANT build, consistent naming.
1.2 2006-03-06 - reformat with IntelliJ, add Javadoc.
1.3 2007-06-03 - add pad and icon
*/
package com.mindprod.pentium;

/**
 * Access Pentium/AMD specific features. Uses JNI native C++/ASM code that only works on Vista, XP, Windows 2000,
 * Windows NT and Windows 98.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.3 2007-06-03
 */
public final class Pentium
    {
// ------------------------------ FIELDS ------------------------------

    /**
     * undisplayed copyright notice
     */
    public static final String EMBEDDED_COPYRIGHT =
            "copyright (c) 2005-2008 Roedy Green, Canadian Mind Products, http://mindprod.com";

    private static final String RELEASE_DATE = "2007-06-03";

    /**
     * embedded version string.
     */
    public static final String VERSION_STRING = "1.3";
// -------------------------- PUBLIC STATIC METHODS --------------------------

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

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

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

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

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

    /**
     * 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 METHODS --------------------------

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

// --------------------------- main() method ---------------------------

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