To create a new CodeModule, there are only two things you (the developer) must do.

  1. In the CodeModules/ directory, create your cxx/hxx pair of files. For this example, I will assume you are writing a Code Module called "HexRotate". If your modules is named something else just do a find/replace for the appropriate name.
    touch CodeModule/HexRotate.cxx
    touch CodeModules/HexRotate.hxx
    
    At this point you will want to fill in their content, you can copy and paste the following as a template:
    HexRotate.hxx:
    
    ///////////////////////////////////////////////////////
    //                                                   //
    // Copyright (C) 2006 by Intel Corporation and CMU   //
    //                                                   //
    ///////////////////////////////////////////////////////
    
    #ifndef __HEXROTATE_H
    #define __HEXROTATE_H
    
    #include "CodeModule.hxx"
    #include "CatomWorld.hxx"
    
    CODE_MODULE_PROTOTYPE( HexRotate, HexRotate );
    using namespace std;
    
    extern CatomWorld *worldPtr;
    
    class HexRotate : public CodeModule {
    	int mode, old_mode;
    	int wait;
    public:
    	HexRotate(catomID _hostCatom) :
    		CodeModule(_hostCatom),mode(0)  {}
    	virtual void newTick();	
    	virtual void endTick();
            virtual void oracle();
    };
    
    #endif
    
    HexRotate.cxx:
    
    ///////////////////////////////////////////////////////
    //                                                   //
    // Copyright (C) 2006 by Intel Corporation and CMU   //
    //                                                   //
    ///////////////////////////////////////////////////////
    
    #include 
    #include 
    #include 
    
    #include "HexRotate.hxx"
    
    #include "CatomWorld.hxx"
    
    CODE_MODULE_DECLARATION( HexRotate, HexRotate );
    
    using namespace std;
    
    void HexRotate::newTick() {
      Catom *thisCatom = &(worldPtr->catomHash[hostCatom]->C);
      // CODE HERE
    }
    
    void HexRotate::endTick() {
      Catom *thisCatom = &(worldPtr->catomHash[hostCatom]->C);
      // CODE HERE
    }
    
    void HexRotate::oracle() {
      cout << "HexRotate Oracle: running concurrently with simulationStart\n";
      // CODE HERE
      oracleYield();
    
      cout << "HexRotate Oracle: running with other oracles only\n";
      // CODE HERE
      oracleYield();
    
      while (1) {
        cout << "HexRotate Oracle: running concurrently with newTick, endTick\n";
        // CODE HERE
        oracleYield();
    
        cout << "HexRotate Oracle: running with other oracles only\n";
        // CODE HERE
        oracleYield();
      }
    }
    
    The only non-obvious part of this should be the
    CODE_MODULE_PROTOTYPE( HexRotate, HexRotate );
    and
    CODE_MODULE_DECLARATION( HexRotate, HexRotate );
    
    parts. These are MACROs that add your Code as a runtime loadable module in the Simulator. In both cases the first argument is the class name you defined, and the second is the string you would like to be able to identify the module as in the Simulator. the presence of these lines allows you to trigger the loading of the module by name in the experiment file by writing MODULES=HexRotate. You can add more than one simultaneous module by making it a comma separated list, such as:
    MODULES=HexRotate,Flicker,Heirarchy
    
  2. Add this module to the source list in the CodeModules/Makefile:
    emacs CodeModules/Makefile
    [add HexRotate.cxx to the COMOSRCS= list]