private void SendBinaryButton_Click(object sender, EventArgs e) { SendBinaryButton.Enabled = false; DisconnectButton.Enabled = false; hideLabelTimer_Tick(null, null); int transmissionSize = GetTransmissionSize(); UploadProgressBar.Maximum = transmissionSize; UploadProgressBar.Value = 0; UploadProgressBar.Visible = true; int BaseBankAddress = 0x38_0000; if (boardVersion == BoardVersion.RevB) { BaseBankAddress = 0x18_0000; } if (SendFileRadio.Checked) { if (serial.IsOpen) { // Get into Debug mode (Reset the CPU and keep it in that state and Gavin will take control of the bus) if (DebugModeCheckbox.Checked) { GetFnxInDebugMode(); } if (Path.GetExtension(FileNameTextBox.Text).ToUpper().Equals(".BIN")) { // Read the bytes and put them in the buffer byte[] DataBuffer = System.IO.File.ReadAllBytes(FileNameTextBox.Text); int FnxAddressPtr = int.Parse(C256DestAddress.Text.Replace(":", ""), System.Globalization.NumberStyles.AllowHexSpecifier); Console.WriteLine("Starting Address: " + FnxAddressPtr); Console.WriteLine("File Size: " + transmissionSize); SendData(DataBuffer, FnxAddressPtr, transmissionSize); // Update the Reset Vectors from the Binary Files Considering that the Files Keeps the Vector @ $00:FF00 if (FnxAddressPtr < 0xFF00 && (FnxAddressPtr + DataBuffer.Length) > 0xFFFF || (FnxAddressPtr == BaseBankAddress && DataBuffer.Length > 0xFFFF)) { PreparePacket2Write(DataBuffer, 0x00FF00, 0x00FF00, 256); } } else { bool resetVector = false; // Page FF is used to store IRQ vectors - this is only used when the program modifies the // values between BaseBank + FF00 to BaseBank + FFFF // BaseBank on RevB is $18 // BaseBank on RevC is $38 byte[] pageFF = PreparePacket2Read(0xFF00, 0x100); // If send HEX files, each time we encounter a "bank" change - record 04 - send a new data block string[] lines = System.IO.File.ReadAllLines(FileNameTextBox.Text); int bank = 0; int address = 0; foreach (string l in lines) { if (l.StartsWith(":")) { string mark = l.Substring(0, 1); string reclen = l.Substring(1, 2); string offset = l.Substring(3, 4); string rectype = l.Substring(7, 2); string data = l.Substring(9, l.Length - 11); string checksum = l.Substring(l.Length - 2); switch (rectype) { case "00": int length = Convert.ToInt32(reclen, 16); byte[] DataBuffer = new byte[length]; address = HexFile.GetByte(offset, 0, 2); for (int i = 0; i < data.Length; i += 2) { DataBuffer[i / 2] = (byte)HexFile.GetByte(data, i, 1); } PreparePacket2Write(DataBuffer, bank + address, 0, length); // TODO - make this backward compatible if (bank + address >= (BaseBankAddress + 0xFF00) && (bank + address) < (BaseBankAddress + 0xFFFF)) { int pageFFLen = length - ((bank + address + length) - (BaseBankAddress + 0x1_0000)); if (pageFFLen > length) { pageFFLen = length; } Array.Copy(DataBuffer, 0, pageFF, bank + address - (BaseBankAddress + 0xFF00), length); resetVector = true; } UploadProgressBar.Increment(length); break; case "01": // Don't do anything... this is the end of file record. break; case "02": bank = HexFile.GetByte(data, 0, 2) * 16; break; case "04": bank = HexFile.GetByte(data, 0, 2) << 16; break; default: Console.WriteLine("Unsupport HEX record type:" + rectype); break; } } } if (DebugModeCheckbox.Checked) { // Update the Reset Vectors from the Binary Files Considering that the Files Keeps the Vector @ $00:FF00 if (resetVector) { PreparePacket2Write(pageFF, 0x00FF00, 0, 256); } } } if (ReflashCheckbox.Checked && MessageBox.Show("Are you sure you want to reflash your C256 System?", "Reflash", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { CountdownLabel.Visible = true; this.Update(); EraseFlash(); int SrcFlashAddress = Convert.ToInt32(C256DestAddress.Text.Replace(":", ""), 16); ProgramFlash(SrcFlashAddress); CountdownLabel.Visible = false; } if (DebugModeCheckbox.Checked) { // The Loading of the File is Done, Reset the FNX and Get out of Debug Mode ExitFnxDebugMode(); } HideProgressBarAfter5Seconds("Transfer Done! System Reset!"); } } else if (BlockSendRadio.Checked && kernel.CPU != null) { // Get into Debug mode (Reset the CPU and keep it in that state and Gavin will take control of the bus) if (DebugModeCheckbox.Checked) { GetFnxInDebugMode(); } int blockAddress = Convert.ToInt32(EmuSrcAddress.Text.Replace(":", ""), 16); // Read the data directly from emulator memory int offset = 0; int FnxAddressPtr = int.Parse(C256DestAddress.Text.Replace(":", ""), System.Globalization.NumberStyles.AllowHexSpecifier); byte[] DataBuffer = new byte[transmissionSize]; // Maximum 2 MB, example from $0 to $1F:FFFF. for (int start = blockAddress; start < blockAddress + transmissionSize; start++) { DataBuffer[offset++] = kernel.CPU.MemMgr.ReadByte(start); } SendData(DataBuffer, FnxAddressPtr, transmissionSize); // Update the Reset Vectors from the Binary Files Considering that the Files Keeps the Vector @ $00:FF00 if (FnxAddressPtr < 0xFF00 && (FnxAddressPtr + DataBuffer.Length) > 0xFFFF || (FnxAddressPtr == BaseBankAddress && DataBuffer.Length > 0xFFFF)) { PreparePacket2Write(DataBuffer, 0x00FF00, 0x00FF00, 256); } if (DebugModeCheckbox.Checked) { // The Loading of the File is Done, Reset the FNX and Get out of Debug Mode ExitFnxDebugMode(); } HideProgressBarAfter5Seconds("Transfer Done! System Reset!"); } else { int blockAddress = Convert.ToInt32(C256SrcAddress.Text.Replace(":", ""), 16); byte[] DataBuffer = new byte[transmissionSize]; // Maximum 2 MB, example from $0 to $1F:FFFF. if (FetchData(DataBuffer, blockAddress, transmissionSize, DebugModeCheckbox.Checked)) { MemoryRAM mem = new MemoryRAM(blockAddress, transmissionSize); mem.Load(DataBuffer, 0, 0, transmissionSize); MemoryWindow tempMem = new MemoryWindow { Memory = mem, Text = "C256 Memory from " + blockAddress.ToString("X6") + " to " + (blockAddress + transmissionSize - 1).ToString("X6") }; tempMem.GotoAddress(blockAddress); tempMem.AllowSave(); tempMem.Show(); } SendBinaryButton.Enabled = true; DisconnectButton.Enabled = true; } }
private void SendBinaryButton_Click(object sender, EventArgs e) { SendBinaryButton.Enabled = false; DisconnectButton.Enabled = false; int transmissionSize = GetTransmissionSize(); UploadProgressBar.Maximum = transmissionSize; UploadProgressBar.Value = 0; UploadProgressBar.Visible = true; if (SendFileRadio.Checked) { if (Path.GetExtension(FileNameTextBox.Text).ToUpper().Equals(".BIN")) { //byte[] DataBuffer = new byte[transmissionSize]; // Maximum 2 MB, example from $0 to $1F:FFFF. // Read the bytes and put them in the buffer byte[] DataBuffer = System.IO.File.ReadAllBytes(FileNameTextBox.Text); int FnxAddressPtr = int.Parse(C256DestAddress.Text.Replace(":", ""), System.Globalization.NumberStyles.AllowHexSpecifier); Console.WriteLine("Starting Address: " + FnxAddressPtr); Console.WriteLine("Size of File: " + transmissionSize); SendData(DataBuffer, FnxAddressPtr, transmissionSize, DebugModeCheckbox.Checked); } else { if (serial.IsOpen) { // Get into Debug mode (Reset the CPU and keep it in that state and Gavin will take control of the bus) if (DebugModeCheckbox.Checked) { GetFnxInDebugMode(); } // If send HEX files, each time we encounter a "bank" change - record 04 - send a new data block string[] lines = System.IO.File.ReadAllLines(FileNameTextBox.Text); int bank = 0; int address = 0; byte[] pageFF = new byte[256]; bool resetVector = false; foreach (string l in lines) { if (l.StartsWith(":")) { string mark = l.Substring(0, 1); string reclen = l.Substring(1, 2); string offset = l.Substring(3, 4); string rectype = l.Substring(7, 2); string data = l.Substring(9, l.Length - 11); string checksum = l.Substring(l.Length - 2); switch (rectype) { case "00": int length = Convert.ToInt32(reclen, 16); byte[] DataBuffer = new byte[length]; address = HexFile.GetByte(offset, 0, 2); for (int i = 0; i < data.Length; i += 2) { DataBuffer[i / 2] = (byte)HexFile.GetByte(data, i, 1); } PreparePacket2Write(DataBuffer, bank + address, 0, length); if (bank + address >= 0xFF00 && (bank + address) < 0xFFFF) { int pageFFLen = length - ((bank + address + length) - 0x1_0000); if (pageFFLen > length) { pageFFLen = length; } Array.Copy(DataBuffer, 0, pageFF, bank + address - 0xFF00, pageFFLen); resetVector = true; } else if (bank + address >= 0x18_FF00 && (bank + address) < 0x18_FFFF) { int pageFFLen = length - ((bank + address + length) - 0x19_0000); if (pageFFLen > length) { pageFFLen = length; } Array.Copy(DataBuffer, 0, pageFF, bank + address - 0x18_FF00, length); resetVector = true; } UploadProgressBar.Increment(length); break; case "04": bank = HexFile.GetByte(data, 0, 2) << 16; break; } } } if (DebugModeCheckbox.Checked) { // Update the Reset Vectors from the Binary Files Considering that the Files Keeps the Vector @ $00:FF00 if (resetVector) { PreparePacket2Write(pageFF, 0x00FF00, 0, 256); } // The Loading of the File is Done, Reset the FNX and Get out of Debug Mode ExitFnxDebugMode(); } MessageBox.Show("Transfer Done! System Reset!", "Send Binary Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else if (BlockSendRadio.Checked) { int blockAddress = Convert.ToInt32(EmuSrcAddress.Text.Replace(":", ""), 16); // Read the data directly from emulator memory int offset = 0; int FnxAddressPtr = int.Parse(C256DestAddress.Text.Replace(":", ""), System.Globalization.NumberStyles.AllowHexSpecifier); byte[] DataBuffer = new byte[transmissionSize]; // Maximum 2 MB, example from $0 to $1F:FFFF. for (int start = blockAddress; start < blockAddress + transmissionSize; start++) { DataBuffer[offset++] = Memory.ReadByte(start); } SendData(DataBuffer, FnxAddressPtr, transmissionSize, DebugModeCheckbox.Checked); } else { int blockAddress = Convert.ToInt32(C256SrcAddress.Text.Replace(":", ""), 16); byte[] DataBuffer = new byte[transmissionSize]; // Maximum 2 MB, example from $0 to $1F:FFFF. if (FetchData(DataBuffer, blockAddress, transmissionSize, DebugModeCheckbox.Checked)) { BasicMemory mem = new BasicMemory("tempbuffer", blockAddress, transmissionSize); mem.Load(DataBuffer, 0, 0, transmissionSize); MemoryWindow tempMem = new MemoryWindow { Memory = mem, Text = "C256 Memory from " + blockAddress.ToString("X6") + " to " + (blockAddress + transmissionSize - 1).ToString("X6") }; tempMem.GotoAddress(blockAddress); tempMem.Show(); } } UploadProgressBar.Visible = false; SendBinaryButton.Enabled = true; DisconnectButton.Enabled = true; }