Skip to content

Instantly share code, notes, and snippets.

@mikpe
mikpe / cdp1802-02.md
Last active April 14, 2025 14:51
Emulating the CDP1804 packed BCD instructions

Emulating the CDP1804 packed BCD instructions

The RCA CDP1802 processor has a successor, the CDP1804/5/6 family. The members of that family implement the same instruction set, extended from the 1802, and differ only in availability of on-chip ROM and RAM. I'll refer to this extension as "the 1804".

One of the extensions are instructions for performing addition and subtraction on bytes containing packed BCD data. As I wanted to add support for these instructions to my 1802 emulator, I needed to understand exactly what they are doing.

BCD - confusion

BCD arithmetic is easy on paper (see link above), but when reviewing existing 1802 emulators, I found that no two emulators contained equivalent implementations. Also the manufacturer's documentation for the 1804 BCD instructions only describes their operations in general terms, e.g. referring to "decimal adjust" without ever

@mikpe
mikpe / cdp1802-01.md
Last active April 14, 2025 14:50
RCA CDP1802 toolchain: Intro

RCA CDP1802 toolchain intro

For the past 9-10 months I've been working on creating a toolchain targeting the RCA CDP1802 processor. Right now I have:

  • a simulator capable of running CDP1802 code from ELF or Intel HEX files
  • a port of GNU binutils (master branch) targeting cdp1802-elf, test suite results on par with similar targets
  • a port of GNU GCC (gcc-14/15 branches) targeting cdp1802-elf, with C and soft-float support (no C++ yet)
  • a custom libc providing C start-up code and whatever functionality is needed by the GCC test suite
  • GCC test suite results with no runtime failures (i.e. no known wrong-code issues)

Simulator