From b688d6b0fe3c25541a1c475ee3661abf8460af95 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Wed, 2 Aug 2023 00:23:25 +0100
Subject: [PATCH] reafctor: rorder of parsing values

---
 frontends/sdl/src/main.rs | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/frontends/sdl/src/main.rs b/frontends/sdl/src/main.rs
index f3afc78a..8782c6c4 100644
--- a/frontends/sdl/src/main.rs
+++ b/frontends/sdl/src/main.rs
@@ -789,12 +789,6 @@ fn main() {
     // parses the provided command line arguments and uses them to
     // obtain structured values
     let args = Args::parse();
-    let mode = if args.mode == "auto" {
-        GameBoyMode::Dmg
-    } else {
-        GameBoyMode::from_string(&args.mode)
-    };
-    let auto_mode = args.mode == "auto";
 
     // in case the default ROM path is provided and the file does not
     // exist then fails gracefully
@@ -804,6 +798,15 @@ fn main() {
         return;
     }
 
+    // tries to build the target mode from the mode argument
+    // parsing it if it does not contain the "auto" value
+    let mode = if args.mode == "auto" {
+        GameBoyMode::Dmg
+    } else {
+        GameBoyMode::from_string(&args.mode)
+    };
+    let auto_mode = args.mode == "auto";
+
     // creates a new Game Boy instance and loads both the boot ROM
     // and the initial game ROM to "start the engine"
     let mut game_boy = GameBoy::new(Some(mode));
-- 
GitLab