all repos — mgba @ e83a371e50638abfe513ef971e16c270f00f012b

mGBA Game Boy Advance Emulator

GBA BIOS: Division by zero sometimes doesn't crash
Vicki Pfau vi@endrift.com
Sat, 19 Sep 2020 00:27:30 -0700
commit

e83a371e50638abfe513ef971e16c270f00f012b

parent

ca67e63abb787756cac5b4692ef7a0b072e03d6e

1 files changed, 5 insertions(+), 1 deletions(-)

jump to
M src/gba/bios.csrc/gba/bios.c

@@ -277,7 +277,11 @@

static void _Div(struct GBA* gba, int32_t num, int32_t denom) { struct ARMCore* cpu = gba->cpu; if (denom == 0) { - mLOG(GBA_BIOS, FATAL, "Attempting to divide %i by zero!", num); + if (num == 0 || num == -1 || num == 1) { + mLOG(GBA_BIOS, GAME_ERROR, "Attempting to divide %i by zero!", num); + } else { + mLOG(GBA_BIOS, FATAL, "Attempting to divide %i by zero!", num); + } // If abs(num) > 1, this should hang, but that would be painful to // emulate in HLE, and no game will get into a state under normal // operation where it hangs...