shithub: pokecrystal

Download patch

ref: 296402bd31946455c500fd524b141c18cf73cf8c
parent: 4c8c5c10a8c7619cfadf68072f2c52ae0e724386
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Sat Aug 25 18:58:26 EDT 2018

_Divide results go in hQuotient and hRemainder, not in hDividend and hDivisor
Note that the result quotient is four bytes, but hQuotient is a three-byte buffer. This is because no Divide caller ever needed a four-byte quotient, so the buffer didn't include the high byte.

--- a/engine/math/math.asm
+++ b/engine/math/math.asm
@@ -172,18 +172,18 @@
 
 .done
 	ldh a, [hDividend + 1]
-	ldh [hDivisor], a
+	ldh [hRemainder], a
 
 	ldh a, [hMathBuffer + 4]
-	ldh [hDividend + 3], a
+	ldh [hQuotient + 2], a
 
 	ldh a, [hMathBuffer + 3]
-	ldh [hDividend + 2], a
+	ldh [hQuotient + 1], a
 
 	ldh a, [hMathBuffer + 2]
-	ldh [hDividend + 1], a
+	ldh [hQuotient + 0], a
 
 	ldh a, [hMathBuffer + 1]
-	ldh [hDividend + 0], a
+	ldh [hQuotient - 1], a
 
 	ret