Ejemplo n.º 1
0
        public void CreateTapeFileIsInvokedWhenEnteringSaveMode()
        {
            // --- Arrange
            var vm           = new SpectrumTapeDeviceTestMachine();
            var saveProvider = new FakeSaveToTapeProvider();
            var td           = new TapeDevice(null, saveProvider);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = vm.RomInfo.SaveBytesRoutineAddress;

            // --- Act
            td.SetTapeMode();

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            saveProvider.CreateTapeFileInvoked.ShouldBeTrue();
        }
Ejemplo n.º 2
0
        public void GetEarBitsReturnTrueInLoadModeWithNoPlayer()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = vm.RomInfo.LoadBytesRoutineAddress;
            td.SetTapeMode();

            // --- Act
            var bit = td.GetEarBit(0);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Load);
            bit.ShouldBeTrue();
        }
Ejemplo n.º 3
0
        public void ProcessMicBitWorksInSaveModeWithBitChange()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = vm.RomInfo.SaveBytesRoutineAddress;
            td.SetTapeMode();

            // --- Act
            td.ProcessMicBit(false);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.None);
        }
Ejemplo n.º 4
0
        public void ProcessMicBitAbortsInPassiveMode()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = 0x0038;
            td.SetTapeMode();

            // --- Act
            td.ProcessMicBit(true);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Passive);
            td.SavePhase.ShouldBe(SavePhase.None);
        }
Ejemplo n.º 5
0
        public void GetEarBitsReturnTrueInPassiveMode()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = 0x0038;
            td.SetTapeMode();

            // --- Act
            var bit = td.GetEarBit(0);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Passive);
            bit.ShouldBeTrue();
        }
Ejemplo n.º 6
0
        public void SetTapeModeLeavesLoadModeWhenEof()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(new EmptyTapeContentProvider());

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = td.LoadBytesRoutineAddress;
            td.SetTapeMode();
            var before = td.CurrentMode;

            // --- Act
            td.SetTapeMode();

            // --- Assert
            before.ShouldBe(TapeOperationMode.Load);
            td.CurrentMode.ShouldBe(TapeOperationMode.Passive);
        }
Ejemplo n.º 7
0
        public void SetTapeModeInvokesEnteredLoadModeEvent()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = td.LoadBytesRoutineAddress;
            var invoked = false;

            td.EnteredLoadMode += (sender, args) => { invoked = true; };

            // --- Act
            td.SetTapeMode();

            // --- Assert
            invoked.ShouldBeTrue();
        }
Ejemplo n.º 8
0
        public void ProcessMicBitFailsWithLongBit1Pulse()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            (var debugCpu, var tacts, var pulse) = EmitHeaderWithSync(vm, td);

            // --- Act
            tacts += TapeDataBlockPlayer.BIT_1_PL + TapeDevice.SAVE_PULSE_TOLERANCE + 1;
            debugCpu.SetTacts(tacts);
            td.ProcessMicBit(pulse);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.Error);
        }
Ejemplo n.º 9
0
        public void SaveTzxBlockIsCalledWhenCompletingDataBlock()
        {
            // --- Arrange
            var vm       = new SpectrumTapeDeviceTestMachine();
            var provider = new FakeTapeProvider();
            var td       = new TapeDevice(provider, provider);

            td.OnAttachedToVm(vm);
            var testData = new byte[] { 0x90, 0x02, 0x05, 0xAA, 0xFF, 0x63 };

            // --- Act
            EmitFullDataBlock(vm, td, testData);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.None);
            provider.SaveTzxBlockInvoked.ShouldBeTrue();
        }
Ejemplo n.º 10
0
        public void SetTapeModeLeavesSaveModeWhenError()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = td.SaveBytesRoutineAddress;
            td.SetTapeMode();
            var before = td.CurrentMode;

            // --- Act
            vm.Cpu.Registers.PC = TapeDevice.ERROR_ROM_ADDRESS;
            td.SetTapeMode();

            // --- Assert
            before.ShouldBe(TapeOperationMode.Save);
            td.CurrentMode.ShouldBe(TapeOperationMode.Passive);
        }
