コード例 #1
0
ファイル: CGAConsole.cs プロジェクト: derplayer/x8086Sharp
        public CGAConsole(X8086 cpu) : base(cpu)
        {
            InitiAdapter();
            AutoSize();

            Console.TreatControlCAsInput = true;
            Console.OutputEncoding       = new System.Text.UTF8Encoding();
            Console.Clear();

            i2a = new Image2Ascii()
            {
                Charset       = Image2Ascii.Charsets.Standard,
                ColorMode     = Image2Ascii.ColorModes.Color,
                GrayScaleMode = Image2Ascii.GrayscaleModes.Average,
                ScanMode      = Image2Ascii.ScanModes.Fast
            };

            System.Threading.Tasks.Task.Run(() =>
            {
                int x      = 0;
                int y      = 0;
                int width  = 0;
                int height = 0;
                do
                {
                    Thread.Sleep(1000 / frameRate);

                    try
                    {
                        if (MainMode == MainModes.Graphics)
                        {
                            i2a.ProcessImage(false);

                            width  = Console.WindowWidth;
                            height = Console.WindowHeight;
                            for (y = 0; y < height; y++)
                            {
                                for (x = 0; x < width; x++)
                                {
                                    //ConsoleCrayon.WriteFast(i2a.Canvas(x)[y].Character,
                                    //Image2Ascii.ToConsoleColor(i2a.Canvas(x)[y].Color),
                                    //ConsoleColor.Black,
                                    ConsoleCrayon.WriteFast(Char.ToString(i2a.Canvas[x][y].Character), Image2Ascii.ToConsoleColor(i2a.Canvas[x][y].Color), ConsoleColor.Black,
                                                            x, y);
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                } while (!base.cancelAllThreads);
            });
        }
コード例 #2
0
ファイル: CGAConsole.cs プロジェクト: derplayer/x8086Sharp
        protected override void InitVideoMemory(bool clearScreen)
        {
            base.InitVideoMemory(clearScreen);

            Console.Title = "x8086SharpEmuConsole - " + VideoMode.ToString();

            if (MainMode == MainModes.Graphics)
            {
                ResetI2A();
            }

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
            case PlatformID.Win32S:
            case PlatformID.Win32Windows:
            case PlatformID.WinCE:
                break;

            default:
                if (mVideoMode != 0xFF && (Console.WindowWidth != mTextResolutionX || Console.WindowHeight != mTextResolutionY))
                {
                    ConsoleCrayon.ResetColor();
                    Console.Clear();
                    ConsoleCrayon.WriteFast("Unsupported Console Window Size", ConsoleColor.White, ConsoleColor.Red, 0, 0);
                    ConsoleCrayon.ResetColor();
                    Console.WriteLine();
                    Console.WriteLine("The window console cannot be resized on this platform, which will case the text to be rendered incorrectly");
                    Console.WriteLine();
                    Console.WriteLine("Expected Resolution for Video Mode {mVideoMode:X2}: {mTextResolution.Width}x{mTextResolution.Height}");
                    Console.WriteLine("Current console window resolution:     {Console.WindowWidth}x{Console.WindowHeight}");
                    Console.WriteLine();
                    Console.WriteLine("Manually resize the window to the appropriate resolution or press any key to continue");
                    do
                    {
                        ConsoleCrayon.WriteFast("New resolution: {Console.WindowWidth}x{Console.WindowHeight}", ConsoleColor.White, ConsoleColor.DarkRed, 0, 10);
                        Thread.Sleep(200);
                        if (Console.WindowWidth == mTextResolutionX && Console.WindowHeight == mTextResolutionY)
                        {
                            break;
                        }
                    } while (!Console.KeyAvailable);
                    ConsoleCrayon.ResetColor();
                    Console.Clear();
                }
                break;
            }
        }
コード例 #3
0
ファイル: ConsoleCrayon.cs プロジェクト: derplayer/x8086Sharp
        public static void DrawLine(char c, int fromCol, int fromRow, int toCol, int toRow, ConsoleColor foreColor, ConsoleColor backColor)
        {
            double angle  = Atan2(toCol - fromCol, toRow - fromRow);
            int    length = (int)(Math.Sqrt(Math.Pow((toCol - fromCol), 2) + Math.Pow((toRow - fromRow), 2)));
            int    px     = 0;
            int    py     = 0;
            double ca     = Math.Cos(angle * toRadians);
            double sa     = Math.Sin(angle * toRadians);

            for (int radius = 0; radius <= length; radius++)
            {
                px = (int)(radius * ca + fromCol);
                py = (int)(radius * sa + fromRow);

                ConsoleCrayon.WriteFast(c.ToString(), foreColor, backColor, px, py);
            }
        }
コード例 #4
0
ファイル: CGAConsole.cs プロジェクト: derplayer/x8086Sharp
        private void RenderText()
        {
            byte b0 = 0;
            byte b1 = 0;

            int col    = 0;
            int row    = 0;
            int bufIdx = 0;

            bool cv = false;

            stringBuilder.Clear(); //string text = "";
            byte b1c = CPU.Memory[mStartTextVideoAddress + 1];
            int  c   = 0;
            int  r   = 0;

            Console.CursorVisible = false;

            // The "-4" is to prevent the code from printing the last character and avoid scrolling.
            // Unfortunately, this causes the last char to not be printed
            for (int address = mStartTextVideoAddress; address <= mEndTextVideoAddress + buffer.Length - 4; address += 2)
            {
                b0 = CPU.Memory[address];
                b1 = CPU.Memory[address + 1];

                if ((blinkCounter < BlinkRate) && BlinkCharOn && (b1 & 0x80) != 0)
                {
                    b0 = (byte)0;
                }

                if (b1c != b1)
                {
                    ConsoleCrayon.WriteFast(stringBuilder.ToString() /*text*/, (ConsoleColor)b1c.LowNib(), (ConsoleColor)b1c.HighNib(), c, r);
                    stringBuilder.Clear(); //text = "";
                    b1c = b1;
                    c   = col;
                    r   = row;
                }
                stringBuilder.Append(chars[b0]); //text += chars[b0].ToString();

                if (CursorVisible && row == CursorRow && col == CursorCol)
                {
                    cv = blinkCounter < BlinkRate;

                    if (blinkCounter >= 2 * BlinkRate)
                    {
                        blinkCounter = 0;
                    }
                    else
                    {
                        blinkCounter++;
                    }
                }

                col++;
                if (col == mTextResolutionX)
                {
                    col = 0;
                    row++;
                    if (row == mTextResolutionY)
                    {
                        break;
                    }
                }

                bufIdx += 2;
            }

            if (stringBuilder.Length > 0 /*!string.IsNullOrEmpty(text)*/)
            {
                ConsoleCrayon.WriteFast(stringBuilder.ToString() /*text*/, (ConsoleColor)b1c.LowNib(), (ConsoleColor)b1c.HighNib(), c, r);
            }

            if (cv)
            {
                Console.SetCursorPosition(CursorCol, CursorRow);
                Console.CursorVisible = true;
            }
        }