0

我正在使用虚拟机并卡在屏幕上。我的代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Drawing.Text;
    using System.Drawing.Imaging;


    namespace GW480_VM
    {
public partial class Form1 : Form
{
    private ushort m_ScreenMemoryLocation = 0xA000;
    private byte[] m_ScreenMemory= new byte[3267];
    private string command, location, A = "empty", B = "empty", C = "empty", X = "empty", Y = "empty", Z = "empty";
    private uint[] BARGB = new uint[3267],FARGB = new uint [3267];
    public Form1()
    {
        InitializeComponent();
        for (int i = 0; i < 3267; i++)
        {
            BARGB[i] = 0x000000;
            FARGB[i] = 0xFFFFFF;
            m_ScreenMemory[i] = 32;
        }




        BIOS();



        //   Commands List
        // RUN location
        // DMP 
        // JMP address                                            //TODO
        // LDA
        // LDB
        // LDC
        // LDX
        // LDY
        // LDZ
        // STA
        // ADD                                                    //Mathematics TODO
        // SUB                                                    //Mathematics TODO
        // DIV                                                    //Mathematics TODO
        // MLP                                                    //Mathematics TODO
        // CMP address1 address2 cmpcode                          //TODO
        // POK address value

    }

    public void BIOS()
    {
        //Interpret_DMP(); //Debuging purpose only
        FARGB[0] = 0xFF0000;    //same
        Interpret_POK(0xa000, 65); //same
    }
    public void Interpret(StreamReader OS)
    {

        command = OS.ReadLine();
        if (command.Contains("GW480") == true)
        {
            command = OS.ReadLine();
            String StartAdd = command;
            while ((command = OS.ReadLine()) != null)
            {
                if (command.Contains("RUN"))
                {
                    command.Replace(" RUN ", "");
                    command.Replace(Environment.NewLine, "");
                    Interpret_RUN(command);

                }
                if (command.Contains("DMP"))
                {

                    Interpret_DMP();
                }
                if (command.Contains("LDA"))
                {
                    command.Replace(" LDA ", "");
                    command.Replace(Environment.NewLine, "");
                    A = command;
                }
                if (command.Contains("LDB"))
                {
                    command.Replace(" LDB ", "");
                    command.Replace(Environment.NewLine, "");
                    B = command;
                }
                if (command.Contains("LDC"))
                {
                    command.Replace(" LDC ", "");
                    command.Replace(Environment.NewLine, "");
                    C = command;
                }
                if (command.Contains("LDX"))
                {
                    command.Replace(" LDX ", "");
                    command.Replace(Environment.NewLine, "");
                    X = command;
                }
                if (command.Contains("LDY"))
                {
                    command.Replace(" LDY ", "");
                    command.Replace(Environment.NewLine, "");
                    Y = command;
                }
                if (command.Contains("LDZ"))
                {
                    command.Replace(" LDZ ", "");
                    command.Replace(Environment.NewLine, "");
                    Z = command;
                }
                if (command.Contains("STA"))
                {
                    command.Replace(" STA ", "");
                    command.Replace(Environment.NewLine, "");
                    switch (command)
                    {
                        case "A":
                            A = A;
                            break;
                        case "B":
                            A = B;
                            break;
                        case "C":
                            A = C;
                            break;
                        case "X":
                            A = X;
                            break;
                        case "Y":
                            A = Y;
                            break;
                        case "Z":
                            A = Z;
                            break;
                        default:
                            A = A;
                            break;
                    }
                }
                if (command.Contains("POK"))
                {
                    command.Replace(" POK ", "");
                    string com_copy = command;
                    command.Remove(7);
                    com_copy.Replace(command + " ", "");
                    Interpret_POK(Convert.ToUInt16(command, 8), Convert.ToByte(com_copy, 2));

                }

            }
        }
    }
    public void Interpret_RUN(string location)
    {
        StreamReader RUNapp = new StreamReader(location);
        Interpret(RUNapp);
        RUNapp.Close();
        RUNapp.Dispose();
    }

    public void Interpret_DMP()
    {
        DialogResult result = saveFileDialog1.ShowDialog();
        if (result == DialogResult.OK)
        {
            StreamWriter Dump = new StreamWriter(saveFileDialog1.FileName);
            Dump.WriteLine("Dump Date = " + DateTime.Today);
            Dump.WriteLine("Dump Time = " + DateTime.Now);
            Dump.WriteLine("");
            Dump.WriteLine("");
            Dump.WriteLine("");
            Dump.WriteLine("Registers");
            Dump.WriteLine("");
            Dump.WriteLine("    A   = " + A);
            Dump.WriteLine("    B   = " + B);
            Dump.WriteLine("    C   = " + C);
            Dump.WriteLine("    X   = " + X);
            Dump.WriteLine("    Y   = " + Y);
            Dump.WriteLine("    Z   = " + Z);
            Dump.WriteLine("");
            Dump.WriteLine("");
            Dump.WriteLine("    Current ARGB Values "+Environment.NewLine+Environment.NewLine);
            Dump.WriteLine("Background      " + BARGB.ToString() + Environment.NewLine);
            Dump.WriteLine("Foreground      " + FARGB.ToString() + Environment.NewLine);
            Dump.WriteLine("    Memory Details "+Environment.NewLine+Environment.NewLine);
            for (int i = 0; i < 3267; i++)
            {

                Dump.WriteLine( Convert.ToInt16(i).ToString() + " :" + m_ScreenMemory[i].ToString());
            }
            Dump.WriteLine("DONE " + DateTime.Now);
            Dump.Close();
            Dump.Dispose();
        }
    }


    public void Interpret_POK(ushort Address, byte Value)
    {
        ushort MemLoc;
        try
        {
            MemLoc = (ushort)(Address - m_ScreenMemoryLocation);
        }
        catch (Exception)
        {
            return;
        }
        if (MemLoc < 0 || MemLoc > 3266)
            return;
        m_ScreenMemory[MemLoc] = Value;
        Refresh();
    }

    private void screen_update(object sender, PaintEventArgs e)
    {
        SolidBrush Bgcolor = null;
        SolidBrush Fgcolor = null;

        Bitmap bmp = new Bitmap(640, 480);
        pictureBox1.InitialImage = bmp;
        pictureBox1.Image = bmp;
        Graphics bmp_graphic = Graphics.FromImage(bmp);
        Font writing = new Font("Courier New", 10f, FontStyle.Bold);
        int i;                                                               float xloc=0,yloc=0;

        for (i = 0; i < 3267; i += 2)
        {
            Bgcolor = new SolidBrush(Color.FromArgb(Convert.ToInt32(BARGB[i])));
            Fgcolor = new SolidBrush(Color.FromArgb(Convert.ToInt32(FARGB[i])));
            bmp_graphic.FillRectangle(Bgcolor, xloc, yloc, 20, 25);
            bmp_graphic.DrawString(m_ScreenMemory[i].ToString(), writing, Fgcolor, xloc,yloc);
            xloc += 6;
            if ((xloc % 640) == 0 && xloc != 0) {
                xloc = 0;
                yloc += 11;
            }

            e.Graphics.DrawImage(bmp, 0, 0);
            bmp.Save("test.bmp");  //Debugging purpose
            bmp.Dispose();
            bmp_graphic.Dispose();
        }



    }
}
     }

我不太明白为什么它不起作用。它显示一个白色屏幕,然后在几秒钟内屏幕上出现一个十字标记。显示代码在 screen_update() 函数中。此外,它保存的 test.bmp 始终是黑色的,无论我如何更改 rgb,我都不明白为什么不写入图形。

Himanshu Goel

4

1 回答 1

0

我看到的几个问题:

  • 您正在处理Bitmap循环的内部。
  • 将位图设置为图片框可能会导致问题,因为您要立即处理它。为什么在表格上绘图时还要设置图片框?
  • 你所有的颜色都是透明的。Color.FromARGB期望较高的位是颜色的 alpha 值,并且在您的代码中指定不透明度为 0 的颜色。尝试 0xFF000000 和 0xFFFFFFFF。
于 2012-08-30T20:39:42.093 回答