(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)

Fix warning in graph_gui.c with const problem
replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
Darkvater 19 years ago
parent e8fac6c6cb
commit a3d40a29fc

@ -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);

@ -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;

@ -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..

@ -826,6 +826,9 @@
<File
RelativePath=".\ai\default\default.c">
</File>
<File
RelativePath=".\ai\default\default.h">
</File>
<Filter
Name="trolly"
Filter="">

@ -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

@ -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");

@ -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

@ -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

@ -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
Loading…
Cancel
Save