Ejemplo n.º 11
0
        public void ProcessMicBitFailsWithLongPilotPulse()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = td.SaveBytesRoutineAddress;
            td.SetTapeMode();
            var debugCpu = vm.Cpu as IZ80CpuTestSupport;

            // --- Act
            debugCpu.SetTacts(TapeDataBlockPlayer.PILOT_PL + TapeDevice.SAVE_PULSE_TOLERANCE + 1);
            td.ProcessMicBit(false);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.Error);
        }
Ejemplo n.º 12
0
        public void ProcessMicBitFailsWithShortTermSyncPulse()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            var testData = new byte[] { 0x90, 0x02, 0x05, 0xAA, 0xFF, 0x63 };

            (var debugCpu, var tacts, var pulse) = EmitHeaderAndData(vm, td, testData);

            // --- Act
            tacts += TapeDataBlockPlayer.TERM_SYNC - TapeDevice.SAVE_PULSE_TOLERANCE - 1;
            debugCpu.SetTacts(tacts);
            td.ProcessMicBit(pulse);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.Error);
        }
Ejemplo n.º 13
0
        public void ProcessMicBitCatchesFirstPilotPulse()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = td.SaveBytesRoutineAddress;
            td.SetTapeMode();
            var debugCpu = vm.Cpu as IZ80CpuTestSupport;

            // --- Act
            debugCpu.SetTacts(TapeDataBlockPlayer.PILOT_PL);
            td.ProcessMicBit(false);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.Pilot);
            td.PilotPulseCount.ShouldBe(1);
        }
Ejemplo n.º 14
0
        public void SetTapeModeInvokesLeftSaveModeWhenError()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = td.SaveBytesRoutineAddress;
            td.SetTapeMode();
            var invoked = false;

            td.LeftSaveMode += (sender, args) => { invoked = true; };

            // --- Act
            vm.Cpu.Registers.PC = TapeDevice.ERROR_ROM_ADDRESS;
            td.SetTapeMode();

            // --- Assert
            invoked.ShouldBeTrue();
        }
Ejemplo n.º 15
0
        public void ProcessMicBitWorksWithDataBytes()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            var testData = new byte[] { 0x90, 0x02, 0x05, 0xAA, 0xFF, 0x63 };

            // --- Act
            EmitHeaderAndData(vm, td, testData);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.Data);
            td.DataLength.ShouldBe(testData.Length);
            for (var i = 0; i < testData.Length; i++)
            {
                td.DataBuffer[i].ShouldBe(testData[i]);
            }
        }
Ejemplo n.º 16
0
        public void ProcessMicBitWorksWithBit1Pulse()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            (var debugCpu, var tacts, var pulse) = EmitHeaderWithSync(vm, td);

            // --- Act
            tacts += TapeDataBlockPlayer.BIT_1_PL;
            debugCpu.SetTacts(tacts);
            td.ProcessMicBit(pulse);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.Data);
            td.BitOffset.ShouldBe(0);
            td.DataByte.ShouldBe((byte)0);
            td.PrevDataPulse.ShouldBe(MicPulseType.Bit1);
        }
Ejemplo n.º 17
0
        public void SetTapeModeLeavesSaveModeAfterSilence()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = td.SaveBytesRoutineAddress;
            td.SetTapeMode();
            var before = td.CurrentMode;

            // --- Act
            var debugCpu = vm.Cpu as IZ80CpuTestSupport;

            debugCpu.SetTacts(2 * TapeDevice.SAVE_STOP_SILENCE);
            td.SetTapeMode();

            // --- Assert
            before.ShouldBe(TapeOperationMode.Save);
            td.CurrentMode.ShouldBe(TapeOperationMode.Passive);
        }
Ejemplo n.º 18
0
        public void SetNameIsNotCalledWithInvalidHeader()
        {
            // --- Arrange
            var vm       = new SpectrumTapeDeviceTestMachine();
            var provider = new FakeTapeProvider();
            var td       = new TapeDevice(provider, provider);

            td.OnAttachedToVm(vm);
            var testData = new byte[]
            {
                0x42, 0x6F, 0x72, 0x64, 0x65, 0x72, 0x20, 0x20, 0x20, 0x20
            };

            // --- Act
            EmitFullDataBlock(vm, td, testData);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.None);
            provider.SuggestedName.ShouldBeNull();
        }
