1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#include "common/scummsys.h"
#include <SDL/SDL.h>
#include "backends/platform/openpandora/op-sdl.h"
#include "backends/plugins/posix/posix-provider.h"
#include "base/main.h"
#include "common/archive.h"
#include "common/config-manager.h"
#include "common/debug.h"
#include "common/events.h"
#include "common/util.h"
#include "common/file.h"
#include "base/main.h"
#include "backends/saves/default/default-saves.h"
#include "backends/timer/default/default-timer.h"
#include "sound/mixer_intern.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <sys/stat.h>
#include <time.h> // for getTimeAndDate()
/* Dump console info to files. */
#define DUMP_STDOUT
static SDL_Cursor *hiddenCursor;
int main(int argc, char *argv[]) {
g_system = new OSystem_OP();
assert(g_system);
#ifdef DYNAMIC_MODULES
PluginManager::instance().addPluginProvider(new POSIXPluginProvider());
#endif
// Invoke the actual ScummVM main entry point:
int res = scummvm_main(argc, argv);
g_system->quit();
return res;
}
static Uint32 timer_handler(Uint32 interval, void *param) {
((DefaultTimerManager *)param)->handler();
return interval;
}
void OSystem_OP::initBackend() {
assert(!_inited);
uint8_t hiddenCursorData = 0;
int joystick_num = ConfMan.getInt("joystick_num");
uint32 sdlFlags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
if (ConfMan.hasKey("disable_sdl_parachute"))
sdlFlags |= SDL_INIT_NOPARACHUTE;
if (joystick_num > -1)
sdlFlags |= SDL_INIT_JOYSTICK;
if (SDL_Init(sdlFlags) == -1) {
error("Could not initialize SDL: %s", SDL_GetError());
}
hiddenCursor = SDL_CreateCursor(&hiddenCursorData, &hiddenCursorData, 8, 1, 0, 0);
/* Setup default save path to be workingdir/saves */
char savePath[PATH_MAX+1];
char workDirName[PATH_MAX+1];
if (getcwd(workDirName, PATH_MAX) == NULL) {
error("Could not obtain current working directory.");
} else {
printf("Current working directory: %s\n", workDirName);
}
strcpy(savePath, workDirName);
strcat(savePath, "/../saves");
printf("Current save directory: %s\n", savePath);
struct stat sb;
if (stat(savePath, &sb) == -1)
if (errno == ENOENT) // Create the dir if it does not exist
if (mkdir(savePath, 0755) != 0)
warning("mkdir for '%s' failed!", savePath);
_savefile = new DefaultSaveFileManager(savePath);
#ifdef DUMP_STDOUT
// The OpenPandora has a serial console on the EXT connection but most users do not use this so we
// output all our STDOUT and STDERR to files for debug purposes.
char STDOUT_FILE[PATH_MAX+1];
char STDERR_FILE[PATH_MAX+1];
strcpy(STDOUT_FILE, workDirName);
strcpy(STDERR_FILE, workDirName);
strcat(STDOUT_FILE, "/scummvm.stdout.txt");
strcat(STDERR_FILE, "/scummvm.stderr.txt");
// Flush the output in case anything is queued
fclose(stdout);
fclose(stderr);
// Redirect standard input and standard output
FILE *newfp = freopen(STDOUT_FILE, "w", stdout);
if (newfp == NULL) {
#if !defined(stdout)
stdout = fopen(STDOUT_FILE, "w");
#else
newfp = fopen(STDOUT_FILE, "w");
if (newfp) {
*stdout = *newfp;
}
#endif
}
newfp = freopen(STDERR_FILE, "w", stderr);
if (newfp == NULL) {
#if !defined(stderr)
stderr = fopen(STDERR_FILE, "w");
#else
newfp = fopen(STDERR_FILE, "w");
if (newfp) {
*stderr = *newfp;
}
#endif
}
setbuf(stderr, NULL);
printf("%s\n", "Debug: STDOUT and STDERR redirected to text files.");
#endif /* DUMP_STDOUT */
/* Trigger autosave every 4 minutes. */
ConfMan.registerDefault("autosave_period", 4 * 60);
ConfMan.registerDefault("fullscreen", true);
/* Make sure that aspect ratio correction is enabled on the 1st run to stop
users asking me what the 'wasted space' at the bottom is ;-). */
ConfMan.registerDefault("aspect_ratio", true);
/* Make sure SDL knows that we have a joystick we want to use. */
ConfMan.setInt("joystick_num", 0);
_graphicsMutex = createMutex();
/* On the OpenPandora we need to work around an SDL assumption that
returns relative mouse coordinates when you get to the screen
edges using the touchscreen. The workaround is to set a blank
SDL cursor and not disable it (Hackish I know).
The root issues likes in the Windows Manager GRAB code in SDL.
That is why the issue is not seen on framebuffer devices like the
GP2X (there is no X window manager ;)).
*/
SDL_ShowCursor(SDL_ENABLE);
SDL_SetCursor(hiddenCursor);
// Enable unicode support if possible
SDL_EnableUNICODE(1);
memset(&_oldVideoMode, 0, sizeof(_oldVideoMode));
memset(&_videoMode, 0, sizeof(_videoMode));
memset(&_transactionDetails, 0, sizeof(_transactionDetails));
_videoMode.mode = GFX_DOUBLESIZE;
_videoMode.scaleFactor = 2;
_videoMode.aspectRatioCorrection = ConfMan.getBool("aspect_ratio");
_scalerProc = Normal2x;
_scalerType = 0;
_videoMode.fullscreen = true;
// enable joystick
if (joystick_num > -1 && SDL_NumJoysticks() > 0) {
printf("Using joystick: %s\n", SDL_JoystickName(0));
_joystick = SDL_JoystickOpen(joystick_num);
}
setupMixer();
// Note: We could implement a custom SDLTimerManager by using
// SDL_AddTimer. That might yield better timer resolution, but it would
// also change the semantics of a timer: Right now, ScummVM timers
// *never* run in parallel, due to the way they are implemented. If we
// switched to SDL_AddTimer, each timer might run in a separate thread.
// However, not all our code is prepared for that, so we can't just
// switch. Still, it's a potential future change to keep in mind.
_timer = new DefaultTimerManager();
_timerID = SDL_AddTimer(10, &timer_handler, _timer);
// Invoke parent implementation of this method
OSystem::initBackend();
_inited = true;
}
void OSystem_OP::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
/* Setup default extra data paths for engine data files and plugins */
char workDirName[PATH_MAX+1];
if (getcwd(workDirName, PATH_MAX) == NULL) {
error("Error: Could not obtain current working directory.");
}
char enginedataPath[PATH_MAX+1];
strcpy(enginedataPath, workDirName);
strcat(enginedataPath, "/../data");
printf("Default engine data directory: %s\n", enginedataPath);
Common::FSNode engineNode(enginedataPath);
if (engineNode.exists() && engineNode.isDirectory()) {
s.add("__OP_ENGDATA__", new Common::FSDirectory(enginedataPath), priority);
}
}
void OSystem_OP::quit() {
SDL_FreeCursor(hiddenCursor);
#ifdef DUMP_STDOUT
printf("%s\n", "Debug: STDOUT and STDERR text files closed.");
fclose(stdout);
fclose(stderr);
#endif /* DUMP_STDOUT */
OSystem_SDL::quit();
}
|