<commit_before>#[macro_use]
extern crate clap;
extern crate osciemu;

use std::io;
use osciemu::utils::{load_file};
use osciemu::memory::{Memory, SliceMemory};
use osciemu::emulator::Emulator;
use osciemu::loader::{hexloader, rawloader};

fn main() {
    let matches = clap_app!(myapp =>
            (version: "0.1.0")
            (author: "Surma <<EMAIL>>")
            (about: "Emulates an osci CPU")
            (@arg IMAGE: -i --image +takes_value "Image to load into memory")
            (@arg BIOS: -b --bios +required +takes_value "BIOS to load")
            (@arg STEP: --step "Walk through in stepping mode")
            (@arg MAX_STEP: --maxstep +takes_value "Maximum number of CPU cycles (0 means infinite)")
        )
        .get_matches();

    let max_steps = matches.value_of("MAX_STEP")
                        .map(|s| {
                            s.parse::<usize>()
                                .expect("--max-step needs to be a number")
                        })
                        .unwrap_or(0);

    let image_mem = matches.value_of("IMAGE")
                            .ok_or(io::Error::new(io::ErrorKind::Other, "Parameter not specified"))
                            .and_then(load_file)
                            .unwrap_or_else(|_err| Box::new(SliceMemory::new(0)));

    let bios_mem = matches.value_of("BIOS")
                            .ok_or(io::Error::new(io::ErrorKind::Other, "Parameter not specified"))
                            .and_then(load_file)
                            .expect("Could not load bios");

    let step_mode = matches.is_present("STEP");

    let mut emulator = Emulator::new(image_mem, bios_mem);

    println!("FLAGS_START_ADDRESS = 0x{:08X}", osciemu::memory::address::FLAGS_START_ADDRESS);
    println!("IVT_START_ADDRESS = 0x{:08X}", osciemu::memory::address::IVT_START_ADDRESS);
    println!("REGISTERS_START_ADDRESS = 0x{:08X}", osciemu::memory::address::REGISTERS_START_ADDRESS);
    println!("STACK_POINTER_ADDRESS = 0x{:08X}", osciemu::memory::address::STACK_POINTER_ADDRESS);

    for _count in RangeIterator::new(0, max_steps) {
        if emulator.is_halted() {
            break;
        }
        println!("ip: 0x{:08X}, r0: 0x{:08X}, r1: 0x{:08X}, r2: 0x{:08X}, r3: \
                  0x{:08X}",
                 emulator.ip,
                 emulator.get_register(0),
                 emulator.get_register(1),
                 emulator.get_register(2),
                 emulator.get_register(3));
        emulator.step();
        if step_mode {
            let mut buffer = String::new();
            let _ = io::stdin().read_line(&mut buffer);<commit_msg>Revert "feat(osci-cli): Don’t show instruction counter"<commit_after>#[macro_use]
extern crate clap;
extern crate osciemu;

use std::io;
use osciemu::utils::{load_file};
use osciemu::memory::{Memory, SliceMemory};
use osciemu::emulator::Emulator;
use osciemu::loader::{hexloader, rawloader};

fn main() {
    let matches = clap_app!(myapp =>
            (version: "0.1.0")
            (author: "Surma <<EMAIL>>")
            (about: "Emulates an osci CPU")
            (@arg IMAGE: -i --image +takes_value "Image to load into memory")
            (@arg BIOS: -b --bios +required +takes_value "BIOS to load")
            (@arg STEP: --step "Walk through in stepping mode")
            (@arg MAX_STEP: --maxstep +takes_value "Maximum number of CPU cycles (0 means infinite)")
        )
        .get_matches();

    let max_steps = matches.value_of("MAX_STEP")
                        .map(|s| {
                            s.parse::<usize>()
                                .expect("--max-step needs to be a number")
                        })
                        .unwrap_or(0);

    let image_mem = matches.value_of("IMAGE")
                            .ok_or(io::Error::new(io::ErrorKind::Other, "Parameter not specified"))
                            .and_then(load_file)
                            .unwrap_or_else(|_err| Box::new(SliceMemory::new(0)));

    let bios_mem = matches.value_of("BIOS")
                            .ok_or(io::Error::new(io::ErrorKind::Other, "Parameter not specified"))
                            .and_then(load_file)
                            .expect("Could not load bios");

    let step_mode = matches.is_present("STEP");

    let mut emulator = Emulator::new(image_mem, bios_mem);

    println!("FLAGS_START_ADDRESS = 0x{:08X}", osciemu::memory::address::FLAGS_START_ADDRESS);
    println!("IVT_START_ADDRESS = 0x{:08X}", osciemu::memory::address::IVT_START_ADDRESS);
    println!("REGISTERS_START_ADDRESS = 0x{:08X}", osciemu::memory::address::REGISTERS_START_ADDRESS);
    println!("STACK_POINTER_ADDRESS = 0x{:08X}", osciemu::memory::address::STACK_POINTER_ADDRESS);

    for count in RangeIterator::new(0, max_steps) {
        if emulator.is_halted() {
            break;
        }
        println!("count: {:4}, ip: 0x{:08X}, r0: 0x{:08X}, r1: 0x{:08X}, r2: 0x{:08X}, r3: \
                  0x{:08X}",
                 count,
                 emulator.ip,
                 emulator.get_register(0),
                 emulator.get_register(1),
                 emulator.get_register(2),
                 emulator.get_register(3));
        emulator.step();
        if step_mode {
            let mut buffer = String::new();
            let _ = io::stdin().read_line(&mut buffer);
{'fraction_non_alphanumeric': 0.1435754189944134, 'fraction_numerical': 0.015828677839851025, 'mean_word_length': 2.0956772334293947, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5737191', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1679, 'n_words': 329}