(svn r1281) -Fix: the OS/2 is now finished. Fixes:

- Networking
  - File selector issue
  - Keyboard input
  - Dedicated server console issue (use dedicated.cmd to open a server)
  - Plus many other minor issues
This commit is contained in:
truelight 2004-12-27 10:40:04 +00:00
parent f3c8f40c51
commit 1f4c1e8821
13 changed files with 989 additions and 745 deletions

View File

@ -20,6 +20,8 @@
# include <unistd.h>
# include <conio.h>
# define STDIN 0 /* file descriptor for standard input */
extern void OS2_SwitchToConsoleMode();
#endif
#ifdef UNIX
@ -100,6 +102,11 @@ static const char *DedicatedVideoStart(char **parm) {
SetConsoleTitle("OpenTTD Dedicated Server");
#endif
#ifdef __OS2__
// For OS/2 we also need to switch to console mode instead of PM mode
OS2_SwitchToConsoleMode();
#endif
DEBUG(misc,0)("Loading dedicated server...");
return NULL;
}

View File

@ -1,48 +1,114 @@
OpenTTD: OS/2 version ** CURRENTLY INCOMPLETE **
OpenTTD: OS/2 version
=====================
OpenTTD has been ported to work on OS/2 4.x or later (including eComStation). At the moment, it does not work properly, but it
can compile and work to an extent.
OpenTTD has been ported to work on OS/2 4.x or later (including
eComStation). The game should work as well as it does on Windows
or other platforms: the main issues you may encounter are graphics
card problems, but that is really the fault of SDL.
=========================
USING OPENTTD FOR OS/2
=========================
LIBRARIES REQUIRED FOR END USERS
--------------------------------
SDL.DLL (SDL 1.2.7) and FSLib.dll are required to use this program:
these can be downloaded from the Files section at
http://sourceforge.net/projects/openttd/ - see "os2-useful.zip".
Note that to actually play the game, I have found in my own
experience that a version of the Scitech Display Drivers or its later
incarnation (see www.scitech.com) are necessary for it to work. If
you have trouble with your native drivers, try the Scitech drivers
and see if they help the problem.
KNOWN ISSUES
------------
- If an error occurs during loading, the OS/2 error message window
is not always displayed.
A NOTE ABOUT MUSIC
------------------
OpenTTD includes a music driver which uses the MCI MIDI system. Unfortunately,
due to the lack of proper MIDI hardware myself, I have been unable to test it,
but during testing, I found that when MIDI was enabled, I got no sound
effects. I therefore decided to DISABLE music by default.
To enable music, start OpenTTD with the command line:
openttd -m os2
If I hear enough responses that both music and sound work together (it might
just be my system), I'll have the defaults changed.
A NOTE ABOUT DEDICATED MULTIPLAYER SERVERS
------------------------------------------
To start a dedicated multiplayer server, you should run the dedicated.cmd
file. This enables OpenTTD to open up a VIO console window to display
its output and gather any necessary input. Running "openttd -D"
directly will result in the console not being displayed. You may
still pass any other parameters ('-D' is already passed) to
dedicated.cmd.
=========================
BUILDING THE OS/2 VERSION
=========================
Compiler
--------
Open Watcom 1.3 was used to build OpenTTD (earlier versions will NOT work). See http://www.openwatcom.org/ to download it.
It may also be possible to build OpenTTD under OS/2: I attempted this before using Open Watcom, but found the tools available
for OS/2 at the time to be a bit more tricky to get working.
Open Watcom 1.3 was used to build OpenTTD (earlier versions will
NOT work). See http://www.openwatcom.org/ to download it. It may
also be possible to build OpenTTD under OS/2: I attempted this
before using Open Watcom, but found the tools available for OS/2
at the time to be a bit more tricky to get working.
Due to complexities in my set-up, I actually used the Win32 version of Open Watcom to initially compile OpenTTD for OS/2. There
should be no reason of course why the OS/2 version cannot be used.
Due to complexities in my set-up, I actually used the Win32 version
of Open Watcom to initially compile OpenTTD for OS/2. There should
be no reason of course why the OS/2 version cannot be used.
Libraries Required
------------------
The following libraries are required. To build zlib and libpng, I simply added the required files (watch out for sample
programs, etc) to an IDE project file and built a library:
The following libraries are required. To build zlib and libpng, I
simply added the required files (watch out for sample programs, etc)
to an IDE project file and built a library. Do not use the makefiles
provided, they are not designed for Watcom (apart from SDL):
- zlib
http://www.zlib.org/ - contains a makefile for OS/2, but is out of date and uses EMX
http://www.zlib.org/ - contains a makefile for OS/2, but is out
of date and uses EMX
- libpng
http://www.libpng.org/ - contains an EMX/gcc makefile
- SDL for OS/2
I used ftp://ftp.netlabs.org/pub/sdl/SDL-1.2.7-src-20040908a.zip - take SDL.dll and SDL.lib from the src/ directory.
I used ftp://ftp.netlabs.org/pub/sdl/SDL-1.2.7-src-20040908a.zip -
take SDL.dll and SDL.lib from the src/ directory.
Note that to use the compiled program, you also need FSLib.dll (from src/ in the SDL zip) and a version of the Scitech
Display Drivers or its later incarnation (see www.scitech.com).
If you do not wish to build the libraries yourself, pre-built versions
can be downloaded from the Files section at
http://sourceforge.net/projects/openttd/ - see "os2-useful.zip".
Compiling
---------
To compile, open the os/os2/openttd.wpj file in the IDE and build the openttd.exe target.
To compile, open the os/os2/openttd.wpj file in the IDE and first build
the strgen.exe target. This will build the .lng file generator, and will
also attempt to build all the language files (plus the table\strings.h
file which is required for openttd.exe to be built). Once strgen.exe and
the language files are built successfully, you can build the openttd.exe
target.
TODO: compilation of language files properly
Contact Information
-------------------
If you have any questions regarding OS/2 issues, please contact me
(owen@owenrudge.net) and I'll try to help you out. For general OpenTTD
issues, see the Contacting section of readme.txt.
** THESE DOCS ARE INCOMPLETE FOR THE MOMENT, WILL BE COMPLETED SOON **
If you have any questions, please contact me (owen@owenrudge.net) and I'll try to help you out
- Owen Rudge, 18th December 2004
- Owen Rudge, 26th December 2004

