EOR #$FF - 6502 Ponderables and Befuddlements

Let's talk about anything related to the 6502 microprocessor.
Post Reply
JoJo1973
Posts: 1
Joined: 12 Sep 2023

EOR #$FF - 6502 Ponderables and Befuddlements

Post by JoJo1973 »

I can't believe nobody has still mentioned this excellent "poetry" book by David Youd!

https://archive.org/details/eor6502

For your edification and purification of spirit! :wink:
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: EOR #$FF - 6502 Ponderables and Befuddlements

Post by BigEd »

Welcome! I'm not so suprised, as it seems to have been self-published this last week.

However, it has some intriguing snippets, such as

Code: Select all

ASL
ADC #$80
ROL
ASL
ADC #$80
ROL
(I imagine many of us will immediately grasp some proportion of the snippets, and ponder over some others, depending on our experience and habits. The specific ponderables will be different for each of us.)

I think it's worth a look - thanks!
chitselb
Posts: 232
Joined: 21 Aug 2010
Location: Ontonagon MI
Contact:

Re: EOR #$FF - 6502 Ponderables and Befuddlements

Post by chitselb »

$1E has this:

Code: Select all

 SED
 CMP #$0A
 ADC #$30
 CLD


I am pretty sure (on the PET anyway) that this needs to be performed in between SEI / CLI so that when the jiffy clock IRQ strikes, we don't have a problem with the processor being in decimal mode.
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: EOR #$FF - 6502 Ponderables and Befuddlements

Post by BigDumbDinosaur »

chitselb wrote:
$1E has this:

Code: Select all

          SED
          CMP #$0A
          ADC #$30
          CLD


I am pretty sure (on the PET anyway) that this needs to be performed in between SEI / CLI so that when the jiffy clock IRQ strikes, we don't have a problem with the processor being in decimal mode.
That requirement applies to all versions of the NMOS 6502.  The 65C02 and 65C816 return to binary mode when responding to any interrupt.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: EOR #$FF - 6502 Ponderables and Befuddlements

Post by BigEd »

A bit of an omission in the PET ROM - it became clear that an ISR should CLD if it needs to. One fix in the ISR, instead of fixes in every application that uses decimal mode. But then again, decimal mode is rather rarely used...
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: EOR #$FF - 6502 Ponderables and Befuddlements

Post by BigDumbDinosaur »

BigEd wrote:
A bit of an omission in the PET ROM - it became clear that an ISR should CLD if it needs to. One fix in the ISR, instead of fixes in every application that uses decimal mode. But then again, decimal mode is rather rarely used...

Actually, decimal arithmetic was used quite a bit in the applications for which the 6502 was originally intended.  I worked on several such things in the 1970s, and all used BCD numbers for tracking human-readable quantities.  I was a bit taken aback when I got my Commodore 64 and discovered that the interrupt service routine didn’t revert to binary arithmetic.

That said, there was no use of BCD arithmetic in any of the Commodore 8-bit machines until the C-128.  Working with the C-64’s and C-128’s TOD clocks in the foreground could get interesting, since they read out in BCD.

It’s likely the 6502 not flipping back to binary arithmetic was part of the cost-reduction process—a few fewer transistors to use up die space.  Or it could be in the heady rush to get product out the door, it was overlooked.  Alas, the one individual who would have known for sure is no longer with us.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
6502inside
Posts: 101
Joined: 03 Jan 2007
Location: Sunny So Cal
Contact:

Re: EOR #$FF - 6502 Ponderables and Befuddlements

Post by 6502inside »

That got a little tricky virtualizing the 6502 in 6o6 because guest code can execute a SED and transiently have decimal mode set before the VM records the flag and cleans the status register. On a system like the PET or C64 that doesn't compensate, this could lead to a race condition, so for the Incredible KIMplement I have the system Timer A IRQ revectored to ensure the decimal flag is clear (since many KIM-1 programs do arithmetic in decimal mode).
Post Reply