smb-vanilla-port
A C and C++ decompilation of the NES games "Super Mario Bros" and "Super Mario Bros: The Lost Levels"
Compact cycle-accurate NES emulator
git clone https://github.com/AndreaOrru/LaiNES.gitAndreaOrru/LaiNESCompact, cycle-accurate NES emulator.
LaiNES should run on any Unix system that is compatible with the following tools.
Install the dependencies:
# Arch Linux: sudo pacman -S clang scons sdl2 sdl2_image sdl2_ttf # Debian-based systems: sudo apt-get install clang scons libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev # Mac OS X: brew install scons sdl2 sdl2_image sdl2_ttf
Compile and run:
git clone --recursive https://github.com/AndreaOrru/LaiNES && cd LaiNES scons -j4 ./laines
The emulator comes bundled with a simple GUI to navigate the filesystem and set preferences. ESC toggles between emulation and menu.
The main menu includes a Reset option to reload and restart the current ROM (only enabled when a ROM is loaded).
LaiNES includes savestate functionality accessible through the main menu (Save State and Load State options). Savestates preserve the complete emulator state including CPU, PPU, APU, mapper state, and expansion audio. Savestates are automatically stored per-ROM and can be loaded at any time.
The size of the window and the controls are customizable. LaiNES supports multiple controllers and should work with joysticks as well. The default controls for the first player are as follows:
LaiNES implements the most common mappers, which should be enough for a good percentage of the games:
You can check the compatibility for each ROM in the following list: http://tuxnes.sourceforge.net/nesmapper.txt
The 6502 CPU and the PPU were originally implemented in just 219 and 283 lines of code respectively, though they have since grown to include full unofficial opcode support and enhanced accuracy. Meta-programming is used extensively to keep the codebase compact. Here is a good example of how that is achieved:
/* Cycle emulation.
* For each CPU cycle, we call the PPU thrice, because it runs at 3 times the frequency. */
#define T tick()
inline void tick() { PPU::step(); PPU::step(); PPU::step(); ... }
...
/* Addressing modes.
* These are all the possible ways instructions can access memory. */
typedef u16 (*Mode)(void);
inline u16 imm() { return PC++; }
...
inline u16 zpx() { T; return (zp() + X) % 0x100; }
...
/* Fetch parameter.
* Get the address of the opcode parameter in a, and the value in p. */
#define G u16 a = m(); u8 p = rd(a)
...
/* Instruction emulation (LDx where x is in registers {A, X, Y}).
* upd_nz, not shown, just updates the CPU flags register. */
template<u8& r, Mode m> void ld() { G; upd_nz(r = p); }
...
/* Execute a CPU instruction.
* Opcodes are instantiated with the right template parameters
* (i.e. register and/or addressing mode).*/
void exec()
{
switch (rd(PC++)) // Fetch the opcode.
{
// Select the right function to emulate the instruction:
...
case 0xA0: return ld<Y,imm>(); case 0xA1: return ld<A,izx>();
...
}
}
export SDL_AUDIODRIVER=ALSA before running the emulator.more like this
A C and C++ decompilation of the NES games "Super Mario Bros" and "Super Mario Bros: The Lost Levels"
search projects, people, and tags