Creado logger. Implementado STOP a medias.
authorslack <slack@0666ae3d-8926-0410-aeff-ae84559ff337>
Fri, 27 Jul 2007 16:05:34 +0000 (16:05 +0000)
committerslack <slack@0666ae3d-8926-0410-aeff-ae84559ff337>
Fri, 27 Jul 2007 16:05:34 +0000 (16:05 +0000)
git-svn-id: http://slack.codemaniacs.com/wenboi@5 0666ae3d-8926-0410-aeff-ae84559ff337

gbcore.cc
logger.h [new file with mode: 0644]

index a54fc8e9b685b437f76e1887ff1de164f668a002..9bd08e66e9b4879563e3616fb33667d97565a21e 100644 (file)
--- a/gbcore.cc
+++ b/gbcore.cc
@@ -4,6 +4,7 @@
 #include "GBRom.h"
 #include "GBMemory.h"
 #include "MBC.h"
+#include "logger.h"
 #include <string>
 #include <cstring>
 
@@ -97,12 +98,14 @@ class GameBoy
 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;
 }
@@ -583,6 +586,17 @@ void GameBoy::run_cycle()
                        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");
+                       }
+
+
+
 
 
 
diff --git a/logger.h b/logger.h
new file mode 100644 (file)
index 0000000..3649563
--- /dev/null
+++ b/logger.h
@@ -0,0 +1,47 @@
+#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