35 lines
935 B
C++
35 lines
935 B
C++
//
|
|
// Created by selim on 9/16/23.
|
|
//
|
|
|
|
#include "Logger.h"
|
|
|
|
#include <cstring>
|
|
#include <fstream>
|
|
#include <format>
|
|
|
|
namespace nes {
|
|
|
|
Logger::Logger(size_t size): _size{size}, _offset{0} {
|
|
_data = std::make_unique<uint8_t[]>(size);
|
|
}
|
|
|
|
void Logger::addLine(uint64_t cycle, std::string_view line) {
|
|
if((_offset + line.size() + 10) >= _size) {
|
|
return;
|
|
}
|
|
|
|
std::string cycleString = std::format("[{:06d}] ", cycle);
|
|
std::memcpy(_data.get() + _offset, cycleString.data(), cycleString.size());
|
|
_offset += cycleString.size();
|
|
|
|
std::memcpy(_data.get() + _offset, line.data(), line.size());
|
|
_offset += line.size();
|
|
_data[_offset++] = '\n';
|
|
}
|
|
|
|
void Logger::dump(const fs::path &path) {
|
|
std::ofstream file(path, std::ios::binary);
|
|
file.write(reinterpret_cast<char*>(_data.get()), static_cast<std::streamsize>(_offset));
|
|
}
|
|
} |