public void RegisterIndexIsSetProperty(int regIndex) { // --- Arrange var spectrum = new SpectrumSoundTestMachine(); var soundDev = new SoundDevice(); soundDev.OnAttachedToVm(spectrum); // --- Act soundDev.SetRegisterIndex((byte)regIndex); // --- Assert soundDev.LastRegisterIndex.ShouldBe((byte)regIndex); }
/// <summary> /// Sends a byte to the port with the specified address /// </summary> /// <param name="addr">Port address</param> /// <param name="data">Data to write to the port</param> /// <returns>Byte read from the memory</returns> public override void WritePort(ushort addr, byte data) { HandleSpectrum48PortWrites(addr, data); // --- Port 0x7FFD, bit 14 set, bit 15 and bit 1 reset if ((addr & 0xC002) == 0x4000) { // --- When paging is disabled, it will be enabled next time // --- only after reset if (PagingEnabled) { // --- Choose the RAM bank for Slot 3 (0xc000-0xffff) LastSlot3Index = data & 0x07; MemoryDevice.PageIn(3, LastSlot3Index); // --- Choose screen (Bank 5 or 7) MemoryDevice.UseShadowScreen = ((data >> 3) & 0x01) == 0x01; // --- Choose ROM bank for Slot 0 (0x0000-0x3fff) SelectRomLow = (byte)((data >> 4) & 0x01); // --- Enable/disable paging PagingEnabled = (data & 0x20) == 0x00; // --- Page the ROM according to current settings MemoryDevice.SelectRom(SelectRomHigh | SelectRomLow); } } // --- Port 0x1FFD, bit 12 set, bit 1, 13, 14 and 15 reset else if ((addr & 0xF002) == 0x1000) { PagingMode = (data & 0x01) != 0; SpecialConfig = (byte)((data >> 1) & 0x03); DiskMotorState = (data & 0x08) != 0; PrinterPortStrobe = (data & 0x10) != 0; SelectRomHigh = (byte)((data >> 1) & 0x02); // --- Page the ROM according to current settings if (PagingMode) { // --- Special paging mode switch (SpecialConfig) { case 0: MemoryDevice.PageIn(0, 0); MemoryDevice.PageIn(1, 1); MemoryDevice.PageIn(2, 2); MemoryDevice.PageIn(3, 3); break; case 1: MemoryDevice.PageIn(0, 4); MemoryDevice.PageIn(1, 5); MemoryDevice.PageIn(2, 6); MemoryDevice.PageIn(3, 7); break; case 2: MemoryDevice.PageIn(0, 4); MemoryDevice.PageIn(1, 5); MemoryDevice.PageIn(2, 6); MemoryDevice.PageIn(3, 3); break; case 3: MemoryDevice.PageIn(0, 4); MemoryDevice.PageIn(1, 7); MemoryDevice.PageIn(2, 6); MemoryDevice.PageIn(3, 3); break; } } else { // --- Normal mode MemoryDevice.PageIn(1, 5); MemoryDevice.PageIn(2, 2); MemoryDevice.PageIn(3, LastSlot3Index); MemoryDevice.SelectRom(SelectRomHigh | SelectRomLow); } } else if (addr == 0xFFFD) { SoundDevice.SetRegisterIndex(data); } else if (addr == 0xBFFD || addr == 0xBEFD) { SoundDevice.SetRegisterValue(data); } }