예제 #1
0
        /// <summary>
        /// Playes back a standard speed data block entirely
        /// </summary>
        /// <param name="block">Data block to play back</param>
        public static void CompleteBlock(this TzxStandardSpeedDataBlock block)
        {
            const int  PILOT_PL           = TapeDataBlockPlayer.PILOT_PL;
            const int  HEADER_PILOT_COUNT = TapeDataBlockPlayer.HEADER_PILOT_COUNT;
            const int  SYNC_1_PL          = TapeDataBlockPlayer.SYNC_1_PL;
            const int  SYNC_2_PL          = TapeDataBlockPlayer.SYNC_2_PL;
            const long PILOT_END          = PILOT_PL * HEADER_PILOT_COUNT;
            const int  TERM_SYNC          = TapeDataBlockPlayer.TERM_SYNC;
            const int  PAUSE_MS           = TapeDataBlockPlayer.PAUSE_MS;

            var start = block.StartTact;

            // --- Skip all pilot pulses + the first sync pulse
            for (long pos = 0; pos < PILOT_END + SYNC_1_PL; pos += 50)
            {
                block.GetEarBit(start + pos);
            }

            // --- Skip the second sync pulse
            for (var pos = PILOT_END + SYNC_1_PL + 50; pos < PILOT_END + SYNC_1_PL + SYNC_2_PL; pos += 50)
            {
                block.GetEarBit(start + pos);
            }

            // --- Play back the data
            for (var i = 0; i < block.DataLength; i++)
            {
                block.ReadNextByte();
            }

            // --- Play back the terminating sync
            var nextTact = block.LastTact;

            for (var pos = nextTact; pos < nextTact + TERM_SYNC + 50; pos += 50)
            {
                block.GetEarBit(pos);
            }

            // --- Play back the pause
            nextTact = block.LastTact;
            for (var pos = nextTact; pos < nextTact + PAUSE_MS * block.PauseAfter + 100; pos += 50)
            {
                block.GetEarBit(pos);
            }
        }
예제 #2
0
        /// <summary>
        /// Reads the data byte from the current playback position
        /// </summary>
        /// <param name="block">Block to play back</param>
        /// <returns>Byte read</returns>
        public static byte ReadNextByte(this TzxStandardSpeedDataBlock block)
        {
            const int BIT_0_PL = TapeDataBlockPlayer.BIT_0_PL;
            const int BIT_1_PL = TapeDataBlockPlayer.BIT_1_PL;
            const int STEP     = 50;

            var  nextTact = block.LastTact + STEP;
            byte bits     = 0x00;

            for (var i = 0; i < 8; i++)
            {
                // --- Wait for the high EAR bit
                var samplesLow = 0;
                while (!block.GetEarBit(nextTact))
                {
                    samplesLow++;
                    nextTact += STEP;
                }

                // --- Wait for the low EAR bit
                var samplesHigh = 0;
                while (block.GetEarBit(nextTact) && samplesHigh < BIT_1_PL / STEP + 2)
                {
                    samplesHigh++;
                    nextTact += STEP;
                }

                bits <<= 1;
                if (samplesLow > (BIT_0_PL + BIT_1_PL) / 2 / STEP &&
                    samplesHigh > (BIT_0_PL + BIT_1_PL) / 2 / STEP)
                {
                    bits++;
                }
            }
            return(bits);
        }