1
0
mirror of https://github.com/mre/mos6502.git synced 2024-11-28 07:49:19 +00:00
Commit Graph

369 Commits

Author SHA1 Message Date
Matthias
77697dbb99 Fix Add with Carry (ADC) Implementation
This pull request addresses several issues with the Add with Carry (ADC)
operation in our 6502 emulator, ensuring correct behavior in both decimal and
non-decimal modes.

It is similar to #106, which improved on our SBC operation.

My hope is that these changes improve the accuracy of our 6502 emulator,
particularly for software that relies on correct decimal mode arithmetic or
precise overflow detection.

- Implement correct decimal mode addition in ADC operation
- Accurate overflow detection for non-decimal mode
- Proper carry flag calculation for both modes
- Preserve overflow flag in decimal mode (as per 6502 specification)

The previous implementation didn't correctly handle Binary-Coded Decimal (BCD)
arithmetic. The new implementation:

1. Performs addition on low and high nibbles separately
2. Adjusts results when they exceed 9 (valid BCD range is 0-9)
3. Propagates carries between nibbles
4. Sets the carry flag correctly based on the final BCD result

- In non-decimal mode: Implemented using the formula `(!(A ^ M) & (A ^ R)) &
  0x80 != 0`, where A is the accumulator, M is the memory operand, and R is the
result.
- In decimal mode: The overflow flag is preserved, matching the behavior of the
  actual 6502 processor.

- In non-decimal mode: Set if the unsigned result is less than either the
  accumulator or the memory operand.
- In decimal mode: Set based on whether the BCD addition resulted in a value
  greater than 99.
2024-10-21 10:37:17 +02:00
Matthias
a0919fe7b8 Fix SBC implementation and improve overflow detection
- Correct decimal mode subtraction in SBC operation
- Implement accurate overflow detection for non-decimal mode
- Fix carry flag calculation as inverse of borrow
- Add comments explaining complex bit manipulation for overflow detection
- Update tests to verify correct behavior in both decimal and non-decimal modes

This commit addresses issues with the Subtract with Carry (SBC) operation,
ensuring correct behavior in both decimal and non-decimal modes, and
improves code readability with added comments.
2024-10-18 15:01:05 +02:00
Sam M W
6b7c8a8aab bump version 2024-09-26 09:04:18 +02:00
Sam M W
0c8616acb0 impl Default for CPU 2024-09-26 09:04:18 +02:00
Sam M W
874422b394 impl Default for the Variant types 2024-09-26 09:04:18 +02:00
Sam M W
40710248ff #[allow(clippy::needless_doctest_main)] 2024-07-29 13:13:07 +02:00
Sam M W
dbbb4a5ccf remove lint for pointer_structural_match, this is now a hard error 2024-07-29 13:13:07 +02:00
Sam M W
b052f9150f version bump 2024-07-29 13:13:07 +02:00
omarandlorraine
265ef6941e
Cmos support (#99) 2024-06-07 15:29:40 +01:00
Matthias Endler
467b3ff436
Code Cleanup (#97)
This adds some new directives for clippy and fixes all warnings.
Also updated the dependencies to their latest versions.
2024-04-27 19:51:39 +01:00
Sam M W
4847744518 correction to comment 2024-04-24 14:51:08 +01:00
Matthias Endler
11d9540729 fix typo 2024-04-24 15:41:25 +02:00
Sam M W
bf06ad8924 better commenting inside of AddressingMode enum 2024-04-24 15:41:25 +02:00
Sam M W
54dd0cd536 rename IndirectWithFix to Indirect 2024-04-24 15:41:25 +02:00
Sam M W
2444ef52d1 fix typo in comment 2024-04-24 15:41:25 +02:00
Sam M W
ad622bc930 formatting 2024-04-24 15:41:25 +02:00
Sam M W
97d6b3fd89 split the Indirect addressing mode into BuggyIndirect and IndirectWithFix 2024-04-24 15:41:25 +02:00
Sam M W
da30c8c67d change arr_to_addr to address_from_bytes 2024-04-24 15:41:25 +02:00
omarandlorraine
11499b6bc8
Starting on implementing different variants (#88)
* start on separating 6502 variants from cpu itself

* add a single variant: the NMOS one

* get examples & tests running again

* Add the Revision A variant, one that has no ROR

* disable failing lint in build-time dependencies

* Variant with no decimal mode

* Revert "disable failing lint in build-time dependencies"

This reverts commit c87975e937.

* some doc comments

* specify the variant in unit test now the API has changed

---------

Co-authored-by: Sam M W <you@example.com>
2023-10-31 16:45:15 +01:00
omarandlorraine
b52e47bbb5
Fix the PHP opcode (#92)
* unit test for php

* get test passing

---------

Co-authored-by: Sam M W <you@example.com>
2023-10-30 02:22:37 +01:00
omarandlorraine
6ce85db45c
boring crate related maintenance (#95)
* remove Cargo.lock

* remove num

---------

Co-authored-by: Sam M W <you@example.com>
2023-10-30 02:20:46 +01:00
omarandlorraine
4d2621d603
use cargo test now instead of skeptic to run tests (#93)
* use cargo test now instead of skeptic to run tests

* formatting

---------

Co-authored-by: Sam M W <you@example.com>
2023-10-29 15:06:41 +00:00
Sam M W
a07df31c26 Cargo update 2023-10-29 13:47:51 +00:00
omarandlorraine
0d65eb0d8d
Merge pull request #87 from omarandlorraine/update
cargo update
2023-08-18 09:07:20 +01:00
Sam M W
9752a1b8f7 cargo update 2023-08-18 09:02:16 +01:00
omarandlorraine
aa1a47a76f
Fix addition and subtraction (#72)
* extract decimal logic into separate function

* squash me

* I think we should be doing unsigned arithmetic here

* squash me

* remove unused function

* update the sign checks

* cargo fmt

* get tests to compile again

* get tests passing again

* squash me

* remove pointless conversion from u8 to u8

* cargo fmt

* accumulator is now u8

* add adc test from solid65

* pass the new test

---------

Co-authored-by: Sam M W <you@example.com>
2023-06-29 12:13:49 +02:00
dependabot[bot]
65817524a2
Bump bitflags from 2.3.2 to 2.3.3 (#82)
Bumps [bitflags](https://github.com/bitflags/bitflags) from 2.3.2 to 2.3.3.
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/2.3.2...2.3.3)

---
updated-dependencies:
- dependency-name: bitflags
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-29 10:52:01 +02:00
Matthias Endler
e88c971625
Add assembly example code (#80)
* Add assembly example code

This should make it easier for beginners to understand
how to test this emulator.

* cleanup

* fix typo
2023-06-20 10:32:28 +02:00
dependabot[bot]
62d4b73cd5
Bump log from 0.4.17 to 0.4.19 (#78)
Bumps [log](https://github.com/rust-lang/log) from 0.4.17 to 0.4.19.
- [Release notes](https://github.com/rust-lang/log/releases)
- [Changelog](https://github.com/rust-lang/log/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/log/compare/0.4.17...0.4.19)

---
updated-dependencies:
- dependency-name: log
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-19 12:45:50 +02:00
dependabot[bot]
4266599bb2
Bump bitflags from 2.2.1 to 2.3.2 (#79)
Bumps [bitflags](https://github.com/bitflags/bitflags) from 2.2.1 to 2.3.2.
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/2.2.1...2.3.2)

---
updated-dependencies:
- dependency-name: bitflags
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-19 11:56:09 +02:00
omarandlorraine
42eb1f8689
Update README.md (#74) 2023-04-26 18:41:44 +02:00
dependabot[bot]
36a9dd19f6
Bump bitflags from 2.1.0 to 2.2.1 (#73)
Bumps [bitflags](https://github.com/bitflags/bitflags) from 2.1.0 to 2.2.1.
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/2.1.0...2.2.1)

---
updated-dependencies:
- dependency-name: bitflags
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-25 10:45:54 +02:00
Matthias Endler
2effe45a08
Add CI pipeline (#71) 2023-04-20 17:42:18 +02:00
Matthias
56001dc63b Add missing updated lockfile 2023-04-20 14:22:03 +02:00
Matthias
1a3d07861b Bump devel version to 0.5.0 2023-04-20 13:22:13 +02:00
dependabot[bot]
c08e8ac595
Bump bitflags from 2.1.0 to 2.2.0 (#69)
Bumps [bitflags](https://github.com/bitflags/bitflags) from 2.1.0 to 2.2.0.
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/2.1.0...2.2.0)

---
updated-dependencies:
- dependency-name: bitflags
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-20 10:49:59 +02:00
omarandlorraine
849f891e24
Merge pull request #67 from mre/rts
Implementation of RTS
2023-04-16 07:08:25 +01:00
omarandlorraine
6232b3bdbd
Merge pull request #68 from mre/bit
bugfix for the bit opcode
2023-04-15 22:05:54 +01:00
Sam M W
bd1ab13dc1 point INY instruction at the correct register 2023-04-15 21:47:17 +01:00
Sam M W
f0fc9829db PLA opcode should update the flags 2023-04-15 21:44:05 +01:00
Sam M W
26a2f51bc6 don't overshoot the stack pointer! (pla and plp) 2023-04-15 21:37:47 +01:00
Sam M W
62424070a1 disable interrupts after BRK instruction 2023-04-15 21:34:07 +01:00
Sam M W
a8d53f926d implement BRK 2023-04-15 21:17:28 +01:00
Sam M W
1c31a73a2b correct endianness for program counter push 2023-04-15 21:01:08 +01:00
Sam M W
239992ea6c first stab at implementing the JSR instruction 2023-04-15 20:58:31 +01:00
Sam M W
70e85a2eaf bugfix for the bit opcode 2023-04-15 16:42:05 +01:00
Sam M W
8e797b70fa implement BNE 2023-04-15 16:17:51 +01:00
Sam M W
18164c7abf implement RTI as well 2023-04-15 15:36:53 +01:00
Sam M W
1b90243738 implementation of RTS 2023-04-15 15:36:43 +01:00
dependabot[bot]
7df9160e32
Bump bitflags from 2.0.2 to 2.1.0 (#65)
Bumps [bitflags](https://github.com/bitflags/bitflags) from 2.0.2 to 2.1.0.
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/2.0.2...2.1.0)

---
updated-dependencies:
- dependency-name: bitflags
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-13 10:58:07 +02:00