(svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
authortruelight
Sat, 04 Aug 2007 12:53:41 +0000
changeset 7408 605b333582d5
parent 7407 a0e8d497e161
child 7409 44932e96a196
(svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
-Fix: WinCE doesn't support console
-Fix: Set debug lvl4 when running a debug WinCE build (as you can't give parameters any easy way)
src/fios.cpp
src/gfx.cpp
src/openttd.cpp
src/video/dedicated_v.cpp
src/video/win32_v.cpp
src/win32.cpp
--- a/src/fios.cpp	Sat Aug 04 01:25:44 2007 +0000
+++ b/src/fios.cpp	Sat Aug 04 12:53:41 2007 +0000
@@ -108,7 +108,9 @@
 	char *path = _fios_path;
 
 	switch (item->type) {
-#if defined(WIN32) || defined(__OS2__)
+#if defined(WINCE)
+	case FIOS_TYPE_DRIVE: sprintf(path, PATHSEP ""); break;
+#elif defined(WIN32) || defined(__OS2__)
 	case FIOS_TYPE_DRIVE: sprintf(path, "%c:" PATHSEP, item->title[0]); break;
 #endif
 
--- a/src/gfx.cpp	Sat Aug 04 01:25:44 2007 +0000
+++ b/src/gfx.cpp	Sat Aug 04 12:53:41 2007 +0000
@@ -840,6 +840,11 @@
 
 void DrawMouseCursor()
 {
+#if defined(WINCE)
+	/* Don't ever draw the mouse for WinCE, as we work with a stylus */
+	return;
+#endif
+
 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 	int x;
 	int y;
--- a/src/openttd.cpp	Sat Aug 04 01:25:44 2007 +0000
+++ b/src/openttd.cpp	Sat Aug 04 12:53:41 2007 +0000
@@ -452,6 +452,11 @@
 		}
 	}
 
+#if defined(WINCE) && defined(_DEBUG)
+	/* Switch on debug lvl 4 for WinCE if Debug release, as you can't give params, and you most likely do want this information */
+	SetDebugString("4");
+#endif
+
 	DeterminePaths(argv[0]);
 	CheckExternalFiles();
 
--- a/src/video/dedicated_v.cpp	Sat Aug 04 01:25:44 2007 +0000
+++ b/src/video/dedicated_v.cpp	Sat Aug 04 12:53:41 2007 +0000
@@ -66,11 +66,13 @@
 }
 #endif
 
-#ifdef WIN32
-#include <windows.h> /* GetTickCount */
-#include <conio.h>
-#include <time.h>
-#include <tchar.h>
+#if defined(WIN32)
+# include <windows.h> /* GetTickCount */
+# if !defined(WINCE)
+#  include <conio.h>
+# endif
+# include <time.h>
+# include <tchar.h>
 static HANDLE _hInputReady, _hWaitForInputHandling;
 static HANDLE _hThread; // Thread to close
 static char _win_console_thread_buffer[200];
@@ -78,6 +80,10 @@
 /* Windows Console thread. Just loop and signal when input has been received */
 static void WINAPI CheckForConsoleInput()
 {
+#if defined(WINCE)
+	/* WinCE doesn't support console stuff */
+	return;
+#else
 	DWORD nb;
 	HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
 	while (true) {
@@ -87,6 +93,7 @@
 		SetEvent(_hInputReady);
 		WaitForSingleObject(_hWaitForInputHandling, INFINITE);
 	}
+#endif
 }
 
 static void CreateWindowsConsoleThread()
@@ -133,7 +140,9 @@
 
 	SetDebugString("net=6");
 
-#ifdef WIN32
+#if defined(WINCE)
+	/* WinCE doesn't support console stuff */
+#elif defined(WIN32)
 	// For win32 we need to allocate a console (debug mode does the same)
 	CreateConsole();
 	CreateWindowsConsoleThread();
--- a/src/video/win32_v.cpp	Sat Aug 04 01:25:44 2007 +0000
+++ b/src/video/win32_v.cpp	Sat Aug 04 12:53:41 2007 +0000
@@ -775,6 +775,8 @@
 
 	FindResolutions();
 
+	DEBUG(driver, 2, "Resolution for display: %dx%d", _cur_resolution[0], _cur_resolution[1]);
+
 	// fullscreen uses those
 	_wnd.width_org = _cur_resolution[0];
 	_wnd.height_org = _cur_resolution[1];
--- a/src/win32.cpp	Sat Aug 04 01:25:44 2007 +0000
+++ b/src/win32.cpp	Sat Aug 04 12:53:41 2007 +0000
@@ -94,7 +94,7 @@
 #endif
 }
 
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && !defined(WINCE)
 
 static void *_safe_esp;
 static char *_crash_msg;
@@ -734,6 +734,14 @@
 
 void FiosGetDrives()
 {
+#if defined(WINCE)
+	/* WinCE only knows one drive: / */
+	FiosItem *fios = FiosAlloc();
+	fios->type = FIOS_TYPE_DRIVE;
+	fios->mtime = 0;
+	snprintf(fios->name, lengthof(fios->name), PATHSEP "");
+	ttd_strlcpy(fios->title, fios->name, lengthof(fios->title));
+#else
 	TCHAR drives[256];
 	const TCHAR *s;
 
@@ -746,6 +754,7 @@
 		ttd_strlcpy(fios->title, fios->name, lengthof(fios->title));
 		while (*s++ != '\0');
 	}
+#endif
 }
 
 bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
