Log division by zero
Jeffrey Pfau jeffrey@endrift.com
Thu, 23 Oct 2014 01:45:32 -0700
1 files changed,
5 insertions(+),
3 deletions(-)
jump to
M
src/gba/gba-bios.c
→
src/gba/gba-bios.c
@@ -99,13 +99,15 @@ uint32_t key = cpu->memory.load32(cpu, cpu->gprs[0] + 4, 0);
cpu->gprs[0] = key / powf(2, (180.f - cpu->gprs[1] - cpu->gprs[2] / 256.f) / 12.f); } -static void _Div(struct ARMCore* cpu, int32_t num, int32_t denom) { +static void _Div(struct GBA* gba, int32_t num, int32_t denom) { + struct ARMCore* cpu = gba->cpu; if (denom != 0) { div_t result = div(num, denom); cpu->gprs[0] = result.quot; cpu->gprs[1] = result.rem; cpu->gprs[3] = abs(result.quot); } else { + GBALog(gba, GBA_LOG_GAME_ERROR, "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 where it hangs... cpu->gprs[0] = (num < 0) ? -1 : 1;@@ -138,10 +140,10 @@ // IntrWait
ARMRaiseSWI(cpu); break; case 0x6: - _Div(cpu, cpu->gprs[0], cpu->gprs[1]); + _Div(gba, cpu->gprs[0], cpu->gprs[1]); break; case 0x7: - _Div(cpu, cpu->gprs[1], cpu->gprs[0]); + _Div(gba, cpu->gprs[1], cpu->gprs[0]); break; case 0x8: cpu->gprs[0] = sqrt(cpu->gprs[0]);