namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { /// /// The abstract class that all emulated models will inherit from /// * Memory * /// public abstract partial class CPCBase { #region Memory Fields & Properties /* ROM Banks */ /// /// Lower: OS ROM /// public byte[] ROMLower = new byte[0x4000]; /// /// Upper: POS 0 (usually BASIC) /// public byte[] ROM0 = new byte[0x4000]; /// /// Upper: POS 7 (usually AMSDOS) /// public byte[] ROM7 = new byte[0x4000]; /* RAM Banks - Lower 64K */ public byte[] RAM0 = new byte[0x4000]; public byte[] RAM1 = new byte[0x4000]; public byte[] RAM2 = new byte[0x4000]; public byte[] RAM3 = new byte[0x4000]; /* RAM Banks - Upper 64K */ public byte[] RAM4 = new byte[0x4000]; public byte[] RAM5 = new byte[0x4000]; public byte[] RAM6 = new byte[0x4000]; public byte[] RAM7 = new byte[0x4000]; /// /// Signs whether Upper ROM is paged in /// public bool UpperROMPaged; /// /// The position of the currently paged upper ROM /// public int UpperROMPosition; /// /// Signs whether Lower ROM is paged in /// public bool LowerROMPaged; /// /// The currently selected RAM config /// public int RAMConfig; /// /// Always 0 on a CPC6128 /// On a machine with more than 128K RAM (standard memory expansion) this selects each additional 64K above the first upper 64K /// public int RAM64KBank; #endregion #region Memory Related Methods /// /// Simulates reading from the bus /// Paging should be handled here /// public abstract byte ReadBus(ushort addr); /// /// Pushes a value onto the data bus that should be valid as long as the interrupt is true /// public virtual byte PushBus() { return 0xFF; } /// /// Simulates writing to the bus /// Paging should be handled here /// public abstract void WriteBus(ushort addr, byte value); /// /// Reads a byte of data from a specified memory address /// (with memory contention if appropriate) /// public abstract byte ReadMemory(ushort addr); /// /// Writes a byte of data to a specified memory address /// (with memory contention if appropriate) /// public abstract void WriteMemory(ushort addr, byte value); /// /// Sets up the ROM /// public abstract void InitROM(RomData[] romData); /// /// ULA reads the memory at the specified address /// (No memory contention) /// public virtual byte FetchScreenMemory(ushort addr) { int divisor = addr / 0x4000; byte result = 0xff; switch (divisor) { // 0x000 case 0: result = RAM0[addr % 0x4000]; break; // 0x4000 case 1: result = RAM1[addr % 0x4000]; break; // 0x8000 case 2: result = RAM2[addr % 0x4000]; break; // 0xc000 or UpperROM case 3: result = RAM3[addr % 0x4000]; break; default: break; } return result; } #endregion } }