Skip to content

Illegal#126

Merged
mre merged 8 commits intomasterfrom
illegal
Feb 6, 2026
Merged

Illegal#126
mre merged 8 commits intomasterfrom
illegal

Conversation

@omarandlorraine
Copy link
Collaborator

I'm working my way through a list I found of illegal opcodes.

I'm adding these to the NMOS variant, but I'm not feeling settled about that. I think it ought to go in another variant, so that the Nmos6502 will terminate if it hits a bad opcode. Is that the correct approach?

As I recall @mre mentioned a timing related test which can't be enabled yet because it also exercises illegal opcodes. Will this test also do to make sure that the illegal opcodes work in the expected ways?

I'm planning to leave out some of the Real Weirdos, like the addressing mode which mixes immediate and absolute-indexed

closes #125

@omarandlorraine
Copy link
Collaborator Author

Obviously there's loads more to go.

I'm planning to do one commit per instruction so we can leave out any deemed too unstable

@mre
Copy link
Owner

mre commented Jan 20, 2026

Very nice!

I'm adding these to the NMOS variant, but I'm not feeling settled about that. I think it ought to go in another variant, so that the Nmos6502 will terminate if it hits a bad opcode. Is that the correct approach?

Does the real Nmos6502 terminate at an illegal opcode? If so, I agree that we should add a new variant. If not it would be more accurate to keep the illegal opcodes in the existing variant in my opinion.

@mlund mlund mentioned this pull request Jan 26, 2026
@mlund
Copy link

mlund commented Jan 26, 2026

Very nice!

I'm adding these to the NMOS variant, but I'm not feeling settled about that. I think it ought to go in another variant, so that the Nmos6502 will terminate if it hits a bad opcode. Is that the correct approach?

Does the real Nmos6502 terminate at an illegal opcode? If so, I agree that we should add a new variant. If not it would be more accurate to keep the illegal opcodes in the existing variant in my opinion.

Nmos6502 executes the illegal opcode so no need for a new variant. https://github.com/mlund/mos6502/tree/illegal

omarandlorraine and others added 4 commits January 27, 2026 12:45
The illegal opcodes implementation caused README doc tests to hang:

1. First example used 0xff as program terminator
   - Previously 0xff was unimplemented (returned None), stopping execution
   - Now 0xff is ISC (INC+SBC) AbsoluteX, causing infinite loop
   - Fix: Use 0x02 (JAM) which explicitly halts the CPU

2. Second example loads euclid.bin which uses BRK (0x00) to terminate
   - BRK jumps to IRQ vector at $FFFE/$FFFF
   - Uninitialized memory contains 0x00, jumping to address $0000
   - This causes infinite loop executing whatever is in low memory
   - Fix: Mark as no_run since it depends on external file anyway
- Replace BRK with JAM ($02) to halt CPU after illegal opcodes impl
- Fix assembly label structure (algo/algo_ were dead infinite loops)
- Simplify linker.cfg to output raw binary at $0010 (was 64KB image)
- Enable README doc test (remove no_run marker)

The old linker config produced a 64KB memory image with code at $0400,
but README loaded at $0010 causing address mismatch. New config outputs
only the code segment at the correct load address.
@omarandlorraine
Copy link
Collaborator Author

This PR now incorporates everything mlund did. I'll be marking it as ready for review.

@omarandlorraine omarandlorraine marked this pull request as ready for review January 27, 2026 12:48
@omarandlorraine
Copy link
Collaborator Author

@mre should I go ahead and merge this?

@mre
Copy link
Owner

mre commented Feb 6, 2026

Sorry for the late reply. I got sidetracked with so many other things. Will take a look quick.

Copy link
Owner

@mre mre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the contribution @mlund and @omarandlorraine. 🫶

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this, but it seems reasonable.

@mre mre merged commit c91d604 into master Feb 6, 2026
7 checks passed
@mre mre deleted the illegal branch February 6, 2026 15:19
@mre mre mentioned this pull request Feb 6, 2026
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.

No illegal opcodes

3 participants