shithub: pokecrystal

Download patch

ref: 9ee2b592083ebaa9fd141406d4c90d5604460c69
parent: ae022e1420ee16032cb7afb1a365bc32fc2a2c9b
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Sun Sep 9 11:10:38 EDT 2018

hMultiplicand is four bytes internally, but the high byte is always 0 since allowing four-byte multiplicands could overflow hProduct.

--- a/engine/math/math.asm
+++ b/engine/math/math.asm
@@ -4,7 +4,7 @@
 	ld b, a
 
 	xor a
-	ldh [hProduct], a
+	ldh [hMultiplicand - 1], a
 	ldh [hMathBuffer + 1], a
 	ldh [hMathBuffer + 2], a
 	ldh [hMathBuffer + 3], a
@@ -36,7 +36,7 @@
 
 	ldh a, [hMathBuffer + 1]
 	ld c, a
-	ldh a, [hProduct]
+	ldh a, [hMultiplicand - 1]
 	adc c
 	ldh [hMathBuffer + 1], a
 
@@ -58,9 +58,9 @@
 	rla
 	ldh [hMultiplicand + 0], a
 
-	ldh a, [hProduct]
+	ldh a, [hMultiplicand - 1]
 	rla
-	ldh [hProduct], a
+	ldh [hMultiplicand - 1], a
 
 	jr .loop