Gathered common functions into new source files
svn-id: r15743
This commit is contained in:
parent
4635440998
commit
618971dd2f
12 changed files with 399 additions and 0 deletions
69
backends/PalmOS/Src/args.cpp
Normal file
69
backends/PalmOS/Src/args.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
#include <PalmOS.h>
|
||||
#include "args.h"
|
||||
|
||||
Char **ArgsInit() {
|
||||
MemHandle argvH = MemHandleNew(MAX_ARG * sizeof(Char *));
|
||||
Char **argvP = (Char **)MemHandleLock(argvH);
|
||||
|
||||
for(UInt8 count = 0; count < MAX_ARG; count++)
|
||||
argvP[count] = NULL;
|
||||
|
||||
return argvP;
|
||||
}
|
||||
|
||||
void ArgsAdd(Char **argvP, const Char *argP, const Char *parmP, UInt8 *countArgP) {
|
||||
if (argP) {
|
||||
MemHandle newArg;
|
||||
UInt16 len2 = 0;
|
||||
UInt16 len1 = StrLen(argP);
|
||||
|
||||
if (len1 > 0) {
|
||||
if (parmP)
|
||||
len2 = StrLen(parmP);
|
||||
|
||||
(*countArgP)++;
|
||||
newArg = MemHandleNew(len1 + len2 + 1); // +1 = NULL CHAR
|
||||
*argvP = (Char *)MemHandleLock(newArg);
|
||||
StrCopy(*argvP, argP);
|
||||
|
||||
if (parmP)
|
||||
StrCat(*argvP, parmP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ArgsFree(Char **argvP) {
|
||||
if (!argvP)
|
||||
return;
|
||||
|
||||
MemHandle oldH;
|
||||
|
||||
for(UInt8 count = 0; count < MAX_ARG; count++)
|
||||
if (argvP[count]) {
|
||||
oldH = MemPtrRecoverHandle(argvP[count]);
|
||||
MemHandleUnlock(oldH);
|
||||
MemHandleFree(oldH);
|
||||
}
|
||||
|
||||
oldH = MemPtrRecoverHandle(argvP);
|
||||
MemHandleUnlock(oldH);
|
||||
MemHandleFree(oldH);
|
||||
}
|
||||
|
||||
void ArgsSetOwner(Char **argvP, UInt16 owner) {
|
||||
if (!argvP)
|
||||
return;
|
||||
|
||||
MemHandle oldH;
|
||||
|
||||
for(UInt8 count = 0; count < MAX_ARG; count++)
|
||||
if (argvP[count]) {
|
||||
oldH = MemPtrRecoverHandle(argvP[count]);
|
||||
MemHandleSetOwner(oldH, owner);
|
||||
// MemPtrSetOwner(argvP[count], 0);
|
||||
}
|
||||
|
||||
oldH = MemPtrRecoverHandle(argvP);
|
||||
MemHandleSetOwner(oldH, owner);
|
||||
// MemPtrSetOwner(argvP, 0);
|
||||
}
|
11
backends/PalmOS/Src/args.h
Normal file
11
backends/PalmOS/Src/args.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef ARGS_H
|
||||
#define ARGS_H
|
||||
|
||||
#define MAX_ARG 25
|
||||
|
||||
Char **ArgsInit();
|
||||
void ArgsAdd(Char **argvP, const Char *argP, const Char *parmP, UInt8 *countArgP);
|
||||
void ArgsFree(Char **argvP);
|
||||
void ArgsSetOwner(Char **argvP, UInt16 owner);
|
||||
|
||||
#endif
|
57
backends/PalmOS/Src/init_arm.cpp
Normal file
57
backends/PalmOS/Src/init_arm.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include <PalmOS.h>
|
||||
#include "globals.h"
|
||||
#include "init_arm.h"
|
||||
|
||||
void ARMInit() {
|
||||
// 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);
|
||||
}
|
||||
|
||||
void ARMRelease() {
|
||||
_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);
|
||||
}
|
||||
|
||||
MemPtr _PceInit(DmResID resID) {
|
||||
MemHandle armH = DmGetResource('ARMC', resID);
|
||||
NativeFuncType *armP = (NativeFuncType *)MemHandleLock(armH);
|
||||
|
||||
return armP;
|
||||
}
|
||||
|
||||
UInt32 _PceCall(void *armP, void *userDataP) {
|
||||
return PceNativeCall((NativeFuncType *)armP, userDataP);
|
||||
}
|
||||
|
||||
void _PceFree(void *armP) {
|
||||
MemHandle armH = MemPtrRecoverHandle(armP);
|
||||
|
||||
MemPtrUnlock(armP);
|
||||
DmReleaseResource(armH);
|
||||
}
|
||||
|
||||
MemPtr _PnoInit(DmResID resID, PnoDescriptor *pnoP) {
|
||||
MemHandle armH = DmGetResource('ARMC', resID);
|
||||
MemPtr armP = MemHandleLock(armH);
|
||||
PnoLoad(pnoP, armP);
|
||||
|
||||
return armP;
|
||||
}
|
||||
|
||||
UInt32 _PnoCall(PnoDescriptor *pnoP, void *userDataP) {
|
||||
return PnoCall(pnoP, userDataP);
|
||||
}
|
||||
|
||||
void _PnoFree(PnoDescriptor *pnoP, MemPtr armP) {
|
||||
MemHandle armH = MemPtrRecoverHandle(armP);
|
||||
|
||||
PnoUnload(pnoP);
|
||||
MemPtrUnlock(armP);
|
||||
DmReleaseResource(armH);
|
||||
}
|
16
backends/PalmOS/Src/init_arm.h
Normal file
16
backends/PalmOS/Src/init_arm.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef INIT_ARM_H
|
||||
#define INIT_ARM_H
|
||||
|
||||
void ARMInit();
|
||||
void ARMRelease();
|
||||
|
||||
// calls
|
||||
MemPtr _PceInit(DmResID resID);
|
||||
UInt32 _PceCall(void *armP, void *userDataP);
|
||||
void _PceFree(void *armP);
|
||||
|
||||
MemPtr _PnoInit(DmResID resID, PnoDescriptor *pnoP);
|
||||
UInt32 _PnoCall(PnoDescriptor *pnoP, void *userDataP);
|
||||
void _PnoFree(PnoDescriptor *pnoP, MemPtr armP);
|
||||
|
||||
#endif
|
30
backends/PalmOS/Src/init_mathlib.cpp
Normal file
30
backends/PalmOS/Src/init_mathlib.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <PalmOS.h>
|
||||
#include "enginersc.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "init_mathlib.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
Err MathlibInit() {
|
||||
Err e;
|
||||
|
||||
if ((e = SysLibFind(MathLibName, &MathLibRef)))
|
||||
if (e == sysErrLibNotFound) // couldn't find lib
|
||||
e = SysLibLoad(LibType, MathLibCreator, &MathLibRef);
|
||||
|
||||
if (e) return sysErrLibNotFound;
|
||||
|
||||
e = MathLibOpen(MathLibRef, MathLibVersion);
|
||||
return e;
|
||||
}
|
||||
|
||||
void MathlibRelease() {
|
||||
UInt16 useCount;
|
||||
|
||||
if (MathLibRef != sysInvalidRefNum) {
|
||||
MathLibClose(MathLibRef, &useCount);
|
||||
|
||||
if (!useCount)
|
||||
SysLibRemove(MathLibRef);
|
||||
}
|
||||
}
|
7
backends/PalmOS/Src/init_mathlib.h
Normal file
7
backends/PalmOS/Src/init_mathlib.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef INIT_MATHLIB_H
|
||||
#define INIT_MATHLIB_H
|
||||
|
||||
Err MathlibInit();
|
||||
void MathlibRelease();
|
||||
|
||||
#endif
|
32
backends/PalmOS/Src/init_pa1lib.cpp
Normal file
32
backends/PalmOS/Src/init_pa1lib.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <PalmOS.h>
|
||||
#include <Sonyclie.h>
|
||||
|
||||
#include "pa1lib.h"
|
||||
#include "init_pa1lib.h"
|
||||
|
||||
void *sndStateOnFuncP = NULL;
|
||||
void *sndStateOffFuncP = NULL;
|
||||
|
||||
#define SndStateOn(a,b,c) if (sndStateOnFuncP)((sndStateOnType)(sndStateOnFuncP))(a, b, c);
|
||||
#define SndStateOff(a) if (sndStateOffFuncP)((sndStateOffType)(sndStateOffFuncP))(a);
|
||||
|
||||
void Pa1libInit() {
|
||||
Pa1Lib_Open();
|
||||
|
||||
// Doesn't work on T4xx and T6xx series ?
|
||||
FtrGet(sonySysFtrCreatorSystem, sonySysFtrNumSystemAOutSndStateOnHandlerP, (UInt32*) &sndStateOnFuncP);
|
||||
FtrGet(sonySysFtrCreatorSystem, sonySysFtrNumSystemAOutSndStateOffHandlerP, (UInt32*) &sndStateOffFuncP);
|
||||
|
||||
SndStateOn(aOutSndKindSp, 31, 31);
|
||||
SndStateOn(aOutSndKindHp, 31, 31);
|
||||
|
||||
Pa1Lib_devHpVolume(31, 31);
|
||||
Pa1Lib_devSpVolume(31);
|
||||
}
|
||||
|
||||
void Pa1libRelease() {
|
||||
SndStateOff(aOutSndKindSp);
|
||||
SndStateOff(aOutSndKindHp);
|
||||
|
||||
Pa1Lib_Close();
|
||||
}
|
22
backends/PalmOS/Src/init_pa1lib.h
Normal file
22
backends/PalmOS/Src/init_pa1lib.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef INIT_PA1LIB_H
|
||||
#define INIT_PA1LIB_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 */
|
||||
|
||||
void Pa1libInit();
|
||||
void Pa1libRelease();
|
||||
|
||||
#endif
|
44
backends/PalmOS/Src/init_palmos.cpp
Normal file
44
backends/PalmOS/Src/init_palmos.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <PalmOS.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "init_palmos.h"
|
||||
|
||||
static UInt16 autoOffDelay;
|
||||
|
||||
void PalmInit(UInt8 init) {
|
||||
// set screen depth
|
||||
UInt32 depth = 8;
|
||||
WinScreenMode(winScreenModeSet, NULL, NULL, &depth, NULL);
|
||||
|
||||
if (init & INIT_AUTOOFF) {
|
||||
autoOffDelay = SysSetAutoOffTime(0);
|
||||
EvtResetAutoOffTimer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PalmRelease(UInt8 init) {
|
||||
SysSetAutoOffTime(autoOffDelay);
|
||||
EvtResetAutoOffTimer();
|
||||
}
|
||||
|
||||
Err PalmHRInit(UInt32 depth) {
|
||||
Err e;
|
||||
UInt32 width = 320;
|
||||
UInt32 height = 320;
|
||||
Boolean color = true;
|
||||
|
||||
e = WinScreenMode (winScreenModeSet, &width, &height, &depth, &color);
|
||||
|
||||
if (!e) {
|
||||
UInt32 attr;
|
||||
WinScreenGetAttribute(winScreenDensity, &attr);
|
||||
e = (attr != kDensityDouble);
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
void PalmHRRelease() {
|
||||
// should i do something here ?
|
||||
}
|
10
backends/PalmOS/Src/init_palmos.h
Normal file
10
backends/PalmOS/Src/init_palmos.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef INIT_PALMOS_H
|
||||
#define INIT_PALMOS_H
|
||||
|
||||
void PalmInit(UInt8 init);
|
||||
void PalmRelease(UInt8 init);
|
||||
|
||||
Err PalmHRInit(UInt32 depth);
|
||||
void PalmHRRelease();
|
||||
|
||||
#endif
|
91
backends/PalmOS/Src/init_sony.cpp
Normal file
91
backends/PalmOS/Src/init_sony.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
#include <PalmOS.h>
|
||||
#include <SonyClie.h>
|
||||
#include "init_sony.h"
|
||||
|
||||
UInt16 SilkInit(UInt32 *retVersion) {
|
||||
SonySysFtrSysInfoP sonySysFtrSysInfoP;
|
||||
UInt32 version;
|
||||
UInt16 slkRefNum;
|
||||
Err e;
|
||||
|
||||
// Sony HiRes+
|
||||
if (!(e = FtrGet(sonySysFtrCreator, sonySysFtrNumSysInfoP, (UInt32*)&sonySysFtrSysInfoP))) {
|
||||
if (sonySysFtrSysInfoP->libr & sonySysFtrSysInfoLibrSilk) {
|
||||
|
||||
if ((e = SysLibFind(sonySysLibNameSilk, &slkRefNum)))
|
||||
if (e == sysErrLibNotFound)
|
||||
e = SysLibLoad(sonySysFileTSilkLib, sonySysFileCSilkLib, &slkRefNum);
|
||||
|
||||
if (!e) {
|
||||
e = FtrGet(sonySysFtrCreator, sonySysFtrNumVskVersion, &version);
|
||||
if (e) {
|
||||
// v1 = NR
|
||||
e = SilkLibOpen(slkRefNum);
|
||||
if(!e) version = vskVersionNum1;
|
||||
|
||||
} else {
|
||||
// v2 = NX/NZ
|
||||
// v3 = UX...
|
||||
e = VskOpen(slkRefNum);
|
||||
}
|
||||
}
|
||||
} else
|
||||
e = sysErrLibNotFound;
|
||||
}
|
||||
|
||||
if (e) {
|
||||
version = 0;
|
||||
slkRefNum = sysInvalidRefNum;
|
||||
}
|
||||
|
||||
*retVersion = version;
|
||||
return slkRefNum;
|
||||
}
|
||||
|
||||
void SilkRelease(UInt16 slkRefNum) {
|
||||
if (slkRefNum != sysInvalidRefNum)
|
||||
SilkLibClose(slkRefNum);
|
||||
}
|
||||
|
||||
UInt16 SonyHRInit(UInt32 depth) {
|
||||
SonySysFtrSysInfoP sonySysFtrSysInfoP;
|
||||
Err e;
|
||||
UInt16 HRrefNum;
|
||||
|
||||
// test if sonyHR is present
|
||||
if (!(e = FtrGet(sonySysFtrCreator, sonySysFtrNumSysInfoP, (UInt32*)&sonySysFtrSysInfoP))) {
|
||||
if (sonySysFtrSysInfoP->libr & sonySysFtrSysInfoLibrHR) { // HR available
|
||||
|
||||
if ((e = SysLibFind(sonySysLibNameHR, &HRrefNum)))
|
||||
if (e == sysErrLibNotFound) // can't find lib
|
||||
e = SysLibLoad( 'libr', sonySysFileCHRLib, &HRrefNum);
|
||||
|
||||
// Now we can use HR lib. Executes Open library.
|
||||
if (!e) e = HROpen(HRrefNum);
|
||||
}
|
||||
}
|
||||
|
||||
if (e) HRrefNum = sysInvalidRefNum;
|
||||
|
||||
if (HRrefNum != sysInvalidRefNum) {
|
||||
UInt32 width = hrWidth;
|
||||
UInt32 height = hrHeight;
|
||||
Boolean color = true;
|
||||
|
||||
e = HRWinScreenMode(HRrefNum, winScreenModeSet, &width, &height, &depth, &color);
|
||||
// error ? release and return an invalid reference number
|
||||
if (e) {
|
||||
SonyHRRelease(HRrefNum);
|
||||
HRrefNum = sysInvalidRefNum;
|
||||
}
|
||||
}
|
||||
|
||||
return HRrefNum;
|
||||
}
|
||||
|
||||
void SonyHRRelease(UInt16 HRrefNum) {
|
||||
if (HRrefNum != sysInvalidRefNum) {
|
||||
HRClose(HRrefNum);
|
||||
//SysLibRemove(gVars->HRrefNum); // never call this !!
|
||||
}
|
||||
}
|
10
backends/PalmOS/Src/init_sony.h
Normal file
10
backends/PalmOS/Src/init_sony.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef INIT_SONY_H
|
||||
#define INIT_SONY_H
|
||||
|
||||
UInt16 SilkInit(UInt32 *retVersion);
|
||||
void SilkRelease(UInt16 slkRefNum);
|
||||
|
||||
UInt16 SonyHRInit(UInt32 depth);
|
||||
void SonyHRRelease(UInt16 HRrefNum);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue