Skip to content

TheAnsarya/poppy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

365 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒธ Poppy Compiler

Smart multi-system assembly compiler for retro gaming projects

License: Unlicense Version VS Code Tests


๐ŸŽ‰ v2.0.0 Released

Poppy v2.0.0 is now available with Pansy.Core integration, reverse converters, and bank switching! Download the release โ†’


๐ŸŽฏ Overview

Poppy is a production-ready multi-system assembly compiler targeting classic gaming platforms:

Platform CPU Status
NES MOS 6502 โœ… Compile-validated
SNES WDC 65816 โœ… Compile-validated
Game Boy Sharp SM83 โœ… Compile-validated
Atari 2600 MOS 6507 โœ… Compile-validated
Atari Lynx WDC 65C02 โœ… Compile-validated
Genesis Motorola 68000 โœ… Compile-validated
GBA ARM7TDMI โœ… Compile-validated
WonderSwan NEC V30MZ โœ… Compile-validated
Master System Zilog Z80 โœ… Compile-validated
TurboGrafx-16 HuC6280 โœ… Compile-validated

The compiler supports real-world game development with comprehensive tooling, including a VS Code extension with IntelliSense, formatting, and build integration.


โœจ Features

Implemented โœ…

Core Compiler Features:

  • ๐Ÿ“ Clean, lowercase assembly syntax
  • ๐Ÿ”ข $ prefix for hexadecimal values (e.g., $40df)
  • ๐Ÿท๏ธ Labels, local labels, and anonymous labels
  • ๐Ÿ“ .org directive for address setting
  • ๐Ÿ“Š Data directives (.byte, .word, .long, .fill, .ds)
  • ๐Ÿ”€ All 6502 addressing modes
  • ๐Ÿ“ˆ Automatic zero-page optimization
  • ๐Ÿ–ฅ๏ธ Command-line interface

File System & Organization:

  • ๐Ÿ“ฆ .include directive for file inclusion
  • ๐Ÿ“‚ .incbin directive for binary data inclusion
  • ๐Ÿงฉ .asset / .asset_manifest directives for binary/JSON/CHR reinsertion
  • ๐Ÿ”„ Preprocessor with include path resolution
  • ๐Ÿ—‚๏ธ Multi-file project support

Target Systems:

  • ๐ŸŽฎ Full NES/Famicom support (6502)
  • ๐ŸŽจ Full SNES/Super Famicom support (65816)
  • ๐Ÿ•น๏ธ Full Game Boy/Color support (SM83)
  • ๐Ÿ›๏ธ Multiple memory mapping modes (LoROM, HiROM, ExHiROM)
  • ๐Ÿ“‹ All iNES mapper configurations

Label System:

  • ๐Ÿท๏ธ Global labels
  • ๐Ÿ“Œ Local labels with @ prefix and scoping
  • โž• Anonymous forward labels (+, ++, etc.)
  • โž– Anonymous backward labels (-, --, etc.)

Directives & Features:

  • ๐ŸŽฏ Target directives (.nes, .snes, .gb)
  • ๐Ÿ—บ๏ธ Memory mapping (.lorom, .hirom, .exhirom)
  • ๐Ÿ”ง Mapper selection (.mapper)
  • ๐Ÿ“ Alignment directives (.align, .pad)
  • โœ… Compile-time assertions (.assert)
  • โš ๏ธ Error and warning directives (.error, .warning)
  • ๐Ÿ’ฌ Multi-line comments (/* */)

SNES ROM Generation:

  • ๐ŸŽจ SNES header at correct ROM offset ($7fc0 LoROM, $ffc0 HiROM)
  • ๐Ÿ“‹ 11 SNES header directives (.snes_name, .snes_map_mode, etc.)
  • ๐Ÿ—บ๏ธ LoROM, HiROM, and ExHiROM support
  • โœ… Automatic checksum calculation
  • ๐Ÿ”ข ROM speed, type, and region configuration

