[Avida-cvs] [Avida2-svn] r63 - trunk/source/cpu

ofria at myxo.css.msu.edu ofria at myxo.css.msu.edu
Mon Mar 21 03:34:24 PST 2005


Author: ofria
Date: 2005-03-21 06:34:23 -0500 (Mon, 21 Mar 2005)
New Revision: 63

Modified:
   trunk/source/cpu/hardware_cpu.cc
   trunk/source/cpu/hardware_cpu.hh
Log:
Added in the "sense" instruction.


Modified: trunk/source/cpu/hardware_cpu.cc
===================================================================
--- trunk/source/cpu/hardware_cpu.cc	2005-03-18 20:38:44 UTC (rev 62)
+++ trunk/source/cpu/hardware_cpu.cc	2005-03-21 11:34:23 UTC (rev 63)
@@ -233,6 +233,8 @@
 
     cInstEntryCPU("send",      &cHardwareCPU::Inst_Send),
     cInstEntryCPU("receive",   &cHardwareCPU::Inst_Receive),
+    cInstEntryCPU("sense",     &cHardwareCPU::Inst_Sense),
+
     cInstEntryCPU("donate-rnd",  &cHardwareCPU::Inst_DonateRandom),
     cInstEntryCPU("donate-kin",  &cHardwareCPU::Inst_DonateKin),
     cInstEntryCPU("donate-edt",  &cHardwareCPU::Inst_DonateEditDist),
@@ -2845,6 +2847,24 @@
   return true;
 }
 
+bool cHardwareCPU::Inst_Sense()
+{
+  const tArray<double> & res_count = organism->PopInterface().GetResources();
+  const int reg_used = FindModifiedRegister(REG_BX);
+
+  // If there are no resources to measure, this instruction fails.
+  if (res_count.GetSize() == 0) return false;
+
+  // Always get the first resource, and convert it to and int.
+  Register(reg_used) = (int) res_count[0];
+
+  // @CAO Since resources are sometimes less than one, perhaps we should
+  // multiply it by some constant?  Or perhaps taking the log would be more
+  // useful so they can easily scan across orders of magnitude?
+
+  return true;
+}
+
 void cHardwareCPU::DoDonate(cOrganism * to_org)
 {
   assert(to_org != NULL);

Modified: trunk/source/cpu/hardware_cpu.hh
===================================================================
--- trunk/source/cpu/hardware_cpu.hh	2005-03-18 20:38:44 UTC (rev 62)
+++ trunk/source/cpu/hardware_cpu.hh	2005-03-21 11:34:23 UTC (rev 63)
@@ -377,6 +377,7 @@
   bool Inst_TaskIO();
   bool Inst_Send();
   bool Inst_Receive();
+  bool Inst_Sense();
 
   void DoDonate(cOrganism * to_org);
   bool Inst_DonateRandom();




More information about the Avida-cvs mailing list