Subject number one: Decimal mode! Consider this VICMON session:
Code: Select all
.A 1800 SED
.A 1801 LDA #$15
.A 1803 CLC
.A 1804 ADC #$26
.A 1806 CLD
.A 1807 BRK
.G 1800
B*
AC
.;41
Note that Decimal mode doesn't apply to increment and decrement instructions. These are still handled as normal. So with LDX #$09, INX, then X = #$0A, and not #$10. You can take advantage of this fact to make a hex-to-decimal conversion subroutine like this:
Code: Select all
HEX2D: PHP
PHA
SED
LDA #$00
H2D_L: CLC
ADC #$01
DEY
BNE H2D_L
TAY
PLA
PLP ; Your main routine may already be in Decimal mode, so I don't want to disrupt that
RTS
Note also that the behavior of the carry flag in decimal mode is as you'd expect, so...
Code: Select all
SED
LDA #$99
CLC
ADC #$01
BCS HAPPENS ; Carry flag set as expected, but
BEQ NOTSOMUCH ; Zero flag isn't set, which is probably a bug
...
CLD
You can, of course, use "out of range" operands in decimal mode. Assignments won't be tampered with, so
Code: Select all
SED
LDA #$0F
CLD
BRK
Code: Select all
SED
LDA #$0F
CLC
ADC #$00
CLD
BRK
I feel like I have a somewhat-decent understanding of how the 6502 handles decimal mode. However, I don't have a specific use for it in mind. Sure, you'll usually want to display results to the end user in decimal instead of hex. But it seems that conversions should be done prior to output, rather than during the calculations. So I'm not really sure what I'd use Decimal mode for.
If you play around with Decimal mode, don't forget to clear it when you're done. The VIC-20's operating system doesn't CLD anywhere except the $FD22 reset routine. So if you leave Decimal mode on, your VIC will be confused about just about every numerical operation it tries, and things will be pretty rough.