📄 pace.c
字号:
PACE_END(sysTrapFrmSetGadgetHandler,NONE,NONE)
PACE_BEGIN(static void _FrmSetEventHandler(FormType *formP,FormEventHandlerType *handler))
PACE_ADD32(formP)
PACE_ADD32(handler)
PACE_END(sysTrapFrmSetEventHandler,NONE,NONE)
PACE_BEGIN(static void _FrmDeleteForm(FormType *formP))
PACE_ADD32(formP)
PACE_END(sysTrapFrmDeleteForm,NONE,NONE)
PACE_BEGIN(static void _FrmReturnToForm(UInt16 formId))
PACE_ADD16(formId)
PACE_END(sysTrapFrmReturnToForm,NONE,NONE)
PACE_BEGIN(Err EvtEnqueueKey(WChar ascii, UInt16 keycode, UInt16 modifiers))
PACE_ADD16(ascii)
PACE_ADD16(keycode)
PACE_ADD16(modifiers)
PACE_END16(sysTrapEvtEnqueueKey,NONE,NONE)
PACE_BEGIN(FontID FntSetFont(FontID font))
PACE_ADD8(font)
PACE_END8(sysTrapFntSetFont,NONE,NONE)
PACE_BEGIN(UInt32 KeyCurrentState())
PACE_END32VOID(sysTrapKeyCurrentState,NONE,NONE)
PACE_BEGIN(UInt32 TimGetSeconds(void))
PACE_END32VOID(sysTrapTimGetSeconds,NONE,NONE)
PACE_BEGIN(void TimSecondsToDateTime(UInt32 seconds, DateTimeType *dateTimeP))
PACE_ADD32(seconds)
PACE_ADD32(dateTimeP)
PACE_END(sysTrapTimSecondsToDateTime,NONE,SwapStruct(dateTimeP,2,2,2,2,2,2,2,0))
/*PACE_BEGIN(Err KeyRates(Boolean set, UInt16 *initDelayP, UInt16 *periodP,
UInt16 *doubleTapDelayP, Boolean *queueAheadP))
PACE_ADD8(set)
PACE_ADD32(initDelayP)
PACE_ADD32(periodP)
PACE_ADD32(doubleTapDelayP)
PACE_ADD32(queueAheadP)
PACE_END16(sysTrapKeyRates,PACE_DATA16(initDelayP) PACE_DATA16(periodP) PACE_DATA16(doubleTapDelayP),
PACE_DATA16(initDelayP) PACE_DATA16(periodP) PACE_DATA16(doubleTapDelayP))
*/
PACE_BEGIN(Err SysLibOpen(UInt16 refNum))
PACE_ADD16(refNum)
PACE_END16(sysLibTrapOpen,NONE,NONE)
PACE_BEGIN(Err SysLibClose(UInt16 refNum))
PACE_ADD16(refNum)
PACE_END16(sysLibTrapClose,NONE,NONE)
PACE_BEGIN(UInt32 RotationMgrGetLibAPIVersion(UInt16 refNum))
PACE_ADD16(refNum)
PACE_END32((sysLibTrapCustom+0),NONE,NONE)
PACE_BEGIN(Err RotationMgrAttributeGet(UInt16 refNum, UInt32 attribute, UInt32 *valueP))
PACE_ADD16(refNum)
PACE_ADD32(attribute)
PACE_ADD32(valueP)
PACE_END16((sysLibTrapCustom+5),NONE,PACE_DATA32(valueP));
PACE_BEGIN(UInt16 SysBatteryInfo(Boolean set, UInt16 *warnThresholdP, UInt16 *criticalThresholdP,
Int16 *maxTicksP, SysBatteryKind* kindP, Boolean *pluggedIn, UInt8 *percentP))
PACE_ADD8(set)
PACE_ADD32(warnThresholdP)
PACE_ADD32(criticalThresholdP)
PACE_ADD32(maxTicksP)
PACE_ADD32(kindP)
PACE_ADD32(pluggedIn)
PACE_ADD32(percentP)
PACE_END16(sysTrapSysBatteryInfo,NONE,PACE_CDATA16(warnThresholdP) PACE_CDATA16(criticalThresholdP) PACE_CDATA16(maxTicksP))
#ifdef HAVE_PALMONE_SDK
PACE_BEGIN(Err HsNavGetFocusRingInfo(const FormType* formP, UInt16* objectIDP,
Int16* extraInfoP, RectangleType* boundsInsideRingP,
HsNavFocusRingStyleEnum* ringStyleP))
PACE_ADD16(hsSelNavGetFocusRingInfo)
PACE_ADD32(formP)
PACE_ADD32(objectIDP)
PACE_ADD32(extraInfoP)
PACE_ADD32(boundsInsideRingP)
PACE_ADD32(ringStyleP)
PACE_END16(sysTrapOEMDispatch, NONE, PACE_CDATA16(objectIDP) PACE_CDATA16(extraInfoP) PACE_CDATA16(ringStyleP) SwapStruct(boundsInsideRingP,2,2,2,2,0))
PACE_BEGINEX(Err HsNavDrawFocusRing(FormType* formP, UInt16 objectID, Int16 extraInfo,
RectangleType* boundsInsideRingP,
HsNavFocusRingStyleEnum ringStyle, Boolean forceRestore),r)
PACE_ADD16(boundsInsideRingP->topLeft.x)
PACE_ADD16(boundsInsideRingP->topLeft.y)
PACE_ADD16(boundsInsideRingP->extent.x)
PACE_ADD16(boundsInsideRingP->extent.y)
PACE_VAR(PACE_PARAM)
PACE_ADD16(hsSelNavDrawFocusRing)
PACE_ADD16(objectID)
PACE_ADD16(extraInfo)
PACE_ADD32(r)
PACE_ADD16(ringStyle)
PACE_ADD8(forceRestore)
PACE_END16(sysTrapOEMDispatch,NONE,NONE)
PACE_BEGIN(Err HsNavRemoveFocusRing (FormType* formP))
PACE_ADD16(hsSelNavRemoveFocusRing)
PACE_ADD32(formP)
PACE_END16(sysTrapOEMDispatch,NONE,NONE)
PACE_BEGIN(void HsNavObjectTakeFocus (const FormType* formP, UInt16 objID))
PACE_ADD16(hsSelNavObjectTakeFocus)
PACE_ADD32(formP)
PACE_ADD16(objID)
PACE_END(sysTrapOEMDispatch,NONE,NONE)
PACE_BEGIN(Err HsLightCircumstance(Boolean add, UInt16 circumstance))
PACE_ADD16(hsSelLightCircumstance)
PACE_ADD8(add)
PACE_ADD16(circumstance)
PACE_END16(sysTrapOEMDispatch, NONE, NONE)
PACE_BEGIN(UInt16 HsCurrentLightCircumstance())
PACE_ADD16(hsGetCurrentLightCircumstance)
PACE_END16(sysTrapOEMDispatch, NONE, NONE)
PACE_BEGIN(Err HsAttrGet(UInt16 attr, UInt32 param, UInt32* valueP))
PACE_ADD16(hsSelAttrGet)
PACE_ADD16(attr)
PACE_ADD32(param)
PACE_ADD32(valueP)
PACE_END16(sysTrapOEMDispatch, NONE, PACE_DATA32(valueP))
PACE_BEGIN(Err HsAttrSet(UInt16 attr, UInt32 param, UInt32* valueP))
PACE_ADD16(hsSelAttrSet)
PACE_ADD16(attr)
PACE_ADD32(param)
PACE_ADD32(valueP)
PACE_END16(sysTrapOEMDispatch, PACE_DATA32(valueP), PACE_DATA32(valueP))
PACE_BEGIN(Err HWUBlinkLED(UInt16 refnum, Boolean b))
PACE_ADD16(refnum)
PACE_ADD8(b)
PACE_END16((sysLibTrapCustom+0),NONE,NONE)
PACE_BEGIN(Err HWUSetBlinkRate(UInt16 refnum, UInt16 rate))
PACE_ADD16(refnum)
PACE_ADD16(rate)
PACE_END16((sysLibTrapCustom+1),NONE,NONE)
PACE_BEGIN(Err HWUEnableDisplay(UInt16 refnum, Boolean on))
PACE_ADD16(refnum)
PACE_ADD8(on)
PACE_END16((sysLibTrapCustom+2),NONE,NONE)
PACE_BEGIN(Boolean HWUGetDisplayState(UInt16 refnum))
PACE_ADD16(refnum)
PACE_END8((sysLibTrapCustom+3),NONE,NONE)
PACE_BEGIN(void *DexGetDisplayAddress(UInt16 refnum))
PACE_ADD16(refnum)
PACE_ENDPTR((sysLibTrapCustom+4),NONE,NONE)
PACE_BEGIN(void DexGetDisplayDimensions(UInt16 refnum, Coord *width, Coord *height, UInt16 *rowBytes))
PACE_ADD16(refnum)
PACE_ADD32(width)
PACE_ADD32(height)
PACE_ADD32(rowBytes)
PACE_END((sysLibTrapCustom+5),NONE,PACE_CDATA16(width) PACE_CDATA16(height) PACE_CDATA16(rowBytes))
#endif
#ifdef HAVE_SONY_SDK
PACE_BEGIN(UInt32 VskGetAPIVersion(UInt16 refNum))
PACE_ADD16(refNum)
PACE_END32((sysLibTrapCustom+3),NONE,NONE)
PACE_BEGIN(Err VskSetState(UInt16 refNum, UInt16 stateType, UInt16 state))
PACE_ADD16(refNum)
PACE_ADD16(stateType)
PACE_ADD16(state)
PACE_END16((sysLibTrapCustom+6),NONE,NONE)
PACE_BEGIN(Err VskGetState(UInt16 refNum, UInt16 stateType, UInt16 *stateP))
PACE_ADD16(refNum)
PACE_ADD16(stateType)
PACE_ADD32(stateP)
PACE_END16((sysLibTrapCustom+7),NONE,PACE_DATA16(stateP))
#endif
PACE_BEGIN(Err SysLibLoad(UInt32 libType, UInt32 libCreator, UInt16 *refNumP))
PACE_ADD32(libType)
PACE_ADD32(libCreator)
PACE_ADD32(refNumP)
PACE_END16(sysTrapSysLibLoad,NONE,PACE_DATA16(refNumP))
PACE_BEGIN(Err SysLibFind(const Char *nameP, UInt16 *refNumP))
PACE_ADD32(nameP)
PACE_ADD32(refNumP)
PACE_END16(sysTrapSysLibFind,NONE,PACE_DATA16(refNumP))
NOINLINE MemPtr MemGluePtrNew(UInt32 Size)
{
MemPtr p = MemPtrNew(Size);
if (!p)
{
SysAppInfoPtr appInfoP;
UInt16 OwnerID = SysGetAppInfo(&appInfoP,&appInfoP)->memOwnerID;
p = MemChunkNew(0, Size,(UInt16)(OwnerID | memNewChunkFlagNonMovable | memNewChunkFlagAllowLarge));
}
return p;
}
NOINLINE FormEventHandlerType* FrmGetEventHandler(FormType *Form)
{
eventhandler *i,*j;
for (i=EventHandler,j=NULL;i;j=i,i=i->Next)
if (i->Form == Form)
{
if (j)
{
// move ahead for faster search next time
j->Next = i->Next;
i->Next = EventHandler;
EventHandler = i;
}
return i->Handler;
}
return NULL;
}
Boolean FrmDispatchEvent(EventType *eventP)
{
// avoid using m68k wrapper for some common events (which are sent to the active form)
if (eventP->eType == keyHoldEvent || eventP->eType == keyDownEvent ||
eventP->eType == keyUpEvent || eventP->eType == nilEvent ||
eventP->eType == penDownEvent || eventP->eType == penMoveEvent ||
eventP->eType == penUpEvent)
{
FormType *Form = FrmGetActiveForm();
FormEventHandlerType* Handler = FrmGetEventHandler(Form);
if (Handler)
{
// call ARM event handler
if (Handler(eventP))
return 1;
// call system event handler
return FrmHandleEvent(Form,eventP);
}
}
return _FrmDispatchEvent(eventP);
}
static void SetCodePtr(uint8_t* p,void* Ptr)
{
p[0] = (uint8_t)(((uint32_t)Ptr) >> 24);
p[1] = (uint8_t)(((uint32_t)Ptr) >> 16);
p[2] = (uint8_t)(((uint32_t)Ptr) >> 8);
p[3] = (uint8_t)(((uint32_t)Ptr) >> 0);
}
static void RemoveHandler(FormType *Form)
{
eventhandler* i;
for (i=EventHandler;i;i=i->Next)
if (i->Form == Form)
i->Form = NULL;
}
void FrmDeleteForm( FormType *formP )
{
_FrmDeleteForm(formP);
RemoveHandler(formP);
}
void FrmReturnToForm( UInt16 formId )
{
FormType* Form = FrmGetActiveForm();
_FrmReturnToForm(formId);
RemoveHandler(Form);
}
void* m68kCallBack(m68kcallback p,NativeFuncType* Func)
{
static const uint8_t Code[24] =
{ 0x4E,0x56,0x00,0x00, // link a6,#0
0x48,0x6E,0x00,0x08, // pea 8(a6)
0x2F,0x3C,0x00,0x00,0x00,0x00, // move.l #$ARM,-(sp)
0x4E,0x4F, // trap #$F
0xA4,0x5A, // dc.w $A45A
0x70,0x00, // moveq #0,d0
0x4E,0x5E, // unlk a6
0x4E,0x75 }; // rts
memcpy(p,Code,sizeof(m68kcallback));
SetCodePtr((uint8_t*)p+10,(void*)(uint32_t)Func);
return p;
}
void FrmSetGadgetHandler(FormType *formP, UInt16 objIndex,FormGadgetHandlerType *attrP)
{
gadgethandler* i;
gadgethandler* Free = NULL;
for (i=GadgetHandler;i;i=i->Next)
{
if (i->Form == formP && i->Index == objIndex)
break;
if (!i->Form)
Free = i;
}
if (!i)
{
if (Free)
i = Free;
else
{
i = MemGluePtrNew(sizeof(gadgethandler));
i->Next = GadgetHandler;
GadgetHandler = i;
}
}
if (i)
{
static const uint8_t Code[68] =
{ 0x4E,0x56,0x00,0x00, // link a6,#0
0x30,0x2E,0x00,0x0C, // move.w $C(a6),d0
0x22,0x2E,0x00,0x0E, // move.l $E(a6),d1
0x23,0xEE,0x00,0x08,0x00,0x00,0x00,0x00, // move.l 8(a6),($Gadget).l
0x33,0xC0,0x00,0x00,0x00,0x00, // move.w d0,($Cmd).l
0x23,0xC1,0x00,0x00,0x00,0x00, // move.l d1,($Event).l
0x2F,0x3C,0x00,0x00,0x00,0x00, // move.l #This,-(sp)
0x2F,0x39,0x00,0x00,0x00,0x00, // move.l (Wrapper).l,-(sp)
0x2F,0x39,0x00,0x00,0x00,0x00, // move.l (Module).l,-(sp)
0x20,0x79,0x00,0x00,0x00,0x00, // movea.l (PealCall).l,a0
0x4E,0x90, // jsr (a0)
0x02,0x80,0x00,0x00,0x00,0xFF, // andi.l #$FF,d0
0x4E,0x5E, // unlk a6
0x4E,0x75 }; // rts
#if defined(_M_IX86)
const tchar_t* Name = T("tcpmp.dll\0WrapperGadgetHandler86");
i->Wrapper = SWAP32(Name);
#else
i->Wrapper = SWAP32(WrapperGadgetHandler);
#endif
i->Form = formP;
i->Index = objIndex;
i->Handler = attrP;
i->Module = Peal.Module;
i->PealCall = Peal.PealCall;
memcpy(i->Code,Code,sizeof(Code));
SetCodePtr(i->Code+16,&i->Gadget);
SetCodePtr(i->Code+22,&i->Cmd);
SetCodePtr(i->Code+28,&i->Event);
SetCodePtr(i->Code+34,i);
SetCodePtr(i->Code+40,&i->Wrapper);
SetCodePtr(i->Code+46,&i->Module);
SetCodePtr(i->Code+52,&i->PealCall);
_FrmSetGadgetHandler(formP,objIndex,(FormGadgetHandlerType*)i->Code);
}
}
void FrmSetEventHandler(FormType *formP,FormEventHandlerType *handler)
{
eventhandler* i;
eventhandler* Free = NULL;
for (i=EventHandler;i;i=i->Next)
{
if (i->Form == formP)
break;
if (!i->Form)
Free = i;
}
if (!i)
{
if (Free)
i = Free;
else
{
i = MemGluePtrNew(sizeof(eventhandler));
i->Next = EventHandler;
EventHandler = i;
}
}
if (i)
{
static const uint8_t Code[48] =
{ 0x4E,0x56,0x00,0x00, // link a6,#0
0x23,0xEE,0x00,0x08,0x00,0x00,0x00,0x00, // move.l arg_0(a6),(Event).l
0x2F,0x3C,0x00,0x00,0x00,0x00, // move.l #This,-(sp)
0x2F,0x39,0x00,0x00,0x00,0x00, // move.l (Wrapper).l,-(sp)
0x2F,0x39,0x00,0x00,0x00,0x00, // move.l (Module).l,-(sp)
0x20,0x79,0x00,0x00,0x00,0x00, // movea.l (PealCall).l,a0
0x4E,0x90, // jsr (a0)
0x4E,0x5E, // unlk a6
0x02,0x80,0x00,0x00,0x00,0xFF, // andi.l #$FF,d0
0x4E,0x75 }; // rts
#if defined(_M_IX86)
const tchar_t* Name = T("tcpmp.dll\0WrapperEventHandler86");
i->Wrapper = SWAP32(Name);
#else
i->Wrapper = SWAP32(WrapperEventHandler);
#endif
i->Form = formP;
i->Handler = handler;
i->Module = Peal.Module;
i->PealCall = Peal.PealCall;
i->Event = NULL;
memcpy(i->Code,Code,sizeof(Code));
SetCodePtr(i->Code+8,&i->Event);
SetCodePtr(i->Code+14,i);
SetCodePtr(i->Code+20,&i->Wrapper);
SetCodePtr(i->Code+26,&i->Module);
SetCodeP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -