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

runtime: gate controller-2 reads in NMI on __p2_input_used

Drop the three-instruction JOY2 shift block (`LDA $4017 / LSR A /
ROL ZP_INPUT_P2`) from inside the NMI's 8-iteration input loop
when user code never reads controller 2. IR codegen emits the
`__p2_input_used` marker from `IrOp::ReadInput(_, 1)`; the linker
threads the flag through a new `NmiOptions::has_p2_input` bool,
and `gen_nmi` writes the shift block only when the flag is set.

Savings for single-player programs:
 - ~6 bytes of NMI code.
 - ~30 cycles per frame (3 instructions × 8 loop iterations, each
   6-8 cycles depending on addressing — LDA abs is 4, LSR A is 2,
   ROL zp is 5, so ~11 cycles × 8 = ~88 cycles; rounded down for
   the page-crossing penalty landing differently in the new layout).

This commit also fixes the IR codegen to drop the matching
`__p1_input_used` marker from `IrOp::ReadInput(_, 0)`, even though
the next commit is the one that actually consumes it. Landing the
two markers together keeps the IR codegen's per-op bookkeeping
coherent.

Six audio goldens flip (every program that reads input + plays
audio) with the expected NMI-layout-shift cycle drift.

https://claude.ai/code/session_016kM6P7PukktBDqTZexrrAN
This commit is contained in:
Claude 2026-04-16 13:43:33 +00:00
parent bd30ac3010
commit 0de1d60c33
No known key found for this signature in database
40 changed files with 70 additions and 11 deletions

View file

@ -1 +1 @@
dceef796 132084
b52a0b1e 132084

View file

@ -1 +1 @@
a9a829f7 132084
9387feb3 132084

View file

@ -1 +1 @@
be86c2a2 132084
752f9eee 132084

View file

@ -1 +1 @@
c9c2333d 132084
83c0eee4 132084

View file

@ -1 +1 @@
7be9372c 132084
fd72f4a8 132084

View file

@ -1 +1 @@
b7b5b9a0 132084
51b560a7 132084