Skip to content

Comments

Complete the WDC 65C02 instruction set implementation#121

Merged
mre merged 2 commits intomasterfrom
add-cmos-instructions
Dec 31, 2025
Merged

Complete the WDC 65C02 instruction set implementation#121
mre merged 2 commits intomasterfrom
add-cmos-instructions

Conversation

@mre
Copy link
Owner

@mre mre commented Dec 30, 2025

This commit finishes implementing the standard Western Design Center 65C02 instruction set by adding the last missing instructions.

The main additions are the two low-power instructions WAI (Wait for Interrupt) and STP (Stop Processor), which allow the CPU to enter power-saving modes. I also added support for the BIT instruction with indexed addressing modes (zero page indexed and absolute indexed), and the indexed indirect jump instruction JMP (abs,X).

Additionally, the Cmos6502 variant now has better documentation that aims to explain all the improvements over the original NMOS 6502.

This closes issue #120.

@mre mre requested a review from omarandlorraine December 30, 2025 18:43
@mre mre force-pushed the add-cmos-instructions branch from 6b19f6a to 88fbf2c Compare December 30, 2025 18:50
This commit finishes implementing the standard Western Design Center 65C02
instruction set by adding the last missing instructions.

The main additions are the two low-power instructions WAI (Wait for Interrupt)
and STP (Stop Processor), which allow the CPU to enter power-saving modes. I
also added support for the BIT instruction with indexed addressing modes (zero
page indexed and absolute indexed), and the indexed indirect jump instruction
JMP (abs,X).

Additionally, the Cmos6502 variant now has better documentation that aims to
explain all the improvements over the original NMOS 6502.

This closes issue #120.
@mre mre force-pushed the add-cmos-instructions branch from 88fbf2c to e6eb6ab Compare December 30, 2025 18:56
@omarandlorraine
Copy link
Collaborator

It seems like the WAI and STP instructions stop the CPU until either any interrupt or a reset.

So then maybe instead of a boolean "halted" it would be better to have an enum "waiting_for", with the variants "Nothing", "Interrupt" and "Reset". The interrupt (when eventually implemented) and the reset could then set it to "Nothing", a condition checked in the "single_step" method.

Does that idea have legs?

@mre
Copy link
Owner Author

mre commented Dec 31, 2025

That's a brilliant idea @omarandlorraine. Let me change that. I would like to do this as part of #122, though, as it seems like a better fit for a follow-up PR to reduce the scope a bit. Do you agree?

@omarandlorraine
Copy link
Collaborator

Also, the "single_step" method could return a boolean: did I step over an instruction or not?

@mre
Copy link
Owner Author

mre commented Dec 31, 2025

I like that.

@mre
Copy link
Owner Author

mre commented Dec 31, 2025

Changed it such that single_step() returns a boolean. Thanks for the suggestion.

@mre
Copy link
Owner Author

mre commented Dec 31, 2025

I will go ahead and merge this as it sounds like the changes are only additive in nature and fill in the missing instructions for CMOS. If bugs remain, we can always fix them later, but the tests should give us a good baseline for future work.

@mre mre merged commit 196f4c1 into master Dec 31, 2025
7 checks passed
@mre mre deleted the add-cmos-instructions branch December 31, 2025 12:15
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.

2 participants