Exemplo n.º 1
0
        /// <summary>
        /// Load a character set from disk
        /// </summary>
        /// <param name="Filename">data file with character glyphs</param>
        /// <param name="Vram">array to store glyph data</param>
        /// <param name="StartAddress">starting address in array</param>
        /// <param name="newCharSize">Size of glyhphs (8x8 or 8x16)</param>
        public void Load(string Filename, int Offset, BasicMemory Vram, int StartAddress, SizeCodes newCharSize)
        {
            this.StartAddress  = StartAddress;
            this.CharSize      = newCharSize;
            this.CharacterData = Vram;

            try
            {
                byte[] d = global::System.IO.File.ReadAllBytes(Filename);
                Vram.Load(d, Offset, StartAddress, d.Length - Offset);
            }
            catch (Exception ex)
            {
                SystemLog.WriteLine(SystemLog.SeverityCodes.Recoverable, "Error in CharacteSet.Load\r\n" + ex.Message + "Filename:" + Filename);
            }
        }
Exemplo n.º 2
0
        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;
        }