⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pace.c

📁 大名鼎鼎的CE下播放软件,TCPPMP的源代码!!!2410下可以流畅的解QVGA的H264,MPEG4等格式.
💻 C
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************
 *
 * 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
 *
 * $Id: pace.c 531 2006-01-04 12:56:13Z picard $
 *
 * The Core Pocket Media Player
 * Copyright (c) 2004-2005 Gabor Kovacs
 *
 ****************************************************************************/

#include "../common.h"

#if defined(TARGET_PALMOS)

#include "pace.h"
#include "peal/arm/pealstub.h"

//tremor uses lot of alloca()
#define STACKSIZE	0x8000
//#define STACKCHECK

#ifdef HAVE_PALMONE_SDK
#define NO_HSEXT_TRAPS
#include <68K/System/HardwareUtils68K.h>
#include <Common/System/HsNavCommon.h>
#include <68K/System/HsExt.h>
#endif

typedef struct launch
{
	UInt32 PealCall; //BE
	UInt32 Module; //BE
	UInt32 LoadModule; //BE
	UInt32 FreeModule; //BE
	UInt32 GetSymbol; //BE

	UInt16 launchParameters[2];
	UInt16 launchCode;
	UInt16 launchFlags;

} launch;

typedef struct gadgethandler
{
	uint8_t Code[68];
	struct gadgethandler* Next;

	FormGadgetTypeInCallback* Gadget; //BE
	uint16_t* Event; //BE
	UInt16 Cmd; //BE
	UInt32 Module; //BE
	UInt32 PealCall; //BE
	UInt32 Wrapper; //BE

	FormType* Form;
	int Index;
	FormGadgetHandlerType* Handler; 

} gadgethandler;

typedef struct eventhandler
{
	uint8_t Code[48];
	struct eventhandler* Next;

	uint16_t* Event; //BE
	UInt32 Module; //BE
	UInt32 PealCall; //BE
	UInt32 Wrapper; //BE

	FormType* Form;
	FormEventHandlerType *Handler;

} eventhandler;

static gadgethandler* GadgetHandler = NULL;
static eventhandler* EventHandler = NULL;
static launch Peal = {0};

static NOINLINE void FreeHandlers()
{
	gadgethandler* j;
	eventhandler* i;
	while ((i=EventHandler)!=NULL)
	{
		EventHandler = i->Next;
		MemPtrFree(i);
	}
	while ((j=GadgetHandler)!=NULL)
	{
		GadgetHandler = j->Next;
		MemPtrFree(j);
	}
}

static NOINLINE void SwapLanchParameters(int launchCode,void* launchParameters,bool_t From)
{
	if (launchCode == sysAppLaunchCmdCustomBase)
	{
		vfspath* p = (vfspath*)launchParameters;
		p->volRefNum = SWAP16(p->volRefNum);
	}

	if (launchCode == sysAppLaunchCmdOpenDB)
	{
		UInt16 tmp;
		SysAppLaunchCmdOpenDBType2* p = (SysAppLaunchCmdOpenDBType2*)launchParameters;
		p->cardNo = SWAP16(p->cardNo);
		tmp = p->dbID[0];
		p->dbID[0] = SWAP16(p->dbID[1]);
		p->dbID[1] = SWAP16(tmp);
	}

	if (launchCode == sysAppLaunchCmdNotify)
	{
		SysNotifyParamType* p = (SysNotifyParamType*)launchParameters;
		UInt32 Type = p->notifyType;
		void* Details = p->notifyDetailsP;

		p->notifyType = SWAP32(p->notifyType);
		p->broadcaster = SWAP32(p->broadcaster);
		p->notifyDetailsP = (void*)SWAP32(p->notifyDetailsP);
		p->userDataP = (void*)SWAP32(p->userDataP);
		
		if (From)
		{
			Type = p->notifyType;
			Details = p->notifyDetailsP;
		}

		if (Type == sysNotifySleepRequestEvent)
		{
			SleepEventParamType* i = (SleepEventParamType*)Details;
			i->reason = SWAP16(i->reason);
			i->deferSleep = SWAP16(i->deferSleep);
		}
	}
}

