-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.c
353 lines (305 loc) · 9.7 KB
/
misc.c
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/************************************************************************
* misc.c
* Miscellaneous functions
*
************************************************************************
*
* Phoinix,
* Nintendo Gameboy(TM) emulator for the Palm OS(R) Computing Platform
*
* (c)2000-2005 Bodo Wenzel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
************************************************************************
* History:
*
* $Log: misc.c,v $
* Revision 1.20 2005/10/11 14:48:05 bodowenzel
* Centralized device type into MiscDevice
*
* Revision 1.19 2005/05/03 08:41:22 bodowenzel
* Insert forgotten DmReleaseResource() call
* Moved SetBackupBit here from states.c
*
* Revision 1.18 2005/01/30 19:36:18 bodowenzel
* Support for LC_Lite
*
* Revision 1.17 2005/01/29 10:25:37 bodowenzel
* Added const qualifier to pointer parameters
*
* Revision 1.16 2005/01/28 17:35:13 bodowenzel
* Manager form uses a scrollable table now for the list of games
*
* Revision 1.15 2004/12/28 13:58:21 bodowenzel
* Support for devices without direct screen access
*
* Revision 1.14 2004/12/02 20:02:16 bodowenzel
* Utility function MiscGetObjectPointer()
*
* Revision 1.13 2004/10/18 17:48:51 bodowenzel
* Dropped macro LITE, no need to maintain smaller code
*
* Revision 1.12 2004/09/19 12:35:54 bodowenzel
* Enhanced error reporting with string parameter
*
* Revision 1.11 2004/06/20 14:23:20 bodowenzel
* VFS mount and unmount support
*
* Revision 1.10 2004/06/11 16:16:43 bodowenzel
* Review and cleanup of miscErr* constants and texts
* Work-around for 'Freeze' error in MiscShowBusy() removed
*
* Revision 1.9 2004/03/02 19:24:16 bodowenzel
* Changed to new error function MiscShowError()
*
* Revision 1.8 2004/01/11 19:08:24 bodowenzel
* Work-around for 'Freeze' error
*
* Revision 1.7 2003/04/27 09:36:18 bodowenzel
* Added Lite edition
*
* Revision 1.6 2003/04/19 13:16:45 bodowenzel
* New variable MiscIsOs5 indicates OS5
*
* Revision 1.5 2002/11/02 15:53:41 bodowenzel
* Check for OS 5 added
*
* Revision 1.4 2002/10/23 16:34:35 bodowenzel
* Busy form centralized
*
* Revision 1.3 2002/10/19 08:08:11 bodowenzel
* History cleanup, Javadoc-style header
*
* Revision 1.2 2001/12/30 18:47:11 bodowenzel
* CVS keyword Log was faulty
*
* Revision 1.1.1.1 2001/12/16 13:38:02 bodowenzel
* Import
*
************************************************************************
*/
/* IMPORTANT!
* Please make sure that any referenced resource is included!
* Unfortunately there is no automatic!
*/
/* === Includes ======================================================= */
#include <PalmOS.h>
#include "Phoinix.h"
#ifdef handera
/* Handera H330 support */
#include <HandEra/Vga.h>
#endif
#ifdef alphasmart
/* AlphaSmart Dana support */
#include <Screen.h>
#endif
#ifdef fossil
/* Fossil WristPDA support */
#include <WristPDA.h>
#endif
#include "misc.h"
/* === Global variables =============================================== */
MiscDeviceType MiscDevice;
/* last posted error, set to miscErrNone after showing */
static MiscErrorType ErrMainIndex;
static MiscErrorType ErrDetailIndex;
static const Char *ErrParameter;
/* === Test for OS version ============================================ */
/**
* Checks for the required OS version.
*
* @param minV value as calculated by sysMakeROMVersion().
* @param maxV value as calculated by sysMakeROMVersion().
* @param launchFlags flags given by the launcher.
* @return error code, errNone if all is OK.
*/
Err MiscRomVersionCompatible(UInt32 minV, UInt32 maxV,
Int16 launchFlags) {
UInt32 version;
/* check for certain devices */
MiscDevice = miscDeviceStandard;
#ifdef handera
if (FtrGet(TRGSysFtrID, TRGVgaFtrNum, &version) == errNone) {
MiscDevice = miscDeviceH330;
}
#endif
#ifdef alphasmart
if (FtrGet(AlphaSmartSysFtrID, ScrnFtrNum, &version)
== errNone) {
MiscDevice = miscDeviceDana;
}
#endif
#ifdef fossil
if (FtrGet(WPdaCreator, WPdaFtrNumVersion, &version)
== errNone) {
MiscDevice = miscDeviceWrist;
}
#endif
FtrGet(sysFtrCreator, sysFtrNumROMVersion, &version);
if (version >= minV && version < maxV) {
return errNone;
}
if ((launchFlags &
(sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) ==
(sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) {
MiscShowError(miscErrInitialization, miscErrSystemVersion, NULL);
if (version < sysMakeROMVersion(2, 0, 0, sysROMStageDevelopment, 0)) {
/* on OS version before 2 the launcher was just a pop-up! */
AppLaunchWithCommand(sysFileCDefaultApp,
sysAppLaunchCmdNormalLaunch, NULL);
}
}
return sysErrRomIncompatible;
}
/* === The "About..." form ============================================ */
/**
* Shows the about form. With the 'Lite' resource set, only the help
* string is shown.
*/
void MiscShowAbout(void) {
MemHandle rsrcH;
rsrcH = DmGetResource('tFRM', formIdAbout);
if (rsrcH != NULL) {
FormType *prevFrmP, *frmP;
DmReleaseResource(rsrcH);
/* prepare new form */
prevFrmP = FrmGetActiveForm();
frmP = FrmInitForm(formIdAbout);
FrmSetActiveForm(frmP);
/* wait until the form returns */
FrmDoDialog(frmP);
/* cleanup and return */
if (prevFrmP != NULL) {
FrmSetActiveForm(prevFrmP);
}
FrmDeleteForm(frmP);
} else {
FrmHelp(helpIdAbout);
}
}
/* === The "Busy..." form ============================================= */
/**
* Draws or removes the form.
*/
void MiscShowBusy(Boolean on) {
static WinHandle oldWinH;
static FormActiveStateType theFormState;
static FormType *frmP;
if (on) {
FrmSaveActiveState(&theFormState);
oldWinH = WinGetDrawWindow();
frmP = FrmInitForm(formIdBusy);
FrmSetActiveForm(frmP);
FrmDrawForm(frmP);
} else {
FrmEraseForm(frmP);
FrmDeleteForm(frmP);
WinSetDrawWindow(oldWinH);
FrmRestoreActiveState(&theFormState);
}
}
/* === Showing errors ================================================= */
/* To get errors displayed "between" switching forms (that is, one form
* was just closed, but a new form is not yet open), errors are posted in
* the event queue.
* To show the last error when stopping the application, the variable
* ErrMainIndex is read. If it doesn't contain miscErrNone, the error is
* shown.
*/
/**
* Posts an event to show the error form.
*
* @param errorIndex index to main string.
* @param detailIndex index to detail string.
* @param parameter pointer to string, must be static.
*/
void MiscPostError(MiscErrorType mainIndex, MiscErrorType detailIndex,
const Char *parameter) {
EventType evt;
ErrMainIndex = mainIndex;
ErrDetailIndex = detailIndex;
ErrParameter = parameter;
MemSet(&evt, sizeof(evt), 0);
evt.eType = phoinixErrorEvent;
EvtAddEventToQueue(&evt);
}
/**
* Shows a pending error.
*/
void MiscShowPendingError(void) {
if (ErrMainIndex != miscErrNone) {
MiscShowError(ErrMainIndex, ErrDetailIndex, ErrParameter);
ErrMainIndex = miscErrNone;
}
}
/**
* Shows the error form.
*
* @param errorIndex index to main string.
* @param detailIndex index to detail string.
* @param parameter pointer to string, must be static.
*/
void MiscShowError(MiscErrorType mainIndex, MiscErrorType detailIndex,
const Char *parameter) {
Char mainLine[miscErrorStringMaxLength];
Char detailLine[miscErrorStringMaxLength];
SysStringByIndex(stblIdError, detailIndex, detailLine,
miscErrorStringMaxLength);
if (detailLine[0] == '\0') {
if (parameter == NULL) {
StrPrintF(detailLine, "(Minor error #%u)", detailIndex);
} else {
StrPrintF(detailLine, "(Minor error #%u\n\"%s\")", detailIndex,
parameter);
}
} else if (parameter != NULL) {
StrCopy(mainLine, detailLine);
StrPrintF(detailLine, mainLine, parameter);
}
SysStringByIndex(stblIdError, mainIndex, mainLine,
miscErrorStringMaxLength);
if (mainLine[0] == '\0') {
StrPrintF(mainLine, "(Major error #%u)", mainIndex);
}
FrmCustomAlert(alertIdError, mainLine, detailLine, NULL);
}
/* === Helper functions =============================================== */
/**
* Sets the backup bit for the given database.
*
* @param dbP reference of the database.
*/
void MiscSetBackupBit(DmOpenRef dbP) {
LocalID dbId;
UInt16 cardNo;
UInt16 attr;
DmOpenDatabaseInfo(dbP, &dbId, NULL, NULL, &cardNo, NULL);
DmDatabaseInfo(cardNo, dbId, NULL, &attr, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
attr |= dmHdrAttrBackup;
DmSetDatabaseInfo(cardNo, dbId, NULL, &attr, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL);
}
/**
* Return a pointer to the data structure of an object in a form.
*
* @param frmP pointer to the form.
* @param id ID of the object.
* @return pointer to the data structure.
*/
void *MiscGetObjectPtr(const FormType *frmP, UInt16 id) {
return FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, id));
}
/* === The end ======================================================== */