コード例 #1
0
ファイル: dx8.cs プロジェクト: betajaen/dx8
        private void OnGUI()
        {
            if (GUI.Button(new Rect(0, 0, 100, 25), "Reload"))
            {
                ReloadNeeded = true;
            }

            if (IsRunning && GUI.Button(new Rect(100, 0, 100, 25), "Pause"))
            {
                IsRunning = false;
            }

            if (!IsRunning && GUI.Button(new Rect(100, 0, 100, 25), "Resume"))
            {
                IsRunning = true;
            }

            if (!IsRunning && GUI.Button(new Rect(200, 0, 100, 25), "Step"))
            {
                RunOnce(-1.0f);

                Debug.LogFormat(
                    "A={0:X2} X={1:X2} Y={2:X2} Z={3:X2} W={4:X2} Pc={5:X4}, St={6:X2}, Fl={7:X2}, Steps={8}, Opcode={9:X2}, Operand={10:X4} GpuTimer={11}",
                    Library.GetValue(Api.A),
                    Library.GetValue(Api.X),
                    Library.GetValue(Api.Y),
                    Library.GetValue(Api.Z),
                    Library.GetValue(Api.W),
                    Library.GetValue(Api.Pc),
                    Library.GetValue(Api.Stack),
                    Library.GetValue(Api.Flags),
                    LastSteps,
                    Library.GetValue(Api.LastOpcode),
                    Library.GetValue(Api.LastOperand),
                    Library.GetValue(Api.GpuTimer)
                    );
            }


            if (!IsRunning && GUI.RepeatButton(new Rect(200, 25, 100, 25), "FWD"))
            {
                RunOnce(-1.0f);

                Debug.LogFormat(
                    "A={0:X2} X={1:X2} Y={2:X2} Z={3:X2} W={4:X2} Pc={5:X4}, St={6:X2}, Fl={7:X2}, Steps={8}, Opcode={9:X2}, Operand={10:X4} GpuTimer={11}",
                    Library.GetValue(Api.A),
                    Library.GetValue(Api.X),
                    Library.GetValue(Api.Y),
                    Library.GetValue(Api.Z),
                    Library.GetValue(Api.W),
                    Library.GetValue(Api.Pc),
                    Library.GetValue(Api.Stack),
                    Library.GetValue(Api.Flags),
                    LastSteps,
                    Library.GetValue(Api.LastOpcode),
                    Library.GetValue(Api.LastOperand),
                    Library.GetValue(Api.GpuTimer)
                    );
            }

            if (!IsRunning && GUI.Button(new Rect(300, 25, 100, 25), "Frame"))
            {
                RunOnce(1.0f / 60.0f);
            }

            if (GUI.Button(new Rect(300, 0, 100, 25), "Turn On"))
            {
                TurnOn();
            }

            if (GUI.Button(new Rect(400, 0, 100, 25), "Save Crt"))
            {
                System.IO.File.WriteAllBytes("crt.png", Crt.EncodeToPNG());
            }

            if (GUI.Button(new Rect(500, 0, 100, 25), "FD Insert"))
            {
                LoadFloppy();
                Library.Call(Api.InsertDisk, 0);
            }

            if (GUI.Button(new Rect(600, 0, 100, 25), "FD Remove"))
            {
                Library.Call(Api.RemoveDisk, 0);
            }

            if (Library.GetValue(Api.CpuHalt) == 1 && GUI.Button(new Rect(700, 0, 100, 25), "Resume"))
            {
                Library.SetValue(Api.CpuHalt, 0);
            }

            if (Library.GetValue(Api.CpuHalt) == 0 && GUI.Button(new Rect(700, 0, 100, 25), "Halt"))
            {
                Library.SetValue(Api.CpuHalt, 1);
            }

            InspectShared = GUI.Toggle(new Rect(0, 125, 100, 25), InspectShared, string.Format("Inspect ${0:X4}", InspectAddress));

            if (InspectShared)
            {
                GUI.changed = false;
                string strV = GUI.TextField(new Rect(0, 150, 100, 25), String.Format("{0:X4}", InspectAddress));
                if (GUI.changed)
                {
                    int newAddress = 0;
                    if (int.TryParse(strV, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out newAddress))
                    {
                        InspectAddress = newAddress;
                    }
                }
                if (GUI.Button(new Rect(100, 150, 25, 25), "<"))
                {
                    InspectAddress -= 16;
                }
                if (GUI.Button(new Rect(125, 150, 25, 25), ">"))
                {
                    InspectAddress += 16;
                }
                if (GUI.Button(new Rect(100, 175, 25, 25), "<<"))
                {
                    InspectAddress -= 40;
                }
                if (GUI.Button(new Rect(125, 175, 25, 25), ">>"))
                {
                    InspectAddress += 40;
                }
                if (GUI.Button(new Rect(150, 150, 50, 25), "0000"))
                {
                    InspectAddress = 0x0000;
                }
                if (GUI.Button(new Rect(200, 150, 50, 25), "0800"))
                {
                    InspectAddress = 0x0800;
                }
                if (GUI.Button(new Rect(150, 175, 50, 25), "8000"))
                {
                    InspectAddress = 0x8000;
                }
                if (GUI.Button(new Rect(200, 175, 50, 25), "7800"))
                {
                    InspectAddress = 0x7800;
                }
                if (GUI.Button(new Rect(150, 200, 50, 25), "+"))
                {
                    InspectAddress = 0x7800 + 0x300;
                }
            }

            GUI.Label(new Rect(0, 50, Screen.width, 90), String.Format(
                          "A={0:X2} X={1:X2} Y={2:X2} Z={3:X2} W={4:X2} Pc={5:X4}, St={6:X2}, Fl={7:X2}, Steps={8}, Opcode={9:X2}, Operand={10:X4} GpuTimer={11} Halt={12}",
                          Library.GetValue(Api.A),
                          Library.GetValue(Api.X),
                          Library.GetValue(Api.Y),
                          Library.GetValue(Api.Z),
                          Library.GetValue(Api.W),
                          Library.GetValue(Api.Pc),
                          Library.GetValue(Api.Stack),
                          Library.GetValue(Api.Flags),
                          LastSteps,
                          Library.GetValue(Api.LastOpcode),
                          Library.GetValue(Api.LastOperand),
                          Library.GetValue(Api.GpuTimer),
                          Library.GetValue(Api.CpuHalt)
                          ));

            if (InspectShared)
            {
                for (int i = 0; i < 16; i++)
                {
                    //int val = Api.
                    int val = Library.GetRam(Api.SharedAddr, i + InspectAddress);
                    GUI.Label(new Rect(i * 25, 75, 25, 25), String.Format("{0:X2}", val));
                    if (val > ' ' && val < 127)
                    {
                        GUI.Label(new Rect(i * 25, 100, 25, 25), String.Format("{0}", (char)val));
                    }
                }
            }
            int s  = 2;
            int sw = 320 * s;
            int sh = 256 * s;

            GUI.DrawTexture(new Rect(Screen.width / 2 - sw / 2, Screen.height / 2 + sh / 2, sw, -sh), Crt);
        }