static INLINE uint32_t ReadSwap32(const void* p)
{
	return 
		(((const uint8_t*)p)[0] << 24)|
		(((const uint8_t*)p)[1] << 16)|
		(((const uint8_t*)p)[2] << 8)|
		(((const uint8_t*)p)[3] << 0);
}

static INLINE void WriteSwap32(void* p,uint32_t i)
{
	((uint8_t*)p)[0] = ((uint8_t*)&i)[3];
	((uint8_t*)p)[1] = ((uint8_t*)&i)[2];
	((uint8_t*)p)[2] = ((uint8_t*)&i)[1];
	((uint8_t*)p)[3] = ((uint8_t*)&i)[0];
}

void Event_M68K_To_ARM(const uint16_t* In,EventType* Out)
{
	Out->eType = SWAP16(In[0]);
	Out->penDown = ((uint8_t*)In)[2];
	Out->tapCount = ((uint8_t*)In)[3];
	Out->screenX = SWAP16(In[2]);
	Out->screenY = SWAP16(In[3]);

	switch (Out->eType)
	{
	// 1*16bit
	case frmLoadEvent:
	case menuEvent:
		Out->data.menu.itemID = SWAP16(In[4]);
		break;

	// 3*16bit
	case frmUpdateEvent:
	case keyUpEvent:
	case keyDownEvent:
	case keyHoldEvent:
		Out->data.keyDown.chr = SWAP16(In[4]);
		Out->data.keyDown.keyCode = SWAP16(In[5]);
		Out->data.keyDown.modifiers = SWAP16(In[6]);
		break;

	// 16bit,32bit
/*	case fldChangedEvent:
		Out->data.fldChanged.fieldID = SWAP16(In[4]);
		Out->data.fldChanged.pField = (FieldType*)ReadSwap32(In+5);
		break;
*/
	// 16bit,32bit,16bit,32bit,16bit,16bit
	case popSelectEvent:
		Out->data.popSelect.controlID = SWAP16(In[4]);
		Out->data.popSelect.controlP = (ControlType*)ReadSwap32(In+5);
		Out->data.popSelect.listID = SWAP16(In[7]);
		Out->data.popSelect.listP = (ListType*)SWAP32(*(uint32_t*)(In+8));
		Out->data.popSelect.selection = SWAP16(In[10]);
		Out->data.popSelect.priorSelection = SWAP16(In[11]);
		break;

	// 16bit,32bit,16bit
	case lstSelectEvent:
		Out->data.lstSelect.listID = SWAP16(In[4]);
		Out->data.lstSelect.pList = (ListType*)ReadSwap32(In+5);
		Out->data.lstSelect.selection = SWAP16(In[7]);
		break;

	//custom
	case sclRepeatEvent:
		Out->data.sclRepeat.scrollBarID = SWAP16(In[4]);
		Out->data.sclRepeat.pScrollBar = (ScrollBarType*)ReadSwap32(In+5);
		Out->data.sclRepeat.value = SWAP16(In[7]);
		Out->data.sclRepeat.newValue = SWAP16(In[8]);
		Out->data.sclRepeat.time = ReadSwap32(In+9);
		break;

	//custom
	case ctlRepeatEvent:
		Out->data.ctlRepeat.controlID = SWAP16(In[4]);
		Out->data.ctlRepeat.pControl = (ControlType*)ReadSwap32(In+5);
		Out->data.ctlRepeat.time = ReadSwap32(In+7);
		Out->data.ctlRepeat.value = SWAP16(In[9]);
		break;

	//custom
	case ctlSelectEvent: 
		Out->data.ctlSelect.controlID = SWAP16(In[4]);
		Out->data.ctlSelect.pControl = (ControlType*)ReadSwap32(In+5);
		Out->data.ctlSelect.on = ((uint8_t*)In)[14];
		Out->data.ctlSelect.reserved1 = ((uint8_t*)In)[15];
		Out->data.ctlSelect.value = SWAP16(In[8]);
		break;

	// 2*32bit
	case winEnterEvent:
	case winExitEvent:
		Out->data.winExit.enterWindow = (WinHandle)SWAP32(((uint32_t*)In)[2]);
		Out->data.winExit.exitWindow = (WinHandle)SWAP32(((uint32_t*)In)[3]);
		break;

	default:
		memcpy(Out->data.generic.datum,In+4,sizeof(uint16_t)*8);
		break;
	}
}