Game Boy ROM Generation:

  • ๐Ÿ•น๏ธ Game Boy header at $0100-$014f
  • ๐Ÿ“‹ 7 GB header directives (.gb_title, .gb_mbc, .gb_cgb, etc.)
  • ๐ŸŽฎ MBC support (MBC1, MBC3, MBC5, etc.)
  • ๐ŸŒˆ CGB (Color Game Boy) mode flags
  • โœ… Automatic Nintendo logo and checksums
  • ๐Ÿ”‹ RAM size and battery configuration

NES ROM Generation:

  • ๐ŸŽฎ iNES 1.0 and iNES 2.0 header generation
  • ๐Ÿ“‹ 12 iNES header directives (.ines_prg, .ines_chr, .ines_mapper, etc.)
  • ๐Ÿ—บ๏ธ Support for mappers 0-4095, submappers 0-15
  • ๐Ÿ”‹ Battery backup, trainer, mirroring configuration
  • ๐ŸŒ NTSC/PAL timing selection

Macro System:

  • ๐Ÿ”ง Macro definitions with parameters (.macro/.endmacro)
  • ๐ŸŽฏ Macro parameter substitution and default values
  • ๐Ÿท๏ธ Local labels within macros
  • ๐Ÿ” Nested macro invocations

Conditional Assembly:

  • โ“ Conditional compilation (.if/.else/.endif)
  • ๐Ÿ” Symbol existence checks (.ifdef/.ifndef)
  • ๐Ÿ”ข Expression-based conditionals (.ifeq, .ifne, .ifgt, etc.)

Code Generation:

  • ๐Ÿ” Repeat blocks (.rept/.endr) for code generation
  • ๐Ÿ”ข Enumeration blocks (.enum/.ende) for sequential constants
  • ๐Ÿ“Š Listing file generation with symbol tables

Metadata & Verification:

  • ๐ŸŒผ Automatic Pansy metadata generation (symbols, CDL, cross-refs)
  • ๐Ÿ”„ Roundtrip verification against original ROM (byte-for-byte)
  • ๐Ÿ“ฆ Peony project support (peony.json from Nexen game packs)
  • ๐ŸŽฏ --pansy, --no-pansy, --no-verify CLI flags

Developer Tools:

  • ๐ŸŽจ VS Code Extension
    • Syntax highlighting for all platforms
    • IntelliSense with opcode documentation
    • Code formatting with column alignment
    • 40+ code snippets
    • Build task integration
    • Go-to-definition and hover info
  • ๐Ÿ“Š Comprehensive error messages with context
  • ๐Ÿงฎ Advanced expression evaluation
  • ๐Ÿ“‹ Multiple output formats (ROM, symbols, listings, memory maps)

