using BizHawk.Emulation.Cores.Components.Z80A; using System.Collections.Generic; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { /// /// 16K is idential to 48K, just without the top 32KB of RAM /// public class ZX16 : ZX48 { #region Construction /// /// Main constructor /// public ZX16(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List files, List joysticks) : base(spectrum, cpu, borderType, files, joysticks) { } #endregion #region Memory /* 48K Spectrum has NO memory paging * * | Bank 0 | | | | | | screen | 0x4000 +--------+ | ROM 0 | | | | | | | 0x0000 +--------+ */ /// /// Simulates reading from the bus (no contention) /// Paging should be handled here /// public override byte ReadBus(ushort addr) { int divisor = addr / 0x4000; var index = addr % 0x4000; // paging logic goes here switch (divisor) { case 0: TestForTapeTraps(addr % 0x4000); return ROM0[index]; case 1: return RAM0[index]; default: // memory does not exist return 0xff; } } /// /// Simulates writing to the bus (no contention) /// Paging should be handled here /// public override void WriteBus(ushort addr, byte value) { int divisor = addr / 0x4000; var index = addr % 0x4000; // paging logic goes here switch (divisor) { case 0: // cannot write to ROM break; case 1: //ULADevice.RenderScreen((int)CurrentFrameCycle); RAM0[index] = value; break; } } /// /// Reads a byte of data from a specified memory address /// (with memory contention if appropriate) /// public override byte ReadMemory(ushort addr) { var data = ReadBus(addr); return data; } /// /// Returns the ROM/RAM enum that relates to this particular memory read operation /// public override ZXSpectrum.CDLResult ReadCDL(ushort addr) { var res = new ZXSpectrum.CDLResult(); int divisor = addr / 0x4000; res.Address = addr % 0x4000; // paging logic goes here switch (divisor) { case 0: res.Type = ZXSpectrum.CDLType.ROM0; break; case 1: res.Type = ZXSpectrum.CDLType.RAM0; break; } return res; } /// /// Writes a byte of data to a specified memory address /// (with memory contention if appropriate) /// public override void WriteMemory(ushort addr, byte value) { WriteBus(addr, value); } /// /// Sets up the ROM /// public override void InitROM(RomData romData) { RomData = romData; // for 16/48k machines only ROM0 is used (no paging) RomData.RomBytes?.CopyTo(ROM0, 0); } #endregion } }