memman.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Fred Klaus                                      *
00003  *   frednet@web.de                                                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef MEMMAN_H
00021 #define MEMMAN_H
00022 
00023 #include "types.h"
00024 #include "gatearray.h"
00025 #include "z80.h"
00026 
00027 #include <string>
00028 
00029 using std::string;
00030 
00032 class MemMan
00033 {
00034 
00035 public:
00036         MemMan(Z80* z80=0, GateArray* gatearray=0, const string & cpcrom="", const string & amsdos="");
00037         ~MemMan() {}
00038 
00039         enum RamSize {ram64=64, ram128=128, ram256=256, ram512=512};
00040 
00041         enum Error {ErrRamSize=1, ErrMemory=2, ErrCpcRom=4, ErrAmsdos=8};
00042 
00043         int init(int ramsize=128, const string & cpcrom="", const string & amsdos="");
00044         int init(Z80* z80, GateArray* gatearray);
00045         
00046         inline void initBanking();
00047         void memoryManager();
00048 
00049         inline void toggleLowerRom();
00050         inline void toggleUpperRom();
00051 
00052         UBYTE* memBankConfig(UBYTE bank, UBYTE seg) {return mMemBankConfig[bank][seg];}
00053         UBYTE* rom(int bank) {return mRom[bank];}
00054 
00055         UBYTE* upperRom() {return mUpperRom;}
00056         UBYTE* lowerRom() {return mLowerRom;}
00057 
00058         UBYTE* base() {return mMemBankConfig[0][0];}
00059 
00060         bool openRom(int idx, const string & filename);
00061         bool openCpcRom(const string & filename);
00062 
00063 private:
00064         GateArray* mGateArray;
00065         Z80* mZ80;
00066 
00067         UBYTE* mRam;
00068         UBYTE* mRom[256];
00069         UBYTE  mCpcRom[2*16384];
00070         UBYTE* mMemBankConfig[8][4];
00071 
00072         UBYTE* mUpperRom;
00073         UBYTE* mLowerRom;
00074 
00075         int mRamSize;
00076 
00077 };
00078 
00079 inline void MemMan::toggleUpperRom()
00080 {
00081 
00082         if (!(mGateArray->romConfig() & 0x08))
00083         {
00084                 if ((mGateArray->upperRom() == 0) || (mRom[mGateArray->upperRom()] == 0))
00085                 {
00086                         mZ80->setMembank_read(3, mUpperRom);
00087                 }
00088                 else
00089                 {
00090                         mZ80->setMembank_read(3, mRom[mGateArray->upperRom()]);
00091                 }
00092         }
00093 }
00094 
00095 inline void MemMan::toggleLowerRom()
00096 {
00097         if (!(mGateArray->romConfig() & 0x04))
00098         {
00099                 mZ80->setMembank_read(0, mLowerRom);
00100         }
00101 }
00102 
00103 #endif

Generated on Fri Mar 16 21:30:28 2007 for roland.kdevelop by  doxygen 1.5.0