00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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