Native Vs Emulation mode

This morning I think I finally found why the NSF Replayer isn’t working. Here is the piece of code :

        sec
        xce             ; 6502 mode
        ldx #0
        txy
        ;jsr ($1013,x) <- commented for testing purpose
        clc
        xce             ; native mode

The problem is when I switch the 65816 execution mode from native to emulation (6502). This code is part of a routine that is called in memory at address 7F5006 with a jsl instruction and the routine return with a rtl to code in bank 0. When I’m removing the xce instruction everything run fine, with the xce instruction the rtl return in the middle of nowhere. Is there something that xce instruction modify that I’m not aware of ?

I will continue to investigate, but usual shoot your ideas in the comments section.

++ Lint

EDIT: The problem is that when comming back emultation mode the stack address is modified. So now as a quick patch I’m saving it somewhere in RAM and restore it. Thanks D4S for spotting this. 

Comments are closed.