reznez 0.0.0

The high accuracy NES Emulator
Documentation
#![feature(array_chunks)]
#![feature(slice_as_chunks)]
#![feature(const_option)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(type_ascription)]
#![feature(const_option_ext)]
#![feature(const_mut_refs)]
#![feature(const_for)]
#![allow(clippy::module_inception)]
#![allow(clippy::new_without_default)]
#![allow(clippy::identity_op)]

mod apu;
mod analysis;
mod cartridge;
mod config;
mod controller;
mod cpu;
mod gui;
mod logging;
mod memory;
pub mod nes;
mod ppu;
mod util;

use structopt::StructOpt;

use crate::config::{Config, Opt};
use crate::logging::logger;
use crate::nes::Nes;
use crate::logging::logger::Logger;

fn main() {
    let opt = Opt::from_args();
    logger::init(logger(&opt)).unwrap();

    if opt.analysis {
        analysis::cartridge_db::analyze(&opt.rom_path);
    } else {
        let config = Config::new(&opt);
        let mut gui = Config::gui(&opt);
        let nes = Nes::new(&config);

        gui.run(nes, config);
    }
}

#[allow(clippy::similar_names)]
fn logger(opt: &Opt) -> Logger {
    let (log_cpu_instructions, log_cpu_steps, log_cpu_flow_control) = if opt.log_cpu_all {
        (true, true, true)
    } else {
        (opt.log_cpu_instructions, opt.log_cpu_steps, opt.log_cpu_flow_control)
    };

    let (log_ppu_stages, log_ppu_flags, log_ppu_steps) = if opt.log_ppu_all {
        (true, true, true)
    } else {
        (opt.log_ppu_stages, opt.log_ppu_flags, opt.log_ppu_steps)
    };

    let (log_apu_cycles, log_apu_events) = if opt.log_apu_all {
        (true, true)
    } else {
        (opt.log_apu_cycles, opt.log_apu_events)
    };

    Logger {
        log_frames: opt.log_frames,
        log_cpu_instructions,
        log_cpu_steps,
        log_cpu_flow_control,
        log_ppu_stages,
        log_ppu_flags,
        log_ppu_steps,
        log_apu_cycles,
        log_apu_events,
        log_oam_addr: opt.log_oam_addr,
        log_timings: opt.log_timings,
    }
}