Giter Club home page Giter Club logo

nes4j's Introduction

Nes4j logo

Nes4j

Nintendo red and white simulator

nes4j DuckTables Super Mario

Project introduction

nes4jThe Nintendo Red and White Machine Simulator is implemented in Java language, mainly including CPUPPU and APU Three parts.PPU is a red and white machine It is difficult to understand the most difficult module.

Project Structure

nes4j
├── app UI module(javafx)
├── bin Simulator core module (CPU/PPU/APU)
└── document Development Documentation

Quick start

Download project

git clone https://gitee.com/navigatorCode/nes4j.git

Start project

 mvn run

Support cartridge mapper

More cartridge mapper are being implemented, please wait.

The core module is introduced separately

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.

First introduce dependency

  • Apache Maven
<dependency>
    <groupId>cn.navclub</groupId>
    <artifactId>nes4j-bin</artifactId>
    <version>1.0.6</version>
</dependency>
  • Gradle(groovy)
implementation group: 'cn.navclub', name: 'nes4j-bin', version: '1.0.6'

or

implementation 'cn.navclub:nes4j-bin:1.0.6'
  • Gradle(Kotlin)
implementation("cn.navclub:nes4j-bin:1.0.6")

Then create an NES instance and initialize

  • GameWorld.java
import cn.navclub.nes4j.bin.NesConsole;
import cn.navclub.nes4j.bin.io.JoyPad;
import cn.navclub.nes4j.bin.ppu.Frame;

public class GameWorld {
    public NES create() {
        NesConsole console = NesConsole.Builder
                .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
            console.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
@SuppressWarnings("all")
public class JavaXAudio implements Player {
    private final byte[] sample;
    private final byte[] buffer;
    private final Line.Info info;
    private final AudioFormat format;
    private final SourceDataLine line;
    private int ldx;
    //Current fill index
    private int index;
    private final Thread thread;
    private volatile boolean stop;
    private final static int SAMPLE_SIZE = 55;

    private static final LoggerDelegate log = LoggerFactory.logger(JavaXAudio.class);


    public JavaXAudio(Integer sampleRate) throws LineUnavailableException {
        this.sample = new byte[SAMPLE_SIZE];
        this.buffer = new byte[SAMPLE_SIZE];
        this.thread = new Thread(this::exec);
        this.format = new AudioFormat(sampleRate, 8, 1, false, false);
        this.info = new DataLine.Info(SourceDataLine.class, format);
        this.line = (SourceDataLine) AudioSystem.getLine(info);

        line.open(format);
        line.start();

        this.thread.start();
    }

    @Override
    public void output(byte sample) {
        this.buffer[this.index] = sample;
        this.index++;
        if (this.index == SAMPLE_SIZE) {
            this.index = 0;
            System.arraycopy(this.buffer, 0, this.sample, 0, SAMPLE_SIZE);
            LockSupport.unpark(this.thread);
        }
        this.index %= SAMPLE_SIZE;
    }


    private void exec() {
        while (!this.stop) {
            LockSupport.park();
            this.line.write(this.sample, 0, SAMPLE_SIZE);
        }
    }

    @Override
    public void stop() {
        this.stop = true;
        LockSupport.unpark(this.thread);
        this.line.close();
    }

    @Override
    public void reset() {
        this.index = 0;
    }
}

Participatory contributions

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 👏。

Copyright Description

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.

Development

document

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:

Assembly debugging(Experimental)

Main interface -> Tool -> Debug

Assembler

Snapshot memory view (Memory)

Assembler

Custom Instructions

For the convenience of program debugging and development, the simulator will continuously add custom instructions internally.

  • LOG($FF) log output instruction
LOG        =        $FF
NULL       =        0

.segment            "STARTUP"

start:
.byte LOG,"ra=\{c.a},rx={c.x},ry={c.y}",NULL
sei
clc
lda #$80
sta PPU_CTRL                    ;Enable val flag
jmp waitvbl
...

String support class string template function, only supports built-in variables such as c.a, c.x, c.y, etc. in the above code.

变量 描述
c.a CPU cumulative register
c.x CPU X register
c.y CPU Y register
c.s CPU Stack Pointer

Consider adding PPU, APU, and simulator related register variables in the later stage.

Special thanks

name describe
Jetbrain Provide a complete set of integrated development environment
NES forum Provide technical support

nes4j's People

Contributors

gzyangkui avatar tianzerl avatar

Stargazers

Cylix Lee avatar JS avatar  avatar  avatar Taketoday avatar  avatar Konstantin Firsov avatar endlessspace avatar  avatar Jason Wang avatar 伏毅 avatar Alexander Pishvanov avatar codingriver avatar  avatar 王晓峰 avatar Y avatar  avatar 不伤手的白猫 avatar  avatar  avatar Extra avatar Free Zhang avatar arctic1106 avatar zhengkai avatar chaosliang avatar luhua avatar Zhuoheng Lee avatar Jenkins avatar 夏文純一 avatar  avatar zhangningwei avatar roc avatar Tom avatar  avatar  avatar SPARON avatar Marco Lopez avatar Raph avatar XUranus avatar  avatar New Coder avatar XueQB avatar Nicola Ken Barozzi avatar  avatar George avatar Chaos John avatar  avatar Thiago Patrício avatar alan avatar autumo avatar groovyquan avatar 王福强 avatar Devm avatar  avatar  avatar BleethNie avatar  avatar Fanon Jupkwo avatar

Watchers

Fanon Jupkwo avatar  avatar  avatar

nes4j's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.