Skip to content

Commit

Permalink
优化代码结构
Browse files Browse the repository at this point in the history
  • Loading branch information
GZYangKui committed Dec 2, 2022
1 parent 3ed298b commit 7c9a9bb
Show file tree
Hide file tree
Showing 37 changed files with 257 additions and 217 deletions.
151 changes: 0 additions & 151 deletions app/src/main/java/cn/navclub/nes4j/app/CHRView.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cn.navclub.nes4j.app;

import cn.navclub.nes4j.app.assets.FXResource;
import cn.navclub.nes4j.app.config.NESConfig;
import cn.navclub.nes4j.app.control.NesGameItem;
import cn.navclub.nes4j.app.dialog.DHandle;
import cn.navclub.nes4j.app.util.JsonUtil;
import cn.navclub.nes4j.app.util.StrUtil;
import cn.navclub.nes4j.bin.Player;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
Expand All @@ -23,7 +23,7 @@
import java.util.ResourceBundle;

@Slf4j
public class NES4J extends Application {
public class Nes4j extends Application {
public static final ResourceBundle RESOURCE_BUNDLE;
private static final String DEFAULT_CONFIG_PATH = "config/config.json";

Expand All @@ -33,7 +33,7 @@ public class NES4J extends Application {
static {
System.loadLibrary("nes4j");
System.setProperty("java.util.PropertyResourceBundle.encoding", "UTF-8");
RESOURCE_BUNDLE = ResourceBundle.getBundle("cn.navclub.nes4j.app.language.nes4j");
RESOURCE_BUNDLE = ResourceBundle.getBundle("cn.navclub.nes4j.app.assets.language.nes4j");
}

private ListView<NesGameItem> listView;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.navclub.nes4j.app;
package cn.navclub.nes4j.app.assets;

import javafx.scene.image.Image;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package cn.navclub.nes4j.app.control;

import cn.navclub.nes4j.app.FXResource;
import cn.navclub.nes4j.app.assets.FXResource;
import cn.navclub.nes4j.app.util.StrUtil;
import cn.navclub.nes4j.app.view.GameWorld;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/cn/navclub/nes4j/app/dialog/DHandle.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.navclub.nes4j.app.dialog;

import cn.navclub.nes4j.app.FXResource;
import cn.navclub.nes4j.app.NES4J;
import cn.navclub.nes4j.app.assets.FXResource;
import cn.navclub.nes4j.app.Nes4j;
import cn.navclub.nes4j.app.model.KeyMapper;
import javafx.geometry.Pos;
import javafx.scene.control.*;
Expand Down Expand Up @@ -114,7 +114,7 @@ public DHandle(final KeyMapper[] mappers) {

this.initTableView();

this.setTitle(NES4J.localeValue("nes4j.handle", true));
this.setTitle(Nes4j.localeValue("nes4j.handle", true));
}

private void initTableView() {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/cn/navclub/nes4j/app/dialog/DPalette.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cn.navclub.nes4j.app.dialog;

import cn.navclub.nes4j.app.FXResource;
import cn.navclub.nes4j.app.assets.FXResource;

import cn.navclub.nes4j.app.NES4J;
import cn.navclub.nes4j.app.Nes4j;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
Expand Down Expand Up @@ -50,7 +50,7 @@ public DPalette(int[][] palette) {
this.getDialogPane().getStylesheets().add(STYLE_SHEET);
this.getDialogPane().getButtonTypes().addAll(ButtonType.APPLY, ButtonType.CANCEL);

this.setTitle(NES4J.localeValue("nes4j.palette", true));
this.setTitle(Nes4j.localeValue("nes4j.palette", true));
}

private void initPalette() {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/cn/navclub/nes4j/app/view/DebuggerView.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.navclub.nes4j.app.view;

import cn.navclub.nes4j.app.FXResource;
import cn.navclub.nes4j.app.NES4J;
import cn.navclub.nes4j.app.assets.FXResource;
import cn.navclub.nes4j.app.Nes4j;
import cn.navclub.nes4j.app.control.BreakLine;
import cn.navclub.nes4j.app.control.CPUControlPane;
import cn.navclub.nes4j.app.control.PPUControlPane;
Expand Down Expand Up @@ -53,7 +53,7 @@ public DebuggerView(final Window owner) {
rrun.setTooltip(new Tooltip("re-run"));
stepOut.setTooltip(new Tooltip("step out"));
stepInto.setTooltip(new Tooltip("step into"));
run.setTooltip(new Tooltip(NES4J.localeValue("nes4j.run")));
run.setTooltip(new Tooltip(Nes4j.localeValue("nes4j.run")));

run.setGraphic(new ImageView(FXResource.loadImage("run.png")));
rrun.setGraphic(new ImageView(FXResource.loadImage("rrun.png")));
Expand Down
23 changes: 11 additions & 12 deletions app/src/main/java/cn/navclub/nes4j/app/view/GameWorld.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.navclub.nes4j.app.view;

import cn.navclub.nes4j.app.FXResource;
import cn.navclub.nes4j.app.NES4J;
import cn.navclub.nes4j.app.assets.FXResource;
import cn.navclub.nes4j.app.Nes4j;
import cn.navclub.nes4j.app.audio.NativePlayer;
import cn.navclub.nes4j.app.dialog.DPalette;
import cn.navclub.nes4j.app.event.GameEventWrap;
Expand Down Expand Up @@ -33,7 +33,6 @@
import java.io.File;
import java.nio.ByteBuffer;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.LinkedBlockingDeque;

public class GameWorld extends Stage {
Expand Down Expand Up @@ -65,14 +64,14 @@ public GameWorld(final File file) {
this.eventQueue = new LinkedBlockingDeque<>();
this.debuggerView = new DebuggerView(this);

var view = new Menu(NES4J.localeValue("nes4j.view"));
var tool = new Menu(NES4J.localeValue("nes4j.tool"));
var emulator = new Menu(NES4J.localeValue("nes4j.emulator"));
var view = new Menu(Nes4j.localeValue("nes4j.view"));
var tool = new Menu(Nes4j.localeValue("nes4j.tool"));
var emulator = new Menu(Nes4j.localeValue("nes4j.emulator"));

var debug = new MenuItem(NES4J.localeValue("nes4j.debug"));
var softRest = new MenuItem(NES4J.localeValue("nes4j.reset"));
var pausePlay = new MenuItem(NES4J.localeValue("nes4j.pplay"));
var palette = new MenuItem(NES4J.localeValue("nes4j.palette"));
var debug = new MenuItem(Nes4j.localeValue("nes4j.debug"));
var softRest = new MenuItem(Nes4j.localeValue("nes4j.reset"));
var pausePlay = new MenuItem(Nes4j.localeValue("nes4j.pplay"));
var palette = new MenuItem(Nes4j.localeValue("nes4j.palette"));

palette.setOnAction(this::systemPalette);

Expand Down Expand Up @@ -124,7 +123,7 @@ public GameWorld(final File file) {
if (!(eventType == KeyEvent.KEY_PRESSED || eventType == KeyEvent.KEY_RELEASED)) {
return;
}
for (KeyMapper keyMapper : NES4J.config.getMapper()) {
for (KeyMapper keyMapper : Nes4j.config.getMapper()) {
if (keyMapper.getKeyCode() == code) {
try {
this.eventQueue.put(new GameEventWrap(eventType, keyMapper.getButton()));
Expand Down Expand Up @@ -187,7 +186,7 @@ private void dispose(Throwable t) {
}
if (t != null) {
var dialog = new ExceptionDialog(t);
dialog.setHeaderText(NES4J.localeValue("nes4j.game.error"));
dialog.setHeaderText(Nes4j.localeValue("nes4j.game.error"));
dialog.showAndWait();
// this.close();
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

opens cn.navclub.nes4j.app.config to com.fasterxml.jackson.databind;
opens cn.navclub.nes4j.app.model to javafx.base, com.fasterxml.jackson.databind;
opens cn.navclub.nes4j.app.assets;

uses cn.navclub.nes4j.bin.Player;
}
20 changes: 16 additions & 4 deletions bin/src/main/java/cn/navclub/nes4j/bin/core/Cartridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cn.navclub.nes4j.bin.enums.NESFormat;
import cn.navclub.nes4j.bin.enums.NMapper;
import cn.navclub.nes4j.bin.enums.NameMirror;
import cn.navclub.nes4j.bin.enums.NameTMirror;
import cn.navclub.nes4j.bin.util.ByteUtil;
import cn.navclub.nes4j.bin.util.IOUtil;

Expand Down Expand Up @@ -180,10 +181,7 @@ public Cartridge(byte[] buffer) {
var flag7 = headers[7] & 0xff;
var flag8 = headers[8] & 0xff;


this.mirrors = NameMirror.values()[flag6 & 1];

var mapper = (flag7 & 0b1111_0000) | ((flag6 & 0b1111_0000) >> 4);
var mapper = (flag7 & 0xf0) | ((flag6 & 0xf0) >> 4);

//NES2.0包含12位
if (this.format == NESFormat.NES_20) {
Expand All @@ -196,6 +194,20 @@ public Cartridge(byte[] buffer) {
this.mapper = NMapper.values()[mapper];
}

NameMirror mirrors;
if (((flag6 >> 3) & 0x01) == 1) {
mirrors = NameMirror.FOUR_SCREEN;
} else {
mirrors = NameMirror.values()[flag6 & 1];
}

//UNROM 512 uses %....1..0 to indicate a 1-screen board, and %....1..1 to indicate a 4-screen board.
if (this.mapper == NMapper.UX_ROM && mirrors == NameMirror.FOUR_SCREEN && (flag6 & 0x01) == 0) {
mirrors = NameMirror.SINGLE_SCREEN;
}

this.mirrors = mirrors;

var trainSize = this.trainAreaSize(flag6);

chrom = new byte[chSize];
Expand Down
5 changes: 3 additions & 2 deletions bin/src/main/java/cn/navclub/nes4j/bin/core/PPU.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import cn.navclub.nes4j.bin.enums.MaskFlag;
import cn.navclub.nes4j.bin.enums.NameMirror;
import cn.navclub.nes4j.bin.enums.PStatus;
import cn.navclub.nes4j.bin.screen.Render;
import cn.navclub.nes4j.bin.util.MathUtil;
import lombok.Getter;
import lombok.Setter;

import java.security.PublicKey;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* <a href="https://www.nesdev.org/wiki/PPU_programmer_reference">PPU document</a>
Expand Down Expand Up @@ -108,6 +107,7 @@ public void tick() {
if (this.scanLine >= 262) {
this.nmi = false;
this.scanLine = 0;
//Sprite 0 notify cpu VBL already end.
this.status.clear(PStatus.V_BLANK_OCCUR, PStatus.SPRITE_ZERO_HIT);
}
}
Expand Down Expand Up @@ -191,6 +191,7 @@ public void write(int address, byte b) {

public byte readStatus() {
var b = this.status.getBits();
//Due to every read ppu status clear VBL so can't judge VBL whether end need use sprite zero
this.status.clear(PStatus.V_BLANK_OCCUR);
this.addr.reset();
this.scroll.reset();
Expand Down
Loading

0 comments on commit 7c9a9bb

Please sign in to comment.