Mano pdp8 RAM.cc

From Minor Miracle Software
Revision as of 17:12, 13 June 2016 by WikiSysop (talk | contribs) (Created page with " RAM.cc <PRE> // Mano Project // Main memory class #include "mano.h" #ifndef RAM_CC #define RAM_CC #ifndef AVL_TREE_CC #include "avl_tree.cc" #endif #ifndef INSTRUCTION...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

RAM.cc

// Mano Project
// Main memory class

#include "mano.h"

#ifndef RAM_CC
#define RAM_CC

#ifndef AVL_TREE_CC
  #include "avl_tree.cc"
#endif

#ifndef INSTRUCTIONWORD_CC
  #include "InstructionWord.cc"
#endif

class RAM {

// trees for main memory
  avl_tree<InstructionWord> avl0000_1023;
  avl_tree<InstructionWord> avl1024_2047;
  avl_tree<InstructionWord> avl2048_3071;
  avl_tree<InstructionWord> avl3072_4095;

  InstructionWord InstructionWord_mCurrent;

friend ostream& operator << (ostream& os, RAM& M )
{
if( DEBUG )
cout << "Main Memory: << 0" << endl;

     os << "      Address  Value" << endl;
     os << "   " << M.avl0000_1023;
if( DEBUG )
cout << "Main Memory: << 1" << endl;
     os << "   " << M.avl1024_2047;
if( DEBUG )
cout << "Main Memory: << 2" << endl;
     os << "   " << M.avl2048_3071;
if( DEBUG )
cout << "Main Memory: << 3" << endl;
     os << "   " << M.avl3072_4095;
if( DEBUG )
cout << "Main Memory: << 4" << endl;
     return os;
}

public:

RAM(){}

RAM(const RAM& M)
{
   avl0000_1023 = M.avl0000_1023;
   avl1024_2047 = M.avl1024_2047;
   avl2048_3071 = M.avl2048_3071;
   avl3072_4095 = M.avl3072_4095;
}


~RAM(){}


void erase()
{
if( DEBUG )
cout << "Main Memory: erase 0" << endl;

    avl0000_1023.erase();
    avl1024_2047.erase();
    avl2048_3071.erase();
    avl3072_4095.erase();
}


short LoadCell( InstructionWord mem_New )
{
if( DEBUG )
cout << "Main Memory: LoadCell 0" << endl;
cout << "Main Memory: LoadCell 1 mem_New is " << mem_New << endl;
cout << "Main Memory: LoadCell 0" << endl;
cout << "Main Memory: LoadCell 0" << endl;

    short S = mem_New.gettag();
    if (( S < 1024 ) && avl0000_1023.locate( mem_New))
    {
        InstructionWord *p_mem = avl0000_1023.returncurrent();
        mem_New.buildpoint( p_mem );
cout << "Main Memory: LoadCell 2.0 avl0000_1023 is " << avl0000_1023 << endl;
        return 1;
    }
    else
    {
       avl0000_1023 += mem_New;
cout << "Main Memory: LoadCell 2.1 avl0000_1023 is " << avl0000_1023 << endl;
       return 1;
     }

    if (( S < 2048 ) && avl1024_2047.locate( mem_New ))
    {
        InstructionWord *p_mem0 = avl1024_2047.returncurrent();
        mem_New.buildpoint( p_mem0 );
cout << "Main Memory: LoadCell 0" << endl;
        return 1;
    }
    else
       return avl1024_2047 += mem_New;
       
    if (( S < 3072 ) && avl2048_3071.locate (mem_New))
    {
        InstructionWord *p_mem1 = avl2048_3071.returncurrent();
        mem_New.buildpoint( p_mem1 );
cout << "Main Memory: LoadCell 0" << endl;
        return 1;
    }
    else
       return avl2048_3071 += mem_New;


    if ( avl3072_4095.locate(mem_New) )
    {
        InstructionWord *p_mem2 = avl3072_4095.returncurrent();
        mem_New.buildpoint( p_mem2 );
        return 1;
    }
    else
       return avl3072_4095 += mem_New;
       
    return 0;
}

short locate( InstructionWord& mem_Find )
{
if( DEBUG )
cout << "Main Memory: locate" << endl;

        short S = mem_Find.gettag();
        if( S < 1024 )
        {
           S = avl0000_1023.locate( mem_Find );
           avl0000_1023.returncurrent( InstructionWord_mCurrent ); 
           return S; 
        }
           
        if( S < 2048 )
        {
           S = avl1024_2047.locate( mem_Find );
           avl1024_2047.returncurrent( InstructionWord_mCurrent ); 
           return S; 
        }
           
        if ( S < 3072 )
        {
           S = avl2048_3071.locate( mem_Find );
           avl2048_3071.returncurrent( InstructionWord_mCurrent ); 
           return S; 
        }

        S = avl3072_4095.locate( mem_Find );
        avl3072_4095.returncurrent( InstructionWord_mCurrent ); 
        return S; 
}


InstructionWord returncell(InstructionWord InstructionWord_Temp )
{
if( DEBUG )
cout << "Main Memory: returncell 0" << endl;

     if( locate( InstructionWord_Temp ) )
         return InstructionWord_mCurrent;

     InstructionWord_mCurrent.clear();
     return InstructionWord_mCurrent;
}


InstructionWord returncurrent( )
{
if( DEBUG )
cout << "Main Memory: returncurrent 0" << endl;

     return InstructionWord_mCurrent;      
}

	unsigned long int census()
	{
		return avl0000_1023.census() +
		       avl1024_2047.census() +
		       avl2048_3071.census() +
		       avl3072_4095.census();
	} // census
};
#endif // MAIN_MEMORY_CC

Internal Links

Parent Article: Mano PDP-8 Simulation Project Source Code