Ejemplo n.º 19
0
        public void SetTapeModeInvokesLedtSaveModeEventAfterSilence()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = td.SaveBytesRoutineAddress;
            td.SetTapeMode();
            var invoked = false;

            td.LeftSaveMode += (sender, args) => { invoked = true; };

            // --- Act
            var debugCpu = vm.Cpu as IZ80CpuTestSupport;

            debugCpu.SetTacts(2 * TapeDevice.SAVE_STOP_SILENCE);
            td.SetTapeMode();

            // --- Assert
            invoked.ShouldBeTrue();
        }
Ejemplo n.º 20
0
        public void FinalizeTapeFileIsInvokedWhenLeavingSaveMode()
        {
            // --- Arrange
            var vm           = new SpectrumTapeDeviceTestMachine();
            var saveProvider = new FakeSaveToTapeProvider();
            var td           = new TapeDevice(saveProvider);

            td.OnAttachedToVm(vm);
            vm.Cpu.Registers.PC = td.SaveBytesRoutineAddress;
            td.SetTapeMode();
            var before = td.CurrentMode;

            // --- Act
            var debugCpu = vm.Cpu as IZ80CpuTestSupport;

            debugCpu.SetTacts(2 * TapeDevice.SAVE_STOP_SILENCE);
            td.SetTapeMode();

            // --- Assert
            before.ShouldBe(TapeOperationMode.Save);
            td.CurrentMode.ShouldBe(TapeOperationMode.Passive);
            saveProvider.FinalizeTapeFileInvoked.ShouldBeTrue();
        }
Ejemplo n.º 21
0
        public void SetNameIsCalledAtFirstDataBlock()
        {
            // --- Arrange
            var vm           = new SpectrumTapeDeviceTestMachine();
            var saveProvider = new FakeSaveToTapeProvider();
            var td           = new TapeDevice(saveProvider);

            td.OnAttachedToVm(vm);
            var testData = new byte[]
            {
                0x00, 0x00,
                0x42, 0x6F, 0x72, 0x64, 0x65, 0x72, 0x20, 0x20, 0x20, 0x20,
                0x4F, 0x00, 0x6F, 0x80, 0x4F, 0x00, 0xC3
            };

            // --- Act
            EmitFullDataBlock(vm, td, testData);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.None);
            saveProvider.SuggestedName.ShouldBe("Border");
        }
Ejemplo n.º 22
0
        public void ProcessMicBitWorksWithTermSyncPulse()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            var testData = new byte[] { 0x90, 0x02, 0x05, 0xAA, 0xFF, 0x63 };

            (var debugCpu, var tacts, var pulse) = EmitHeaderAndData(vm, td, testData);

            // --- Act
            tacts += TapeDataBlockPlayer.TERM_SYNC;
            debugCpu.SetTacts(tacts);
            td.ProcessMicBit(pulse);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.None);
            for (var i = 0; i < testData.Length; i++)
            {
                td.DataBuffer[i].ShouldBe(testData[i]);
            }
        }
Ejemplo n.º 23
0
        public void ProcessMicBitWorksWithMultipleDataBlock()
        {
            // --- Arrange
            var vm = new SpectrumTapeDeviceTestMachine();
            var td = new TapeDevice(null, null);

            td.OnAttachedToVm(vm);
            var testData = new byte[] { 0x90, 0x02, 0x05, 0xAA, 0xFF, 0x63 };

            // --- Act
            (var debugCpu, var tacts, var pulse) = EmitFullDataBlock(vm, td, testData);
            tacts += TapeDataBlockPlayer.PILOT_PL * 5;
            debugCpu.SetTacts(tacts);
            td.ProcessMicBit(pulse);
            (debugCpu, tacts, pulse) = EmitFullDataBlock(vm, td, testData);
            tacts += TapeDataBlockPlayer.PILOT_PL * 5;
            debugCpu.SetTacts(tacts);
            td.ProcessMicBit(pulse);

            // --- Assert
            td.CurrentMode.ShouldBe(TapeOperationMode.Save);
            td.SavePhase.ShouldBe(SavePhase.None);
            td.DataBlockCount.ShouldBe(2);
        }