shithub: pokered

Download patch

ref: 94daf57156f34cf95885ba8e6f32ee0f69436bb1
parent: 21908ba30a8bae5c5e1c86b1164402ec95da0220
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Wed Jan 6 05:20:37 EST 2021

The 'tmhm' macro adjusts to the number of TMs/HMs

--- a/constants/item_constants.asm
+++ b/constants/item_constants.asm
@@ -219,7 +219,9 @@
 	add_tm SUBSTITUTE   ; $FA
 assert NUM_TMS == const_value - TM01, "NUM_TMS ({d:NUM_TMS}) does not match the number of add_tm definitions"
 
+NUM_TM_HM EQU NUM_TMS + NUM_HMS
+
 ; 50 TMs + 5 HMs = 55 learnable TM/HM flags per Pokémon.
 ; These fit in 7 bytes, with one unused bit left over.
-__tmhm_value__ = NUM_TMS + NUM_HMS + 1
+__tmhm_value__ = NUM_TM_HM + 1
 UNUSED_TMNUM EQU __tmhm_value__
--- a/macros/data.asm
+++ b/macros/data.asm
@@ -16,36 +16,36 @@
 coins EQUS "bcd2"
 money EQUS "bcd3"
 
-tmhm: MACRO
 ; used in data/pokemon/base_stats/*.asm
-_tms1 = 0 ; TM01-TM24 (24)
-_tms2 = 0 ; TM25-TM48 (24)
-_tms3 = 0 ; TM49-TM50 + HM01-HM05 (7/24)
+tmhm: MACRO
+; initialize bytes to 0
+n = 0
+REPT (NUM_TM_HM + 7) / 8
+_TM_BYTE EQUS "_tm{d:n}"
+_TM_BYTE = 0
+PURGE _TM_BYTE
+n = n + 1
+ENDR
+; set bits of bytes
 REPT _NARG
-	if DEF(\1_TMNUM)
-	if \1_TMNUM < 24 + 1
-_tms1 = _tms1 | (1 << ((\1_TMNUM) - 1))
-	ELIF \1_TMNUM < 48 + 1
-_tms2 = _tms2 | (1 << ((\1_TMNUM) - 1 - 24))
-	else
-_tms3 = _tms3 | (1 << ((\1_TMNUM) - 1 - 48))
+	IF DEF(\1_TMNUM)
+n = (\1_TMNUM - 1) / 8
+i = (\1_TMNUM - 1) % 8
+_TM_BYTE EQUS "_tm{d:n}"
+_TM_BYTE = _TM_BYTE | (1 << i)
+PURGE _TM_BYTE
+	ELSE
+		FAIL "\1 is not a TM or HM move"
 	ENDC
-	else
-		fail "\1 is not a TM or HM move"
-	ENDC
 	SHIFT
 ENDR
-REPT 3 ; TM01-TM24 (24/24)
-	db _tms1 & $ff
-_tms1 = _tms1 >> 8
-ENDR
-REPT 3 ; TM25-TM48 (24/24)
-	db _tms2 & $ff
-_tms2 = _tms2 >> 8
-ENDR
-REPT 1 ; TM49-TM50 + HM01-HM05 (7/8)
-	db _tms3 & $ff
-_tms3 = _tms3 >> 8
+; output bytes
+n = 0
+REPT (NUM_TM_HM + 7) / 8
+_TM_BYTE EQUS "_tm{d:n}"
+	db _TM_BYTE
+PURGE _TM_BYTE
+n = n + 1
 ENDR
 ENDM