mirror of
https://github.com/imjasonh/nescript
synced 2026-07-08 17:06:04 +00:00
A small example that exercises all three inline-assembly paths in
one program:
- \`asm { ... }\` with \`{var}\` substitution for \`result\` and
\`frame_count\`
- \`poke(addr, value)\` for a hardware register write (PPU \$2005)
- A helper function whose body is hand-written 6502 that still
reads and writes NEScript-owned local variables
Useful as a short reference for anyone learning the escape hatches
to hand-written 6502.
https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
|
||
|---|---|---|
| .. | ||
| arrays_and_functions.ne | ||
| bouncing_ball.ne | ||
| coin_cavern.ne | ||
| hello_sprite.ne | ||
| inline_asm_demo.ne | ||
| mmc1_banked.ne | ||
| README.md | ||
| sprites_and_palettes.ne | ||
| state_machine.ne | ||
| structs_enums_for.ne | ||
NEScript Examples
Quick Start
# Build the compiler
cargo build --release
# Compile all examples
for f in examples/*.ne; do cargo run -- build "$f"; done
# Or compile one
cargo run -- build examples/hello_sprite.ne
Open any .nes file in an NES emulator (Mesen, FCEUX, etc.)
Examples
| File | Features | Description |
|---|---|---|
hello_sprite.ne |
input, draw | Move a sprite with the d-pad |
bouncing_ball.ne |
if/else, variables | Auto-bouncing sprite with edge detection |
coin_cavern.ne |
states, functions, constants | 3-state game with gravity and coin collection |
arrays_and_functions.ne |
arrays, functions, while | Enemy array with collision detection |
state_machine.ne |
on enter/exit, transitions | Multi-state flow with timers |
sprites_and_palettes.ne |
sprites, palettes, scroll, cast | Inline CHR data, palette switching, type casting |
mmc1_banked.ne |
MMC1, banks, multiply | Banked mapper with software multiply |
Emulator Controls
| NES Button | Typical Key |
|---|---|
| D-pad | Arrow keys |
| A | Z |
| B | X |
| Start | Enter |
| Select | Right Shift |
About Sprites
Sprite names in draw Player at: (x, y) are parsed and recorded in the AST.
You can define sprites with inline CHR tile data:
sprite Player {
chr: [0x3C, 0x42, 0x81, 0x81, 0x81, 0x81, 0x42, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
}
If no matching sprite declaration exists, the draw uses the built-in default
tile (a smiley face). See sprites_and_palettes.ne for a full example.
Compiler Commands
# Compile to ROM
cargo run -- build game.ne
# Custom output path
cargo run -- build game.ne --output my_game.nes
# Type-check only
cargo run -- check game.ne
# View generated 6502 assembly
cargo run -- build game.ne --asm-dump
# Debug mode
cargo run -- build game.ne --debug