void Event_ARM_To_M68K(const EventType* In,uint16_t* Out)
{
	Out[0] = SWAP16(In->eType);
	((uint8_t*)Out)[2] = In->penDown;
	((uint8_t*)Out)[3] = In->tapCount;
	Out[2] = SWAP16(In->screenX);
	Out[3] = SWAP16(In->screenY);

	switch (In->eType)
	{
	// 1*16bit
	case frmLoadEvent:
	case menuEvent:
		Out[4] = SWAP16(In->data.menu.itemID);
		break;

	// 3*16bit
	case frmUpdateEvent:
	case keyUpEvent:
	case keyDownEvent:
	case keyHoldEvent:
		Out[4] = SWAP16(In->data.keyDown.chr);
		Out[5] = SWAP16(In->data.keyDown.keyCode);
		Out[6] = SWAP16(In->data.keyDown.modifiers);
		break;

	// 16bit,32bit,16bit
	case lstSelectEvent:
		Out[4] = SWAP16(In->data.lstSelect.listID);
		WriteSwap32(Out+5,(uint32_t)In->data.lstSelect.pList);
		Out[7] = SWAP16(In->data.lstSelect.selection);
		break;

	// 16bit,32bit
/*	case fldChangedEvent:
		Out[4] = SWAP16(In->data.fldChanged.fieldID);
		WriteSwap32(Out+5,(uint32_t)In->data.fldChanged.pField);
		break;
*/
	// 16bit,32bit,16bit,32bit,16bit,16bit
	case popSelectEvent:
		Out[4] = SWAP16(In->data.popSelect.controlID);
		WriteSwap32(Out+5,(uint32_t)In->data.popSelect.controlP);
		Out[7] = SWAP16(In->data.popSelect.listID);
		WriteSwap32(Out+8,(uint32_t)In->data.popSelect.listP);
		Out[10] = SWAP16(In->data.popSelect.selection);
		Out[11] = SWAP16(In->data.popSelect.priorSelection);
		break;

	//custom
	case sclRepeatEvent:
		Out[4] = SWAP16(In->data.sclRepeat.scrollBarID);
		WriteSwap32(Out+5,(uint32_t)In->data.sclRepeat.pScrollBar);
		Out[7] = SWAP16(In->data.sclRepeat.value);
		Out[8] = SWAP16(In->data.sclRepeat.newValue);
		WriteSwap32(Out+9,In->data.sclRepeat.time);
		break;

	//custom
	case ctlRepeatEvent:
		Out[4] = SWAP16(In->data.ctlRepeat.controlID);
		WriteSwap32(Out+5,(uint32_t)In->data.ctlRepeat.pControl);
		WriteSwap32(Out+7,In->data.ctlRepeat.time);
		Out[9] = SWAP16(In->data.ctlRepeat.value);
		break;

	//custom
	case ctlSelectEvent: 
		Out[4] = SWAP16(In->data.ctlSelect.controlID);
		WriteSwap32(Out+5,(uint32_t)In->data.ctlSelect.pControl);
		((uint8_t*)Out)[14] = In->data.ctlSelect.on;
		((uint8_t*)Out)[15] = In->data.ctlSelect.reserved1;
		Out[8] = SWAP16(In->data.ctlSelect.value);
		break;

	// 2*32bit
	case winEnterEvent:
	case winExitEvent:
		((uint32_t*)Out)[2] = SWAP32(In->data.winExit.enterWindow);
		((uint32_t*)Out)[3] = SWAP32(In->data.winExit.exitWindow);
		break;

	default:
		memcpy(Out+4,In->data.generic.datum,sizeof(uint16_t)*8);
		break;
	}
}


