示例#1
0
        public static void CheckTapeRecorderPlayback()
        {
            TapeRecorder tapeRecorder = new _TapeRecorder();

            Tape testTape = new Tape("TestTape",
                                     new TapeSection("section 1",
                                                     new ToneSequence("tone", 4, 5),                                 // 20 TStates
                                                     new PulsesSequence("pulses", new ushort[] { 1, 2, 3, 4 }),      // 10 TStates
                                                     new DataSequence("data", new byte[] { 15, 175 }, 1, 2, 4)),     // 36 TStates
                                     new TapeSection("section 2",
                                                     new PauseSequence("pause", 1)),                                 // 3500 TStates
                                     new TapeSection("section 3",
                                                     new SamplesSequence("samples", new byte[] { 15, 175 }, 2, 7))); // 30 TStates

            tapeRecorder.InsertTape(testTape);

            StringBuilder sbResult = new StringBuilder();

            tapeRecorder.Start();
            sbResult.AppendLine(tapeRecorder.PlayingTime + "," + tapeRecorder.SoundSignal.Level + "," + tapeRecorder.GetPosition());

            for (int i = 1; i < 70; i++)
            {
                tapeRecorder.Tick();
                sbResult.AppendLine(tapeRecorder.PlayingTime + "," + tapeRecorder.SoundSignal.Level + "," + tapeRecorder.GetPosition());
            }

            for (int i = 1; i <= 3492; i++)
            {
                tapeRecorder.Tick();
            }

            for (int i = 1; i <= 35; i++)
            {
                tapeRecorder.Tick();
                sbResult.AppendLine(tapeRecorder.PlayingTime + "," + tapeRecorder.SoundSignal.Level + "," + tapeRecorder.GetPosition());
            }

            string testResult = sbResult.ToString();

            string expectedResult = null;

            using (StreamReader reader = new StreamReader(PlatformSpecific.GetStreamForProjectFile("TapeFiles/Logs/CheckTapeRecorderPlayback.csv")))
            {
                expectedResult = reader.ReadToEnd();
            }

            if (testResult != expectedResult)
            {
                throw new Exception("TapeRecorder playback test failed");
            }
        }
        public static void CheckTapeRecorderPlayback()
        {
            TapeRecorder tapeRecorder = new _TapeRecorder();

            Tape testTape = new Tape("TestTape",
                new TapeSection("section 1",
                    new ToneSequence("tone", 4, 5),                                 // 20 TStates
                    new PulsesSequence("pulses", new ushort[] {1,2,3,4}),           // 10 TStates
                    new DataSequence("data", new byte[] {15,175}, 1, 2, 4)),        // 36 TStates
                new TapeSection("section 2",
                    new PauseSequence("pause", 1)),                                 // 3500 TStates
                new TapeSection("section 3",
                    new SamplesSequence("samples", new byte[] { 15, 175 }, 2, 7))); // 30 TStates

            tapeRecorder.InsertTape(testTape);

            StringBuilder sbResult = new StringBuilder();

            tapeRecorder.Start();
            sbResult.AppendLine(tapeRecorder.PlayingTime + "," + tapeRecorder.SoundSignal.Level + "," + tapeRecorder.GetPosition());

            for (int i = 1; i < 70; i++)
            {
                tapeRecorder.Tick();
                sbResult.AppendLine(tapeRecorder.PlayingTime + "," + tapeRecorder.SoundSignal.Level + "," + tapeRecorder.GetPosition());
            }

            for (int i = 1; i <= 3492; i++)
            {
                tapeRecorder.Tick();
            }

            for (int i = 1; i <= 35; i++)
            {
                tapeRecorder.Tick();
                sbResult.AppendLine(tapeRecorder.PlayingTime + "," + tapeRecorder.SoundSignal.Level + "," + tapeRecorder.GetPosition());
            }

            string testResult = sbResult.ToString();

            string expectedResult = null;
            using (StreamReader reader = new StreamReader(PlatformSpecific.GetStreamForProjectFile("TapeFiles/Logs/CheckTapeRecorderPlayback.csv")))
            {
                expectedResult = reader.ReadToEnd();
            }

            if (testResult != expectedResult)
            {
                throw new Exception("TapeRecorder playback test failed");
            }
        }
示例#3
0
        public static void CheckTapeRecorderStates()
        {
            StringBuilder testStates = new StringBuilder();

            TapeRecorder tapeRecorder = new _TapeRecorder();

            testStates.AppendLine(tapeRecorder.ToString());

            // From initial state
            tapeRecorder.Eject();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.RewindOrForward(10);
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.RewindToStart();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i < 5000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Stop();
            testStates.AppendLine(tapeRecorder.ToString());

            // Tape inserted
            string fileName = "BuggyBoy.tzx";

            using (Stream stream = PlatformSpecific.GetStreamForProjectFile("TapeFiles/SampleTzxFiles/" + fileName))
            {
                tapeRecorder.InsertTape(stream, fileName);
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Stop();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.RewindToStart();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 3000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Stop();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 2000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 2000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 17500000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.RewindToStart();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 4000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.RewindOrForward(5);
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 3000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Stop();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 3000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Eject();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 5000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());

            string testResult = testStates.ToString();

            string expectedResult = null;

            using (StreamReader reader = new StreamReader(PlatformSpecific.GetStreamForProjectFile("TapeFiles/Logs/CheckTapeRecorderStates.txt")))
            {
                expectedResult = reader.ReadToEnd();
            }

            if (testResult != expectedResult)
            {
                throw new Exception("TapeRecorder states test failed");
            }
        }
        public ZXSpectrumComputer()
        {
            // -- Initialize components --

            // System clock
            Clock = new _Clock(Clock.FREQ_3_5MHZ);
            // Init CPU
            CPU = new _Z80CPU();
            // Reset button
            ResetButton = new Button(SignalState.HIGH);

            // ZX Spectrum memory map
            /// NB : in the real machine, there is also a multiplexed address bus for each device :
            /// select row (7 bits) then select colum (7bits).
            /// Row and column address strobe - RAS/CAS - signals must therefore be generated.
            /// We do not simulate theses details here, as they are complex to understand
            /// and can be ignored without losing any fildelity to the behavior of the machine.

            // 16K ROM
            // 0 - 16383 : ROM Program
            ROM = new _ROM();
            // 16K RAM
            // 16384 - 23295 : Video display memory (6910 bytes)
            // 23296 -  : System variables
            // User programs
            RAM16K = new _DualAccessMemoryMappedChip(Memory.BYTES_16K, 0x4000);
            // 32K RAM (only in 48K models)
            RAM32K = new _MemoryMappedChip(Memory.BYTES_32K, 0x8000);

            // Initialize ULA :
            //   Video generator
            //   CPU clock generator
            //   Memory access governor
            //   Keyboard controller
            //   Tape I/O controller
            //   Speaker controller
            ULA = new _ULA();

            // Initialize peripherals
            Keyboard     = new _Keyboard();
            Screen       = new _Screen();
            Speaker      = new _Speaker();
            TapeRecorder = new _TapeRecorder();

            // Initialize Sinclair joysticks
            Joystick1 = new Joystick(true, Keyboard);
            Joystick2 = new Joystick(false, Keyboard);

            // -- Initialize and connect system buses --

            // CPU buses
            AddressBus = new Bus <ushort>();
            DataBus    = new Bus <byte>();
            CPU.Address.ConnectTo(AddressBus);
            CPU.Data.ConnectTo(DataBus);
            ROM.Address.ConnectTo(AddressBus);
            ROM.Data.ConnectTo(DataBus);
            RAM16K.AddressInput1.ConnectTo(AddressBus);
            RAM16K.DataInput1.ConnectTo(DataBus);
            RAM32K.Address.ConnectTo(AddressBus);
            RAM32K.Data.ConnectTo(DataBus);
            ULA.Address.ConnectTo(AddressBus);
            ULA.Data.ConnectTo(DataBus);

            // Dedicated video buses : firect Video Memory Access for the ULA
            VideoAddressBus = new Bus <ushort>();
            VideoDataBus    = new Bus <byte>();
            ULA.VideoAddress.ConnectTo(VideoAddressBus);
            ULA.VideoData.ConnectTo(VideoDataBus);
            RAM16K.AddressInput2.ConnectTo(VideoAddressBus);
            RAM16K.DataInput2.ConnectTo(VideoDataBus);

            // Connect Keyboard to the ULA
            KeyboardDataBus = new Bus <byte>();
            ULA.KeyboardData.ConnectTo(KeyboardDataBus);
            Keyboard.Address.ConnectTo(AddressBus);
            Keyboard.Data.ConnectTo(KeyboardDataBus);

            // Connect ULA analog video signal to screen
            ULA.ColorSignal.ConnectTo(Screen.ColorSignal);

            // Connect tape recorder sound output to ULA
            TapeRecorder.SoundSignal.ConnectTo(ULA.TapeInputSignal);

            // Connect ULA sound output to the speaker
            ULA.SpeakerSoundSignal.ConnectTo(Speaker.SoundSignal);

            // -- Connect individual PINs --

            ((_Clock)Clock).ConnectTo(ULA, Screen, TapeRecorder);
            ((_Z80CPU)CPU).ConnectTo(ResetButton, ULA, ROM, RAM16K, RAM32K);
            ((_ROM)ROM).ConnectTo(CPU);
            ((_DualAccessMemoryMappedChip)RAM16K).ConnectTo(CPU, ULA);
            ((_MemoryMappedChip)RAM32K).ConnectTo(CPU);
            ((_ULA)ULA).ConnectTo(Clock, CPU, RAM16K, Keyboard, Screen, Speaker);
            ((_Keyboard)Keyboard).ConnectTo(ULA);
            ((_Screen)Screen).ConnectTo(ULA);
            ((_Speaker)Speaker).ConnectTo(ULA);
            ((_TapeRecorder)TapeRecorder).ConnectTo(Clock);
        }
        public static void CheckTapeRecorderStates()
        {
            StringBuilder testStates = new StringBuilder();

            TapeRecorder tapeRecorder = new _TapeRecorder();
            testStates.AppendLine(tapeRecorder.ToString());

            // From initial state
            tapeRecorder.Eject();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.RewindOrForward(10);
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.RewindToStart();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i < 5000; i++ )
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Stop();
            testStates.AppendLine(tapeRecorder.ToString());

            // Tape inserted
            string fileName = "BuggyBoy.tzx";
            using (Stream stream = PlatformSpecific.GetStreamForProjectFile("TapeFiles/SampleTzxFiles/" + fileName))
            {
                tapeRecorder.InsertTape(stream, fileName);
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Stop();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.RewindToStart();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 3000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Stop();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 2000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 2000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 17500000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.RewindToStart();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 4000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.RewindOrForward(5);
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 3000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Stop();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 3000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Eject();
            testStates.AppendLine(tapeRecorder.ToString());
            tapeRecorder.Start();
            testStates.AppendLine(tapeRecorder.ToString());
            for (int i = 1; i <= 5000; i++)
            {
                tapeRecorder.Tick();
            }
            testStates.AppendLine(tapeRecorder.ToString());

            string testResult = testStates.ToString();

            string expectedResult = null;
            using (StreamReader reader = new StreamReader(PlatformSpecific.GetStreamForProjectFile("TapeFiles/Logs/CheckTapeRecorderStates.txt")))
            {
                expectedResult = reader.ReadToEnd();
            }

            if (testResult != expectedResult)
            {
                throw new Exception("TapeRecorder states test failed");
            }
        }
        public ZXSpectrumComputer()
        {
            // -- Initialize components --

            // System clock
            Clock = new _Clock(Clock.FREQ_3_5MHZ);
            // Init CPU
            CPU = new _Z80CPU();
            // Reset button
            ResetButton = new Button(SignalState.HIGH);

            // ZX Spectrum memory map
            /// NB : in the real machine, there is also a multiplexed address bus for each device :
            /// select row (7 bits) then select colum (7bits).
            /// Row and column address strobe - RAS/CAS - signals must therefore be generated.
            /// We do not simulate theses details here, as they are complex to understand
            /// and can be ignored without losing any fildelity to the behavior of the machine.

            // 16K ROM
            // 0 - 16383 : ROM Program
            ROM = new _ROM();
            // 16K RAM
            // 16384 - 23295 : Video display memory (6910 bytes)
            // 23296 -  : System variables
            // User programs
            RAM16K = new _DualAccessMemoryMappedChip(Memory.BYTES_16K, 0x4000);
            // 32K RAM (only in 48K models)
            RAM32K = new _MemoryMappedChip(Memory.BYTES_32K, 0x8000);

            // Initialize ULA :
            //   Video generator
            //   CPU clock generator
            //   Memory access governor
            //   Keyboard controller
            //   Tape I/O controller
            //   Speaker controller
            ULA = new _ULA();

            // Initialize peripherals
            Keyboard = new _Keyboard();
            Screen = new _Screen();
            Speaker = new _Speaker();
            TapeRecorder = new _TapeRecorder();

            // Initialize Sinclair joysticks
            Joystick1 = new Joystick(true, Keyboard);
            Joystick2 = new Joystick(false, Keyboard);

            // -- Initialize and connect system buses --

            // CPU buses
            AddressBus = new Bus<ushort>();
            DataBus = new Bus<byte>();
            CPU.Address.ConnectTo(AddressBus);
            CPU.Data.ConnectTo(DataBus);
            ROM.Address.ConnectTo(AddressBus);
            ROM.Data.ConnectTo(DataBus);
            RAM16K.AddressInput1.ConnectTo(AddressBus);
            RAM16K.DataInput1.ConnectTo(DataBus);
            RAM32K.Address.ConnectTo(AddressBus);
            RAM32K.Data.ConnectTo(DataBus);
            ULA.Address.ConnectTo(AddressBus);
            ULA.Data.ConnectTo(DataBus);

            // Dedicated video buses : firect Video Memory Access for the ULA
            VideoAddressBus = new Bus<ushort>();
            VideoDataBus = new Bus<byte>();
            ULA.VideoAddress.ConnectTo(VideoAddressBus);
            ULA.VideoData.ConnectTo(VideoDataBus);
            RAM16K.AddressInput2.ConnectTo(VideoAddressBus);
            RAM16K.DataInput2.ConnectTo(VideoDataBus);

            // Connect Keyboard to the ULA
            KeyboardDataBus = new Bus<byte>();
            ULA.KeyboardData.ConnectTo(KeyboardDataBus);
            Keyboard.Address.ConnectTo(AddressBus);
            Keyboard.Data.ConnectTo(KeyboardDataBus);

             // Connect ULA analog video signal to screen
            ULA.ColorSignal.ConnectTo(Screen.ColorSignal);

            // Connect tape recorder sound output to ULA
            TapeRecorder.SoundSignal.ConnectTo(ULA.TapeInputSignal);

            // Connect ULA sound output to the speaker
            ULA.SpeakerSoundSignal.ConnectTo(Speaker.SoundSignal);

            // -- Connect individual PINs --

            ((_Clock)Clock).ConnectTo(ULA, Screen, TapeRecorder);
            ((_Z80CPU)CPU).ConnectTo(ResetButton, ULA, ROM, RAM16K, RAM32K);
            ((_ROM)ROM).ConnectTo(CPU);
            ((_DualAccessMemoryMappedChip)RAM16K).ConnectTo(CPU, ULA);
            ((_MemoryMappedChip)RAM32K).ConnectTo(CPU);
            ((_ULA)ULA).ConnectTo(Clock, CPU, RAM16K, Keyboard, Screen, Speaker);
            ((_Keyboard)Keyboard).ConnectTo(ULA);
            ((_Screen)Screen).ConnectTo(ULA);
            ((_Speaker)Speaker).ConnectTo(ULA);
            ((_TapeRecorder)TapeRecorder).ConnectTo(Clock);
        }