I am working on a game that utilizes greyscale by swapping two images on the screen really fast, so I made a mode 2 interrupt set to draw the images with a custom function. Everything works great until I get to this code, or other loops similar to it:
SplashKey_Loop:
ld a,(KeyStAny)
cp 1
jr nz,SplashKey_Loop
If I comment out the ld or if I disable interrupts, nothing bad happens at all. I tried disabling interrupts and calling my interrupt within the loop, and it worked just fine.
Even stranger to me is that it only crashes on my key input loops. Initially I had the key input handling within each loop itself, but that caused this crash in menu (and is what led me to putting key handling into the interrupt to try and fix it and that I decided it would be better so I wouldn't have to repeat it elsewhere that it is needed.) I've trimmed down the code and determined that whenever I do ld with the memory address, it crashes. I know that it isn't crashing because of the address as my interrupt reads/writes to it every time.
I have tried it on TI's FlashSim debugger emulator, but it seems like it doesn't handle IM 2 properly. Because of that, I set some breakpoints at appropriate places and disabled interrupts and manually added PC to the stack and set PC to the interrupt address and it all ran just fine.
If anybody here knows if I totally missed something that everyone should know, has any experience with this or a similar issue or knows of something I could try, I would love to hear from them. Thanks.