Beispiel #1
0
void EmFileRef::SetEmulatorRef	(const EmFileRef& ref)
{
	EmAssert (ref.IsSpecified ());
	EmAssert (!gEmulatorRef.IsSpecified ());

	gEmulatorRef = ref;
}
Beispiel #2
0
void EmHAL::AddHandler (EmHALHandler* handler)
{
	EmAssert (handler->fNextHandler == NULL);
	EmAssert (handler->fPrevHandler == NULL);
	EmAssert (fgRootHandler == NULL || fgRootHandler->fPrevHandler == NULL);

	if (fgRootHandler != NULL)
	{
		fgRootHandler->fPrevHandler = handler;
		handler->fNextHandler = fgRootHandler;
	}

	fgRootHandler = handler;
}
Beispiel #3
0
EmDocument* EmDocument::DoNewBound (void)
{
	EmAssert (gApplication->IsBoundPartially ());

	// Create the new document.

	EmDocument*	doc = EmDocument::HostCreateDocument ();

	try
	{
		// Create the new session.

		doc->fSession = new EmSession;
		doc->fSession->CreateBound ();
		doc->fSession->CreateThread (false);	// !!! Created here, but destroyed in EmSession::~EmSession!
	}
	catch (...)
	{
		delete doc;
		throw;
	}

	// If we got here, then everything worked.  Open a window on the session.

	doc->PrvOpenWindow ();

	return doc;
}
EmApplicationFltk::EmApplicationFltk (void) :
	EmApplication (),
	fAppWindow (NULL)
{
	EmAssert (gHostApplication == NULL);
	gHostApplication = this;
}
Beispiel #5
0
void StateBehavior::StdOnSignal() {
    EmAssert(this->getParent() != NULL, "Parent NULL");
    if (p_CurrentStateItem == NULL && m_vStateItem.size() == 0) return;

    // initialize origo, this is a ugle hack
    if (m_iTick == 0) {
        this->getParent()->getTranslation(m_vtxTr.x, m_vtxTr.y, m_vtxTr.z);
        this->getParent()->getRotation(m_vtxRot.x, m_vtxRot.y, m_vtxRot.z);
    }

#if EM_DEBUG
    if (Loader::getInstance()->getSignal(GetSignal()) != NULL) {
        EM_COUT("Got signal " << Loader::getInstance()->getSignal(GetSignal()), 0);
    }
#endif

    OnSignal( PBL_SIG_RESET_ALL) {
        this->setState(m_vStateItem[0]);
        // do a fast move
        if (m_bMove) {
            this->getParent()->setTransform(m_vtxTr.x + p_CurrentStateItem->m_vtxTr.x,
                                            m_vtxTr.y + p_CurrentStateItem->m_vtxTr.y,
                                            m_vtxTr.z + p_CurrentStateItem->m_vtxTr.z,
                                            m_vtxRot.x + p_CurrentStateItem->m_vtxRot.x,
                                            m_vtxRot.y + p_CurrentStateItem->m_vtxRot.y,
                                            m_vtxRot.z + p_CurrentStateItem->m_vtxRot.z);

        }
    }
    else {
EmApplicationFltk::~EmApplicationFltk (void)
{
	delete fAppWindow;

	EmAssert (gHostApplication == this);
	gHostApplication = NULL;
}
Beispiel #7
0
Bool EmDocument::AskLoadSession (EmFileRef& ref, EmFileType type)
{
	EmAssert (!gApplication->IsBoundFully ());

	// Start by showing the user the directory in which they saved the
	// last session file.

	Preference<EmFileRef>	pref (kPrefKeyLastPSF);
	EmFileRef				lastSession = *pref;

	// Get other parameters used in presenting the dialog.

	string					prompt (Platform::GetString (kStr_LoadSession));
	EmDirRef				defaultPath (lastSession.GetParent ());
	EmFileTypeList			filterList;

	filterList.push_back (type);
	filterList.push_back (kFileTypeAll);

	// Ask the user for a file name.

	EmDlgItemID	item = EmDlg::DoGetFile (
		ref, prompt, defaultPath, filterList);

	// Return whether or not the user cancelled the operation.

	return item == kDlgItemOK;
}
Beispiel #8
0
void EmHAL::EnsureCoverage (void)
{
#if 0
	// Rats...can't get this work...

	Bool			isHandled[20];
	EmHALHandler*	thisHandler = fgRootHandler;
	EmHALHandler	baseHandler;

	while (thisHandler)
	{
		typedef void (EmHALHandler::*CycleHandler)(Bool);
		CycleHandler	p1 = (thisHandler->Cycle);
		CycleHandler	p2 = (baseHandler.Cycle);

		if (p1 != p2)
		{
			isHandled[0] = true;
		}

		thisHandler = thisHandler->fNextHandler;
	}

	for (int ii = 0; ii < sizeof (isHandled); ++ii)
	{
		EmAssert (isHandled[ii]);
	}
#endif
}
Beispiel #9
0
Bool EmDocument::HandleSaveTo (const EmFileRef& destRef)
{
	EmAssert (destRef.IsSpecified ());

	// Suspend the session so that we can save its data.

	EmSessionStopper	stopper (fSession, kStopNow);

	// Have the session save itself.

	const Bool kUpdateFileRef = true;
	fSession->Save (destRef, kUpdateFileRef);

	// Remember that we are now associated with this file.

	fFile = destRef;

	// Save the last-saved session file for next time.

	Preference<EmFileRef>	pref (kPrefKeyLastPSF);
	pref = destRef;

	// Update the MRU menu.

	gEmuPrefs->UpdateRAMMRU (destRef);

	// Return that we saved the file.

	return true;
}
Beispiel #10
0
Bool PrvHandleTrap12 (ExceptionNumber)
{
	EmAssert (gSession);
	gSession->ScheduleSuspendSubroutineReturn ();

	return true;
}
Beispiel #11
0
void EmDocument::HandleButton (SkinElementType theButton, Bool isDown)
{
	EmAssert (fSession);

	EmButtonEvent	event (theButton, isDown);
	fSession->PostButtonEvent (event);
}
Beispiel #12
0
Bool EmHALHandler::GetVibrateOn (void)
{
	if (!this->GetNextHandler())
		return false;

	EmAssert (this->GetNextHandler());
	return this->GetNextHandler()->GetVibrateOn ();
}
Beispiel #13
0
EmDocument::EmDocument (void) :
	EmActionHandler (),
	fSession (NULL),
	fFile ()
{
	EmAssert (gDocument == NULL);
	gDocument = this;
}
Beispiel #14
0
uint16 EmHALHandler::GetLEDState (void)
{
	if (!this->GetNextHandler())
		return 0;

	EmAssert (this->GetNextHandler());
	return this->GetNextHandler()->GetLEDState ();
}
Beispiel #15
0
void StateBehavior::onTick() {
    EmAssert(this->getParent() != NULL, "Parent NULL");
    if (p_CurrentStateItem == NULL) return;

    // initialize origo
    if (m_iTick == 0) {
        this->getParent()->getTranslation(m_vtxTr.x, m_vtxTr.y, m_vtxTr.z);
        this->getParent()->getRotation(m_vtxRot.x, m_vtxRot.y, m_vtxRot.z);
    }

    m_iTick++;
    p_CurrentStateItem->m_iTick++;

    if (p_CurrentStateItem->m_iDelay >= 0 &&
            p_CurrentStateItem->m_iTick >= p_CurrentStateItem->m_iDelay &&
            p_CurrentStateItem->m_iDelayState >= 0) {
        this->setState(this->getStateItem(p_CurrentStateItem->m_iDelayState));
    }
    // the ball recently collided with this object is in a safe distance
    if (m_iTick > m_iCollisionSafe) {
        m_iOwnerBall = -1;
    }
    // move the object to towards the next spot
    // TODO smother move
    if (m_bMove) {
        int steps = p_CurrentStateItem->m_iMoveSteps - p_CurrentStateItem->m_iTick;

        if (steps <= 0) {
            this->getParent()->setTransform(m_vtxTr.x + p_CurrentStateItem->m_vtxTr.x,
                                            m_vtxTr.y + p_CurrentStateItem->m_vtxTr.y,
                                            m_vtxTr.z + p_CurrentStateItem->m_vtxTr.z,
                                            m_vtxRot.x + p_CurrentStateItem->m_vtxRot.x,
                                            m_vtxRot.y + p_CurrentStateItem->m_vtxRot.y,
                                            m_vtxRot.z + p_CurrentStateItem->m_vtxRot.z);
        } else {
            float dtx, dty, dtz, drx, dry, drz;
            float tx, ty, tz, rx, ry, rz;
            this->getParent()->getTranslation(tx, ty, tz);
            this->getParent()->getRotation(rx, ry, rz);

            dtx =  p_CurrentStateItem->m_vtxTr.x + m_vtxTr.x - tx;
            dty =  p_CurrentStateItem->m_vtxTr.y + m_vtxTr.y - ty;
            dtz =  p_CurrentStateItem->m_vtxTr.z + m_vtxTr.z - tz;
            drx =  p_CurrentStateItem->m_vtxRot.x + m_vtxRot.x - rx;
            dry =  p_CurrentStateItem->m_vtxRot.y + m_vtxRot.y - ry;
            drz =  p_CurrentStateItem->m_vtxRot.z + m_vtxRot.z - rz;

            dtx /= steps;
            dty /= steps;
            dtz /= steps;
            drx /= steps;
            dry /= steps;
            drz /= steps;
            this->getParent()->addTransform(dtx, dty, dtz, drx, dry, drz);
        }
    }
}
Beispiel #16
0
ATrap::~ATrap (void)
{
	// Put things back the way they were.

	EmPalmOS::ForgetStack (EmBankMapped::GetEmulatedAddress (this->GetStackBase ()));

	EmAssert (gCPU68K);
	gCPU68K->SetRegisters (fOldRegisters);

	// Check to see if anything interesting was registered while we
	// were making the Palm OS subroutine call.  The "check after end
	// of cycle" bit may have gotten cleared when restoring the old
	// registers, so set it on the off chance that it was.  Doing this
	// is harmless if there really aren't any scheduled tasks.

	EmAssert (gSession);
	gCPU68K->CheckAfterCycle ();
}
Beispiel #17
0
EmDocument::~EmDocument (void)
{
	EmDlg::GremlinControlClose ();

	EmAssert (gDocument == this);
	gDocument = NULL;

	delete fSession;
}
Beispiel #18
0
void EmActionDialog::Do (void)
{
	// Show any error messages from the CPU thread.

	fDlgResult = EmDlg::RunDialog (fDlgFn, fDlgParms);

#if HAS_OMNI_THREAD
	EmAssert (gSession);
	gSession->UnblockDialog ();
#endif
}
Beispiel #19
0
void StdAnimation::onTick() {
    EmAssert(this->getParent() != NULL, "Parent not allowed to be null");

    float x, y, z;
    float sX, sY, sZ;
    float eX, eY, eZ;
    float k=0.0;
    int index;
    int size = m_vVertex.size();

    if (m_iTick >= size*m_iStep) {
        m_iTick = 0;
    }

    index = (int)(m_iTick/m_iStep);

    sX = m_vVertex[index].x;
    sY = m_vVertex[index].y;
    sZ = m_vVertex[index].z;

    if (index + 1 < size) {
        eX = m_vVertex[index+1].x;
        eY = m_vVertex[index+1].y;
        eZ = m_vVertex[index+1].z;
    } else {
        eX = m_vtxEnd.x;
        eY = m_vtxEnd.y;
        eZ = m_vtxEnd.z;
    }

    k = ((float)(m_iTick%m_iStep)/m_iStep);
    x = (float)(sX + (eX - sX)*k);
    y = (float)(sY + (eY - sY)*k);
    z = (float)(sZ + (eZ - sZ)*k);

    m_iTick++;

    if (m_iAnimType & EM_TRANSLATION) {
        this->getParent()->setTranslation(x, y, z);
    }	else if (m_iAnimType & EM_ROTATION) {
        this->getParent()->setRotation(x, y, z);
    }	else if (m_iAnimType & EM_LIGHT) {
        Light* l = this->getParent()->getLight();
        if (l != NULL) {
            l->setColor(x, y, z);
        }
    } else if (m_iAnimType & EM_BILLBOARD_SIZE) {
        BillBoard * b = this->getParent()->getBillBoard();
        if (b != NULL) {
            b->setSize(x, y);
            b->setZOffset(z);
        }
    }
}
Beispiel #20
0
Bool EmDocument::AskNewSession (Configuration& cfg)
{
	EmAssert (!gApplication->IsBound ());

	// Ask the user for new configuration information.

	EmDlgItemID	item = EmDlg::DoSessionNew (cfg);

	// Return whether or not the user cancelled the operation.

	return item == kDlgItemOK;
}
Beispiel #21
0
void ATrap::Call (uint16 trapWord)
{
	EmAssert (trapWord != sysTrapSysReset);

	// Up until now, the registers in "regs" have been left alone.  If any
	// values were pushed on the stack, the stack position was reflected in
	// fNewRegisters.  Now's the time to move those values from fNewRegisters
	// to regs.

	EmAssert (gCPU68K);
	gCPU68K->SetRegisters (fNewRegisters);

	// Make the call.

	this->DoCall(trapWord);

	// Remember the resulting register values so that we can report them to
	// the user when they call GetD0 and/or GetA0.

	gCPU68K->GetRegisters (fNewRegisters);
}
Beispiel #22
0
void EmHAL::RemoveHandler (EmHALHandler* handler)
{
	if (handler->fNextHandler)
	{
		handler->fNextHandler->fPrevHandler = handler->fPrevHandler;
	}

	if (handler->fPrevHandler)
	{
		handler->fPrevHandler->fNextHandler = handler->fNextHandler;
	}
	else
	{
		fgRootHandler = handler->fNextHandler;
	}

	handler->fNextHandler = NULL;
	handler->fPrevHandler = NULL;

	EmAssert (handler->fNextHandler == NULL);
	EmAssert (handler->fPrevHandler == NULL);
	EmAssert (fgRootHandler == NULL || fgRootHandler->fPrevHandler == NULL);
}
Beispiel #23
0
void Memory::Save (SessionFile& f)
{
	EmBankDummy::Save (f);
	EmBankRegs::Save (f);
	EmBankSRAM::Save (f);
	EmBankDRAM::Save (f);
	EmBankROM::Save (f);
	EmBankMapped::Save (f);

	EmAssert (gSession);
	if (gSession->GetDevice ().HasFlash ())
		EmBankFlash::Save (f);

	MetaMemory::Save (f);
}
Beispiel #24
0
ATrap::ATrap (void) :
#if (__GNUC__ < 2)
/* Can't call the default constructor because there isn't one defined */
/* on a struct as there is with a class under GCC 2.8.1 */
	fNewRegisters (),
#endif
	fEmulatedStackMapper (this->GetStackBase (), kStackSize)
{
	// Get the registers.

	EmAssert (gCPU68K);
	gCPU68K->GetRegisters (fOldRegisters);
	fNewRegisters = fOldRegisters;

	// Make sure the CPU is not stopped.  I suppose that we could force the CPU
	// to no longer be stopped, but I'd rather that the Palm OS itself woke up
	// first before we try making calls into it.  Therefore, anything making
	// an out-of-the-blue Palm OS call via this class (that is, a call outside
	// of the context of a Palm OS function head- or tailpatch) should first
	// bring the CPU to a halt by calling EmSession::ExecuteUntilSysCall first.

	EmAssert (fNewRegisters.stopped == 0);

	// Give ourselves our own private stack.  We'll want this in case
	// we're in the debugger and the stack pointer is hosed.

	m68k_areg (fNewRegisters, 7) = EmBankMapped::GetEmulatedAddress (
										this->GetStackBase () + kStackSize - 4);

	// Remember this as a stack so that our stack sniffer won't complain.

	char*	stackBase = this->GetStackBase ();
	StackRange	range (	EmBankMapped::GetEmulatedAddress (&stackBase[0]), 
						EmBankMapped::GetEmulatedAddress (&stackBase[kStackSize - 4]));
	EmPalmOS::RememberStackRange (range);
}
Beispiel #25
0
void Memory::Load (SessionFile& f)
{
	EmBankDummy::Load (f);
	EmBankRegs::Load (f);
	EmBankSRAM::Load (f);
	EmBankDRAM::Load (f);
	EmBankROM::Load (f);
	EmBankMapped::Load (f);

	EmAssert (gSession);
	if (gSession->GetDevice ().HasFlash ())
		EmBankFlash::Load (f);

	MetaMemory::Load (f);

	Memory::ResetBankHandlers ();
}
Beispiel #26
0
void Memory::Reset (Bool hardwareReset)
{
	EmBankDummy::Reset (hardwareReset);
	EmBankRegs::Reset (hardwareReset);
	EmBankSRAM::Reset (hardwareReset);
	EmBankDRAM::Reset (hardwareReset);
	EmBankROM::Reset (hardwareReset);
	EmBankMapped::Reset (hardwareReset);

	EmAssert (gSession);
	if (gSession->GetDevice ().HasFlash ())
		EmBankFlash::Reset (hardwareReset);

	Memory::ResetBankHandlers ();

	MetaMemory::Reset ();
}
void CollisionBounds::addIntersect(Polygon3D* p) {
	EmAssert(p != NULL, "CollisionBounds::add polygon NULL");
	EM_COUT("CollisionBounds::add" << endl, 0);
	// add polygons only to leafs
	if (m_vCollisionBounds.size() > 0) {
		vector<CollisionBounds*>::iterator iter = m_vCollisionBounds.begin();
		vector<CollisionBounds*>::iterator end = m_vCollisionBounds.end();
		for (; iter != end; ++iter) {
			(*iter)->addIntersect(p);
		}
	} else {
		// add intersection polygon to bounds
		if (this->intersect(p)) {
			m_vPolygon.push_back(p);
		}
	}
}
/* Adds a polygon to the collision bound.
 * If the the collision bound has children the polygon is
 * added to all of the children. If a leaf collision bounds
 * surrounds a polygon, there is no need to add it to
 * neighbouring bounds. This function returns true if
 * if a leaf fully surrounds a polygon. */
bool CollisionBounds::addSurround(Polygon3D* p) {
	EmAssert(p != NULL, "CollisionBounds::add polygon NULL");
	EM_COUT("CollisionBounds::add" << endl, 0);
	// add polygons only to leafs
	if (m_vCollisionBounds.size() > 0) {
		vector<CollisionBounds*>::iterator iter = m_vCollisionBounds.begin();
		vector<CollisionBounds*>::iterator end = m_vCollisionBounds.end();
		for (; iter != end; ++iter) {
			if ((*iter)->addSurround(p)) return true;
		}
	} else {
		// add surrounded polygon to bounds
		if (this->surround(p) == 2) {
			m_vPolygon.push_back(p);
			return true;
		}
	}
	return false;
}
Beispiel #29
0
void Memory::Initialize (	EmStream&		hROM,
							RAMSizeType		ramSize)
{
	// Clear everything out.
	
	memset (gEmMemBanks, 0, sizeof (gEmMemBanks));

	// Initialize the valid memory banks.

	EmBankDummy::Initialize ();

	// Initialize the Hardware registers memory bank.  Do this
	// *before* initializing the other RAM banks so that we
	// know how memory is laid out from the chip selects.

	EmBankRegs::Initialize ();

	// Initialize EmBankDRAM after initializing the EmBankSRAM. The order is
	// important for DragonballEZ. On Dragonball devices, DRAM is
	// at 0x00000000, and SRAM is at 0x10000000. But on EZ devices,
	// both start at 0x00000000. By calling EmBankDRAM::Initialize
	// second, we allow it to overwrite the EmAddressBank handlers
	// for the part of memory where they overlap.

	EmBankSRAM::Initialize (ramSize);
	EmBankDRAM::Initialize ();

	EmBankROM::Initialize (hROM);

	EmBankMapped::Initialize ();

	EmAssert (gSession);
	if (gSession->GetDevice ().HasFlash ())
		EmBankFlash::Initialize ();

	MetaMemory::Initialize ();

//	Memory::ResetBankHandlers ();	// Can't do this yet.  We can't set the
									// bank handlers until we know how memory
									// is laid out, and that information isn't
									// determined until reset.
}
Beispiel #30
0
EmDlgItemID EmDocument::AskSaveChanges (Bool quitting)
{
	string	name;

	if (fFile.IsSpecified ())
	{
		name = fFile.GetName ();
	}
	else
	{
		// DoSessionSave provides the kStr_Untitled string
		// if the given string is empty.
	}

	EmDlgItemID	item = EmDlg::DoSessionSave (name, quitting);

	EmAssert (item == kDlgItemYes || item == kDlgItemNo || item == kDlgItemCancel);

	return item;
}