diff options
author | Chris Apers | 2004-11-09 11:54:16 +0000 |
---|---|---|
committer | Chris Apers | 2004-11-09 11:54:16 +0000 |
commit | 28682e6d095fe4ac37f298c2bdde045021a25d75 (patch) | |
tree | 01687e13b89dd6b09f39a9ee84c1d4032ce627f6 | |
parent | fd2bde21d32a2ef72e34f71d02f37fdfc460c6d4 (diff) | |
download | scummvm-rg350-28682e6d095fe4ac37f298c2bdde045021a25d75.tar.gz scummvm-rg350-28682e6d095fe4ac37f298c2bdde045021a25d75.tar.bz2 scummvm-rg350-28682e6d095fe4ac37f298c2bdde045021a25d75.zip |
Major update :
- now modular
- modules are located on memory card and imported to storage memory when needed
- renamed AddArgs(..) -> ArgsAdd
- args related fucntions moved to args.* source files
- make some args passed even if no game was selected
- modules management stuffs
svn-id: r15770
-rw-r--r-- | backends/PalmOS/Src/launch.cpp | 455 |
1 files changed, 247 insertions, 208 deletions
diff --git a/backends/PalmOS/Src/launch.cpp b/backends/PalmOS/Src/launch.cpp index bff3de1452..4f2a654f12 100644 --- a/backends/PalmOS/Src/launch.cpp +++ b/backends/PalmOS/Src/launch.cpp @@ -1,53 +1,18 @@ #include <PalmOS.h> -#include <Sonyclie.h> #include "StarterRsc.h" -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> - #include "games.h" #include "start.h" #include "rumble.h" -#include "pa1lib.h" #include "extend.h" #include "globals.h" #include "features.h" +#include "formUtil.h" +#include "modules.h" +#include "args.h" -// need to move this on a .h file -#define sonySysFileCSystem 'SsYs' /* Sony overall System */ -#define sonySysFtrCreatorSystem sonySysFileCSystem - -#define sonySysFtrNumSystemBase 10000 -#define sonySysFtrNumSystemAOutSndStateOnHandlerP (sonySysFtrNumSystemBase + 4) -#define sonySysFtrNumSystemAOutSndStateOffHandlerP (sonySysFtrNumSystemBase + 5) - -typedef void (*sndStateOnType)(UInt8 /* kind */, UInt8 /* L volume 0-31 */, UInt8 /* R volume 0-31 */); -typedef void (*sndStateOffType)(UInt8 /* kind */); - -/* kind */ -#define aOutSndKindSp (0) /* Speaker volume */ -#define aOutSndKindHp (2) /* HeadPhone volume */ -//////////////////////////////////////////////////////////// -#define MAX_ARG 25 - -static void initARM() { - // init global ARM only - MemSet(gVars->arm, sizeof(gVars->arm), 0); - ARM(PNO_COPYRECT ).pnoPtr = _PnoInit(RSC_COPYRECT, &ARM(PNO_COPYRECT).pnoDesc); - ARM(PNO_COSTUMEPROC3).pnoPtr = _PceInit(RSC_COSTUMEPROC3); - ARM(PNO_DRAWSTRIP ).pnoPtr = _PceInit(RSC_DRAWSTRIP); - ARM(PNO_BLIT ).pnoPtr = _PnoInit(RSC_BLIT, &ARM(PNO_BLIT).pnoDesc); -} - -static void releaseARM() { - _PnoFree(&ARM(PNO_BLIT ).pnoDesc, ARM(PNO_BLIT).pnoPtr); - _PceFree(ARM(PNO_DRAWSTRIP ).pnoPtr); - _PceFree(ARM(PNO_COSTUMEPROC3 ).pnoPtr); - _PnoFree(&ARM(PNO_COPYRECT ).pnoDesc, ARM(PNO_COPYRECT).pnoPtr); -} - +/* static Boolean checkPath(const Char *pathP) { FILE *tmpRef; @@ -58,51 +23,144 @@ static Boolean checkPath(const Char *pathP) { return true; } } +*/ + +#define BUILD_FILE(h,m) \ + StrCopy(filename, "/Palm/Programs/ScummVM/Mods/"); \ + StrCat(filename, h); \ + StrCat(filename, m); + +#define CHECK_FILE() \ + e = VFSFileOpen(volRefNum, filename, vfsModeRead, &file); \ + if (e) \ + goto onError; \ + else \ + VFSFileClose(file); + +#define DELET_FILE(f) \ + del_dbID = DmFindDatabase(0, f); \ + if (del_dbID) \ + DmDeleteDatabase(0, del_dbID); + +void ModDelete() { + LocalID del_dbID; + + DELET_FILE("Glbs::Common"); + DELET_FILE("Glbs::Scumm"); + DELET_FILE("Glbs::Simon"); + DELET_FILE("Glbs::Queen"); + DELET_FILE("Glbs::Sword1"); + DELET_FILE("ScummVM-Engine"); +} -static void AddArg(Char **argvP, const Char *argP, const Char *parmP, UInt8 *countArgP) -{ - if (argP) - { - UInt16 len2 = 0; - UInt16 len1 = StrLen(argP); - - if (len1 > 0) - { - if (parmP) - len2 = StrLen(parmP); - - (*countArgP)++; - *argvP = (Char *)MemPtrNew(len1 + len2 + 1); - StrCopy(*argvP, argP); - - if (parmP) - StrCat(*argvP, parmP); +static void ModSetStack(UInt32 newSize, UInt16 cardNo, LocalID dbID) { + DmOpenRef dbRef = DmOpenDatabase(cardNo, dbID, dmModeReadWrite); + + if (dbRef) { + MemHandle pref = DmGetResource('pref',0); + UInt32 size = 0; + + if (pref) { + SysAppPrefsType *data = (SysAppPrefsType *)MemHandleLock(pref); + size = data->stackSize; + + if (newSize) { + SysAppPrefsType newData; + MemMove(&newData, data, sizeof(SysAppPrefsType)); + newData.stackSize = newSize; + DmWrite(data, 0, &newData, sizeof(SysAppPrefsType)); + } + + MemPtrUnlock(data); + DmReleaseResource(pref); } + + DmCloseDatabase(dbRef); } } +static Err ModImport(UInt16 volRefNum, UInt8 engine) { + const Char *files[] = { + { "scumm" }, + { "simon" }, + { "queen" }, + { "sword1" } + }; + + char filename[256]; + UInt16 dum1; + UInt32 dum2; + FileRef file; + Err e; + FormPtr ofmP, frmP; + + ofmP = FrmGetActiveForm(); + frmP = FrmInitForm(ImportForm); + FrmSetActiveForm(frmP); + FrmDrawForm(frmP); + + BUILD_FILE(files[engine], ".engine"); // engine file ? + CHECK_FILE(); + BUILD_FILE(files[engine], ".data"); // data file ? + CHECK_FILE(); + BUILD_FILE("common", ".data") // common data ? + CHECK_FILE(); + + BUILD_FILE("common", ".data"); + e = (e) ? e : VFSImportDatabaseFromFile(volRefNum, filename, &dum1, &dum2); + BUILD_FILE(files[engine], ".data"); + e = (e) ? e : VFSImportDatabaseFromFile(volRefNum, filename, &dum1, &dum2); + BUILD_FILE(files[engine], ".engine"); + e = (e) ? e : VFSImportDatabaseFromFile(volRefNum, filename, &dum1, &dum2); + + // if error, cleanup + if (e) ModDelete(); + +onError: + FrmEraseForm(frmP); + FrmDeleteForm(frmP); + if (e && ofmP) FrmSetActiveForm(ofmP); + + return e; +} + +#undef DELET_FILE +#undef CHECK_FILE +#undef BUILD_FILE + Boolean StartScummVM() { - Char *argvP[MAX_ARG]; - UInt8 argc = 0; - UInt8 count; + Char **argvP; + UInt8 lightspeed, argc = 0; + UInt32 stackSize; + Boolean toLauncher; + UInt8 engine; - Boolean autoOff; - UInt16 autoOffDelay; UInt16 musicDriver = sysInvalidRefNum; // for launch call - UInt16 index = GamGetSelected(); - for(count = 0; count < MAX_ARG; count++) - argvP[count] = NULL; + Char num[6]; + + argvP = ArgsInit(); + + if (index == dmMaxRecordIndex) { + UInt16 whichButton; + FormPtr frmP = FrmInitForm(EngineForm); + whichButton = FrmDoDialog(frmP); + FrmDeleteForm(frmP); + + if (whichButton == EngineCancelButton) + return false; + + engine = (whichButton - Engine0Button); - if (index != dmMaxRecordIndex) { + } else { Char pathP[256]; - Char num[6]; MemHandle recordH; GameInfoType *gameInfoP; recordH = DmQueryRecord(gameDB,index); gameInfoP = (GameInfoType *)MemHandleLock(recordH); + engine = gameInfoP->engine; // build path StrCopy(pathP,"/Palm/Programs/ScummVM/Games/"); @@ -115,31 +173,29 @@ Boolean StartScummVM() { if (!checkPath(pathP)) { MemHandleUnlock(recordH); FrmCustomAlert(FrmErrorAlert,"The specified path was not found !",0,0); + ArgsFree(argvP); return false; } */ + // ScummVM - AddArg(&argvP[argc], "-", NULL, &argc); + ArgsAdd(&argvP[argc], "-", NULL, &argc); // path - AddArg(&argvP[argc], "-p", pathP, &argc); + ArgsAdd(&argvP[argc], "-p", pathP, &argc); // language if (gameInfoP->language > 0) { const Char *lang = "en\0de\0fr\0it\0p\0es\0jp\0z\0kr\0hb\0ru\0cz\0nl\0"; - AddArg(&argvP[argc], "-q", (lang + (gameInfoP->language - 1) * 3), &argc); + ArgsAdd(&argvP[argc], "-q", (lang + (gameInfoP->language - 1) * 3), &argc); } // fullscreen ? if (gameInfoP->fullscreen) - AddArg(&argvP[argc], "-f", NULL, &argc); + ArgsAdd(&argvP[argc], "-f", NULL, &argc); // aspect-ratio ? - AddArg(&argvP[argc], (gameInfoP->aspectRatio ? "--aspect-ratio" : "--no-aspect-ratio"), NULL, &argc); - - // copy protection ? - if (gPrefs->copyProtection) - AddArg(&argvP[argc], "--copy-protection", NULL, &argc); + ArgsAdd(&argvP[argc], (gameInfoP->aspectRatio ? "--aspect-ratio" : "--no-aspect-ratio"), NULL, &argc); // gfx mode gVars->flipping.pageAddr1 = (UInt8 *)(BmpGetBits(WinGetBitmap(WinGetDisplayWindow()))); @@ -148,135 +204,126 @@ Boolean StartScummVM() { switch (gameInfoP->gfxMode) { case 1: - AddArg(&argvP[argc], "-g", "flipping", &argc); + ArgsAdd(&argvP[argc], "-g", "flipping", &argc); gVars->flipping.pageAddr1 = (UInt8 *)WinScreenLock(winLockDontCare); WinScreenUnlock(); break; case 2: - AddArg(&argvP[argc], "-g", "buffered", &argc); + ArgsAdd(&argvP[argc], "-g", "buffered", &argc); break; case 3: - AddArg(&argvP[argc], "-g", "wide", &argc); + ArgsAdd(&argvP[argc], "-g", "wide", &argc); gVars->flipping.pageAddr1 = (UInt8 *)WinScreenLock(winLockDontCare); WinScreenUnlock(); break; default: - AddArg(&argvP[argc], "-g", "normal", &argc); + ArgsAdd(&argvP[argc], "-g", "normal", &argc); break; } // load state if (gameInfoP->autoLoad) { StrIToA(num, gameInfoP->loadSlot); - AddArg(&argvP[argc], "-x", num, &argc); + ArgsAdd(&argvP[argc], "-x", num, &argc); } // boot script parameter if (gameInfoP->bootParam) { StrIToA(num, gameInfoP->bootValue); - AddArg(&argvP[argc], "-b", num, &argc); + ArgsAdd(&argvP[argc], "-b", num, &argc); } // not a PC version if (gameInfoP->setPlatform) { switch (gameInfoP->platform) { case 0: - AddArg(&argvP[argc], "--platform=", "amiga", &argc); + ArgsAdd(&argvP[argc], "--platform=", "amiga", &argc); break; case 1: - AddArg(&argvP[argc], "--platform=", "atari", &argc); + ArgsAdd(&argvP[argc], "--platform=", "atari", &argc); break; case 2: - AddArg(&argvP[argc], "--platform=", "mac", &argc); + ArgsAdd(&argvP[argc], "--platform=", "mac", &argc); break; case 3: - AddArg(&argvP[argc], "--platform=", "pc", &argc); + ArgsAdd(&argvP[argc], "--platform=", "pc", &argc); break; case 4: - AddArg(&argvP[argc], "--platform=", "fmtowns", &argc); + ArgsAdd(&argvP[argc], "--platform=", "fmtowns", &argc); break; case 5: - AddArg(&argvP[argc], "--platform=", "windows", &argc); + ArgsAdd(&argvP[argc], "--platform=", "windows", &argc); break; } } // subtitles if (gameInfoP->subtitles) - AddArg(&argvP[argc], "-n", NULL, &argc); - - // talk speed - if (gameInfoP->talkSpeed) { - StrIToA(num, gameInfoP->talkValue); - AddArg(&argvP[argc], "--talkspeed=", num, &argc); - } - // debug level - if (gPrefs->debug) { - StrIToA(num, gPrefs->debugLevel); - AddArg(&argvP[argc], "-d", num, &argc); - } - // demo mode ? - if (gPrefs->demoMode) - AddArg(&argvP[argc], "--demo-mode", NULL, &argc); - - // alternative intro ? - if (gPrefs->altIntro) - AddArg(&argvP[argc], "--alt-intro", NULL, &argc); + ArgsAdd(&argvP[argc], "-n", NULL, &argc); // multi midi ? if (gameInfoP->musicInfo.sound.multiMidi) - AddArg(&argvP[argc], "--multi-midi", NULL, &argc); + ArgsAdd(&argvP[argc], "--multi-midi", NULL, &argc); + + if (engine == ENGINE_SCUMM) { + // music tempo + StrIToA(num, gameInfoP->musicInfo.sound.tempo); + ArgsAdd(&argvP[argc], "--tempo=", num, &argc); + // talk speed + if (gameInfoP->talkSpeed) { + StrIToA(num, gameInfoP->talkValue); + ArgsAdd(&argvP[argc], "--talkspeed=", num, &argc); + } + } // music driver musicDriver =gameInfoP->musicInfo.sound.music; if (musicDriver) { switch (gameInfoP->musicInfo.sound.drvMusic) { case 0: // NULL - AddArg(&argvP[argc], "-e", "null", &argc); + ArgsAdd(&argvP[argc], "-e", "null", &argc); break; case 1: // built-in MIDI if (OPTIONS_TST(kOptDeviceZodiac)) - AddArg(&argvP[argc], "-e", "zodiac", &argc); // Tapwave Zodiac + ArgsAdd(&argvP[argc], "-e", "zodiac", &argc); // Tapwave Zodiac else if (OPTIONS_TST(kOptSonyPa1LibAPI)) - AddArg(&argvP[argc], "-e", "ypa1", &argc); // Pa1Lib devices + ArgsAdd(&argvP[argc], "-e", "ypa1", &argc); // Pa1Lib devices else - AddArg(&argvP[argc], "-e", "null", &argc); // error, no music driver + ArgsAdd(&argvP[argc], "-e", "null", &argc); // error, no music driver break; case 2: // PC Speaker - AddArg(&argvP[argc], "-e", "pcspk", &argc); + ArgsAdd(&argvP[argc], "-e", "pcspk", &argc); break; case 3: // IBM PCjr - AddArg(&argvP[argc], "-e", "pcjr", &argc); + ArgsAdd(&argvP[argc], "-e", "pcjr", &argc); case 4: // FM Towns - AddArg(&argvP[argc], "-e", "towns", &argc); + ArgsAdd(&argvP[argc], "-e", "towns", &argc); + case 5: // AdLib + ArgsAdd(&argvP[argc], "-e", "adlib", &argc); } } else // NULL as default - AddArg(&argvP[argc], "-e", "null", &argc); - - // music tempo - StrIToA(num, gameInfoP->musicInfo.sound.tempo); - AddArg(&argvP[argc], "--tempo=", num, &argc); + ArgsAdd(&argvP[argc], "-e", "null", &argc); // volume control StrIToA(num, gameInfoP->musicInfo.volume.master); - AddArg(&argvP[argc], "-o", num, &argc); + ArgsAdd(&argvP[argc], "-o", num, &argc); StrIToA(num, gameInfoP->musicInfo.volume.sfx); - AddArg(&argvP[argc], "-s", num, &argc); + ArgsAdd(&argvP[argc], "-s", num, &argc); StrIToA(num, gameInfoP->musicInfo.volume.music); - AddArg(&argvP[argc], "-m", num, &argc); + ArgsAdd(&argvP[argc], "-m", num, &argc); StrIToA(num, gameInfoP->musicInfo.volume.speech); - AddArg(&argvP[argc], "-r", num, &argc); + ArgsAdd(&argvP[argc], "-r", num, &argc); // output rate if (gameInfoP->musicInfo.sound.sfx) { UInt32 rates[] = {8000, 11025, 22050}; StrIToA(num, rates[gameInfoP->musicInfo.sound.rate]); - AddArg(&argvP[argc], "--output-rate=", num, &argc); + ArgsAdd(&argvP[argc], "--output-rate=", num, &argc); } // game name - AddArg(&argvP[argc], gameInfoP->gameP, NULL, &argc); + ArgsAdd(&argvP[argc], gameInfoP->gameP, NULL, &argc); // use sound if (!gameInfoP->musicInfo.sound.sfx) { @@ -295,108 +342,100 @@ Boolean StartScummVM() { MemHandleUnlock(recordH); } - if (argc > MAX_ARG) - FrmCustomAlert(FrmErrorAlert, "Too many parameters.",0,0); + // debug level + if (gPrefs->debug) { + StrIToA(num, gPrefs->debugLevel); + ArgsAdd(&argvP[argc], "-d", num, &argc); + } + + if (engine == ENGINE_QUEEN) { + // alternative intro ? + if (gPrefs->altIntro) + ArgsAdd(&argvP[argc], "--alt-intro", NULL, &argc); + } + + if (engine == ENGINE_SCUMM) { + // copy protection ? + if (gPrefs->copyProtection) + ArgsAdd(&argvP[argc], "--copy-protection", NULL, &argc); + // demo mode ? + if (gPrefs->demoMode) + ArgsAdd(&argvP[argc], "--demo-mode", NULL, &argc); + } + +// if (argc > MAX_ARG) +// FrmCustomAlert(FrmErrorAlert, "Too many parameters.",0,0); - gVars->skinSet = false; - gVars->pinUpdate = false; - GamCloseDatabase(false); - FrmCloseAllForms(); + gVars->skinSet = false; + gVars->pinUpdate= false; - autoOff = gPrefs->autoOff; - if (!autoOff) { - autoOffDelay = SysSetAutoOffTime(0); - EvtResetAutoOffTimer(); - } + stackSize = (gPrefs->setStack ? STACK_LARGER : STACK_DEFAULT); + lightspeed= (gPrefs->lightspeed.enable ? gPrefs->lightspeed.mode : 255); + toLauncher= (gPrefs->exitLauncher); + + // gVars values + // (gVars->HRrefNum defined in checkHRmode on Clié) + gVars->screenLocked = false; + gVars->volRefNum = gPrefs->card.volRefNum; + gVars->vibrator = gPrefs->vibrator; + gVars->stdPalette = gPrefs->stdPalette; - // gVars values - //gVars->HRrefNum defined in checkHRmode on Clié OS4 - gVars->screenLocked = false; - gVars->volRefNum = gPrefs->card.volRefNum; - gVars->vibrator = gPrefs->vibrator; - gVars->stdPalette = gPrefs->stdPalette; - gVars->autoReset = gPrefs->autoReset; - // user params + HWR_RSTALL(); + + if (!gPrefs->autoOff) + HWR_SET(INIT_AUTOOFF); + if (!gPrefs->arm) { OPTIONS_RST(kOptDeviceARM); OPTIONS_RST(kOptDeviceProcX86); + } else { + HWR_SET(INIT_ARM); } if (gVars->vibrator) - gVars->vibrator = RumbleInit(); - - // create file for printf, warnings, etc... - void DrawStatus(Boolean show); - StdioInit(gVars->volRefNum, "/PALM/Programs/ScummVM/scumm.log", DrawStatus); - gUnistdCWD = SCUMMVM_SAVEPATH; - - // TODO : move this to ypa1.cpp (?) - void *sndStateOnFuncP = NULL, - *sndStateOffFuncP = NULL; - - if (musicDriver == 1 || musicDriver == 3 || musicDriver == 4 || musicDriver == sysInvalidRefNum) { - - Pa1Lib_Open(); + HWR_SET(INIT_VIBRATOR); - // Don't work on T4xx and T6xx series ? - FtrGet(sonySysFtrCreatorSystem, sonySysFtrNumSystemAOutSndStateOnHandlerP, (UInt32*) &sndStateOnFuncP); - FtrGet(sonySysFtrCreatorSystem, sonySysFtrNumSystemAOutSndStateOffHandlerP, (UInt32*) &sndStateOffFuncP); - - if (sndStateOnFuncP && sndStateOffFuncP) { - ((sndStateOnType)(sndStateOnFuncP))(aOutSndKindSp, 31, 31); - ((sndStateOnType)(sndStateOnFuncP))(aOutSndKindHp, 31, 31); - } + if ( musicDriver == 1 || + musicDriver == 3 || + musicDriver == 4 || + musicDriver == sysInvalidRefNum) { + HWR_SET(INIT_PA1LIB); + } - Pa1Lib_devHpVolume(31, 31); - Pa1Lib_devSpVolume(31); + if (ModImport(gVars->volRefNum, engine) != errNone) { + FrmCustomAlert(FrmErrorAlert, "Error importing files:\nplease check that all required files are installed on the selected memory card, and you have enough free storage memory.", 0, 0); + ArgsFree(argvP); + return false; } - // ------------- - SavePrefs(); // free globals pref memory - GlbOpen(); - initARM(); - - // reset screen depth + // free and save globals pref memory + GamCloseDatabase(false); + FrmCloseAllForms(); + SavePrefs(); + { - UInt32 depth = 8; - WinScreenMode(winScreenModeSet, NULL, NULL, &depth, NULL); - } + UInt16 cardNo; + UInt32 dbID; - DO_EXIT( main(argc, argvP); ) - - // be sure to release feature memory - FREE_FTR(ftrBufferOverlay) - FREE_FTR(ftrBufferBackup) - FREE_FTR(ftrBufferHotSwap) - - releaseARM(); - GlbClose(); - - // TODO : move this to ypa1.cpp (?) - if (musicDriver == 1 || musicDriver == 3 || musicDriver == 4 || musicDriver == sysInvalidRefNum) { - if (sndStateOnFuncP && sndStateOffFuncP) { - ((sndStateOffType)(sndStateOffFuncP))(aOutSndKindSp); - ((sndStateOffType)(sndStateOffFuncP))(aOutSndKindHp); - } + LaunchParamType *cmdPBP = (LaunchParamType *)MemPtrNew(sizeof(LaunchParamType)); - Pa1Lib_Close(); - } - // ------------- + MemPtrSetOwner(cmdPBP, 0); + MemPtrSetOwner(gVars, 0); + ArgsSetOwner(argvP, 0); - // close log file - StdioRelease(); + cardNo = 0; + dbID = DmFindDatabase(0, "ScummVM-Engine"); + ModSetStack(stackSize, cardNo, dbID); - for(count = 0; count < MAX_ARG; count++) - if (argvP[count]) - MemPtrFree(argvP[count]); - - if (gVars->vibrator) - RumbleRelease(); + cmdPBP->args.argc = argc; + cmdPBP->args.argv = argvP; + cmdPBP->gVars = gVars; + cmdPBP->lightspeed = lightspeed; + cmdPBP->exitLauncher = toLauncher; - if (!autoOff) { - SysSetAutoOffTime(autoOffDelay);SystemPreferencesChoice - EvtResetAutoOffTimer(); + SysUIAppSwitch(cardNo, dbID, sysAppLaunchCmdNormalLaunch, cmdPBP); + bLaunched = true; } return false; |