6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Sep 20, 2024 6:35 pm

All times are UTC




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: processor detection
PostPosted: Mon Sep 11, 2017 11:48 pm 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
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


Top
 Profile  
Reply with quote  
 Post subject: Re: processor detection
PostPosted: Tue Sep 12, 2017 12:51 am 
Offline

Joined: Fri Apr 15, 2016 1:03 am
Posts: 139
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


Top
 Profile  
Reply with quote  
 Post subject: Re: processor detection
PostPosted: Tue Sep 12, 2017 4:21 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 674
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 ;) ).

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
 Post subject: Re: processor detection
PostPosted: Tue Sep 12, 2017 5:45 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8510
Location: Southern California
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: processor detection
PostPosted: Tue Sep 12, 2017 7:59 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
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


Top
 Profile  
Reply with quote  
 Post subject: Re: processor detection
PostPosted: Tue Sep 12, 2017 8:42 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
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.

An excellent safeguard!


Top
 Profile  
Reply with quote  
 Post subject: Re: processor detection
PostPosted: Wed Sep 13, 2017 4:10 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8389
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3

All times are UTC


Who is online

Users browsing this forum: No registered users and 32 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: