DCP Indirect Indexed

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

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

DCP Indirect Indexed

Post by Hastouki » Wed May 06, 2020 2:28 pm

Hey guys, I'm implementing my 6502 core and running through the nestest log. So far I'm pretty accurate across the board, but I'm struggling a little with this DCP instruction. Here is a snippet of the nestest log for context:

Code: Select all

EA15  A9 EB     LDA #$EB                        A:36 X:02 Y:9D P:67 SP:FB PPU:319,151 CYC:17277
EA17  8D 47 06  STA $0647 = 36                  A:EB X:02 Y:9D P:E5 SP:FB PPU:325,151 CYC:17279
EA1A  A9 48     LDA #$48                        A:EB X:02 Y:9D P:E5 SP:FB PPU:337,151 CYC:17283
EA1C  85 45     STA $45 = 32                    A:48 X:02 Y:9D P:65 SP:FB PPU:  2,152 CYC:17285
EA1E  A9 05     LDA #$05                        A:48 X:02 Y:9D P:65 SP:FB PPU: 11,152 CYC:17288
EA20  85 46     STA $46 = 04                    A:05 X:02 Y:9D P:65 SP:FB PPU: 17,152 CYC:17290
EA22  A0 FF     LDY #$FF                        A:05 X:02 Y:9D P:65 SP:FB PPU: 26,152 CYC:17293
EA24  20 31 FA  JSR $FA31                       A:05 X:02 Y:FF P:E5 SP:FB PPU: 32,152 CYC:17295
FA31  24 01     BIT $01 = FF                    A:05 X:02 Y:FF P:E5 SP:F9 PPU: 50,152 CYC:17301
FA33  18        CLC                             A:05 X:02 Y:FF P:E5 SP:F9 PPU: 59,152 CYC:17304
FA34  A9 40     LDA #$40                        A:05 X:02 Y:FF P:E4 SP:F9 PPU: 65,152 CYC:17306
FA36  60        RTS                             A:40 X:02 Y:FF P:64 SP:F9 PPU: 71,152 CYC:17308
EA27  D3 45    *DCP ($45),Y = 0548 @ 0647 = EB  A:40 X:02 Y:FF P:64 SP:FB PPU: 89,152 CYC:17314
EA29  EA        NOP                             A:40 X:02 Y:FF P:64 SP:FB PPU:113,152 CYC:17322
and here is from my own log:

Code: Select all

A:36    X:02    Y:9D    P:01100111=67   SP:FB   Cycles:17277    $EA15: A9 LDA #EB
A:EB    X:02    Y:9D    P:11100101=E5   SP:FB   Cycles:17279    $EA17: 8D STA $0647
A:EB    X:02    Y:9D    P:11100101=E5   SP:FB   Cycles:17283    $EA1A: A9 LDA #48
A:48    X:02    Y:9D    P:01100101=65   SP:FB   Cycles:17285    $EA1C: 85 STA $45 = 48
A:48    X:02    Y:9D    P:01100101=65   SP:FB   Cycles:17288    $EA1E: A9 LDA #05
A:05    X:02    Y:9D    P:01100101=65   SP:FB   Cycles:17290    $EA20: 85 STA $46 = 5
A:05    X:02    Y:9D    P:01100101=65   SP:FB   Cycles:17293    $EA22: A0 LDY #FF
A:05    X:02    Y:FF    P:11100101=E5   SP:FB   Cycles:17295    $EA24: 20 JSR $FA31
A:05    X:02    Y:FF    P:11100101=E5   SP:F9   Cycles:17301    $FA31: 24 BIT $01 = FF
A:05    X:02    Y:FF    P:11100101=E5   SP:F9   Cycles:17304    $FA33: 18 CLC
A:05    X:02    Y:FF    P:11100100=E4   SP:F9   Cycles:17306    $FA34: A9 LDA #40
A:40    X:02    Y:FF    P:01100100=64   SP:F9   Cycles:17308    $FA36: 60 RTS
A:40    X:02    Y:FF    P:01100100=64   SP:FB   Cycles:17314    $EA27: D3 *DCP ($45), Y = 0548 @ 0647 = EB
A:40    X:02    Y:FF    P:01100100=64   SP:FB   Cycles:17323    $EA29: EA NOP
So calculating the indirect indexed address using the following args:
ZP@FF = 0x48
ZP@00 = 0x05
Y = 0xFF
0x0548 + 0xFF = 0x0647 (page cross)

Nesdev wiki has the following:

Code: Select all

DCP (d,X) ($C3 dd; 8 cycles)
DCP d ($C7 dd; 5 cycles)
DCP a ($CF aa aa; 6 cycles)
DCP (d),Y ($D3 dd; 8 cycles)
DCP d,X ($D7 dd; 6 cycles)
DCP a,Y ($DB aa aa; 7 cycles)
DCP a,X ($DF aa aa; 7 cycles)
Specifically opcode 0xD3, 8 cycles + 1 page cross = 9 cycles. What am I not understanding?

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

Re: DCP Indirect Indexed

Post by Quietust » Wed May 06, 2020 2:58 pm

The 8 cycle timing you saw on the wiki includes the page crossing because DCP is a Read-Modify-Write instruction (being based on DEC) and thus always takes the extra cycle for page crossing.
64doc wrote:

Code: Select all

     Read-Modify-Write instructions (SLO, SRE, RLA, RRA, ISB, DCP)

        #    address   R/W description
       --- ----------- --- ------------------------------------------
        1      PC       R  fetch opcode, increment PC
        2      PC       R  fetch pointer address, increment PC
        3    pointer    R  fetch effective address low
        4   pointer+1   R  fetch effective address high,
                           add Y to low byte of effective address
        5   address+Y*  R  read from effective address,
                           fix high byte of effective address
        6   address+Y   R  read from effective address
        7   address+Y   W  write the value back to effective address,
                           and do the operation on it
        8   address+Y   W  write the new value to effective address

       Notes: The effective address is always fetched from zero page,
              i.e. the zero page boundary crossing is not handled.

              * The high byte of the effective address may be invalid
                at this time, i.e. it may be smaller by $100.
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: DCP Indirect Indexed

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

Thanks for clearing that up for me! I've managed to correctly implement DCP now and I'm scratching my head over ISC.

Post Reply