1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-08 08:55:38 +00:00

Codegen: MMC3 on_scanline IRQ dispatch (minimal)

Wires \`on scanline(N)\` handlers through IR lowering and codegen:

- IR lowering: each scanline handler becomes a regular IR function
  named \`{state}_scanline_{N}\`
- IR codegen: when any scanline handler exists, emits MMC3 IRQ setup
  at program start (\$C000 latch, \$C001 reload, \$E001 enable, CLI)
  and a \`__irq_user\` handler that saves registers, acknowledges via
  \$E000, JSRs the scanline handler, restores registers, and RTIs
- Linker: vector table prefers \`__irq_user\` over the default \`__irq\`
  stub when both exist

Scope of this first pass is intentionally minimal: supports ONE
scanline handler per program (the first one found in IR function
order). Per-state dispatch and multi-scanline reload will come later.

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
Claude 2026-04-12 16:22:54 +00:00
parent 281198cbb9
commit 359241d906
No known key found for this signature in database
4 changed files with 123 additions and 2 deletions

View file

@ -141,6 +141,21 @@ fn program_with_functions() {
rom::validate_ines(&rom_data).expect("should be valid iNES");
}
#[test]
fn program_with_on_scanline_mmc3() {
let source = r#"
game "Scanline" { mapper: MMC3 }
var sx: u8 = 0
state Main {
on frame { wait_frame }
on scanline(120) { scroll(sx, 0) }
}
start Main
"#;
let rom_data = compile(source);
rom::validate_ines(&rom_data).expect("should be valid iNES");
}
#[test]
fn program_with_structs() {
let source = r#"