# G5_detector.cpp

Go to the documentation of this file.

    00001 /* $Id: G5_detector.cpp 17248 2009-08-21 20:21:05Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include <mach/mach.h>
    00013 #include <mach/mach_host.h>
    00014 #include <mach/host_info.h>
    00015 #include <mach/machine.h>
    00016 #include <stdio.h>
    00017
    00018
    00019 #ifndef CPU_SUBTYPE_POWERPC_970
    00020 #define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
    00021 #endif
    00022
    00023 /* this function is a lightly modified version of some code from Apple's developer homepage to detect G5 CPUs at runtime */
    00024 main()
    00025 {
    00026   host_basic_info_data_t hostInfo;
    00027   mach_msg_type_number_t infoCount;
    00028   boolean_t is_G5;
    00029
    00030   infoCount = HOST_BASIC_INFO_COUNT;
    00031   host_info(mach_host_self(), HOST_BASIC_INFO,
    00032         (host_info_t)&hostInfo, &infoCount);
    00033
    00034    is_G5 = ((hostInfo.cpu_type == CPU_TYPE_POWERPC) &&
    00035       (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970));
    00036    if (is_G5)
    00037      printf("1");
    00038 }