From e424f16033a0a09a5abf8a24e03bf66cd9ad76bd Mon Sep 17 00:00:00 2001 From: Alexandre Rocha Lima e Marcondes Date: Wed, 20 Feb 2019 14:00:51 +0100 Subject: [PATCH] Removing Console.WriteLine and using Debug.Print --- Chip8.Sharp/Chip8.Core/CPU.cs | 23 ++-- Chip8.Sharp/Chip8.SDL/Program.cs | 121 +++++++++++---------- Chip8.Sharp/Chip8.SDL/SDLDriver.cs | 17 +-- Chip8.Sharp/Chip8.SDL/Texture.cs | 21 ++-- Chip8.Sharp/Chip8.WPF/MainWindow.xaml.cs | 98 ++++++++--------- Chip8.Sharp/Chip8.WindowsForms/MainForm.cs | 98 ++++++++--------- 6 files changed, 191 insertions(+), 187 deletions(-) diff --git a/Chip8.Sharp/Chip8.Core/CPU.cs b/Chip8.Sharp/Chip8.Core/CPU.cs index 9b52254..1f14d29 100644 --- a/Chip8.Sharp/Chip8.Core/CPU.cs +++ b/Chip8.Sharp/Chip8.Core/CPU.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; @@ -138,7 +139,7 @@ public void LoadGame(string fileName) { var buffer = new byte[MAX_BUFFER_SIZE]; var bufferSize = stream.Read(this.Memory, 0x200, MAX_BUFFER_SIZE); - Console.WriteLine($"Loaded {bufferSize.ToString(NumberFormatInfo.CurrentInfo)} bytes"); + Debug.Print($"Loaded {bufferSize.ToString(NumberFormatInfo.CurrentInfo)} bytes"); } } @@ -188,7 +189,7 @@ public void EmulateCycle() if (this.SP == 0) { var message = "Illegal return operation, stack is empty."; - Console.WriteLine(message); + Debug.Print(message); throw new StackOverflowException(message); } @@ -206,7 +207,7 @@ public void EmulateCycle() default: { var message = $"Illegal call to RCA 1802 program: 0x{this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}"; - Console.WriteLine(message); + Debug.Print(message); throw new InvalidOperationException(message); } } @@ -221,7 +222,7 @@ public void EmulateCycle() if (op.NNN < 0x200) { var message = $"Illegal jump target: 0x{this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}"; - Console.WriteLine(message); + Debug.Print(message); throw new InvalidOperationException(message); } @@ -233,7 +234,7 @@ public void EmulateCycle() if (this.SP > 0xF) { var message = "Illegal call operation, stack is full."; - Console.WriteLine(message); + Debug.Print(message); throw new StackOverflowException(message); } @@ -608,7 +609,7 @@ public void EmulateCycle() break; default: - Console.WriteLine($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}"); + Debug.Print($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}"); break; } break; @@ -666,14 +667,14 @@ public void EmulateCycle() if (dest < 0x200) { var message = $"Illegal jump target: 0x{dest.ToString("X4", NumberFormatInfo.CurrentInfo)} => 0x{this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)} + this.V[0] (0x{this.V[0].ToString("X2", NumberFormatInfo.CurrentInfo)})"; - Console.WriteLine(message); + Debug.Print(message); throw new InvalidOperationException(message); } if (dest > 0xFFF) { var message = $"Illegal jump target: 0x{dest.ToString("X4", NumberFormatInfo.CurrentInfo)} => 0x{this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)} + this.V[0] (0x{this.V[0].ToString("X2", NumberFormatInfo.CurrentInfo)})"; - Console.WriteLine(message); + Debug.Print(message); throw new InvalidOperationException(message); } @@ -803,7 +804,7 @@ public void EmulateCycle() break; default: - Console.WriteLine($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}"); + Debug.Print($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}"); break; } break; @@ -1023,13 +1024,13 @@ public void EmulateCycle() break; default: - Console.WriteLine($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}"); + Debug.Print($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}"); break; } break; default: - Console.WriteLine($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}"); + Debug.Print($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}"); break; } diff --git a/Chip8.Sharp/Chip8.SDL/Program.cs b/Chip8.Sharp/Chip8.SDL/Program.cs index 478ac62..c8d870c 100644 --- a/Chip8.Sharp/Chip8.SDL/Program.cs +++ b/Chip8.Sharp/Chip8.SDL/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; @@ -78,27 +79,27 @@ static int Main(string[] args) { if (!driver.Init(WIDTH, HEIGHT)) { - Console.WriteLine("Failed to initialize!"); + Debug.Print("Failed to initialize!"); return -1; } // Setup the graphics (window size, display mode, etc) if (!driver.SetupGraphics($"assets{Path.DirectorySeparatorChar.ToString(CultureInfo.CurrentCulture)}CHIP-8.logo.bmp")) { - Console.WriteLine("Failed to setup graphics!"); + Debug.Print("Failed to setup graphics!"); return -2; } // Setup the input system (register input callbacks) if (!driver.SetupInput()) { - Console.WriteLine("Failed to setup input!"); + Debug.Print("Failed to setup input!"); return -3; } if (!LoadMedia()) { - Console.WriteLine("Failed to load media!"); + Debug.Print("Failed to load media!"); return -4; } @@ -110,7 +111,7 @@ static int Main(string[] args) //Set default current surface currentTexture = textures[(int)KeyPressSurface.Default]; - Console.WriteLine("Loaded..."); + Debug.Print("Loaded..."); // Initialize the CHIP-8 system (Clear the memory, registers and screen) myChip8 = new CPU(); @@ -150,7 +151,7 @@ static int Main(string[] args) switch (evt.type) { case SDL.SDL_EventType.SDL_QUIT: - Console.WriteLine("Quitting..."); + Debug.Print("Quitting..."); quit = true; break; @@ -159,101 +160,101 @@ static int Main(string[] args) switch (evt.key.keysym.sym) { case SDL.SDL_Keycode.SDLK_ESCAPE: - Console.WriteLine("ESCAPE"); - Console.WriteLine("Quitting..."); + Debug.Print("ESCAPE"); + Debug.Print("Quitting..."); quit = true; break; case SDL.SDL_Keycode.SDLK_UP: currentTexture = textures[(int)KeyPressSurface.Up]; - Console.WriteLine("UP"); + Debug.Print("UP"); break; case SDL.SDL_Keycode.SDLK_DOWN: currentTexture = textures[(int)KeyPressSurface.Down]; - Console.WriteLine("DOWN"); + Debug.Print("DOWN"); break; case SDL.SDL_Keycode.SDLK_LEFT: currentTexture = textures[(int)KeyPressSurface.Left]; - Console.WriteLine("LEFT"); + Debug.Print("LEFT"); break; case SDL.SDL_Keycode.SDLK_RIGHT: currentTexture = textures[(int)KeyPressSurface.Right]; - Console.WriteLine("RIGHT"); + Debug.Print("RIGHT"); break; case SDL.SDL_Keycode.SDLK_1: keys[0x0] = 1; - Console.WriteLine("1"); + Debug.Print("1"); break; case SDL.SDL_Keycode.SDLK_2: keys[0x1] = 1; - Console.WriteLine("2"); + Debug.Print("2"); break; case SDL.SDL_Keycode.SDLK_3: keys[0x2] = 1; - Console.WriteLine("3"); + Debug.Print("3"); break; case SDL.SDL_Keycode.SDLK_4: keys[0x3] = 1; - Console.WriteLine("4"); + Debug.Print("4"); break; case SDL.SDL_Keycode.SDLK_q: keys[0x4] = 1; - Console.WriteLine("q"); + Debug.Print("q"); break; case SDL.SDL_Keycode.SDLK_w: keys[0x5] = 1; - Console.WriteLine("w"); + Debug.Print("w"); break; case SDL.SDL_Keycode.SDLK_e: keys[0x6] = 1; - Console.WriteLine("e"); + Debug.Print("e"); break; case SDL.SDL_Keycode.SDLK_r: keys[0x7] = 1; - Console.WriteLine("r"); + Debug.Print("r"); break; case SDL.SDL_Keycode.SDLK_a: keys[0x8] = 1; - Console.WriteLine("a"); + Debug.Print("a"); break; case SDL.SDL_Keycode.SDLK_s: keys[0x9] = 1; - Console.WriteLine("s"); + Debug.Print("s"); break; case SDL.SDL_Keycode.SDLK_d: keys[0xA] = 1; - Console.WriteLine("d"); + Debug.Print("d"); break; case SDL.SDL_Keycode.SDLK_f: keys[0xA] = 1; - Console.WriteLine("f"); + Debug.Print("f"); break; case SDL.SDL_Keycode.SDLK_z: keys[0xB] = 1; - Console.WriteLine("z"); + Debug.Print("z"); break; case SDL.SDL_Keycode.SDLK_y: keys[0xB] = 1; - Console.WriteLine("y"); + Debug.Print("y"); break; case SDL.SDL_Keycode.SDLK_x: keys[0xC] = 1; - Console.WriteLine("x"); + Debug.Print("x"); break; case SDL.SDL_Keycode.SDLK_c: keys[0xD] = 1; - Console.WriteLine("c"); + Debug.Print("c"); break; case SDL.SDL_Keycode.SDLK_v: keys[0xE] = 1; - Console.WriteLine("v"); + Debug.Print("v"); break; case SDL.SDL_Keycode.SDLK_BACKSPACE: @@ -262,11 +263,11 @@ static int Main(string[] args) if (debugPixels) { - Console.WriteLine("Entering debug pixel mode"); + Debug.Print("Entering debug pixel mode"); } else { - Console.WriteLine("Leaving debug pixel mode"); + Debug.Print("Leaving debug pixel mode"); } break; case SDL.SDL_Keycode.SDLK_RETURN: @@ -275,30 +276,30 @@ static int Main(string[] args) if (debugKeys) { - Console.WriteLine("Entering debug keys mode"); + Debug.Print("Entering debug keys mode"); } else { - Console.WriteLine("Leaving debug keys mode"); + Debug.Print("Leaving debug keys mode"); } break; case SDL.SDL_Keycode.SDLK_PLUS: zoom += 0.5f; - Console.WriteLine($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); + Debug.Print($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); break; case SDL.SDL_Keycode.SDLK_MINUS: zoom -= 0.5f; - Console.WriteLine($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); + Debug.Print($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); break; case SDL.SDL_Keycode.SDLK_0: zoom = 1.0f; - Console.WriteLine($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); + Debug.Print($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); break; default: currentTexture = textures[(int)KeyPressSurface.Default]; - Console.WriteLine("Default Key Press"); + Debug.Print("Default Key Press"); break; } break; @@ -325,53 +326,53 @@ static int Main(string[] args) case SDL.SDL_Keycode.SDLK_1: keys[0x0] = 0; - Console.WriteLine("1"); + Debug.Print("1"); break; case SDL.SDL_Keycode.SDLK_2: keys[0x1] = 0; - Console.WriteLine("2"); + Debug.Print("2"); break; case SDL.SDL_Keycode.SDLK_3: keys[0x2] = 0; - Console.WriteLine("3"); + Debug.Print("3"); break; case SDL.SDL_Keycode.SDLK_4: keys[0x3] = 0; - Console.WriteLine("4"); + Debug.Print("4"); break; case SDL.SDL_Keycode.SDLK_q: keys[0x4] = 0; - Console.WriteLine("q"); + Debug.Print("q"); break; case SDL.SDL_Keycode.SDLK_w: keys[0x5] = 0; - Console.WriteLine("w"); + Debug.Print("w"); break; case SDL.SDL_Keycode.SDLK_e: keys[0x6] = 0; - Console.WriteLine("e"); + Debug.Print("e"); break; case SDL.SDL_Keycode.SDLK_r: keys[0x7] = 0; - Console.WriteLine("r"); + Debug.Print("r"); break; case SDL.SDL_Keycode.SDLK_a: keys[0x8] = 0; - Console.WriteLine("a"); + Debug.Print("a"); break; case SDL.SDL_Keycode.SDLK_s: keys[0x9] = 0; - Console.WriteLine("s"); + Debug.Print("s"); break; case SDL.SDL_Keycode.SDLK_d: keys[0xA] = 0; - Console.WriteLine("d"); + Debug.Print("d"); break; case SDL.SDL_Keycode.SDLK_f: keys[0xA] = 0; - Console.WriteLine("f"); + Debug.Print("f"); break; case SDL.SDL_Keycode.SDLK_z: @@ -402,7 +403,7 @@ static int Main(string[] args) { if (!SDLDriver.Render(currentTexture)) { - Console.WriteLine("Failed to render texture!"); + Debug.Print("Failed to render texture!"); } } @@ -440,7 +441,7 @@ static int Main(string[] args) //Render text if (!fpsTextTexture.LoadFromRenderedText(timerText, color)) { - Console.WriteLine("Unable to render FPS texture!"); + Debug.Print("Unable to render FPS texture!"); } //Clear screen @@ -453,7 +454,7 @@ static int Main(string[] args) //Update screen if (!driver.Present()) { - Console.WriteLine("Failed to present render!"); + Debug.Print("Failed to present render!"); } ++countedFrames; @@ -587,7 +588,7 @@ static bool LoadMedia() surface = SDLDriver.LoadSurface("assets/press.bmp"); if (surface == IntPtr.Zero) { - Console.WriteLine("Failed to load default image!"); + Debug.Print("Failed to load default image!"); success = false; } else @@ -603,7 +604,7 @@ static bool LoadMedia() surface = SDLDriver.LoadSurface("assets/up.bmp"); if (surface == IntPtr.Zero) { - Console.WriteLine("Failed to load up image!"); + Debug.Print("Failed to load up image!"); success = false; } else @@ -619,7 +620,7 @@ static bool LoadMedia() surface = SDLDriver.LoadSurface("assets/down.bmp"); if (surface == IntPtr.Zero) { - Console.WriteLine("Failed to load down image!"); + Debug.Print("Failed to load down image!"); success = false; } else @@ -636,7 +637,7 @@ static bool LoadMedia() surface = SDLDriver.LoadSurface("assets/left.bmp"); if (surface == IntPtr.Zero) { - Console.WriteLine("Failed to load left image!"); + Debug.Print("Failed to load left image!"); success = false; } else @@ -653,7 +654,7 @@ static bool LoadMedia() surface = SDLDriver.LoadSurface("assets/right.bmp"); if (surface == IntPtr.Zero) { - Console.WriteLine("Failed to load right image!"); + Debug.Print("Failed to load right image!"); success = false; } else @@ -672,7 +673,7 @@ static bool LoadMedia() pixelDebugTexture = new Texture(driver); if (!pixelDebugTexture.CreateBlank(WIDTH, HEIGHT, SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET)) { - Console.WriteLine("Failed to create target debug texture!"); + Debug.Print("Failed to create target debug texture!"); success = false; } @@ -683,7 +684,7 @@ static bool LoadMedia() pixelTexture = new Texture(driver); if (!pixelTexture.CreateBlank(WIDTH, HEIGHT, SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET)) { - Console.WriteLine("Failed to create target texture!"); + Debug.Print("Failed to create target texture!"); success = false; } @@ -697,7 +698,7 @@ private static void OnStartSound(int channel, int frequency, int duration) private static void OnEndSound(int channel) { - Console.WriteLine("BEEP!"); + Debug.Print("BEEP!"); } #region IDisposable Support diff --git a/Chip8.Sharp/Chip8.SDL/SDLDriver.cs b/Chip8.Sharp/Chip8.SDL/SDLDriver.cs index d2a251a..07539b3 100644 --- a/Chip8.Sharp/Chip8.SDL/SDLDriver.cs +++ b/Chip8.Sharp/Chip8.SDL/SDLDriver.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using SDL2; @@ -30,7 +31,7 @@ public bool Init(int width, int height) //Initialize SDL if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) < 0) { - Console.WriteLine($"SDL could not initialize! SDL_Error: {SDL.SDL_GetError()}"); + Debug.Print($"SDL could not initialize! SDL_Error: {SDL.SDL_GetError()}"); result = false; } @@ -39,7 +40,7 @@ public bool Init(int width, int height) //Set texture filtering to linear if (SDL.SDL_SetHint(SDL.SDL_HINT_RENDER_SCALE_QUALITY, "1") == SDL.SDL_bool.SDL_FALSE) { - Console.WriteLine("Warning: Linear texture filtering not enabled!"); + Debug.Print("Warning: Linear texture filtering not enabled!"); } //Create window @@ -47,7 +48,7 @@ public bool Init(int width, int height) if (windowPtr == IntPtr.Zero) { - Console.WriteLine($"Window could not be created! SDL_Error: {SDL.SDL_GetError()}"); + Debug.Print($"Window could not be created! SDL_Error: {SDL.SDL_GetError()}"); result = false; } else @@ -57,7 +58,7 @@ public bool Init(int width, int height) if (rendererPtr == IntPtr.Zero) { - Console.WriteLine($"Renderer could not be created! SDL_Error: {SDL.SDL_GetError()}"); + Debug.Print($"Renderer could not be created! SDL_Error: {SDL.SDL_GetError()}"); result = false; } else @@ -74,14 +75,14 @@ public bool Init(int width, int height) //Initialize PNG loading if ((((SDL_image.IMG_InitFlags)SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_PNG)) & SDL_image.IMG_InitFlags.IMG_INIT_PNG) == 0) { - Console.WriteLine($"SDL_image could not initialize! SDL_image Error: {SDL.SDL_GetError()}"); + Debug.Print($"SDL_image could not initialize! SDL_image Error: {SDL.SDL_GetError()}"); result = false; } //Initialize SDL_ttf if (SDL_ttf.TTF_Init() == -1) { - Console.WriteLine($"SDL_ttf could not initialize! SDL_ttf Error: {SDL.SDL_GetError()}"); + Debug.Print($"SDL_ttf could not initialize! SDL_ttf Error: {SDL.SDL_GetError()}"); result = false; } @@ -90,7 +91,7 @@ public bool Init(int width, int height) if (fontPtr == IntPtr.Zero) { - Console.WriteLine($"Failed to load lazy font! SDL_ttf Error: {SDL.SDL_GetError()}"); + Debug.Print($"Failed to load lazy font! SDL_ttf Error: {SDL.SDL_GetError()}"); result = false; } @@ -238,7 +239,7 @@ public static IntPtr LoadSurface(string fileName) if (loadedSurface == IntPtr.Zero) { - Console.WriteLine($"Unable to load image {fileName}! SDL Error: {SDL.SDL_GetError()}"); + Debug.Print($"Unable to load image {fileName}! SDL Error: {SDL.SDL_GetError()}"); } return loadedSurface; diff --git a/Chip8.Sharp/Chip8.SDL/Texture.cs b/Chip8.Sharp/Chip8.SDL/Texture.cs index 62b8f47..590d849 100644 --- a/Chip8.Sharp/Chip8.SDL/Texture.cs +++ b/Chip8.Sharp/Chip8.SDL/Texture.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using SDL2; @@ -55,7 +56,7 @@ public bool LoadFromSurface(IntPtr loadedSurfacePtr) if (loadedSurfacePtr == IntPtr.Zero) { - Console.WriteLine($"Unable to load surface! SDL_image Error: {SDL.SDL_GetError()}"); + Debug.Print($"Unable to load surface! SDL_image Error: {SDL.SDL_GetError()}"); } else { @@ -68,7 +69,7 @@ public bool LoadFromSurface(IntPtr loadedSurfacePtr) newTexturePtr = SDL.SDL_CreateTextureFromSurface(rendererPtr, loadedSurfacePtr); if (newTexturePtr == IntPtr.Zero) { - Console.WriteLine($"Unable to create texture from surface! SDL Error: {SDL.SDL_GetError()}"); + Debug.Print($"Unable to create texture from surface! SDL Error: {SDL.SDL_GetError()}"); } else { @@ -100,7 +101,7 @@ public bool LoadFromFile(string path) if (loadedSurfacePtr == IntPtr.Zero) { - Console.WriteLine($"Unable to load image {path}! SDL_image Error: {SDL.SDL_GetError()}"); // SDL_image.IMG_GetError() + Debug.Print($"Unable to load image {path}! SDL_image Error: {SDL.SDL_GetError()}"); // SDL_image.IMG_GetError() } else { @@ -113,7 +114,7 @@ public bool LoadFromFile(string path) newTexturePtr = SDL.SDL_CreateTextureFromSurface(rendererPtr, loadedSurfacePtr); if (newTexturePtr == IntPtr.Zero) { - Console.WriteLine($"Unable to create texture from {path}! SDL Error: {SDL.SDL_GetError()}"); + Debug.Print($"Unable to create texture from {path}! SDL Error: {SDL.SDL_GetError()}"); } else { @@ -145,7 +146,7 @@ public bool LoadFromRenderedText(string textureText, SDL.SDL_Color textColor) if (textSurfacePtr == IntPtr.Zero) { - Console.WriteLine($"Unable to render text surface! SDL_ttf Error: {SDL.SDL_GetError()}"); // SDL_ttf.TTF_GetError() + Debug.Print($"Unable to render text surface! SDL_ttf Error: {SDL.SDL_GetError()}"); // SDL_ttf.TTF_GetError() } else { @@ -155,7 +156,7 @@ public bool LoadFromRenderedText(string textureText, SDL.SDL_Color textColor) texturePtr = SDL.SDL_CreateTextureFromSurface(rendererPtr, textSurfacePtr); if (texturePtr == IntPtr.Zero) { - Console.WriteLine($"Unable to create texture from rendered text! SDL Error: {SDL.SDL_GetError()}"); + Debug.Print($"Unable to create texture from rendered text! SDL Error: {SDL.SDL_GetError()}"); } else { @@ -179,7 +180,7 @@ public bool CreateBlank(int width, int height, SDL.SDL_TextureAccess access) if (texturePtr == IntPtr.Zero) { - Console.WriteLine($"Unable to create blank texture! SDL Error: {SDL.SDL_GetError()}\n"); + Debug.Print($"Unable to create blank texture! SDL Error: {SDL.SDL_GetError()}\n"); } else { @@ -275,7 +276,7 @@ public bool Lock() //Texture is already locked if (pixelsPtr != IntPtr.Zero) { - Console.WriteLine("Texture is already locked!\n"); + Debug.Print("Texture is already locked!\n"); success = false; } //Lock texture @@ -283,7 +284,7 @@ public bool Lock() { if (SDL.SDL_LockTexture(texturePtr, IntPtr.Zero, out pixelsPtr, out pitch) != 0) { - Console.WriteLine($"Unable to lock texture! {SDL.SDL_GetError()}\n"); + Debug.Print($"Unable to lock texture! {SDL.SDL_GetError()}\n"); success = false; } else @@ -303,7 +304,7 @@ public bool Unlock() //Texture is not locked if (pixelsPtr == IntPtr.Zero) { - Console.WriteLine("Texture is not locked!\n"); + Debug.Print("Texture is not locked!\n"); success = false; } //Unlock texture diff --git a/Chip8.Sharp/Chip8.WPF/MainWindow.xaml.cs b/Chip8.Sharp/Chip8.WPF/MainWindow.xaml.cs index 3d60e7d..b275265 100644 --- a/Chip8.Sharp/Chip8.WPF/MainWindow.xaml.cs +++ b/Chip8.Sharp/Chip8.WPF/MainWindow.xaml.cs @@ -118,74 +118,74 @@ private void OnKeyUp(object sender, KeyEventArgs e) case Key.D1: keys[0x0] = 0; - Console.WriteLine("1"); + Debug.Print("1"); break; case Key.D2: keys[0x1] = 0; - Console.WriteLine("2"); + Debug.Print("2"); break; case Key.D3: keys[0x2] = 0; - Console.WriteLine("3"); + Debug.Print("3"); break; case Key.D4: keys[0x3] = 0; - Console.WriteLine("4"); + Debug.Print("4"); break; case Key.Q: keys[0x4] = 0; - Console.WriteLine("q"); + Debug.Print("q"); break; case Key.W: keys[0x5] = 0; - Console.WriteLine("w"); + Debug.Print("w"); break; case Key.E: keys[0x6] = 0; - Console.WriteLine("e"); + Debug.Print("e"); break; case Key.R: keys[0x7] = 0; - Console.WriteLine("r"); + Debug.Print("r"); break; case Key.A: keys[0x8] = 0; - Console.WriteLine("a"); + Debug.Print("a"); break; case Key.S: keys[0x9] = 0; - Console.WriteLine("s"); + Debug.Print("s"); break; case Key.D: keys[0xA] = 0; - Console.WriteLine("d"); + Debug.Print("d"); break; case Key.F: keys[0xA] = 0; - Console.WriteLine("f"); + Debug.Print("f"); break; case Key.Z: keys[0xB] = 0; - Console.WriteLine("z"); + Debug.Print("z"); break; case Key.Y: keys[0xB] = 0; - Console.WriteLine("y"); + Debug.Print("y"); break; case Key.X: keys[0xC] = 0; - Console.WriteLine("x"); + Debug.Print("x"); break; case Key.C: keys[0xD] = 0; - Console.WriteLine("c"); + Debug.Print("c"); break; case Key.V: keys[0xE] = 0; - Console.WriteLine("v"); + Debug.Print("v"); break; default: @@ -202,95 +202,95 @@ private void OnKeyDown(object sender, KeyEventArgs e) switch (e.Key) { case Key.Escape: - Console.WriteLine("ESCAPE"); - Console.WriteLine("Quitting..."); + Debug.Print("ESCAPE"); + Debug.Print("Quitting..."); quit = true; Close(); break; case Key.Up: - Console.WriteLine("UP"); + Debug.Print("UP"); break; case Key.Down: - Console.WriteLine("DOWN"); + Debug.Print("DOWN"); break; case Key.Left: - Console.WriteLine("LEFT"); + Debug.Print("LEFT"); break; case Key.Right: - Console.WriteLine("RIGHT"); + Debug.Print("RIGHT"); break; case Key.D1: keys[0x0] = 1; - Console.WriteLine("1"); + Debug.Print("1"); break; case Key.D2: keys[0x1] = 1; - Console.WriteLine("2"); + Debug.Print("2"); break; case Key.D3: keys[0x2] = 1; - Console.WriteLine("3"); + Debug.Print("3"); break; case Key.D4: keys[0x3] = 1; - Console.WriteLine("4"); + Debug.Print("4"); break; case Key.Q: keys[0x4] = 1; - Console.WriteLine("q"); + Debug.Print("q"); break; case Key.W: keys[0x5] = 1; - Console.WriteLine("w"); + Debug.Print("w"); break; case Key.E: keys[0x6] = 1; - Console.WriteLine("e"); + Debug.Print("e"); break; case Key.R: keys[0x7] = 1; - Console.WriteLine("r"); + Debug.Print("r"); break; case Key.A: keys[0x8] = 1; - Console.WriteLine("a"); + Debug.Print("a"); break; case Key.S: keys[0x9] = 1; - Console.WriteLine("s"); + Debug.Print("s"); break; case Key.D: keys[0xA] = 1; - Console.WriteLine("d"); + Debug.Print("d"); break; case Key.F: keys[0xA] = 1; - Console.WriteLine("f"); + Debug.Print("f"); break; case Key.Z: keys[0xB] = 1; - Console.WriteLine("z"); + Debug.Print("z"); break; case Key.Y: keys[0xB] = 1; - Console.WriteLine("y"); + Debug.Print("y"); break; case Key.X: keys[0xC] = 1; - Console.WriteLine("x"); + Debug.Print("x"); break; case Key.C: keys[0xD] = 1; - Console.WriteLine("c"); + Debug.Print("c"); break; case Key.V: keys[0xE] = 1; - Console.WriteLine("v"); + Debug.Print("v"); break; case Key.Back: @@ -299,11 +299,11 @@ private void OnKeyDown(object sender, KeyEventArgs e) if (debugPixels) { - Console.WriteLine("Entering debug pixel mode"); + Debug.Print("Entering debug pixel mode"); } else { - Console.WriteLine("Leaving debug pixel mode"); + Debug.Print("Leaving debug pixel mode"); } break; case Key.Enter: @@ -312,30 +312,30 @@ private void OnKeyDown(object sender, KeyEventArgs e) if (debugKeys) { - Console.WriteLine("Entering debug keys mode"); + Debug.Print("Entering debug keys mode"); } else { - Console.WriteLine("Leaving debug keys mode"); + Debug.Print("Leaving debug keys mode"); } break; case Key.OemPlus: case Key.Add: zoom += 0.5f; - Console.WriteLine($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); + Debug.Print($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); break; case Key.OemMinus: case Key.Subtract: zoom -= 0.5f; - Console.WriteLine($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); + Debug.Print($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); break; case Key.D0: zoom = 1.0f; - Console.WriteLine($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); + Debug.Print($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); break; default: - Console.WriteLine("Default Key Press"); + Debug.Print("Default Key Press"); break; } @@ -425,7 +425,7 @@ private static void OnStartSound(int channel, int frequency, int duration) private static void OnEndSound(int channel) { - Console.WriteLine("BEEP!"); + Debug.Print("BEEP!"); } private void ComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) diff --git a/Chip8.Sharp/Chip8.WindowsForms/MainForm.cs b/Chip8.Sharp/Chip8.WindowsForms/MainForm.cs index 9b5381a..c98d63f 100644 --- a/Chip8.Sharp/Chip8.WindowsForms/MainForm.cs +++ b/Chip8.Sharp/Chip8.WindowsForms/MainForm.cs @@ -101,95 +101,95 @@ private void MainForm_KeyDown(object sender, KeyEventArgs e) switch (e.KeyCode) { case Keys.Escape: - Console.WriteLine("ESCAPE"); - Console.WriteLine("Quitting..."); + Debug.Print("ESCAPE"); + Debug.Print("Quitting..."); quit = true; Close(); break; case Keys.Up: - Console.WriteLine("UP"); + Debug.Print("UP"); break; case Keys.Down: - Console.WriteLine("DOWN"); + Debug.Print("DOWN"); break; case Keys.Left: - Console.WriteLine("LEFT"); + Debug.Print("LEFT"); break; case Keys.Right: - Console.WriteLine("RIGHT"); + Debug.Print("RIGHT"); break; case Keys.D1: keys[0x0] = 1; - Console.WriteLine("1"); + Debug.Print("1"); break; case Keys.D2: keys[0x1] = 1; - Console.WriteLine("2"); + Debug.Print("2"); break; case Keys.D3: keys[0x2] = 1; - Console.WriteLine("3"); + Debug.Print("3"); break; case Keys.D4: keys[0x3] = 1; - Console.WriteLine("4"); + Debug.Print("4"); break; case Keys.Q: keys[0x4] = 1; - Console.WriteLine("q"); + Debug.Print("q"); break; case Keys.W: keys[0x5] = 1; - Console.WriteLine("w"); + Debug.Print("w"); break; case Keys.E: keys[0x6] = 1; - Console.WriteLine("e"); + Debug.Print("e"); break; case Keys.R: keys[0x7] = 1; - Console.WriteLine("r"); + Debug.Print("r"); break; case Keys.A: keys[0x8] = 1; - Console.WriteLine("a"); + Debug.Print("a"); break; case Keys.S: keys[0x9] = 1; - Console.WriteLine("s"); + Debug.Print("s"); break; case Keys.D: keys[0xA] = 1; - Console.WriteLine("d"); + Debug.Print("d"); break; case Keys.F: keys[0xA] = 1; - Console.WriteLine("f"); + Debug.Print("f"); break; case Keys.Z: keys[0xB] = 1; - Console.WriteLine("z"); + Debug.Print("z"); break; case Keys.Y: keys[0xB] = 1; - Console.WriteLine("y"); + Debug.Print("y"); break; case Keys.X: keys[0xC] = 1; - Console.WriteLine("x"); + Debug.Print("x"); break; case Keys.C: keys[0xD] = 1; - Console.WriteLine("c"); + Debug.Print("c"); break; case Keys.V: keys[0xE] = 1; - Console.WriteLine("v"); + Debug.Print("v"); break; case Keys.Back: @@ -198,11 +198,11 @@ private void MainForm_KeyDown(object sender, KeyEventArgs e) if (debugPixels) { - Console.WriteLine("Entering debug pixel mode"); + Debug.Print("Entering debug pixel mode"); } else { - Console.WriteLine("Leaving debug pixel mode"); + Debug.Print("Leaving debug pixel mode"); } break; case Keys.Enter: @@ -211,30 +211,30 @@ private void MainForm_KeyDown(object sender, KeyEventArgs e) if (debugKeys) { - Console.WriteLine("Entering debug keys mode"); + Debug.Print("Entering debug keys mode"); } else { - Console.WriteLine("Leaving debug keys mode"); + Debug.Print("Leaving debug keys mode"); } break; case Keys.Oemplus: case Keys.Add: zoom += 0.5f; - Console.WriteLine($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); + Debug.Print($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); break; case Keys.OemMinus: case Keys.Subtract: zoom -= 0.5f; - Console.WriteLine($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); + Debug.Print($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); break; case Keys.D0: zoom = 1.0f; - Console.WriteLine($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); + Debug.Print($"Zoom level: {zoom.ToString(NumberFormatInfo.CurrentInfo)}x"); break; default: - Console.WriteLine("Default Key Press"); + Debug.Print("Default Key Press"); break; } @@ -258,74 +258,74 @@ private void MainForm_KeyUp(object sender, KeyEventArgs e) case Keys.D1: keys[0x0] = 0; - Console.WriteLine("1"); + Debug.Print("1"); break; case Keys.D2: keys[0x1] = 0; - Console.WriteLine("2"); + Debug.Print("2"); break; case Keys.D3: keys[0x2] = 0; - Console.WriteLine("3"); + Debug.Print("3"); break; case Keys.D4: keys[0x3] = 0; - Console.WriteLine("4"); + Debug.Print("4"); break; case Keys.Q: keys[0x4] = 0; - Console.WriteLine("q"); + Debug.Print("q"); break; case Keys.W: keys[0x5] = 0; - Console.WriteLine("w"); + Debug.Print("w"); break; case Keys.E: keys[0x6] = 0; - Console.WriteLine("e"); + Debug.Print("e"); break; case Keys.R: keys[0x7] = 0; - Console.WriteLine("r"); + Debug.Print("r"); break; case Keys.A: keys[0x8] = 0; - Console.WriteLine("a"); + Debug.Print("a"); break; case Keys.S: keys[0x9] = 0; - Console.WriteLine("s"); + Debug.Print("s"); break; case Keys.D: keys[0xA] = 0; - Console.WriteLine("d"); + Debug.Print("d"); break; case Keys.F: keys[0xA] = 0; - Console.WriteLine("f"); + Debug.Print("f"); break; case Keys.Z: keys[0xB] = 0; - Console.WriteLine("z"); + Debug.Print("z"); break; case Keys.Y: keys[0xB] = 0; - Console.WriteLine("y"); + Debug.Print("y"); break; case Keys.X: keys[0xC] = 0; - Console.WriteLine("x"); + Debug.Print("x"); break; case Keys.C: keys[0xD] = 0; - Console.WriteLine("c"); + Debug.Print("c"); break; case Keys.V: keys[0xE] = 0; - Console.WriteLine("v"); + Debug.Print("v"); break; default: @@ -429,7 +429,7 @@ private static void OnStartSound(int channel, int frequency, int duration) private static void OnEndSound(int channel) { - Console.WriteLine("BEEP!"); + Debug.Print("BEEP!"); } private void cbPrograms_SelectedIndexChanged(object sender, EventArgs e)