static void GadgetTypeInCallback_M68K_To_ARM(const uint16_t* In,FormGadgetTypeInCallback* Out)
{
	Out->id = SWAP16(In[0]);
	*(UInt16*)&Out->attr = SWAP16(In[1]);
	Out->rect.topLeft.x = SWAP16(In[2]);
	Out->rect.topLeft.y = SWAP16(In[3]);
	Out->rect.extent.x = SWAP16(In[4]);
	Out->rect.extent.y = SWAP16(In[5]);
	Out->data = (const void*)SWAP32(*(const uint32_t*)(In+6));
	Out->handler = (FormGadgetHandlerType*)SWAP32(*(const uint32_t*)(In+8));
}

static void GadgetTypeInCallback_ARM_To_M68K(const FormGadgetTypeInCallback* In,uint16_t* Out)
{
	Out[0] = SWAP16(In->id);
	Out[1] = SWAP16(*(UInt16*)&In->attr);
	Out[2] = SWAP16(In->rect.topLeft.x);
	Out[3] = SWAP16(In->rect.topLeft.y);
	Out[4] = SWAP16(In->rect.extent.x);
	Out[5] = SWAP16(In->rect.extent.y);
	*(uint32_t*)(Out+6) = SWAP32(In->data);
	*(uint32_t*)(Out+8) = SWAP32(In->handler);
}

static NOINLINE bool_t CmdLaunch(int Code)
{
	return Code == sysAppLaunchCmdNormalLaunch ||
		Code == sysAppLaunchCmdOpenDB ||
		Code == sysAppLaunchCmdCustomBase;
}

#if defined(_M_IX86)

#define NONE 0

pcecall PceCall = {NULL};

#include <windows.h>

DLLEXPORT uint32_t PaceMain86(const void *emulStateP, launch* Launch, Call68KFuncType *call68KFuncP)
{
	MemPtr Parameters = (MemPtr)((SWAP16(Launch->launchParameters[0])<<16)|(SWAP16(Launch->launchParameters[1])));
	int Code = SWAP16(Launch->launchCode);
	uint32_t Result; 
	pcecall Old = PceCall;

	if (CmdLaunch(Code))
		memcpy(&Peal,Launch,sizeof(launch));

	PceCall.Func = call68KFuncP;
	PceCall.State = emulStateP;

	SwapLanchParameters(Code,Parameters,1);
	Result = PilotMain((UInt16)Code,Parameters,SWAP16(Launch->launchFlags));
	SwapLanchParameters(Code,Parameters,0);

	if (CmdLaunch(Code))
		FreeHandlers();

	PceCall = Old;
	return Result;
}

void SaveSysRegs(sysregs* p)
{
}

void LoadSysRegs(sysregs* p)
{
}

static NOINLINE unsigned long Call68K(unsigned long trapOrFunction,
									const void *argsOnStackP, unsigned long argsSizeAndwantA0)
{
	pcecall* Call = &PceCall;
	return Call->Func(Call->State,trapOrFunction,argsOnStackP,argsSizeAndwantA0);
}

DLLEXPORT Boolean WrapperEventHandler86(const void *emulStateP, eventhandler* i, Call68KFuncType *call68KFuncP)
{
	Boolean Result;
	EventType EventARM;
	uint16_t* EventM68K = (uint16_t*) SWAP32(i->Event);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -