1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-08 17:06:04 +00:00
nescript/examples
Claude 28cb739840
examples: inline_asm_demo.ne
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
2026-04-12 18:02:59 +00:00
..
arrays_and_functions.ne Add README, LICENSE, examples, fix draw parser lookahead 2026-04-12 00:38:19 +00:00
bouncing_ball.ne Add example builds to CI, document sprite name behavior 2026-04-11 22:55:43 +00:00
coin_cavern.ne M2: Wire IR pipeline, add Coin Cavern example and integration tests 2026-04-11 23:34:35 +00:00
hello_sprite.ne Add example builds to CI, document sprite name behavior 2026-04-11 22:55:43 +00:00
inline_asm_demo.ne examples: inline_asm_demo.ne 2026-04-12 18:02:59 +00:00
mmc1_banked.ne Add README, LICENSE, examples, fix draw parser lookahead 2026-04-12 00:38:19 +00:00
README.md Add README, LICENSE, examples, fix draw parser lookahead 2026-04-12 00:38:19 +00:00
sprites_and_palettes.ne Add README, LICENSE, examples, fix draw parser lookahead 2026-04-12 00:38:19 +00:00
state_machine.ne Add README, LICENSE, examples, fix draw parser lookahead 2026-04-12 00:38:19 +00:00
structs_enums_for.ne Language: struct literals 2026-04-12 17:15:57 +00:00

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