<commit_before>#include <cassert>
#include <iostream>
#include <iomanip>
#include <boost/format.hpp>
#include "memory.h"
#include "cpu.h"

// ---------------------------------------------------------------------------------------------- //
class StdOutLogger : public ICpuLogger {
public:
    void log(uint8_t const * instr, uint8_t bytes, uint16_t instr_addr, uint8_t cycles,
             struct CpuContext const * const context);
};

// ---------------------------------------------------------------------------------------------- //
void StdOutLogger::log(uint8_t const * instr, uint8_t bytes, uint16_t instr_addr, uint8_t cycles,
                       struct CpuContext const * const context) {
    std::cout << boost::format("%-06X") % instr_addr;

    for (int i = 0; i < 3; i++) {
        if (bytes > i) {
            std::cout << boost::format("%02X ") % static_cast<int>(instr[i]);
        } else {
            std::cout << "   ";
        }
    }

    // TODO(amiko): disassembly
    std::cout << boost::format("%-20s") % "";

    std::cout << boost::format("A:%02X X:%02X Y:%02X P:%02X SP:%02X CYC:%d \n")
    % static_cast<int>(context->sregs[A]) % static_cast<int>(context->sregs[X])
    % static_cast<int>(context->sregs[Y]) % static_cast<int>(context->P)
    % static_cast<int>(context->SP) % static_cast<int>(cycles);
}

// ---------------------------------------------------------------------------------------------- //
int main(int argc, char **argv)
{
    assert(argc == 2);
    std::string file = std::string(argv[1]);

    StdOutLogger logger;
    Memory mem(file);
    Cpu cpu(mem);
    cpu.set_logger(&logger);

    cpu.reset();

    cpu.context.PC = 0xC000U;

    unsigned ret;
    do {
        ret = cpu.tick();
    } while(ret != 0U);

    return 0;
}<commit_msg>Add counting of executed instructions to the test app<commit_after>#include <cassert>
#include <iostream>
#include <iomanip>
#include <boost/format.hpp>
#include "memory.h"
#include "cpu.h"

// ---------------------------------------------------------------------------------------------- //
class StdOutLogger : public ICpuLogger {
public:
    void log(uint8_t const * instr, uint8_t bytes, uint16_t instr_addr, uint8_t cycles,
             struct CpuContext const * const context);
};

// ---------------------------------------------------------------------------------------------- //
void StdOutLogger::log(uint8_t const * instr, uint8_t bytes, uint16_t instr_addr, uint8_t cycles,
                       struct CpuContext const * const context) {
    std::cout << boost::format("%-06X") % instr_addr;

    for (int i = 0; i < 3; i++) {
        if (bytes > i) {
            std::cout << boost::format("%02X ") % static_cast<int>(instr[i]);
        } else {
            std::cout << "   ";
        }
    }

    // TODO(amiko): disassembly
    std::cout << boost::format("%-20s") % "";

    std::cout << boost::format("A:%02X X:%02X Y:%02X P:%02X SP:%02X CYC:%d \n")
    % static_cast<int>(context->sregs[A]) % static_cast<int>(context->sregs[X])
    % static_cast<int>(context->sregs[Y]) % static_cast<int>(context->P)
    % static_cast<int>(context->SP) % static_cast<int>(cycles);
}

// ---------------------------------------------------------------------------------------------- //
int main(int argc, char **argv)
{
    assert(argc == 2);
    std::string file = std::string(argv[1]);

    StdOutLogger logger;
    Memory mem(file);
    Cpu cpu(mem);
    cpu.set_logger(&logger);

    cpu.reset();

    cpu.context.PC = 0xC000U;

    unsigned ret;
    unsigned instructions = 0U;
    do {
        ret = cpu.tick();
        instructions++;
    } while(ret != 0U);

    std::cout << "Unknown instruction" << std::endl;
    std::cout << instructions - 1 <<  " instructions executed" << std::endl;

    return 0;
}
{'fraction_non_alphanumeric': 0.29614071934891045, 'fraction_numerical': 0.01942767130480441, 'mean_word_length': 1.7253218884120172, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 37, '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': '1944631', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1123, 'n_words': 246}