Format Export:

  • ๐Ÿ”„ PASM-to-ASAR exporter (.asm output)
  • ๐Ÿ”„ PASM-to-CA65 exporter (.s output with .โ†’@ local label conversion)
  • ๐Ÿ”„ PASM-to-XKAS exporter (;โ†’// comment conversion)
  • ๐Ÿญ ExporterFactory for extensible format registration
  • ๐Ÿ“ Automatic directive translation via reverse mapping tables

๐Ÿš€ Quick Start

Installation

From GitHub Releases

Download the latest release from GitHub Releases.

From Source

# Clone the repository
git clone https://github.com/TheAnsarya/poppy.git
cd poppy

# Build the compiler
cd src
dotnet build -c Release

# The compiler will be at: src/Poppy.CLI/bin/Release/net10.0/poppy.exe

VS Code Extension

Install the "Poppy Assembly" extension from the Visual Studio Code Marketplace for the best development experience.

Usage

# Basic assembly
poppy game.pasm                     # Output: game.bin

# Specify output file
poppy -o rom.nes game.pasm          # Output: rom.nes

# Generate debug symbols
poppy -s game.nl game.pasm          # Creates FCEUX .nl symbol file
poppy -s game.mlb game.pasm         # Creates Mesen .mlb symbol file
poppy -s game.sym game.pasm         # Creates generic .sym symbol file

# Generate listing file
poppy -l game.lst game.pasm         # Creates symbol table listing

# Verbose output
poppy -V game.pasm                  # Shows compilation progress

# Target different architectures
poppy -t 6502 game.pasm             # NES (default)
poppy -t 65816 game.pasm            # SNES
poppy -t sm83 game.pasm             # Game Boy

# Pansy metadata & roundtrip verification
poppy game.pasm -o game.nes         # Auto-generates game.pansy
poppy game.pasm --no-pansy          # Disable Pansy generation
poppy game.pasm --no-verify         # Disable roundtrip verification
poppy game.pasm --pansy out.pansy   # Custom Pansy output path

# Export to other assembler formats
poppy export game.pasm --to asar    # Export to ASAR format (.asm)
poppy export game.pasm --to ca65    # Export to CA65 format (.s)
poppy export game.pasm --to xkas    # Export to XKAS format (.asm)
poppy export src/ --to asar         # Export entire project directory

# Genesis asset-manifest workflow (conversion + inclusion)
poppy --platform genesis src/main.pasm -o build/game.bin

Example Assembly (NES/6502)

; Example NES ROM with iNES 2.0 header
.nes
.ines_prg 2        ; 32KB PRG ROM
.ines_chr 1        ; 8KB CHR ROM
.ines_mapper 0     ; NROM mapper
.ines_mirroring 1  ; vertical mirroring

; Constants
PPU_CTRL = $2000
PPU_MASK = $2001
PPU_STATUS = $2002

; Reset vector
.org $8000

reset:
    sei
    cld
    ldx #$ff
    txs

    lda #$00
    sta PPU_CTRL
    sta PPU_MASK

@wait_vblank1:
    bit PPU_STATUS
    bpl @wait_vblank1

@wait_vblank2:
    bit PPU_STATUS
    bpl @wait_vblank2

main_loop:
    jmp main_loop

; NMI handler
nmi:
    rti

; IRQ handler  
irq:
    rti

; Interrupt vectors
.org $fffa
.word nmi        ; NMI vector
.word reset      ; Reset vector
.word irq        ; IRQ/BRK vector

Advanced Features

Local Labels

subroutine1:
@local_loop:     ; local to subroutine1
    dex
    bne @local_loop
    rts

subroutine2:
@local_loop:     ; different local scope
    dey
    bne @local_loop
    rts

Anonymous Labels

; Forward references (+)
lda #$00
beq +            ; jump to next +
lda #$01
+:
sta $2000

; Backward references (-)
-:
lda ($00),y
sta $2007
iny
bne -            ; jump to previous -

File Inclusion

.include "constants.inc"
.include "macros.inc"

; Binary data inclusion
.org $a000
.incbin "graphics.chr"

Compile-Time Assertions

.assert * < $8000, "Code exceeds PRG ROM bank"
.error "Not implemented yet"
.warning "TODO: Optimize this section"

Examples

Check out the example projects in the examples/ directory:


๐Ÿ“– Documentation

User Guides

Document Description
User Manual Complete usage guide with examples
Channel F Development Guide Channel F/F8 project layout, syntax, and coding patterns
SNES Development Guide Comprehensive SNES/65816 guide
Game Boy Development Guide Complete GB/GBC guide with SM83
Atari Lynx Guide Atari Lynx/65C02 assembly guide
System Syntax Reference Per-system .target, CLI platform commands, and baseline syntax
Build from Project Nexen โ†’ Peony โ†’ Poppy pipeline
Project File Format .poppy project configuration
Syntax Specification Assembly language syntax guide

Migration Guides

Document Description
Migrating from ASAR ASAR โ†’ Poppy for SNES
Migrating from ca65 ca65/cc65 โ†’ Poppy for NES/SNES
Migrating from xkas xkas โ†’ Poppy for SNES
Migrating from RGBDS RGBDS โ†’ Poppy for Game Boy
Migrating from WLA-DX WLA-DX โ†’ Poppy for Z80/6502/65816
Migrating from DASM DASM โ†’ Poppy for Atari 2600
Migrating from ASM68K ASM68K โ†’ Poppy for Genesis
Migrating from devkitARM devkitARM/GAS โ†’ Poppy for GBA

Technical Reference

Document Description
Architecture Compiler design and structure
Benchmarks BenchmarkDotNet suite and ARM special-emission benchmark workflows
PASM File Format Poppy Assembly .pasm file format specification
CDL/DIZ Workflow Poppy โ†” Peony roundtrip workflow with CDL/DIZ files
File Formats ROM and patch format reference
Resources External links and research
Release Notes v1.0.0 Complete v1.0.0 release summary

Planning Documents

Document Description
Roadmap Development roadmap and milestones (v1.0 complete!)
v1.x Roadmap Plans for v1.1-v1.3 (project system, assets, advanced features)
v2.0 Roadmap Platform expansion (GBA, Genesis, SPC700, LSP, WASM)
v1.0.0 Release Report Complete v1.0.0 release summary
All Plans Architecture plans, encoding specs, issue analysis

Internal Documentation

Document Description
Chat Logs AI conversation archives
Session Logs Work session summaries

๐ŸŽฎ Target Projects

Priority compilation targets:

  1. Dragon Warrior 1 (NES) - Simple NES game
  2. Final Fantasy Mystic Quest (SNES) - Simple SNES game
  3. Dragon Warrior 4 (NES) - Complex NES game
  4. Dragon Quest 3 Remake (SNES) - Complex SNES project

๐Ÿ“ Syntax Highlights

Hexadecimal Notation

lda #$40        ; immediate value
sta $2000       ; absolute address
lda $10,x       ; zero page indexed

Labels and References

start:
lda #$01
jsr subroutine
jmp start

subroutine:
inc $10
rts

Include Directives

.include "constants.inc"
.include "macros.inc"

; Asset with convertor (planned)
.asset "graphics.png" png2chr

๐Ÿ—๏ธ Project Status

Current Version: v2.0.0 (Released 2026)

Completed:

  • โœ… Full NES support (6502, iNES 2.0)
  • โœ… Full SNES support (65816, LoROM/HiROM/ExHiROM)
  • โœ… Full Game Boy support (SM83, MBC1/3/5, CGB modes)
  • โœ… Full Atari 2600 support (6507)
  • โœ… Full Atari Lynx support (65C02)
  • โœ… Complete macro system with parameters
  • โœ… Conditional assembly (.if, .ifdef, .ifndef)
  • โœ… Include system (.include, .incbin)
  • โœ… Debug symbol export (.sym, .nl, .mlb)
  • โœ… Reverse converters (PASM โ†’ ASAR/CA65/XKAS)
  • โœ… VS Code extension (published to marketplace)
  • โœ… Comprehensive documentation (21 guides, 5,800+ lines)
  • โœ… Example projects for all platforms
  • โœ… Pansy.Core integration for metadata export
  • โœ… Bank switching support
  • โœ… 3,185 tests passing

Planned:

  • Language Server Protocol (LSP)
  • Web-based compiler (WASM)
  • Plugin system

See v1.x Roadmap and v2.0 Roadmap for details.


๐Ÿ“‹ Coding Standards

This project follows strict formatting guidelines:

  • Indentation: TABS only (never spaces)
  • Brace Style: K&R (opening brace on same line)
  • Hexadecimal: Always lowercase with $ prefix
  • Assembly: Lowercase opcodes (lda, sta, jsr)
  • Encoding: UTF-8 with BOM
  • Line Endings: CRLF

See .github/copilot-instructions.md for complete guidelines.


๐ŸŒท Integrated Pipeline

Poppy is the build stage of the Flower Toolchain โ€” an integrated pipeline for playing, debugging, disassembling, editing, and rebuilding retro games:

Stage Tool Poppy Role
1. Play & Debug Nexen โ€”
2. Disassemble Peony โ€”
3. Edit & Document Editor + Pansy UI โ€”
4. Build Poppy Compile .pasm โ†’ ROM, generate Pansy metadata
5. Verify Game Garden Roundtrip byte-identical rebuild

See the Integrated Pipeline Master Plan for architecture details.

๐Ÿค Related Projects


๐Ÿ“œ License

See the LICENSE file for details (Unlicense)


๐Ÿ”— References

Inspired by and learning from:

  • ASAR - SNES patching assembler
  • XKAS - SNES assembler
  • Ophis - 6502 assembler
  • ca65 - Part of cc65 suite

๐ŸŒธ Poppy - Making retro game development bloom

About

Smart compiler for retro gaming projects

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors