6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Apr 28, 2024 4:41 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Mar 03, 2022 10:23 am 
Offline

Joined: Wed Mar 02, 2022 10:03 pm
Posts: 3
Hi,

I'm running Klaus' excellent functional test against my emulator.
At test 2Ah (42) something goes wrong:

Code:
32f4[f8], 2a, a: 2a, x: 0e, y: ff, flags: 71, sp: 01ff, BS: 00 SED
32f5[a2], 2a, a: 2a, x: 0e, y: ff, flags: 79, sp: 01ff, BS: 00 LDX #$0e
32f7[a0], 2a, a: 2a, x: 0e, y: ff, flags: 79, sp: 01ff, BS: 00 LDY #$ff
32f9[a9], 2a, a: 2a, x: 0e, y: ff, flags: f9, sp: 01ff, BS: 00 LDA #$99
32fb[85], 2a, a: 99, x: 0e, y: ff, flags: f9, sp: 01ff, BS: 00 STA $0d
32fd[85], 2a, a: 99, x: 0e, y: ff, flags: f9, sp: 01ff, BS: 00 STA $0e
32ff[8d], 2a, a: 99, x: 0e, y: ff, flags: f9, sp: 01ff, BS: 00 STA $0203
3302[85], 2a, a: 99, x: 0e, y: ff, flags: f9, sp: 01ff, BS: 00 STA $0f
3304[a9], 2a, a: 99, x: 0e, y: ff, flags: f9, sp: 01ff, BS: 00 LDA #$01
3306[85], 2a, a: 01, x: 0e, y: ff, flags: 79, sp: 01ff, BS: 00 STA $0c
3308[85], 2a, a: 01, x: 0e, y: ff, flags: 79, sp: 01ff, BS: 00 STA $10
330a[a9], 2a, a: 01, x: 0e, y: ff, flags: 79, sp: 01ff, BS: 00 LDA #$00
330c[85], 2a, a: 00, x: 0e, y: ff, flags: 7b, sp: 01ff, BS: 00 STA $12
330e[8d], 2a, a: 00, x: 0e, y: ff, flags: 7b, sp: 01ff, BS: 00 STA $0204
3311[38], 2a, a: 00, x: 0e, y: ff, flags: 7b, sp: 01ff, BS: 00 SEC
3312[20], 2a, a: 00, x: 0e, y: ff, flags: 7b, sp: 01ff, BS: 00 JSR $339f
339f[08], 2a, a: 00, x: 0e, y: ff, flags: 7b, sp: 01fd, BS: 00 PHP              push status
33a0[a5], 2a, a: 00, x: 0e, y: ff, flags: 7b, sp: 01fc, BS: 00 LDA $0d
33a2[65], 2a, a: 99, x: 0e, y: ff, flags: f9, sp: 01fc, BS: 00 ADC $0e  [99]
33a4[08], 2a, a: 99, x: 0e, y: ff, flags: b9, sp: 01fc, BS: 00 PHP              push status
33a5[c5], 2a, a: 99, x: 0e, y: ff, flags: b9, sp: 01fb, BS: 00 CMP $0f  [99 versus 99]
33a7[d0], 2a, a: 99, x: 0e, y: ff, flags: 3b, sp: 01fb, BS: 00 BNE $33a7
33a9[68], 2a, a: 99, x: 0e, y: ff, flags: 3b, sp: 01fb, BS: 00 PLA              pull a
33aa[29], 2a, a: b9, x: 0e, y: ff, flags: b9, sp: 01fc, BS: 00 AND #$01
33ac[c5], 2a, a: 01, x: 0e, y: ff, flags: 39, sp: 01fc, BS: 00 CMP $10  [01 versus 01]
33ae[d0], 2a, a: 01, x: 0e, y: ff, flags: 3b, sp: 01fc, BS: 00 BNE $33ae
33b0[28], 2a, a: 01, x: 0e, y: ff, flags: 3b, sp: 01fc, BS: 00 PLP              pull status
33b1[08], 2a, a: 01, x: 0e, y: ff, flags: 7b, sp: 01fd, BS: 00 PHP              push status
33b2[a5], 2a, a: 01, x: 0e, y: ff, flags: 7b, sp: 01fc, BS: 00 LDA $0d
33b4[e5], 2a, a: 99, x: 0e, y: ff, flags: f9, sp: 01fc, BS: 00 SBC $12  [99 -= 00]
33b6[08], 2a, a: 98, x: 0e, y: ff, flags: b8, sp: 01fc, BS: 00 PHP
33b7[c5], 2a, a: 98, x: 0e, y: ff, flags: b8, sp: 01fb, BS: 00 CMP $0f  [98 versus 99]
33b9[d0], 2a, a: 98, x: 0e, y: ff, flags: b8, sp: 01fb, BS: 00 BNE $33b9
LOOP AT 33b9


at address 33b4 00h is substracted from a which is 99h at that time. The flag-register is F9h so decimal and carry are set.
My emulator calculates 98h of this, the test expects 99h though. I don't understand this.

Is it that maybe SBC does not do the subtraction if the value is 0, even though carry is set? Or something else?


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 03, 2022 10:29 am 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 293
It looks like you're calculating A - operand - carry instead of A - operand - (not carry). SBC with an operand of 0 and carry set should not change A, whether it's in decimal mode or not.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 03, 2022 10:41 am 
Offline

Joined: Wed Mar 02, 2022 10:03 pm
Posts: 3
John West wrote:
It looks like you're calculating A - operand - carry instead of A - operand - (not carry). SBC with an operand of 0 and carry set should not change A, whether it's in decimal mode or not.


Oh indeed!
Thanks


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 03, 2022 11:23 am 
Offline

Joined: Wed Mar 02, 2022 10:03 pm
Posts: 3
Very cool: it now runs upto test $f0, so all is fine. Pretty quick (I think) for a python program (with pypy): 4.6 seconds om a "11th Gen Intel(R) Core(TM) i5-11400H @ 2.70GHz" laptop.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 03, 2022 12:54 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Splendid - and welcome!


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 07, 2022 10:04 am 
Offline

Joined: Tue Apr 19, 2005 7:25 pm
Posts: 15
flok wrote:
John West wrote:
It looks like you're calculating A - operand - carry instead of A - operand - (not carry). SBC with an operand of 0 and carry set should not change A, whether it's in decimal mode or not.


Oh indeed!
Thanks


Just a quick note Flok, when I reached this point I thought I was done for a while, and then I noticed how poor my emulator behaved on decimal mode. Klaus has incorporated a separate test for decimal mode behavior (including flags and response to non-valid BCD inputs) and that has helped me complete my testing (though I later found out I needed to emulate non-documented opcodes, but that was a different story).

The few challenges I faced were:

Klaus decimal test are only available in assembly code (no binaries). So you will need to download the code and the assembler and assemble it yourself.

The assembly code requires updating which CPU behavior you want to check (as 6502, 65C02 and the 16 bit version all behave differently) and also which tests you want to run (accumulator results and each of the carry, zero, negative and overflow flags). I have set all to true, so my emulation was more precise. But you can do one by one to check as you improve.

Lastly, you may find a description of how ADC and SBC behave for each of these calculations under decimal mode on this page: http://6502.org/tutorials/decimal_mode.html . It was incredibly useful (despite being a bit difficult to understand) and it does contain all the information you might need to do this.

Hope this is useful.

Best Regards,
Nelson


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

All times are UTC


Who is online

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