diff options
-rw-r--r-- | functions.h | 4 | ||||
-rw-r--r-- | graph_gui.c | 6 | ||||
-rw-r--r-- | map.c | 5 | ||||
-rw-r--r-- | minilzo.c | 7 | ||||
-rw-r--r-- | network_core.h | 4 | ||||
-rw-r--r-- | openttd.vcproj | 3 | ||||
-rw-r--r-- | saveload.c | 4 | ||||
-rw-r--r-- | stdafx.h | 13 | ||||
-rw-r--r-- | strgen/strgen.c | 4 | ||||
-rw-r--r-- | train_cmd.c | 10 | ||||
-rw-r--r-- | viewport.c | 2 | ||||
-rw-r--r-- | win32.c | 72 | ||||
-rw-r--r-- | win64.asm | 17 |
13 files changed, 127 insertions, 24 deletions
diff --git a/functions.h b/functions.h index 52abb297b..d5fcd6c50 100644 --- a/functions.h +++ b/functions.h @@ -131,8 +131,8 @@ uint InteractiveRandomRange(uint max); // Used for profiling -#define TIC() { extern uint32 rdtsc(void); uint32 _xxx_ = rdtsc(); static float __avg__; -#define TOC(s) _xxx_ = rdtsc() - _xxx_; __avg__=__avg__*0.99+_xxx_*0.01; printf("%s: %8d %f\n", s, _xxx_,__avg__); } +#define TIC() { extern uint32 _rdtsc(void); uint32 _xxx_ = _rdtsc(); static float __avg__; +#define TOC(s) _xxx_ = _rdtsc() - _xxx_; __avg__=__avg__*0.99+_xxx_*0.01; printf("%s: %8d %f\n", s, _xxx_,__avg__); } void SetDate(uint date); diff --git a/graph_gui.c b/graph_gui.c index e861de2a7..cedca5f46 100644 --- a/graph_gui.c +++ b/graph_gui.c @@ -824,10 +824,10 @@ static int CDECL _perf_hist_comp(const void *elem1, const void *elem2 ) { static void CompanyLeagueWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: { const Player* p; - const Player* plist[MAX_PLAYERS]; + Player const *plist[MAX_PLAYERS]; uint pl_num; uint i; @@ -840,7 +840,7 @@ static void CompanyLeagueWndProc(Window *w, WindowEvent *e) } assert(pl_num > 0); - qsort(plist, pl_num, sizeof(Player*), _perf_hist_comp); + qsort((void*)plist, pl_num, sizeof(Player*), _perf_hist_comp); i = 0; do { @@ -7,6 +7,11 @@ #include "macros.h" #include "map.h" +#if defined(_MSC_VER) && _MSC_VER >= 1400 /* VStudio 2005 is stupid! */ +/* Why the hell is that not in all MSVC headers?? */ +_CRTIMP void __cdecl _assert(void *, void *, unsigned); +#endif + uint _map_log_x; uint _map_size_x; uint _map_size_y; @@ -329,6 +329,13 @@ extern "C" { # endif #endif #if !defined(__LZO_HAVE_PTR_T) +# if defined(_WIN64) + typedef unsigned __int64 lzo_ptr_t; + typedef signed __int64 lzo_sptr_r; +# define __LZO_HAVE_PTR_T +# endif +#endif +#if !defined(__LZO_HAVE_PTR_T) # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_LONG) # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG) typedef unsigned long lzo_ptr_t; diff --git a/network_core.h b/network_core.h index cb4df4a1f..855e5f2c3 100644 --- a/network_core.h +++ b/network_core.h @@ -12,10 +12,10 @@ #ifdef ENABLE_NETWORK // Windows stuff -#if defined(WIN32) -#include <windows.h> +#if defined(WIN32) || defined(WIN64) #include <winsock2.h> #include <ws2tcpip.h> +#include <windows.h> #if !(defined(__MINGW32__) || defined(__CYGWIN__)) // Windows has some different names for some types.. diff --git a/openttd.vcproj b/openttd.vcproj index 96f40d01d..fe500fa71 100644 --- a/openttd.vcproj +++ b/openttd.vcproj @@ -826,6 +826,9 @@ <File RelativePath=".\ai\default\default.c"> </File> + <File + RelativePath=".\ai\default\default.h"> + </File> <Filter Name="trolly" Filter=""> diff --git a/saveload.c b/saveload.c index 5e5ff00a7..70d77eabc 100644 --- a/saveload.c +++ b/saveload.c @@ -958,7 +958,9 @@ static void WriteMem(uint size) // This is needed to zlib uses the stdcall calling convention on visual studio #ifdef _MSC_VER -#define ZLIB_WINAPI +# ifndef ZLIB_WINAPI +# define ZLIB_WINAPI +# endif #endif #include <zlib.h> @@ -121,14 +121,25 @@ # define NOT_REACHED() _assume(0) # endif int CDECL snprintf(char *str, size_t size, const char *format, ...); +#if _MSC_VER < 1400 int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap); +#endif # undef TTD_ALIGNMENT_4 # undef TTD_ALIGNMENT_2 # define GCC_PACK #endif +// Needed for old PlatformSDK versions (e.g. VC6) +#if defined(WIN32) && !defined(_WIN64) && !defined(WIN64) +# ifndef _W64 +# define _W64 +# endif +typedef _W64 int INT_PTR, *PINT_PTR; +typedef _W64 unsigned int UINT_PTR, *PUINT_PTR; +#endif + // Windows has always LITTLE_ENDIAN -#if defined(WIN32) || defined(__OS2__) +#if defined(WIN32) || defined(__OS2__) || defined(WIN64) #define TTD_LITTLE_ENDIAN #else // Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile diff --git a/strgen/strgen.c b/strgen/strgen.c index b6f6717b0..431077979 100644 --- a/strgen/strgen.c +++ b/strgen/strgen.c @@ -8,7 +8,7 @@ #include <stdlib.h> #include <stdarg.h> -#if !defined(WIN32) || defined(__CYGWIN__) +#if (!defined(WIN32) && !defined(WIN64)) || defined(__CYGWIN__) #include <unistd.h> #endif @@ -996,7 +996,7 @@ static void WriteStringsH(const char *filename) unlink("tmp.xxx"); } else { // else rename tmp.xxx into filename -#if defined(WIN32) +#if defined(WIN32) || defined(WIN64) unlink(filename); #endif if (rename("tmp.xxx", filename) == -1) Fatal("rename() failed"); diff --git a/train_cmd.c b/train_cmd.c index 606dde670..d418469a6 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -1943,7 +1943,7 @@ static const byte _search_directions[6][4] = { static const byte _pick_track_table[6] = {1, 3, 2, 2, 0, 0}; #if PF_BENCHMARK #if !defined(_MSC_VER) -unsigned int rdtsc() +unsigned int _rdtsc() { unsigned int high, low; @@ -1951,7 +1951,8 @@ unsigned int rdtsc() return low; } #else -static unsigned int _declspec(naked) rdtsc(void) +#ifndef _M_AMD64 +static unsigned int _declspec(naked) _rdtsc(void) { _asm { rdtsc @@ -1960,6 +1961,7 @@ static unsigned int _declspec(naked) rdtsc(void) } #endif #endif +#endif @@ -1969,7 +1971,7 @@ static byte ChooseTrainTrack(Vehicle *v, TileIndex tile, int enterdir, TrackdirB TrainTrackFollowerData fd; uint best_track; #if PF_BENCHMARK - int time = rdtsc(); + int time = _rdtsc(); static float f; #endif @@ -2040,7 +2042,7 @@ static byte ChooseTrainTrack(Vehicle *v, TileIndex tile, int enterdir, TrackdirB } #if PF_BENCHMARK - time = rdtsc() - time; + time = _rdtsc() - time; f = f * 0.99 + 0.01 * time; printf("PF time = %d %f\n", time, f); #endif diff --git a/viewport.c b/viewport.c index c3cc10834..66b93a852 100644 --- a/viewport.c +++ b/viewport.c @@ -2229,7 +2229,7 @@ void SetObjectToPlace(CursorID icon, byte mode, WindowClass window_class, Window VpStartPreSizing(); if ( (int)icon < 0) - SetAnimatedMouseCursor(_animcursors[~icon]); + SetAnimatedMouseCursor(_animcursors[~(int32)icon]); else SetMouseCursor(icon); } @@ -61,6 +61,11 @@ bool LoadLibraryList(Function proc[], const char* dll) } #ifdef _MSC_VER +# ifdef _M_AMD64 +void* _get_save_esp(void); +uint64 _rdtsc(void); +# endif + static const char *_exception_string; #endif @@ -452,6 +457,37 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) if (_exception_string) output += sprintf(output, "Reason: %s\r\n", _exception_string); +#ifdef _M_AMD64 + output += sprintf(output, "Exception %.8X at %.16IX\r\n" + "Registers:\r\n" + "RAX: %.16llX RBX: %.16llX RCX: %.16llX RDX: %.16llX\r\n" + "RSI: %.16llX RDI: %.16llX RBP: %.16llX RSP: %.16llX\r\n" + "R8: %.16llX R9: %.16llX R10: %.16llX R11: %.16llX\r\n" + "R12: %.16llX R13: %.16llX R14: %.16llX R15: %.16llX\r\n" + "RIP: %.16llX EFLAGS: %.8X\r\n" + "\r\nBytes at CS:RIP:\r\n", + ep->ExceptionRecord->ExceptionCode, + ep->ExceptionRecord->ExceptionAddress, + ep->ContextRecord->Rax, + ep->ContextRecord->Rbx, + ep->ContextRecord->Rcx, + ep->ContextRecord->Rdx, + ep->ContextRecord->Rsi, + ep->ContextRecord->Rdi, + ep->ContextRecord->Rbp, + ep->ContextRecord->Rsp, + ep->ContextRecord->R8, + ep->ContextRecord->R9, + ep->ContextRecord->R10, + ep->ContextRecord->R11, + ep->ContextRecord->R12, + ep->ContextRecord->R13, + ep->ContextRecord->R14, + ep->ContextRecord->R15, + ep->ContextRecord->Rip, + ep->ContextRecord->EFlags + ); +#else output += sprintf(output, "Exception %.8X at %.8X\r\n" "Registers:\r\n" " EAX: %.8X EBX: %.8X ECX: %.8X EDX: %.8X\r\n" @@ -471,9 +507,14 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) ep->ContextRecord->Eip, ep->ContextRecord->EFlags ); +#endif { +#ifdef _M_AMD64 + byte *b = (byte*)ep->ContextRecord->Rip; +#else byte *b = (byte*)ep->ContextRecord->Eip; +#endif int i; for (i = 0; i != 24; i++) { if (IsBadReadPtr(b, 1)) { @@ -491,7 +532,11 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) { int i,j; +#ifdef _M_AMD64 + uint32 *b = (uint32*)ep->ContextRecord->Rsp; +#else uint32 *b = (uint32*)ep->ContextRecord->Esp; +#endif for (j = 0; j != 24; j++) { for (i = 0; i != 8; i++) { if (IsBadReadPtr(b,sizeof(uint32))) { @@ -530,8 +575,13 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) CloseConsoleLogIfActive(); if (_safe_esp) { +#ifdef _M_AMD64 + ep->ContextRecord->Rip = (DWORD64)Handler2; + ep->ContextRecord->Rsp = (DWORD64)_safe_esp; +#else ep->ContextRecord->Eip = (DWORD)Handler2; ep->ContextRecord->Esp = (DWORD)_safe_esp; +#endif return EXCEPTION_CONTINUE_EXECUTION; } @@ -541,9 +591,13 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) static void Win32InitializeExceptions(void) { +#ifdef _M_AMD64 + _safe_esp = _get_save_esp(); +#else _asm { mov _safe_esp, esp } +#endif SetUnhandledExceptionFilter(ExceptionHandler); } @@ -997,8 +1051,8 @@ static int ParseCommandLine(char *line, char **argv, int max_argc) } -#if defined(_MSC_VER) -uint32 _declspec(naked) rdtsc(void) +#if defined(_MSC_VER) && !defined(_M_AMD64) +uint64 _declspec(naked) _rdtsc(void) { _asm { rdtsc @@ -1025,9 +1079,9 @@ void CreateConsole(void) // redirect unbuffered STDIN, STDOUT, STDERR to the console #if !defined(__CYGWIN__) - *stdout = *_fdopen( _open_osfhandle((long)hand, _O_TEXT), "w" ); - *stdin = *_fdopen(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT), "r" ); - *stderr = *_fdopen(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" ); + *stdout = *_fdopen( _open_osfhandle((intptr_t)hand, _O_TEXT), "w" ); + *stdin = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT), "r" ); + *stderr = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" ); #else // open_osfhandle is not in cygwin *stdout = *fdopen(1, "w" ); @@ -1082,9 +1136,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, // setup random seed to something quite random #if defined(_MSC_VER) { - uint64 seed = rdtsc(); - _random_seeds[0][0] = GB(seed, 0, 32); - _random_seeds[0][1] = GB(seed, 32, 32); + ULARGE_INTEGER seed; seed.QuadPart = _rdtsc(); + _random_seeds[0][0] = seed.LowPart; + _random_seeds[0][1] = seed.HighPart; } #else _random_seeds[0][0] = GetTickCount(); @@ -1155,6 +1209,7 @@ int CDECL snprintf(char *str, size_t size, const char *format, ...) return ret; } +#if _MSC_VER < 1400 /* Already defined in VS 2005 */ int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap) { int ret; @@ -1162,6 +1217,7 @@ int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap) if (ret < 0) str[size - 1] = '\0'; return ret; } +#endif /** * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard diff --git a/win64.asm b/win64.asm new file mode 100644 index 000000000..21bfebbde --- /dev/null +++ b/win64.asm @@ -0,0 +1,17 @@ + .CODE + +PUBLIC _get_save_esp +_get_save_esp: + MOV RAX,RSP + RET + +PUBLIC _rdtsc +_rdtsc: + RDTSC + MOV RCX,RDX + SHL RCX,32 + AND RAX,0FFFFFFFFh + OR RAX,RCX + RET + + END |