Skip to content

Fix interrupt(): clear INTE on acceptance, EI delay, 11 T-states; remove global T - #14

Merged
maly merged 1 commit into
masterfrom
agent/issue-13-interrupt-inte-ei-delay
Oct 17, 2026
Merged

maly merged 1 commit into
masterfrom
agent/issue-13-interrupt-inte-ei-delay

Conversation

@maly

@maly maly commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Closes #13

Changes (8080.js)

  • Interrupt acceptance (interrupt(vector)): clears INTE and any pending EI, wakes a halted CPU, pushes PC, jumps to the vector and adds 11 T-states. The vector uses an explicit undefined check, so interrupt(0) now jumps to 0x0000 (the default is still 0x38).
  • EI delay: EI sets eiPending, and INTE becomes 1 only after the following instruction, so EI; RET at the end of a handler is safe. DI clears INTE and cancels a pending EI. reset and the Cpu constructor initialise eiPending.
  • No global T: removed the undeclared T=0; in steps().

Deviation from the proposed snippet: the issue's step() applied the pending enable after executing the next instruction. With that code, EI; DI would end with interrupts enabled, because DI's clear gets overwritten, and that contradicts the "DI cancels a pending EI" requirement. Interrupts are only accepted between step() calls, so this PR sets INTE right before the instruction after EI. Seen from outside, the timing is identical: no interrupt can be taken between EI and the next instruction. A following DI now correctly wins.

Tests

  • New Interrupts suite in test/node/cpu8080.test.js covering:
    • acceptance after EI plus one instruction: PC, pushed return address, +11 T
    • a second request is ignored (PC, SP and T unchanged) until the handler executes EI plus one instruction
    • a request right after EI is ignored
    • EI; HLT followed by an interrupt wakes the CPU and returns after HLT
    • DI cancels a pending EI
    • interrupt(0) jumps to 0x0000 and the default vector is 0x38
    • reset clears a pending EI
    • no globalThis.T after steps()
  • The reset tests in test/node/cpu8080.test.js and test/tests.js (QUnit) now step twice to get past the EI delay.
  • npm test: 18/18 pass, including the cpudiag diagnostic. The reproduction from the issue now prints 38 11, 38, undefined.

Docs

  • README API section documents interrupt(vector).

…emove global T

- interrupt() now clears INTE (and a pending EI), wakes from HLT, pushes PC,
  jumps to the vector (interrupt(0) -> 0x0000, default 0x38) and adds 11 T-states
- EI enables interrupts only after the following instruction; DI cancels a pending EI
- reset clears a pending EI
- remove the undeclared T=0 in steps() that leaked a global
- add Interrupts regression tests, adjust reset tests for the EI delay
- document interrupt() in README

Closes #13
@maly
maly merged commit fc471f7 into master Oct 17, 2026
4 checks passed
@maly
maly deleted the agent/issue-13-interrupt-inte-ei-delay branch October 17, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

interrupt(): INTE not cleared on acceptance, no EI delay, 0 T-states charged; steps() leaks a global T

1 participant