Move the instruction ptr to the next active promoter
| 7802 | |
| 7803 | // Move the instruction ptr to the next active promoter |
| 7804 | bool cHardwareCPU::Inst_Terminate(cAvidaContext& ctx) |
| 7805 | { |
| 7806 | // Optionally, |
| 7807 | // Reset the thread. |
| 7808 | if (m_world->GetConfig().TERMINATION_RESETS.Get()) |
| 7809 | { |
| 7810 | //const int write_head_pos = getHead(nHardware::HEAD_WRITE).GetPosition(); |
| 7811 | //const int read_head_pos = getHead(nHardware::HEAD_READ).GetPosition(); |
| 7812 | m_threads[m_cur_thread].Reset(this, m_threads[m_cur_thread].GetID()); |
| 7813 | //getHead(nHardware::HEAD_WRITE).Set(write_head_pos); |
| 7814 | //getHead(nHardware::HEAD_READ).Set(read_head_pos); |
| 7815 | |
| 7816 | //Setting this makes it harder to do things. You have to be modular. |
| 7817 | m_organism->GetOrgInterface().ResetInputs(ctx); // Re-randomize the inputs this organism sees |
| 7818 | m_organism->ClearInput(); // Also clear their input buffers, or they can still claim |
| 7819 | // rewards for numbers no longer in their environment! |
| 7820 | } |
| 7821 | |
| 7822 | // Reset our count |
| 7823 | m_threads[m_cur_thread].ResetPromoterInstExecuted(); |
| 7824 | m_advance_ip = false; |
| 7825 | const int reg_used = REG_BX; // register to put chosen promoter code in, for now always BX |
| 7826 | |
| 7827 | // Search for an active promoter |
| 7828 | int start_offset = m_promoter_offset; |
| 7829 | int start_index = m_promoter_index; |
| 7830 | |
| 7831 | bool no_promoter_found = true; |
| 7832 | if ( m_promoters.GetSize() > 0 ) { |
| 7833 | while (true) { |
| 7834 | // If the next promoter is active, then break out |
| 7835 | NextPromoter(); |
| 7836 | if (IsActivePromoter()) { |
| 7837 | no_promoter_found = false; |
| 7838 | break; |
| 7839 | } |
| 7840 | |
| 7841 | // If we just checked the promoter that we were originally on, then there |
| 7842 | // are no active promoters. |
| 7843 | if ( (start_offset == m_promoter_offset) && (start_index == m_promoter_index) ) break; |
| 7844 | |
| 7845 | // If we originally were not on a promoter, then stop once we check the |
| 7846 | // first promoter and an offset of zero |
| 7847 | if (start_index == -1) { |
| 7848 | start_index = 0; |
| 7849 | } |
| 7850 | } |
| 7851 | } |
| 7852 | |
| 7853 | if (no_promoter_found) { |
| 7854 | if ((m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 0) || (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 2)) { |
| 7855 | // Set defaults for when no active promoter is found |
| 7856 | m_promoter_index = -1; |
| 7857 | getIP().Set(0); |
| 7858 | GetRegister(reg_used) = 0; |
| 7859 | } |
| 7860 | // Death to organisms that refuse to use promoters! |
| 7861 | else if (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 1) { |
nothing calls this directly
no test coverage detected