【问题标题】:Read From Hexidimal Literal to String从十六进制文字读取到字符串
【发布时间】:2018-02-02 09:16:09
【问题描述】:

一直在从事一个涉及读取 ROM 标头(来自仿真场景)和报告数据的项目。我已经把大部分内容都布置好了,但是找不到从 ROM 中的十六进制文字地址读取的代码(EX:120h,然后读取“x”字节数)(EX2:一些调用读取 120h 到 140h )。我试过在 YouTube 上搜索并搜索它,但到目前为止没有运气。另外,语言是 C#。

这是我目前的代码。

private void openROMToolStripMenuItem_Click(object sender, EventArgs e)
{
    OpenFileDialog1.Title = "Select A ROM File";
    OpenFileDialog1.InitialDirectory = "C:/Users";
    OpenFileDialog1.ShowDialog();
    textBox1.Text = System.IO.Path.GetFileName(OpenFileDialog1.FileName);
    textBox8.Text = "Calculating...";
    {
        backgroundWorker1.RunWorkerAsync(OpenFileDialog1.FileName);
    }

    string getExt = Path.GetExtension(OpenFileDialog1.FileName);

    getExt = getExt.ToLower();

    if (getExt == ".smd" || getExt == ".gen" || getExt == ".md")
    {
       // SEGA GENESIS CODE (READ ROM DATA GOES HERE)
    }
    // REPEAT "if" STATEMENT FOR NEXT FILE FORMAT

任何帮助将不胜感激。谢谢。

【问题讨论】:

  • 你的项目中ROM是不是用文件表示的?
  • 是的。它是从 OpenDialoge 框中提取的。

标签: c# windows emulation


【解决方案1】:

我得到了我正在寻找的解决方案。我使用了这个代码。

// SEGA GENESIS CODE

      // ROM NAME 2

                BinaryReader br = new 
                BinaryReader(File.OpenRead(OpenFileDialog1.FileName));
                string romNameA = null;
                for (int i = 0x120; i <= 0x144; i++)
                {
                    br.BaseStream.Position = i;
                    romNameA += br.ReadByte().ToString("X2");
                    textBox4.Text = romNameA;
                }
                br.Close();

我现在有了我需要的代码字符串。但现在提出了一个可能的新问题,我将在新帖子中提出。

【讨论】:

  • 您应该将BinaryReader 包装在using 块中,以防止异常停止处理正在处理的句柄。
猜你喜欢
  • 2010-10-04
  • 2014-03-07
  • 1970-01-01
  • 1970-01-01
  • 2021-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-26
相关资源
最近更新 更多