/* * When one player's ship dies, there's a delay before the next ship * can be chosen. This time depends on the time the ditty is playing * and may differ for each side. * To synchronise the time, the following protocol is followed: * 1. (NetState_inBattle) The Ready protocol is used to let either * party know when they're ready to stop the battle. * 2. (NetState_endingBattle) Each party sends the frame number of when * it wants to end the battle, and continues until that point, where * it waits until it has received the frame number of the other party. * 3. After a player has both sent and received a frame count, the * simulation continues for each party, until the maximum of both * frame counts has been achieved. * 4. The Ready protocol is used to let each side signal that it has * reached the target frame count. * 5. The battle ends. */ static bool readyForBattleEndPlayer (NetConnection *conn) { BattleStateData *battleStateData; battleStateData = (BattleStateData *) NetConnection_getStateData(conn); if (NetConnection_getState (conn) == NetState_interBattle || NetConnection_getState (conn) == NetState_inSetup) { // This connection is already ready. The entire synchronisation // protocol has already been done for this connection. return true; } if (NetConnection_getState (conn) == NetState_inBattle) { if (Netplay_isLocalReady(conn)) { // We've already sent notice that we are ready, but we're // still waiting for the other side to say it's ready too. return false; } // We haven't yet told the other side we're ready. We do so now. Netplay_localReady (conn, readyToEndCallback, NULL, true); // This may set the state to endingBattle. if (NetConnection_getState (conn) == NetState_inBattle) return false; } assert (NetConnection_getState (conn) == NetState_endingBattle || NetConnection_getState (conn) == NetState_endingBattle2); // Keep the simulation going as long as the target frame count // hasn't been reached yet. Note that if the connection state is // NetState_endingBattle, then we haven't yet received the // remote frame count, so the target frame count may still rise. if (battleFrameCount < battleStateData->endFrameCount) return false; if (NetConnection_getState (conn) == NetState_endingBattle) { // We have reached the target frame count, but we don't know // the remote target frame count yet. So we wait until it has // come in. waitReady (conn); // TODO: check whether all connections are still connected. assert (NetConnection_getState (conn) == NetState_endingBattle2); // Continue the simulation if the battleFrameCount has gone up. if (battleFrameCount < battleStateData->endFrameCount) return false; } // We are ready and wait for the other party to become ready too. negotiateReady (conn, true, NetState_interBattle); return true; }
bool Flash::erase() { mBase->CR.PSIZE = static_cast<uint32_t>(mAccessSize); mBase->CR.MER = 1; mBase->CR.STRT = 1; waitReady(); mBase->CR.MER = 0; return result(); }
bool Flash::erase(unsigned int sector) { mBase->CR.PSIZE = static_cast<uint32_t>(mAccessSize); mBase->CR.SER = 1; mBase->CR.SNB = sector; mBase->CR.STRT = 1; waitReady(); mBase->CR.SER = 0; return result(); }
bool Flash::write(uint32_t address, const T *data, unsigned int count) { uint32_t size = 0; while (sizeof(T) != (1 << size)) ++size; mBase->CR.PSIZE = size; volatile T* dest = reinterpret_cast<volatile T*>(address); mBase->CR.PG = 1; for (unsigned int i = 0; i < count; ++i) *dest++ = *data++; waitReady(); mBase->CR.PG = 0; return result(); }
//============================================================================= // METHOD: SPELLipcClientInterface:connectIfc //============================================================================= void SPELLipcClientInterface::connectIfc() { DEBUG("[IPC-CLI-" + m_name + "] Connecting client interface"); m_socket = SPELLsocket::connect( m_serverHost, m_serverPort ); readMyKey(); m_connected = true; m_writer = new SPELLipcOutput(m_name, m_socket, m_clientKey, this); m_reader = new SPELLipcInput(m_name, m_socket, m_clientKey, this); m_reader->start(); waitReady(); DEBUG("[[IPC-CLI-" + m_name + "] Ready"); }
bool Pad::init() { int ret; int modes; int i; waitReady(); // How many different modes can this device operate in? // i.e. get # entrys in the modetable modes = padInfoMode(m_port, m_slot, PAD_MODETABLE, -1); //printf("The device has %d modes\n", modes); if (modes > 0) { //printf("( "); for (i = 0; i < modes; i++) { //printf("%d ", padInfoMode(m_port, m_slot, PAD_MODETABLE, i)); } //printf(")"); } //printf("It is currently using mode %d\n", padInfoMode(m_port, m_slot, PAD_MODECURID, 0)); // If modes == 0, this is not a Dual shock controller // (it has no actuator engines) if (modes == 0) { //printf("This is a digital controller?\n"); return false; } // Verify that the controller has a DUAL SHOCK mode i = 0; do { if (padInfoMode( m_port, m_slot, PAD_MODETABLE, i) == PAD_TYPE_DUALSHOCK) break; i++; } while (i < modes); if (i >= modes) { //printf("This is no Dual Shock controller\n"); return false; } // If ExId != 0x0 => This controller has actuator engines // This check should always pass if the Dual Shock test above passed ret = padInfoMode(m_port, m_slot, PAD_MODECUREXID, 0); if (ret == 0) { //printf("This is no Dual Shock controller??\n"); return false; } //printf("Enabling dual shock functions\n"); // When using MMODE_LOCK, user cant change mode with Select button padSetMainMode(m_port, m_slot, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK); waitReady(); //printf("infoPressMode: %d\n", padInfoPressMode(m_port, m_slot)); waitReady(); //printf("enterPressMode: %d\n", padEnterPressMode(m_port, m_slot)); waitReady(); s_actuators = padInfoAct(m_port, m_slot, -1, 0); //printf("# of m_actuators: %d\n",ms_actuators); if (s_actuators != 0) { s_actAlign[0] = 0; // Enable small engine s_actAlign[1] = 1; // Enable big engine s_actAlign[2] = 0xff; s_actAlign[3] = 0xff; s_actAlign[4] = 0xff; s_actAlign[5] = 0xff; waitReady(); //printf("padSetActAlign: %d\n", //padSetActAlign(m_port, m_slot, ms_actAlign)); } else { //printf("Did not find any m_actuators.\n"); } waitReady(); update(); return true; }