TEST(Z80_JumpTest, JumpToImmediateAddress) { TestJumpToImmediateAddress(0xC3, 0x0123, 0x0123, Clock(4, 16), { Flags::Zero }); TestJumpToImmediateAddress(0xC3, 0x4567, 0x4567, Clock(4, 16), { Flags::Subtract }); TestJumpToImmediateAddress(0xC3, 0x89AB, 0x89AB, Clock(4, 16), { Flags::HalfCarry }); TestJumpToImmediateAddress(0xC3, 0xCDEF, 0xCDEF, Clock(4, 16), { Flags::Carry }); }
TEST(Z80_JumpTest, JumpToAddressDisplacementIfCarry) { TestJumpToAddressDisplacement(0x38, 127, 128, Clock(3, 12), { Flags::Carry }); TestJumpToAddressDisplacement(0x38, -128, -127, Clock(3, 12), { Flags::Zero, Flags::Subtract, Flags::HalfCarry, Flags::Carry }); TestJumpToAddressDisplacement(0x38, 127, 1, Clock(2, 8), {}); TestJumpToAddressDisplacement(0x38, -128, 1, Clock(2, 8), { Flags::Zero, Flags::Subtract, Flags::HalfCarry }); }
TEST(Z80_JumpTest, JumpToImmediateAddressIfCarry) { TestJumpToImmediateAddress(0xDA, 0xCDEF, 0xCDEF, Clock(4, 16), { Flags::Carry }); TestJumpToImmediateAddress(0xDA, 0xCDEF, 0xCDEF, Clock(4, 16), { Flags::Zero, Flags::Subtract, Flags::HalfCarry, Flags::Carry }); TestJumpToImmediateAddress(0xDA, 0xCDEF, 0x0002, Clock(3, 12), {}); TestJumpToImmediateAddress(0xDA, 0xCDEF, 0x0002, Clock(3, 12), { Flags::Zero, Flags::Subtract, Flags::HalfCarry }); }
TEST(Z80_JumpTest, JumpToImmediateAddressIfNonZero) { TestJumpToImmediateAddress(0xC2, 0x0123, 0x0123, Clock(4, 16), {}); TestJumpToImmediateAddress(0xC2, 0x0123, 0x0123, Clock(4, 16), { Flags::Subtract, Flags::HalfCarry, Flags::Carry }); TestJumpToImmediateAddress(0xC2, 0x0123, 0x0002, Clock(3, 12), { Flags::Zero }); TestJumpToImmediateAddress(0xC2, 0x0123, 0x0002, Clock(3, 12), { Flags::Zero, Flags::Subtract, Flags::HalfCarry, Flags::Carry }); }
void Base::SourceAudioPreRead(std::size_t numFrames) //-------------------------------------------------- { if(!InternalHasTimeInfo()) { if(InternalHasGetStreamPosition()) { SoundDevice::TimeInfo timeInfo; timeInfo.StreamFrames = InternalHasGetStreamPosition(); timeInfo.SystemTimestamp = Clock().NowNanoseconds(); timeInfo.Speed = 1.0; UpdateTimeInfo(timeInfo); } else { SoundDevice::TimeInfo timeInfo; { Util::lock_guard<Util::mutex> lock(m_StreamPositionMutex); timeInfo.StreamFrames = m_StreamPositionRenderFrames + numFrames; } timeInfo.SystemTimestamp = Clock().NowNanoseconds() + Util::Round<int64>(m_BufferAttributes.Latency * 1000000000.0); timeInfo.Speed = 1.0; UpdateTimeInfo(timeInfo); } } }
TEST(Z80_JumpTest, JumpToAddressDisplacement) { TestJumpToAddressDisplacement(0x18, 127, 128, Clock(3, 12), { Flags::Zero }); TestJumpToAddressDisplacement(0x18, -128, -127, Clock(3, 12), { Flags::Subtract }); TestJumpToAddressDisplacement(0x18, 0, 1, Clock(3, 12), { Flags::HalfCarry }); TestJumpToAddressDisplacement(0x18, -1, 0, Clock(3, 12), { Flags::Carry }); }
void Client::Logic() { clock_t time = clock(); clock_t actime = time; SOCKET bsock; SocketBase bcomm; sockaddr_in &bsin = bcomm.Connect( PORT_BROADCAST ); bsock = bcomm.CreateSocket(); bcomm.Bind(); bcomm.SetBroadcast( true ); int keysize = int( key.size() + 1 ); int portsize = sizeof port; char *message = new char[ keysize + portsize ]; //memcpy( message, this.key.c_str(), keysize ); //memcpy( message + keysize, &this.port, portsize ); while ( running ) { LONGLONG flowend = Clock() - flowstart; if ( flowend > 1000000LL ) { flowstart = Clock(); currentdatasent = 0; float l = GetRTT(); if ( l < 0.0001f ) BandWidth += 512; else if ( l > 0.001f ) BandWidth -= 512; } if ( !ServerFound ) { FindServer( bsock, message, portsize, keysize ); } SendPackets(); ReceivePackets(); HandlePackets(); UpdateRTT(); Sleep( 10 ); } }
void Client::SendPackets() { msguse.Synchronize(); FillBuckets( messages ); messages.clear(); msguse.Release(); bool notdone = true; unsigned num = GetMaxPackSend(); while ( notdone && --num ) { unsigned char Buffer[MaxPacketSize]; unsigned offset = sizeof( UDPHeader ); while ( notdone = GetNextMessage( *reinterpret_cast<MessagePacket *>( Buffer + offset ) ) && ( offset += sizeof( MessagePacket ) ) < MaxPacketSize ); unsigned Size = offset - sizeof( UDPHeader ); UDPHeader Header = { CW, GetId(), seqnum, lastseqnum, Size, MissedPackets }; packetsent.push_back( Tick( seqnum++, Clock() ) ); memcpy( Buffer, &Header, sizeof Header ); currentdatasent += offset; int n = sendto( sock, ( char * )Buffer, offset, 0, ( sockaddr * )&serversin, sizeof( sockaddr_in ) ); Check( n ); } }
void TestJumpToAddressInRegHL(uint8_t opcode, uint16_t address, std::list<Flags> &&set_flags) { std::list<Flags> all_flags{ Flags::Zero, Flags::Subtract, Flags::HalfCarry, Flags::Carry }; all_flags.sort(); set_flags.sort(); std::list<Flags> unexpected_flags; auto it = std::set_difference(all_flags.begin(), all_flags.end(), set_flags.begin(), set_flags.end(), std::back_inserter(unexpected_flags)); TesterMMU mmu; Z80 z80(mmu); for (const auto& flag : set_flags) { z80.GetRegisters().SetFlag(flag, true); } z80.GetRegisters().Write(Register16bit::HL, address); z80.Execute(opcode); ASSERT_EQ(address, z80.GetRegisters().Read(Register16bit::PC)) << "PC read unexpected value: " << static_cast<size_t>(z80.GetRegisters().Read(Register16bit::PC)) << " (input value: 0x" << std::hex << static_cast<size_t>(address) << ")"; // Cycles information extracted from GameBoyProgrammingManual.pdf ASSERT_EQ(Clock(1, 4), z80.GetClock()) << "Unexpected operation duration: " << static_cast<size_t>(z80.GetClock().GetTicks()) << " (input value: 0x" << std::hex << static_cast<size_t>(address) << ")"; for (const auto& flag : set_flags) { ASSERT_TRUE(z80.GetRegisters().IsFlagSet(flag)) << "Expected flag is not set: " << flag << " (input value: 0x" << std::hex << static_cast<size_t>(address) << ")"; } for (const auto& flag : unexpected_flags) { ASSERT_FALSE(z80.GetRegisters().IsFlagSet(flag)) << "Unexpected flag is set: " << flag << " (input value: 0x" << std::hex << static_cast<size_t>(address) << ")"; } }
void TestRotateOperation(uint8_t opcode, uint8_t cb_opcode, Register8bit reg, uint8_t value, uint8_t expected_result, std::list<Flags> &&expected_flags, bool set_carry = false) { std::list<Flags> all_flags{ Flags::Zero, Flags::Subtract, Flags::HalfCarry, Flags::Carry }; all_flags.sort(); expected_flags.sort(); std::list<Flags> unexpected_flags; auto it = std::set_difference(all_flags.begin(), all_flags.end(), expected_flags.begin(), expected_flags.end(), std::back_inserter(unexpected_flags)); TesterMMU mmu; Z80 z80(mmu); if (set_carry) { z80.GetRegisters().SetFlag(Flags::Carry, true); } z80.GetRegisters().Write(reg, value); mmu.Write8bitToMemory(0, cb_opcode); z80.Execute(opcode); ASSERT_EQ(expected_result, z80.GetRegisters().Read(reg)) << "Register read unexpected value: " << static_cast<size_t>(z80.GetRegisters().Read(reg)) << " (input value: 0x" << std::hex << static_cast<size_t>(value) << ")"; ASSERT_EQ(1, z80.GetRegisters().Read(Register16bit::PC)) << "PC read unexpected value: " << static_cast<size_t>(z80.GetRegisters().Read(Register16bit::PC)) << " (input value: 0x" << std::hex << static_cast<size_t>(value) << ")"; ASSERT_EQ(Clock(2, 8), z80.GetClock()) << "Unexpected operation duration: " << static_cast<size_t>(z80.GetClock().GetTicks()) << " (input value: 0x" << std::hex << static_cast<size_t>(value) << ")"; for (const auto& flag : expected_flags) { ASSERT_TRUE(z80.GetRegisters().IsFlagSet(flag)) << "Expected flag is not set: " << flag << " (input value: 0x" << std::hex << static_cast<size_t>(value) << ")"; } for (const auto& flag : unexpected_flags) { ASSERT_FALSE(z80.GetRegisters().IsFlagSet(flag)) << "Unexpected flag is set: " << flag << " (input value: 0x" << std::hex << static_cast<size_t>(value) << ")"; } }
GLBox::GLBox( QWidget* parent, const QGLWidget* shareWidget ) : QGLWidget( parent, shareWidget ) { scale = 100; m_texID = 0; m_winWidth = 700; m_winHeight = 700; m_Ygravity = 1.0; m_Xgravity = 0.2; double m_focus = 0; //Brennweite, distance Viewer to Bildfläche // Initialize the texture buffer. m_buffer = new unsigned char[3*TEX_RES]; // Set new Clock m_clock = Clock(Vec3d(-1.0,1.0,1.0),100); // Set the timeout to 50 milliseconds, corresponding to 20 FPS. m_timeout = 50; // 50 msecs m_timer = new QTimer(this); // Connect the timeout signal of the timer to the animate slot. connect(m_timer, SIGNAL(timeout()), this, SLOT(animate())); // Start the timer. m_timer->start(m_timeout); m_elapsed = 0; }
Pipe::Pipe(const std::string& textureName, Vector2f& position, int indexPipeDestination, const std::string& levelDestination, State state, int lenght, Direction direction, Monster* monster) : Collisionable("textures/pipes/" + textureName, position), _indexDestination(indexPipeDestination), _levelDestination(levelDestination), _state(state), _lenght(lenght), _direction(direction), _monster(monster), _monsterExitDuration(Clock()) { _hitboxPosition.x = position.x; _hitboxPosition.y = position.y; setPositionX(position.x); setPositionY(position.y); _hitboxSize.x = _texture->getSize().x; _hitboxSize.y = (_texture->getSize().y / 2 * _lenght) + _texture->getSize().y / 2; }
void Timer::Start() { begin = Clock(); last = begin; buffer = 8; last_buffer = buffer; delay = 0; request = 0; }
ComponentMiniMap::ComponentMiniMap(const char* spriteFilename, int color) { clock = Clock(); //Calcula cuantos frames tiene que dejar pasar para repartirse entre todos los frames //Estos sprites empiezan a partir del id 4602 this->spriteFilename = spriteFilename; this->color = color; }
ComponentBulletLauncher::ComponentBulletLauncher(float damage, float fireRate,void (ComponentBulletLauncher::*fnc)()) { gameObjectManager = GameManager::getInstance()->getGameObjectManager(); this->damage = damage; delay = Clock(); shooting = false; targetObject = NULL; this->fireRate = fireRate; superShoot = fnc; }
ComponentHealth::ComponentHealth(float health, float shield, float rechargeTime) { this->health = health; this->maxHealth = health; this->shield = shield; this->maxShield = shield; this->initialHP = health; this->initialShield = shield; this->rechargeActivated = true; // El tiempo que tarda en comenzar a regenerarse el escudo this->rechargeTime = rechargeTime; this->rechargeClock = Clock(); // Tiempo que un jugador puede permanecer derribado antes de morir this->deathTime = 40000; // 40 segundos this->deathClock = Clock(); // Tiempo para revivir a un jugador this->reviveTime = 5000; // 5 segundos this->reviveClock = Clock(); this->playersVision = 0; }
USec MeasureAndPrint(const std::string &test, const std::string &stage, unsigned amount) const { if (amount < 1) amount = 1; const USec kResTm = Clock().GetDiff(*this) / amount; std::cout << "\t * " << test << ": " << stage << ": " << "[" << amount << "] " << kResTm << " usec" << std::endl; return kResTm; }
// RES n, r // (Z80 p.256) Clock Z80::ResetBit(uint8_t bit_index, Register8bit reg) { if (bit_index >= 8) { throw std::logic_error("ResetBit called with invalid bit index"); } // Flags not affected registers_.Write(reg, registers_.Read(reg) & ~(1 << bit_index)); return Clock(2, 8); }
void* SketchThread::sketch_thread_main(void*) { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL); Clock().delay(50); // Experimenting with some delay setup(); while(1) loop(); return NULL; }
// RES n, (rr) // (Z80 p.241) Clock Z80::ResetBit(uint8_t bit_index, Register16bit reg_addr) { if (bit_index >= 8) { throw std::logic_error("ResetBit called with invalid bit index"); } // Flags not affected WriteToMmu(registers_.Read(reg_addr), static_cast<uint8_t>(mmu_.Read8bitFromMemory(registers_.Read(reg_addr)) & ~(1 << bit_index))); return Clock(4, 16); }
void main() { old=getvect(0x1C);//得到中断向量 setvect(0x1C,get);//设置中断向量 gettime(&t);//获取时间 PrintClock();//显示时间 while(1) { Clock(); UpdateClock();//更新显示 End(); } }
bool ClockCollection::AddClocks(std::vector<SuiteRoot> suites, DWORD day_flag, DWORD hour, DWORD min, bool weekly) { if (day_flag > EVERY_DAY || hour > 24 || min > 60) return false; for (int i = 0; i < DAYS_IN_WEEK; ++i) { DWORD day_of_week = day_flag & (1 << i); if (day_of_week) clocks.push_back(Clock(suites, weekly, day_of_week, hour, min)); } return true; }
uint Timer::State() { if (request == buffer - 1) { uint now = Clock(); delay = now - last; if (delay < kClockDelay) { last_buffer = buffer; buffer *= 2; } last = now; request = 0; } else ++request; return last + request * delay / last_buffer - begin; }
void MidiController::loop() { unsigned long now = micros(); if (now >= _next) { _next += _sleep; Clock(); if (_timerCallback) { _timerCallback(); } } midiOUT2.read(); midiOUT.read(); midiIN.read(); }
OOBase::detail::xoroshiro128plus::xoroshiro128plus() { uint64_t s[2]; if (random_bytes(s,sizeof(s)) != 0) { splitmix64 sm(Clock().microseconds()); m_s0 = sm.next(); m_s1 = sm.next(); } else { m_s0 = s[0]; m_s1 = s[1]; } }
// ADD rr, rr' // (Z80 p.186) Clock Z80::Add(Register16bit dest, Register16bit source) { registers_.SetFlag(Flags::Subtract, false); {const uint16_t low_12_bits_result = (registers_.Read(source) & 0x0FFF) + (registers_.Read(dest) & 0x0FFF); registers_.SetFlag(Flags::HalfCarry, (low_12_bits_result & 0x1000) != 0); } const uint32_t result = registers_.Read(source) + registers_.Read(dest); registers_.SetFlag(Flags::Carry, (result & 0x10000) != 0); // Z is unaffected registers_.Write(dest, static_cast<uint16_t>(result & 0xFFFF)); return Clock(2, 8); }
// BIT n, r // (Z80 p.241) Clock Z80::TestBit(uint8_t bit_index, Register8bit reg) { if (bit_index >= 8) { throw std::logic_error("TestBit called with invalid bit index"); } registers_.SetFlag(Flags::HalfCarry, true); registers_.SetFlag(Flags::Subtract, false); // C is not affected registers_.SetFlag(Flags::Zero, (registers_.Read(reg) & (1 << bit_index)) == 0); return Clock(2, 8); }
void Aggregator::StartThread() { int id = thread_counter_++; VectorClock flush_vector(num_trainers_); VectorClock clock_vector(num_trainers_); DeltaPool* delta_pool = delta_pools_[id]; barrier_->Wait(); integer_t table, row, col; void* delta; zmq::socket_t* socket = ZMQUtil::CreateSocket(); while (delta_pool->Pop(table, row, col, delta)) { switch (static_cast<DeltaType>(row)) { case DeltaType::Flush: if (flush_vector.Update(col)) { Send(id, socket); if (barrier_->Wait()) { for (auto& table : tables_) { table->Clear(); } } barrier_->Wait(); } break; case DeltaType::Clock: if (clock_vector.Update(col)) { if (barrier_->Wait()) { Clock(socket); } barrier_->Wait(); } break; default: // the general delta type, add update to aggregator table assert(row >= 0); tables_[table]->GetRow(row)->Add(col, delta); } } delete socket; }
// SBC rr, rr' // (Z80 p.190) Clock Z80::SubtractMinusCarry(Register16bit dest, Register16bit source) { registers_.SetFlag(Flags::Subtract, true); {const uint16_t low_12_bits_result = (registers_.Read(source) & 0x0FFF) - (registers_.Read(dest) & 0x0FFF) - (registers_.IsFlagSet(Flags::Carry) ? 1 : 0); registers_.SetFlag(Flags::HalfCarry, (low_12_bits_result & 0x1000) != 0); } const uint32_t result = registers_.Read(source) - registers_.Read(dest) - (registers_.IsFlagSet(Flags::Carry) ? 1 : 0); registers_.SetFlag(Flags::Carry, (result & 0x10000) != 0); registers_.SetFlag(Flags::Zero, (result & 0xFFFF) == 0); registers_.Write(dest, static_cast<uint16_t>(result & 0xFFFF)); return Clock(4, 16); }
void GboxInstance::HandleMessage(const pp::Var& var_message) { if (!var_message.is_string()) return; std::string message = var_message.AsString(); pp::Var var_reply; if (message == kHelloString) { theLog.info("message: '%s'", message.c_str()); Hello(); } else if (message == kPaintMethodId) { Paint(); } else if (message == kClockMethodId) { Clock(); } else if (message == "quiet") { theLog.info("message: '%s'", message.c_str()); Quiet(); } else { theLog.info("other message: '%s'", message.c_str()); Other(message); } }