Example #1
0
        // Convert a Hex file to PGX
        // Header is PGX,1,4 byte jump address
        private void ConvertHexToPGXToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter          = "Hex Files|*.hex",
                Title           = "Select a Hex File",
                CheckFileExists = true
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                MemoryRAM temporaryRAM = new MemoryRAM(0, 4 * 1024 * 1024);
                HexFile.Load(temporaryRAM, dialog.FileName, 0, out int DataStartAddress, out int DataLength);
                // write the file
                string outputFileName = Path.ChangeExtension(dialog.FileName, "PGX");

                byte[] buffer = new byte[DataLength];
                temporaryRAM.CopyIntoBuffer(DataStartAddress, buffer, 0, DataLength);
                using (BinaryWriter writer = new BinaryWriter(File.Open(outputFileName, FileMode.Create)))
                {
                    // 8 byte header
                    writer.Write((byte)'P');
                    writer.Write((byte)'G');
                    writer.Write((byte)'X');
                    writer.Write((byte)1);
                    writer.Write(DataStartAddress);
                    writer.Write(buffer);
                }
            }
        }
Example #2
0
        public void ResetCPU(bool ResetMemory)
        {
            CPU.Halt();

            gpu.Refresh();

            // This fontset is loaded just in case the kernel doesn't provide one.
            gpu.LoadFontSet("Foenix", @"Resources\Bm437_PhoenixEGA_8x8.bin", 0, CharacterSet.CharTypeCodes.ASCII_PET, CharacterSet.SizeCodes.Size8x8);

            if (Configuration.Current.StartUpHexFile.EndsWith(".fnxml", true, null))
            {
                FoeniXmlFile fnxml = new FoeniXmlFile(MemoryManager, Resources, CPUWindow.Instance.breakpoints);
                fnxml.Load(Configuration.Current.StartUpHexFile);
            }
            else
            {
                Configuration.Current.StartUpHexFile = HexFile.Load(MemoryManager, Configuration.Current.StartUpHexFile);
                if (Configuration.Current.StartUpHexFile != null)
                {
                    if (ResetMemory)
                    {
                        lstFile = new ListFile(Configuration.Current.StartUpHexFile);
                    }
                    else
                    {
                        // TODO: We should really ensure that there are no duplicated PC in the list
                        ListFile tempList = new ListFile(Configuration.Current.StartUpHexFile);
                        lstFile.Lines.InsertRange(0, tempList.Lines);
                    }
                }
            }

            // If the reset vector is not set in Bank 0, but it is set in Bank 18, then copy bank 18 into bank 0.
            if (MemoryManager.ReadLong(0xFFE0) == 0 && MemoryManager.ReadLong(0x18_FFE0) != 0)
            //if (MemoryManager.ReadLong(0xFFFC) == 0 && MemoryManager.ReadLong(0x18_FFFC) != 0)
            {
                MemoryManager.Copy(0x180000, MemoryMap.RAM_START, MemoryMap.PAGE_SIZE);
                // See if lines of code exist in the 0x18_0000 to 0x18_FFFF block
                List <DebugLine> copiedLines = new List <DebugLine>();
                if (lstFile.Lines.Count > 0)
                {
                    List <DebugLine> tempLines = new List <DebugLine>();
                    foreach (DebugLine line in lstFile.Lines)
                    {
                        if (line.PC >= 0x18_0000 && line.PC < 0x19_0000)
                        {
                            DebugLine dl = (DebugLine)line.Clone();
                            dl.PC -= 0x18_0000;
                            copiedLines.Add(dl);
                        }
                    }
                }
                if (copiedLines.Count > 0)
                {
                    lstFile.Lines.InsertRange(0, copiedLines);
                }
            }
            CPU.Reset();
        }
