示例#1
0
Boolean IntlSetStrictChecks(Boolean iStrictChecks)
{
	Boolean oldSetting;
	UInt32 flags;
	Err result;
	
	// Global flags has precedence over feature value.
	oldSetting = (GIntlData->intlFlags & kStrictChecksFlag) != 0;
	 
	result = FtrGet(sysFtrCreator, sysFtrNumIntlMgr, &flags);
	ErrNonFatalDisplayIf(result != errNone, "Can't get sysFtrNumIntlMgr feature");
	if (iStrictChecks)
	{
		flags |= intlMgrStrict;
		GIntlData->intlFlags |= kStrictChecksFlag;
	}
	else
	{
		flags &= ~intlMgrStrict;
		GIntlData->intlFlags &= ~kStrictChecksFlag;
	}
	
	result = FtrSet(sysFtrCreator, sysFtrNumIntlMgr, flags);
	ErrNonFatalDisplayIf(result != errNone, "Can't set sysFtrNumIntlMgr feature");
	
	return(oldSetting);
} // IntlSetStrictChecks
示例#2
0
Err zlib_close(UInt16 ref, UInt16 *numop) {
  UInt32 val = 0;
  *numop = 0;

  FtrGet('ZLib', ref, &val);
  if( val <= 0 )
    return -1;

  FtrSet('ZLib', ref, --val);
  *numop = val;
  return 0;
}
示例#3
0
void run(int argc, char *argv[]) {
	// init args
	ArgsExportInit(argv, argc, true);

	// init system
	PalmHRInit(16);
	PalmInit(HWR_GET());
	void *__ptr = StuffsForceVG();

	gVars->screenPitch = StuffsGetPitch(gVars->screenFullWidth);

	// export global struct to ARM
	VARS_EXPORT();
	DO_VARS(_4B, 32, 0);
	DO_VARS(_2B, 16, (gVars->_4B * sizeof(UInt32)));
	FtrSet(appFileCreator, ftrVars , (UInt32)gVars);

	// run the module
#ifdef COMPILE_ZODIAC
	NativeFuncType *entry;
	TwLoadModule(0, 0, 0, 1, twLoadFlagTNA|twLoadFlagQuickRun, &entry);
#else
	UInt32 glue;
	FtrGet(twFtrCreator, twFtrAPIGlue, &glue);

	PnoDescriptor pno;
	PnoLoadFromResources(&pno, 'ARMC', 1, appFileCreator, 1);
	PnoCall(&pno, (void*)glue);
	PnoUnload(&pno);
#endif

	// reset globals
	DO_VARS(_4B, 32, 0);
	DO_VARS(_2B, 16, (gVars->_4B * sizeof(UInt32)));

	// release
	StuffsReleaseVG(__ptr);
	PalmRelease(HWR_GET());
	PalmHRRelease();

	// free args
	ArgsExportRelease(true);
	ArgsFree(argv);

	// release global struct
	FtrUnregister(appFileCreator, ftrVars);
	FtrUnregister(appFileCreator, ftrStack);
	MemPtrFree(gVars);

	// reset the palette if needed
	WinPalette(winPaletteSetToDefault, 0, 256, NULL);
}
示例#4
0
文件: Atlas.c 项目: openmobl/Atlas
static Boolean InitGlobals(void)
{
    GlobalsPtr  gP  = NULL;
    
    gP = (GlobalsPtr)MemPtrNew(sizeof(GlobalsType));
    if (!gP) {
        return false;
    }
    MemSet(gP, sizeof(GlobalsType), 0);
    FtrSet(kAppFileCreator, ftrGlobals, (UInt32)gP);
    
    return true;
}
示例#5
0
bool handleProcessSoftKeyStroke(PointType * start, PointType * end)
{
   Err err;
   UInt32 romVersion;
   RexxletHackPrefs * prefs = 0;
   
   // For romVersion-specific behavior.
   FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
   if (romVersion < sysMakeROMVersion(3, 0, 0, sysROMStageRelease, 0)) {
      goto passthru;
   }

   // Avoid re-entering, only because there's typically not enough
   // stack space to handle this.  If we did our own stack, then maybe...
   UInt32 isRexxletRunning = 0;
   err = FtrGet(CREATORID, FEATURE_ISREXXLETRUNNING, &isRexxletRunning);
   if (err == errNone && isRexxletRunning == 1) { goto passthru; }
   
   // Set prefs and check to see if this is our custom penstroke.
   // If not, pass it thru.
   prefs = RexxletHackPrefs__ctor();
   Int16 strokeIndex = myStroke(start, end, prefs);
   if (strokeIndex == -1) { goto passthru; }
   StrokeDescriptor * stroke = RexxletHackPrefs__strokeDescriptor(prefs, strokeIndex);

   // Set up the Rexxlet launch code's param type.
   struct RexxAppLaunchRexxletParamType r;
   MemSet((void *)&r, sizeof(struct RexxAppLaunchRexxletParamType), 0);
   r.iflags.pauseWhenDone = stroke->flags.pauseWhenDone;
   r.iflags.copyAndPaste = stroke->flags.copyAndPaste;  
   r.iflags.defaultInput = stroke->flags.defaultInput;
   r.iflags.defaultOutput = stroke->flags.defaultOutput;
   r.iflags.defaultError = stroke->flags.defaultError;  
   r.script = RexxletHackPrefs__url(prefs, strokeIndex + 1);
   // allow a null script...it will pop up the url dialog to prompt for one
   //   if (r.script == 0 || StrLen(r.script) == 0) {
   //      goto passthru;
   //   }
   r.iflags.args = stroke->flags.args;
   if (stroke->flags.args == RexxAppLaunchRexxletParamType::ARGS_SELECTION) {
      FieldType * activeField = MyFrmGetActiveField();
	   if (activeField) {
	      UInt16 startPosition, endPosition;
	      FldGetSelection(activeField, &startPosition, &endPosition);
	      Int32 len = endPosition - startPosition;
	      if (len > 0) {
	         char * p = FldGetTextPtr(activeField);
	         if (p) {
	            r.args = (char *)MemPtrNew(len + 1);
	            if (r.args) {
	               MemMove(r.args, &p[startPosition], len);
	               r.args[len] = '\0';
	            }
	         }
	      }
	   }
   }

   // no more literal scripts...could be done if we really wanted, e.g.,
   // not in the configuration (we don't want to store scripts in prefs),
   // but instead to allow the user to use the current selection as the script,
   // much in the same way we allow the clipboard, e.g., selection:   
   // r.script = "say \"This is the identity Rexxlet! Enter something to return, and press Enter when done:\"; parse pull x; return x";
   // r.script = "say \"Please enter numbers to add and press Enter when done:\"; parse pull n; r=0; do i=1 to words(n); if datatype(word(n,i))=\"NUM\" then r=r+word(n,i); end; return r";
   // r.script = "parse arg s; say s; return s";  // PGR idea:  use currently selected text!
   
   if (romVersion < sysMakeROMVersion(5, 0, 0, sysROMStageRelease, 0)) {
      EvtFlushNextPenStroke();
   }
   
   // Remember that a rexxlet is active because we're not
   // going to allow then to be "stacked" for now...not enough stack space!
	FtrSet(CREATORID, FEATURE_ISREXXLETRUNNING, 1);
   Rexxlet(r);
	FtrSet(CREATORID, FEATURE_ISREXXLETRUNNING, 0);
		
	if (r.args && stroke->flags.args == RexxAppLaunchRexxletParamType::ARGS_SELECTION) {
	   MemPtrFree(r.args);
	}
	if (prefs) { RexxletHackPrefs__dtor(prefs); }
	return true;
	
passthru:   
	if (prefs) { RexxletHackPrefs__dtor(prefs); }
	return false;
}
示例#6
0
Boolean StartScummVM() {
	Char **argvP;
	UInt8 lightspeed, argc	= 0;
	UInt32 stackSize;
	Boolean toLauncher, direct, isARM;
	UInt8 engine;
	Char num[6];

	UInt16 index = GamGetSelected();

	argvP = ArgsInit();
	direct = false;

	// start command line (exec name)
	ArgsAdd(&argvP[argc], "-", NULL, &argc);

	// no game selected
	if (index == dmMaxRecordIndex) {
		ListPtr listP;
		UInt16 whichButton;
		
		// init form
		FormPtr frmP = FrmInitForm(EngineForm);
		listP = (ListType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, EngineListList));
		itemsText = (Char **)MemPtrNew(ENGINE_COUNT * sizeof(Char *));
		
		for (int i = 0; i < ENGINE_COUNT; i++)
			itemsText[i] = (Char *)engines[i].nameP;
			
		LstSetListChoices (listP, itemsText, ENGINE_COUNT);
		LstSetSelection(listP, 0);	
		
		whichButton = FrmDoDialog(frmP);
		engine = LstGetSelection(listP);

		FrmDeleteForm(frmP);
		MemPtrFree(itemsText);
		itemsText = NULL;
		
		if (whichButton == EngineCancelButton) {
			if (bDirectMode) {
				// and force exit if nothing selected
				EventType event;
				event.eType = keyDownEvent;
				event.data.keyDown.chr = vchrLaunch;
				event.data.keyDown.modifiers = commandKeyMask;
				EvtAddUniqueEventToQueue(&event, 0, true);
			}
			// free args
			ArgsFree(argvP);
			return false;
		}

		// default values
		if (bDirectMode)
			gPrefs->card.volRefNum = parseCards();	// always use the first removable card available (?)
		gVars->filter		= true;
		gVars->palmVolume	= 50;
		gVars->fmQuality	= FM_QUALITY_INI;
		direct = true;

	// somthing selected
	} else {
		Char pathP[256];
		MemHandle recordH;
		GameInfoType *gameInfoP;

		recordH = DmQueryRecord(gameDB,index);
		gameInfoP = (GameInfoType *)MemHandleLock(recordH);
		engine = gameInfoP->engine;

		// build path
		StrCopy(pathP,"/Palm/Programs/ScummVM/Games/");
		if (gameInfoP->pathP[0] == '/')
			StrCopy(pathP, gameInfoP->pathP);
		else if (!(gameInfoP->pathP[0] == '.' && StrLen(gameInfoP->pathP) == 1))
			StrCat(pathP, gameInfoP->pathP);

		// path
		ArgsAdd(&argvP[argc], "-p", pathP, &argc);

		// language
		if (gameInfoP->language > 0) {
			const Char *lang = "zh\0cz\0gb\0en\0fr\0de\0hb\0it\0jp\0kr\0pl\0pt\0ru\0es\0se\0";
			ArgsAdd(&argvP[argc], "-q", (lang + (gameInfoP->language - 1) * 3), &argc);
		}

		// fullscreen ?
		if (gameInfoP->fullscreen)
			ArgsAdd(&argvP[argc], "-f", NULL, &argc);

		// aspect-ratio ?
		ArgsAdd(&argvP[argc], (gameInfoP->aspectRatio ? "--aspect-ratio" : "--no-aspect-ratio"), NULL, &argc);

		// gfx mode
		gVars->filter = gameInfoP->filter;

		switch (gameInfoP->renderMode) {
			case 1:
				ArgsAdd(&argvP[argc], "--render-mode=", "amiga", &argc);
				break;
			case 2:
				ArgsAdd(&argvP[argc], "--render-mode=", "cga", &argc);
				break;
			case 3:
				ArgsAdd(&argvP[argc], "--render-mode=", "ega", &argc);
				break;
			case 4:
				ArgsAdd(&argvP[argc], "--render-mode=", "hercAmber", &argc);
				break;
			case 5:
				ArgsAdd(&argvP[argc], "--render-mode=", "hercGreen", &argc);
				break;
		}		

		switch (gameInfoP->gfxMode)	{
			case 1:
				ArgsAdd(&argvP[argc], "-g", "wide", &argc);
				break;
			default:
				ArgsAdd(&argvP[argc], "-g", "1x", &argc);
				break;
		}

		// load state
		if (gameInfoP->autoLoad) {
			StrIToA(num, gameInfoP->loadSlot);
			ArgsAdd(&argvP[argc], "-x", num, &argc);
		}
		// boot script parameter
		if (gameInfoP->bootParam) {
			StrIToA(num, gameInfoP->bootValue);
			ArgsAdd(&argvP[argc], "-b", num, &argc);
		}
		// not a PC version
		if (gameInfoP->setPlatform) {
			static const char *platform[] = {
				"3do",
				"acorn",
				"amiga",
				"atari",
				"c64",
				"pc",
				"fmtowns",
				"linux",
				"mac",
				"nes",
				"segacd",
				"windows"
			};
			ArgsAdd(&argvP[argc], "--platform=", platform[gameInfoP->platform], &argc);	
		}

		// subtitles
		if (gameInfoP->subtitles)
			ArgsAdd(&argvP[argc],  "-n", NULL, &argc);

		// multi midi ?
		if (gameInfoP->musicInfo.sound.multiMidi)
			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
		if (gameInfoP->musicInfo.sound.music) {
			static char *drv[] = {
				"auto",
				"null",
				"adlib",
				"towns",
				"pcjr",
				"native",
				"pcspk"
			};

			if (StrCompare(drv[gameInfoP->musicInfo.sound.drvMusic], "native") == 0) {
				if (OPTIONS_TST(kOptDeviceZodiac))
					ArgsAdd(&argvP[argc], "-e", "zodiac", &argc);	// Tapwave Zodiac
				else if (OPTIONS_TST(kOptSonyPa1LibAPI))
					ArgsAdd(&argvP[argc], "-e", "ypa1", &argc);		// Pa1Lib devices
				else
					ArgsAdd(&argvP[argc], "-e", "auto", &argc);		// no driver, switch to auto
			} else {
				ArgsAdd(&argvP[argc], "-e", drv[gameInfoP->musicInfo.sound.drvMusic], &argc);	
			}

			// output rate
			UInt32 rates[] = {4000, 8000, 11025, 22050, 44100};
			StrIToA(num, rates[gameInfoP->musicInfo.sound.rate]);
			ArgsAdd(&argvP[argc], "--output-rate=", num, &argc);

			// FM quality
			gVars->fmQuality = gameInfoP->fmQuality;

		} else {
			ArgsAdd(&argvP[argc], "-e", "null", &argc);
		}

		// volume control
		StrIToA(num, gameInfoP->musicInfo.volume.sfx);
		ArgsAdd(&argvP[argc], "-s", num, &argc);
		StrIToA(num, gameInfoP->musicInfo.volume.music);
		ArgsAdd(&argvP[argc], "-m", num, &argc);
		StrIToA(num, gameInfoP->musicInfo.volume.speech);
		ArgsAdd(&argvP[argc], "-r", num, &argc);

		// game name
		ArgsAdd(&argvP[argc], gameInfoP->gameP, NULL, &argc);

		// others globals data
		gVars->CD.enable = gameInfoP->musicInfo.sound.CD;
		gVars->CD.driver = gameInfoP->musicInfo.sound.drvCD;
		gVars->CD.format = gameInfoP->musicInfo.sound.frtCD;
		gVars->CD.volume = gameInfoP->musicInfo.volume.audiocd;
		gVars->CD.defaultTrackLength = gameInfoP->musicInfo.sound.defaultTrackLength;
		gVars->CD.firstTrack = gameInfoP->musicInfo.sound.firstTrack;
		gVars->palmVolume = gameInfoP->musicInfo.sound.music ? gameInfoP->musicInfo.volume.palm : 0;

		MemHandleUnlock(recordH);
	} // end no game / game selected

	// common command line options

	// debug level
	if (gPrefs->debug) {
		StrIToA(num, gPrefs->debugLevel);
		ArgsAdd(&argvP[argc], "-d", num, &argc);
	}

	if (engine == ENGINE_QUEEN || engine == ENGINE_SKY) {
		// alternative intro ?
		if (gPrefs->altIntro)
			ArgsAdd(&argvP[argc], "--alt-intro", NULL, &argc);
	}
		
	if (engine == ENGINE_SCUMM) {
		// demo mode ?
		if (gPrefs->demoMode)
			ArgsAdd(&argvP[argc], "--demo-mode", NULL, &argc);
	}

	// copy protection ?
	if (gPrefs->copyProtection)
		ArgsAdd(&argvP[argc], "--copy-protection", NULL, &argc);

	// exceed max args ?
	if (argc > MAX_ARG)
		FrmCustomAlert(FrmErrorAlert, "Too many parameters.",0,0);

	// set some common options
	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->VFS.volRefNum	= gPrefs->card.volRefNum;
	gVars->vibrator			= gPrefs->vibrator;
	gVars->stdPalette		= gPrefs->stdPalette;
	gVars->VFS.cacheSize	= (gPrefs->card.useCache ? gPrefs->card.cacheSize : 0);
	gVars->indicator.showLED= gPrefs->card.showLED;
	gVars->stylusClick		= gPrefs->stylusClick;
	gVars->autoSave			= (gPrefs->autoSave ? gPrefs->autoSavePeriod : -1);
	gVars->advancedMode		= gPrefs->advancedMode;
	gVars->arrowKeys		= gPrefs->arrowKeys;

	// user params
	HWR_RSTALL();
	
	if (gPrefs->goLCD)
		HWR_SET(INIT_GOLCD);
	else
		OPTIONS_RST(kOptGoLcdAPI);
	
	if (!gPrefs->autoOff)
		HWR_SET(INIT_AUTOOFF);

	if (gVars->vibrator)
		HWR_SET(INIT_VIBRATOR);
