]> localhost Git - WindEmu.git/commitdiff
logging: add a centralised logging macro
authorGeorge Wright <gw@gwright.org.uk>
Thu, 25 Jun 2026 01:49:22 +0000 (18:49 -0700)
committerGeorge Wright <gw@gwright.org.uk>
Fri, 26 Jun 2026 03:44:07 +0000 (20:44 -0700)
CMakeLists.txt
WindCore/arm710.cpp
WindCore/logger.cpp [new file with mode: 0644]
WindCore/logger.h [new file with mode: 0644]

index be002264bc0df9d65b2a14e7a647e2f75abf44e6..cae2a76a7584105d142ee2e566f427330bf3fedc 100644 (file)
@@ -18,6 +18,7 @@ set(WIND_CORE_SOURCES
     WindCore/emubase.cpp
     WindCore/decoder.c
     WindCore/decoder-arm.c
+    WindCore/logger.cpp
     WindCore/osaris/clps7111.cpp
     WindCore/osaris/clps7600.cpp
     WindCore/series5mx/etna.cpp
index 4cbe1e1ee0278b2c18623d9bc0f42cb9f8603112..c568470bf17d93fd1d3ce3f3ef3daebf1fc98046 100644 (file)
@@ -1,5 +1,6 @@
 #include "arm710.h"
 #include "common.h"
+#include "logger.h"
 
 // this will need changing if this code ever compiles on big-endian procs
 inline uint32_t read32LE(uint8_t* p) { return *((uint32_t*)p); }
@@ -73,6 +74,9 @@ void ARM710::reset() {
 }
 
 uint32_t ARM710::tick() {
+  uint32_t pc = getGPR(15) - 0x8;
+  setPC(pc);
+
   // pop an instruction off the end of the pipeline
   bool haveInsn = false;
   uint32_t insn;
diff --git a/WindCore/logger.cpp b/WindCore/logger.cpp
new file mode 100644 (file)
index 0000000..94328f2
--- /dev/null
@@ -0,0 +1,20 @@
+#include "logger.h"
+
+static uint64_t sEventNumber = 0;
+
+uint64_t getNextEventNumber() {
+    return sEventNumber++;
+}
+
+uint64_t getEventNumber() {
+    return sEventNumber;
+}
+
+static uint32_t sCurrentPC = 0;
+
+void setPC(uint32_t pc) {
+    sCurrentPC = pc;
+}
+uint32_t getPC() {
+    return sCurrentPC;
+}
diff --git a/WindCore/logger.h b/WindCore/logger.h
new file mode 100644 (file)
index 0000000..829543d
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef LOGGER_H
+#define LOGGER_H
+
+#include <stdint.h>
+#include <stdio.h>
+
+uint64_t getNextEventNumber();
+uint64_t getEventNumber();
+
+void setPC(uint32_t);
+uint32_t getPC();
+
+#define LOGGING_ENABLE 0
+
+#if LOGGING_ENABLE
+#define LOG_REG_W(name, addr, value)                                           \
+  printf("%llu: (%08x) [W] %s [%08x] <= %08x\n", getNextEventNumber(),         \
+         getPC(), name, addr, value)
+
+#define LOG_REG_R(name, addr, value)                                           \
+  printf("%llu: (%08x) [R] %s [%08x] => %08x\n", getNextEventNumber(),         \
+         getPC(), name, addr, value)
+
+#define LOG(...) printf(__VA_ARGS__)
+#else
+#define LOG_REG_W(name, addr, value)                                           \
+  do {                                                                         \
+    {                                                                          \
+    }                                                                          \
+  } while (0)
+#define LOG_REG_R(name, addr, value)                                           \
+  do {                                                                         \
+    {                                                                          \
+    }                                                                          \
+  } while (0)
+#define LOG(...)
+#endif
+
+#endif // LOGGER_H