Пример #1
0
        private void dumpButton_Click(object sender, EventArgs e)
        {
            if (!validateWavFilename())
            {
                return;
            }

            Application.DoEvents();

            using (NAudio.Wave.WaveFileReader waveFile = new NAudio.Wave.WaveFileReader(wavFilenameTextBox.Text))
            {
                tapFile = new TapFile();

                WaveSeeker waveSeeker = new WaveSeeker(waveFile);

                infoTextBox.Clear();
                // Read Header Information
                if (!readHeaderInfo(waveSeeker))
                {
                    return;
                }

                byte theByte = 0;

                short  counter     = 0;
                string charVersion = "";

                // while not eof...
                while (waveSeeker.readByte(out theByte))
                {
                    infoTextBox.AppendText(theByte.ToString("X2") + " ");
                    charVersion += printableChar((char)theByte);
                    if (counter == 7)
                    {
                        infoTextBox.AppendText(" " + charVersion + Environment.NewLine);
                        charVersion = "";
                        counter     = 0;
                    }
                    else
                    {
                        counter++;
                    }
                }

                // Formatting...
                while (counter < 8)
                {
                    infoTextBox.AppendText("   ");
                    counter++;
                }

                if (charVersion != "")
                {
                    infoTextBox.AppendText(" " + charVersion + Environment.NewLine + Environment.NewLine);
                }
            }
        }
Пример #2
0
 private bool readLoadPoint(WaveSeeker waveSeeker)
 {
     // Read load point
     if ((tapFile.fileType == '9') || (tapFile.fileType == 'M'))
     {
         tapFile.loadPoint = waveSeeker.readUShort();
         infoTextBox.AppendText("Load Point: " + "0x" + tapFile.loadPoint.ToString("X4") + Environment.NewLine);
     }
     return(true);
 }
Пример #3
0
        private bool findA5Byte(WaveSeeker waveSeeker)
        {
            if (!waveSeeker.seekA5Byte())
            {
                infoTextBox.AppendText("Failed: A5 Byte not found! End Of File." + Environment.NewLine);
                return(false);
            }

            infoTextBox.AppendText("A5 byte found at " + waveSeeker.WavePositions.max + Environment.NewLine);
            return(true);
        }
Пример #4
0
        private bool readLoadFilename(WaveSeeker waveSeeker)
        {
            tapFile.loadName = waveSeeker.readLoadName();

            if (tapFile.loadName == "")
            {
                infoTextBox.AppendText("Failed: Load Name not found." + Environment.NewLine);
                return(false);
            }
            infoTextBox.AppendText("Load Name: " + (tapFile.loadName == "<Level9>" ? "N/A " : "") + tapFile.loadName + Environment.NewLine);
            return(true);
        }
Пример #5
0
        private bool readFileType(WaveSeeker waveSeeker)
        {
            tapFile.fileType = waveSeeker.readFileType();

            if (tapFile.fileType == '\0')
            {
                infoTextBox.AppendText("Warning: File Type not found." + Environment.NewLine);
            }
            else
            {
                infoTextBox.AppendText("File Type: " + tapFile.fileType + Environment.NewLine);
            }

            return(true);
        }
Пример #6
0
        private bool readProgramLength(WaveSeeker waveSeeker)
        {
            // Read program length
            tapFile.programLength = waveSeeker.readUShort();

            if (tapFile.programLength == 0)
            {
                infoTextBox.AppendText("Warning: Program Length not found." + Environment.NewLine);
            }
            else
            {
                infoTextBox.AppendText("Program Length: " + tapFile.programLength + Environment.NewLine);
            }

            return(true);
        }
Пример #7
0
        private bool readProgramBytes(WaveSeeker waveSeeker)
        {
            tapFile.program = new byte[tapFile.programLength];

            programLength = waveSeeker.readProgram(tapFile.program, tapFile.programLength);

            if (tapFile.programLength != programLength)
            {
                infoTextBox.AppendText("Failed: Actual length: " + programLength + Environment.NewLine);
                return(false);
            }

            if (waveSeeker.EndOfFile)
            {
                infoTextBox.AppendText("Failed: End-of-file reached. " + Environment.NewLine);
                return(false);
            }

            return(true);
        }
Пример #8
0
        private bool findSyncZero(WaveSeeker waveSeeker)
        {
            WavePositionsStruct wavePositions = waveSeeker.findSyncZero();

            if (waveSeeker.EndOfFile)
            {
                infoTextBox.AppendText("Failed: Sync zero not found. End of File." + Environment.NewLine);
                return(false);
            }

            infoTextBox.AppendText(
                "Sync zero found. " +
                "(" + wavePositions.start +
                "," + wavePositions.min +
                "," + wavePositions.crossover +
                "," + wavePositions.max + ")" + Environment.NewLine
                );

            return(true);
        }
