nes4jThe Nintendo Red and White Machine Simulator is implemented in Java language, mainly including CPU、 PPU and APU Three parts.PPU is a red and white machine It is difficult to understand the most difficult module.
nes4j
├── app UI module(javafx)
├── bin Simulator core module (CPU/PPU/APU)
└── document Development Documentation
git clone https://gitee.com/navigatorCode/nes4j.git
mvn run
More cartridge mapper are being implemented, please wait.
If you feel that the current game output program cannot meet your needs, you can provide PR to us, and we will try our best to meet your needs. Another way is to introduce nes4j bin module yourself to achieve video and audio output of the game.
- Apache Maven
<dependency>
<groupId>cn.navclub</groupId>
<artifactId>nes4j-bin</artifactId>
<version>1.0.1</version>
</dependency>
- Gradle(groovy)
implementation group: 'cn.navclub', name: 'nes4j-bin', version: '1.0.1'
or
implementation 'cn.navclub:nes4j-bin:1.0.1'
- Gradle(Kotlin)
implementation("cn.navclub:nes4j-bin:1.0.1")
- GameWorld.java
import cn.navclub.nes4j.bin.NES;
import cn.navclub.nes4j.bin.io.JoyPad;
import cn.navclub.nes4j.bin.ppu.Frame;
public class GameWorld {
public NES create() {
NES instance = NES.NESBuilder
.newBuilder()
//nes game rom
.file(file)
//Audio Handler
.player(JavaXAudio.class)
//Game loop callback
.gameLoopCallback(GameWorld.this::gameLoopCallback)
.build();
try {
//Current method was called current will block current thread until game stop or exception occurred
instance.execute();
} catch (Exception e) {
//todo An error occurred during the game.Once error occurred game immediate stop
}
}
//This function was callback when a game frame generate
private void gameLoopCallback(Frame frame, JoyPad joyPad, JoyPad joyPad1) {
}
}
- JavaXAudio.java
package cn.navclub.nes4j.app.audio;
import cn.navclub.nes4j.bin.apu.Player;
import javax.sound.sampled.*;
import static cn.navclub.nes4j.bin.util.BinUtil.int8;
@SuppressWarnings("all")
public class JavaXAudio implements Player {
private final byte[] sample;
private final Line.Info info;
private final AudioFormat format;
private final SourceDataLine line;
private int index;
public JavaXAudio() throws LineUnavailableException {
this.sample = new byte[735 * 2];
this.format = new AudioFormat(44100, 8, 1, false, false);
this.info = new DataLine.Info(SourceDataLine.class, format);
this.line = (SourceDataLine) AudioSystem.getLine(info);
line.open(format);
line.start();
}
//When a audio sample generate call this function
@Override
public void output(float sample) {
var value = int8(Math.round(sample * 0xff));
this.sample[this.index++] = value;
if (this.index == this.sample.length) {
this.index = 0;
this.line.write(this.sample, 0, this.sample.length);
}
}
//When Nes instance stop or error occurred call this function
@Override
public void stop() {
this.line.close();
}
}
We strongly welcome interested developers to participate in the project construction, and welcome everyone to put forward valuable suggestions and functional requirements for the project. The project is being actively developed, and welcome PR 👏。
At present, most of the game copyrights in the market are owned by Nintendo. Do not distribute the game without permission from Nintendo If any infringement is caused thereby, it has nothing to do with the software. If any infringing material is designed in the software, please send an email to [email protected] Notify me to delete the corresponding infringing materials.
If you want to write your own simulator or understand the internal structure of the simulator, the following resources can provide you with some basic knowledge of the simulator:
name | describe |
---|---|
Jetbrain | Provide a complete set of integrated development environment |
NES forum | Provide technical support |