ISC Instruction

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Hastouki
Posts: 4
Joined: Wed May 06, 2020 10:39 am

ISC Instruction

Post by Hastouki » Thu May 07, 2020 4:26 pm

Hey guys, the docs tell me ISC = INC + SBC. If INC doesn't affect the C flag, and the 6500 programming manual tells me this about SBC:
This instruction affects the accumulator. The carry flag is set if the result is greater than or equal to 0. The carry flag is reset when the result is less than 0, indicating a borrow.
This is what I'm seeing in the nestest log:

Code: Select all

FAB4  A9 40     LDA #$40                        A:EB X:02 Y:AA P:E4 SP:F9 PPU:286,160 CYC:18289
FAB6  60        RTS                             A:40 X:02 Y:AA P:64 SP:F9 PPU:292,160 CYC:18291
EB9E  E3 45    *ISB ($45,X) @ 47 = 0647 = EB    A:40 X:02 Y:AA P:64 SP:FB PPU:310,160 CYC:18297
EBA0  EA        NOP                             A:53 X:02 Y:AA P:24 SP:FB PPU:334,160 CYC:18305
and then mine:

Code: Select all

A:EB    X:02    Y:AA    P:11100100=E4   SP:F9   Cycles:18289    $FAB4: A9 LDA #40
A:40    X:02    Y:AA    P:01100100=64   SP:F9   Cycles:18291    $FAB6: 60 RTS
A:40    X:02    Y:AA    P:01100100=64   SP:FB   Cycles:18297    $EB9E: E3 ISC @ 47 0647 = EB
A:53    X:02    Y:AA    P:00100101=25   SP:FB   Cycles:18305    $EBA0: EA NOP
A gets set to 53 in both cases, the result is the same, but my instruction sets the C flag whereas the official log doesn't. I'm scratching my head a little bit on this one.

User avatar
Quietust
Posts: 1555
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: ISC Instruction

Post by Quietust » Thu May 07, 2020 4:46 pm

Hastouki wrote:
Thu May 07, 2020 4:26 pm
A gets set to 53 in both cases, the result is the same, but my instruction sets the C flag whereas the official log doesn't. I'm scratching my head a little bit on this one.
The subtraction is resulting in borrow ($40 - $EB), and that should clear the carry flag (because it's the opposite of how it works with addition).
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.

Hastouki
Posts: 4
Joined: Wed May 06, 2020 10:39 am

Re: ISC Instruction

Post by Hastouki » Thu May 07, 2020 6:54 pm

So I was storing the result of the subtraction into a signed byte and then checking if I had to flag a borrow. The result being -171 (after also taking the borrow from the previous instruction into account), doesn't quite work well in a signed byte. Ended up storing the result into a int16_t to ensure it stays negative.

Thanks for your help, again.

Post Reply