2006-01-12 11:20:41 +00:00
/ * $ Id $ * /
2005-07-24 21:47:42 +01:00
# include < AppKit / AppKit . h >
2006-03-02 21:43:09 +00:00
# include < mach / mach . h >
# include < mach / mach_host . h >
# include < mach / host_info . h >
# include < mach / machine . h >
# include < stdio . h >
# include "../../stdafx.h"
# include "../../openttd.h"
# include "../../newgrf.h"
# include "../../gfx.h"
# ifndef CPU_SUBTYPE _POWERPC _970
# define CPU_SUBTYPE _POWERPC _970 ( ( cpu_subtype _t ) 100 )
# endif
2005-07-24 21:47:42 +01:00
/ *
* This file contains objective C
* Apple uses objective C instead of plain C to interact with OS specific / native functions
*
* Note : TrueLight ' s crosscompiler can handle this , but it likely needs a manual modification for each change in this file .
* To insure that the crosscompiler still works , let him try any changes before they are committed
* /
2006-03-02 21:43:09 +00:00
static char * GetOSString ( void )
{
static char buffer [ 175 ] ;
char CPU [ 20 ] ;
char OS [ 20 ] ;
char newgrf [ 125 ] ;
long sysVersion ;
extern const char _openttd _revision [ ] ;
// get the hardware info
host_basic _info _data _t hostInfo ;
mach_msg _type _number _t infoCount ;
infoCount = HOST_BASIC _INFO _COUNT ;
host_info ( mach_host _self ( ) , HOST_BASIC _INFO ,
( host_info _t ) & hostInfo , & infoCount ) ;
// replace the hardware info with strings , that tells a bit more than just an int
# ifdef __POWERPC __
switch ( hostInfo . cpu_subtype ) {
case CPU_SUBTYPE _POWERPC _750 :
sprintf ( CPU , "G3" ) ;
break ;
case CPU_SUBTYPE _POWERPC _7400 :
case CPU_SUBTYPE _POWERPC _7450 :
sprintf ( CPU , "G4" ) ;
break ;
case CPU_SUBTYPE _POWERPC _970 :
sprintf ( CPU , "G5" ) ;
break ;
default :
sprintf ( CPU , "Unknown PPC" ) ;
}
# else
// it looks odd to have a switch for two cases , but it leaves room for easy expansion . Odds are that Apple will some day use newer CPUs than i686
switch ( hostInfo . cpu_subtype ) {
case CPU_SUBTYPE _PENTPRO :
sprintf ( CPU , "i686" ) ;
break ;
default :
sprintf ( CPU , "Unknown Intel" ) ;
}
# endif
// get the version of OSX
if ( Gestalt ( gestaltSystemVersion , & sysVersion ) ! = noErr ) {
sprintf ( OS , "Undetected" ) ;
} else {
int majorHiNib , majorLoNib , minorNib , bugNib ;
majorHiNib = ( sysVersion & 0 x0000F000 ) > > 12 ;
majorLoNib = ( sysVersion & 0 x00000F00 ) > > 8 ;
minorNib = ( sysVersion & 0 x000000F0 ) > > 4 ;
bugNib = sysVersion & 0 x0000000F ;
sprintf ( OS , "%d%d.%d.%d" , majorHiNib , majorLoNib , minorNib , bugNib ) ;
}
// make a list of used newgrf files
if ( _first _grffile ! = NULL ) {
GRFFile * file ;
newgrf [ 0 ] = 0 ;
for ( file = _first _grffile ; file ! = NULL ; file = file -> next ) {
sprintf ( newgrf , "%s %s" , newgrf , file -> filename ) ;
}
} else {
sprintf ( newgrf , "none" ) ;
}
sprintf ( buffer , "Please add this info: (tip: copy-paste works)\nCPU: %s, OSX: %s, OpenTTD version: %s\nNewGRF files:%s" , CPU , OS , _openttd _revision , newgrf ) ;
return buffer ;
}
2006-01-06 21:27:44 +00:00
# ifdef WITH_SDL
2005-07-24 21:47:42 +01:00
void ShowMacDialog ( const char * title , const char * message , const char * buttonLabel )
{
NSRunAlertPanel ( [ NSString stringWithCString : title ] , [ NSString stringWithCString : message ] , [ NSString stringWithCString : buttonLabel ] , nil , nil ) ;
}
2006-01-06 21:27:44 +00:00
# elif defined WITH_COCOA
void CocoaDialog ( const char * title , const char * message , const char * buttonLabel ) ;
void ShowMacDialog ( const char * title , const char * message , const char * buttonLabel )
{
CocoaDialog ( title , message , buttonLabel ) ;
}
# else
void ShowMacDialog ( const char * title , const char * message , const char * buttonLabel )
{
fprintf ( stderr , "%s: %s\n" , title , message ) ;
}
# endif
2005-07-28 22:47:41 +01:00
void ShowMacAssertDialog ( const char * function , const char * file , const int line , const char * expression )
{
2005-12-10 11:16:45 +00:00
const char * buffer =
2006-03-02 21:43:09 +00:00
[ [ NSString stringWithFormat : @ "An assertion has failed and OpenTTD must quit.\n%s in %s (line %d)\n\" % s \ "\n\nYou should report this error the OpenTTD developers if you think you found a bug.\n\n%s" ,
function , file , line , expression , GetOSString ( ) ] cString ] ;
2005-07-28 22:47:41 +01:00
NSLog ( @ "%s" , buffer ) ;
2006-03-02 21:43:09 +00:00
ToggleFullScreen ( 0 ) ;
2005-07-28 22:47:41 +01:00
ShowMacDialog ( "Assertion Failed" , buffer , "Quit" ) ;
2005-12-10 11:16:45 +00:00
2005-07-28 22:47:41 +01:00
// abort so that a debugger has a chance to notice
abort ( ) ;
}
2006-03-02 21:43:09 +00:00
void ShowMacErrorDialog ( const char * error )
{
const char * buffer =
[ [ NSString stringWithFormat : @ "Please update to the newest version of OpenTTD\nIf the problem presists, please report this to\nhttp://bugs.openttd.org\n\n%s" , GetOSString ( ) ] cString ] ;
ToggleFullScreen ( 0 ) ;
ShowMacDialog ( error , buffer , "Quit" ) ;
abort ( ) ;
}