#include "GBRom.h"
#include "GBMemory.h"
#include "MBC.h"
+#include "logger.h"
#include <string>
#include <cstring>
GameBoy::GameBoy(std::string rom_name):
rom(0), regs(), IME(1), HALT(0)
{
+ logger.info("GameBoy init");
rom = read_gbrom(rom_name);
reset();
}
void GameBoy::reset()
{
+ logger.info("GameBoy reset");
std::memcpy(memory, rom->data, 16384);
regs.PC = 0x100;
}
HALT = true;
break;
+ // STOP
+ case 0x10:
+ int sub_opcode = memory[regs.PC++];
+ if (sub_opcode == 0x00) {
+ HALT = true;
+ } else {
+ logger.critical("Unknown sub-opcode after 0x10");
+ }
+
+
+
--- /dev/null
+#if !defined(LOGGER_H)
+#define LOGGER_H
+
+#include <string>
+#include <iostream>
+#include <ctime>
+
+class Logger
+{
+ private:
+ std::ostream& out;
+ static Logger instance;
+
+ public:
+ static Logger& getInstance() { return instance; }
+ Logger(std::ostream& os): out(os) {}
+
+ enum log_level{
+ OFF = -1,
+ CRITICAL=0,
+ ERROR=1,
+ WARNING=2,
+ INFO=3,
+ DEBUG=4,
+ TRACE=5
+ };
+
+ log_level current_log_level;
+
+
+ void log(log_level level, std::string str)
+ {
+ if (level <= current_log_level)
+ out << "[" << time(NULL) << "] " << str << std::endl;
+ }
+
+ void critical(std::string str) { log(CRITICAL, str); }
+ void error (std::string str) { log(ERROR , str); }
+ void warning (std::string str) { log(WARNING , str); }
+ void info (std::string str) { log(INFO , str); }
+ void debug (std::string str) { log(DEBUG , str); }
+ void trace (std::string str) { log(TRACE , str); }
+};
+
+#define logger Logger::getInstance()
+
+#endif