Beispiel #1
0
        private void UpdateDisplay() // redraws the display to the screen, cannot be in GraphicsHandler due to drawing to the forms elements
        {
            // start timer to see how long frame takes
            Stopwatch frameDrawTime = Stopwatch.StartNew();

            // draws the black borders around the main window
            GraphicsHandler.DrawBorder();

            int[] vram = GLOBAL.VRAM.GetContents(); // gets the characters on screen

            // draw each character to the screen
            for (int i = 0; i < vram.Length; i++)
            {
                GraphicsHandler.DrawChar(i % 40, i / 40, vram[i]); // i % 40, i / 40 turns the 1D vram array to 2D co-ordinates for the GraphicsHandler object
            }

            // gets window size properties
            int[] dimensions = GraphicsHandler.GetDimensions();
            int   width      = dimensions[0];
            int   height     = dimensions[1];

            int borderSize   = GLOBAL.AppConfig.border_size;
            int displayScale = GLOBAL.AppConfig.display_scale;

            // upscales the output by displayScale with nearest neighbour (for no blurring pixels)
            displayPictureBox.Image = GraphicsHandler.DrawCursor(GraphicsHandler.GetDisplay(), GLOBAL.cursorPos[0], GLOBAL.cursorPos[1], cursorVisible);
            Graphics graphics = Graphics.FromImage(zoomedDisplay);

            graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
            // draw the upscaled image to the screen
            graphics.DrawImage(displayPictureBox.Image, 0, 0, (width + (borderSize * 2)) * displayScale, (height + (borderSize * 2)) * displayScale);
            displayPictureBox.Image = zoomedDisplay;
            // update screen and clear memory
            displayPictureBox.Refresh();
            graphics.Dispose();

            // store how long it took to draw that drame
            frameDrawTime.Stop();
            lastFrameTime = frameDrawTime.Elapsed.TotalMilliseconds;
        }
Beispiel #2
0
        private void SetupEnviroment() // prepare the application before main execution
        {
            // reads user config file
            FileHandler.ReadAppConfig();

            // gets window size properties
            int[] dimensions   = GraphicsHandler.GetDimensions();
            int   width        = dimensions[0];
            int   height       = dimensions[1];
            int   borderSize   = GLOBAL.AppConfig.border_size;
            int   displayScale = GLOBAL.AppConfig.display_scale;

            // gets the user's display resolution
            int windowWidth  = Screen.FromControl(this).Bounds.Width;
            int windowHeight = Screen.FromControl(this).Bounds.Height;

            // gets the wanted size for the window
            int newWidth  = (width + (borderSize * 2)) * displayScale;
            int newHeight = (height + (borderSize * 2)) * displayScale;

            if (newWidth > windowWidth || newHeight > windowHeight - 50) // if resulting window would be larger than resolution, -50 height accounting for the taskbar
            {
                // reset the scale to the default value
                ErrorHandler.ShowSystemError(6);
                GLOBAL.AppConfig.display_scale = 3;

                // calculate a new size
                displayScale = GLOBAL.AppConfig.display_scale;
                newWidth     = (width + (borderSize * 2)) * displayScale;
                newHeight    = (height + (borderSize * 2)) * displayScale;
            }

            // changes GUI elements depending on the display scale value and border width
            displayPictureBox.Size = new Size(newWidth, newHeight);  // the area showing the main program
            this.Size     = new Size(newWidth + 15, newHeight + 88); // the window size. extra size accounts for window border and buttons
            zoomedDisplay = new Bitmap(newWidth, newHeight);         // final image the user sees

            // changes button location based on display scale and border width
            int newY           = newHeight;    // right below main program area
            int newButtonWidth = newWidth / 4; // 4 buttons

            // location
            toggleKeyboardButton.Location = new Point(newButtonWidth * 0, newY);
            toggleDebugButton.Location    = new Point(newButtonWidth * 1, newY);
            LoadProgramButton.Location    = new Point(newButtonWidth * 2, newY);
            SaveProgramButton.Location    = new Point(newButtonWidth * 3, newY);
            // dimensions
            toggleKeyboardButton.Size = new Size(newButtonWidth, 50);
            toggleDebugButton.Size    = new Size(newButtonWidth, 50);
            LoadProgramButton.Size    = new Size(newButtonWidth, 50);
            SaveProgramButton.Size    = new Size(newButtonWidth, 50);

            GLOBAL.C64_ROM.LoadCharsetData(); // loads character set
            GLOBAL.VRAM.FillContents(0x20);   // fills the vram (characters on screen) with spaces, hex 0x20

            // setup display and print the default text on boot
            displayPictureBox.Image = GraphicsHandler.GetDisplay();
            GLOBAL.C64_ROM.ShowStartupText();
            GLOBAL.cursorPos = new int[] { 0, 32 };
            PrintReady(8);
            GLOBAL.cursorPos = new int[] { 0, 48 };

            // sets up the performance monitoring object
            string currentProcessName = Process.GetCurrentProcess().ProcessName;

            cpuUsage = new PerformanceCounter("Process", "% Processor Time", currentProcessName, true);
            ramUsage = new PerformanceCounter("Process", "Private Bytes", currentProcessName, true);

            // cursor fires CursorTick_Event three times a second
            cursorTick.Interval = 333;
            cursorTick.Tick    += new EventHandler(CursorTick_Event);
            cursorTick.Enabled  = true;
        }