diff --git a/gb-emu/src/main.rs b/gb-emu/src/main.rs index 930a860..775dbad 100644 --- a/gb-emu/src/main.rs +++ b/gb-emu/src/main.rs @@ -9,7 +9,9 @@ use cpal::{ }; use futures::executor; use gb_emu_lib::{ - connect::{AudioOutput, DownsampleType, EmulatorMessage, JoypadState, Renderer, RomFile}, + connect::{ + AudioOutput, DownsampleType, EmulatorMessage, JoypadState, Renderer, RomFile, SerialTarget, + }, util::scale_buffer, EmulatorCore, }; @@ -75,14 +77,16 @@ fn main() { 3 }; - let options = gb_emu_lib::Options { - rom: RomFile::Path(args.rom), - save_path: args.save, - no_save: args.no_save, - bootrom: args.bootrom.map(RomFile::Path), - connect_serial: args.connect_serial, - verbose: args.verbose, - }; + let options = gb_emu_lib::Options::new(RomFile::Path(args.rom)) + .with_save_path(args.save) + .with_serial_target(if args.connect_serial { + SerialTarget::Stdout + } else { + SerialTarget::None + }) + .with_bootrom(args.bootrom.map(RomFile::Path)) + .with_no_save(args.no_save) + .with_verbose(args.verbose); let tile_window: Option>> = if args.tile_window { Some(Box::new(WindowRenderer::new(factor, None))) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 6106ef5..3fbb192 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -44,8 +44,8 @@ impl Options { } } - pub fn with_save_path(mut self, path: String) -> Self { - self.save_path = Some(path); + pub fn with_save_path(mut self, path: Option) -> Self { + self.save_path = path; self } @@ -54,6 +54,16 @@ impl Options { self } + pub fn with_no_save(mut self, no_save: bool) -> Self { + self.no_save = no_save; + self + } + + pub fn with_verbose(mut self, verbose: bool) -> Self { + self.verbose = verbose; + self + } + pub fn with_bootrom(mut self, bootrom: Option) -> Self { self.bootrom = bootrom; self @@ -69,7 +79,7 @@ impl Options { self } - pub fn with_verbose(mut self) -> Self { + pub fn verbose(mut self) -> Self { self.verbose = true; self }