示例#1
0
        static public String Load(MemoryRAM ram, string Filename, int gabeAddressBank, out int startAddress, out int length)
        {
            int    bank              = 0;
            int    address           = 0;
            String processedFileName = Filename;

            startAddress = -1;
            length       = -1;

            if (!System.IO.File.Exists(Filename))
            {
                OpenFileDialog f = new OpenFileDialog
                {
                    Title  = "Select a kernel file",
                    Filter = "Hex Files|*.hex|All Files|*.*"
                };
                if (f.ShowDialog() == DialogResult.OK)
                {
                    processedFileName = f.FileName;
                }
                else
                {
                    return(null);
                }
            }


            string[] lines = System.IO.File.ReadAllLines(processedFileName);

            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)
                    {
                    // data row. The next n bytes are data to be loaded into memory
                    case "00":
                        address = GetByte(offset, 0, 2);
                        if (startAddress == -1 && ((address & 0xFF00) != 0xFF00))
                        {
                            startAddress = bank + address;
                        }
                        if (bank <= ram.Length)
                        {
                            for (int i = 0; i < data.Length; i += 2)
                            {
                                int b = GetByte(data, i, 1);
                                ram.WriteByte(bank + address, (byte)b);
                                // Copy bank $38 or $18 to page 0
                                if (bank == gabeAddressBank)
                                {
                                    ram.WriteByte(address, (byte)b);
                                }
                                address++;
                            }
                        }

                        break;

                    // end of file - just ignore
                    case "01":
                        length = address;
                        break;

                    case "02":
                        bank = GetByte(data, 0, 2) * 16;
                        break;

                    // extended linear address
                    // lower byte will populate the bank number.
                    case "04":
                        bank = GetByte(data, 0, 2) << 16;
                        break;

                    // extended linear start address
                    // set the initial bank register value. Not used in the simulator.
                    case "05":
                        break;

                    default:
                        throw new NotImplementedException("Record type not implemented: " + rectype);
                    }
                }
                else
                {
                    MessageBox.Show("This doesn't appear to be an Intel Hex file.", "Error Loading Hex File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            return(processedFileName);
        }
示例#2
0
        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;
        }