75 lines
1.6 KiB
C++
75 lines
1.6 KiB
C++
|
|
#include "Bus.h"
|
||
|
|
#include "cpu.h"
|
||
|
|
|
||
|
|
#include "spdlog/spdlog.h"
|
||
|
|
#include "spdlog/sinks/rotating_file_sink.h"
|
||
|
|
|
||
|
|
#include "CLI11/include/CLI/CLI.hpp"
|
||
|
|
|
||
|
|
Bus* g_bus;
|
||
|
|
|
||
|
|
IMemoryAccessor* g_cpuMemory;
|
||
|
|
CPU* g_cpu;
|
||
|
|
|
||
|
|
Cartridge* g_cartridge;
|
||
|
|
|
||
|
|
std::shared_ptr<spdlog::logger> gLogger;
|
||
|
|
spdlog::logger* Logger() { return gLogger.get(); }
|
||
|
|
|
||
|
|
void initLogger()
|
||
|
|
{
|
||
|
|
constexpr static std::size_t MAX_LOG_SIZE = 1048576 * 5;
|
||
|
|
constexpr static std::size_t MAX_LOG_FILES = 10;
|
||
|
|
|
||
|
|
gLogger = spdlog::rotating_logger_mt("bear", "logs/bear.log", MAX_LOG_SIZE, MAX_LOG_FILES);
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(int argc, char** argv)
|
||
|
|
{
|
||
|
|
initLogger();
|
||
|
|
Logger()->info("Bear started...");
|
||
|
|
|
||
|
|
CLI::App args { "A NES Emulator" };
|
||
|
|
argv = args.ensure_utf8(argv);
|
||
|
|
|
||
|
|
std::string filename;
|
||
|
|
args.add_option("-f, --file", filename, ".nes ROM file to load");
|
||
|
|
|
||
|
|
CLI11_PARSE(args, argc, argv);
|
||
|
|
|
||
|
|
if (filename.empty())
|
||
|
|
{
|
||
|
|
Logger()->error("ROM file not specified");
|
||
|
|
exit(-1);
|
||
|
|
}
|
||
|
|
|
||
|
|
std::ifstream romFile(filename.c_str(), std::ios::binary);
|
||
|
|
if (!romFile.is_open())
|
||
|
|
{
|
||
|
|
Logger()->error("Could not open ROM file");
|
||
|
|
exit(-1);
|
||
|
|
}
|
||
|
|
|
||
|
|
romFile.seekg(0, std::ios::end);
|
||
|
|
const std::streamsize romFileSize = romFile.tellg();
|
||
|
|
romFile.seekg(0, std::ios::beg);
|
||
|
|
|
||
|
|
auto* rom = new std::byte[romFileSize];
|
||
|
|
|
||
|
|
if (!romFile.read(reinterpret_cast<char*>(rom), romFileSize))
|
||
|
|
{
|
||
|
|
Logger()->error("Could not read ROM file");
|
||
|
|
exit(-1);
|
||
|
|
}
|
||
|
|
|
||
|
|
g_cartridge = new Cartridge(rom);
|
||
|
|
g_bus->cartridge = g_cartridge;
|
||
|
|
|
||
|
|
g_cpuMemory = new CPUMemoryAccessor(g_bus);
|
||
|
|
g_cpu = new CPU(g_cpuMemory);
|
||
|
|
g_bus->cpu = g_cpu;
|
||
|
|
|
||
|
|
g_cpu->start();
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|