driver.c
author tron
Sun, 14 Aug 2005 18:10:18 +0000
changeset 2340 e18ef06bc59a
parent 2303 559e782ebc25
child 2458 dbaf5dffbb28
permissions -rw-r--r--
(svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
This doesn't ease the global variable mess, but makes the distinction between sprite heap and gfx loading routines easier.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     2
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     3
#include "stdafx.h"
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     4
#include "openttd.h"
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
     5
#include "debug.h"
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     6
#include "driver.h"
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     7
#include "functions.h"
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     8
#include "hal.h"
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     9
#include "string.h"
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    10
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    11
#include "music/bemidi.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    12
#include "music/dmusic.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    13
#include "music/extmidi.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    14
#include "music/null_m.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    15
#include "music/os2_m.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    16
#include "music/win32_m.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    17
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    18
#include "sound/null_s.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    19
#include "sound/sdl_s.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    20
#include "sound/win32_s.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    21
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    22
#include "video/dedicated_v.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    23
#include "video/null_v.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    24
#include "video/sdl_v.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    25
#include "video/win32_v.h"
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    26
2219
2437978eae8f (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    27
typedef struct DriverDesc {
2437978eae8f (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    28
	const char* name;
2437978eae8f (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    29
	const char* longname;
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    30
	const HalCommonDriver* drv;
2219
2437978eae8f (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    31
} DriverDesc;
2437978eae8f (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    32
2437978eae8f (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    33
typedef struct DriverClass {
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    34
	const DriverDesc *descs;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    35
	const char *name;
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    36
	const HalCommonDriver** drv;
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    37
} DriverClass;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    38
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    39
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    40
#define M(x, y, z) { x, y, (const HalCommonDriver*)z }
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    41
static const DriverDesc _music_driver_descs[] = {
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    42
#ifdef __BEOS__
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    43
	M("bemidi",  "BeOS MIDI Driver",        &_bemidi_music_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    44
#endif
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    45
#ifdef __OS2__
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    46
	M("os2",     "OS/2 Music Driver",       &_os2_music_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    47
#endif
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    48
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    49
	M("dmusic",  "DirectMusic MIDI Driver", &_dmusic_midi_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    50
#endif
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    51
#ifdef WIN32
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    52
	M("win32",   "Win32 MIDI Driver",       &_win32_music_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    53
#endif
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    54
#ifdef UNIX
2303
559e782ebc25 (svn r2827) BeOS meets all prerequisites for extmidi
tron
parents: 2224
diff changeset
    55
#if !defined(__MORPHOS__) && !defined(__AMIGA__)
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    56
	M("extmidi", "External MIDI Driver",    &_extmidi_music_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    57
#endif
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    58
#endif
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    59
	M("null",    "Null Music Driver",       &_null_music_driver),
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    60
	M(NULL, NULL, NULL)
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    61
};
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    62
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    63
static const DriverDesc _sound_driver_descs[] = {
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    64
#ifdef WIN32
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    65
	M("win32", "Win32 WaveOut Driver", &_win32_sound_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    66
#endif
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    67
#ifdef WITH_SDL
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    68
	M("sdl",   "SDL Sound Driver",     &_sdl_sound_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    69
#endif
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    70
	M("null",  "Null Sound Driver",    &_null_sound_driver),
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    71
	M(NULL, NULL, NULL)
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    72
};
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    73
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    74
static const DriverDesc _video_driver_descs[] = {
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    75
#ifdef WIN32
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    76
	M("win32",      "Win32 GDI Video Driver", &_win32_video_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    77
#endif
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    78
#ifdef WITH_SDL
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    79
	M("sdl",        "SDL Video Driver",       &_sdl_video_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    80
#endif
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    81
	M("null",       "Null Video Driver",      &_null_video_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    82
#ifdef ENABLE_NETWORK
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    83
	M("dedicated",  "Dedicated Video Driver", &_dedicated_video_driver),
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    84
#endif
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    85
	M(NULL, NULL, NULL)
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    86
};
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    87
#undef M
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    88
2219
2437978eae8f (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    89
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    90
#define M(x, y, z) { x, y, (const HalCommonDriver**)z }
2219
2437978eae8f (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    91
static const DriverClass _driver_classes[] = {
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    92
	M(_video_driver_descs, "video", &_video_driver),
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    93
	M(_sound_driver_descs, "sound", &_sound_driver),
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    94
	M(_music_driver_descs, "music", &_music_driver)
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    95
};
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    96
#undef M
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    97
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    98
static const DriverDesc* GetDriverByName(const DriverDesc* dd, const char* name)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    99
{
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   100
	for (; dd->name != NULL; dd++) {
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   101
		if (strcmp(dd->name, name) == 0) return dd;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   102
	}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   103
	return NULL;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   104
}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   105
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   106
void LoadDriver(int driver, const char *name)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   107
{
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   108
	const DriverClass *dc = &_driver_classes[driver];
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   109
	const DriverDesc *dd;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   110
	const char *err;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   111
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   112
	if (*name == '\0') {
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   113
		for (dd = dc->descs; dd->name != NULL; dd++) {
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   114
			err = dd->drv->start(NULL);
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   115
			if (err == NULL) break;
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   116
			DEBUG(driver, 1) ("Probing %s driver \"%s\" failed with error: %s",
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   117
				dc->name, dd->name, err
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   118
			);
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   119
		}
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   120
		if (dd->name == NULL) {
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   121
			error("Couldn't find any suitable %s driver", dc->name);
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   122
		}
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   123
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   124
		DEBUG(driver, 1)
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   125
			("Successfully probed %s driver \"%s\"", dc->name, dd->name);
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   126
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   127
		*dc->drv = dd->drv;
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   128
	} else {
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   129
		char* parm;
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   130
		char buffer[256];
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   131
		const char* parms[32];
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   132
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   133
		// Extract the driver name and put parameter list in parm
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   134
		ttd_strlcpy(buffer, name, sizeof(buffer));
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   135
		parm = strchr(buffer, ':');
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   136
		parms[0] = NULL;
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   137
		if (parm != NULL) {
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   138
			uint np = 0;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   139
			// Tokenize the parm.
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   140
			do {
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   141
				*parm++ = '\0';
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   142
				if (np < lengthof(parms) - 1)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   143
					parms[np++] = parm;
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   144
				while (*parm != '\0' && *parm != ',')
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   145
					parm++;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   146
			} while (*parm == ',');
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   147
			parms[np] = NULL;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   148
		}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   149
		dd = GetDriverByName(dc->descs, buffer);
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   150
		if (dd == NULL)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   151
			error("No such %s driver: %s\n", dc->name, buffer);
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   152
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   153
		if (*dc->drv != NULL) (*dc->drv)->stop();
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   154
		*dc->drv = NULL;
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   155
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   156
		err = dd->drv->start(parms);
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   157
		if (err != NULL) {
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   158
			error("Unable to load driver %s(%s). The error was: %s\n",
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   159
				dd->name, dd->longname, err
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   160
			);
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   161
		}
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   162
		*dc->drv = dd->drv;
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   163
	}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   164
}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   165
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   166
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   167
static const char* GetDriverParam(const char* const* parm, const char* name)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   168
{
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   169
	uint len;
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   170
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   171
	if (parm == NULL) return NULL;
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   172
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   173
	len = strlen(name);
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   174
	for (; *parm != NULL; parm++) {
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   175
		const char* p = *parm;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   176
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   177
		if (strncmp(p, name, len) == 0) {
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   178
			if (p[len] == '=')  return p + len + 1;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   179
			if (p[len] == '\0') return p + len;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   180
		}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   181
	}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   182
	return NULL;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   183
}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   184
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   185
bool GetDriverParamBool(const char* const* parm, const char* name)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   186
{
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   187
	return GetDriverParam(parm, name) != NULL;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   188
}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   189
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   190
int GetDriverParamInt(const char* const* parm, const char* name, int def)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   191
{
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   192
	const char* p = GetDriverParam(parm, name);
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   193
	return p != NULL ? atoi(p) : def;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   194
}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   195
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   196
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   197
void GetDriverList(char* p)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   198
{
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   199
	const DriverClass* dc;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   200
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   201
	for (dc = _driver_classes; dc != endof(_driver_classes); dc++) {
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   202
		const DriverDesc* dd;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   203
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   204
		p += sprintf(p, "List of %s drivers:\n", dc->name);
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   205
		for (dd = dc->descs; dd->name != NULL; dd++) {
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   206
			p += sprintf(p, "%10s: %s\n", dd->name, dd->longname);
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   207
		}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   208
	}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   209
}