View File

@ -22,13 +22,13 @@ openttd \- An open source clone of the Microprose game "Transport Tycoon Deluxe
.RI [ options ]
.br
.SH DESCRIPTION
Unfortanetely, there is no real manpage for openttd yet. Hopefully someone
Unfortunately, there is no real manpage for openttd yet. Hopefully someone
will write one soon. For now you should use
.B openttd -h
for more information, or check our Wiki manual: http://wiki.openttd.org/
.PP
.\" TeX users may be more comfortable with the \fB<whatever>\fP and
.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
.\" \fI<whatever>\fP escape sequences to invoke bold face and italics,
.\" respectively.
.\" \fBopenttd\fP is a program that...
.SH OPTIONS

View File

@ -1,6 +1,6 @@
#include "stdafx.h"
#include "ttd.h"
#if defined(UNIX)
#if defined(UNIX) || defined(__OS2__)
#include <ctype.h> // required for tolower()
#endif

4
hal.h
View File

@ -71,6 +71,10 @@ extern const HalMusicDriver _extmidi_music_driver;
extern const HalMusicDriver _bemidi_music_driver;
#endif
#if defined(__OS2__)
extern const HalMusicDriver _os2_music_driver;
#endif
extern const HalVideoDriver _dedicated_video_driver;
enum DriverType {

View File

@ -199,6 +199,8 @@ static void AskAbandonGameWndProc(Window *w, WindowEvent *e) {
SetDParam(0, STR_OSNAME_MORPHOS);
#elif defined(__AMIGA__)
SetDParam(0, STR_OSNAME_AMIGAOS);
#elif defined(__OS2__)
SetDParam(0, STR_OSNAME_OS2);
#else
SetDParam(0, STR_0134_UNIX);
#endif

View File

@ -311,6 +311,7 @@ STR_0135_OSX :OS X
STR_OSNAME_BEOS :BeOS
STR_OSNAME_MORPHOS :MorphOS
STR_OSNAME_AMIGAOS :AmigaOS
STR_OSNAME_OS2 :OS/2
STR_0139_IMPERIAL_MILES :Imperial (miles)
STR_013A_METRIC_KILOMETERS :Metric (kilometers)

View File

@ -88,7 +88,7 @@ typedef struct ifreq IFREQ;
typedef struct ifreq IFREQ;
# define ioctlsocket ioctl
# define closesocket close
# define GET_LAST_ERROR() (errno)
# define GET_LAST_ERROR() (sock_errno())
// Includes needed for OS/2 systems
# include <types.h>
@ -103,6 +103,7 @@ typedef struct ifreq IFREQ;
# include <sys/time.h>
# include <netdb.h>
# include <nerrno.h>
# define INADDR_NONE 0xffffffff
typedef unsigned long in_addr_t;
#endif // OS/2

File diff suppressed because it is too large Load Diff

View File

@ -42,8 +42,8 @@ WRect
WFileName
17
..\..\openttd.tgt
51
52
47
47
11
VComponent
12

217
os2.c
View File

@ -6,10 +6,16 @@
#include <direct.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <time.h>
#include <dos.h>
#define INCL_DOS
#define INCL_WINDIALOGS
#define INCL_OS2MM
#include <os2.h>
#include <os2me.h>
#if defined(WITH_SDL)
#include <SDL.h>
@ -27,6 +33,7 @@ static FiosItem *FiosAlloc()
_fios_alloc += 256;
_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem));
}
return &_fios_items[_fios_count++];
}
@ -45,6 +52,22 @@ int compare_FiosItems (const void *a, const void *b) {
}
static DIR *my_opendir(char *path, char *file)
{
char paths[MAX_PATH];
append_path(paths, path, file);
return opendir(paths);
}
static void append_path(char *out, char *path, char *file)
{
if ((path[2] == '\\') && (path[3] == 0))
sprintf(out, "%s%s", path, file);
else
sprintf(out, "%s\\%s", path, file);
}
// Get a list of savegames
FiosItem *FiosGetSavegameList(int *num, int mode)
{
@ -60,32 +83,31 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
strcpy(_fios_save_path, _path.save_dir);
}
if(_game_mode==GM_EDITOR)
if (_game_mode == GM_EDITOR)
_fios_path = _fios_scn_path;
else
_fios_path = _fios_save_path;
// Parent directory, only if not in root already.
if (_fios_path[1] != 0) {
// Parent directory, only if not of the type C:\.
if (_fios_path[3] != 0) {
fios = FiosAlloc();
fios->type = FIOS_TYPE_PARENT;
fios->mtime = 0;
sprintf(fios->title, ".. (Parent directory)");
strcpy(fios->title, ".. (Parent directory)");
}
// Show subdirectories first
dir = opendir(_fios_path[0] ? _fios_path : "C:\\");
dir = my_opendir(_fios_path, "*.*");
if (dir != NULL) {
while ((dirent = readdir(dir))) {
sprintf (filename, "%s\\%s", _fios_path, dirent->d_name);
append_path(filename, _fios_path, dirent->d_name);
if (!stat(filename, &sb)) {
if (S_ISDIR(sb.st_mode)) {
if (dirent->d_name[0] != '.') {
if (!(dirent->d_name[0] == '.' && (dirent->d_name[1] == 0 || (dirent->d_name[1] == '.' && dirent->d_name[2] == 0))))
{
fios = FiosAlloc();
fios->mtime = 0;
fios->type = FIOS_TYPE_DIR;
fios->title[0] = 0;
sprintf(fios->name, "%s\\ (Directory)", dirent->d_name);
strcpy(fios->name, dirent->d_name);
sprintf(fios->title, "%s\\ (Directory)", dirent->d_name);
}
}
}
@ -110,10 +132,10 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
* .SV1 Transport Tycoon Deluxe (Patch) saved game
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game
*/
dir = opendir(_fios_path[0] ? _fios_path : "C:\\");
dir = my_opendir(_fios_path, "*.*");
if (dir != NULL) {
while ((dirent = readdir(dir))) {
sprintf (filename, "%s\\%s", _fios_path, dirent->d_name);
append_path(filename, _fios_path, dirent->d_name);
if (!stat(filename, &sb)) {
if (!S_ISDIR(sb.st_mode)) {
char *t = strrchr(dirent->d_name, '.');
@ -185,25 +207,35 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
int sort_start;
char filename[MAX_PATH];
if (_fios_scn_path == NULL) {
_fios_scn_path = malloc(MAX_PATH);
if (mode == SLD_NEW_GAME || _fios_scn_path == NULL) {
if (_fios_scn_path == NULL)
_fios_scn_path = malloc(MAX_PATH);
strcpy(_fios_scn_path, _path.scenario_dir);
}
_fios_path = _fios_scn_path;
// Parent directory, only if not of the type C:\.
if (_fios_path[3] != 0 && mode != SLD_NEW_GAME) {
fios = FiosAlloc();
fios->type = FIOS_TYPE_PARENT;
strcpy(fios->title, ".. (Parent directory)");
}
// Show subdirectories first
dir = opendir(_fios_path[0] ? _fios_path : "C:\\");
dir = my_opendir(_fios_path, "*.*");
if (dir != NULL) {
while ((dirent = readdir(dir))) {
sprintf (filename, "%s\\%s", _fios_path, dirent->d_name);
append_path(filename, _fios_path, dirent->d_name);
if (!stat(filename, &sb)) {
if (S_ISDIR(sb.st_mode)) {
if (dirent->d_name[0] != '.') {
if (!(dirent->d_name[0] == '.' && (dirent->d_name[1] == 0 || (dirent->d_name[1] == '.' && dirent->d_name[2] == 0))))
{
fios = FiosAlloc();
fios->mtime = 0;
fios->type = FIOS_TYPE_DIR;
fios->title[0] = 0;
sprintf(fios->name, "%s\\ (Directory)", dirent->d_name);
strcpy(fios->name, dirent->d_name);
sprintf(fios->title, "%s\\ (Directory)", dirent->d_name);
}
}
}
@ -219,10 +251,10 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
* .SV0 Transport Tycoon Deluxe (Patch) scenario
* .SS0 Transport Tycoon Deluxe preset scenario
*/
dir = opendir(_fios_path[0] ? _fios_path : "C:\\");
dir = my_opendir(_fios_path, "*.*");
if (dir != NULL) {
while ((dirent = readdir(dir))) {
sprintf (filename, "%s\\%s", _fios_path, dirent->d_name);
append_path(filename, _fios_path, dirent->d_name);
if (!stat(filename, &sb)) {
if (!S_ISDIR(sb.st_mode)) {
char *t = strrchr(dirent->d_name, '.');
@ -301,16 +333,28 @@ char *FiosBrowseTo(const FiosItem *item)
char *s;
switch(item->type) {
case FIOS_TYPE_DRIVE:
sprintf(path, "%c:\\", item->title[0]);
break;
case FIOS_TYPE_PARENT:
s = strrchr(path, '\\');
if (s != NULL) *s = 0;
// Skip drive part
path += 3;
s = path;
while (*path) {
if (*path== '\\')
s = path;
path++;
}
*s = 0;
break;
case FIOS_TYPE_DIR:
s = strchr((char*)item->name, '\\');
if (s) *s = 0;
while (*path) path++;
*path++ = '\\';
// Scan to end
while (*++path);
// Add backslash?
if (path[-1] != '\\') *path++ = '\\';
strcpy(path, item->name);
break;
@ -325,7 +369,6 @@ char *FiosBrowseTo(const FiosItem *item)
case FIOS_TYPE_SCENARIO:
sprintf(str_buffr, "%s\\%s.scn", path, item->name);
return str_buffr;
case FIOS_TYPE_OLD_SCENARIO:
sprintf(str_buffr, "%s\\%s.%s", path, item->name, _old_extensions[item->old_extension]);
return str_buffr;
@ -342,11 +385,11 @@ StringID FiosGetDescText(const char **path)
struct diskfree_t free;
char drive;
*path = _fios_path[0] ? _fios_path : "C:\\";
drive = 'B' - *path[0];
*path = _fios_path;
drive = *path[0] - 'A'+1;
_getdiskfree(drive, &free);
SetDParam(0, free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector);
return STR_4005_BYTES_FREE;
}
@ -367,33 +410,33 @@ void FiosDelete(const char *name)
}
const DriverDesc _video_driver_descs[] = {
{"null", "Null Video Driver", &_null_video_driver, 0},
{ "null", "Null Video Driver", &_null_video_driver, 0},
#if defined(WITH_SDL)
{ "sdl", "SDL Video Driver", &_sdl_video_driver, 1},
{ "sdl", "SDL Video Driver", &_sdl_video_driver, 1},
#endif
{ "dedicated", "Dedicated Video Driver", &_dedicated_video_driver, 0},
{ NULL, NULL, NULL, 0}
{ "dedicated", "Dedicated Video Driver", &_dedicated_video_driver, 0},
{ NULL, NULL, NULL, 0}
};
const DriverDesc _sound_driver_descs[] = {
{"null", "Null Sound Driver", &_null_sound_driver, 0},
{ "null", "Null Sound Driver", &_null_sound_driver, 0},
#if defined(WITH_SDL)
{ "sdl", "SDL Sound Driver", &_sdl_sound_driver, 1},
{ "sdl", "SDL Sound Driver", &_sdl_sound_driver, 1},
#endif
{ NULL, NULL, NULL, 0}
{ NULL, NULL, NULL, 0}
};
const DriverDesc _music_driver_descs[] = {
{ "null", "Null Music Driver", &_null_music_driver, 0},
{ NULL, NULL, NULL, 0}
{ "os2", "OS/2 Music Driver", &_os2_music_driver, 0},
{ "null", "Null Music Driver", &_null_music_driver, 1},
{ NULL, NULL, NULL, 0}
};
/* GetOSVersion returns the minimal required version of OS to be able to use that driver.
Not needed for *nix. */
Not needed for OS/2. */
byte GetOSVersion()
{
return 2; // any arbitrary number bigger then 0
// numbers lower than 2 breaks default music selection on mac
}
bool FileExists(const char *filename)
@ -438,15 +481,15 @@ static void ChangeWorkingDirectory(char *exe)
}
}
// for some reason these calls don't actually work properly :/
void ShowInfo(const char *str)
{
puts(str);
WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, str, "OpenTTD", 0, MB_OK | MB_SYSTEMMODAL | MB_MOVEABLE | MB_INFORMATION);
}
void ShowOSErrorBox(const char *buf)
{
WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, buf, "OpenTTD", 263, MB_OK | MB_APPLMODAL | MB_MOVEABLE | MB_ERROR);
// TODO: FIX, doesn't always appear
WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, buf, "OpenTTD", 0, MB_OK | MB_SYSTEMMODAL | MB_MOVEABLE | MB_ERROR);
}
int CDECL main(int argc, char* argv[])
@ -529,3 +572,85 @@ void DeterminePaths()
mkdir(_path.scenario_dir);
}
// FUNCTION: OS2_SwitchToConsoleMode
//
// Switches OpenTTD to a console app at run-time, instead of a PM app
// Necessary to see stdout, etc
void OS2_SwitchToConsoleMode()
{
PPIB pib;
PTIB tib;
DosGetInfoBlocks(&tib, &pib);
// Change flag from PM to VIO
pib->pib_ultype = 3;
}
/**********************
* OS/2 MIDI PLAYER
**********************/
/* Interesting how similar the MCI API in OS/2 is to the Win32 MCI API,
* eh? Anyone would think they both came from the same place originally! ;)
*/
static long CDECL MidiSendCommand(const char *cmd, ...)
{
va_list va;
char buf[512];
va_start(va, cmd);
vsprintf(buf, cmd, va);
va_end(va);
return mciSendString(buf, NULL, 0, NULL, 0);
}
static void OS2MidiPlaySong(const char *filename)
{
MidiSendCommand("close all");
if (MidiSendCommand("open %s type sequencer alias song", filename) != 0)
return;
MidiSendCommand("play song from 0");
}
static void OS2MidiStopSong()
{
MidiSendCommand("close all");
}
static void OS2MidiSetVolume(byte vol)
{
MidiSendCommand("set song audio volume %d", ((vol/127)*100));
}
static bool OS2MidiIsSongPlaying()
{
char buf[16];
mciSendString("status song mode", buf, sizeof(buf), NULL, 0);
return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
}
static char *OS2MidiStart(char **parm)
{
return 0;
}
static void OS2MidiStop()
{
MidiSendCommand("close all");
}
const HalMusicDriver _os2_music_driver = {
OS2MidiStart,
OS2MidiStop,
OS2MidiPlaySong,
OS2MidiStopSong,
OS2MidiIsSongPlaying,
OS2MidiSetVolume,
};

2
sdl.c
View File

@ -408,7 +408,7 @@ static uint32 ConvertSdlKeyIntoMy(SDL_keysym *sym)
}
// check scancode for BACKQUOTE key, because we want the key left of "1", not anything else (on non-US keyboards)
#if defined(WIN32)
#if defined(WIN32) || defined(__OS2__)
if (sym->scancode == 41) key |= WKC_BACKQUOTE;
#elif defined(__APPLE__)
if (sym->scancode == 10) key |= WKC_BACKQUOTE;

View File

@ -15,13 +15,15 @@ WString
oc2en
1
0
1
0
4
MCommand
0
5
MCommand
0
26
..\os\os2\build_lang.cmd
6
MItem
10
@ -77,44 +79,68 @@ WString
COBJ
19
WVList
0
2
20
MRState
21
WString
3
WCC
22
WString
29
?????No debugging information
0
1
23
MRState
24
WString
3
WCC
25
WString
28
?????Line number information
0
0
26
WVList
0
-1
1
1
0
21
27
MItem
8
stdafx.c
22
28
WString
4
COBJ
23
29
WVList
0
24
30
WVList
0
17
1
1
0
25
31
MItem
8
strgen.c
26
32
WString
4
COBJ
27
33
WVList
0
28
34
WVList
0
17