Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid carry flag after DAA #3

Open
KarolS opened this issue Jun 19, 2020 · 2 comments
Open

Invalid carry flag after DAA #3

KarolS opened this issue Jun 19, 2020 · 2 comments

Comments

@KarolS
Copy link

KarolS commented Jun 19, 2020

Steps to reproduce:

Assemble and run the following code:

LDA #$91
ADD #$91
DAA

What happened?

Carry was reset.

When similar code was used for multi-byte decimal addition, it yielded incorrect results.

What was expected?

Carry should be set. DAA keeps the carry flag set if it was set beforehand, see the mc6809 emulator sources for comparison: https://github.com/spc476/mc6809/blob/master/mc6809.c#L420 or the official Programming Manual: https://archive.org/details/bitsavers_motorola68_13419254/page/n83/mode/2up

C – Set if a carry is generated or if the carry bit was set before the operation; cleared otherwise.

After some research, I noticed that this is a common bug in many 6809 emulators.

@jedie
Copy link
Member

jedie commented Mar 24, 2021

Hm. Interesting.

In the past I have come across incorrect information in the manual. Thus, I would not trust it 100%.

I had tested such behavior on real hardware a few times. I did this in a small BASIC program on my Dragon 32. See Listings here: https://github.com/jedie/DragonPy/tree/master/BASIC%20tools/TestCC_Registers

Would be cool to repeat that for this case. To be sure what the real processor is really doing.

EDIT: We already have some tests for DAA:

def test_DAA(self):

A later test, checks also the Carry flag, see:

There was also a discussion about DAA here: http://archive.worldofdragon.org/phpBB3/viewtopic.php?f=8&t=4896

The Carry flag was updated because of the call here:

self.update_NZC_8(new_value)
and in the end this code part touch it:
def set_C8(self, r):
But yes, it only set the Carry flag, but doesn't clear it...

@maddes-b
Copy link

There is an inofficial version of the M6809PM document, with additional errata at https://github.com/M6809-Docs/m6809pm
Incl. errata for DAA (H for LSN). Currently updating pages incl. upcoming errata for BGT.
Please provide input to create a more reliable document. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants