When I try to battle a trainer, the screen comes up and the music playes as if it's not frozen, but then the pokeballs next to the trainers keep spinning endlessly.
Sounds like you are playing HeartGold or SoulSilver
this is a known issue that occurs on hardware with flashcarts after a number of events (events being things such as talking to people, battling pokemon, entering and exitting buildings)
Usually it is pre-empted by overworld sprites becoming glitched.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What version of desmume are you using?
Sounds like you are playing HeartGold or SoulSilver
this is a known issue that occurs on hardware with flashcarts after a number of events (events being things such as talking to people, battling pokemon, entering and exitting buildings)
Usually it is pre-empted by overworld sprites becoming glitched.