SingleStepTests / 65x02

A language-agnostic JSON-encoded instruction-by-instruction test suite for the 65[c]02 that includes bus activity.
MIT License
17 stars 3 forks source link

Rockwell 65c02 JSR test is probably wrong ¿? #9

Closed drhelius closed 2 months ago

drhelius commented 2 months ago

20.json, test 5358 "20 e2 b0" in my books is JSR $B0E2 But for some reason is expecting a final PC of $BEE2 (final PC=48866)

Is there something I'm missing?

{
    'cycles': [
        [
            444,
            32,
            "read"
        ],
        [
            445,
            226,
            "read"
        ],
        [
            447,
            53,
            "read"
        ],
        [
            447,
            1,
            "write"
        ],
        [
            446,
            190,
            "write"
        ],
        [
            446,
            190,
            "read"
        ]
    ],
    'final': {
        'ram': [
            [
                444,
                32
            ],
            [
                445,
                226
            ],
            [
                446,
                190
            ],
            [
                447,
                1
            ],
            [
                48866,
                156
            ]
        ],
        'p': 34,
        'x': 142,
        'y': 179,
        's': 189,
        'a': 246,
        'pc': 48866
    },
    'initial': {
        'ram': [
            [
                444,
                32
            ],
            [
                445,
                226
            ],
            [
                446,
                176
            ],
            [
                447,
                53
            ],
            [
                48866,
                156
            ]
        ],
        'p': 34,
        'x': 142,
        'y': 179,
        's': 191,
        'a': 246,
        'pc': 444
    },
    'name': "20 e2 b0"
}
TomHarte commented 2 months ago

I had a quick look at the Rockwell data sheet and could find no reason to believe that JMP's implementation differs from the baseline 6502 so I think the result here is just because code is being executed from the stack page.

Given that initially PC = 444 = $1BC, and S = 191 = $BF

sequence of events here is:

  1. CPU reads $20 from PC=$1BC, which is JMP;
  2. CPU reads $E2 from PC=$1BD, leaving the PC at $1BE;
  3. CPU writes the low byte of the PC, $BE, to $1BF as per the stack pointer;
  4. CPU writes the high byte of the PC, $01 to $1BE, the next location on the stack;
  5. CPU now reads $BE from PC=$1BE.

Therefore the destination address the processor reads is $BEE2 because the low byte of the PC is written to the stack modifying the instruction before it has fully been read.

drhelius commented 2 months ago

Yes, you are right. Thanks for the clear explanation!