call() {
};
}
+ /**
+ *
+ * Open current project open source address.If user location in China will visit gitee,
+ * otherwise visit github.
+ */
@FXML
public void github() {
- INes.eventBus.publish(EventBusAddress.OPEN_URI, "https://github.com/GZYangKui/nes4j");
+ final String uri;
+ var tid = TimeZone.getDefault().getID();
+ if (tid.toLowerCase().contains("shanghai")) {
+ uri = "https://gitee.com/navigatorcode/nes4j";
+ } else {
+ uri = "https://github.com/GZYangKui/nes4j";
+ }
+ INes.eventBus.publish(EventBusAddress.OPEN_URI, uri);
}
@FXML
diff --git a/app/src/main/java/module-info.java b/app/src/main/java/module-info.java
index 1724699..ef3daca 100644
--- a/app/src/main/java/module-info.java
+++ b/app/src/main/java/module-info.java
@@ -12,9 +12,6 @@
requires cn.navclub.nes4j.bin;
requires org.controlsfx.controls;
- requires org.slf4j;
- requires ch.qos.logback.core;
- requires ch.qos.logback.classic;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
diff --git a/app/src/main/resources/cn/navclub/nes4j/app/assets/css/GameHallStyle.css b/app/src/main/resources/cn/navclub/nes4j/app/assets/css/GameHallStyle.css
index bcc5d23..82df416 100644
--- a/app/src/main/resources/cn/navclub/nes4j/app/assets/css/GameHallStyle.css
+++ b/app/src/main/resources/cn/navclub/nes4j/app/assets/css/GameHallStyle.css
@@ -1,5 +1,6 @@
@import "common.css";
+
.navbar *, .assort, .flow-pane .game-tray .label, .empty .label {
-fx-font-size: 1.4em;
-fx-text-fill: -nes4j-game-hall-text-fill;
diff --git a/app/src/main/resources/cn/navclub/nes4j/app/assets/fxml/GameHall.fxml b/app/src/main/resources/cn/navclub/nes4j/app/assets/fxml/GameHall.fxml
index 4fcd73b..f5da7c6 100644
--- a/app/src/main/resources/cn/navclub/nes4j/app/assets/fxml/GameHall.fxml
+++ b/app/src/main/resources/cn/navclub/nes4j/app/assets/fxml/GameHall.fxml
@@ -16,7 +16,7 @@
-
+
@@ -29,11 +29,6 @@
-
diff --git a/app/src/main/resources/cn/navclub/nes4j/app/assets/img/nes4j.png b/app/src/main/resources/cn/navclub/nes4j/app/assets/img/nes4j.png
new file mode 100644
index 0000000..e2b5ef8
Binary files /dev/null and b/app/src/main/resources/cn/navclub/nes4j/app/assets/img/nes4j.png differ
diff --git a/app/src/main/resources/logback.xml b/app/src/main/resources/logback.xml
deleted file mode 100644
index c24f7d7..0000000
--- a/app/src/main/resources/logback.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
- ${LOG_PATTERN}
-
-
-
-
- ${LOG_HOME}
-
-
- ${LOG_HOME}.%d{yyyy-MM-dd}.%i
- 30
- 50MB
-
-
- ${LOG_PATTERN}
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/bin/pom.xml b/bin/pom.xml
index 9472087..11a483d 100644
--- a/bin/pom.xml
+++ b/bin/pom.xml
@@ -34,23 +34,6 @@
-
-
-
- org.slf4j
- slf4j-api
-
-
- ch.qos.logback
- logback-core
- test
-
-
- ch.qos.logback
- logback-classic
- test
-
-
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/NES.java b/bin/src/main/java/cn/navclub/nes4j/bin/NES.java
index 0287bd1..44aa9a5 100644
--- a/bin/src/main/java/cn/navclub/nes4j/bin/NES.java
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/NES.java
@@ -3,8 +3,6 @@
import cn.navclub.nes4j.bin.apu.APU;
import cn.navclub.nes4j.bin.apu.Player;
import cn.navclub.nes4j.bin.core.*;
-import cn.navclub.nes4j.bin.core.impl.NRMapper;
-import cn.navclub.nes4j.bin.core.impl.UXMapper;
import cn.navclub.nes4j.bin.debug.Debugger;
import cn.navclub.nes4j.bin.config.CPUInterrupt;
import cn.navclub.nes4j.bin.eventbus.EventBus;
@@ -15,15 +13,11 @@
import cn.navclub.nes4j.bin.ppu.PPU;
import lombok.Getter;
import lombok.Setter;
-import lombok.extern.slf4j.Slf4j;
import java.io.File;
-import java.util.Queue;
-import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.locks.LockSupport;
-@Slf4j
@Getter
public class NES {
private final Bus bus;
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/apu/FrameCounter.java b/bin/src/main/java/cn/navclub/nes4j/bin/apu/FrameCounter.java
index 1af7028..2267548 100644
--- a/bin/src/main/java/cn/navclub/nes4j/bin/apu/FrameCounter.java
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/apu/FrameCounter.java
@@ -26,7 +26,6 @@
*
* @author GZYangKui
*/
-@Slf4j
public class FrameCounter implements Component {
/**
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/config/Instruction.java b/bin/src/main/java/cn/navclub/nes4j/bin/config/Instruction.java
index da5fe6c..7dd4dc4 100644
--- a/bin/src/main/java/cn/navclub/nes4j/bin/config/Instruction.java
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/config/Instruction.java
@@ -13,7 +13,6 @@
*
* @author GZYangKui
*/
-@Slf4j
public enum Instruction {
/**
* More detail please visit:ADC Document
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/core/Bus.java b/bin/src/main/java/cn/navclub/nes4j/bin/core/Bus.java
index 0a5f13b..151c557 100644
--- a/bin/src/main/java/cn/navclub/nes4j/bin/core/Bus.java
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/core/Bus.java
@@ -2,12 +2,9 @@
import cn.navclub.nes4j.bin.NES;
import cn.navclub.nes4j.bin.apu.APU;
-import cn.navclub.nes4j.bin.config.NMapper;
-import cn.navclub.nes4j.bin.io.Cartridge;
import cn.navclub.nes4j.bin.io.JoyPad;
import cn.navclub.nes4j.bin.ppu.PPU;
import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
import static cn.navclub.nes4j.bin.util.BinUtil.int8;
import static cn.navclub.nes4j.bin.util.BinUtil.uint8;
@@ -15,7 +12,6 @@
/**
* @author GZYangKui
*/
-@Slf4j
public class Bus implements Component {
private static final int RPG_ROM = 0x8000;
private static final int RPG_ROM_END = 0xFFFF;
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/core/CPU.java b/bin/src/main/java/cn/navclub/nes4j/bin/core/CPU.java
index b815622..8ff5242 100644
--- a/bin/src/main/java/cn/navclub/nes4j/bin/core/CPU.java
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/core/CPU.java
@@ -3,6 +3,8 @@
import cn.navclub.nes4j.bin.NES;
import cn.navclub.nes4j.bin.config.*;
import cn.navclub.nes4j.bin.core.register.CPUStatus;
+import cn.navclub.nes4j.bin.log.Logger;
+import cn.navclub.nes4j.bin.log.LoggerAdapter;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -16,8 +18,9 @@
*
* @author GZYangKui
*/
-@Slf4j
public class CPU {
+ private final static Logger logger = LoggerAdapter.logger(CPU.class);
+
//Stack offset
public static final int STACK = 0x0100;
//Program counter reset offset
@@ -375,12 +378,12 @@ public int next() {
var mode = instruction6502.getAddressMode();
var instruction = instruction6502.getInstruction();
- if (log.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
var operand = "";
if (mode != AddressMode.Implied && mode != AddressMode.Accumulator && mode != AddressMode.Relative) {
operand = "0x" + Integer.toHexString(this.modeProvider.getAbsAddr(mode));
}
- log.debug(
+ logger.debug(
"[0x{}] A:{} X:{} Y:{} S:{} {} {}",
Integer.toHexString(this.pc - 1),
Integer.toHexString(this.ra),
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/log/Level.java b/bin/src/main/java/cn/navclub/nes4j/bin/log/Level.java
new file mode 100644
index 0000000..09e82ea
--- /dev/null
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/log/Level.java
@@ -0,0 +1,17 @@
+package cn.navclub.nes4j.bin.log;
+
+/**
+ * Enum all log level
+ *
+ * @author GZYangKui
+ */
+public enum Level {
+ ALL,
+ TRACE,
+ DEBUG,
+ INFO,
+ WARN,
+ ERROR,
+ FATAL,
+ OFF
+}
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/log/Logger.java b/bin/src/main/java/cn/navclub/nes4j/bin/log/Logger.java
new file mode 100644
index 0000000..99a9e2b
--- /dev/null
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/log/Logger.java
@@ -0,0 +1,42 @@
+package cn.navclub.nes4j.bin.log;
+
+public interface Logger {
+ /**
+ * Output a debug level message
+ *
+ * @param msg message content
+ * @param params message params
+ */
+ void debug(String msg, Object... params);
+
+ /**
+ * Output a info level message
+ *
+ * @param msg message content
+ * @param params message params
+ */
+ void info(String msg, Object... params);
+
+ /**
+ * Output a warning level message
+ *
+ * @param msg message content
+ * @param params message params
+ */
+ void warning(String msg, Object... params);
+
+ /**
+ * Output a fatal level message
+ *
+ * @param msg message content
+ * @param throwable exception detail
+ */
+ void fatal(String msg, Throwable throwable);
+
+ /**
+ * Whether debug is enable
+ *
+ * @return If debug is enable return {@code true} otherwise {@code false}
+ */
+ boolean isDebugEnabled();
+}
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/log/LoggerAdapter.java b/bin/src/main/java/cn/navclub/nes4j/bin/log/LoggerAdapter.java
new file mode 100644
index 0000000..d747a88
--- /dev/null
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/log/LoggerAdapter.java
@@ -0,0 +1,20 @@
+package cn.navclub.nes4j.bin.log;
+
+import cn.navclub.nes4j.bin.log.impl.NLogger;
+
+public class LoggerAdapter {
+ private static final Level level;
+
+ static {
+ var str = System.getProperty("nes4j.log.level");
+ if (str == null || str.trim().equals("")) {
+ level = Level.INFO;
+ } else {
+ level = Level.valueOf(str.toUpperCase());
+ }
+ }
+
+ public static Logger logger(Class> clazz) {
+ return new NLogger(clazz, level);
+ }
+}
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/log/formatter/NFormatter.java b/bin/src/main/java/cn/navclub/nes4j/bin/log/formatter/NFormatter.java
new file mode 100644
index 0000000..cffb0b3
--- /dev/null
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/log/formatter/NFormatter.java
@@ -0,0 +1,72 @@
+package cn.navclub.nes4j.bin.log.formatter;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.regex.Pattern;
+
+public class NFormatter extends Formatter {
+ private final Pattern pattern;
+ private final SimpleDateFormat format;
+
+ public NFormatter() {
+ this.pattern = Pattern.compile("\\{}");
+ this.format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ }
+
+ @Override
+ public String format(LogRecord record) {
+ var str = String.format("[%s [%s] [%-7s] [%s]",
+ this.format.format(new Date()),
+ Thread.currentThread().getName(),
+ record.getLevel().getName(),
+ record.getLoggerName()
+ );
+ var message = record.getMessage();
+ var params = record.getParameters();
+ var length = params == null ? 0 : params.length;
+
+ var index = 0;
+ var offset = 0;
+ var sb = new StringBuilder(message);
+ var matter = pattern.matcher(message);
+ while (matter.find() && index < length) {
+ var start = matter.start();
+ var end = matter.end();
+ var param = record.getParameters()[index];
+ if (param == null) {
+ param = "nil";
+ }
+ var value = param.toString();
+ sb.replace(start + offset, end + offset, value);
+ offset += (value.length() - 2);
+ index++;
+ }
+ str = String.format("%s %s", str, sb);
+
+ if (record.getLevel() == Level.SEVERE) {
+ var e = record.getThrown();
+ if (e != null) {
+ str += "\n";
+ str += throwable2Str(e);
+ }
+ }
+ str += "\n";
+ return str;
+ }
+
+ private String throwable2Str(Throwable throwable) {
+ try (
+ var sw = new StringWriter();
+ var pw = new PrintWriter(sw)) {
+ throwable.printStackTrace(pw);
+ return sw.toString();
+ } catch (Exception e) {
+ return throwable2Str(new RuntimeException("Log exception parser error!"));
+ }
+ }
+}
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/log/impl/NLogger.java b/bin/src/main/java/cn/navclub/nes4j/bin/log/impl/NLogger.java
new file mode 100644
index 0000000..7e20178
--- /dev/null
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/log/impl/NLogger.java
@@ -0,0 +1,55 @@
+package cn.navclub.nes4j.bin.log.impl;
+
+import cn.navclub.nes4j.bin.log.formatter.NFormatter;
+
+import java.util.logging.*;
+
+public class NLogger implements cn.navclub.nes4j.bin.log.Logger {
+
+ private final Logger logger;
+ @SuppressWarnings("all")
+ private final Handler handler;
+
+ public NLogger(Class> clazz, cn.navclub.nes4j.bin.log.Level level) {
+ this.handler = new ConsoleHandler();
+ this.handler.setFormatter(new NFormatter());
+ this.logger = Logger.getLogger(clazz.getName());
+ this.logger.addHandler(handler);
+ this.logger.setUseParentHandlers(false);
+ switch (level) {
+ case ALL -> this.logger.setLevel(Level.ALL);
+ case TRACE -> this.logger.setLevel(Level.FINEST);
+ case DEBUG -> this.logger.setLevel(Level.FINER);
+ case INFO -> this.logger.setLevel(Level.INFO);
+ case WARN -> this.logger.setLevel(Level.WARNING);
+ case FATAL -> this.logger.setLevel(Level.SEVERE);
+ case OFF -> this.logger.setLevel(Level.OFF);
+ }
+ }
+
+ @Override
+ public void debug(String msg, Object... params) {
+ this.logger.log(Level.FINER, msg, params);
+ }
+
+ @Override
+ public void info(String msg, Object... params) {
+ this.logger.log(Level.INFO, msg, params);
+ }
+
+ @Override
+ public void warning(String msg, Object... params) {
+ this.logger.log(Level.WARNING, msg, params);
+ }
+
+ @Override
+ public void fatal(String msg, Throwable throwable) {
+ this.logger.log(Level.SEVERE, msg, throwable);
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ var level = this.logger.getLevel();
+ return level == Level.ALL || level.intValue() <= Level.CONFIG.intValue();
+ }
+}
diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/ppu/register/PPUControl.java b/bin/src/main/java/cn/navclub/nes4j/bin/ppu/register/PPUControl.java
index 64afbe9..ebc09e0 100644
--- a/bin/src/main/java/cn/navclub/nes4j/bin/ppu/register/PPUControl.java
+++ b/bin/src/main/java/cn/navclub/nes4j/bin/ppu/register/PPUControl.java
@@ -29,7 +29,7 @@
*
* @author GZYangKui
*/
-@Slf4j
+
public class PPUControl extends Register {
public PPUControl() {
diff --git a/bin/src/main/java/module-info.java b/bin/src/main/java/module-info.java
index 9a9243f..776c967 100644
--- a/bin/src/main/java/module-info.java
+++ b/bin/src/main/java/module-info.java
@@ -2,9 +2,10 @@
module cn.navclub.nes4j.bin {
requires static lombok;
- requires org.slf4j;
+ requires java.logging;
exports cn.navclub.nes4j.bin;
+ exports cn.navclub.nes4j.bin.log;
exports cn.navclub.nes4j.bin.core;
exports cn.navclub.nes4j.bin.util;
exports cn.navclub.nes4j.bin.ppu;
@@ -17,6 +18,7 @@
exports cn.navclub.nes4j.bin.apu;
exports cn.navclub.nes4j.bin.eventbus;
exports cn.navclub.nes4j.bin.apu.impl.timer;
+ exports cn.navclub.nes4j.bin.log.impl;
uses Player;
}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 9592250..2de3c6c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,21 +44,6 @@
-
- org.slf4j
- slf4j-api
- ${slf4j.version}
-
-
- ch.qos.logback
- logback-core
- ${logback.version}
-
-
- ch.qos.logback
- logback-classic
- ${logback.version}
-
com.fasterxml.jackson.core
jackson-databind