# pcengine.asm
A two-pass HuC6280 assembler (65C02 + HuC6280 extras) written in Luau, used to
build the PC Engine package's homebrew HuCards inside the engine; any
6502/65C02 machine's homebrew can use it too. Labels and `.local` labels,
`equ`/`=`, `bank`/`org` for 8 KB HuCard banks, `db/dw/ds`, `align`, `assert`,
expressions (`*`/`$` = here, `lo()`/`hi()`/`bank(label)`), every 65C02
addressing mode with `[zp]` or `(zp)` indirect, and the HuC6280 forms
(`tst #i, ea`, `tii s, d, n` and friends, `bbr0 zp, label`, `smb3 zp`,
`st0 #i`, `tam #mask`). Zero page is chosen by `<expr` or a value known in
pass 1, so sizes never change between passes (see the header of `init.luau`).
```lua
local Asm = require("pcengine.asm")
local bin, symbols = Asm.assemble(sourceText, { size = 0x8000, fill = 0xFF })
```
# pcengine
A NEC PC Engine / TurboGrafx-16 emulator written in Luau, packaged as an
`emulatorCore` so the console appears on the room's console TVs beside the
NES, Game Boy, Neo Geo, Mega Drive and Master System. Players upload their own
`.pce` HuCards (or a zip of one); the shelf carries original homebrew written
for this package and released under CC0.
- `pcengine_core.emulatorCore` — the console spec: 512×240 at 59.83 Hz (256 / 336 / 512-pixel modes all span the tube), worker thread, pad bar D-pad / I / II / Run / Select, pad 2 through the multitap, 44.1 kHz stereo, Tennokoe-style backup RAM under `pcengine_saves/`, save states.
- `huc6280.module` (`require("pcengine.huc6280")`) — the HuC6280 CPU: 65C02 core plus MMU (TAM/TMA, 8 KB pages of a 21-bit space), block transfers, T flag, CSL/CSH, ST0-2, BBR/BBS/RMB/SMB, TST, timer and interrupt controller. Reusable by any 65C02-family machine.
- `machine.module` (`require("pcengine.machine")`) — the machine: HuC6270 VDC line renderer (BAT with virtual sizes, 64 sprites 16×16..32×64 with the 16-per-line limit, overflow and sprite-0 collision, per-line scroll latch, RCR + vblank IRQs, VRAM→VRAM and SATB DMA, burst mode), HuC6260 VCE (512 colours, three dot clocks), PSG (6 wavetable channels, DDA, noise, LFO, balance → 44.1 kHz), HuCard loader (.pce, copier header, zip, 384 KB layout), joypad + multitap, backup RAM gate, 263×455 scheduler, save states.
- `asm.module` (`require("pcengine.asm")`) — a two-pass HuC6280 assembler, reusable for any 65C02 machine.
- `homebrew.module` (`require("pcengine.homebrew")`) — the HuC6280 runtime (raster-split table, multitap pads, music + SFX drivers, text), Luau art/music helpers and the games below; `build()` writes the carts.
- `tests/cpu_tests.luau` (54 checks) and `tests/pce_tests.luau` (78 checks, incl. PSG LFO and timer-driven DDA).
## Games on the shelf (all CC0 1.0, written for this package)
The engine has no network access, so no published homebrew could be fetched;
these HuCards were written here in HuC6280 assembly and are released under
**CC0 1.0 Universal** (public domain dedication: copy, modify, redistribute,
commercially or not, without asking). Source: `homebrew.module/*.luau`.
| HuCard | players | what it shows |
|---|---|---|
| `pcengine_roms/nebula_storm.pce` — Nebula Storm | 1 | horizontal shooter: four parallax bands split by raster-compare interrupts under a fixed status bar, ~60 sprites (32×16 ship, waves, aimed bullets, explosions, a 64×32 boss), palette-cycled stars, 3-voice wavetable music with sampled DDA kick + snare streamed by the timer interrupt, high score in backup RAM |
| `pcengine_roms/tank_duel.pce` — Tank Duel | 1-2 (CPU drives tank 2 until a pad-2 button is pressed) | arena duel in the 336-pixel mode, both pads through the multitap, bouncing shells, first to 5, DDA drums |
Every game advances the zero-page byte `$2000` (RAM offset 0) once per logic
step: the logic-rate probe (`m:watchRam(0)`).
## Not emulated
CD-ROM², SuperGrafx, Arcade Card, the Street Fighter II mapper, Populous cart RAM, US bit-reversed dumps, PAL, mid-line raster effects, 6-button pads.