Example #3
0
        public void Reset()
        {
            CPU.Halt();

            Cls();
            gpu.Refresh();

            // Load the ROM data from disk. On the real system, the ROMs are not accessible by the CPU
            // and will be copied to RAM by VICKY
            MemoryRAM flashROM = new MemoryRAM(0, 16 * 65536);

            this.ReadyHandler = Monitor;
            HexFile.Load(flashROM, @"ROMs\kernel.hex");
            flashROM.Copy(0, Memory.SRAM, 0, 2 * 65536);
            CPU.Reset();

            //CPUTest test= new CPUTest(this);
            //test.BeginTest(0xf81000);

            this.TickTimer.Interval = 1000 / 60;
            this.TickTimer.Elapsed += TickTimer_Elapsed;
            this.TickTimer.Enabled  = true;
        }
Example #4
0
        // return true if the CPU was reset and the program was loaded
        public bool ResetCPU(string kernelFilename)
        {
            if (CPU != null)
            {
                CPU.DebugPause = true;
                //CPU.Halt();
            }

            if (kernelFilename != null)
            {
                LoadedKernel = kernelFilename;
            }

            // If the reset vector is not set in Bank 0, but it is set in Bank 18, the copy bank 18 into bank 0.
            int BasePageAddress = 0x18_0000;

            if (boardVersion == BoardVersion.RevC)
            {
                BasePageAddress = 0x38_0000;
            }

            if (LoadedKernel.EndsWith(".fnxml", true, null))
            {
                this.ResetMemory();
                FoeniXmlFile fnxml = new FoeniXmlFile(this, Resources);
                fnxml.Load(LoadedKernel);
                boardVersion = fnxml.Version;
            }
            else
            {
                LoadedKernel = HexFile.Load(MemMgr.RAM, LoadedKernel, BasePageAddress, out _, out _);
                if (LoadedKernel != null)
                {
                    if (lstFile == null)
                    {
                        lstFile = new ListFile(LoadedKernel);
                    }
                    else
                    {
                        // TODO: This results in lines of code to be shown in incorrect order - Fix
                        ListFile tempList = new ListFile(LoadedKernel);
                        foreach (DebugLine line in tempList.Lines.Values)
                        {
                            if (lstFile.Lines.ContainsKey(line.PC))
                            {
                                lstFile.Lines.Remove(line.PC);
                            }
                            lstFile.Lines.Add(line.PC, line);
                            for (int i = 1; i < line.commandLength; i++)
                            {
                                if (lstFile.Lines.ContainsKey(line.PC + i))
                                {
                                    lstFile.Lines.Remove(line.PC + i);
                                }
                            }
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }

            // See if lines of code exist in the 0x18_0000 to 0x18_FFFF block for RevB or 0x38_0000 to 0x38_FFFF block for Rev C
            List <DebugLine> copiedLines = new List <DebugLine>();

            if (lstFile.Lines.Count > 0)
            {
                foreach (DebugLine line in lstFile.Lines.Values)
                {
                    if (line != null && line.PC >= BasePageAddress && line.PC < BasePageAddress + 0x1_0000)
                    {
                        DebugLine dl = (DebugLine)line.Clone();
                        dl.PC -= BasePageAddress;
                        copiedLines.Add(dl);
                    }
                }
            }
            if (copiedLines.Count > 0)
            {
                foreach (DebugLine line in copiedLines)
                {
                    if (lstFile.Lines.ContainsKey(line.PC))
                    {
                        lstFile.Lines.Remove(line.PC);
                    }
                    lstFile.Lines.Add(line.PC, line);
                }
            }
            CPU.Reset();
            return(true);
        }
Example #5
0
        public void OpenEeprom(string filePath)
        {
            var hexFile = HexFile.Load(filePath);

            EepromHexBoard = HexBoard.From(hexFile);
        }
Example #6
0
        public void OpenFlash(string filePath)
        {
            var hexFile = HexFile.Load(filePath);

            FlashHexBoard = HexBoard.From(hexFile);
        }