processor detection
Re: processor detection
This might not be the best time to ask, but other than processor detection and maybe making calculators, is there any good purpose for the SED/CLD instructions? The PET ROM does CLD during initialization, and nothing I've ever seen turns it on without turning it back off again. But in tons of programs I've seen (admittedly mine too!) , there is this CLD in there somewhere near the beginning, an homage to the D flag
-
leepivonka
- Posts: 168
- Joined: 15 Apr 2016
Re: processor detection
SED & CLD are a handy way to change D.
The D flag controls whether ADC & SBC work in binary or BCD.
If doing ADC on $99 and $01 with C clear:
If D is set, the result is $00
If D is clear, the result is $9A
The D flag controls whether ADC & SBC work in binary or BCD.
If doing ADC on $99 and $01 with C clear:
If D is set, the result is $00
If D is clear, the result is $9A
-
White Flame
- Posts: 704
- Joined: 24 Jul 2012
Re: processor detection
Yeah, you certainly want decimal mode off by default, and only turn it on when you need it. ADC and SBC are very widely used in assumption of full 8-bit mode to toy with leaving it on. Many IRQ routines also forget to CLD, so interrupting decimal mode code can be dangerous. Note that since the processor flags get effectively PHP/PLP'd in the IRQ/RTI mechanism, the routine doesn't have to worry about restoring the prior state of D manually.
Beyond the financial fixed point & high score calculations, there are also some clever routines that print a register in ASCII decimal digits that use decimal mode for the conversion (and turn it off when they're done
).
Beyond the financial fixed point & high score calculations, there are also some clever routines that print a register in ASCII decimal digits that use decimal mode for the conversion (and turn it off when they're done
- GARTHWILSON
- Forum Moderator
- Posts: 8774
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: processor detection
Note that the CMOS '02 (65c02) does clear the D flag upon reset or interrupt. The NMOS needs the CLD in the reset routine and ISRs though.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- BitWise
- In Memoriam
- Posts: 996
- Joined: 02 Mar 2004
- Location: Berkshire, UK
- Contact:
Re: processor detection
I always set the I flag and clear D flag in my reset routines in case an application has executed JMP ($FFFC) to simulate a hardware reset.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
Re: processor detection
BitWise wrote:
I always set the I flag and clear D flag in my reset routines in case an application has executed JMP ($FFFC) to simulate a hardware reset.
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: processor detection
Elsewhere on this tie, there is a "universal" binary to ASCII conversion routine that uses decimal mode.
x86? We ain't got no x86. We don't NEED no stinking x86!