Mano pdp8 mainmem.cc
mainmem.cc
// Mano Project // Main memory class #ifndef MAIN_MEMORY_CC #define MAIN_MEMORY_CC #ifndef AVL_TREE_CC #include "avl_tree.cc" #endif #ifndef MEMORYCELL_CC #include "memorycell.cc" #endif class Main_Memory { // trees for main memory avl_tree<memorycell> avl0000_1023; avl_tree<memorycell> avl1024_2047; avl_tree<memorycell> avl2048_3071; avl_tree<memorycell> avl3072_4095; memorycell memorycell_mCurrent; friend ostream& operator << (ostream& os, Main_Memory& 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: Main_Memory(){} Main_Memory(const Main_Memory& M) { avl0000_1023 = M.avl0000_1023; avl1024_2047 = M.avl1024_2047; avl2048_3071 = M.avl2048_3071; avl3072_4095 = M.avl3072_4095; } ~Main_Memory(){} void erase() { if( DEBUG ) cout << "Main Memory: erase 0" << endl; avl0000_1023.erase(); avl1024_2047.erase(); avl2048_3071.erase(); avl3072_4095.erase(); } short LoadCell( memorycell 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)) { memorycell *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 )) { memorycell *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)) { memorycell *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) ) { memorycell *p_mem2 = avl3072_4095.returncurrent(); mem_New.buildpoint( p_mem2 ); return 1; } else return avl3072_4095 += mem_New; return 0; } short locate( memorycell& 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( memorycell_mCurrent ); return S; } if( S < 2048 ) { S = avl1024_2047.locate( mem_Find ); avl1024_2047.returncurrent( memorycell_mCurrent ); return S; } if ( S < 3072 ) { S = avl2048_3071.locate( mem_Find ); avl2048_3071.returncurrent( memorycell_mCurrent ); return S; } S = avl3072_4095.locate( mem_Find ); avl3072_4095.returncurrent( memorycell_mCurrent ); return S; } memorycell returncell(memorycell memorycell_Temp ) { if( DEBUG ) cout << "Main Memory: returncell 0" << endl; if( locate( memorycell_Temp ) ) return memorycell_mCurrent; memorycell_mCurrent.clear(); return memorycell_mCurrent; } memorycell returncurrent( ) { if( DEBUG ) cout << "Main Memory: returncurrent 0" << endl; return memorycell_mCurrent; } }; #endif // MAIN_MEMORY_CC
Internal Links
Parent Article: Mano PDP-8 Simulation Project Source Code