Пример #9
0
        private bool validateWavFormat(WaveSeeker waveSeeker)
        {
            infoTextBox.AppendText("Wave Format: " + waveSeeker.WaveFormat + Environment.NewLine);
            infoTextBox.AppendText("Length: " + waveSeeker.WaveFile.Length + " bytes" + Environment.NewLine);
            infoTextBox.AppendText("Total time: " + waveSeeker.WaveFile.TotalTime + Environment.NewLine);

            // Validate wave file format
            if (waveSeeker.WaveFormat.BitsPerSample != 16)
            {
                infoTextBox.AppendText("Failed: only works with 16 bit audio (-for now)." + Environment.NewLine);
                return(false);
            }

            if (waveSeeker.WaveFormat.SampleRate != 22050)
            {
                infoTextBox.AppendText("Failed: only works with 22Khz sample rate (-for now)." + Environment.NewLine);
                return(false);
            }

            return(true);
        }
Пример #10
0
        private void ReloadButton_Click(object sender, EventArgs e)
        {
            if (!validateWavFilename())
            {
                return;
            }

            Application.DoEvents();

            using (NAudio.Wave.WaveFileReader waveFile = new NAudio.Wave.WaveFileReader(wavFilenameTextBox.Text))
            {
                tapFile = new TapFile();

                WaveSeeker waveSeeker = new WaveSeeker(waveFile);

                // Read Header Information
                if (!readHeaderInfo(waveSeeker))
                {
                    return;
                }

                // If we don't know the program length
                if (tapFile.programLength == 0)
                {
                    return;
                }

                // Read program itself
                if (!readProgramBytes(waveSeeker))
                {
                    return;
                }

                // Display program bytes
                displayProgramBytes();

                // Validate Basic terminator
                if ((tapFile.fileType == 'B') && (tapFile.program[tapFile.programLength - 1] != 0x80))
                {
                    infoTextBox.AppendText("Warning: 'End-of-program' terminator missing (&80)" + Environment.NewLine);
                }

                // Actual length
                infoTextBox.AppendText(Environment.NewLine + "Length: " + tapFile.programLength + " (agreed)" + Environment.NewLine);

                infoTextBox.AppendText(Environment.NewLine + "Trailing Information:" + Environment.NewLine + "---------------------" + Environment.NewLine);

                // Read checksum
                if ((tapFile.fileType == 'M') || (tapFile.fileType == 'D') || (tapFile.fileType == '9'))
                {
                    if (!waveSeeker.readChecksum(out tapFile.checksum))
                    {
                        infoTextBox.AppendText("Warning: Checksum wrong/not found (ignored)" + Environment.NewLine);
                    }

                    infoTextBox.AppendText("Checksum: " + tapFile.checksum.ToString("X2") + Environment.NewLine);

                    // Calculate actual checksum
                    byte actualChecksum = 0;
                    for (int i = 0; i < tapFile.program.Length; i++)
                    {
                        actualChecksum += tapFile.program[i];
                    }
                    infoTextBox.AppendText("Calculated Checksum: " + actualChecksum.ToString("X2"));
                    if (tapFile.checksum == actualChecksum)
                    {
                        infoTextBox.AppendText(" (agreed)" + Environment.NewLine);
                    }
                    else
                    {
                        infoTextBox.AppendText(Environment.NewLine + "Warning: checksums disagree (ignored)" + Environment.NewLine);
                    }
                    tapFile.checksum = actualChecksum;

                    if ((tapFile.fileType == 'M') || (tapFile.fileType == 'D'))
                    {
                        waveSeeker.readByte(out tapFile.mysteryByte);
                        infoTextBox.AppendText("Mystery byte: " + tapFile.mysteryByte.ToString("X2") + Environment.NewLine);
                    }
                }

                // Read excution point
                if (tapFile.fileType != '9' && tapFile.fileType != 'D')
                {
                    tapFile.executionPoint = waveSeeker.readUShort();
                    infoTextBox.AppendText("Execution point: 0x" + tapFile.executionPoint.ToString("X4") + Environment.NewLine);
                }

                // Scroll to top
                infoTextBox.SelectionStart  = 0;
                infoTextBox.SelectionLength = 1;
                infoTextBox.ScrollToCaret();

                // Now enable Tap controls.
                saveButton.Enabled = isSaveEnabled();
            }
        }
Пример #11
0
        private bool readHeaderInfo(WaveSeeker waveSeeker)
        {
            try
            {
                infoTextBox.Clear();

                infoTextBox.AppendText("Header Information: " + Environment.NewLine + "-------------------" + Environment.NewLine);

                if (!validateWavFormat(waveSeeker))
                {
                    return(false);
                }

                if (!findSyncZero(waveSeeker))
                {
                    return(false);
                }

                if (!findA5Byte(waveSeeker))
                {
                    return(false);
                }

                if (!readLoadFilename(waveSeeker))
                {
                    return(false);
                }

                if (tapFile.loadName == "<Level9>")
                {
                    tapFile.fileType = '9';
                    if (!readLoadPoint(waveSeeker))
                    {
                        return(false);
                    }
                    if (!readProgramLength(waveSeeker))
                    {
                        return(false);
                    }
                }
                else if (tapFile.loadName != "")
                {
                    if (!findA5Byte(waveSeeker))
                    {
                        return(false);
                    }
                    if (!readFileType(waveSeeker))
                    {
                        return(false);
                    }
                    if (!readProgramLength(waveSeeker))
                    {
                        return(false);
                    }
                    if (!readLoadPoint(waveSeeker))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (IOException err)
            {
                infoTextBox.AppendText(err.Message + Environment.NewLine + "Error reading file." + Environment.NewLine);
                return(false);
            }
        }