6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 8:54 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: SBC and Carry
PostPosted: Thu Apr 04, 2013 5:21 am 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
So, I managed to get the simulator proof test running on my simulator, and I've found several issues.

I'm down to decimal mode.

I have this sequence. This is the 'chkdad' routine for those following along at home. This shows the address, instruction, status, registers, and the top part of the stack ($1FF down to, I dunno, $1F5 or so...)
Code:
3cd3: PHP              -- -O*-D--C A:a0 X:58 Y:ff S:fb 3c 7b 7a f8 ff 32 fd 30 0 0 0
3cd4: LDA $57          -- -O*-D--C A:a0 X:58 Y:ff S:fa 3c 7b 7a f8 79 32 fd 30 0 0 0
3cd6: ADC $58          -- -O*-D--C A:1 X:58 Y:ff S:fa 3c 7b 7a f8 79 32 fd 30 0 0 0
3cd8: PHP              -- -O*-D--C A:1 X:58 Y:ff S:fa 3c 7b 7a f8 79 32 fd 30 0 0 0
3cd9: CMP $59          -- -O*-D--C A:1 X:58 Y:ff S:f9 3c 7b 7a f8 79 79 fd 30 0 0 0
3cdb: BNE $3cdb        -- -O*-D--C A:1 X:58 Y:ff S:f9 3c 7b 7a f8 79 79 fd 30 0 0 0


Also, here's the content of the $0050-005F, which does not change in this process:
Code:
       0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
0050: 59 02 59 01 5a 01 00 01 99 00 01 02 00 42 52 00


So it's LDA $57, which is 01, and then it ADC $58, which is 99, with Carry set, in Decimal mode. I have this coming out at $01 (99 + 1 + 1 = 101, mod 100 = 1), with carry set. But the test is comparing it with $59, which is a zero. Am I missing something here? Why would ADC be set to 0?


Top
 Profile  
Reply with quote  
 Post subject: Re: SBC and Carry
PostPosted: Thu Apr 04, 2013 8:18 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
There is two calls of the decimal add & subtract routine "chkdad". One is with carry clear, the other with carry set. You can distinguish them by looking at $56 which is "adfc", 1 for carry set, 0 for carry clear. According to this "chkdad" was called with a CLC ahead of it but carry in the processor status is on.

You need to find the place where the carry is illegaly set or not cleared.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
 Post subject: Re: SBC and Carry
PostPosted: Thu Apr 04, 2013 2:31 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Klaus2m5 wrote:
There is two calls of the decimal add & subtract routine "chkdad". One is with carry clear, the other with carry set. You can distinguish them by looking at $56 which is "adfc", 1 for carry set, 0 for carry clear. According to this "chkdad" was called with a CLC ahead of it but carry in the processor status is on.

You need to find the place where the carry is illegaly set or not cleared.


Ah, thank you so much. I've been managing to bumble through the rest of this with only a basic understanding of how the test works, rewrote my math routines from scratch, but this one was flummoxing me. I will look at it later when I return from a trip.


Top
 Profile  
Reply with quote  
 Post subject: Re: SBC and Carry
PostPosted: Thu Apr 18, 2013 4:15 am 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Yay!

It works!

None of my CLx routines were working, it turned out. So, CLC was failing.

Then I had a final problem with ADC in Decimal, where 99 + 1 was turning in to "A0"...doh! One off error for carry.

But now it passes (I get to the JMP $3CD0 spot...).

Now I need to add interrupts and reset and those bits to it. Clean up the UI.

Thanks for the help, and thanks so much for the test suite.


Top
 Profile  
Reply with quote  
 Post subject: Re: SBC and Carry
PostPosted: Thu Apr 18, 2013 9:50 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
whartung wrote:
None of my CLx routines were working, it turned out. So, CLC was failing.
CLC and all other CLx opcodes are checked earlier in the test. Was this going undetected?
Code:
; test set and clear flags CLC CLI CLD CLV SEC SEI SED
        set_stat $ff
        clc
        tst_stat $ff-carry
        sec
        tst_stat $ff
; ... continues to test I, D & V, then tests reverse flags
        set_stat 0
        tst_stat 0
        sec
        tst_stat carry
        clc
        tst_stat 0 

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
 Post subject: Re: SBC and Carry
PostPosted: Thu Apr 18, 2013 5:32 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Klaus2m5 wrote:
CLC and all other CLx opcodes are checked earlier in the test. Was this going undetected?


Well, I looked through it and I think that the CLC/SEC check was working in that case, but it was clearly failing in the other case. Now, CLC is a pretty simple routine.

What I had before, in Java, was:
Code:
status &= ~(CARRY_MASK);

And in context of the ADC tests, this was apparently not sufficient. So I changed it to:
Code:
status &= ~(CARRY_MASK) & 0xff);

That was enough to make it work.

I tried to change it back to what it was, and all the tests pass, so something else I may have done added to the repair.

But when I was initially testing, I stepped over CLC, and saw the C flag bright as day, so at the time, that was the correct solution.


Top
 Profile  
Reply with quote  
 Post subject: Re: SBC and Carry
PostPosted: Thu Apr 18, 2013 6:48 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
Strange, because the second version shouldn't make a difference except the extra closing parenthesis, which is probably just a typo in the example but not present in your code.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 15 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: