eda8774e08
The current (before-this-patch) version of sim65.c does not correctly implement the ADC and SBC instructions in 65C02 mode. This PR fixes that. The 6502 and 65C02 behave identically in binary mode; in decimal behavior however they diverge, both in the handling of inputs that are not BCD values, and in the handling of processor flags. This fix restructures the original "ADC" and "SBC" macros in versions that are specific for the 6502 and the 65C02, and updates the opcode tables to ensure that they point to the correct implementations. Considering the ADC instruction for a moment, the original "ADC" macro was changed to two macros ADC_6502 and ADC_65C02. These check the D (decimal mode) bit, and defer their implementation to any of three macros ADC_BINARY_MODE, ADC_DECIMAL_MODE_6502, and ADC_DECIMAL_MODE_65C02. This is a bit verbose but it makes it very clear what's going on. (For the SBC changes, the analogous changes were made.) The correctness of the changes made is ensured as follows: First, an in-depth study was made how ADC and SBC work, both in the original 6502 and the later 65C02 processor. The actual behavior of both processors was captured on hardware (an Atari 800 XL with a 6502 and a Neo6502 equipped with a WDC 65C02 processor), and was analyzed. The results were cross-referenced with internet sources, leading to a C implementation that reproduces the exact result of the hardware processors. See: https://github.com/sidneycadot/6502-test/blob/main/functional_test/adc_sbc/c_and_python_implementations/6502_adc_sbc.c Next, these C implementations of ADC and SBC were fitted into sim65's macro- based implementation scheme, replacing the existing 6502-only implementation. Finally, the new sim65 implementation was tested against the 65x02 testsuite, showing that (1) the 6502 implementation was still correct; and (2) that the 65C02 implementation is now also correct. As an added bonus, this new implementation of ADC/SBC no longer relies on a dirty implementation detail in sim65: the previous implementation relied on the fact that currently, the A register in the simulator is implemented as an "unsigned", with more bits than the actual A register (8 bits). In the future we want to change the register width to 8 bits, and this updated ADC/SBC is a necessary precursor to that change. |
||
---|---|---|
.github | ||
asminc | ||
cfg | ||
doc | ||
include | ||
libsrc | ||
samples | ||
src | ||
targettest | ||
test | ||
util | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
.travis.yml | ||
Contributing.md | ||
LICENSE | ||
Makefile | ||
Makefile.travis | ||
README.md |
The cc65 cross-compiler suite
cc65 is a complete cross-development package for 65(C)02 systems, including a powerful macro assembler, a C compiler, linker, archiver, simulator and several other tools. cc65 has C and runtime library support for many of the old 6502 machines. For details look at the cc65 web site:
Company / People | Machine / Environment |
---|---|
Apple | Apple II |
Apple IIe enhanced | |
Atari | Atari 400/800 |
Atari 2600 | |
Atari 5200 | |
Atari 7800 | |
Atari XL | |
Lynx | |
Tangerine | Oric Atmos |
Eureka | Oric Telestrat |
Acorn | BBC series |
Commodore | C128 |
C16 | |
C64 | |
CBM 510/610 | |
PET | |
Plus/4 | |
VIC-20 | |
VTech | CreatiVision |
Commander X16 Community | Commander X16 |
Bit Corporation | Gamate |
Berkeley Softworks | GEOS (Apple/CBM) |
LUnix Team | LUnix (C64) |
Nintendo | Nintendo Entertainment System (NES) |
Ohio Scientific | OSI C1P |
MOS Technology, Inc. | KIM-1 |
NEC | PC Engine (PCE) |
Dr. Jozo Dujmović | Picocomputer (RP6502) |
Watara | Watura/QuickShot Supervision |
Synertek | SYM-1 |
A generic configuration to adapt cc65 to new targets is also around.
People
cc65 is originally based on the "Small C" compiler by Ron Cain and enhanced by James E. Hendrix.
Project founders
- John R. Dunning: original implementation of the C compiler and runtime library, Atari hosted.
- Ullrich von Bassewitz:
- moved Dunning's code to modern systems,
- rewrote most parts of the compiler,
- rewrote all of the runtime library.
Core team members
- Christian Groessler: Atari, Atari5200, and CreatiVision library Maintainer
- dqh: GHA help
- Greg King: all around hackery
- groepaz: CBM library, Project Maintainer
- Oliver Schmidt: Apple II library Maintainer
External contributors
- acqn: various compiler fixes
- jedeoric: Telestrat target
- jmr: compiler fixes
- karrika: Atari 7800 target
- Stephan Mühlstrasser: osic1p target
- Wayne Parham: Sym-1 target
- Dave Plummer: KIM-1 target
- rumbledethumps: Picocomputer target
(The above list is incomplete, if you feel left out - please speak up or add yourself in a PR)
For a complete list look at the full team list or the list of all contributors.
Contact
For general discussion, questions, etc subscribe to the mailing list or use the github discussions.
Some of us may also be around on IRC #cc65 on libera.chat.
Documentation
- The main Documentation for users and developers.
- Info on Contributing to the CC65 project. Please read this before working on something you want to contribute, and before reporting bugs.
- The Wiki contains some extra info that does not fit into the regular documentation.