liveBook · Manning

Decimal mode

As explained in Classic Game Programming on the NES: Make your own retro video game

Decimal mode is a 6502 arithmetic mode in which binary-coded decimal operations interpret nibbles as decimal digits.

Decimal mode makes 6502 arithmetic treat each byte as two decimal digits: one in each four-bit nibble. CLD clears the decimal flag for ordinary arithmetic, while SED enables decimal arithmetic. section 5.12

The NES version of the 6502 does not support decimal operations, so NES startup code disables decimal mode before continuing with initialization. section 5.12

cld          #1
ldx #$FF
txs          #2

Place CLD near the beginning of reset initialization, before normal arithmetic is used. section 5.12

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Defines BCD nibbles and CLD/SED behavior, then stops at the startup instruction that disables the mode.
Examples
Uses the two-instruction startup sequence CLD, LDX, and TXS, with CLD disabling decimal mode.
What you can do after
Configure NES reset code to clear decimal mode before performing arithmetic.
How it connects
Connects 6502 arithmetic flags with NES hardware initialization and startup code.

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.