private void button20_Click_1(object sender, EventArgs e) { //int i; StringBuilder tbt = new StringBuilder(); StringBuilder txt = new StringBuilder(); // Convert string of hex encoded ascii to byte array byte[] bytes = FDDProcessing.HexToBytes(tbBIN.Text); byte[] mfmbytes; // Convert bytes to Amiga mfm mfmbytes = processing.amigamfmencodebytes(bytes, 0, bytes.Length); byte[] checksum; checksum = processing.amigachecksum(mfmbytes, 0, mfmbytes.Length); tbt.Append("Checksum:" + checksum[0].ToString("X2") + checksum[1].ToString("X2") + checksum[2].ToString("X2") + checksum[3].ToString("X2")); tbTest.Clear(); AntxtBox.Clear(); tbTest.AppendText(tbt.ToString()); AntxtBox.AppendText(txt.ToString()); }
private void button25_Click(object sender, EventArgs e) { byte[] bytes = FDDProcessing.HexToBytes(tbBIN.Text); ushort datacrcchk; Crc16Ccitt crc = new Crc16Ccitt(InitialCrcValue.NonZero3); datacrcchk = crc.ComputeGoodChecksum(bytes); tbTest.AppendText("CRC: " + datacrcchk.ToString("X4") + "\r\n"); }
private void ConvertToMFMBtn_Click(object sender, EventArgs e) { int i; StringBuilder tbt = new StringBuilder(); StringBuilder txt = new StringBuilder(); // Convert string of hex encoded ascii to byte array byte[] bytes = FDDProcessing.HexToBytes(tbBIN.Text); if (ANPCRadio.Checked) { // Convert byte array to MFM byte[] mfmbytes = processing.BIN2MFMbits(ref bytes, bytes.Count(), 0, false); byte[] bytebuf = new byte[tbBIN.Text.Length]; // Convert mfm to string tbMFM.Text = Encoding.ASCII.GetString(processing.BIN2MFMbits(ref bytes, bytes.Count(), 0, true)); for (i = 0; i < mfmbytes.Length / 16; i++) { bytebuf[i] = processing.MFMBits2BINbyte(ref mfmbytes, (i * 16)); tbt.Append(bytebuf[i].ToString("X2") + " "); if (bytebuf[i] > ' ' && bytebuf[i] < 127) { txt.Append((char)bytebuf[i]); } else { txt.Append("."); } } } else if (ANAmigaRadio.Checked) { byte[] mfmbytes = new byte[bytes.Length * 8]; int j; // Convert byte array to MFM for (i = 0; i < bytes.Length; i++) { for (j = 0; j < 8; j++) { mfmbytes[i * 8 + j] = (byte)(bytes[i] >> (7 - j) & 1); } } //byte[] mfmbytes = BIN2MFMbits(ref bytes, bytes.Count(), 0, false); byte[] bytebuf = new byte[tbBIN.Text.Length]; // Convert mfm to string tbMFM.Text = Encoding.ASCII.GetString(processing.BIN2MFMbits(ref bytes, bytes.Count(), 0, true)); bytebuf = processing.amigamfmdecodebytes(mfmbytes, 0, mfmbytes.Length); // This doesn't convert sector properly yet // Convert mfm back to bytes for (i = 0; i < bytebuf.Length; i++) { //bytebuf[i] = MFMBits2BINbyte(ref mfmbytes, (i * 16)); tbt.Append(bytebuf[i].ToString("X2") + " "); if (bytebuf[i] > 31 && bytebuf[i] < 127) { txt.Append((char)bytebuf[i]); } else { txt.Append("."); } if (i % 16 == 15) { tbt.Append("\r\n"); } if (i % 32 == 31) { txt.Append("\r\n"); } } } else if (AmigaMFMRadio.Checked) { byte[] mfmbytes; // Convert bytes to Amiga mfm mfmbytes = processing.amigamfmencodebytes(bytes, 0, bytes.Length); byte[] bytebuf = new byte[tbBIN.Text.Length]; // Convert mfm to string tbMFM.Text = Encoding.ASCII.GetString(processing.BIN2MFMbits(ref bytes, bytes.Count(), 0, true)); bytebuf = processing.amigamfmdecodebytes(mfmbytes, 0, mfmbytes.Length); // This doesn't convert sector properly yet // Convert mfm back to bytes for (i = 0; i < bytebuf.Length; i++) { //bytebuf[i] = MFMBits2BINbyte(ref mfmbytes, (i * 16)); tbt.Append(bytebuf[i].ToString("X2") + " "); if (bytebuf[i] > 31 && bytebuf[i] < 127) { txt.Append((char)bytebuf[i]); } else { txt.Append("."); } if (i % 16 == 15) { tbt.Append("\r\n"); } if (i % 32 == 31) { txt.Append("\r\n"); } } } tbTest.Clear(); AntxtBox.Clear(); tbTest.AppendText(tbt.ToString()); AntxtBox.AppendText(txt.ToString()); }