@@ -821,6 +830,9 @@
 
 void CreateConsole()
 {
+#if defined(WINCE)
+	/* WinCE doesn't support console stuff */
+#else
 	HANDLE hand;
 	CONSOLE_SCREEN_BUFFER_INFO coninfo;
 
@@ -849,6 +861,7 @@
 	setvbuf(stdin, NULL, _IONBF, 0);
 	setvbuf(stdout, NULL, _IONBF, 0);
 	setvbuf(stderr, NULL, _IONBF, 0);
+#endif
 }
 
 void ShowInfo(const char *str)
@@ -882,7 +895,11 @@
 	int _set_error_mode(int);
 #endif
 
+#if defined(WINCE)
+int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
+#else
 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+#endif
 {
 	int argc;
 	char *argv[64]; // max 64 command line arguments
@@ -893,8 +910,11 @@
 #endif /* UNICODE */
 
 #if defined(UNICODE)
+
+#if !defined(WINCE)
 	/* Check if a win9x user started the win32 version */
 	if (HASBIT(GetVersion(), 31)) error("This version of OpenTTD doesn't run on windows 95/98/ME.\nPlease download the win9x binary and try again.");
+#endif
 
 	/* For UNICODE we need to convert the commandline to char* _AND_
 	 * save it because argv[] points into this buffer and thus needs to
@@ -908,7 +928,9 @@
 	CreateConsole();
 #endif
 
+#if !defined(WINCE)
 	_set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox
+#endif
 
 	/* setup random seed to something quite random */
 	_random_seeds[1][0] = _random_seeds[0][0] = GetTickCount();
@@ -951,7 +973,14 @@
 
 char *getcwd(char *buf, size_t size)
 {
-#if defined(UNICODE)
+#if defined(WINCE)
+ 	TCHAR path[MAX_PATH];
+	GetModuleFileName(NULL, path, MAX_PATH);
+	convert_from_fs(path, buf, size);
+	/* GetModuleFileName returns dir with file, so remove everything behind latest '\\' */
+	char *p = strrchr(buf, '\\');
+	if (p != NULL) *p = '\0';
+#elif defined(UNICODE)
 	TCHAR path[MAX_PATH];
 	GetCurrentDirectory(MAX_PATH - 1, path);
 	convert_from_fs(path, buf, size);