2012-08-30 90 views
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戈埃爾

回答

0

幾個問題我看到:

  • 您要處理的Bitmap環路內。
  • 將位圖設置爲圖片框可能會導致問題,因爲您立即處理它。無論如何,當你繪製表單時,爲什麼還要設置圖片框?
  • 所有的顏色都是透明的。 Color.FromARGB期望較高的比特是顏色的alpha值,並且在您的代碼中,您將指定具有0不透明度的顏色。嘗試0xFF000000和0xFFFFFFFF。
+0

對不起,但它沒有幫助,我現在只是馬上得到十字架 – hgoel0974