using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { /// /// The abstract class that all emulated models will inherit from /// * Memory * /// public abstract partial class SpectrumBase { /// /// ROM Banks /// public byte[] ROM0 = new byte[0x4000]; public byte[] ROM1 = new byte[0x4000]; public byte[] ROM2 = new byte[0x4000]; public byte[] ROM3 = new byte[0x4000]; /// /// RAM Banks /// public byte[] RAM0 = new byte[0x4000]; // Bank 0 public byte[] RAM1 = new byte[0x4000]; // Bank 1 public byte[] RAM2 = new byte[0x4000]; // Bank 2 public byte[] RAM3 = new byte[0x4000]; // Bank 3 public byte[] RAM4 = new byte[0x4000]; // Bank 4 public byte[] RAM5 = new byte[0x4000]; // Bank 5 public byte[] RAM6 = new byte[0x4000]; // Bank 6 public byte[] RAM7 = new byte[0x4000]; // Bank 7 /// /// Represents the addressable memory space of the spectrum /// All banks for the emulated system should be added during initialisation /// public Dictionary Memory = new Dictionary(); /// /// 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 virtual void WriteBus(ushort addr, byte value) { throw new NotImplementedException("Must be overriden"); } /// /// 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) { var value = ReadBus((ushort)((addr & 0x3FFF) + 0x4000)); return value; } /// /// Helper function to refresh memory array (probably not the best way to do things) /// public abstract void ReInitMemory(); /// /// Returns the memory contention value for the specified T-State (cycle) /// The ZX Spectrum memory access is contended when the ULA is accessing the lower 16k of RAM /// /// /// public virtual byte GetContentionValue(int cycle) { var val = _renderingCycleTable[cycle % UlaFrameCycleCount].ContentionDelay; return val; } } }