/* ????
	if (	musicDriver == 1 ||
			musicDriver == 3 ||
			musicDriver == 4 ||
			musicDriver == sysInvalidRefNum) {
		HWR_SET(INIT_PA1LIB);
	}
*/
	if (ModImport(gVars->VFS.volRefNum, engine, &isARM) != errNone) {
		if (bDirectMode) {
			// and force exit if nothing selected
			EventType event;
			event.eType = keyDownEvent;
			event.data.keyDown.chr = vchrLaunch;
			event.data.keyDown.modifiers = commandKeyMask;
			EvtAddUniqueEventToQueue(&event, 0, true);
		}
		ArgsFree(argvP);
		return false;
	}

	// reset mode if screen rotation occured (DIA only)
	if (!direct && OPTIONS_TST(kOptCollapsible)) {
		UInt8 mode = PalmScreenSize(0,0, &(gVars->screenFullWidth), &(gVars->screenFullHeight));
		OPTIONS_RST(kOptModeLandscape);
		OPTIONS_SET((mode == PALM_LANDSCAPE) ? kOptModeLandscape : kOptNone);
	}

	// free and save globals pref memory
	GamCloseDatabase(false);
	FrmCloseAllForms();
	SavePrefs();

	{
		UInt16 cardNo;
		UInt32 dbID;

		LaunchParamType *cmdPBP = (LaunchParamType *)MemPtrNew(sizeof(LaunchParamType));

		MemPtrSetOwner(cmdPBP, 0);
		MemPtrSetOwner(gVars, 0);
		ArgsSetOwner(argvP, 0);

		cardNo = 0;
		dbID = DmFindDatabase(0, "ScummVM-Engine");

		if (isARM)
			FtrSet(appFileCreator, ftrStack , (stackSize * 4));
		else
			ModSetStack(stackSize, cardNo, dbID);

		cmdPBP->args.argc = argc;
		cmdPBP->args.argv = argvP;
		cmdPBP->gVars = gVars;
		cmdPBP->lightspeed = lightspeed;
		cmdPBP->exitLauncher = toLauncher;

		SysUIAppSwitch(cardNo, dbID, sysAppLaunchCmdNormalLaunch, cmdPBP);
		bLaunched = true;
	}

	return false;
}
示例#7
0
文件: noah_pro.c 项目: kjk/noah-palm
Err AppCommonInit(AppContext* appContext)
{
    Err     error;

    MemSet(appContext, sizeof(*appContext), 0);
    error=FtrSet(APP_CREATOR, appFtrContext, (UInt32)appContext);
    if (error) 
        goto OnError;
    error=FtrSet(APP_CREATOR, appFtrLeaksFile, 0);
    if (error) 
        goto OnError;
    
    LogInit( appContext, "c:\\noah_pro_log.txt" );
    InitFiveWay(appContext);

    appContext->err = ERR_NONE;
    appContext->prevSelectedWord = 0xfffff;

    appContext->firstDispLine = -1;
    appContext->currentWord = -1;
    appContext->prevSelectedWord = -1;
    // disable getting nilEvent
    appContext->ticksEventTimeout = evtWaitForever;
#ifdef DEBUG
    appContext->currentStressWord = 0;
#endif

    appContext->residentWordLookup = NULL;
    // fill out the default values for Noah preferences
    // and try to load them from pref database
    appContext->prefs.startupAction      = startupActionNone;
    appContext->prefs.hwButtonScrollType = scrollPage;
    appContext->prefs.navButtonScrollType = scrollPage;
    appContext->prefs.dbStartupAction    = dbStartupActionLast;
    appContext->prefs.lastDbUsedName     = NULL;
    appContext->prefs.bookmarksSortType  = bkmSortByTime;
    appContext->prefs.fResidentModeEnabled = true;

    // fill out the default display preferences
    appContext->prefs.displayPrefs.listStyle = 2;
    SetDefaultDisplayParam(&appContext->prefs.displayPrefs,false,false);
    appContext->ptrOldDisplayPrefs = NULL;
    // set ARM state
#ifndef DONT_DO_ARMLET
    appContext->armIsPresent = armTestArmLet();
#endif

    appContext->bookmarksDb = NULL;
    appContext->currBookmarkDbType = bkmInvalid;
    appContext->fInResidentMode = false;

    SyncScreenSize(appContext);
    FsInit(&appContext->fsSettings);
    
    LoadPreferencesNoahPro(appContext);
    
    error=DIA_Init(&appContext->diaSettings);
    if (error) 
        goto OnError;
    
OnError:
    return error;
}
示例#8
0
Err zlib_open(UInt16 ref) {
  UInt32 val=0;
  FtrGet('ZLib', ref, &val);
  FtrSet('ZLib', ref, ++val);
  return 0;
}
示例#9
0
void IntlInit(void)
{
	Err result;
	MemHandle localeCodeH;
	MemHandle tableListH;
	MemHandle featureTableH;
	ROMFtrTableType* featureTableP;
	ROMFtrCreatorType* creatorTableP;
	UInt16 creators;
	Boolean fastSort = true;
	Boolean fastSearch = true;
	Boolean fastAttr = true;
	UInt16 index;
	UInt32 intlFtrFlags;

#if (EMULATION_LEVEL == EMULATION_NONE)
	UInt16 systemCard;
	LocalID systemID;
	DmSearchStateType* searchStateP;
	MemHandle localeNameH;
	LocalID moduleID;
	DmOpenRef moduleRef;

	// Locate the system DB, so that we know where to look (which card)
	// for the locale module.
	searchStateP = (DmSearchStateType*)MemPtrNew(sizeof(DmSearchStateType));
	result = DmGetNextDatabaseByTypeCreator(	true,
															searchStateP,
															sysFileTSystem,
															sysFileCSystem,
															true,					// onlyLatestVers
															&systemCard,
															&systemID);
	ErrNonFatalDisplayIf((result != errNone) || (systemID == 0), "Can't find system DB");
	MemPtrFree((MemPtr)searchStateP);
	
	localeNameH = DmGetResource(strRsc, localeModuleNameStrID);
	ErrNonFatalDisplayIf(localeNameH == NULL, "Missing locale module name string");
	
	moduleID = DmFindDatabaseWithTypeCreator(	systemCard,
															(Char*)MemHandleLock(localeNameH),
															sysFileTLocaleModule,
															sysFileCSystem);
	MemHandleUnlock(localeNameH);
	
	if (moduleID != 0)
	{
		moduleRef = DmOpenDatabase(systemCard, moduleID, dmModeReadOnly | dmModeLeaveOpen);
		ErrNonFatalDisplayIf(moduleRef == 0, "Can't open locale module");
		
		if (ResLoadConstant(kIntlLMVersResID) != kIntlLMVersion)
		{
			DmCloseDatabase(moduleRef);
			moduleID = 0;
		}
	}
	
	// If we couldn't find the locale module, or it has the wrong version, then
	// default to the ROM locale's locale module.
	if (moduleID == 0)
	{
		SysNVParamsType* romParamsP;
		OmLocaleType romLocale;
		Char* overlayName;
		LocalID overlayID;
		DmOpenRef overlayRef;
		Char* systemName;
		
		// Open up the system overlay that corresponds to the ROM's locale.
		// Note that (assuming the ROM locale != current locale) we have to
		// try to open up the overlay explicitly, since the Overlay Mgr
		// won't be opening it automatically. We also have to handle the case
		// of a ROM built without overlays, in which case the ROM locale's
		// locale module name string is located in the base, which means we
		// have to make a low-level resource call to get it (otherwise we'll
		// get the string from the system overlay).
		romParamsP = (SysNVParamsType*)MemPtrNew(sizeof(SysNVParamsType));
		MemGetRomNVParams(romParamsP);
		romLocale.country = romParamsP->localeCountry;
		romLocale.language = romParamsP->localeLanguage;
		MemPtrFree((MemPtr)romParamsP);
		
		// Get the name of the system DB, so that we can construct the overlay
		// name.
		systemName = (Char*)MemPtrNew(dmDBNameLength);
		overlayName = (Char*)MemPtrNew(dmDBNameLength);

		result = DmDatabaseInfo(systemCard, systemID, systemName,
						NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
		ErrNonFatalDisplayIf(result != errNone, "Can't get system DB info");
		
		result = OmLocaleToOverlayDBName(systemName, &romLocale, overlayName);
		ErrNonFatalDisplayIf(result != errNone, "Can't make ROM locale system overlay name");
		
		overlayID = DmFindDatabaseWithTypeCreator(systemCard,
																overlayName,
																sysFileTOverlay,
																sysFileCSystem);
		MemPtrFree(systemName);
		MemPtrFree((MemPtr)overlayName);
		
		if (overlayID != 0)
		{
			overlayRef = DmOpenDatabase(systemCard, overlayID, dmModeReadOnly);
			ErrNonFatalDisplayIf(overlayRef == 0, "Can't open system overlay");
			
			// Now load the locale module name string from this overlay, and use
			// it to find the locale module.
			localeNameH = DmGet1Resource(strRsc, localeModuleNameStrID);
			ErrNonFatalDisplayIf(localeNameH == NULL, "Missing locale module name string");
			moduleID = DmFindDatabaseWithTypeCreator(	systemCard,
																	(Char*)MemHandleLock(localeNameH),
																	sysFileTLocaleModule,
																	sysFileCSystem);
			MemHandleUnlock(localeNameH);
			DmCloseDatabase(overlayRef);
		}
		else
		{
			// Assume it's a ROM built without overlays, in which case we need to
			// get the locale name handle from the system base.
			DmOpenRef sysRef = NULL;
			Int16 index;
			
			do
			{
				LocalID dbID;
				
				sysRef = DmNextOpenResDatabase(sysRef);
				
				if ((sysRef != NULL)
				 && (DmOpenDatabaseInfo(sysRef, &dbID, NULL, NULL, NULL, NULL) == errNone)
				 && (dbID == systemID))
				{
				 	break;
				}
			} while (sysRef != NULL);

			ErrNonFatalDisplayIf(sysRef == NULL, "Can't find system DB");
			index = DmFindResource(sysRef, strRsc, localeModuleNameStrID, NULL);
			ErrNonFatalDisplayIf(index == -1, "Missing locale module name string");
			localeNameH = DmGetResourceIndex(sysRef, index);
			ErrNonFatalDisplayIf(localeNameH == NULL, "Missing locale module name string");
			moduleID = DmFindDatabaseWithTypeCreator(	systemCard,
																	(Char*)MemHandleLock(localeNameH),
																	sysFileTLocaleModule,
																	sysFileCSystem);
		}
		
		// If we found the locale module DB, open it up and make sure it has
		// the right version.
		if (moduleID != 0)
		{
			moduleRef = DmOpenDatabase(systemCard, moduleID, dmModeReadOnly | dmModeLeaveOpen);
			if ((moduleRef == 0)
			 || (ResLoadConstant(kIntlLMVersResID) != kIntlLMVersion))
			{
				// Trigger fatal alert below. No need to close the DB in that case.
				moduleID = 0;
			}
			else
			{
				// We found a valid locale module, using the ROM locale, so set
				// the current locale to be the ROM locale.
				result = FtrSet(sysFtrCreator, sysFtrNumLanguage, romLocale.language);
				
				if (result == errNone)
				{
					result = FtrSet(sysFtrCreator, sysFtrNumCountry, romLocale.country);
				}
				
				ErrNonFatalDisplayIf(result != errNone, "Can't switch current locale to ROM locale");
			}
		}
		
		ErrFatalDisplayIf(moduleID == 0, "No valid locale module");
	}
	
	result = DmDatabaseProtect(systemCard, moduleID, true);
	if (result != dmErrROMBased)
	{
		ErrNonFatalDisplayIf(result != errNone, "Can't protect locale module");
	}
#else
	// Give the locale module code in the Simulator a chance to
	// initialize itself. If there's no such code (e.g. with latin) then the
	// routine in SimStubs.cp does nothing.
	StubPalmOSInitLocaleModule();
#endif

	// If there's a locale module code resource, load & call it now.
	localeCodeH = DmGet1Resource(kIntlLMCodeType, kIntlLMCodeResID);
	if (localeCodeH != NULL)
	{
		ProcPtr localeCodeP = (ProcPtr)MemHandleLock(localeCodeH);
		(*localeCodeP)();
		MemHandleUnlock(localeCodeH);
	}
	
	// If the IntlMgr data ptr hasn't been set up by the locale module code,
	// allocate it now.
	if (GIntlMgrGlobalsP == NULL)
	{
		UInt16 numCustomTransTables;
		MemPtr globalPtr;

		numCustomTransTables = ResLoadConstant(kIntlLMCustomTransCountID);
		ErrNonFatalDisplayIf(numCustomTransTables > kIntlMaxCustomTransliterations,
									"Too many custom transliterations");
		
		globalPtr = MemPtrNew(sizeof(IntlGlobalsType) + (numCustomTransTables * sizeof(void*)));
		ErrNonFatalDisplayIf(globalPtr == NULL, "Out of memory");
		
		MemSet(globalPtr, sizeof(IntlGlobalsType) + (numCustomTransTables * sizeof(void*)), 0);
		GIntlMgrGlobalsP = globalPtr;
		
		GIntlData->numCustomTransliterations = numCustomTransTables;
	}
	else
	{
		// If any of the sorting tables are already configured, we can't do
		// our fast sorting optimization.
		for (index = 0; index < kIntlMaxSortLevels; index++)
		{
			if (GIntlData->sortTables[index] != NULL)
			{
				fastSort = false;
				break;
			}
		}
		
		// If the word start or word match tables are already configured, we
		// can't do our fast word search optimization.
		
		if ((GIntlData->findWordStartTable != NULL)
		 || (GIntlData->findWordMatchTable != NULL))
		{
			fastSearch = false;
		}
		
		// If the character attribute table is already configured, we can't do
		// our fast attribute optimization.
		if (GIntlData->charAttrTable != NULL)
		{
			fastAttr = false;
		}
	}
	
	// Loop over all of the table resources, locking & setting up pointers in
	// the IntlMgr global data structure.
	tableListH = DmGet1Resource(kIntlLMTableListType, kIntlLMTableListResID);
	if (tableListH != NULL)
	{
		IntlLMTableEntryType* curTable;
		UInt8* globalsP = (UInt8*)GIntlMgrGlobalsP;
		IntlLMTableResType* tableListP = (IntlLMTableResType*)MemHandleLock(tableListH);
		
		for (index = 0, curTable = tableListP->resources; index < tableListP->numResources; index++, curTable++)
		{
			void** ptrLocation;
			MemHandle tableH;
			
			tableH = DmGet1Resource(curTable->resType, curTable->resID);
			ErrFatalDisplayIf(tableH == NULL, "Missing table resource from locale module");
			ErrFatalDisplayIf(curTable->tableIndex >= intlLMNumTableIndexes, "Invalid table index");
			
			ptrLocation = (void**)(globalsP + kIntlGlobalOffsets[curTable->tableIndex]);
			ErrFatalDisplayIf(*ptrLocation != NULL, "Resource overriding existing table ptr");
			*ptrLocation = MemHandleLock(tableH);
		}
		
		MemHandleUnlock(tableListH);
	}

	// Note that we can't check for the presence of tables here, as a table that
	// is required by a Text Mgr routine might be NULL if the locale module has
	// patched out that routine.
	
	// As an optimization, see if all of the sorting tables are byte-indexed 8-bit
	// values. If so, then replace the table ptrs with ptrs to the actual data,
	// and set the fast sorting intl mgr flag.
	for (index = 0; (index < kIntlMaxSortLevels) && fastSort; index++)
	{
		void* sortTable = GIntlData->sortTables[index];
		if (sortTable == NULL)
		{
			break;
		}
		else if (PrvGetByteIndexedTable(sortTable, 8) == NULL)
		{
			fastSort = false;
		}
	}
	
	if (fastSort)
	{
		GIntlData->intlFlags |= kByteSortingFlag;
		
		for (index = 0; index < kIntlMaxSortLevels; index++)
		{
			GIntlData->sortTables[index] = PrvGetByteIndexedTable(GIntlData->sortTables[index], 8);
		}
	}
	
	// As an optimization, see if all of the searching tables are byte-indexed 8-bit
	// values. If so, then replace the table ptrs with ptrs to the actual data,
	// and set the fast searching intl mgr flag. Note that PrvGetByteIndexedTable
	// will return NULL if findWordMatchTable is NULL, which is OK because then
	// TxtFindString must be patched out anyway. The findWordStartTable is optional,
	// and thus it can either be NULL or a byte indexed byte table.
	if ((fastSearch)
	 && ((GIntlData->findWordStartTable == NULL)
	  || (PrvGetByteIndexedTable(GIntlData->findWordStartTable, 8) != NULL))
	 && (PrvGetByteIndexedTable(GIntlData->findWordMatchTable, 8) != NULL))
	{
		GIntlData->intlFlags |= kByteSearchingFlag;

		GIntlData->findWordStartTable = PrvGetByteIndexedTable(GIntlData->findWordStartTable, 8);
		GIntlData->findWordMatchTable = PrvGetByteIndexedTable(GIntlData->findWordMatchTable, 8);
	}
	
	// As an optimization, see if the character attribute table is a byte-indexed
	// table of 16-bit values. If so, then replace the table ptr with a ptr to
	// the data, and set the kByteCharAttrFlag flag.
	if (fastAttr && (PrvGetByteIndexedTable(GIntlData->charAttrTable, 16) != NULL))
	{
		GIntlData->intlFlags |= kByteCharAttrFlag;
		GIntlData->charAttrTable = PrvGetByteIndexedTable(GIntlData->charAttrTable, 16);
	
	// As an optimization, see if the character attribute table is a stage index map
	// table of 16-bit values. If so, then replace the table ptr with a ptr to
	// the sub-table offsets, set up the result table ptr, and set the
	// kStageCharAttrFlag flag.
	}
	else if (fastAttr && PrvGetStageIndexMapTable(GIntlData->charAttrTable, 16))
	{
		GIntlData->intlFlags |= kStageCharAttrFlag;
		GIntlData->charAttrTable = PrvGetStageIndexMapTable(GIntlData->charAttrTable, 16);
	}
	
	// If there's a doubleCharTable, we want to (a) verify that it's a byte-indexed
	// byte table, and (b) set up the pointer now.
	if (GIntlData->doubleCharTable != NULL)
	{
		void* tableP = PrvGetByteIndexedTable(GIntlData->doubleCharTable, 8);
		ErrNonFatalDisplayIf(tableP == NULL, "Double-char table isn't byte-indexed byte table");
		GIntlData->doubleCharTable = tableP;
	}
	
	// Load the 'feat' resource from the locale module, and use it to initialize
	// various locale-specific features. Typically this includes sysFtrNumCharEncodingFlags,
	// sysFtrNumEncoding, sysFtrDefaultFont, and sysFtrDefaultBoldFont.
	// Try to load the 'feat' resource.
	featureTableH = DmGet1Resource(sysResTFeatures, kIntlLMFeatureResID);
	ErrFatalDisplayIf(featureTableH == NULL, "Missing feature table");
	featureTableP = (ROMFtrTableType*)MemHandleLock(featureTableH);
	creatorTableP = featureTableP->creator;
	
	for (creators = 0; creators < featureTableP->numEntries; creators++)
	{
		UInt16 features;
		
		for (features = 0; features < creatorTableP->numEntries; features++)
		{
			result = FtrSet(	creatorTableP->creator,
									creatorTableP->feature[features].num,
									creatorTableP->feature[features].value);
			ErrNonFatalDisplayIf(result != errNone, "Can't set locale feature");
		}
		
		// Advance to next creator table.
		creatorTableP = (ROMFtrCreatorType*)((UInt8*)creatorTableP
								+ sizeof(ROMFtrCreatorType)
								+ (creatorTableP->numEntries * sizeof(ROMFtrFeatureType)));
	}
	
	MemHandleUnlock(featureTableH);
	
	// Now, set up our internal kByteSearchingFlag flag based on the sysFtrNumCharEncodingFlags
	// feature value. This means that sysFtrNumCharEncodingFlags is read-only, since if
	// anybody uses FtrSet to change the settings of the flags, that won't update
	// our internal flag(s).
	if ((FtrGet(sysFtrCreator, sysFtrNumCharEncodingFlags, &intlFtrFlags) == errNone)
	 && ((intlFtrFlags & charEncodingOnlySingleByte) != 0))
	{
		GIntlData->intlFlags |= kSingleByteOnlyFlag;
	}
	
	// Finally set the bit that tells everybody we're ready to support IntlMgr/TextMgr calls.
	FtrSet(sysFtrCreator, sysFtrNumIntlMgr, intlMgrExists);
} // IntlInit