mirror of
https://github.com/ApfelTeeSaft/NESDecompiler.git
synced 2026-08-27 03:43:30 +00:00
When a function is decompiled in the middle of a function, and that function has a jump point prior to the function's entry point, we need to add a fake virtual instruction that jumps back to the start of the function. The virtual instruction needs to be the last instruction in the ordered instruction set. We previously accomplished that by adding an instruction at the location of the function entrypiont minus one. However, this was failing in cases where a system would cause an interrupt right on the virtual address. Emulators would then save the virtual instruction's address to the stack, and jump back into that address once RTI occurs. This fails because the virtual address can't be decompiled, because legit code doesn't exist at that address. To fix this, I updated the `SubAddressOrder` property to allow for negative values. This allows the loopback instruction to be on the correct CPUAddress while still being ordered as expected. Also ensured that virtual addresses do not get labels, as they are not actually valid jump targets.