0

I am working on a VM and am stuck on the screen. My code

    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();
        }



    }
}
     }

I don't quite understand why it isn't working. It displays a white screen and then in a few seconds a cross mark appears on screen. The display code is in the screen_update() function. Also the test.bmp that it saves is always black, no matter how i change the rgb,I don't understand why the graphics isn't written to.

Himanshu Goel

Seki
  • 11,135
  • 7
  • 46
  • 70
hgoel0974
  • 1
  • 2

1 Answers1

0

Several problems I see:

  • You are disposing the Bitmap inside of the loop.
  • Setting the bitmap to the picture box will likely cause problems since you are disposing of it immediately. Why are you even setting the picture box when you are drawing on the form anyway?
  • All of your colors are transparent. Color.FromARGB expects the higher bits to be the alpha value of the color and in your code you are specifying colors with 0 opacity. Try 0xFF000000 and 0xFFFFFFFF.
SomeWritesReserved
  • 1,075
  • 7
  • 17